From be28fb5bb3b68f5dcce4273adde56bef669f711e Mon Sep 17 00:00:00 2001
From: cl <418351270@qq.com>
Date: 星期五, 06 九月 2024 09:22:49 +0800
Subject: [PATCH] 修改电芯挡位功能

---
 jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/IDaCellDataService.java         |    3 +++
 jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/impl/DaCellDataServiceImpl.java |    6 ++++++
 jcdm-main/src/main/java/com/jcdm/main/da/cellData/mapper/DaCellDataMapper.java            |    2 ++
 jcdm-main/src/main/resources/mapper/da/cellData/DaCellDataMapper.xml                      |    7 +++++++
 jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java                |   28 ++++++++++++++++++++--------
 jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java                             |    2 ++
 6 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java b/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java
index 6516f4a..f0a9847 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java
@@ -57,6 +57,8 @@
     public static final String OP210= "M2OP210";
     public static final String OP220= "M2OP220";
 
+    public static String OLD_CELL_GEAR = "";
+
     public static final Integer INT_ONE= 1;
     public static final Integer INT_TWO= 2;
     public static final Integer INT_THREE= 3;
diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/cellData/mapper/DaCellDataMapper.java b/jcdm-main/src/main/java/com/jcdm/main/da/cellData/mapper/DaCellDataMapper.java
index 67efce7..7fd80fb 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/da/cellData/mapper/DaCellDataMapper.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/da/cellData/mapper/DaCellDataMapper.java
@@ -63,4 +63,6 @@
     public int deleteDaCellDataByIds(Long[] ids);
 
     void deleteDaCellDataByGbCellCode(@Param("gbCellCode") String gbCellCode);
+
+    void deleteDaCellDataByCellSerial(@Param("cellSerial") String cellSerial);
 }
diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/IDaCellDataService.java b/jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/IDaCellDataService.java
index cd35068..27594b1 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/IDaCellDataService.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/IDaCellDataService.java
@@ -4,6 +4,7 @@
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jcdm.main.da.cellData.domain.DaCellData;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 鐢佃姱鏁版嵁Service鎺ュ彛
@@ -64,4 +65,6 @@
     void insertBatch(List<DaCellData> daCellDataList);
 
     void deleteDaCellDataByGbCellCode(String gbCellCode);
+
+    void deleteDaCellDataByCellSerial(String cellSerial);
 }
diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/impl/DaCellDataServiceImpl.java b/jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/impl/DaCellDataServiceImpl.java
index 60e0b0d..2c5a33b 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/impl/DaCellDataServiceImpl.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/da/cellData/service/impl/DaCellDataServiceImpl.java
@@ -109,4 +109,10 @@
         daCellDataMapper.deleteDaCellDataByGbCellCode(gbCellCode);
 
     }
+
+    @Override
+    public void deleteDaCellDataByCellSerial(String cellSerial) {
+        daCellDataMapper.deleteDaCellDataByCellSerial(cellSerial);
+    }
+
 }
diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
index 6b5a617..7e08480 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -166,8 +166,9 @@
                             result = 16;//鐢佃姱鎸′綅涓虹┖
                         }else{
                             String cellGear = cellGearObjcet.toString();
-                      /*      List<String> cellCodeList = readCellCodeList(thoroughfare, device);
-                            result = checkCellGear(thoroughfare, device,cellCodeList,cellGear);//鏍¢獙鐢佃姱鎸′綅鍜岀粍鍒�*/
+                            List<String> cellCodeList = readCellCodeList(thoroughfare, device);
+                            result = checkCellGear(thoroughfare, device,cellCodeList,cellGear);//鏍¢獙鐢佃姱鎸′綅鍜岀粍鍒�
+                            Constants.OLD_CELL_GEAR = cellGear;//鎸′綅璧嬪��
                         }
                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
 
