From baebeeb3275273f96055c33f9eb6daa1c9ffde2f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 09 四月 2024 10:33:53 +0800
Subject: [PATCH] Merge branch 'Four-Way-Rack' of http://47.97.1.152:5880/r/zy-asrs-master into Four-Way-Rack

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/timer/DeviceTimer.java               |    6 +
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java   |    7 +
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/BasShuttleController.java |   67 ++++++++++++++++
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java            |  147 ++++++++++++++++++++++++++++++++++++
 4 files changed, 226 insertions(+), 1 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
index 0314e53..6f55847 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
@@ -2,15 +2,20 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.wcs.core.entity.BasShuttle;
+import com.zy.asrs.wcs.core.entity.Loc;
+import com.zy.asrs.wcs.core.entity.Task;
 import com.zy.asrs.wcs.core.model.NavigateNode;
 import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand;
 import com.zy.asrs.wcs.core.model.command.ShuttleCommand;
 import com.zy.asrs.wcs.core.model.command.ShuttleRedisCommand;
 import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType;
 import com.zy.asrs.wcs.core.service.BasShuttleService;
+import com.zy.asrs.wcs.core.service.LocService;
 import com.zy.asrs.wcs.core.utils.NavigateMapUtils;
 import com.zy.asrs.wcs.core.utils.RedisUtil;
+import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
 import com.zy.asrs.wcs.core.utils.Utils;
 import com.zy.asrs.wcs.rcs.News;
 import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
@@ -23,6 +28,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Component
@@ -34,6 +40,10 @@
     private NavigateMapUtils navigateMapUtils;
     @Autowired
     private BasShuttleService basShuttleService;
+    @Autowired
+    private LocService locService;
+    @Autowired
+    private ShuttleDispatcher shuttleDispatcher;
 
     public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) {
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
@@ -195,6 +205,143 @@
         return true;
     }
 
