From 0d04bc5d8080b82338302fba0a59fccff2eaedfc Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期日, 06 七月 2025 11:28:29 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/OpenServiceImpl.java |  245 ++++++++++++++++++++++++++++++------------------
 1 files changed, 153 insertions(+), 92 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/OpenServiceImpl.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/OpenServiceImpl.java
index 3dd8255..9a55d74 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/OpenServiceImpl.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/OpenServiceImpl.java
@@ -7,6 +7,7 @@
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.common.R;
 import com.zy.asrs.framework.common.SnowflakeIdWorker;
+import com.zy.asrs.framework.exception.CoolException;
 import com.zy.asrs.wcs.core.domain.dto.BasLiftStaDto;
 import com.zy.asrs.wcs.core.domain.param.AgvTaskCreateParam;
 import com.zy.asrs.wcs.core.domain.param.CreateInTaskParam;
@@ -26,6 +27,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 
@@ -56,20 +58,21 @@
 
 
     @Override
-    public R createInTask(CreateInTaskParam param) {
+    @Transactional
+    public R createInTask(CreateInTaskParam param, CreateWcsTaskParam createWcsTaskParam) {
         //鑾峰彇鍏ュ簱浠诲姟绫诲瀷
         TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                 .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN))
                 .eq(TaskCtg::getStatus, 1));
         if (taskCtg == null) {
-            return R.error("浠诲姟绫诲瀷寮傚父");
+            throw new CoolException("浠诲姟绫诲瀷寮傚父");
         }
 
         Long hostId = 1L;//榛樿涓讳粨搴�
 
         Loc loc = locService.selectByLocNo(param.getDestLoc());
         if (loc == null) {
-            return R.error("搴撲綅鍙蜂笉瀛樺湪");
+            throw new CoolException("搴撲綅鍙蜂笉瀛樺湪");
         }
 
         //鑾峰彇涓ユ牸妯″紡鍙傛暟
@@ -80,7 +83,7 @@
         }
 
         if (mapStrict && !loc.getLocStsFlag().equals("O")) {
-            return R.error("搴撲綅鐘舵�佷笉婊¤冻鍏ュ簱鏉′欢");
+            throw new CoolException("搴撲綅鐘舵�佷笉婊¤冻鍏ュ簱鏉′欢");
         }
 
         Task one = taskService.getOne(new LambdaQueryWrapper<Task>()
@@ -89,7 +92,7 @@
                 .eq(Task::getDestSite, param.getDestSite())
                 .eq(Task::getDestLoc, param.getDestLoc()));
         if (one != null) {
-            return R.error("浠诲姟宸插瓨鍦�");
+            throw new CoolException("浠诲姟宸插瓨鍦�");
         }
 
         String destSite = param.getDestSite();
@@ -100,7 +103,7 @@
                     .eq(BasConveyorPath::getHostId, hostId)
                     .eq(BasConveyorPath::getStnNo, param.getOriginSite()));
             if(path == null) {
-                return R.error("鍐呯疆璺緞涓嶅瓨鍦�");
+                throw new CoolException("鍐呯疆璺緞涓嶅瓨鍦�");
             }
             destSite = String.valueOf(path.getDeviceStn());
         }
@@ -115,27 +118,27 @@
                     .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT))
                     .eq(TaskCtg::getStatus, 1));
             if (taskInCtg == null) {
-                return R.error("浠诲姟绫诲瀷寮傚父");
+                throw new CoolException("浠诲姟绫诲瀷寮傚父");
             }
             List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                     .eq(Task::getTaskCtg, taskInCtg.getId()));
             if (!tasks.isEmpty()) {
-                return R.error("褰撳墠瀛樺湪鍑哄簱浠诲姟锛屾棤娉曞垏鎹㈠叆搴撴ā寮�");
+                throw new CoolException("褰撳墠瀛樺湪鍑哄簱浠诲姟锛屾棤娉曞垏鎹㈠叆搴撴ā寮�");
             }
 
             BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getConveyorNo, basConveyorSta.getConveyorNo()));
             if(basConveyor == null) {
-                return R.error("杈撻�佺嚎涓嶅瓨鍦�");
+                throw new CoolException("杈撻�佺嚎涓嶅瓨鍦�");
             }
 
             DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue());
             if(devpThread == null) {
-                return R.error("杈撻�佺嚎绾跨▼涓嶅瓨鍦�");
+                throw new CoolException("杈撻�佺嚎绾跨▼涓嶅瓨鍦�");
             }
 
             boolean result = devpThread.switchWorkMode(Integer.parseInt(destSite), WorkModeType.PAKIN_MODE.id);
             if (!result) {
-                return R.error("妯″紡鍒囨崲澶辫触");
+                throw new CoolException("妯″紡鍒囨崲澶辫触");
             }
         }
 
@@ -145,49 +148,119 @@
             priority = param.getPriority();
         }
 
-        Task task = new Task();
-        task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
-        task.setTaskNo(String.valueOf(Utils.getTaskNo("IN")));
-        task.setWmsTaskNo(param.getTaskNo());
-        task.setTaskSts(TaskStsType.NEW_INBOUND.sts);
-        task.setTaskCtg(taskCtg.getId());
-        task.setPriority(priority);
-        task.setOriginSite(param.getOriginSite());
-        task.setOriginLoc(null);
-        task.setDestSite(destSite);
-        task.setDestLoc(param.getDestLoc());
-        task.setZpallet(param.getBarcode());
-        task.setIoTime(new Date());
-        task.setStartTime(new Date());
-        task.setStatus(1);
-        task.setMemo("");
-        task.setShuttleNo(null);//绛夊緟涓荤嚎绋嬪垎閰嶅皬杞�
-        task.setRecordLoc("Y");//璁板綍搴撳瓨淇℃伅
-        task.setHostId(hostId);//涓存椂鎺у埗鍙厑璁竓ost涓�1
-        task.setMemo(param.getEndSite());
+        if (createWcsTaskParam != null) {
+            //杞彂agv
+            if (!createWcsTaskParam.getFrmPos().equals("06YZ0001")){
+                try {
+                    AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
+                    getInRequestParam(agvTaskCreateParam, createWcsTaskParam);
+                    String httpRequest = doHttpRequest(agvTaskCreateParam, "172.18.16.248:443", "/rcs/rtas/api/robot/controller/task/submit");
+                    if (!httpRequest.equals("SUCCESS")){
+                        throw new CoolException("杞彂AGV浠诲姟澶辫触" + httpRequest);
+                    }
 
-        boolean result = taskService.save(task);
-        if (!result) {
-            return R.error("鐢熸垚鍏ュ簱浠诲姟澶辫触锛�");
+                    Task task = new Task();
+                    task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
+                    task.setTaskNo(String.valueOf(Utils.getTaskNo("IN")));
+                    task.setWmsTaskNo(param.getTaskNo());
+                    task.setTaskSts(TaskStsType.NEW_INBOUND.sts);
+                    task.setTaskCtg(taskCtg.getId());
+                    task.setPriority(priority);
+                    task.setOriginSite(param.getOriginSite());
+                    task.setOriginLoc(null);
+                    task.setDestSite(destSite);
+                    task.setDestLoc(param.getDestLoc());
+                    task.setZpallet(param.getBarcode());
+                    task.setIoTime(new Date());
+                    task.setStartTime(new Date());
+                    task.setStatus(1);
+                    task.setMemo("");
+                    task.setShuttleNo(null);//绛夊緟涓荤嚎绋嬪垎閰嶅皬杞�
+                    task.setRecordLoc("Y");//璁板綍搴撳瓨淇℃伅
+                    task.setHostId(hostId);//涓存椂鎺у埗鍙厑璁竓ost涓�1
+                    task.setMemo(param.getEndSite());
+
+                    boolean result = taskService.save(task);
+                    if (!result) {
+                        throw new CoolException("鐢熸垚鍏ュ簱浠诲姟澶辫触锛�");
+                    }
+                }catch (Exception e){
+                    throw new CoolException("杞彂AGV浠诲姟鍑洪敊" + e.getMessage());
+                }
+            }else {
+                Task task = new Task();
+                task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
+                task.setTaskNo(String.valueOf(Utils.getTaskNo("IN")));
+                task.setWmsTaskNo(param.getTaskNo());
+                task.setTaskSts(TaskStsType.NEW_INBOUND.sts);
+                task.setTaskCtg(taskCtg.getId());
+                task.setPriority(priority);
+                task.setOriginSite(param.getOriginSite());
+                task.setOriginLoc(null);
+                task.setDestSite(destSite);
+                task.setDestLoc(param.getDestLoc());
+                task.setZpallet(param.getBarcode());
+                task.setIoTime(new Date());
+                task.setStartTime(new Date());
+                task.setStatus(1);
+                task.setMemo("");
+                task.setShuttleNo(null);//绛夊緟涓荤嚎绋嬪垎閰嶅皬杞�
+                task.setRecordLoc("Y");//璁板綍搴撳瓨淇℃伅
+                task.setHostId(hostId);//涓存椂鎺у埗鍙厑璁竓ost涓�1
+                task.setMemo(param.getEndSite());
+
+                boolean result = taskService.save(task);
+                if (!result) {
+                    throw new CoolException("鐢熸垚鍏ュ簱浠诲姟澶辫触锛�");
+                }
+            }
+        }else {
+            Task task = new Task();
+            task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
+            task.setTaskNo(String.valueOf(Utils.getTaskNo("IN")));
+            task.setWmsTaskNo(param.getTaskNo());
+            task.setTaskSts(TaskStsType.NEW_INBOUND.sts);
+            task.setTaskCtg(taskCtg.getId());
+            task.setPriority(priority);
+            task.setOriginSite(param.getOriginSite());
+            task.setOriginLoc(null);
+            task.setDestSite(destSite);
+            task.setDestLoc(param.getDestLoc());
+            task.setZpallet(param.getBarcode());
+            task.setIoTime(new Date());
+            task.setStartTime(new Date());
+            task.setStatus(1);
+            task.setMemo("");
+            task.setShuttleNo(null);//绛夊緟涓荤嚎绋嬪垎閰嶅皬杞�
+            task.setRecordLoc("Y");//璁板綍搴撳瓨淇℃伅
+            task.setHostId(hostId);//涓存椂鎺у埗鍙厑璁竓ost涓�1
+            task.setMemo(param.getEndSite());
+
+            boolean result = taskService.save(task);
+            if (!result) {
+                throw new CoolException("鐢熸垚鍏ュ簱浠诲姟澶辫触锛�");
+            }
         }
+
         return R.ok();
     }
 
     @Override
