Commit b25b6eb9 authored by zhangsen's avatar zhangsen

水池液位趋势修改

parent b918e882
...@@ -38,6 +38,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation; ...@@ -38,6 +38,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -846,18 +847,18 @@ public class TopographyController extends AbstractBaseController { ...@@ -846,18 +847,18 @@ public class TopographyController extends AbstractBaseController {
@RequestParam(required = false) String endDate) throws ParseException { @RequestParam(required = false) String endDate) throws ParseException {
Map<String, List<IotIndexResVo>> resultMap = new HashMap<>(); Map<String, List<IotIndexResVo>> resultMap = new HashMap<>();
List<String> split= Arrays.asList(equipSpeId.split(",")); List<String> split = Arrays.asList(equipSpeId.split(","));
List<IotIndexResVo> finalRes = new ArrayList<>(); List<IotIndexResVo> finalRes = new ArrayList<>();
List<IotIndexResVo> finalResContainsWaterLevel = new ArrayList<>(); List<IotIndexResVo> finalResContainsWaterLevel = new ArrayList<>();
List<IotIndexResVo> resultResContainsWater = new ArrayList<>(); List<IotIndexResVo> resultResContainsWater = new ArrayList<>();
Map<String, String> iotCodeMap = new HashMap<>();
for (String specId : split) { for (String specId : split) {
String eqpId; String eqpId;
String iotCode = null; String iotCode = null;
if(null != fieldKey || null != isTrend) { if (null != fieldKey || null != isTrend) {
EquipmentSpecific equipmentSpecific = equipmentSpecificService.getById(specId); EquipmentSpecific equipmentSpecific = equipmentSpecificService.getById(specId);
iotCode = equipmentSpecific.getIotCode(); iotCode = equipmentSpecific.getIotCode();
iotCodeMap.put(specId, iotCode);
List<EquipmentIndex> equipmentSpecifics = equipmentIndexService.getPerfQutoaIotList(Long.valueOf(specId)); List<EquipmentIndex> equipmentSpecifics = equipmentIndexService.getPerfQutoaIotList(Long.valueOf(specId));
...@@ -867,7 +868,6 @@ public class TopographyController extends AbstractBaseController { ...@@ -867,7 +868,6 @@ public class TopographyController extends AbstractBaseController {
if ("true".equals(isTrend)) { if ("true".equals(isTrend)) {
fieldKey = equipmentSpecifics.stream().filter(equipmentIndex -> equipmentIndex.getIsTrend()).map(EquipmentIndex::getPerfQuotaDefinitionId).collect(Collectors.joining(",")); fieldKey = equipmentSpecifics.stream().filter(equipmentIndex -> equipmentIndex.getIsTrend()).map(EquipmentIndex::getPerfQuotaDefinitionId).collect(Collectors.joining(","));
} }
} else { } else {
if (StringUtil.isNotEmpty(specId)) { if (StringUtil.isNotEmpty(specId)) {
eqpId = specId; eqpId = specId;
...@@ -882,7 +882,6 @@ public class TopographyController extends AbstractBaseController { ...@@ -882,7 +882,6 @@ public class TopographyController extends AbstractBaseController {
EquipmentSpecific equipmentSpecific = equipmentSpecificService.getById(eqpId); EquipmentSpecific equipmentSpecific = equipmentSpecificService.getById(eqpId);
iotCode = equipmentSpecific.getIotCode(); iotCode = equipmentSpecific.getIotCode();
} }
String prefix = null; String prefix = null;
String suffix = null; String suffix = null;
if (StringUtil.isNotEmpty(iotCode) && iotCode.length() > 8) { if (StringUtil.isNotEmpty(iotCode) && iotCode.length() > 8) {
...@@ -911,14 +910,7 @@ public class TopographyController extends AbstractBaseController { ...@@ -911,14 +910,7 @@ public class TopographyController extends AbstractBaseController {
} }
} }
} }
// List<IotDataVO> timeList = vos.stream().filter(x -> x.getKey().equals("time")).collect(Collectors.toList());
// List<Date> dates = new ArrayList<>();
Map<String, List<Date>> dateMap = new HashMap<>(); Map<String, List<Date>> dateMap = new HashMap<>();
// String indexKey = null;
// String useDate = null;
for (int i = 0; i < vos.size(); i = i + 2) { for (int i = 0; i < vos.size(); i = i + 2) {
Date useDate = null; Date useDate = null;
String indexKey = null; String indexKey = null;
...@@ -941,44 +933,7 @@ public class TopographyController extends AbstractBaseController { ...@@ -941,44 +933,7 @@ public class TopographyController extends AbstractBaseController {
dateMap.get(indexKey).add(useDate); dateMap.get(indexKey).add(useDate);
} }
} }
// for (IotDataVO vo : vos) {
// if (!vo.getKey().equals("time")) {
// indexKey = vo.getKey();
// if (useDate != null) {
// SimpleDateFormat sdf1 = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN);
// if (!dateMap.containsKey(indexKey)) {
// ArrayList<Date> dates1 = new ArrayList<>();
// dates1.add(sdf1.parse(useDate));
// dateMap.put(indexKey, dates1);
// } else {
// dateMap.get(indexKey).add(sdf1.parse(useDate));
// }
// indexKey = null;
// }
// } else {
// String value = String.valueOf(vo.getValue());
// String strDate = value.substring(0, 19);
// SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_DATE_HOUR_MIN_SEC);
// SimpleDateFormat sdf1 = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN);
// logger.info("返回时间===================================(" + vo.getValue() + ") =======================================");
// sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
// Date date = sdf.parse(strDate);
// String time = DateTimeUtil.format(date, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
// if (indexKey == null) {
// useDate = time;
// }
//// dates.add(sdf1.parse(time));
// logger.info("返回时间===================================(" + sdf1.parse(time) + ") =======================================");
// }
// }
List<EquipmentSpecificIndex> indexes = equipmentSpecificIndexMapper.getEquipmentSpeIndexByIotCodeAndTrend(iotCode); List<EquipmentSpecificIndex> indexes = equipmentSpecificIndexMapper.getEquipmentSpeIndexByIotCodeAndTrend(iotCode);
if (0 < indexes.size()) { if (0 < indexes.size()) {
List<TopographyIotIndexTrendVo> list = new ArrayList<>(); List<TopographyIotIndexTrendVo> list = new ArrayList<>();
vos.forEach(iotDataVO -> { vos.forEach(iotDataVO -> {
...@@ -1006,7 +961,6 @@ public class TopographyController extends AbstractBaseController { ...@@ -1006,7 +961,6 @@ public class TopographyController extends AbstractBaseController {
for (String str : maps.keySet()) { for (String str : maps.keySet()) {
mapIndex.put(str, maps.get(str).get(0).getId()); mapIndex.put(str, maps.get(str).get(0).getId());
} }
List<IotIndexResVo> res = new ArrayList<>(); List<IotIndexResVo> res = new ArrayList<>();
List<IotIndexResVo> resContainsWaterLevelList = new ArrayList<>(); List<IotIndexResVo> resContainsWaterLevelList = new ArrayList<>();
for (String s : mapIndex.keySet()) { for (String s : mapIndex.keySet()) {
...@@ -1027,7 +981,6 @@ public class TopographyController extends AbstractBaseController { ...@@ -1027,7 +981,6 @@ public class TopographyController extends AbstractBaseController {
res.add(vo); res.add(vo);
} }
} }
for (IotIndexResVo s : res) { for (IotIndexResVo s : res) {
s.setIotData(map.get(s.getNameKey())); s.setIotData(map.get(s.getNameKey()));
s.setTimes(dateMap.get(s.getNameKey())); s.setTimes(dateMap.get(s.getNameKey()));
...@@ -1037,9 +990,9 @@ public class TopographyController extends AbstractBaseController { ...@@ -1037,9 +990,9 @@ public class TopographyController extends AbstractBaseController {
} }
} }
} }
List<Date> containsWaterDates = new ArrayList<>();
Map<String, Map<Date, IotDataVO>> iotDataAndDateMap= new HashMap<>(); List<Date> containsWaterDates = new ArrayList<>();
Map<String, Map<Date, IotDataVO>> iotDataAndDateMap = new HashMap<>();
finalResContainsWaterLevel.stream().forEach(item -> { finalResContainsWaterLevel.stream().forEach(item -> {
if (!CollectionUtils.isEmpty(item.getTimes())) { if (!CollectionUtils.isEmpty(item.getTimes())) {
containsWaterDates.addAll(item.getTimes()); containsWaterDates.addAll(item.getTimes());
...@@ -1051,9 +1004,9 @@ public class TopographyController extends AbstractBaseController { ...@@ -1051,9 +1004,9 @@ public class TopographyController extends AbstractBaseController {
} }
}); });
List<Date> collect = containsWaterDates.stream().distinct().sorted(Comparator.comparing(t -> t)).collect(Collectors.toList()); List<Date> collect = containsWaterDates.stream().distinct().sorted(Comparator.comparing(t -> t)).collect(Collectors.toList());
IotIndexResVo iotIndexRes = new IotIndexResVo();
Map<String, List<IotDataVO>> map = new HashMap<>();
for (IotIndexResVo indexResVo : finalResContainsWaterLevel) { for (IotIndexResVo indexResVo : finalResContainsWaterLevel) {
IotIndexResVo iotIndexRes = new IotIndexResVo();
iotIndexRes.setName(indexResVo.getName()); iotIndexRes.setName(indexResVo.getName());
iotIndexRes.setTimes(collect); iotIndexRes.setTimes(collect);
iotIndexRes.setId(indexResVo.getId()); iotIndexRes.setId(indexResVo.getId());
...@@ -1063,16 +1016,65 @@ public class TopographyController extends AbstractBaseController { ...@@ -1063,16 +1016,65 @@ public class TopographyController extends AbstractBaseController {
List<IotDataVO> list = new ArrayList<>(); List<IotDataVO> list = new ArrayList<>();
collect.forEach(item -> { collect.forEach(item -> {
IotDataVO iotDataVO = new IotDataVO(); IotDataVO iotDataVO = new IotDataVO();
iotDataVO.setValue(0);
iotDataVO.setKey(indexResVo.getIotData().get(0).getKey()); iotDataVO.setKey(indexResVo.getIotData().get(0).getKey());
iotDataVO.setValue(0);
if (dateIotDataVOMap.containsKey(item)) { if (dateIotDataVOMap.containsKey(item)) {
iotDataVO.setValue(dateIotDataVOMap.get(item).getValue()); iotDataVO.setValue(dateIotDataVOMap.get(item).getValue());
} else {
String currentIotCode = iotCodeMap.get(indexResVo.getEquipId());
String currentPrefix = currentIotCode.substring(0, 8);
String currentSuffix = currentIotCode.substring(8);
ResponseModel entity = null;
try {
entity = iotFeign.selectPage(getAppKey(), getProduct(), getToken(), "2000-01-01 00:00:00", endDate, currentPrefix, currentSuffix, indexResVo.getIotData().get(0).getKey(), 0, 1);
} catch (Exception e) {
throw new RuntimeException("调用AMOS-API-IOT服务失败,请检查服务是否正常!");
}
if (200 == entity.getStatus() && !ObjectUtils.isEmpty(entity.getResult())) {
String json = JSON.toJSONString(entity.getResult());
Map<String, Object> listObject = (Map<String, Object>) JSONArray.parse(json);
List<Map<String, String>> listData = (List<Map<String, String>>) listObject.get("records");
if (!CollectionUtils.isEmpty(listData)) {
for (Map.Entry<String, String> stringStringEntry : listData.get(0).entrySet()) {
if (indexResVo.getIotData().get(0).getKey().equals(stringStringEntry.getKey())) {
iotDataVO.setValue(String.valueOf(stringStringEntry.getValue()));
}
}
} else {
iotDataVO.setValue(0);
}
} else {
iotDataVO.setValue(0);
}
} }
list.add(iotDataVO); list.add(iotDataVO);
}); });
iotIndexRes.setIotData(list); map.put(indexResVo.getEquipId(), list);
resultResContainsWater.add(iotIndexRes); }
List<IotDataVO> list = new ArrayList<>();
int j = 0;
for (Map.Entry<String, List<IotDataVO>> stringListEntry : map.entrySet()) {
if (j == 0) {
list = stringListEntry.getValue();
} else {
for (int i = 0; i < stringListEntry.getValue().size(); i++) {
Object last = list.get(i).getValue();
Object current = stringListEntry.getValue().get(i).getValue();
BigDecimal value1 = new BigDecimal(String.valueOf(last));
BigDecimal value2 = new BigDecimal(String.valueOf(current));
BigDecimal add = value1.add(value2);
BigDecimal divide = add.divide(new BigDecimal(2), 2, BigDecimal.ROUND_DOWN);
list.get(i).setValue(divide);
}
}
j++;
} }
iotIndexRes.setIotData(list);
resultResContainsWater.add(iotIndexRes);
resultMap.put("noMergeList", finalRes); resultMap.put("noMergeList", finalRes);
resultMap.put("mergeList", resultResContainsWater); resultMap.put("mergeList", resultResContainsWater);
return CommonResponseUtil.success(resultMap); return CommonResponseUtil.success(resultMap);
......
...@@ -25,4 +25,17 @@ public interface IotFeign { ...@@ -25,4 +25,17 @@ public interface IotFeign {
@RequestParam(value = "deviceName") String deviceName, @RequestParam(value = "deviceName") String deviceName,
@RequestParam(required = false, value = "fieldKey") String fieldKey); @RequestParam(required = false, value = "fieldKey") String fieldKey);
@RequestMapping(value = "/v1/livedata/page", method = RequestMethod.GET, consumes = "application/json")
ResponseModel selectPage(
@RequestHeader("appKey") String appKey,
@RequestHeader("product") String product,
@RequestHeader("token") String token,
@RequestParam(value = "timeStart") String beginDate,
@RequestParam(value = "timeEnd") String endDate,
@RequestParam(value = "productKey") String productKey,
@RequestParam(value = "deviceName") String deviceName,
@RequestParam(required = false, value = "fieldKey") String fieldKey,
@RequestParam(value = "current") Integer current,
@RequestParam(value = "size") Integer size);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment