From fdef922f0f8adea77cfaee8194033b2947575fd2 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Mon, 16 Oct 2023 09:32:43 +0800
Subject: [PATCH] Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into wb

---
 screen-job/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java |   53 ++++++++++++++++++++++++-----------------------------
 1 files changed, 24 insertions(+), 29 deletions(-)

diff --git a/screen-job/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java b/screen-job/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
index 5409221..bc817e4 100644
--- a/screen-job/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
+++ b/screen-job/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
@@ -3,7 +3,6 @@
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.moral.api.entity.HistoryDaily;
-import com.moral.api.entity.HistoryHourly;
 import com.moral.api.entity.Sensor;
 import com.moral.api.mapper.HistoryDailyMapper;
 import com.moral.api.service.HistoryDailyService;
@@ -18,7 +17,9 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
 
+import javax.xml.crypto.Data;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -50,9 +51,14 @@
 
     @Override
     @Transactional
-    public void insertHistoryDaily() {
+    public void insertHistoryDaily(String time) {
         String format = DateUtils.yyyy_MM_dd_EN;
-        Date now = new Date();
+        Date now;
+        if(StringUtils.isEmpty(time)){
+            now = new Date();
+        } else {
+            now = DateUtils.getDate(time,"yyyy-MM-dd");
+        }
         //���������������������
         Date start = DateUtils.dataToTimeStampTime(DateUtils.getDateOfDay(now, -1), format);
         //���������������������
@@ -61,12 +67,16 @@
         QueryWrapper<Sensor> sensorQueryWrapper = new QueryWrapper<>();
         sensorQueryWrapper.select("code", "lower", "upper").eq("is_delete", Constants.NOT_DELETE);
         List<Sensor> sensors = sensorService.list(sensorQueryWrapper);
-
         //������������������������������
-        QueryWrapper<HistoryHourly> historyHourlyQueryWrapper = new QueryWrapper<>();
-        historyHourlyQueryWrapper.ge("time", DateUtils.dateToDateString(start)).le("time", DateUtils.dateToDateString(end));
-        List<Map<String, Object>> dailyData = historyHourlyService.listMaps(historyHourlyQueryWrapper);
+        Map<String, Object> prop = new HashMap<>();
+        String timeUnits = DateUtils.dateToDateString(start, DateUtils.yyyyMM_EN);
+        prop.put("timeUnits", timeUnits);
+        prop.put("start", DateUtils.dateToDateString(start));
+        prop.put("end", DateUtils.dateToDateString(end));
+        List<Map<String, Object>> dailyData = historyHourlyService.selectDailyData(prop);
+
         if (dailyData.size() == 0) {
+            System.out.println("������������������"+DateUtils.dateToDateString(start));
             return;
         }
 
@@ -76,17 +86,11 @@
         //���������������������������
         List<Map<String, Object>> insertData = new ArrayList<>();
 
-        data.forEach((key, value) -> {
+        data.forEach((mac, value) -> {
             Map<String, Object> dataMap = new HashMap<>();
             Map<String, Object> jsonMap = new HashMap<>();
-            dataMap.put("mac", key);
+            dataMap.put("mac", mac);
             dataMap.put("time", start);
-
-            //���������������������������������������������������
-            List<Map<String, Object>> tempValue = new ArrayList<>(value);
-
-            //������������������������0������������O3������������������������������1���-8���
-            value.removeIf(map -> ((Date) map.get("time")).getTime() == start.getTime());
 
             Map<String, Object> params = new HashMap<>();
             params.put("data", value);
@@ -129,12 +133,8 @@
             if (!ObjectUtils.isEmpty(o3AvgOfDay)) {
                 jsonMap.putAll(o3AvgOfDay);
             }
-            //������������������������������������
-            tempValue.removeIf(o -> ((Date) o.get("time")).getTime() == end.getTime());
 
             //���������������������������
-            params.put("data", tempValue);
-
             Map<String, Object> windDirAvg = AmendUtils.getWindDirAvg(params);
             if (!ObjectUtils.isEmpty(windDirAvg)) {
                 jsonMap.putAll(windDirAvg);
@@ -144,18 +144,17 @@
                 String sensorCode = sensor.getCode();
                 Double upper = sensor.getUpper();
                 Double lower = sensor.getLower();
-                OptionalDouble optionalDouble = tempValue.parallelStream()
+                OptionalDouble optionalDouble = value.parallelStream()
                         .flatMapToDouble(v -> {
                             Map<String, Object> dataValue = JSONObject.parseObject((String) v.get("value"), Map.class);
                             Object sensorValue = dataValue.get(sensorCode);
                             //������������������������
-                            Object flag = dataValue.get(sensorCode + Constants.MARKER_BIT_KEY);
+                            Object flag = dataValue.get(sensorCode + "-" + Constants.MARKER_BIT_KEY);
                             if (!Constants.MARKER_BIT_TRUE.equals(flag)) {
                                 return null;
                             }
 
                             if (ObjectUtils.isEmpty(sensorValue)) {
-                                System.out.println(456);
                                 return null;
                             }
 
@@ -167,19 +166,15 @@
                             //������������������������������������
                             double aDouble = Double.parseDouble(sensorValue.toString());
                             if (!ObjectUtils.isEmpty(upper)) {
-                                if (aDouble < upper) {
+                                if (aDouble > upper) {
                                     return null;
                                 }
                             }
                             if (!ObjectUtils.isEmpty(lower)) {
-                                if (aDouble > lower) {
+                                if (aDouble < lower) {
                                     return null;
                                 }
                             }
-                            if ("a00e12".equals(sensorCode)) {
-                                System.out.println(key + "==" + sensorCode + "==" + v.get("time") + "==" + aDouble);
-                            }
-
                             return DoubleStream.of(aDouble);
                         }).average();
                 if (optionalDouble.isPresent()) {
@@ -191,8 +186,8 @@
             dataMap.put("value", JSONObject.toJSONString(jsonMap));
             insertData.add(dataMap);
         });
-
         //���������������
         historyDailyMapper.insertHistoryDaily(insertData);
+        System.out.println("������������");
     }
 }

--
Gitblit v1.8.0