@@ -864,7 +865,7 @@
      */
     private Integer checkCellGear(String thoroughfare, String device,List<String> cellCodeList,String cellGear) throws Exception {
         Integer result = 11;
-
+        String cellSerial = "";
         for(int i = 0; i < cellCodeList.size(); i ++){
             Integer cellStatus = 1;
             String cellCode = cellCodeList.get(i);
@@ -874,20 +875,31 @@
                 if(CollUtil.isNotEmpty(list)){
                     DaCellData daCellData = list.get(0);
                     String cellValue = daCellData.getCellValue();//鏁版嵁搴撲腑鐢佃姱鎸′綅
-                    String cellSerial = daCellData.getCellSerial();//鏁版嵁搴撲腑鐢佃姱缁勫埆
+                    cellSerial = daCellData.getCellSerial();//鏁版嵁搴撲腑鐢佃姱缁勫埆
                     if(!cellValue.isEmpty() && cellValue.equals(cellGear)){
                         cellStatus = 1;
                     }else {
                         cellStatus = 2;
                         result = 16;//鎸′綅鏍¢獙涓嶅悎鏍�
+                        log.info("鐢佃姱鎸′綅鏍¢獙涓嶅悎鏍硷細鐢佃姱鐮佷负{}锛孭LC璁剧疆鎸′綅涓簕}锛屽伐鍘侻ES涓嬪彂鎸′綅涓猴細{}",cellCode,cellGear,cellValue);
                     }
-                }/*else {
+                }else {
                     cellStatus = 2;
-                    result = 17;//鏌ヤ笉鍒拌鏍¢獙鐨勬尅浣�
-                }*/
-                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_"+(i+1)).value(cellStatus).build());
+                    result = 16;//鏌ヤ笉鍒拌鏍¢獙鐨勬尅浣�
+                    log.info("鐢佃姱鎸′綅鏍¢獙涓嶅悎鏍硷細鐢佃姱鐮佷负{}锛孭LC璁剧疆鎸′綅涓簕}锛屽伐鍘侻ES涓嬪彂鎸′綅涓虹┖锛屾煡璇笉鍒拌鏁版嵁",cellCode,cellGear);
+                }
+                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".Cell_Status_"+(i+1)).value(cellStatus).build());
             }
         }
+
+        //褰撶數鑺尅浣嶅彂鐢熷彉鍖栨椂锛屽苟涓旇�佺殑鎸′綅涓嶄负绌猴紝鍒犻櫎褰撳墠鐢佃姱鎵规
+        if(!Constants.OLD_CELL_GEAR.isEmpty() && !cellGear.equals(Constants.OLD_CELL_GEAR)){
+            if(!cellSerial.isEmpty()){
+                daCellDataService.deleteDaCellDataByCellSerial(cellSerial);
+            }
+            log.info("鐢佃姱鎸′綅鍙戠敓鏀瑰彉锛岃�佺殑鎸′綅涓猴細{}锛屾柊鐨勬尅浣嶄负锛歿}锛屾壒娆″彿涓簕}",Constants.OLD_CELL_GEAR,cellGear,cellSerial);
+        }
+
         return result;
     }
 
diff --git a/jcdm-main/src/main/resources/mapper/da/cellData/DaCellDataMapper.xml b/jcdm-main/src/main/resources/mapper/da/cellData/DaCellDataMapper.xml
index 9a31757..5a25647 100644
--- a/jcdm-main/src/main/resources/mapper/da/cellData/DaCellDataMapper.xml
+++ b/jcdm-main/src/main/resources/mapper/da/cellData/DaCellDataMapper.xml
@@ -147,4 +147,11 @@
         WHERE
             gb_cell_code = #{gbCellCode}
     </delete>
+    <delete id="deleteDaCellDataByCellSerial" parameterType="String">
+        DELETE
+        FROM
+            da_cell_data
+        WHERE
+            cell_serial = #{cellSerial}
+    </delete>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3