From eb6d41359a8957c6355275f7697db202d6a523db Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Fri, 11 Aug 2023 14:29:55 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into cjl
---
screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java | 291 +++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 247 insertions(+), 44 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
index d534583..8a068b7 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
@@ -248,23 +248,17 @@
Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_EN);
Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_EN);
List<HistoryDaily> historyDailyByMacAndTimeSlot = historyDailyService.getHistoryDailyByMacAndTimeSlot(macs, startDate, endDate);
- Map<String,Map<String,Object>> map = resultMap(historyDailyByMacAndTimeSlot);
+ Map<String,Map<String,Object>> map = resultMap(historyDailyByMacAndTimeSlot,new ArrayList<>());
+ Map<Integer,String> pointMap = pointMap(devices);
+ Map<String,String> sensorMap = sensorMap(sensorsList);
for (Device device:devices) {
- QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>();
- monitorPointQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
- monitorPointQueryWrapper.eq("id",device.getMonitorPointId());
- MonitorPoint monitorPoint = monitorPointMapper.selectOne(monitorPointQueryWrapper);
for (String sensor:sensorsList) {
Date ks = DateUtils.getDate(startTime,"yyyy-MM-dd");
Date js = DateUtils.getDateOfDay(DateUtils.getDate(endTime,"yyyy-MM-dd"),1);
Map<String, Object> timeValueMap = new LinkedHashMap<>();//key���time���value������������json
- timeValueMap.put("������������",monitorPoint.getName());
+ timeValueMap.put("������������",pointMap.get(device.getMonitorPointId()));
timeValueMap.put("name",device.getName());
- QueryWrapper<Sensor> sensorQueryWrapper = new QueryWrapper<>();
- sensorQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
- sensorQueryWrapper.eq("code",sensor);
- Sensor sensorEntity = sensorMapper.selectOne(sensorQueryWrapper);
- timeValueMap.put("sensor",sensorEntity.getName());
+ timeValueMap.put("sensor",sensorMap.get(sensor));
ArrayList<Double> doubleArrayList = new ArrayList<>();
while (DateUtils.isTimeBefor(js,ks)){
String c = DateUtils.dateToDateString(ks,"yyyy-MM-dd");
@@ -272,22 +266,14 @@
if(map.containsKey(k)){
Object o = map.get(k).get(sensor);
timeValueMap.put(c,Objects.nonNull(o)?Double.valueOf(o.toString()):0);
+ if(Objects.nonNull(o)&& (!Double.valueOf(o.toString()).equals(0d))){
+ doubleArrayList.add(Double.valueOf(o.toString()));
+ }
}else {
timeValueMap.put(c,0);
}
ks = DateUtils.getDateOfDay(ks,1);
}
-
- /*for (HistoryDaily historyDaily : historyDailyByMacAndTimeSlot) {
- Date time = historyDaily.getTime();
- String dateStr = DateUtils.dateToDateString(time, "yyyy-MM-dd");
- String value = historyDaily.getValue();
- JSONObject jsonObject = JSONObject.parseObject(value);
- doubleArrayList.add(Objects.nonNull(jsonObject)&&Objects.nonNull(jsonObject.get(sensor))?Double.parseDouble(jsonObject.get(sensor).toString()):0);
- if (jsonObject.containsKey(sensor)){
- timeValueMap.put(dateStr, jsonObject.get(sensor).toString());
- }
- }*/
Double ListAvg = doubleArrayList.stream().collect(Collectors.averagingDouble(Double::doubleValue));
double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
timeValueMap.put("���������",rsAvg);
@@ -295,32 +281,31 @@
}
}
}else {
+ QueryWrapper<HistoryMonthly> HistoryMonthlyWrapper = new QueryWrapper<>();
+ HistoryMonthlyWrapper.in("mac",devices.stream().map(Device::getMac).collect(Collectors.toList()));
+ HistoryMonthlyWrapper.between("time",startTime,endTime);
+ List<HistoryMonthly> historyMonthlyList = historyMonthlyMapper.selectList(HistoryMonthlyWrapper);
+ Map<String,Map<String,Object>> map = resultMap(new ArrayList<>(),historyMonthlyList);
+ Map<Integer,String> pointMap = pointMap(devices);
+ Map<String,String> sensorMap = sensorMap(sensorsList);
for (Device device:devices) {
- QueryWrapper<HistoryMonthly> HistoryMonthlyWrapper = new QueryWrapper<>();
- HistoryMonthlyWrapper.eq("mac",device.getMac());
- HistoryMonthlyWrapper.between("time",startTime,endTime);
- List<HistoryMonthly> historyMonthlyList = historyMonthlyMapper.selectList(HistoryMonthlyWrapper);
for (String sensor:sensorsList) {
+ Date ks = DateUtils.getDate(startTime,"yyyy-MM");
+ Date js = DateUtils.addMonths(DateUtils.getDate(endTime,"yyyy-MM"),1);
Map<String, Object> timeValueMap = new LinkedHashMap<>();//key���time���value������������json
- QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>();
- monitorPointQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
- monitorPointQueryWrapper.eq("id",device.getMonitorPointId());
- MonitorPoint monitorPoint = monitorPointMapper.selectOne(monitorPointQueryWrapper);
- timeValueMap.put("������������",monitorPoint.getName());
+ timeValueMap.put("������������",pointMap.get(device.getMonitorPointId()));
timeValueMap.put("name",device.getName());
- QueryWrapper<Sensor> sensorQueryWrapper = new QueryWrapper<>();
- sensorQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
- sensorQueryWrapper.eq("code",sensor);
- Sensor sensorEntity = sensorMapper.selectOne(sensorQueryWrapper);
- timeValueMap.put("sensor",sensorEntity.getName());
- for (HistoryMonthly historyMonthly : historyMonthlyList) {
- Date time = historyMonthly.getTime();
- String dateStr = DateUtils.dateToDateString(time, "yyyy-MM");
- String value = historyMonthly.getValue();
- JSONObject jsonObject = JSONObject.parseObject(value);
- if (jsonObject.containsKey(sensor)){
- timeValueMap.put(dateStr, jsonObject.get(sensor).toString());
+ timeValueMap.put("sensor",sensorMap.get(sensor));
+ while (DateUtils.isTimeBefor(js,ks)){
+ String c = DateUtils.dateToDateString(ks,"yyyy-MM");
+ String k = c+"_"+device.getMac();
+ if(map.containsKey(k)){
+ Object o = map.get(k).get(sensor);
+ timeValueMap.put(c,Objects.nonNull(o)?Double.valueOf(o.toString()):0);
+ }else {
+ timeValueMap.put(c,0);
}
+ ks = DateUtils.addMonths(ks,1);
}
resultList.add(timeValueMap);
}
@@ -329,8 +314,177 @@
return resultList;
}
+ @Override
+ public List<Map<String, Object>> getHourlyDataDataV3Excel(Map<String, Object> params) {
+ List<String> macs = (List<String>) params.remove("macs");
+ List<String> times = (List<String>) params.remove("times");
+ String type = params.get("type").toString();
+ String startTime = times.get(0);
+ String endTime = times.get(1);
- private Map<String,Map<String,Object>> resultMap(List<HistoryDaily> list ){
+// String[] macs = params.remove("macs").toString().split(",");
+// List<String> macsList = Arrays.asList(macs);
+ QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("is_delete",Constants.NOT_DELETE);
+ queryWrapper.in("mac", macs);
+ List<Device> devices = deviceMapper.selectList(queryWrapper);
+ if (devices.size()<=0){
+ return null;
+ }
+ String[] sensors = params.remove("sensors").toString().split(",");
+ List<String> sensorsList = Arrays.asList(sensors);
+ List<Map<String,Object>> resultList = new ArrayList<>();
+
+// List<String> sensorsList = (List<String>) params.remove("sensors");
+// String startTime = params.get("startTime").toString();
+// String endTime = params.get("endTime").toString();
+ if (type.equals("hours")){
+ Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_EN);
+ Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_EN);
+ List<HistoryHourly> hourlies = historyHourlyService.getValueByMacAndTime(macs, DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_EN), DateUtils.getDate(endTime, DateUtils.yyyy_MM_dd_HH_EN));
+ Map<String,Map<String,Object>> map = resultMap(hourlies);
+ Map<Integer,String> pointMap = pointMap(devices);
+ Map<String,String> sensorMap = sensorMap(sensorsList);
+
+ for (Device device:devices) {
+ Date ks = DateUtils.getDate(startTime,"yyyy-MM-dd HH");
+ Date js = DateUtils.getDateAddHour(DateUtils.getDate(endTime,"yyyy-MM-dd HH"),1);
+ while (DateUtils.isTimeBefor(js,ks)){
+ Map<String, Object> timeValueMap = new LinkedHashMap<>();//key���time���value������������json
+ timeValueMap.put("������������",pointMap.get(device.getMonitorPointId()));
+ timeValueMap.put("name",device.getName());
+ String c = DateUtils.dateToDateString(ks,DateUtils.yyyy_MM_dd_HH_EN);
+ timeValueMap.put("������",c);
+ for (String sensor:sensorsList) {
+ String k = c+"_"+device.getMac();
+ Double num = 0d;
+ if(map.containsKey(k)){
+ Object o = map.get(k).get(sensor);
+ num = Objects.nonNull(o)?Double.valueOf(o.toString()):0d;
+ }
+ timeValueMap.put(sensorMap.get(sensor),num);
+ }
+ resultList.add(timeValueMap);
+ ks = DateUtils.getDateAddHour(ks,1);
+ }
+ }
+ } else if("day".equals(type)){
+ Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_EN);
+ Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_EN);
+ List<HistoryDaily> historyDailyByMacAndTimeSlot = historyDailyService.getHistoryDailyByMacAndTimeSlot(macs, startDate, endDate);
+ Map<String,Map<String,Object>> map = resultMap(historyDailyByMacAndTimeSlot,new ArrayList<>());
+ Map<Integer,String> pointMap = pointMap(devices);
+ Map<String,String> sensorMap = sensorMap(sensorsList);
+ for (Device device:devices) {
+ Date ks = DateUtils.getDate(startTime,"yyyy-MM-dd");
+ Date js = DateUtils.getDateOfDay(DateUtils.getDate(endTime,"yyyy-MM-dd"),1);
+ String nameSite = pointMap.get(device.getMonitorPointId());
+ String name = device.getName();
+ Map<String, Object> timeValueMap = new LinkedHashMap<>();
+ Map<String,ArrayList<Double>> listMap = new HashMap<>();
+ int numCount = 0;
+ while (DateUtils.isTimeBefor(js,ks)){
+ timeValueMap = new LinkedHashMap<>();//key���time���value������������json
+ timeValueMap.put("������������",nameSite);
+ timeValueMap.put("name",name);
+ String c = DateUtils.dateToDateString(ks,"yyyy-MM-dd");
+ timeValueMap.put("������",c);
+ for (String sensor:sensorsList) {
+ String k = c+"_"+device.getMac();
+ Double num = 0d;
+ if(map.containsKey(k)){
+ Object o = map.get(k).get(sensor);
+ num = Objects.nonNull(o)?Double.valueOf(o.toString()):0d;
+ if(Objects.nonNull(num)&& !num.equals(0d)){
+ ArrayList<Double> doubleArrayList = Objects.isNull(listMap.get(numCount+"_"+sensorMap.get(sensor)))?new ArrayList<>():listMap.get(numCount+"_"+sensorMap.get(sensor));
+ doubleArrayList.add(num);
+ listMap.put(numCount+"_"+sensorMap.get(sensor),doubleArrayList);
+ }
+ }
+ timeValueMap.put(sensorMap.get(sensor),num);
+ }
+ resultList.add(timeValueMap);
+ ks = DateUtils.getDateOfDay(ks,1);
+ }
+ timeValueMap = new LinkedHashMap<>();
+ timeValueMap.put("������������",nameSite);
+ timeValueMap.put("name",name);
+ timeValueMap.put("������","���������");
+ for(int z = 0 ;z< sensorsList.size();z++){
+ double rsAvg = 0L;
+ String son = numCount+"_"+sensorMap.get(sensorsList.get(z));
+ if(listMap.containsKey(numCount+"_"+sensorMap.get(sensorsList.get(z)))){
+ if(son.contains("������")){
+ rsAvg = percentile(listMap.get(numCount+"_"+sensorMap.get(sensorsList.get(z))),90d);
+ }else if(son.contains("������������")){
+ rsAvg = percentile(listMap.get(numCount+"_"+sensorMap.get(sensorsList.get(z))),95d);
+ }else {
+ Double ListAvg = listMap.get(numCount+"_"+sensorMap.get(sensorsList.get(z))).stream().collect(Collectors.averagingDouble(Double::doubleValue));
+ rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
+ }
+ }
+ timeValueMap.put(sensorMap.get(sensorsList.get(z)),rsAvg);
+ }
+ resultList.add(timeValueMap);
+ numCount++;
+ }
+
+ }else {
+ QueryWrapper<HistoryMonthly> HistoryMonthlyWrapper = new QueryWrapper<>();
+ HistoryMonthlyWrapper.in("mac",devices.stream().map(Device::getMac).collect(Collectors.toList()));
+ HistoryMonthlyWrapper.between("time",startTime,endTime);
+ List<HistoryMonthly> historyMonthlyList = historyMonthlyMapper.selectList(HistoryMonthlyWrapper);
+ Map<String,Map<String,Object>> map = resultMap(new ArrayList<>(),historyMonthlyList);
+ Map<Integer,String> pointMap = pointMap(devices);
+ Map<String,String> sensorMap = sensorMap(sensorsList);
+ for (Device device:devices) {
+ Date ks = DateUtils.getDate(startTime,"yyyy-MM");
+ Date js = DateUtils.addMonths(DateUtils.getDate(endTime,"yyyy-MM"),1);
+ while (DateUtils.isTimeBefor(js,ks)){
+ Map<String, Object> timeValueMap = new LinkedHashMap<>();//key���time���value������������json
+ timeValueMap.put("������������",pointMap.get(device.getMonitorPointId()));
+ timeValueMap.put("name",device.getName());
+ String c = DateUtils.dateToDateString(ks,"yyyy-MM");
+ timeValueMap.put("������",c);
+ for (String sensor:sensorsList) {
+ String k = c+"_"+device.getMac();
+ Double num = 0d;
+ if(map.containsKey(k)){
+ Object o = map.get(k).get(sensor);
+ num = Objects.nonNull(o)?Double.valueOf(o.toString()):0d;
+ }
+ timeValueMap.put(sensorMap.get(sensor),num);
+ }
+ resultList.add(timeValueMap);
+ ks = DateUtils.addMonths(ks,1);
+ }
+ /*for (String sensor:sensorsList) {
+ Date ks = DateUtils.getDate(startTime,"yyyy-MM");
+ Date js = DateUtils.addMonths(DateUtils.getDate(endTime,"yyyy-MM"),1);
+ Map<String, Object> timeValueMap = new LinkedHashMap<>();//key���time���value������������json
+ timeValueMap.put("������������",pointMap.get(device.getMonitorPointId()));
+ timeValueMap.put("name",device.getName());
+ timeValueMap.put("sensor",sensorMap.get(sensor));
+ while (DateUtils.isTimeBefor(js,ks)){
+ String c = DateUtils.dateToDateString(ks,"yyyy-MM");
+ String k = c+"_"+device.getMac();
+ if(map.containsKey(k)){
+ Object o = map.get(k).get(sensor);
+ timeValueMap.put(c,Objects.nonNull(o)?Double.valueOf(o.toString()):0);
+ }else {
+ timeValueMap.put(c,0);
+ }
+ ks = DateUtils.addMonths(ks,1);
+ }
+ resultList.add(timeValueMap);
+ }*/
+ }
+ }
+ return resultList;
+ }
+
+
+ private Map<String,Map<String,Object>> resultMap(List<HistoryDaily> list ,List<HistoryMonthly> historyMonthlyList){
Map<String,Map<String,Object>> map = new HashMap<>();
for(HistoryDaily h : list){
String dateStr = DateUtils.dateToDateString( h.getTime(), "yyyy-MM-dd")+"_"+h.getMac();
@@ -339,8 +493,57 @@
jsonMap = jsonObject.getInnerMap();
map.put(dateStr,jsonMap);
}
+ for(HistoryMonthly h : historyMonthlyList){
+ String dateStr = DateUtils.dateToDateString( h.getTime(), "yyyy-MM")+"_"+h.getMac();
+ Map<String,Object> jsonMap = new HashMap<>();
+ JSONObject jsonObject = JSONObject.parseObject(h.getValue());
+ jsonMap = jsonObject.getInnerMap();
+ map.put(dateStr,jsonMap);
+ }
+
return map;
}
+ private Map<String,Map<String,Object>> resultMap(List<HistoryHourly> list){
+ Map<String,Map<String,Object>> map = new HashMap<>();
+ for(HistoryHourly h : list){
+ String dateStr = DateUtils.dateToDateString( h.getTime(), DateUtils.yyyy_MM_dd_HH_EN)+"_"+h.getMac();
+ Map<String,Object> jsonMap = new HashMap<>();
+ JSONObject jsonObject = JSONObject.parseObject(h.getValue());
+ jsonMap = jsonObject.getInnerMap();
+ map.put(dateStr,jsonMap);
+ }
+
+ return map;
+ }
+ private Map<String,String> sensorMap(List<String> sensorsList){
+ Map<String,String> map = new HashMap<>();
+ QueryWrapper<Sensor> sensorQueryWrapper = new QueryWrapper<>();
+ sensorQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
+ sensorQueryWrapper.in("code",sensorsList);
+ sensorMapper.selectList(sensorQueryWrapper).forEach(it->map.put(it.getCode(),it.getName()));
+ return map;
+ }
+
+ private Map<Integer,String> pointMap(List<Device> devices){
+ Map<Integer,String> map = new HashMap<>();
+ QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>();
+ monitorPointQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
+ monitorPointQueryWrapper.in("id",devices.stream().map(Device::getMonitorPointId).collect(Collectors.toList()));
+ monitorPointMapper.selectList(monitorPointQueryWrapper).forEach(it->map.put(it.getId(),it.getName()));
+ return map;
+ }
+ private Double percentile(List<Double> date,double num){
+ Collections.sort(date);
+ double position = (num / 100) * (date.size() - 1);
+ int index = (int) position;
+ // ���������������������������������
+ double fraction = position - index;
+
+ // ������������������
+ double percentileValue = date.get(index) + fraction * (date.get(index + 1) - date.get(index));
+ return new BigDecimal(percentileValue).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
+ }
+
}
--
Gitblit v1.8.0