-    public R createOutTask(CreateOutTaskParam param) {
+    @Transactional
+    public R createOutTask(CreateOutTaskParam param, CreateWcsTaskParam createWcsTaskParam) {
         //鑾峰彇鍑哄簱浠诲姟绫诲瀷
         TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                 .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT))
                 .eq(TaskCtg::getStatus, 1));
         if (taskCtg == null) {
-            return R.error("浠诲姟绫诲瀷寮傚父");
+            throw new CoolException("浠诲姟绫诲瀷寮傚父");
         }
 
         Long hostId = 1L;//榛樿涓讳粨搴�
 
         Loc loc = locService.selectByLocNo(param.getOriginLoc());
         if (loc == null) {
-            return R.error("搴撲綅鍙蜂笉瀛樺湪");
+            throw new CoolException("搴撲綅鍙蜂笉瀛樺湪");
         }
 
         //鑾峰彇涓ユ牸妯″紡鍙傛暟
@@ -198,7 +271,7 @@
         }
 
         if (mapStrict && !loc.getLocStsFlag().equals("F")) {
-            return R.error("搴撲綅鐘舵�佷笉婊¤冻鍑哄簱鏉′欢");
+            throw new CoolException("搴撲綅鐘舵�佷笉婊¤冻鍑哄簱鏉′欢");
         }
 
         Task one = taskService.getOne(new LambdaQueryWrapper<Task>()
@@ -207,7 +280,7 @@
                 .eq(Task::getOriginLoc, param.getOriginLoc())
                 .eq(Task::getDestSite, param.getDestSite()));
         if (one != null) {
-            return R.error("浠诲姟宸插瓨鍦�");
+            throw new CoolException("浠诲姟宸插瓨鍦�");
         }
 
         String originSite = param.getOriginSite();
