dubin
2025-08-26 7cf48f71577796759277ff0b413823d6131c365e
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -4,6 +4,7 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
@@ -94,6 +95,8 @@
    private WrkMastService wrkMastService;
    @Autowired
    private BasRgvMapService basRgvMapService;
    @Autowired
    private BasCrnOptService crnOptService;
    @Value("${wms.url}")
    private String wmsUrl;
@@ -150,7 +153,7 @@
                    errMsg = "右超限";
                    back = true;
                }
                if (!back && staProtocol.getWeight() > 1000) {
                if (!back && staProtocol.getWeight() > 15000) {
                    errMsg = "超重或未读取";
                    back = true;
                }
@@ -180,7 +183,7 @@
                    if (!staProtocol.isPakMk()) {
                        continue;
                    }
                    staProtocol.setWorkNo(wrkNo);
                    staProtocol.setWorkNo(wrkNo);//退回 工作号:10000
                    News.info("{}PLC入库回退:{},任务号:{}", inSta.getStaNo(), errMsg, wrkNo);
                    wrkNo++;
                    staProtocol.setStaNo(inSta.getBackSta().shortValue());
@@ -334,7 +337,7 @@
            }
        }
//        News.infoNoLog(""+mark+" - 0"+" - 组托  ===》执行完成");
        News.infoNoLog(""+mark+" - 0"+" - 组托  ===》执行完成");
    }
@@ -465,7 +468,7 @@
                // 退回
//                if (back) {
//                    log.info("errmsg: " + errMsg);
////                        News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg);
//                        News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg);
//                    MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(5, errMsg));
//                    if (!staProtocol.isLoading()) {
//                        continue;
@@ -500,7 +503,7 @@
//
//
//                    if (!Cools.isEmpty(barcode)) {
////                    News.info(""+mark+" - 1"+" - {}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
//                    News.info(""+mark+" - 1"+" - {}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
//                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
//                            continue;
//                        }
@@ -517,7 +520,7 @@
                    staProtocol = staProtocol.clone();
                }
//                // 入出库模式判断
                // 入出库模式判断
//                if (devpThread.ioMode != IoModeType.PAKIN_MODE) { continue; }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()) {
@@ -611,9 +614,9 @@
                    // 更新站点信息 且 下发plc命令
                    staProtocol.setWorkNo(wrkMast.getWrkNo());
                    if(staProtocol.getSiteId() < 400){
//                    if(staProtocol.getSiteId() < 400){
                        staProtocol.setStaNo(Short.valueOf(wrkMast.getStaNo().toString()));
                    }
//                    }
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    log.error("输送线下发5:" + wrkMast.getWrkNo() + "," + wrkMast.getStaNo());
@@ -1195,14 +1198,18 @@
                } else {
                    staProtocol = staProtocol.clone();
                }
                StaProtocol staProtocol1 = devpThread.getStation().get(crnStn.getStaNo() - 1);
                StaProtocol staProtocol1 = staProtocol.getSiteId()==101?devpThread.getStation().get(crnStn.getStaNo() + 1):devpThread.getStation().get(crnStn.getStaNo() - 1);
//                StaProtocol staProtocol1 = devpThread.getStation().get(crnStn.getStaNo() - 1);
//                StaProtocol staProtocol1 = devpThread.getStation().get(crnStn.getStaNo() + 1);
                if (staProtocol1 == null) {
                    News.infoNoLog("" + mark + " - 2" + " - 3" + " - 堆垛机出库站信息(staProtocol!=null继续执行,否则循环终止):staProtocol=" + staProtocol);
                    break;
                } else {
                    staProtocol1 = staProtocol1.clone();
                }
                StaProtocol staProtocol2 = devpThread.getStation().get(crnStn.getStaNo() - 2);
                StaProtocol staProtocol2 = staProtocol.getSiteId()==101?devpThread.getStation().get(crnStn.getStaNo() + 2):devpThread.getStation().get(crnStn.getStaNo());
