Junjie
2023-03-28 ae35f8d3521741b87835c6122053ec1af449d4ab
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -22,10 +22,7 @@
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
import com.zy.core.model.*;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.command.LedCommand;
import com.zy.core.model.command.ShuttleCommand;
import com.zy.core.model.command.SteCommand;
import com.zy.core.model.command.*;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.model.protocol.StaProtocol;
@@ -631,91 +628,62 @@
                    //分配目标库位
                    shuttleProtocol.setLocNo(wrkSts.getLocNo());
                    //计算路径
                    List<NavigateNode> calc = NavigateUtils.calc(wrkSts.getSourceLocNo(), wrkSts.getLocNo(), "in");
                    //获取分段路径
                    ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
                    //将此map存入redis中
                    HashMap<String, Object> map = new HashMap<>();
                    //执行步序
                    map.put("step", 0);
                    //路径数据
                    map.put("path", data);
                    //工作号
                    map.put("wrk_no", wrkSts.getWrkNo());
                    //任务数据保存到redis
                    redisUtil.set("wrk_no_" + wrkSts.getWrkNo().shortValue(), JSON.toJSONString(map));
                    ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                    //四向穿梭车号
                    assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());
                    //任务号
                    assignCommand.setTaskNo(wrkSts.getWrkNo().shortValue());
                    //入出库模式
                    assignCommand.setTaskMode((short) 0);
                    //源库位
                    assignCommand.setSourceLocNo(wrkSts.getSourceLocNo());
                    //目标库位
                    assignCommand.setDistLocNo(wrkSts.getLocNo());
                    //下发任务
                    MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                }
            } else if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE && shuttleProtocol.getTaskNo() != 0) {
                //四向穿梭车空闲 并且有任务
                Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getTaskNo());
                HashMap map = JSON.parseObject(o.toString(), HashMap.class);
                //当前步序
                int step = Integer.parseInt(map.get("step").toString());
                //当前路径数据
                Object data = map.get("path");
                ArrayList pathList = JSON.parseObject(data.toString(), ArrayList.class);
                //取第一条路径
                Object o1 = pathList.get(step);
                ArrayList path = JSON.parseObject(o1.toString(), ArrayList.class);
                int size = path.size();
                //开始路径
                JSONObject startPath = JSON.parseObject(path.get(0).toString());
                System.out.println(startPath);
                //目标路径
                JSONObject endPath = JSON.parseObject(path.get(size - 1).toString());
                System.out.println(endPath);
                //下发命令
                ShuttleCommand command = new ShuttleCommand();
                command.setCommandWord((short) 1);
                command.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getIntValue("x"), startPath.getIntValue("y")));
                command.setMiddleCodeNum((short) 0);
                command.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getIntValue("x"), endPath.getIntValue("y")));
                command.setStartToDistDistance(1000);
                command.setMiddleToDistDistance(1000);
                command.setRunDirection(ShuttleRunDirection.get(startPath.get("direction").toString()).id);
                command.setPalletLift((short) 1);
                command.setForceMoveDistance(1000);
                command.setChargeSwitch((short) 2);
                command.setIOControl((short) 0);
                command.setRunSpeed((short) 1000);
                command.setRadarTmp((short) 0);
                command.setCommandEnd((short) 1);
                if (!MessageQueue.offer(SlaveType.Shuttle, shuttleProtocol.getShuttleNo().intValue(), new Task(2, command))) {
                    News.error("四向穿梭车命令下发失败,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
                } else {
                    News.info("四向穿梭车命令下发成功,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
                    //判断数据是否执行完成
                    if (step < size) {
                        //更新redis数据
                        //步序增加
                        step++;
                        map.put("step", step);
                        //任务数据保存到redis
                        redisUtil.set("wrk_no_" + map.get("wrk_no").toString(), JSON.toJSONString(map));
                    }else {
                        //已执行完成
                        //保存数据到数据库做流水
                        //删除redis
                        redisUtil.del("wrk_no_" + map.get("wrk_no").toString());
                        //。。。
                        //1、命令下方需要判断小车空闲状态
                        //2、
                    }
                }
            }
        }
    }
    /**
     * 四向穿梭车任务完成
     */
    public synchronized void shuttleFinished() {
        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
            //获取四向穿梭车信息
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                continue;
            }
            //四向穿梭车状态为等待确认
            if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id && shuttleProtocol.getTaskNo() != 0) {
                //将任务档标记为完成
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(shuttleProtocol.getTaskNo().intValue());
                if (wrkMast != null) {
                    wrkMast.setWrkSts(8L);
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        //设置四向穿梭车为空闲状态
                        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                        //任务号清零
                        shuttleProtocol.setTaskNo((short) 0);
                        News.error("四向穿梭车处于等待确认且任务完成状态,复位。堆垛机号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
                    } else {
                        News.error("四向穿梭车处于等待确认且任务完成状态,复位失败,但未找到工作档。四向穿梭车号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
                    }
                }
            }
        }
    }
    /**
     * 入出库  ===>>  堆垛机入出库作业下发
     */
    public synchronized void crnIoExecute(){