#
luxiaotao1123
2020-08-11 892b13a55e27a950993f3d0fafb997be5360177d
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -12,8 +12,7 @@
import com.zy.common.model.StartupDto;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.CrnStatusType;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.*;
import com.zy.core.model.CrnSlave;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.Task;
@@ -142,7 +141,7 @@
                    staProtocol.setStaNo(startupDto.getStaNo());
                    staProtocol.setPakMk(false);
                    staProtocol.setInreq1(false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task<>(4, staProtocol));
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol));
                    if (!result) {
                        throw new CoolException("更新plc站点信息失败");
                    }
@@ -221,7 +220,7 @@
                    staProtocol.setStaNo(wrkMast.getStaNo());
                    staProtocol.setPakMk(false);
                    staProtocol.setInreq1(false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task<>(4, staProtocol));
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol));
                    if (!result) {
                        throw new CoolException("更新plc站点信息失败");
                    }
@@ -261,9 +260,9 @@
                        continue;
                    }
                    // 更新工作档状态为14失败 todo:luxiaotao
                    if (crnProtocol.mode == 3 && crnProtocol.getTaskNo() == wrkMast.getWrkNo()
                    if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
                            && crnProtocol.statusType == CrnStatusType.IDLE
                            && crnProtocol.forkPos==0) {
                            && crnProtocol.forkPosType == CrnForkPosType.HOME) {
                        wrkMast.setWrkSts(14L);
                        wrkMast.setCrnEndTime(new Date());
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
@@ -276,14 +275,14 @@
                    // 1.复位堆垛机 更新堆垛机信息 且 下发plc命令 todo:luxiaotao
                    crnProtocol.setStatus(CrnStatusType.IDLE);
                    crnProtocol.setTaskNo((short)0);
                    if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task<>(4, crnProtocol))) {
                    if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(4, crnProtocol))) {
                        throw new CoolException("更新堆垛机信息失败");
                    }
                    // 2.下发站点信息
                    staProtocol.setWorkNo(wrkMast.getWrkNo());
                    staProtocol.setStaNo(wrkMast.getStaNo());
                    if (!MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task<>(4, staProtocol))) {
                    if (!MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol))) {
                        throw new CoolException("更新plc站点信息失败");
                    }
                }
@@ -327,8 +326,7 @@
                }
            }
            // 库位移转
            this.locToLoc();
            this.locToLoc(crn);
        }
    }
@@ -378,7 +376,7 @@
            crnCommand.setDestinationPosX(locMast.getRow1().shortValue()); // 排
            crnCommand.setDestinationPosY(locMast.getBay1().shortValue()); // 列
            crnCommand.setDestinationPosZ(locMast.getLev1().shortValue()); // 层
            if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task<>(2, crnCommand))) {
            if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
            }
        }
@@ -422,7 +420,7 @@
                crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
                crnCommand.setAckFinish((short) 1);  // 任务完成确认位
                if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task<>(2, crnCommand))) {
                if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                }
            }
@@ -432,8 +430,48 @@
    /**
     * 库位移转
     */
    private void locToLoc(){
    private void locToLoc(CrnSlave slave){
        // 获取工作档信息
        WrkMast wrkMast = wrkMastMapper.selectLocMove(slave.getId());
        if (null == wrkMast) {
            return;
        }
        // 获取源库位信息
        LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
        if (null == sourceSta) {
            log.error("工作档库位移转失败,原因:检索源库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
            return;
        }
        // 源库位  库位状态判断
        if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("S")) {
            return;
        }
        // 获取目标库位信息
        LocMast sta = locMastService.selectById(wrkMast.getLocNo());
        if (null == sta) {
            log.error("工作档库位移转失败,原因:检索目标库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
            return;
        }
        // 获取堆垛机信息 并 判断是否可入出
        BasCrnp basCrnp = basCrnpService.selectById(slave.getId());
        if (!basCrnp.getInEnable().equals("Y") && !basCrnp.getOutEnable().equals("Y")) {
            return;
        }
        // 命令下发区 --------------------------------------------------------------------------
        CrnCommand crnCommand = new CrnCommand();
        crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
        crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
        crnCommand.setAckFinish((short) 0);  // 任务完成确认位
        crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
        crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
        crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
        crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 源库位层
        crnCommand.setDestinationPosX(sta.getRow1().shortValue());     // 目标库位排
        crnCommand.setDestinationPosY(sta.getBay1().shortValue());     // 目标库位列
        crnCommand.setDestinationPosZ(sta.getLev1().shortValue());     // 目标库位层
        if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
            log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
        }
    }
    /**