//                StaProtocol staProtocol2 = devpThread.getStation().get(crnStn.getStaNo() - 2);
//                StaProtocol staProtocol2 = devpThread.getStation().get(crnStn.getStaNo() + 2);
                if (staProtocol2 == null) {
                    News.infoNoLog("" + mark + " - 2" + " - 3" + " - 堆垛机出库站信息(staProtocol!=null继续执行,否则循环终止):staProtocol=" + staProtocol);
                    break;
@@ -1210,7 +1217,7 @@
                    staProtocol2 = staProtocol2.clone();
                }
                //出入口输送线只允许存在一个托盘
                if(staProtocol.isLoading() || staProtocol1.isLoading() || staProtocol2.isLoading() ) {
                if(staProtocol.isLoading() || staProtocol1.isLoading() || staProtocol2.isLoading() || staProtocol.getWorkNo() != 0 || staProtocol1.getWorkNo() != 0 || staProtocol2.getWorkNo() != 0) {
                    break;
                }
@@ -1541,7 +1548,10 @@
            //  状态:等待确认 并且  任务完成位 = 1
            if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
                News.warnNoLog("" + mark + " - 0" + " - 开始执行对工作档的完成操作,任务号:" + crnProtocol.getTaskNo());
                if (crnProtocol.getTaskNo() == 9999){
                    crnThread.setResetFlag(true);
                    continue;
                }
                // 获取入库待确认工作档
                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
                if (wrkMast == null) {
@@ -1768,7 +1778,7 @@
                                LedCommand ledCommand = new LedCommand();
                                ledCommand.setWorkNo(dto.getWorkNo());
                                ledCommand.setIoType(1);
                                ledCommand.setTitle("全板入库");
                                ledCommand.setTitle("空板入库");
                                ledCommand.setLocNo(dto.getLocNo());
                                ledCommand.setStaNo(dto.getStaNo());
                                commands.add(ledCommand);
@@ -1805,7 +1815,7 @@
                }
            }
        }
//        News.infoNoLog(""+mark+" - 0"+" - 空栈板初始化入库,叉车入库站放货执行完成");
        News.infoNoLog(""+mark+" - 0"+" - 空栈板初始化入库,叉车入库站放货执行完成");
    }
    /**
@@ -3193,4 +3203,90 @@
        }
    }
    public synchronized void crnMove() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) {
                continue;
            }
            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
            if (basCrnp == null) {
                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
//                if ((crnProtocol.getCrnNo()==3 || crnProtocol.getCrnNo()==4) && crnProtocol.getBay()==0 && crnProtocol.getLevel() == 1) {
//                    continue;
//                }
//                if ((crnProtocol.getCrnNo()==1 || crnProtocol.getCrnNo()==2) && crnProtocol.getBay()==1 && crnProtocol.getLevel() == 1) {
//                    continue;
//                }
                if (crnProtocol.getCrnNo()==1 && crnProtocol.getBay()==1 && crnProtocol.getLevel() == 1) {
                    continue;
                }
                Page<BasCrnOpt> basCrnOptPage = crnOptService.selectPage(new Page<>(1, 1), new EntityWrapper<BasCrnOpt>().eq("crn_no", crn.getId()).orderBy("send_time", false));
                if (basCrnOptPage != null && basCrnOptPage.getRecords() != null && basCrnOptPage.getRecords().size() > 0) {
                    if (System.currentTimeMillis() - basCrnOptPage.getRecords().get(0).getSendTime().getTime() < 1000 * 60 * 3) {
                        continue;
                    }
                } else {
                    if (System.currentTimeMillis() - crnProtocol.getLastCommandTime() < 1000 * 60 * 2) {
                        continue;
                    }
                }
                List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                        .eq("crn_no", crn.getId())
                        .notIn("wrk_sts", 5, 14, 15)
                );
                if (!wrkMasts.isEmpty()) {
                    continue;
                }
                CrnSlave.CrnStn crnStn = crn.getCrnInStn().get(0);
                News.info("堆垛机无任务自动回入库口待机==>>" + crnProtocol.getCrnNo() + "号堆垛机");
                // 命令下发区 --------------------------------------------------------------------------
                CrnCommand crnCommand = new CrnCommand();
//                if (crnProtocol.getCrnNo()==3 || crnProtocol.getCrnNo()==4){
//                    crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
//                    crnCommand.setTaskNo((short) 9999); // 工作号
//                    crnCommand.setAckFinish((short) 0);  // 任务完成确认位
//                    crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式:  堆垛机移动
//                    crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 源库位排
//                    crnCommand.setSourcePosY((short) 0);     // 源库位列
//                    crnCommand.setSourcePosZ((short) 1);     // 源库位层
//                    crnCommand.setDestinationPosX((short) 0);     // 目标库位排
//                    crnCommand.setDestinationPosY((short) 0);     // 目标库位列
//                    crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
//                    crnCommand.setCommand((short) 1);
//                }else {
                    crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
                    crnCommand.setTaskNo((short) 9999); // 工作号
                    crnCommand.setAckFinish((short) 0);  // 任务完成确认位
//                    crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式:  堆垛机移动
                    crnCommand.setTaskMode(CrnTaskModeType.X_MOVE);//余姚锐麒回原点任务模式:  站位转移
                    crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 源库位排
                    crnCommand.setSourcePosY((short) 1);     // 源库位列
                    crnCommand.setSourcePosZ((short) 1);     // 源库位层
                    crnCommand.setDestinationPosX((short) 0);     // 目标库位排
                    crnCommand.setDestinationPosY((short) 0);     // 目标库位列
                    crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
                    crnCommand.setCommand((short) 1);
//                }
                if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
                    News.error("堆垛机移动命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
                }
                crnThread.setBackHpFlag(true);
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}