@@ -217,13 +290,13 @@
                     .eq(BasConveyorPath::getTypeNo, taskCtg.getId())
                     .eq(BasConveyorPath::getHostId, hostId)
                     .eq(BasConveyorPath::getStnNo, param.getDestSite()));
-            if(path == null) {
-                return R.error("鍐呯疆璺緞涓嶅瓨鍦�");
+            if (path == null) {
+                throw new CoolException("鍐呯疆璺緞涓嶅瓨鍦�");
             }
             Integer deviceNo = path.getDeviceNo();//鑾峰彇鎻愬崌鏈哄彿
             BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>().eq(BasLift::getLiftNo, deviceNo).eq(BasLift::getHostId, hostId));
-            if(basLift == null) {
-                return R.error("鎻愬崌鏈哄璞′笉瀛樺湪");
+            if (basLift == null) {
+                throw new CoolException("鎻愬崌鏈哄璞′笉瀛樺湪");
             }
             List<BasLiftStaDto> staList = JSON.parseArray(basLift.getSta(), BasLiftStaDto.class);
             BasLiftStaDto originStaDto = null;
@@ -235,7 +308,7 @@
             }
 
             if (originStaDto == null) {
-                return R.error("婧愮珯涓嶅瓨鍦�");
+                throw new CoolException("婧愮珯涓嶅瓨鍦�");
             }
 
             originSite = String.valueOf(originStaDto.getStaNo());
@@ -251,27 +324,27 @@
                     .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN))
                     .eq(TaskCtg::getStatus, 1));
             if (taskInCtg == null) {
-                return R.error("浠诲姟绫诲瀷寮傚父");
+                throw new CoolException("浠诲姟绫诲瀷寮傚父");
             }
             List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                     .eq(Task::getTaskCtg, taskInCtg.getId()));
             if (!tasks.isEmpty()) {
-                return R.error("褰撳墠瀛樺湪鍏ュ簱浠诲姟锛屾棤娉曞垏鎹㈠嚭搴撴ā寮�");
+                throw new CoolException("褰撳墠瀛樺湪鍏ュ簱浠诲姟锛屾棤娉曞垏鎹㈠嚭搴撴ā寮�");
             }
 
             BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getConveyorNo, basConveyorSta.getConveyorNo()));
-            if(basConveyor == null) {
-                return R.error("杈撻�佺嚎涓嶅瓨鍦�");
+            if (basConveyor == null) {
+                throw new CoolException("杈撻�佺嚎涓嶅瓨鍦�");
             }
 
             DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue());
-            if(devpThread == null) {
-                return R.error("杈撻�佺嚎绾跨▼涓嶅瓨鍦�");
+            if (devpThread == null) {
+                throw new CoolException("杈撻�佺嚎绾跨▼涓嶅瓨鍦�");
             }
 
             boolean result = devpThread.switchWorkMode(Integer.parseInt(originSite), WorkModeType.PAKOUT_MODE.id);
             if (!result) {
-                return R.error("妯″紡鍒囨崲澶辫触");
+                throw new CoolException("妯″紡鍒囨崲澶辫触");
             }
         }
 
@@ -303,39 +376,19 @@
 
         boolean result = taskService.save(task);
         if (!result) {
-            return R.error("鐢熸垚鍑哄簱浠诲姟澶辫触锛�");
+            throw new CoolException("鐢熸垚鍑哄簱浠诲姟澶辫触锛�");
         }
+
         return R.ok();
     }
 
     @Override
