From d835d1b51f832889929cdf69010034a30ef44d02 Mon Sep 17 00:00:00 2001 From: Junjie <xjj@123> Date: 星期四, 17 十月 2024 13:57:29 +0800 Subject: [PATCH] # --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java | 571 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 544 insertions(+), 27 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 873cb42..6bcfefc 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 @@ -1,26 +1,42 @@ package com.zy.asrs.wcs.core.action; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.zy.asrs.wcs.common.ExecuteSupport; +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.LocStsType; +import com.zy.asrs.wcs.core.model.enums.MotionCtgType; import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType; -import com.zy.asrs.wcs.core.utils.NavigateMapUtils; -import com.zy.asrs.wcs.core.utils.RedisUtil; -import com.zy.asrs.wcs.core.utils.Utils; +import com.zy.asrs.wcs.core.model.enums.ShuttleTaskModeType; +import com.zy.asrs.wcs.core.service.BasShuttleService; +import com.zy.asrs.wcs.core.service.LocService; +import com.zy.asrs.wcs.core.utils.*; import com.zy.asrs.wcs.rcs.News; import com.zy.asrs.wcs.rcs.cache.SlaveConnection; import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant; +import com.zy.asrs.wcs.rcs.entity.BasShuttleOpt; import com.zy.asrs.wcs.rcs.entity.Device; +import com.zy.asrs.wcs.rcs.model.CommandResponse; import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType; 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.BasShuttleOptService; import com.zy.asrs.wcs.rcs.thread.ShuttleThread; +import com.zy.asrs.wcs.system.entity.Dict; +import com.zy.asrs.wcs.system.service.DictService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.List; +import java.util.*; @Component public class ShuttleAction { @@ -29,6 +45,20 @@ private RedisUtil redisUtil; @Autowired private NavigateMapUtils navigateMapUtils; + @Autowired + private BasShuttleService basShuttleService; + @Autowired + private LocService locService; + @Autowired + private ShuttleDispatcher shuttleDispatcher; + @Autowired + private ObjectMapper objectMapper; + @Autowired + private DictService dictService; + @Autowired + private ConveyorDispatcher conveyorDispatcher; + @Autowired + private BasShuttleOptService basShuttleOptService; public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) { ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); @@ -44,12 +74,23 @@ ShuttleRedisCommand redisCommand = new ShuttleRedisCommand(); redisCommand.setShuttleNo(assignCommand.getShuttleNo());//鍥涘悜绌挎杞﹀彿 - redisCommand.setWrkNo(assignCommand.getTaskNo());//宸ヤ綔鍙� + redisCommand.setTaskNo(assignCommand.getTaskNo());//宸ヤ綔鍙� redisCommand.setCommandStep(0);//鍛戒护鎵ц姝ュ簭 redisCommand.setAssignCommand(assignCommand);//鍛戒护 //浠诲姟鏁版嵁淇濆瓨鍒皉edis - if (redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand))) { - shuttleProtocol.setTaskNo(assignCommand.getTaskNo().intValue()); + if (redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect))) { + if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id + || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id + || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_LOC_NO.id + || assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id) { + //涓嬪彂琛岄┒璺緞 + CommandResponse response = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo()); + Boolean result = response.getResult(); + if (!result) { + return false; + } + } + shuttleProtocol.setSyncTaskNo(assignCommand.getTaskNo()); return true; } return false; @@ -60,7 +101,14 @@ if (obj == null) { return false; } - ShuttleRedisCommand redisCommand = JSON.parseObject(obj.toString(), ShuttleRedisCommand.class); + + ShuttleRedisCommand redisCommand = null; + try { + redisCommand = objectMapper.readValue(String.valueOf(obj), ShuttleRedisCommand.class); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + if (redisCommand == null) { return false; } @@ -75,10 +123,8 @@ return false; } - //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟銆佹爣璁颁负true銆佸瓨鍦ㄤ换鍔℃寚浠わ紝闇�瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠� - if (!shuttleProtocol.getIdle() - || shuttleProtocol.getTaskNo() == 0 - || !shuttleProtocol.getPakMk()) { + //鍒ゆ柇宸ヤ綔鍙锋槸鍚︾浉鍚� + if (!shuttleProtocol.getTaskNo().equals(taskNo)) { return false; } @@ -90,15 +136,46 @@ ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand(); int commandStep = redisCommand.getCommandStep(); + Integer mode = -1; + if(commandStep < commands.size()) { + //鍙栧嚭鍛戒护 + ShuttleCommand currentCommand = commands.get(commandStep); + mode = currentCommand.getMode(); + } + + //鍒ゆ柇璁惧鏄惁绌洪棽 + Integer finalMode = mode; + if (!shuttleThread.isDeviceIdle(new ExecuteSupport() { + @Override + public Boolean judgement() { + if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(finalMode)) {//鍏抽棴鍏呯數motion + return false;//涓嶉渶瑕佸垽鏂姸鎬� + } + return true;//闇�瑕佸垽鏂姸鎬� + } + })) { + return false; + } + // 瀹岀粨涓婁竴鏉″懡浠� + boolean updateCommand = false; if (commandStep != 0) { ShuttleCommand command = commands.get(commandStep - 1); if (command.getMode() == ShuttleCommandModeType.MOVE.id) { // 姝e父绉诲姩 if (command.getTargetLocNo().equals(shuttleProtocol.getCurrentLocNo())) { command.setComplete(true); + updateCommand = true; //瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰� - List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class);//杩涜娣卞害copy + List<NavigateNode> nodes = null; + try { + String nodesStr = objectMapper.writeValueAsString(command.getNodes()); + nodes = objectMapper.readValue(nodesStr, new TypeReference<List<NavigateNode>>() { + }); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + if (nodes != null) { NavigateNode targetNode = assignCommand.getNodes().get(assignCommand.getNodes().size() - 1);//鏈�缁堣妭鐐� NavigateNode node = nodes.get(nodes.size() - 1); @@ -115,29 +192,36 @@ // 鎵樼洏椤跺崌 //鍒ゆ柇鏄惁椤跺崌鍒颁綅 if (shuttleProtocol.getHasLift()) { - //鍒ゆ柇鏄惁鏈夌墿 - if (shuttleProtocol.getHasPallet()) { - command.setComplete(true); - } + command.setComplete(true); + updateCommand = true; +// //鍒ゆ柇鏄惁鏈夌墿 +// if (shuttleProtocol.getHasPallet()) { +// command.setComplete(true); +// } } } else if (command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) { // 鎵樼洏涓嬮檷鍛戒护 // 鍒ゆ柇鏄惁涓嬮檷鍒颁綅 if (!shuttleProtocol.getHasLift()) { command.setComplete(true); + updateCommand = true; } - } else if (command.getMode() == ShuttleCommandModeType.CHARGE.id) { - // 鍏呯數寮�鍏� + } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) { + // 鍏呯數寮� //鍒ゆ柇灏忚溅鍏呯數鐘舵�� if (shuttleProtocol.getHasCharge()) { command.setComplete(true); + updateCommand = true; } }else { command.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚 + updateCommand = true; } - // 鏇存柊redis鏁版嵁 - redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); + if(updateCommand) { + // 鏇存柊redis鏁版嵁 + redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect)); + } if (!command.getComplete()) { return false; @@ -152,30 +236,463 @@ if (assignCommand.getAuto()) { if (!assignCommand.getCharge()) { //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING); + shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING); }else { - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); + shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); } News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); // 鎵嬪姩浠诲姟 } else { //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅绌洪棽鐘舵�� - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); + shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); //浠诲姟鍙锋竻闆� - shuttleProtocol.setTaskNo(0); + shuttleThread.setSyncTaskNo(0); //鏍囪澶嶄綅 - shuttleProtocol.setPakMk(true); + shuttleThread.setPakMk(true); News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); } //鍒犻櫎redis - redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo()); + redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo()); return false;//绂佹鍐嶄笅鍙戝懡浠� } } + //鍙栧嚭鍛戒护 + ShuttleCommand command = commands.get(commandStep); + + // 涓嬪彂鍛戒护 + CommandResponse response = write(command, device); + + //淇濆瓨鍛戒护鏃ュ織 + BasShuttleOpt basShuttleOpt = new BasShuttleOpt(); + basShuttleOpt.setTaskNo(redisCommand.getTaskNo()); + basShuttleOpt.setShuttleNo(Integer.parseInt(device.getDeviceNo())); + + basShuttleOpt.setMode(ShuttleCommandModeType.get(command.getMode()).desc); + basShuttleOpt.setSourceLocNo(assignCommand.getSourceLocNo()); + basShuttleOpt.setDistLocNo(assignCommand.getLocNo()); + basShuttleOpt.setCommand(JSON.toJSONString(command)); + basShuttleOpt.setSystemStatus(JSON.toJSONString(shuttleProtocol)); + basShuttleOpt.setDeviceId(device.getId()); + basShuttleOpt.setDeviceWrk(String.valueOf(command.getTaskNo())); + basShuttleOpt.setResponse(response.getMessage());//鑾峰彇鍝嶅簲 + basShuttleOpt.setSendTime(new Date());//鎸囦护涓嬪彂鏃堕棿 + basShuttleOpt.setSend(response.getResult() ? 1 : 0); + basShuttleOpt.setHostId(device.getHostId()); + //淇濆瓨鍛戒护娴佹按 + basShuttleOptService.save(basShuttleOpt); + + if (!response.getResult()) { + News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); + return false; + } + + shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WORKING); + commandStep++; + //鏇存柊redis鏁版嵁 + redisCommand.setCommandStep(commandStep); + //浠诲姟鏁版嵁淇濆瓨鍒皉edis + redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand)); 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(false); + if (shuttleProtocol == null) { + return; + } + + //灏忚溅寮�鍚窇搴撴ā寮� + if (!shuttleProtocol.getMoveLoc()) { + return; + } + + //灏忚溅绌洪棽 + if (!shuttleThread.isIdle()) { + return; + } + + int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠妤煎眰 + + if (shuttleProtocol.getMoveType() == 0) {//璺戣建閬� + //鏍规嵁鍦板浘鏂瑰悜鍐冲畾璺憍鎴杫 + Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>() + .eq(Dict::getFlag, "direction_map") + .eq(Dict::getStatus, 1)); + if (dict == null) { + //璺戝簱缁撴潫 + 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; + } + String direction = dict.getValue(); + + if (direction.equals("y")) {//璺憍杞存柟鍚戯紝璺戝畬x杞村啀鍒囨崲y杞� + 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>() + .eq(Loc::getLocSts, LocStsType.O.val()) + .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 { + //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃� + Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo()); + if (task != null) { + shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//鍒囨崲y杞� + } + + if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { + //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱 + 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; + } + } + }else {//璺憏杞存柟鍚戯紝璺戝畬y杞村啀鍒囨崲x杞� + ArrayList<String> locs = new ArrayList<>(); + for (int i = shuttleProtocol.getYCurrent(); i <= shuttleProtocol.getYTarget(); i++) { + String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), i, lev); + locs.add(locNo); + } + + List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() + .eq(Loc::getLocSts, LocStsType.O.val()) + .in(Loc::getLocNo, locs)); + if (locList.isEmpty()) { + //绌哄簱浣� + shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 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 { + //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃� + Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo()); + if (task != null) { + shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//鍒囨崲x杞� + } + + if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { + //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱 + 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; + } + } + } + + } else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣� + //鏍规嵁鍦板浘鏂瑰悜鍐冲畾璺憍鎴杫 + Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>() + .eq(Dict::getFlag, "direction_map") + .eq(Dict::getStatus, 1)); + if (dict == null) { + //璺戝簱缁撴潫 + 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; + } + String direction = dict.getValue(); + + if (direction.equals("y")) {//璺憍杞存柟鍚戯紝璺戝畬x杞村啀鍒囨崲y杞� + Integer xCurrent = shuttleProtocol.getXCurrent(); + + //鑾峰彇寰呰窇搴撲綅鍙� + String locNo = Utils.getLocNo(xCurrent, shuttleProtocol.getYCurrent(), lev); + Loc target = locService.getOne(new LambdaQueryWrapper<Loc>() + .eq(Loc::getLocNo, locNo) + .eq(Loc::getLocSts, LocStsType.O.val()) + .eq(Loc::getHostId, device.getHostId())); + if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//搴撲綅涓嶅瓨鍦ㄦ垨灏忚溅宸插湪褰撳墠浣嶇疆 + shuttleProtocol.setXCurrent(xCurrent + 1); + if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { + //x杞磋窇瀹岋紝鍒囨崲y杞� + shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); + shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); + + if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { + //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱 + 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; + } + } + return; + } + + //璋冨害鍘诲簱浣� + Task task = shuttleDispatcher.generateMoveTask(device, locNo); + if (task == null) { + return;//璋冨害澶辫触 + } + + shuttleProtocol.setXCurrent(xCurrent + 1); + if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { + //x杞磋窇瀹岋紝鍒囨崲y杞� + shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); + shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); + + if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { + //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱 + 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; + } + } + + }else {//璺憏杞存柟鍚戯紝璺戝畬y杞村啀鍒囨崲x杞� + Integer yCurrent = shuttleProtocol.getYCurrent(); + + //鑾峰彇寰呰窇搴撲綅鍙� + String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), yCurrent, lev); + Loc target = locService.getOne(new LambdaQueryWrapper<Loc>() + .eq(Loc::getLocNo, locNo) + .eq(Loc::getLocSts, LocStsType.O.val()) + .eq(Loc::getHostId, device.getHostId())); + if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//搴撲綅涓嶅瓨鍦ㄦ垨灏忚溅宸插湪褰撳墠浣嶇疆 + shuttleProtocol.setYCurrent(yCurrent + 1); + if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { + //y杞磋窇瀹岋紝鍒囨崲x杞� + shuttleProtocol.setYCurrent(shuttleProtocol.getYStart()); + shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); + + if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { + //x杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱 + 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; + } + } + return; + } + + //璋冨害鍘诲簱浣� + Task task = shuttleDispatcher.generateMoveTask(device, locNo); + if (task == null) { + return;//璋冨害澶辫触 + } + + shuttleProtocol.setYCurrent(yCurrent + 1); + if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { + //y杞磋窇瀹岋紝鍒囨崲x杞� + shuttleProtocol.setYCurrent(shuttleProtocol.getYStart()); + shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); + + if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { + //x杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱 + 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; + } + } + + } + } 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());//鍒囨崲搴撲綅 + } + } + } + } else if (shuttleProtocol.getMoveType() == 4) {//鍙栨斁璐� + Integer xCurrent = shuttleProtocol.getXCurrent(); + if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊� + shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); + shuttleProtocol.setYCurrent(shuttleProtocol.getYStart()); + return; + } + + //鍒ゆ柇x杞磋揣浣嶆槸鍚︽斁婊� + boolean flag = true; + for (Loc loc : locService.list(new LambdaQueryWrapper<Loc>() + .eq(Loc::getHostId, device.getHostId()) + .eq(Loc::getRow, xCurrent) + .ge(Loc::getBay, shuttleProtocol.getYStart()) + .le(Loc::getBay, shuttleProtocol.getYTarget()))) { + if (loc.getLocSts() != LocStsType.F.val()) { + flag = false;//鏈弧 + break; + } + } + if (flag) { + shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); + return; + } + + //鎼滅储鏈夎揣搴撲綅 + List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>() + .eq(Loc::getLocSts, LocStsType.F.val()) + .eq(Loc::getHostId, device.getHostId()) + .notIn(Loc::getRow, xCurrent) + .eq(Loc::getStatus, 1)); + if (list.isEmpty()) { + return; + } + + Loc start = list.get(0); + + List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() + .eq(Loc::getHostId, device.getHostId()) + .eq(Loc::getStatus, 1) + .eq(Loc::getLocSts, LocStsType.O.val()) + .eq(Loc::getRow, xCurrent) + .orderByDesc(Loc::getBay) + .orderByAsc(Loc::getRow)); + if (locList.isEmpty()) { + return; + } + + Loc target = locList.get(0); + if (target == null) { + return; + } + + //璋冨害鍘荤洰鏍囦綅缃� + if (!shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) { + Task task = shuttleDispatcher.generateManuaTakeMoveTask(device, start.getLocNo(), target.getLocNo()); +// if(task != null) {//璋冨害鎴愬姛 +// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); +// } + } + } + } + + private synchronized CommandResponse write(ShuttleCommand command, Device device) { + CommandResponse response = new CommandResponse(false); + if (null == command) { + News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�"); + response.setMessage("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�"); + return response; + } + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); + if (command.getMode() == ShuttleCommandModeType.MOVE.id + || command.getMode() == ShuttleCommandModeType.IN_LIFT.id + || command.getMode() == ShuttleCommandModeType.OUT_LIFT.id) {//绉诲姩 + response = shuttleThread.move(command); + } else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id + || command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {//椤跺崌 + response = shuttleThread.lift(command); + } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id + || command.getMode() == ShuttleCommandModeType.CHARGE_CLOSE.id) {//鍏呯數 + response = shuttleThread.charge(command); + } else if (command.getMode() == ShuttleCommandModeType.RESET.id) {//澶嶄綅 + response = shuttleThread.reset(command); + } else if (command.getMode() == ShuttleCommandModeType.UPDATE_LOCATION.id) {//鏇存柊鍧愭爣 + response = shuttleThread.updateLocation(command); + } + +// News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戯紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", device.getDeviceNo(), JSON.toJSON(command)); + return response; + } + } -- Gitblit v1.9.1