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/OP080/impl/OP080ServerInterfaceImpl.java |   95 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 1 deletions(-)

diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP080/impl/OP080ServerInterfaceImpl.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP080/impl/OP080ServerInterfaceImpl.java
index 013b419..334f2be 100644
--- a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP080/impl/OP080ServerInterfaceImpl.java
+++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/server/OP080/impl/OP080ServerInterfaceImpl.java
@@ -11,6 +11,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.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.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
@@ -50,10 +58,34 @@
     private static String GROUP_NAME  = "OP080_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.getOP080_F_HEART_BEAT(), "true");
+            GlobalVariable.OP080_F_HEART_BEAT = true;
+            count = 0;
+        } else {
+            count++;
+        }
+        // 寰幆璇诲彇棰戠巼鏄細500ms涓�娆★紝濡傛灉瓒呰繃6娆★紝涔熷氨鏄�3s璁ゅ畾瓒呮椂
+        if (count > GlobalVariable.HEART_MAX_COUNT) {
+            GlobalVariable.OP080_F_HEART_BEAT = false;
+        }
+    }
+
     @Override
     public synchronized void monitor() {
         String ecpStr = "";//寮傚父璁板綍鏍囪
         try{
+
+          /*  String isHeartBeat = OPCUnit.read(opc.getOP080_F_HEART_BEAT());
+            setHeartbeat(isHeartBeat);*/
+
             if(GlobalVariable.OP080_F_HEART_BEAT) {
                 //PC璇诲伐鍗�
                 String isPLCStart = OPCUnit.read(opc.getOP080_J_PLC_START());//PLC寮�濮�
@@ -76,8 +108,15 @@
                 if(isPLCFinish.equals("true")){
                     String isFinish = OPCUnit.read(opc.getOP080_J_PC_FINISH());//PC鎿嶄綔瀹屾垚
                     if(isFinish.equals("false")){
-                        handleInfo();
+                        logger.info("handleFinsh寮�濮嬫椂闂�:"+new Date());
                         handleFinsh();
+                        logger.info("handleFinsh瀹屾垚鏃堕棿:"+new Date());
+                        logger.info("handleInfo寮�濮嬫椂闂�:"+new Date());
+                        handleInfo();
+                        logger.info("handleInfo瀹屾垚鏃堕棿:"+new Date());
+                        logger.info("handleMaterial寮�濮嬫椂闂�:"+new Date());
+                        handleMaterial();
+                        logger.info("handleMaterial瀹屾垚鏃堕棿:"+new Date());
                     }
                 }
 
@@ -151,6 +190,42 @@
         logger.info("OP080宸ヤ綅,handleOrder PC澶勭悊瀹屾垚锛�");
     }
 
+    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 handleInfo() throws Exception {
         logger.info("OP080宸ヤ綅,handleInfo START锛�");
@@ -215,6 +290,24 @@
         }
         //澶勭悊杩囩珯淇℃伅
         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP080_S_PRODUCT_STATE_CODE());
+
+        //淇敼鎶ュ伐璁板綍
+        if("false".equals(S_PRODUCT_STATE_CODE)){
+            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(S_PRODUCT_STATE_CODE);
+                productionOrderRecordsService.update(productionOrderRecordsParam);
+            }
+        }
+
+
         PassingStationCollectionParam param = new PassingStationCollectionParam();
         param.setWorkOrderNo(S_ORDER_CODE);
         param.setProductCode(S_PRODUCT_CODE);

--
Gitblit v1.9.3