自动化立体仓库 - WCS系统
Junjie
2023-03-27 87f00d0a2de9c22a56de6abd28806261adf38c10
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -10,15 +10,11 @@
import com.zy.asrs.mapper.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.LocTypeDto;
import com.zy.common.model.MatDto;
import com.zy.common.model.SearchLocParam;
import com.zy.common.model.StartupDto;
import com.zy.common.model.*;
import com.zy.common.model.enums.WrkChargeType;
import com.zy.common.service.CommonService;
import com.zy.common.service.erp.ErpService;
import com.zy.common.utils.CollectionUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.*;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.News;
@@ -28,6 +24,7 @@
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.protocol.CrnProtocol;
import com.zy.core.model.protocol.ShuttleProtocol;
@@ -94,6 +91,8 @@
    private OrderMapper orderMapper;
    @Autowired
    private OrderDetlMapper orderDetlMapper;
    @Autowired
    private RedisUtil redisUtil;
    /**
     * 组托
@@ -624,7 +623,93 @@
            // 只有当四向穿梭车空闲 并且无任务时才继续执行
            if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE && shuttleProtocol.getTaskNo() == 0) {
                //入出库逻辑
                //.....
                for (WrkMast wrkSts : wrkMastMapper.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 2))) {
                    //分配任务号
                    shuttleProtocol.setTaskNo(wrkSts.getWrkNo().shortValue());
                    //分配源库位
                    shuttleProtocol.setSourceLocNo(wrkSts.getSourceLocNo());
                    //分配目标库位
                    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));
                }
            } 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、
                    }
                }
            }
        }