zc
2025-05-17 c946b206b0923e8b9567a529b8fd5d2d684c8265
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -38,6 +38,8 @@
import com.zy.core.thread.BarcodeThread;
import com.zy.core.thread.LedThread;
import com.zy.core.thread.SiemensDevpThread;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -93,7 +95,8 @@
    private WrkMastService wrkMastService;
    @Autowired
    private BasRgvMapService basRgvMapService;
    @Autowired
    private ConfigService configService;
    @Value("${wms.url}")
    private String wmsUrl;
@@ -284,64 +287,64 @@
     * 入库站,根据条码扫描生成入库工作档,工作状态 1 ==>> 2
     */
    public synchronized void generateStoreWrkFile0(Integer mark) {
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库口
            for (DevpSlave.Sta inSta : devp.getInSta()) {
                if (inSta.getStaNo() != 1035) {
                    continue;
                }
                // 获取入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                // 判断是否满足入库条件
                if (!staProtocol.isLoading()) {
                    continue;
                }
                if (staProtocol.isAutoing() && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() == 9999)
                        && staProtocol.isPakMk()) {
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行");
                    // 判断重复工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
                    if (wrkMast == null) {
                        continue;
                    }
                    // 命令下发区 --------------------------------------------------------------------------
                    // 更新站点信息 且 下发plc命令
                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    log.error("输送线下发3:" + wrkMast.getWrkNo() + "," + wrkMast.getStaNo());
                    if (result) {
                        // 更新工作主档
                        wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
                        wrkMast.setModiTime(new Date());
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            News.error("" + mark + " - 1" + " - 更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
                        }
                    } else {
                        News.error("" + mark + " - 2" + " - 发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                    }
                } else {
                    News.errorNoLog("" + mark + " - 6" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isLoading() + "、可入信号:" + staProtocol.isInEnable()
                            + "、空板信号:" + staProtocol.isEmptyMk() + "、工作号:" + staProtocol.getWorkNo()
                            + "、锁定标记" + staProtocol.isPakMk() + "、入库印记:" + staProtocol.getStamp());
                }
            }
        // 获取入库站信息
        SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
        StaProtocol staProtocol = devpThread.getStation().get(1135);
        if (staProtocol == null) {
            return;
        } else {
            staProtocol = staProtocol.clone();
        }
//        News.infoNoLog(""+mark+" - 0"+" - wms入库  ===》执行完成");
        // 判断是否满足入库条件
        if (!staProtocol.isLoading()) {
            return;
        }
        if (staProtocol.isAutoing()
                && !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() == 9999)
                && staProtocol.isPakMk()) {
            News.warnNoLog("" + mark + " - 0" + " - 开始执行");
            // 判断重复工作档
            WrkMast wrkMast = wrkMastMapper.selectPakInStep11(1135);
            if (wrkMast == null) {
                return;
            }
            if (wrkMast.getPltType().shortValue() != staProtocol.getFinishWorkNo()) {
                log.info("工作档和完结工作号不匹配,{},{}", wrkMast.getPltType(), staProtocol.getFinishWorkNo());
                return;
            }
            Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "2.5F_Mode"));
            if (Cools.isEmpty(config) || config.getValue().equals("false")) {
                return;
            }
            if (!config.getValue().equalsIgnoreCase("1")) {
                log.info("模式不对1");
                return;
            }
            // 命令下发区 --------------------------------------------------------------------------
            // 更新站点信息 且 下发plc命令
            staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
            staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
            devpThread.setPakMk(staProtocol.getSiteId(), false);
            boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
            log.error("输送线下发3:" + wrkMast.getWrkNo() + "," + wrkMast.getStaNo());
            if (result) {
                // 更新工作主档
                wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
                wrkMast.setModiTime(new Date());
                if (wrkMastMapper.updateById(wrkMast) == 0) {
                    News.error("" + mark + " - 1" + " - 更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
                }
            } else {
                News.error("" + mark + " - 2" + " - 发布命令至输送线队列失败!!! [plc编号:{}]", 1);
            }
        } else {
            News.errorNoLog("" + mark + " - 6" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isLoading() + "、可入信号:" + staProtocol.isInEnable()
                    + "、空板信号:" + staProtocol.isEmptyMk() + "、工作号:" + staProtocol.getWorkNo()
                    + "、锁定标记" + staProtocol.isPakMk() + "、入库印记:" + staProtocol.getStamp());
        }
    }
