From cf6bff3922bbd0624b98834f6ea85c8e619e564f Mon Sep 17 00:00:00 2001
From: cl <418351270@qq.com>
Date: 星期二, 16 一月 2024 12:45:46 +0800
Subject: [PATCH] 修改数据采集

---
 guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP050/impl/OP050ServerInterfaceImpl.java |  136 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 134 insertions(+), 2 deletions(-)

diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP050/impl/OP050ServerInterfaceImpl.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP050/impl/OP050ServerInterfaceImpl.java
index 8cca803..ec7996e 100644
--- a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP050/impl/OP050ServerInterfaceImpl.java
+++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP050/impl/OP050ServerInterfaceImpl.java
@@ -7,10 +7,19 @@
 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
 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.model.result.PassingStationCollectionResult;
 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.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
+import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
+import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
 import cn.stylefeng.guns.plcserver.opc.OPCComm;
 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
@@ -51,10 +60,34 @@
     private static String GROUP_NAME  = "OP050_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.getOP050_F_HEART_BEAT(), "true");
+            GlobalVariable.OP050_F_HEART_BEAT = true;
+            count = 0;
+        } else {
+            count++;
+        }
+        // 寰幆璇诲彇棰戠巼鏄細500ms涓�娆★紝濡傛灉瓒呰繃6娆★紝涔熷氨鏄�3s璁ゅ畾瓒呮椂
+        if (count > GlobalVariable.HEART_MAX_COUNT) {
+            GlobalVariable.OP050_F_HEART_BEAT = false;
+        }
+    }
+
     @Override
     public synchronized void monitor() {
         String ecpStr = "";//寮傚父璁板綍鏍囪
         try{
+
+            String isHeartBeat = OPCUnit.read(opc.getOP050_F_HEART_BEAT());
+            setHeartbeat(isHeartBeat);
+
             if(GlobalVariable.OP050_F_HEART_BEAT) {
                 //PC璇诲伐鍗�
                 String isPLCStart = OPCUnit.read(opc.getOP050_J_PLC_START());//PLC寮�濮�
@@ -71,6 +104,7 @@
                 if(isPLCFinish.equals("true")){
                     String isFinish = OPCUnit.read(opc.getOP050_J_PC_FINISH());//PC鎿嶄綔瀹屾垚
                     if(isFinish.equals("false")){
+                        handleMaterial();
                         handleInfo();
                         handleFinsh();
                     }
@@ -108,7 +142,7 @@
             }else{
                 OPCUnit.write(opc.getOP050_OIL_STATE(), "true"); //鍐欐补鑴傜姸鎬�
             }
-            logger.info("鍒版湡鏃ユ湡锛�"+duaDate+"褰撳墠鏃ユ湡锛�"+currentDate+"鍓╀綑澶╂暟锛氾細"+daysBetween);
+            //logger.info("鍒版湡鏃ユ湡锛�"+duaDate+"褰撳墠鏃ユ湡锛�"+currentDate+"鍓╀綑澶╂暟锛氾細"+daysBetween);
         }
     }
 
@@ -128,6 +162,61 @@
         S_SFC_CODE = OPCUnit.read(opc.getOP050_S_SFC_CODE());//鎬绘垚缂栫爜
         OPCUnit.write(opc.getOP050_J_PC_WRITE_ORDER(), "true"); //PC璇诲伐鍗曞畬鎴�
         logger.info("OP050宸ヤ綅,handleOrder PC澶勭悊瀹屾垚锛�");
+    }
+
+    public void handleMaterial() {
+        if("".equals(S_ORDER_CODE)){
+            IN_TIME = DateTool.getLocalTimeForDate();
+            S_ORDER_CODE = OPCUnit.read(opc.getOP050_S_ORDER_CODE());//宸ュ崟缂栧彿
+            S_PRODUCT_TYPE = OPCUnit.read(opc.getOP050_S_PRODUCT_CODE());//浜у搧缂栧彿
+            S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
+            S_SFC_CODE = OPCUnit.read(opc.getOP050_S_SFC_CODE());//鎬绘垚缂栫爜
+        }
+        //鏌ヨ鎵规涓婃枡淇℃伅
+        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);
+
+            //鍒ゆ柇鏄惁鏈夎宸ヤ綅
+            String[] locationCodes = productionOrderBatchInfoResult.getLocationCode().split("/");
+            logger.info("褰撳墠宸ヤ綅锛�"+locationCodes.toString());
+            boolean isLocationCode = false;
+            if(locationCodes.length>0)
+            {
+                for (int j=0;j<locationCodes.length;j++){
+                    String location = locationCodes[j];
+                    if(location.equals(LOCATION_CODE)){
+                        isLocationCode = true;
+                    }
+                }
+            }
+
+            int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺
+            if(remainingQuantity>0 && isLocationCode){
+                //鏂板鐗╂枡杩芥函
+                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璇诲弬鏁颁俊鎭�
@@ -196,6 +285,7 @@
 
         //澶勭悊杩囩珯淇℃伅
         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP050_S_PRODUCT_STATE_CODE());