+    //璺戝簱绋嬪簭
+    public synchronized void moveLoc(Device device) {
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+        if (shuttleThread == null) {
+            return;
+        }
+
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null) {
+            return;
+        }
+
+        //灏忚溅绌洪棽涓旀湁璺戝簱绋嬪簭
+        if (!(shuttleThread.isIdle() && shuttleProtocol.getMoveLoc())) {
+            return;
+        }
+
+        int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠妤煎眰
+        if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+            //璺戝簱缁撴潫
+            shuttleProtocol.setMoveLoc(false);
+            shuttleProtocol.setMoveType(0);
+            shuttleProtocol.setXStart(0);
+            shuttleProtocol.setXTarget(0);
+            shuttleProtocol.setXCurrent(0);
+            shuttleProtocol.setYStart(0);
+            shuttleProtocol.setYTarget(0);
+            shuttleProtocol.setYCurrent(0);
+            return;
+        }
+
+        if (shuttleProtocol.getMoveType() == 0) {//璺戣建閬�
+            ArrayList<String> locs = new ArrayList<>();
+            for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) {
+                String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev);
+                locs.add(locNo);
+            }
+
+            List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
+                    .in(Loc::getLocNo, locs));
+            if (locList.isEmpty()) {
+                //绌哄簱浣�
+                shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+                return;
+            }
+
+            Loc start = locList.get(0);
+            Loc target = locList.get(locList.size() - 1);
+            //鍒ゆ柇灏忚溅鏄惁鍦ㄨ捣鐐逛綅缃�
+            if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//涓嶅湪璧风偣浣嶇疆锛岃皟搴﹀幓璧风偣浣嶇疆
+                shuttleDispatcher.generateMoveTask(device, start.getLocNo());
+            }else {
+                //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
+                if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
+                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
+                }else {
+                    shuttleDispatcher.generateMoveTask(device, start.getLocNo());
+                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+                }
+            }
+        } else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣�
+            Integer xCurrent = shuttleProtocol.getXCurrent();
+            if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊硷紝杩涜褰掗浂涓擸鏂瑰悜+1
+                shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
+                shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+                return;
+            }
+
+            Integer yCurrent = shuttleProtocol.getYCurrent();
+            String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+            Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
+                    .eq(Loc::getLocNo, locNo)
+                    .eq(Loc::getHostId, device.getHostId()));
+            if (target == null) {
+                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+                return;
+            }
+
+//            if (!target.getLocSts().equals("O")) {
+//                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+//                return;
+//            }
+
+            //璋冨害鍘荤洰鏍囦綅缃�
+            if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
+                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
+            } else {
+                shuttleDispatcher.generateMoveTask(device, target.getLocNo());
+                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+            }
+        } else if (shuttleProtocol.getMoveType() == 2) {//姣嶈建閬撳惊鐜窇
+            Integer xCurrent = shuttleProtocol.getXCurrent();
+            Integer yCurrent = shuttleProtocol.getYCurrent();
+
+            String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+            //璋冨害鍘荤洰鏍囦綅缃�
+            if (shuttleProtocol.getCurrentLocNo().equals(locNo)) {
+                if (yCurrent.equals(shuttleProtocol.getYStart())) {
+                    shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+                } else {
+                    shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+                }
+            } else {
+                Task result = shuttleDispatcher.generateMoveTask(device, locNo);
+                if (result != null) {//璋冨害鎴愬姛
+                    if (yCurrent.equals(shuttleProtocol.getYStart())) {
+                        shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//鍒囨崲搴撲綅
+                    } else {
+                        shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//鍒囨崲搴撲綅
+                    }
+                }
+            }
+        } else if (shuttleProtocol.getMoveType() == 3) {//瀛愯建閬撳惊鐜窇
+            Integer xCurrent = shuttleProtocol.getXCurrent();
+            Integer yCurrent = shuttleProtocol.getYCurrent();
+
+            String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+            //璋冨害鍘荤洰鏍囦綅缃�
+            if (shuttleProtocol.getCurrentLocNo().equals(locNo)) {
+                if (xCurrent.equals(shuttleProtocol.getXStart())) {
+                    shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+                } else {
+                    shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+                }
+            } else {
+                Task result = shuttleDispatcher.generateMoveTask(device, locNo);
+                if (result != null) {//璋冨害鎴愬姛
+                    if (xCurrent.equals(shuttleProtocol.getXStart())) {
+                        shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//鍒囨崲搴撲綅
+                    } else {
+                        shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//鍒囨崲搴撲綅
+                    }
+                }
+            }
+        }
+    }
+
     private synchronized boolean write(ShuttleCommand command, Device device) {
         if (null == command) {
             News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/BasShuttleController.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/BasShuttleController.java
index b5a01f7..cfca0db 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/BasShuttleController.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/BasShuttleController.java
@@ -23,6 +23,14 @@
 import com.zy.asrs.wcs.core.service.TaskService;
 import com.zy.asrs.wcs.core.utils.Utils;
 import com.zy.asrs.wcs.rcs.News;
+import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
+import com.zy.asrs.wcs.rcs.entity.Device;
+import com.zy.asrs.wcs.rcs.entity.DeviceType;
+import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
+import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
+import com.zy.asrs.wcs.rcs.service.DeviceService;
+import com.zy.asrs.wcs.rcs.service.DeviceTypeService;
+import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
 import com.zy.asrs.wcs.system.controller.BaseController;
 import com.zy.asrs.wcs.utils.ExcelUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,6 +57,10 @@
     private AnalyzeService analyzeService;
     @Autowired
     private MotionService motionService;
+    @Autowired
+    private DeviceService deviceService;
+    @Autowired
+    private DeviceTypeService deviceTypeService;
 
     @PreAuthorize("hasAuthority('core:basShuttle:list')")
     @PostMapping("/basShuttle/page")
@@ -120,10 +132,11 @@
         ExcelUtil.build(ExcelUtil.create(basShuttleService.list(), BasShuttle.class), response);
     }
 
+    //鎵嬪姩鎿嶄綔
     @PreAuthorize("hasAuthority('core:basShuttle:operator')")
     @PostMapping("/basShuttle/operator/shuttle")
     @Transactional
-    public R shuttleOperator(@RequestBody ShuttleOperatorParam param) {
+    public synchronized R shuttleOperator(@RequestBody ShuttleOperatorParam param) {
         if (Cools.isEmpty(param.getShuttleNo(), param.getShuttleTaskMode())) {
             return R.error("鍙傛暟涓虹┖");
         }
@@ -183,4 +196,56 @@
         return R.ok();
     }
 
+    //璺戝簱绯荤粺
+    @PreAuthorize("hasAuthority('core:basShuttle:operator')")
+    @PostMapping("/basShuttle/moveLoc")
+    @Transactional
+    public synchronized R shuttleMoveLoc(@RequestParam Integer shuttleNo,
+                            @RequestParam Integer moveType,
+                            @RequestParam Integer xStart,
+                            @RequestParam Integer xTarget,
+                            @RequestParam Integer yStart,
+                            @RequestParam Integer yTarget) {
+        DeviceType deviceType = deviceTypeService.getOne(new LambdaQueryWrapper<DeviceType>()
+                .eq(DeviceType::getFlag, String.valueOf(SlaveType.Shuttle))
+                .eq(DeviceType::getStatus, 1)
+                .eq(DeviceType::getHostId, getHostId()));
+        if (deviceType == null) {
+            return R.error();
+        }
+
+        Device device = deviceService.getOne(new LambdaQueryWrapper<Device>()
+                .eq(Device::getDeviceType, deviceType.getId())
+                .eq(Device::getStatus, 1)
+                .eq(Device::getHostId, getHostId())
+                .eq(Device::getDeviceNo, shuttleNo));
+        if (device == null) {
+            return R.error();
+        }
+
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+        if (shuttleThread == null) {
+            return R.error();
+        }
+
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null) {
+            return R.error();
+        }
+
+        if (!shuttleThread.isIdle()) {
+            return R.error("灏忚溅蹇欑涓�");
+        }
+
+        shuttleProtocol.setMoveLoc(true);//寮�鍚窇搴�
+        shuttleProtocol.setMoveType(moveType);
+        shuttleProtocol.setXStart(xStart);
+        shuttleProtocol.setXTarget(xTarget);
+        shuttleProtocol.setXCurrent(xStart);
+        shuttleProtocol.setYStart(yStart);
+        shuttleProtocol.setYTarget(yTarget);
+        shuttleProtocol.setYCurrent(yStart);
+        return R.ok();
+    }
+
 }
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/timer/DeviceTimer.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/timer/DeviceTimer.java
index 6446488..c127569 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/timer/DeviceTimer.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/timer/DeviceTimer.java
@@ -4,12 +4,15 @@
 import com.zy.asrs.wcs.core.action.LiftAction;
 import com.zy.asrs.wcs.core.action.ShuttleAction;
 import com.zy.asrs.wcs.core.utils.RedisUtil;
+import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
 import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
 import com.zy.asrs.wcs.rcs.entity.Device;
 import com.zy.asrs.wcs.rcs.entity.DeviceType;
 import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
+import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
 import com.zy.asrs.wcs.rcs.service.DeviceService;
 import com.zy.asrs.wcs.rcs.service.DeviceTypeService;
+import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -55,6 +58,9 @@
                 //瀛樺湪浠诲姟闇�瑕佹墽琛�
                 boolean result = shuttleAction.executeWork(device, taskNo);
             }
+
+            //灏忚溅绌洪棽涓旀湁璺戝簱绋嬪簭
+            shuttleAction.moveLoc(device);
         }
     }
 
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java
index bee13fe..fe13fcb 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java
@@ -441,6 +441,13 @@
 
     @Override
     public boolean isChargingCompleted() {
+        if (this.shuttleProtocol.getBatteryPower() == null) {
+            return false;
+        }
+
+        if (Integer.valueOf(this.shuttleProtocol.getBatteryPower()) >= 100) {
+            return true;
+        }
         return false;
     }
 

--
Gitblit v1.9.1