From e0fac38b26845f25de479783e0c76cf12a5311e0 Mon Sep 17 00:00:00 2001
From: cl <418351270@qq.com>
Date: 星期五, 19 一月 2024 10:31:28 +0800
Subject: [PATCH] 修改数据采集

---
 guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/DOP020/impl/DOP020ServerInterfaceImpl.java |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/DOP020/impl/DOP020ServerInterfaceImpl.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/DOP020/impl/DOP020ServerInterfaceImpl.java
index 6e9b378..dd78843 100644
--- a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/DOP020/impl/DOP020ServerInterfaceImpl.java
+++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/DOP020/impl/DOP020ServerInterfaceImpl.java
@@ -8,6 +8,14 @@
 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
+import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
+import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
+import cn.stylefeng.guns.modular.gm.greaseManage.model.params.GreaseManageParam;
+import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult;
+import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
+import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
+import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
+import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
 import cn.stylefeng.guns.plcserver.opc.OPCComm;
 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
@@ -19,6 +27,10 @@
 import org.openscada.opc.lib.da.Group;
 import org.openscada.opc.lib.da.Item;
 
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.Date;
 import java.util.List;
 
@@ -44,10 +56,33 @@
     private static String GROUP_NAME  = "DOP020_P";//缁勫悕
     private static List list = null;
     private static Group group = null;
+
+    private int count = 0;
+
+    /**
+     * 璁剧疆蹇冭烦鏍囧織浣嶏紝淇濆瓨鍒板叏灞�鍙橀噺
+     */
+    public void setHeartbeat(String value) {
+        if ("false".equals(value)) {
+            OPCUnit.write(opc.getDOP020_F_HEART_BEAT(), "true");
+            GlobalVariable.DOP020_F_HEART_BEAT = true;
+            count = 0;
+        } else {
+            count++;
+        }
+        // 寰幆璇诲彇棰戠巼鏄細500ms涓�娆★紝濡傛灉瓒呰繃6娆★紝涔熷氨鏄�3s璁ゅ畾瓒呮椂
+        if (count > GlobalVariable.HEART_MAX_COUNT) {
+            GlobalVariable.DOP020_F_HEART_BEAT = false;
+        }
+    }
+
     @Override
     public synchronized void monitor() {
         String ecpStr = "";//寮傚父璁板綍鏍囪
         try{
+           /* String isHeartBeat = OPCUnit.read(opc.getDOP020_F_HEART_BEAT());
+            setHeartbeat(isHeartBeat);*/
+
             if(GlobalVariable.DOP020_F_HEART_BEAT) {
                 //PC璇诲伐鍗�
                 String isPLCStart = OPCUnit.read(opc.getDOP020_J_PLC_START());//PLC寮�濮�
@@ -64,11 +99,12 @@
                 if(isPLCFinish.equals("true")){
                     String isFinish = OPCUnit.read(opc.getDOP020_J_PC_FINISH());//PC鎿嶄綔瀹屾垚
                     if(isFinish.equals("false")){
-                        handleInfo();
                         handleFinsh();
+                        handleInfo();
+                        handleMaterial();
                     }
                 }
-
+                handleOilState();
             }else{
                 logger.info("DOP020宸ヤ綅涓嶱LC鏂紑,璇锋鏌LC鎴栫綉缁滄槸鍚﹀紓甯革紒");
             }
@@ -80,6 +116,33 @@
                 logger.info(ecpStr+"\r\n");
             }
         }
+    }
+    public void handleOilState(){
+        GreaseManageParam param = new GreaseManageParam();
+        GreaseManageService greaseManageService = opc.greaseManageService;
+        param.setLocationCode(LOCATION_CODE);
+        List<GreaseManageResult> list = greaseManageService.findListBySpec(param);
+        if(list.size()>0) {
+            String duaDate = list.get(0).getDuaDate();
+
+            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
+            String currentDate = format.format(new Date());
+            long  daysBetween = getRemainder(currentDate,duaDate);
+            if(daysBetween>0){
+                OPCUnit.write(opc.getDOP020_OIL_STATE(), "false"); //鍐欐补鑴傜姸鎬�
+            }else{
+                OPCUnit.write(opc.getDOP020_OIL_STATE(), "true"); //鍐欐补鑴傜姸鎬�
+            }
+            //logger.info("鍒版湡鏃ユ湡锛�"+duaDate+"褰撳墠鏃ユ湡锛�"+currentDate+"鍓╀綑澶╂暟锛氾細"+daysBetween);
+        }
+    }
+
+    public static long getRemainder(String currentDate,String tableDate){
+        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
+        LocalDate localDate1 = LocalDate.parse(currentDate, dateFormatter);
+        LocalDate localDate2 = LocalDate.parse(tableDate, dateFormatter);
+        long days = ChronoUnit.DAYS.between(localDate1, localDate2);
+        return days;
     }
 
     //PC璇诲伐鍗�
@@ -146,6 +209,42 @@
         logger.info("DOP020宸ヤ綅,handleInfo END锛�");
     }
 
+    public void handleMaterial() {
+
+        //鏌ヨ鎵规涓婃枡淇℃伅
+        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
+        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
+        productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
+        ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
+        List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
+        for(int i=0;i<list1.size();i++){
+            ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
+
+
+            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺
+            if(remainingQuantity>0 ){
+                //鏂板鐗╂枡杩芥函
+                MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
+                materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
+                materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
+                materialTraceabilityParam.setProductNo(S_SFC_CODE);
+                materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
+                materialTraceabilityParam.setLocationCode(LOCATION_CODE);
+                materialTraceabilityParam.setAssemblyQty(1);
+                materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
+                materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//鐗╂枡缂栫爜
+                materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//鐗╂枡鎵规
+
+                MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
+                materialTraceabilityService.add(materialTraceabilityParam);
+                //鏇存柊鍓╀綑鏁伴噺
+                productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
+                productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//鍓╀綑鏁伴噺
+                productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
+            }
+        }
+    }
+
     //PC瀹屾垚
     public void handleFinsh() {
         if("".equals(S_ORDER_CODE)){

--
Gitblit v1.9.3