增加用水数据接口

This commit is contained in:
wyw
2024-08-16 02:32:02 +08:00
parent 0d42fc0785
commit 0388cd8aba
6 changed files with 137 additions and 10 deletions

View File

@ -97,6 +97,26 @@ public class DeviceDetailController extends BaseController {
return ajaxResult;
}
/**
* 查询用水数据
* @param queryLogVo 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
@ApiOperation("查询用水数据")
@GetMapping("/yongshuiChart")
public AjaxResult yongshuiChart(QueryLogVo queryLogVo)
{
if (null == queryLogVo.getDeviceId() || queryLogVo.getDeviceId() == 0L) {
return AjaxResult.error("请选择设备");
}
//设备历史echart数据
List<Object> list = deviceDetailService.yongshuiChart(queryLogVo);
AjaxResult ajaxResult = AjaxResult.success();
ajaxResult.put("data", list);
ajaxResult.put("realData", deviceDetailService.yongshuiRealData(queryLogVo));
return ajaxResult;
}
/**
* 查询巡检记录

View File

@ -29,6 +29,7 @@ public interface IDeviceDetailService {
List<Device> getBindDevices(String ids);
ArrayList<Object> gongdianChart(QueryLogVo queryLogVo);
List<Object> yongshuiChart(QueryLogVo queryLogVo);
List<XjInspectionRecords> xunjianRecord(QueryLogVo queryLogVo);
@ -41,4 +42,6 @@ public interface IDeviceDetailService {
* @param queryLogVo
*/
List<HashMap<Object, Object>> gongdianRealData(QueryLogVo queryLogVo);
List<HashMap<Object, Object>> yongshuiRealData(QueryLogVo queryLogVo);
}

View File

@ -107,6 +107,27 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
return deviceLogAllCurves;
}
@Override
public List<Object> yongshuiChart(QueryLogVo queryLogVo) {
Long deviceId = queryLogVo.getDeviceId();
if (deviceId == null) {
throw new RuntimeException("请上传devicerId");
}
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
if (device == null) {
throw new RuntimeException("未查到该设备");
}
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
//太阳能设备
String liuliangIds = devParams.get("liuliangIds").toString();
if (liuliangIds == null) {
return new ArrayList<>();
}
ArrayList<Object> deviceLogAllCurves =
iDeviceService.getDeviceLogAllCurves(Long.parseLong(liuliangIds), queryLogVo.getStartTime(), queryLogVo.getEndTime());
return deviceLogAllCurves;
}
@Override
public List<XjInspectionRecords> xunjianRecord(QueryLogVo queryLogVo) {
@ -270,6 +291,90 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
return list;
}
@Override
public List<HashMap<Object, Object>> yongshuiRealData(QueryLogVo queryLogVo) {
Long deviceId = queryLogVo.getDeviceId();
if (deviceId == null) {
throw new RuntimeException("请上传devicerId");
}
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
if (device == null) {
throw new RuntimeException("未查到该设备");
}
DateTime dateTime = DateUtil.date(new Date());
Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
//太阳能设备
String liuliangIds = devParams.get("liuliangIds").toString();
ThingsModel thingsModel1 = new ThingsModel();
thingsModel1.setProductId(139L);
List<ThingsModel> liuliangModels = thingsModelService.selectThingsModelList(thingsModel1);
liuliangModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
List<HashMap<Object, Object>> list = new ArrayList<>();
if (StringUtils.isNotEmpty(liuliangIds)) {
Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(liuliangIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(taiyangnengDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
for (ThingsModel thingsModel : liuliangModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if (parse.containsKey("unit")) {
hashMap.put("unit", parse.get("unit"));
}
}
if (hashMap.size() > 1) {
List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs1 != null) {
if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", -1);
}
hashMap.put("value", deviceLogs1.get(0).getLogValue());
} else {
hashMap.put("value", "--");
hashMap.put("upType", 0);
}
}
} else if (hashMap.size() > 0) {
List<DeviceLog> deviceLogs2 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs2 != null) {
hashMap.put("value", deviceLogs2.get(0).getLogValue());
}
}
list.add(hashMap);
}
} else {
for (ThingsModel thingsModel : liuliangModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
list.add(hashMap);
}
}
return list;
}
@Override
public CommonResult<CmdHaiWeiVo> cmdDevices(CmdHaiWeiDto cmdHaiWeiDto) {
String url = "https://cloud.haiwell.com/api/project/machine/datagroup/setTagsValue";

View File

@ -107,7 +107,6 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
return deviceListVo;
}
//todo 需要修改安防版和水电双计设备实时数据
@Override
public Object getRealTimeDataByDevicerId(Long deviceId) {
HashMap<String, Object> rMap = new HashMap<String, Object>() {