增加用水数据接口

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>() {

View File

@ -133,6 +133,9 @@ public class DeviceServiceImpl implements IDeviceService {
@Override
public Device selectDeviceByDeviceId(Long deviceId) {
Device device = deviceMapper.selectDeviceByDeviceId(deviceId);
if (device == null) {
return null;
}
List<ValueItem> list = itslValueCache.getCacheDeviceStatus(device.getProductId(), device.getSerialNumber());
if (list != null && list.size() > 0) {
// redis中获取设备状态物模型值
@ -1600,12 +1603,10 @@ public class DeviceServiceImpl implements IDeviceService {
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
devices.setProductId(136L);
List<Device> deviceList = selectDeviceList(devices);
for (Device device : deviceList) {
HashMap<String, Object> itemMap = new HashMap<>();
resultList.add(itemMap);
Integer integer = 0;
itemMap.put("device",device);
if (device.getStatus() != null) {
if (device.getStatus().equals(4)) {
@ -1613,7 +1614,6 @@ public class DeviceServiceImpl implements IDeviceService {
}
}
itemMap.put("online",integer);
}
return resultList;
}

View File

@ -202,9 +202,9 @@ public class MaWatereleRecordServiceImpl implements IMaWatereleRecordService
List<String> time = new ArrayList<>();
List<String> sumFlow = new ArrayList<>();
List<String> sumEle = new ArrayList<>();
HashMap<String, Object> sumFlowtMap = new HashMap<>();
sumFlowtMap.put("name", "累计水量");
sumFlowtMap.put("unit", "");
// HashMap<String, Object> sumFlowtMap = new HashMap<>();
// sumFlowtMap.put("name", "累计水量");
// sumFlowtMap.put("unit", "");
HashMap<String, Object> sumEletMap = new HashMap<>();
sumEletMap.put("name", "累计电量");
sumEletMap.put("unit", "");
@ -213,11 +213,11 @@ public class MaWatereleRecordServiceImpl implements IMaWatereleRecordService
sumFlow.add(record.getSumflow());
sumEle.add(record.getSumele());
}
sumFlowtMap.put("time", time);
sumFlowtMap.put("data", sumFlow);
// sumFlowtMap.put("time", time);
// sumFlowtMap.put("data", sumFlow);
sumEletMap.put("time", time);
sumEletMap.put("data", sumEle);
list.add(sumFlowtMap);
// list.add(sumFlowtMap);
list.add(sumEletMap);
// map.put("time", time);
// map.put("sumFlow", sumFlow);