From e39c11465130d5b74be7f1db7df70e902403da49 Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期三, 06 十一月 2024 13:05:33 +0800
Subject: [PATCH] 出库呼叫agv修改

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 114 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 366427b..d3bc141 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -7,6 +7,7 @@
 import com.core.common.Cools;
 import com.core.common.DateUtils;
 import com.core.exception.CoolException;
+import com.zy.asrs.domain.param.ForwardAGVTaskParam;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.mapper.*;
 import com.zy.asrs.service.*;
@@ -30,17 +31,17 @@
 import com.zy.core.enums.DevpType.DevpStateType;
 import com.zy.core.enums.DevpType.DevpTrayType;
 import com.zy.core.enums.DevpType.DevpWorkType;
-import com.zy.core.model.*;
+import com.zy.core.model.CrnSlave;
+import com.zy.core.model.DevpSlave;
+import com.zy.core.model.LedSlave;
+import com.zy.core.model.Task;
 import com.zy.core.model.command.CrnCommand;
 import com.zy.core.model.command.LedCommand;
-import com.zy.core.model.command.RgvCommand;
 import com.zy.core.model.protocol.CrnProtocol;
-import com.zy.core.model.protocol.RgvProtocol;
 import com.zy.core.model.protocol.StaProtocol;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.BarcodeThread;
 import com.zy.core.thread.LedThread;
-import com.zy.core.thread.RgvThread;
 import com.zy.core.thread.SiemensDevpThread;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,8 +50,9 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
 import java.util.*;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -660,7 +662,7 @@
                         }
 
                         // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触
-                        wrkMast.setWrkSts(14L);
+                        wrkMast.setWrkSts(13L);
                         wrkMast.setCrnEndTime(new Date());
                         if (wrkMastMapper.updateById(wrkMast) != 0) {
                             // 澶嶄綅鍫嗗灈鏈�
@@ -2101,9 +2103,115 @@
 //        News.infoNoLog(""+mark+" - 0"+" - outOfDevp鎵ц瀹屾垚");
     }
 
+    public synchronized void forwardAGVInTasks() {
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            // 閬嶅巻鍏ュ簱鍙�
+            for (DevpSlave.Sta agvSta : devp.getAgvOutSta()) {
+                // 鑾峰彇鍏ュ簱绔欎俊鎭�
+                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+                StaProtocol staProtocol = devpThread.getStation().get(agvSta.getStaNo());
+                if (staProtocol == null) {
+                    continue;
+                } else {
+                    staProtocol = staProtocol.clone();
+                }
+                if (!(staProtocol.stateType == DevpStateType.AUTO && staProtocol.requestType == DevpRequestType.OUT)){
+                    continue;
+                }
+                if (staProtocol.getWorkNo() == 0){
+                    continue;
+                }
+                WrkMast wrkMast1 = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", staProtocol.getWorkNo()).eq("wrk_sts", 101));
+                if(!Cools.isEmpty(wrkMast1)){
+                    continue;
+                }
+                //鏌ヨ鐘舵�佷负2鐨勪换鍔�
+                //鏌ヨ鐘舵�佷负2鐨勪换鍔�
+                WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
+                        .eq("wrk_no", staProtocol.getWorkNo())
+                        .in("io_type",101,110,103,104,107)
+                        .eq("wrk_sts", 15));
+                if (Cools.isEmpty(wrkMast)) {
+                    log.error(agvSta.getStaNo()+"绔�,杞彂agv浠诲姟鏈壘鍒板搴斾换鍔�,浠诲姟鍙凤細"+staProtocol.getWorkNo());
+                    continue;
+                }
+                ForwardAGVTaskParam forwardAGVTaskParam = new ForwardAGVTaskParam();
+                getAgvTaskParam(forwardAGVTaskParam,wrkMast,staProtocol.getSiteId());
+                String request = forwardAGVHttpRequest(forwardAGVTaskParam, "10.0.100.110:8182", "/rcms/services/rest/hikRpcService/genAgvSchedulingTask");
+                if ("SUCCESS".equals(request)) {
+                    wrkMast.setWrkSts(14L);
+                    boolean update = wrkMastService.updateById(wrkMast);
+                    if (update){
+                        log.info("鍏ュ簱杞彂AGV浠诲姟瀹屾垚,浠诲姟鍙�:"+wrkMast.getWrkNo());
+                        devpThread.setPakMk(staProtocol.getSiteId(), false);
+                    }
+                }
 
 
 
+            }
+        }
+
+    }
+
+    private void getAgvTaskParam(ForwardAGVTaskParam agvTaskCreateParam,WrkMast param,Integer staNo){
+        String sourceSite = "";
+        if (staNo == 1040 || staNo == 1042) {
+            sourceSite = "a";
+        } else if (staNo == 2010 || staNo == 2012) {
+            sourceSite = "b";
+        } else if(staNo == 3010  || staNo ==3012) {
+            sourceSite = "c";
+        } else if(staNo == 2000 || staNo ==2002) {
+            sourceSite = "d";
+        }
+        List<ForwardAGVTaskParam.PositionCodePaths> agvTaskParamList = Arrays.asList(
+                //璧峰浣�
+                new ForwardAGVTaskParam.PositionCodePaths(staNo.toString(),"05"),
+                //鐩爣浣�
+                new ForwardAGVTaskParam.PositionCodePaths(sourceSite,"04")
+        );
+        Date date = new Date();
+        DecimalFormat df = new DecimalFormat("0000");
+        String wrkNo = "Crn"+df.format(param.getWrkNo())+date.getTime()/1000;
+        agvTaskCreateParam.setReqCode(wrkNo);
+        agvTaskCreateParam.setReqTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+        agvTaskCreateParam.setTaskTyp("GT4");
+        agvTaskCreateParam.setCtnrCode(param.getBarcode());
+        agvTaskCreateParam.setPositionCodePath(agvTaskParamList);
+        agvTaskCreateParam.setCtnrTyp("2");
+        agvTaskCreateParam.setPriority("1");
+        agvTaskCreateParam.setTaskCode(wrkNo);
+
+    }
+
+    private String forwardAGVHttpRequest(Object requestParam, String url, String path){
+        String response = "";
+        String success = "error";
+        try {
+            response = new HttpHandler.Builder()
+                    .setUri(url)
+//                    .setHttps(true)
+                    .setPath(path)
+                    .setJson(JSONObject.toJSONString(requestParam))
+                    .build()
+                    .doPost();
+            JSONObject jsonObject = JSON.parseObject(response);
+
+            String message = jsonObject.get("code").toString();
+            if(("0").equals(message) || ("璇锋眰缂栧彿宸插瓨鍦�").contains(message)){
+                success = "SUCCESS";
+            }else {
+                success = message;
+            }
+            log.info("杞彂agv浠诲姟锛氳姹備綋:"+JSONObject.toJSONString(requestParam)+",杩斿洖鍊�:"+jsonObject);
+        }catch (Exception e){
+
+        }
+        return success;
+    }
+
+
 
 
 

--
Gitblit v1.9.1