From 09ceef0603c39adc3b00650c33e9bb945e0ad2dd Mon Sep 17 00:00:00 2001
From: admin <15939171744@163.com>
Date: 星期四, 11 七月 2024 10:11:51 +0800
Subject: [PATCH] 100-1工位 接收工单bug修复

---
 jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/controller/OmProductionOrdeInfoController.java |   72 ++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/controller/OmProductionOrdeInfoController.java b/jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/controller/OmProductionOrdeInfoController.java
index 46ff5d3..39ade17 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/controller/OmProductionOrdeInfoController.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/om/productionOrde/controller/OmProductionOrdeInfoController.java
@@ -3,8 +3,10 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.CompletableFuture;
 import javax.servlet.http.HttpServletResponse;
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -12,11 +14,15 @@
 import com.jcdm.common.core.domain.model.LoginUser;
 import com.jcdm.common.utils.ServletUtils;
 import com.jcdm.common.utils.StringUtils;
+import com.jcdm.framework.websocket.WebSocketUsers;
+import com.jcdm.main.constant.Constants;
 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfoExcelImport;
 import com.jcdm.main.om.productionOrde.mapper.OmProductionOrdeInfoMapper;
 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
 import com.jcdm.main.restful.factoryMes.service.RestfulService;
+import com.kangaroohy.milo.model.ReadWriteEntity;
+import com.kangaroohy.milo.service.MiloService;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.weaver.loadtime.Aj;
 import org.slf4j.Logger;
@@ -54,6 +60,9 @@
 
     @Autowired
     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
+
+    @Autowired
+    private MiloService miloService;
 
     /**
      * 鏌ヨ鐢熶骇宸ュ崟鍒楄〃
@@ -113,15 +122,17 @@
     }
 
     @GetMapping("/receivingWorkOrders")
-    public AjaxResult receivingWorkOrders()
-    {
+    public AjaxResult receivingWorkOrders() throws Exception {
         String paramProductNum = "";
-        // 鏌ヨ鏈�鏂扮殑宸ュ崟淇℃伅
-        List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().orderByAsc(OmProductionOrdeInfo::getCreateTime));
-        if(list.size() > 0){
-            paramProductNum = list.get(list.size()-1).getProductNum();
+        Object productTypeObjcet = miloService.readFromOpcUa("thoroughfare" + "." + "device" + ".ProductType").getValue();//浜у搧绫诲瀷
+        if (ObjectUtil.isNull(productTypeObjcet)) {
+            return AjaxResult.error("鎺ュ崟澶辫触,PLC鏈紶杈撶敓浜х被鍨嬶紝璇疯仈绯荤鐞嗗憳");
         }
-        String orderJsonString = RestfulService.getProductionWorkOrderRequest(paramProductNum, "OP230");
+        String productType = productTypeObjcet.toString();//浜у搧绫诲瀷
+        String materialCode = Constants.materialMap.get(productType);
+        // 鏌ヨ鏈�鏂扮殑宸ュ崟淇℃伅
+        OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder();
+        String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode);
         JSONObject jsonObject = new JSONObject(orderJsonString);
         // 浠嶫SONObject涓幏鍙杁ata瀵硅薄
         JSONObject dataObject = jsonObject.getJSONObject("data");
@@ -153,6 +164,53 @@
         return AjaxResult.success(dataObject.getStr("productNum"));
     }
 
+    @GetMapping("/mozuReceivingWorkOrders")
+    public AjaxResult mozuReceivingWorkOrders(OmProductionOrdeInfo paramOrder) throws Exception {
+        String paramProductNum = "";
+        Object productTypeObjcet = miloService.readFromOpcUa("MOZU1." + paramOrder.getLineCode() + ".ProductType").getValue();//浜у搧绫诲瀷
+        if (ObjectUtil.isNull(productTypeObjcet)) {
+            return AjaxResult.error("鎺ュ崟澶辫触,PLC鏈紶杈撶敓浜х被鍨嬶紝璇疯仈绯荤鐞嗗憳");
+        }
+        String productType = productTypeObjcet.toString();//浜у搧绫诲瀷
+        String materialCode = Constants.materialMap.get(productType);
+
+        OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder();
+        String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode);
+        JSONObject jsonObject = new JSONObject(orderJsonString);
+        // 浠嶫SONObject涓幏鍙杁ata瀵硅薄
+        JSONObject dataObject = jsonObject.getJSONObject("data");
+        String code = jsonObject.getStr("code");
+        // 鍒ゆ柇鎺ュ崟鏄惁鎴愬姛
+        if(code.equals("success")){
+            logger.info("璇锋眰宸ュ巶MES宸ュ崟锛氬叆鍙俻ack{}鍑哄弬pack锛歿}",paramProductNum,dataObject.getStr("productNum"));
+            List<OmProductionOrdeInfo> check = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum,dataObject.getStr("productNum")));
+            if(check.size() == 0){
+                try {
+                    log.info("璇锋眰宸ュ巶MES宸ュ崟锛氬叆鍙俻ack{}鍑哄弬pack锛歿}", paramProductNum, dataObject.getStr("productNum"));
+                    OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
+                    omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum"));
+                    omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum"));
+                    omProductionOrdeInfo.setStationCode(dataObject.getStr("stationCode"));
+                    omProductionOrdeInfo.setMaterialCode(dataObject.getStr("materialCode"));
+                    omProductionOrdeInfo.setOnlineCompletionMark("0");
+                    omProductionOrdeInfo.setSfResult("0");
+                    omProductionOrdeInfo.setProductCode(dataObject.getStr("model"));
+                    omProductionOrdeInfo.setCreateTime(new Date());
+                    omProductionOrdeInfo.setCreateUser("宸ュ巶MES");
+                    omProductionOrdeInfoService.save(omProductionOrdeInfo);
+                    //鍐橮LC
+                    miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".MES_WorkOrderNumber").value(dataObject.getStr("productionOrderNum")).build());
+                    miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".MES_ModuleCode").value(dataObject.getStr("productNum")).build());
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }else {
+            return AjaxResult.error("鎺ュ崟澶辫触,璇疯仈绯荤鐞嗗憳");
+        }
+        return AjaxResult.success(dataObject.getStr("productNum"));
+    }
+
     @GetMapping(value = "/jieBang/{id}")
     public AjaxResult jieBang(@PathVariable("id") Long id)
     {

--
Gitblit v1.9.3