huangws 10 месяцев назад
Родитель
Сommit
f172d2695b

+ 19 - 0
GetDataByView/.mvn/wrapper/maven-wrapper.properties

@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+wrapperVersion=3.3.2
+distributionType=only-script
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

+ 9 - 1
GetDataByView/pom.xml

@@ -49,7 +49,15 @@
             <artifactId>lombok</artifactId>
             <scope>provided</scope>
         </dependency>
-<!--        <dependency>-->
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+        <!--        <dependency>-->
 <!--            <groupId>org.springframework.boot</groupId>-->
 <!--            <artifactId>spring-boot-starter-log4j2</artifactId>-->
 <!--        </dependency>-->

+ 2 - 0
GetDataByView/src/main/java/com/jyxt/getdatabyview/GetDataByViewApplication.java

@@ -49,6 +49,8 @@ public class GetDataByViewApplication implements CommandLineRunner{
             if(wsdEntityList != null){
                 handleData.startHandleData(wsdEntityList);
             }
+            //查询当日需要监测的待处理数据
+            handleData.updateUndoData();
         } else if(run_mode.equals("0")){
             log.info("run_mode=0,qry uncontrol judge");
             handleData.unControlJudge();

+ 139 - 0
GetDataByView/src/main/java/com/jyxt/getdatabyview/HandleData.java

@@ -1,6 +1,10 @@
 package com.jyxt.getdatabyview;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.jyxt.getdatabyview.view.IBPSRepository;
+import com.jyxt.getdatabyview.view.entity.CollectorEntity;
+import com.jyxt.getdatabyview.view.entity.MonitoredEntity;
 import com.jyxt.getdatabyview.view.entity.WSDEntity;
 import com.jyxt.getdatabyview.view.repository.LISViewRepository;
 import com.jyxt.getdatabyview.view.repository.QualityIndicatorRepository;
@@ -8,18 +12,37 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.RowMapper;
 import org.springframework.stereotype.Component;
 
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 @Component
 public class HandleData {
     private static final Logger log = LoggerFactory.getLogger(GetDataByViewApplication.class);
 
+    private static final ObjectMapper mapper = new ObjectMapper();
+
     @Autowired
     private IBPSRepository ibpsRepository;
 
+    @Value("${config.testmode}")
+    private String testmode;
+
+    @Value("${config.fridge.monitor}")
+    private String fridgeMonitor;
+
+    @Value("${config.device.monitor}")
+    private String deviceMonitor;
 
+    @Value("${config.cabinet.monitor}")
+    private String cabinetMonitor;
+
+    @Value("${config.waterbath.monitor}")
+    private String waterbathMonitor;
 
     private static final String RESULT_DELIMITER = "\\^";
 
@@ -39,4 +62,120 @@ public class HandleData {
     public void unControlJudge(){
 
     }
+
+    /**
+     * 20250619 huangws
+     * 查询当日状态为待处理的温湿度记录数据并填入结果
+     * @throws JsonProcessingException
+     */
+    public void updateUndoData() throws JsonProcessingException {
+        log.info("check daliy undo device...");
+        LocalDate today = LocalDate.now();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        String formattedDate = today.format(formatter);
+        if(fridgeMonitor.equals("1")){
+            List<MonitoredEntity> undoFridgeList = ibpsRepository.getUndoFridgeList(formattedDate);
+            log.info("get undo fridge list size:" + undoFridgeList.size());
+            if(undoFridgeList.size() > 0){
+                for (MonitoredEntity fridge : undoFridgeList) {
+                    String DeviceNo = fridge.getDeviceNo().split(" ")[0];
+                    List<WSDEntity> wsdEntityList = ibpsRepository.getWSDEntityList(formattedDate, "fridgeMonitor", DeviceNo);
+                    log.info("get "+DeviceNo+" size:" + wsdEntityList.size());
+                    if(wsdEntityList.size() > 0){
+                        String undoFridgeID = fridge.getId();
+                        String JsonStr = fridge.getJsonStr();
+                        String retString = handJsonStr(JsonStr,wsdEntityList,fridgeMonitor);
+                        String hasFinished = retString.split("@")[0];
+                        String newJsonStr = retString.split("@")[1];
+                        ibpsRepository.saveMonitoredData(undoFridgeID, hasFinished, newJsonStr);
+                    }
+                }
+            }
+        }
+
+    }
+
+    /**
+     * 20250619 huangws
+     * 处理json串,将获得的实际结果填入json串再返回
+     * @param JsonStr
+     * @param wsdEntityList
+     * @param Type
+     * @return
+     * @throws JsonProcessingException
+     */
+    public String handJsonStr(String JsonStr, List<WSDEntity> wsdEntityList, String Type) throws JsonProcessingException {
+        String retVal = JsonStr;
+        log.info("org json string:"+JsonStr);
+        String hasFinished = "1";
+        // 字符串转List<Map>
+        List<Map<String, String>> jsonList = mapper.readValue(JsonStr, List.class);
+        for(Map<String, String> jsonMap : jsonList){
+            String hasLable = "0";
+            String curResult = null;
+            Date curCollectTime = null;
+            String curFlag = null;
+            String label = jsonMap.get("label");
+            if(label.contains("冷藏")) {
+                for (WSDEntity wsdEntity : wsdEntityList) {
+                    if (wsdEntity.getNote().equals("冷藏")) {
+                        if((jsonMap.get("result") != null) && (jsonMap.get("result") != "")){
+                            hasLable = "2";
+                            break;
+                        }
+                        hasLable = "1";
+                        curResult = wsdEntity.getResult();
+                        curCollectTime = wsdEntity.getCollectTime();
+                        curFlag = wsdEntity.getControlFlag();
+                        break;
+                    }
+                }
+            }
+            if(label.contains("冷冻")) {
+                for (WSDEntity wsdEntity : wsdEntityList) {
+                    if (wsdEntity.getNote().equals("冷冻")) {
+                        if((jsonMap.get("result") != null) && (jsonMap.get("result") != "")){
+                            hasLable = "2";
+                            break;
+                        }
+                        hasLable = "1";
+                        curResult = wsdEntity.getResult();
+                        curCollectTime = wsdEntity.getCollectTime();
+                        curFlag = wsdEntity.getControlFlag();
+                        break;
+                    }
+                }
+            }
+            if(label.contains("湿度")) {
+                for (WSDEntity wsdEntity : wsdEntityList) {
+                    if (wsdEntity.getNote().equals("湿度")) {
+                        if((jsonMap.get("result") != null) && (jsonMap.get("result") != "")){
+                            hasLable = "2";
+                            break;
+                        }
+                        hasLable = "1";
+                        curResult = wsdEntity.getResult();
+                        curCollectTime = wsdEntity.getCollectTime();
+                        curFlag = wsdEntity.getControlFlag();
+                        break;
+                    }
+                }
+            }
+            if(hasLable.equals("1")) {
+                String fixValue = jsonMap.get("fixValue");
+                if ((fixValue == null) || (fixValue == "")) {
+                    fixValue = "0";
+                }
+                jsonMap.put("value", curResult);
+                jsonMap.put("result", String.valueOf(Float.parseFloat(fixValue) + Float.parseFloat(curResult)));
+                jsonMap.put("status", curFlag);
+            } else if (hasLable.equals("0")){
+                hasFinished = "0";
+            }
+        }
+        JsonStr = mapper.writeValueAsString(jsonList);
+        log.info("new json string:"+JsonStr);
+        return hasFinished+"@"+JsonStr;
+    }
+
 }

+ 186 - 73
GetDataByView/src/main/java/com/jyxt/getdatabyview/view/HuaTuRepository.java

@@ -31,27 +31,43 @@ public class HuaTuRepository {
     @Value("${fetch.condition}")
     private String condition;
 
+    @Value("${config.testmode}")
+    private String testmode;
+
+    @Autowired
+    private IBPSRepository ibpsRepository;
 
     public List<WSDEntity> query(List<String> existIDList) throws ParseException {
+        List<CollectorEntity> collectorList = ibpsRepository.getCollectorlist();
+        StringBuilder colIDList = new StringBuilder();
+        for (CollectorEntity collector : collectorList) {
+            if(colIDList.length() > 0) {
+                colIDList.append(",'").append(collector.getCollectID()).append("'");
+            } else {
+                colIDList.append("'").append(collector.getCollectID()).append("'");
+            }
+        }
+        String colIDListString = colIDList.toString();
         /**
          * 正式启用开启这一段
+         * * */
          String sqlStr ="select LOGGER_SN as LOGSN,GROUP_ID,LOGGER_NAME as LOGNAME,LOGGER_CHNUM as CHNUM,"+
                         "CHONE_TYPE as TYPE1,CHONE_HIGH as HIGH1,CHONE_LOW as LOW1,CHONE_DOT as DOT1,"+
                         "CHTWO_TYPE as TYPE2,CHTWO_HIGH as HIGH2,CHTWO_LOW as LOW2,CHTWO_DOT as DOT2,"+
                         "CHTHR_TYPE as TYPE3,CHTHR_HIGH as HIGH3,CHTHR_LOW as LOW3,CHTHR_DOT as DOT3,"+
                         "CHFOU_TYPE as TYPE4,CHFOU_HIGH as HIGH4,CHFOU_LOW as LOW4,CHFOU_DOT as DOT4 "+
-                        "from TO_LOGGER_INFO where LOGGER_STATE='1'"
+                        "from TO_LOGGER_INFO where LOGGER_STATE='1' and LOGGER_SN in ("+colIDListString+")";
 
-        * */
-        String sql = "select * from TO_LOGGER_INFO";
-        log.info("excute sql:" + sql);
+        /**
+         * 测试调试开启这一段
+         *
+        String sqlStr = "select * from TO_LOGGER_INFO where LOGSN in ("+colIDListString+")";
+         * */
+        log.info("excute sql:" + sqlStr);
         RowMapper<ToLoggerInfo> infoRowMapper = new BeanPropertyRowMapper<>(ToLoggerInfo.class);
         RowMapper<EquipResult> humitureRowMapper = new BeanPropertyRowMapper<>(EquipResult.class);
-        RowMapper<CollectorEntity> collectorRowMapper = new BeanPropertyRowMapper<>(CollectorEntity.class);
-        String collectorSql = "select id_,DeviceID,DeviceNo,DeviceName,DeviceType,CollectID,CollectName from equip_relation where enable='1'";
-        List<CollectorEntity> collectorList = jdbcTemplate.query(collectorSql, collectorRowMapper);
-        List<ToLoggerInfo> equipList = jdbcTemplate.query(sql, infoRowMapper);
-        Set<WSDEntity> wsdSet = new LinkedHashSet<>();
+        List<ToLoggerInfo> equipList = jdbcTemplate.query(sqlStr, infoRowMapper);
+        List<WSDEntity> wsdlist = new LinkedList<>();
 
 
         SimpleDateFormat saveToIDFormat = new SimpleDateFormat("yyyyMMddHHmm");
@@ -67,15 +83,23 @@ public class HuaTuRepository {
             String equipSn = toLoggerInfo.getLOGSN();
             /**
              * 正式启用开启这一段
+             * **/
              String subSql = "SELECT * FROM LOGS_"+equipSn+" WHERE "+condition + " order by LOGS_TIME";
+            /**
+             * 测试调试开启这一段
+             *String subSql = "SELECT * FROM LOGS_" + equipSn + " WHERE DATE(LOGS_TIME) = CURDATE() ORDER BY LOGS_TIME";
              **/
-            String subSql = "SELECT * FROM LOGS_" + equipSn + " WHERE DATE(LOGS_TIME) = CURDATE()-5 ORDER BY LOGS_TIME";
             log.info("Execute SQL: " + subSql);
             /**
              * 正式启用开启这一段
-             String sqlQry = "SELECT COUNT(*) as result FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'huatu' AND TABLE_NAME = 'LOGS_"+ equipSn +"'";
-             **/
-            String sqlQry = "SELECT COUNT(*) as result FROM information_schema.tables WHERE table_schema = 'klims-ibps3' AND table_name = 'LOGS_"+ equipSn +"'";
+             *  **/
+             String sqlQry = "SELECT COUNT(*) as result FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'sql' AND TABLE_NAME = 'LOGS_"+ equipSn +"'";
+
+            /**
+             * 测试调试开启这一段
+             *
+             * String sqlQry = "SELECT COUNT(*) as result FROM information_schema.tables WHERE table_schema = 'klims-ibps3' AND table_name = 'LOGS_"+ equipSn +"'";
+             */
             List<String> hastable = jdbcTemplate.queryForList(sqlQry, String.class);
 //            log.info("hastable: " + hastable.get(0));
             if (Objects.equals(hastable.get(0), "1")) {
@@ -88,86 +112,160 @@ public class HuaTuRepository {
                         log.warn("时间格式化异常{},设备编号:{}",equipResult.getLogsTime(),equipSn);
                         e.printStackTrace();
                     }
-                    WSDEntity wsdEntity = new WSDEntity();
-                    wsdEntity.setId(equipSn+"-"+saveToIDFormat.format(equipResult.getLogsTime()));
-                    wsdEntity.setCollectID(equipSn);
-                    wsdEntity.setCollectName(toLoggerInfo.getLOGNAME());
-                    wsdEntity.setCollectTime(equipResult.getLogsTime());
-                    wsdEntity.setCreateTime(currentDate);
-                    List<CollectorEntity> currentCollectorList = getDeviceInfo(equipSn, collectorList);
-                    if(!currentCollectorList.isEmpty()){
-                        for (CollectorEntity collectorEntity : currentCollectorList) {
-                            wsdEntity.setDeviceID(collectorEntity.getDeviceID());
-                            wsdEntity.setDeviceNo(collectorEntity.getDeviceNo());
-                            wsdEntity.setDeviceName(collectorEntity.getDeviceName());
-                            wsdEntity.setDeviceID(collectorEntity.getDeviceID());
-                        }
-                    }
+
                     if (toLoggerInfo.getCHNUM()==1){
+                        WSDEntity wsdEntity = new WSDEntity();
+                        List<CollectorEntity> currentCollectorList = getDeviceInfo(equipSn, collectorList);
+                        if(!currentCollectorList.isEmpty()){
+                            for (CollectorEntity collectorEntity : currentCollectorList) {
+                                wsdEntity.setDeviceNo(collectorEntity.getDeviceNo());
+                                wsdEntity.setDeviceName(collectorEntity.getDeviceName());
+                            }
+                        }
+                        wsdEntity.setId(equipSn+"-"+saveToIDFormat.format(equipResult.getLogsTime()));
+                        wsdEntity.setCollectID(equipSn);
+                        wsdEntity.setCollectName(toLoggerInfo.getLOGNAME());
+                        wsdEntity.setCollectTime(equipResult.getLogsTime());
+                        wsdEntity.setCreateTime(currentDate);
+                        wsdEntity.setShiYanZu(equipSn);
                         Integer type1 = toLoggerInfo.getTYPE1();
                         //0 温度 1 湿度
                         if (type1==0){
-                            wsdEntity.setType("温度计");
-                            wsdEntity.setTemperature(equipResult.getLogsChone());
-                            wsdEntity.setTemperatureHigh(String.valueOf(toLoggerInfo.getHIGH1()));
-                            wsdEntity.setTemperatureLow(String.valueOf(toLoggerInfo.getLOW1()));
+                            wsdEntity.setType("温度");
+                            if(toLoggerInfo.getLOW1()>0){
+                                wsdEntity.setNote("冷藏");
+                            }
+                            if(toLoggerInfo.getHIGH1()<0){
+                                wsdEntity.setNote("冷冻");
+                            }
                         }
                         if (type1==1){
-                            wsdEntity.setType("湿度计");
-                            wsdEntity.setHumidity(equipResult.getLogsChone());
-                            wsdEntity.setHumidityHigh(String.valueOf(toLoggerInfo.getHIGH1()));
-                            wsdEntity.setHumidityLow(String.valueOf(toLoggerInfo.getLOW1()));
+                            wsdEntity.setType("湿度");
+                            wsdEntity.setNote("湿度");
                         }
-                    } else if (toLoggerInfo.getCHNUM()==2){
-                        Integer type1 = toLoggerInfo.getTYPE1();
-                        //0 温度 1 湿度
-                        if (type1==0){
-//                            wsdEntity.setType("温度计");
-                            wsdEntity.setTemperature(equipResult.getLogsChone());
-                            wsdEntity.setTemperatureHigh(String.valueOf(toLoggerInfo.getHIGH1()));
-                            wsdEntity.setTemperatureLow(String.valueOf(toLoggerInfo.getLOW1()));
+                        wsdEntity.setResult(equipResult.getLogsChone());
+                        wsdEntity.setResultHigh(String.valueOf(toLoggerInfo.getHIGH1()));
+                        wsdEntity.setResultLow(String.valueOf(toLoggerInfo.getLOW1()));
+                        wsdEntity.setControlFlag(isLoseControl(wsdEntity.getResult(), wsdEntity.getResultHigh(), wsdEntity.getResultLow()));
+                        if((!existIDList.contains(wsdEntity.getId()))&&(!testmode.equals("2"))){
+                            wsdlist.add(wsdEntity);
                         }
-                        if (type1==1){
-//                            wsdEntity.setType("湿度计");
-                            wsdEntity.setHumidity(equipResult.getLogsChone());
-                            wsdEntity.setHumidityHigh(String.valueOf(toLoggerInfo.getHIGH1()));
-                            wsdEntity.setHumidityLow(String.valueOf(toLoggerInfo.getLOW1()));
+                        if(testmode.equals("2")){
+                            wsdlist.add(wsdEntity);
                         }
-                        Integer type2 = toLoggerInfo.getTYPE2();
-                        //0 温度 1 湿度
-                        if (type2==0){
-                            if (type1==0){
-                                wsdEntity.setType("温度计");
-                            } else if (type1==1){
-                                wsdEntity.setType("温湿度计");
+                    } else {
+                        for (int i = 1; i<=toLoggerInfo.getCHNUM(); i++){
+                            WSDEntity wsdEntity = new WSDEntity();
+                            List<CollectorEntity> currentCollectorList = getDeviceInfo(equipSn, collectorList);
+                            if(!currentCollectorList.isEmpty()){
+                                for (CollectorEntity collectorEntity : currentCollectorList) {
+                                    wsdEntity.setDeviceNo(collectorEntity.getDeviceNo());
+                                    wsdEntity.setDeviceName(collectorEntity.getDeviceName());
+                                }
                             }
-                            wsdEntity.setTemperature(equipResult.getLogsChtwo());
-                            wsdEntity.setTemperatureHigh(String.valueOf(toLoggerInfo.getHIGH2()));
-                            wsdEntity.setTemperatureLow(String.valueOf(toLoggerInfo.getLOW2()));
-                        }
-                        if (type2==1){
-                            if (type1==0){
-                                wsdEntity.setType("温湿度计");
-                            } else if (type1==1){
-                                wsdEntity.setType("湿度计");
+                            wsdEntity.setId(equipSn+"-"+i+"-"+saveToIDFormat.format(equipResult.getLogsTime()));
+                            wsdEntity.setCollectID(equipSn);
+                            wsdEntity.setCollectName(toLoggerInfo.getLOGNAME());
+                            wsdEntity.setCollectTime(equipResult.getLogsTime());
+                            wsdEntity.setCreateTime(currentDate);
+                            wsdEntity.setShiYanZu(equipSn+"-"+i);
+                            if(i==1){
+                                Integer type1 = toLoggerInfo.getTYPE1();
+                                //0 温度 1 湿度
+                                if (type1==0){
+                                    wsdEntity.setType("温度");
+                                    if(toLoggerInfo.getLOW1()>0){
+                                        wsdEntity.setNote("冷藏");
+                                    }
+                                    if(toLoggerInfo.getHIGH1()<0){
+                                        wsdEntity.setNote("冷冻");
+                                    }
+                                }
+                                if (type1==1){
+                                    wsdEntity.setType("湿度");
+                                    wsdEntity.setNote("湿度");
+                                }
+                                wsdEntity.setResult(equipResult.getLogsChone());
+                                wsdEntity.setResultHigh(String.valueOf(toLoggerInfo.getHIGH1()));
+                                wsdEntity.setResultLow(String.valueOf(toLoggerInfo.getLOW1()));
+                            }
+                            if(i==2){
+                                Integer type2 = toLoggerInfo.getTYPE2();
+                                //0 温度 1 湿度
+                                if (type2==0){
+                                    wsdEntity.setType("温度");
+                                    if(toLoggerInfo.getLOW2()>0){
+                                        wsdEntity.setNote("冷藏");
+                                    }
+                                    if(toLoggerInfo.getHIGH2()<0){
+                                        wsdEntity.setNote("冷冻");
+                                    }
+                                }
+                                if (type2==1){
+                                    wsdEntity.setType("湿度");
+                                    wsdEntity.setNote("湿度");
+                                }
+                                wsdEntity.setResult(equipResult.getLogsChtwo());
+                                wsdEntity.setResultHigh(String.valueOf(toLoggerInfo.getHIGH2()));
+                                wsdEntity.setResultLow(String.valueOf(toLoggerInfo.getLOW2()));
+                            }
+                            if(i==3){
+                                Integer type3 = toLoggerInfo.getTYPE3();
+                                //0 温度 1 湿度
+                                if (type3==0){
+                                    wsdEntity.setType("温度");
+                                    if(toLoggerInfo.getLOW3()>0){
+                                        wsdEntity.setNote("冷藏");
+                                    }
+                                    if(toLoggerInfo.getHIGH3()<0){
+                                        wsdEntity.setNote("冷冻");
+                                    }
+                                }
+                                if (type3==1){
+                                    wsdEntity.setType("湿度");
+                                    wsdEntity.setNote("湿度");
+                                }
+                                wsdEntity.setResult(equipResult.getLogsChthr());
+                                wsdEntity.setResultHigh(String.valueOf(toLoggerInfo.getHIGH3()));
+                                wsdEntity.setResultLow(String.valueOf(toLoggerInfo.getLOW3()));
+                            }
+                            if(i==4){
+                                Integer type4 = toLoggerInfo.getTYPE4();
+                                //0 温度 1 湿度
+                                if (type4==0){
+                                    wsdEntity.setType("温度");
+                                    if(toLoggerInfo.getLOW4()>0){
+                                        wsdEntity.setNote("冷藏");
+                                    }
+                                    if(toLoggerInfo.getHIGH4()<0){
+                                        wsdEntity.setNote("冷冻");
+                                    }
+                                }
+                                if (type4==1){
+                                    wsdEntity.setType("湿度");
+                                    wsdEntity.setNote("湿度");
+                                }
+                                wsdEntity.setResult(equipResult.getLogsChfou());
+                                wsdEntity.setResultHigh(String.valueOf(toLoggerInfo.getHIGH4()));
+                                wsdEntity.setResultLow(String.valueOf(toLoggerInfo.getLOW4()));
+                            }
+                            wsdEntity.setControlFlag(isLoseControl(wsdEntity.getResult(), wsdEntity.getResultHigh(), wsdEntity.getResultLow()));
+                            if((!existIDList.contains(wsdEntity.getId()))&&(!testmode.equals("2"))){
+                                wsdlist.add(wsdEntity);
+                            }
+                            if(testmode.equals("2")){
+                                wsdlist.add(wsdEntity);
                             }
-                            wsdEntity.setHumidity(equipResult.getLogsChtwo());
-                            wsdEntity.setHumidityHigh(String.valueOf(toLoggerInfo.getHIGH2()));
-                            wsdEntity.setHumidityLow(String.valueOf(toLoggerInfo.getLOW2()));
                         }
-                    }else if (toLoggerInfo.getCHNUM()==3){
-                        //暂时没发现有
                     }
-                    wsdSet.add(wsdEntity);
                 }
             }else{
                 log.info("table:LOGS_"+equipSn+" not exist!");
             }
         }
-        return new ArrayList<>(wsdSet);
+        return new LinkedList<>(wsdlist);
     }
 
-
     public List<CollectorEntity> getDeviceInfo(String CollectID, List<CollectorEntity> collectorList){
         List<CollectorEntity> retEntity = new ArrayList<>();
         for (CollectorEntity collectorEntity:collectorList){
@@ -178,5 +276,20 @@ public class HuaTuRepository {
         return retEntity;
     }
 
+    public String isLoseControl(String result, String resultHigh, String resultLow) {
+        String retVal = "失控";
+        try {
+            double res = Double.parseDouble(result);
+            double high = Double.parseDouble(resultHigh);
+            double low = Double.parseDouble(resultLow);
+            if (res > low && res < high) {
+                retVal = "正常";
+            }
+        } catch (NumberFormatException e) {
+            // 如果字符串无法转换为数字,保持默认返回值1
+        }
+        return retVal;
+    }
+
 
 }

+ 121 - 29
GetDataByView/src/main/java/com/jyxt/getdatabyview/view/IBPSRepository.java

@@ -1,69 +1,161 @@
 package com.jyxt.getdatabyview.view;
 
+import com.jyxt.getdatabyview.view.entity.CollectorEntity;
+import com.jyxt.getdatabyview.view.entity.MonitoredEntity;
 import com.jyxt.getdatabyview.view.entity.WSDEntity;
+import com.jyxt.getdatabyview.view.repository.LISViewRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.PreparedStatementCreator;
+import org.springframework.jdbc.core.RowMapper;
 import org.springframework.stereotype.Repository;
 
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
+import java.sql.*;
 import java.util.ArrayList;
 import java.util.List;
-import java.sql.Date;
 
 @Repository
 public class IBPSRepository {
 
+    private static final Logger log = LoggerFactory.getLogger(LISViewRepository.class);
+
     @Autowired
     @Qualifier("secondJdbcTemplate")
     private JdbcTemplate jdbcTemplate;
 
+    @Value("${config.testmode}")
+    private String testmode;
+
+
     public List<String> getExistID(){
         List<String> existIDList = new ArrayList<String>();
         /**
          * 正式启用开启这一段
-         * String existSql = "select id from t_dsfwdjlb where Date(collectTime) = CURDATE()"
+         * String existSql = "select id from t_dsfwsdjlb where Date(collectTime) = CURDATE()"
          */
-        String existSql = "select id from t_dsfwdjlb where Date(collectTime) = CURDATE()-5";
+        String existSql = "select id from t_dsfwsdjlb where Date(collectTime) = CURDATE()";
         existIDList = jdbcTemplate.queryForList(existSql, String.class);
         return existIDList;
     }
 
+    public List<CollectorEntity> getCollectorlist(){
+        RowMapper<CollectorEntity> collectorRowMapper = new BeanPropertyRowMapper<>(CollectorEntity.class);
+        String collectorSql = "select deviceNo,deviceName,collectID,collectName,type from t_cjqsbglpz where enable='1'";
+        List<CollectorEntity> collectorList = jdbcTemplate.query(collectorSql, collectorRowMapper);
+        return collectorList;
+    }
 
     public void save(final WSDEntity wsdEntity){
         //sql语句
-        final String sql =  "insert into t_dsfwdjlb (id,createTime,collectTime,temperature,humidity,deviceID,deviceNo,deviceName,collectID, "+
-                            "collectName,temperatureHigh,temperatureLow,humidityHigh,humidityLow,shiYanZu,shiYanZuID,type,area,diDian,room)  "+
-                            " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)                                                                            ";
+        final String sql =  "insert into t_dsfwsdjlb (id,createTime,collectTime,result,resultHigh,resultLow,deviceNo,deviceName,collectID, "+
+                            "collectName,shiYanZu,note,type,area,diDian,room,controlFlag) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
+        if((testmode.equals("1")) || (testmode.equals("2"))){
+            log.info("pretend to insert: id:{},Res:{},ResH:{},ResL:{},DevName:{},ColID:{},ColName:{},ShiYanZu:{},Type:{},Flag:{}",
+                    wsdEntity.getId(),wsdEntity.getResult(),wsdEntity.getResultHigh(),wsdEntity.getResultLow(),wsdEntity.getDeviceName(),
+                    wsdEntity.getCollectID(),wsdEntity.getCollectName(),wsdEntity.getShiYanZu(),wsdEntity.getType(),wsdEntity.getControlFlag()
+            );
+        }
+        if(testmode.equals("0")){
+            log.info("ready to insert: id:{},Res:{},ResH:{},ResL:{},DevName:{},ColID:{},ColName:{},ShiYanZu:{},Type:{},Flag:{}",
+                    wsdEntity.getId(),wsdEntity.getResult(),wsdEntity.getResultHigh(),wsdEntity.getResultLow(),wsdEntity.getDeviceName(),
+                    wsdEntity.getCollectID(),wsdEntity.getCollectName(),wsdEntity.getShiYanZu(),wsdEntity.getType(),wsdEntity.getControlFlag()
+            );
+            jdbcTemplate.update(new PreparedStatementCreator() {
+                public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
+                    PreparedStatement prepareStatement = connection.prepareStatement(sql);
+                    prepareStatement.setString(1,wsdEntity.getId());
+                    prepareStatement.setTimestamp(2, new java.sql.Timestamp(wsdEntity.getCreateTime().getTime()));
+                    prepareStatement.setTimestamp(3, new java.sql.Timestamp(wsdEntity.getCollectTime().getTime()));
+                    prepareStatement.setString(4,wsdEntity.getResult());
+                    prepareStatement.setString(5,wsdEntity.getResultHigh());
+                    prepareStatement.setString(6,wsdEntity.getResultLow());
+                    prepareStatement.setString(7,wsdEntity.getDeviceNo());
+                    prepareStatement.setString(8,wsdEntity.getDeviceName());
+                    prepareStatement.setString(9,wsdEntity.getCollectID());
+                    prepareStatement.setString(10,wsdEntity.getCollectName());
+                    prepareStatement.setString(11,wsdEntity.getShiYanZu());
+                    prepareStatement.setString(12,wsdEntity.getNote());
+                    prepareStatement.setString(13,wsdEntity.getType());
+                    prepareStatement.setString(14,wsdEntity.getArea());
+                    prepareStatement.setString(15,wsdEntity.getDiDian());
+                    prepareStatement.setString(16,wsdEntity.getRoom());
+                    prepareStatement.setString(17,wsdEntity.getControlFlag());
+                    return prepareStatement;
+                }
+            });
+        }
+    }
+
+    public List<MonitoredEntity> getUndoFridgeList(String curdate) {
+        List<MonitoredEntity> undoFridgeList = jdbcTemplate.query(
+                "select * from t_bxwdjkjlb where date(create_time_)=? and shi_fou_guo_shen_='待处理'",
+                new RowMapper<MonitoredEntity>() {
+                    @Override
+                    public MonitoredEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
+                        MonitoredEntity entity = new MonitoredEntity();
+                        entity.setId(rs.getString("id_"));
+                        entity.setDeviceNo(rs.getString("bing_xiang_bian_h"));
+                        entity.setJsonStr(rs.getString("lie_biao_shu_ju_"));
+                        return entity;
+                    }
+                },
+                curdate  // 使用预编译参数防止SQL注入
+        );
+        return undoFridgeList;
+    }
+
+    public List<WSDEntity> getWSDEntityList(String CurDate, String Type,String DeviceNo) {
+        List<WSDEntity> wsdEntityList = jdbcTemplate.query(
+                "select id,collectTime,collectID,collectName,shiYanZu,result,deviceNo,type,note,controlFlag from t_dsfwsdjlb where date(collectTime)=? and deviceNo=? order by collectTime desc",
+                new RowMapper<WSDEntity>() {
+                    @Override
+                    public WSDEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
+                        WSDEntity entity = new WSDEntity();
+                        entity.setId(rs.getString("id"));
+                        entity.setCollectTime(rs.getTimestamp("collectTime"));
+                        entity.setCollectID(rs.getString("collectID"));
+                        entity.setCollectName(rs.getString("collectName"));
+                        entity.setShiYanZu(rs.getString("shiYanZu"));
+                        entity.setResult(rs.getString("result"));
+                        entity.setDeviceNo(rs.getString("deviceNo"));
+                        entity.setType(rs.getString("type"));
+                        entity.setNote(rs.getString("note"));
+                        entity.setControlFlag(rs.getString("controlFlag"));
+                        return entity;
+                    }
+                },
+                CurDate,DeviceNo  // 使用预编译参数防止SQL注入
+        );
+        return wsdEntityList;
+    }
+
+    /**
+     * 20250619 huangws
+     * 保存被监测设备的温湿度结果
+     * 如果还没未完成的不会改变是否过审的状态
+     * @param undoMonitorID
+     * @param hasFinished
+     * @param newJsonStr
+     */
+    public void saveMonitoredData(String undoMonitorID, String hasFinished, String newJsonStr){
+        final String sql = hasFinished.equals("1")
+                ? "update t_bxwdjkjlb set lie_biao_shu_ju_=?, update_time_=?, bei_zhu_='自动导入', shi_fou_guo_shen_='已完成' where id_=?"
+                : "update t_bxwdjkjlb set lie_biao_shu_ju_=?, update_time_=?, bei_zhu_='自动导入' where id_=?";
         jdbcTemplate.update(new PreparedStatementCreator() {
             public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                 PreparedStatement prepareStatement = connection.prepareStatement(sql);
-                prepareStatement.setString(1,wsdEntity.getId());
-                prepareStatement.setTimestamp(2, new java.sql.Timestamp(wsdEntity.getCreateTime().getTime()));
-                prepareStatement.setTimestamp(3, new java.sql.Timestamp(wsdEntity.getCollectTime().getTime()));
-                prepareStatement.setString(4,wsdEntity.getTemperature());
-                prepareStatement.setString(5,wsdEntity.getHumidity());
-                prepareStatement.setString(6,wsdEntity.getDeviceID());
-                prepareStatement.setString(7,wsdEntity.getDeviceNo());
-                prepareStatement.setString(8,wsdEntity.getDeviceName());
-                prepareStatement.setString(9,wsdEntity.getCollectID());
-                prepareStatement.setString(10,wsdEntity.getCollectName());
-                prepareStatement.setString(11,wsdEntity.getTemperatureHigh());
-                prepareStatement.setString(12,wsdEntity.getTemperatureLow());
-                prepareStatement.setString(13,wsdEntity.getHumidityHigh());
-                prepareStatement.setString(14,wsdEntity.getHumidityLow());
-                prepareStatement.setString(15,wsdEntity.getShiYanZu());
-                prepareStatement.setString(16,wsdEntity.getShiYanZuID());
-                prepareStatement.setString(17,wsdEntity.getType());
-                prepareStatement.setString(18,wsdEntity.getArea());
-                prepareStatement.setString(19,wsdEntity.getDiDian());
-                prepareStatement.setString(20,wsdEntity.getRoom());
+                prepareStatement.setString(1, newJsonStr);
+                prepareStatement.setTimestamp(2, new Timestamp(System.currentTimeMillis()));  // 设置当前时间
+                prepareStatement.setString(3, undoMonitorID);
                 return prepareStatement;
             }
         });
     }
 
+
 }

+ 23 - 10
GetDataByView/src/main/java/com/jyxt/getdatabyview/view/entity/CollectorEntity.java

@@ -1,8 +1,6 @@
 package com.jyxt.getdatabyview.view.entity;
 
 public class CollectorEntity {
-    private String DeviceID;
-
     private String DeviceNo;
 
     private String DeviceName;
@@ -13,15 +11,9 @@ public class CollectorEntity {
 
     private String CollectName;
 
-    private String Enable;
-
-    public String getDeviceID() {
-        return DeviceID;
-    }
+    private String Type;
 
-    public void setDeviceID(String deviceID) {
-        DeviceID = deviceID;
-    }
+    private String Enable;
 
     public String getDeviceNo() {
         return DeviceNo;
@@ -63,6 +55,14 @@ public class CollectorEntity {
         CollectName = collectName;
     }
 
+    public String getType() {
+        return Type;
+    }
+
+    public void setType(String type) {
+        Type = type;
+    }
+
     public String getEnable() {
         return Enable;
     }
@@ -70,4 +70,17 @@ public class CollectorEntity {
     public void setEnable(String enable) {
         Enable = enable;
     }
+
+    @Override
+    public String toString() {
+        return "CollectorEntity{" +
+                "DeviceNo='" + DeviceNo + '\'' +
+                ", DeviceName='" + DeviceName + '\'' +
+                ", DeviceType='" + DeviceType + '\'' +
+                ", CollectID='" + CollectID + '\'' +
+                ", CollectName='" + CollectName + '\'' +
+                ", Type='" + Type + '\'' +
+                ", Enable='" + Enable + '\'' +
+                '}';
+    }
 }

+ 110 - 0
GetDataByView/src/main/java/com/jyxt/getdatabyview/view/entity/MonitoredEntity.java

@@ -0,0 +1,110 @@
+package com.jyxt.getdatabyview.view.entity;
+
+import java.util.Date;
+
+public class MonitoredEntity {
+    private String id;
+
+    private String type;
+
+    private Date updateTime;
+
+    private String shifouguoshen;
+
+    private String areaName;
+
+    private String room;
+
+    private String deviceNo;
+
+    private String JsonStr;
+
+    private String note;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public String getShifouguoshen() {
+        return shifouguoshen;
+    }
+
+    public void setShifouguoshen(String shifouguoshen) {
+        this.shifouguoshen = shifouguoshen;
+    }
+
+    public String getAreaName() {
+        return areaName;
+    }
+
+    public void setAreaName(String areaName) {
+        this.areaName = areaName;
+    }
+
+    public String getRoom() {
+        return room;
+    }
+
+    public void setRoom(String room) {
+        this.room = room;
+    }
+
+    public String getDeviceNo() {
+        return deviceNo;
+    }
+
+    public void setDeviceNo(String deviceNo) {
+        this.deviceNo = deviceNo;
+    }
+
+    public String getJsonStr() {
+        return JsonStr;
+    }
+
+    public void setJsonStr(String jsonStr) {
+        JsonStr = jsonStr;
+    }
+
+    public String getNote() {
+        return note;
+    }
+
+    public void setNote(String note) {
+        this.note = note;
+    }
+
+    @Override
+    public String toString() {
+        return "MonitoredEntity{" +
+                "id=" + id +
+                ", type='" + type + '\'' +
+                ", updateTime=" + updateTime +
+                ", shifouguoshen='" + shifouguoshen + '\'' +
+                ", areaName='" + areaName + '\'' +
+                ", room='" + room + '\'' +
+                ", deviceNo='" + deviceNo + '\'' +
+                ", JsonStr='" + JsonStr + '\'' +
+                ", note='" + note + '\'' +
+                '}';
+    }
+}

+ 1 - 3
GetDataByView/src/main/java/com/jyxt/getdatabyview/view/entity/ToLoggerInfo.java

@@ -153,9 +153,7 @@ public class ToLoggerInfo {
         this.HIGH3 = HIGH3;
     }
 
-    public float getLOW3() {
-        return LOW3;
-    }
+    public float getLOW3() { return LOW3; }
 
     public void setLOW3(float LOW3) {
         this.LOW3 = LOW3;

+ 59 - 55
GetDataByView/src/main/java/com/jyxt/getdatabyview/view/entity/WSDEntity.java

@@ -9,9 +9,11 @@ public class WSDEntity {
 
     private Date collectTime;
 
-    private String temperature;
+    private String result;
 
-    private String humidity;
+    private String resultHigh;
+
+    private String resultLow;
 
     private String deviceID;
 
@@ -23,17 +25,9 @@ public class WSDEntity {
 
     private String collectName;
 
-    private String temperatureHigh;
-
-    private String temperatureLow;
-
-    private String humidityHigh;
-
-    private String humidityLow;
-
     private String shiYanZu;
 
-    private String shiYanZuID;
+    private String note;
 
     private String type;
 
@@ -43,6 +37,8 @@ public class WSDEntity {
 
     private String room;
 
+    private String controlFlag;
+
     public String getId() {
         return id;
     }
@@ -67,20 +63,28 @@ public class WSDEntity {
         this.collectTime = collectTime;
     }
 
-    public String getTemperature() {
-        return temperature;
+    public String getResult() {
+        return result;
+    }
+
+    public void setResult(String result) {
+        this.result = result;
+    }
+
+    public String getResultHigh() {
+        return resultHigh;
     }
 
-    public void setTemperature(String temperature) {
-        this.temperature = temperature;
+    public void setResultHigh(String resultHigh) {
+        this.resultHigh = resultHigh;
     }
 
-    public String getHumidity() {
-        return humidity;
+    public String getResultLow() {
+        return resultLow;
     }
 
-    public void setHumidity(String humidity) {
-        this.humidity = humidity;
+    public void setResultLow(String resultLow) {
+        this.resultLow = resultLow;
     }
 
     public String getDeviceID() {
@@ -123,38 +127,6 @@ public class WSDEntity {
         this.collectName = collectName;
     }
 
-    public String getTemperatureHigh() {
-        return temperatureHigh;
-    }
-
-    public void setTemperatureHigh(String temperatureHigh) {
-        this.temperatureHigh = temperatureHigh;
-    }
-
-    public String getTemperatureLow() {
-        return temperatureLow;
-    }
-
-    public void setTemperatureLow(String temperatureLow) {
-        this.temperatureLow = temperatureLow;
-    }
-
-    public String getHumidityHigh() {
-        return humidityHigh;
-    }
-
-    public void setHumidityHigh(String humidityHigh) {
-        this.humidityHigh = humidityHigh;
-    }
-
-    public String getHumidityLow() {
-        return humidityLow;
-    }
-
-    public void setHumidityLow(String humidityLow) {
-        this.humidityLow = humidityLow;
-    }
-
     public String getShiYanZu() {
         return shiYanZu;
     }
@@ -163,12 +135,12 @@ public class WSDEntity {
         this.shiYanZu = shiYanZu;
     }
 
-    public String getShiYanZuID() {
-        return shiYanZuID;
+    public String getNote() {
+        return note;
     }
 
-    public void setShiYanZuID(String shiYanZuID) {
-        this.shiYanZuID = shiYanZuID;
+    public void setNote(String note) {
+        this.note = note;
     }
 
     public String getType() {
@@ -202,4 +174,36 @@ public class WSDEntity {
     public void setRoom(String room) {
         this.room = room;
     }
+
+    public String getControlFlag() {
+        return controlFlag;
+    }
+
+    public void setControlFlag(String controlFlag) {
+        this.controlFlag = controlFlag;
+    }
+
+    @Override
+    public String toString() {
+        return "WSDEntity{" +
+                "id='" + id + '\'' +
+                ", createTime=" + createTime +
+                ", collectTime=" + collectTime +
+                ", result='" + result + '\'' +
+                ", resultHigh='" + resultHigh + '\'' +
+                ", resultLow='" + resultLow + '\'' +
+                ", deviceID='" + deviceID + '\'' +
+                ", deviceNo='" + deviceNo + '\'' +
+                ", deviceName='" + deviceName + '\'' +
+                ", collectID='" + collectID + '\'' +
+                ", collectName='" + collectName + '\'' +
+                ", shiYanZu='" + shiYanZu + '\'' +
+                ", note='" + note + '\'' +
+                ", type='" + type + '\'' +
+                ", area='" + area + '\'' +
+                ", diDian='" + diDian + '\'' +
+                ", room='" + room + '\'' +
+                ", controlFlag='" + controlFlag + '\'' +
+                '}';
+    }
 }

+ 26 - 11
GetDataByView/src/main/resources/application.properties

@@ -1,13 +1,13 @@
 spring.application.name=GetDataByView
-#spring.datasource.jdbc-url=jdbc:sqlserver://localhost:1433;databaseName=huatu
-#spring.datasource.username=sa
-#spring.datasource.password=your_password
-#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
-spring.datasource.jdbc-url=jdbc:mysql://localhost:3306/klims-ibps3?characterEncoding=utf8&useSSL=false
-spring.datasource.username=root
-spring.datasource.password=test001
-spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.second-datasource.jdbc-url = jdbc:mysql://localhost:3306/klims-ibps3?characterEncoding=utf8&useSSL=false
+spring.datasource.jdbc-url=jdbc:sqlserver://10.130.4.29:1433;databaseName=sql
+spring.datasource.username=sa
+spring.datasource.password=123456
+spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
+#spring.datasource.jdbc-url=jdbc:mysql://localhost:3306/klims-ibps3?characterEncoding=utf8&useSSL=false
+#spring.datasource.username=root
+#spring.datasource.password=test001
+#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.second-datasource.jdbc-url = jdbc:mysql://192.168.2.161:3306/klims-ibps3?characterEncoding=utf8&useSSL=false
 spring.second-datasource.username = root
 spring.second-datasource.password = test001
 spring.second-datasource.driver-class-name = com.mysql.cj.jdbc.Driver
@@ -15,5 +15,20 @@ logging.file.name=logs/GetDataByView.log
 fetch.condition=DATEDIFF(day, LOGS_TIME, GETDATE()) = 0
 # level:TRACE < DEBUG < INFO < WARN < ERROR < FATAL
 logging.level.root=INFO
-#1 or 0,1 means qry and insert new data,0 means qry uncontrol judge
-config.run_mode=1
+#1 or 0
+# 1 means qry and insert new data
+# 0 means uncontrol judge
+config.run_mode=1
+#1 or 0 or 2,
+# 0 means run on product environment
+# 1 means only test mode,qry data need to insert and ooutput log
+# 2 means only test mode,qry all daliy data and ooutput log
+config.testmode=0
+# fridge monitor switch
+config.fridge.monitor=1
+# indoor device switch
+config.device.monitor=1
+# cool cabinet switch
+config.cabinet.monitor=0
+# water bath switch
+config.waterbath.monitor=0