@@ -353,11 +356,19 @@
            // 遍历拣料入库口
            for (DevpSlave.Sta pickSta : devp.getPickSta()) {
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
                if (barcodeThread == null) {
//                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
//                if (barcodeThread == null) {
//                    continue;
//                }
                // 获取拣料入库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                String barcode = barcodeThread.getBarcode();
                String barcode = staProtocol.getBarcode();
                if (!Cools.isEmpty(barcode)) {
//                    News.info(""+mark+" - 1"+" - {}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
                    if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
@@ -367,14 +378,6 @@
                    continue;
                }
                // 获取拣料入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
//                // 入出库模式判断
//                if (devpThread.ioMode != IoModeType.PAKIN_MODE) { continue; }
@@ -466,7 +469,7 @@
                    // 更新站点信息 且 下发plc命令
                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                    staProtocol.setStaNo((short) 161);
                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    log.error("输送线下发5:" + wrkMast.getWrkNo() + "," + wrkMast.getStaNo());
@@ -507,11 +510,8 @@
                        && staProtocol.isPakMk()) {
                    // 获取条码扫描仪信息
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
                    if (barcodeThread == null) {
                        continue;
                    }
                    String barcode = barcodeThread.getBarcode();
                    String barcode = staProtocol.getBarcode();
                    if (!Cools.isEmpty(barcode)) {
//                        log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
                        if ("00000000".equals(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
@@ -605,7 +605,7 @@
                                try {
                                    // 更新站点信息 且 下发plc命令
                                    staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                                    staProtocol.setStaNo((short) 161);
                                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
@@ -701,7 +701,7 @@
                        }
                        // 更新工作档状态为14失败
                        if (crnStn.getStaNo() == 1035) {
                        if (wrkMast.getStaNo() == 1135) {
                            wrkMast.setWrkSts(107L);
                        } else {
                            wrkMast.setWrkSts(14L);
@@ -734,14 +734,14 @@
     */
    public synchronized void toSxk(Integer mark) {
        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
        for (DevpSlave devpSlave : slaveProperties.getDevp()) {
            // 遍历堆垛机出库站
            for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
                if (crnStn.getStaNo() != 1035) {
            for (DevpSlave.Sta crnStn : devpSlave.getOutSta()) {
                if (crnStn.getStaNo() != 1135) {
                    continue;
                }
                // 获取堆垛机出库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devpSlave.getId());
                StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                if (staProtocol == null) {
                    continue;
@@ -754,6 +754,9 @@
                    if (wrkMast == null) {
                        continue;
                    }
                    if (wrkMast.getWrkNo().shortValue() != staProtocol.getFinishWorkNo()) {
                        continue;
                    }
                    // 判断工作档条件
                    if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
                        continue;
@@ -761,8 +764,8 @@
                    // 下发站点信息
                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                    staProtocol.setStaNo(RouteUtils.CrnStaEnd(1031, 1135));
                    if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
                    staProtocol.setStaNo((short) 1031);
                    if (!MessageQueue.offer(SlaveType.Devp, devpSlave.getId(), new Task(2, staProtocol))) {
                        log.info(staProtocol.getWorkNo() + "," + staProtocol.getStaNo() + "输送线出库命令下发失败222");
                        continue;
                    } else {
@@ -920,45 +923,91 @@
                News.error("" + mark + " - 1" + " - 2" + " - 入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                continue;
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
                    && staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) {
                flag = true;
            }
            if (!flag) {
                News.errorNoLog("" + mark + " - 1" + " - 3" + " - 堆垛机入库站信息(以下需要全true):"
                        + "自动信号" + staProtocol.isAutoing() + "有物信号" + staProtocol.isLoading()
                        + "工作号>0" + staProtocol.getWorkNo() + "可入信号" + staProtocol.isInEnable()
                        + "能入信号(wms设置).equals(\"Y\")" + staDetl.getCanining());
                continue;
            }
            // 获取工作状态为2(设备上走)的入库工作档
            WrkMast wrkMast = wrkMastMapper.selectPakInStep2(slave.getId(), staProtocol.getWorkNo().intValue(), crnStn.getStaNo());
            if (null == wrkMast) {
                News.infoNoLog("" + mark + " - 1" + " - 4" + " - 查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
            WrkMast wrkMast;
            LocMast locMast;
            if (crnStn.getStaNo() == 1131) {
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getFinishWorkNo() > 0
                        && staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) {
                    flag = true;
                }
                if (!flag) {
                    News.errorNoLog("" + mark + " - 1" + " - 3" + " - 堆垛机入库站信息(以下需要全true):"
                            + "自动信号" + staProtocol.isAutoing() + "有物信号" + staProtocol.isLoading()
                            + "工作号>0" + staProtocol.getWorkNo() + "可入信号" + staProtocol.isInEnable()
                            + "能入信号(wms设置).equals(\"Y\")" + staDetl.getCanining());
                    continue;
                }
                // 获取工作状态为2(设备上走)的入库工作档
                wrkMast = wrkMastMapper.selectPakInStep2(slave.getId(), staProtocol.getFinishWorkNo().intValue(), crnStn.getStaNo());
                if (null == wrkMast) {
                    News.infoNoLog("" + mark + " - 1" + " - 4" + " - 查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getFinishWorkNo());
//                log.error("查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
                continue;
            }
            // 获取库位信息
            LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
            if (locMast == null) {
                News.error("" + mark + " - 1" + " - 5" + " - 查询库存无数据--库位号{}", wrkMast.getLocNo());
                continue;
            }
            if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
                News.error("" + mark + " - 1" + " - 6" + " - 入库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
                continue;
            }
                    continue;
                }
                // 获取库位信息
                locMast = locMastService.selectById(wrkMast.getLocNo());
                if (locMast == null) {
                    News.error("" + mark + " - 1" + " - 5" + " - 查询库存无数据--库位号{}", wrkMast.getLocNo());
                    continue;
                }
                if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
                    News.error("" + mark + " - 1" + " - 6" + " - 入库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
                    continue;
                }
            // 堆垛机控制过滤
            if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                // 堆垛机控制过滤
                if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
//                News.infoNoLog(""+mark+" - 1"+" - 7"+" - 堆垛机控制过滤:堆垛机是否空闲={},任务号={}", crnProtocol.getStatusType(),crnProtocol.getTaskNo());
                continue;
                    continue;
                }
                // 已经存在吊车执行任务时,则过滤
                if (wrkMastMapper.selectWorking(slave.getId()) != null) {
                    continue;
                }
            } else {
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
                        && staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) {
                    flag = true;
                }
                if (!flag) {
                    News.errorNoLog("" + mark + " - 1" + " - 3" + " - 堆垛机入库站信息(以下需要全true):"
                            + "自动信号" + staProtocol.isAutoing() + "有物信号" + staProtocol.isLoading()
                            + "工作号>0" + staProtocol.getWorkNo() + "可入信号" + staProtocol.isInEnable()
                            + "能入信号(wms设置).equals(\"Y\")" + staDetl.getCanining());
                    continue;
                }
                // 获取工作状态为2(设备上走)的入库工作档
                wrkMast = wrkMastMapper.selectPakInStep2(slave.getId(), staProtocol.getWorkNo().intValue(), crnStn.getStaNo());
                if (null == wrkMast) {
                    News.infoNoLog("" + mark + " - 1" + " - 4" + " - 查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
//                log.error("查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
                    continue;
                }
                // 获取库位信息
                locMast = locMastService.selectById(wrkMast.getLocNo());
                if (locMast == null) {
                    News.error("" + mark + " - 1" + " - 5" + " - 查询库存无数据--库位号{}", wrkMast.getLocNo());
                    continue;
                }
                if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
                    News.error("" + mark + " - 1" + " - 6" + " - 入库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
                    continue;
                }
                // 堆垛机控制过滤
                if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
//                News.infoNoLog(""+mark+" - 1"+" - 7"+" - 堆垛机控制过滤:堆垛机是否空闲={},任务号={}", crnProtocol.getStatusType(),crnProtocol.getTaskNo());
                    continue;
                }
                // 已经存在吊车执行任务时,则过滤
                if (wrkMastMapper.selectWorking(slave.getId()) != null) {
                    continue;
                }
            }
            // 已经存在吊车执行任务时,则过滤
            if (wrkMastMapper.selectWorking(slave.getId()) != null) {
                continue;
            }
            // 双深库位且浅库位有货,则需先对浅库位进行库位移转
            if (Utils.isDeepLoc(slaveProperties, wrkMast.getLocNo())) {
@@ -1069,6 +1118,15 @@
//            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo());
            List<WrkMast> wrkMasts = wrkMastMapper.selectPakOutStep11(slave.getId(), crnStn.getStaNo());
            for (WrkMast wrkMast : wrkMasts) {
                if (crnStn.getStaNo() == 1131) {
                    Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "2.5F_Mode"));
                    if (Cools.isEmpty(config) || config.getValue().equals("false")) {
                        return;
                    }
                    if (!config.getValue().equalsIgnoreCase("2")) {
                        return;
                    }
                }
                if (wrkMast == null) {
                    continue;
                }