+    @Transactional
     public HashMap<String, Object> executeWcsTaskCache(CreateWcsTaskParam param) {
         HashMap<String, Object> map = new HashMap<>();
         String sta = "06YZ";
         String loc = "0601KW";
         if (param.getFrmPos().substring(0,4).equals(sta) && param.getToPos().substring(0,6).equals(loc)){
-            if (!param.getFrmPos().equals("06YZ0001")){
-                try {
-                    AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
-                    getInRequestParam(agvTaskCreateParam,param);
-                    String httpRequest = doHttpRequest(agvTaskCreateParam, "172.18.16.248:443", "/rcs/rtas/api/robot/controller/task/submit");
-                    if (!httpRequest.equals("SUCCESS")){
-                        map.put("success", "0");
-                        map.put("message", httpRequest);
-                        map.put("result", "");
-                        map.put("requestPK", param.getRequestPK());
-                        log.info("杩斿洖mes淇℃伅:"+ JSONObject.toJSONString(map));
-                        return map;
-                    }
-                }catch (Exception e){
-                    map.put("success", "0");
-                    map.put("message", "杞彂AGV浠诲姟鍑洪敊");
-                    map.put("result", "");
-                    map.put("requestPK", param.getRequestPK());
-                    log.info("杩斿洖mes淇℃伅:"+JSONObject.toJSONString(map));
-                    return map;
-                }
-            }
 
             CreateInTaskParam createInTaskParam = new CreateInTaskParam();
             createInTaskParam.setTaskNo(param.getRequestPK());
@@ -346,15 +399,7 @@
             createInTaskParam.setEndSite(param.getToPos());
             R inTask = null;
             try {
-                inTask = this.createInTask(createInTaskParam);
-            }catch (Exception e){
-                map.put("success", "0");
-                map.put("message", "鐢熸垚浠诲姟鍑洪敊");
-                map.put("result", "");
-                map.put("requestPK", param.getRequestPK());
-                log.info("杩斿洖mes淇℃伅:"+JSONObject.toJSONString(map));
-                return map;
-            }finally {
+                inTask = this.createInTask(createInTaskParam, param);
                 int code = (int) inTask.get("code");
                 if (code == 200){
                     map.put("success", "1");
@@ -367,6 +412,14 @@
                     map.put("result", "");
                     map.put("requestPK", param.getRequestPK());
                 }
+
+            }catch (Exception e){
+                map.put("success", "0");
+                map.put("message", e.getMessage());
+                map.put("result", "");
+                map.put("requestPK", param.getRequestPK());
+                log.info("杩斿洖mes淇℃伅:" + JSONObject.toJSONString(map));
+                return map;
             }
         } else if (param.getFrmPos().substring(0,6).equals(loc) && param.getToPos().substring(0,4).equals(sta)) {
             CreateOutTaskParam createOutTaskParam = new CreateOutTaskParam();
@@ -379,15 +432,8 @@
             createOutTaskParam.setZpallet(param.getContNo());
             R outTask = null;
             try {
-                outTask = this.createOutTask(createOutTaskParam);
-            }catch (Exception e){
-                map.put("success", "0");
-                map.put("message", "鐢熸垚浠诲姟鍑洪敊");
-                map.put("result", "");
-                map.put("requestPK", param.getRequestPK());
-                log.info("杩斿洖mes淇℃伅:"+JSONObject.toJSONString(map));
-                return map;
-            }finally {
+                outTask = this.createOutTask(createOutTaskParam, param);
+
                 int code = (int) outTask.get("code");
                 if (code == 200){
                     map.put("success", "1");
@@ -400,6 +446,14 @@
                     map.put("result", "");
                     map.put("requestPK", param.getRequestPK());
                 }
+
+            }catch (Exception e){
+                map.put("success", "0");
+                map.put("message", e.getMessage());
+                map.put("result", "");
+                map.put("requestPK", param.getRequestPK());
+                log.info("杩斿洖mes淇℃伅:"+JSONObject.toJSONString(map));
+                return map;
             }
 
         } else if (param.getFrmPos().substring(0,4).equals(sta) && param.getToPos().substring(0,4).equals(sta)) {
@@ -488,6 +542,13 @@
                     map.put("requestPK", param.getRequestPK());
                     log.info("杩斿洖mes淇℃伅:"+JSONObject.toJSONString(map));
                     return map;
+                }else {
+                    map.put("success", "1");
+                    map.put("message", "success");
+                    map.put("result", "");
+                    map.put("requestPK", param.getRequestPK());
+                    log.info("杩斿洖mes淇℃伅:"+JSONObject.toJSONString(map));
+                    return map;
                 }
             }catch (Exception e){
                 map.put("success", "0");

--
Gitblit v1.9.1