+
         PassingStationCollectionParam param = new PassingStationCollectionParam();
         param.setWorkOrderNo(S_ORDER_CODE);
         param.setProductCode(S_PRODUCT_CODE);
@@ -208,9 +298,17 @@
         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
         passingStationCollectionService.add(param);
 
-        //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP杩囩珯鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜
+
+
         String  copSfcCode = OPCUnit.read(opc.getOP050_S_SFC_CODE_COP());//COP鍒嗘�绘垚
         String  bopSfcCode = OPCUnit.read(opc.getOP050_S_SFC_CODE_BOP());//BOP鍒嗘�绘垚
+
+        //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP鐗╂枡鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜
+        MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
+        materialTraceabilityService.updateSFC(S_SFC_CODE,copSfcCode);
+        materialTraceabilityService.updateSFC(S_SFC_CODE,bopSfcCode);
+
+        //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP杩囩珯鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜
         passingStationCollectionService.updateSFC(S_SFC_CODE,copSfcCode);
         passingStationCollectionService.updateSFC(S_SFC_CODE,bopSfcCode);
 
@@ -220,6 +318,40 @@
         paramCollectionService.updateSFC(S_SFC_CODE,copSfcCode);
         paramCollectionService.updateSFC(S_SFC_CODE,bopSfcCode);
 
+        logger.info("S_SFC_CODE:"+S_SFC_CODE);
+        logger.info("copSfcCode:"+copSfcCode);
+        logger.info("bopSfcCode:"+bopSfcCode);
+
+        //鏌ヨCOP鍜孊OP鏄惁鍚堟牸
+        PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam();
+        passingStationCollectionParam.setSfcCode(S_SFC_CODE);
+        List<PassingStationCollectionResult> passingStationCollectionResultList =
+                opc.passingStationCollectionService.findListBySpec(passingStationCollectionParam);
+
+        String isProductState = "true";
+        for(int i=0;i<passingStationCollectionResultList.size();i++){
+            PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i);
+            if("false".equals(passingStationCollectionResult.getOutRsSign())){
+                isProductState = "false";
+                break;
+            }
+        }
+        //淇敼鎶ュ伐璁板綍
+        if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){
+            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
+            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
+            productionOrderRecordsParam.setProductNo(S_SFC_CODE);
+            ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService;
+
+            List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
+            if(list.size()>0){
+                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
+                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
+                productionOrderRecordsParam.setWhetherPass("false");
+                productionOrderRecordsService.update(productionOrderRecordsParam);
+            }
+        }
+
 
         OPCUnit.write(opc.getOP050_J_PC_FINISH(), "true"); //PC瀹屾垚
 

--
Gitblit v1.9.3