Junjie
2025-07-22 cbeff29a3261cb13ed3c5aada8bbd9cc4c1fee72
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.BasCrnErrorMapper;
@@ -1634,13 +1635,43 @@
                    continue;
                }
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode());
                if (barcodeThread == null) {
                    continue;
                }
                // 站点条件判断
                if (staProtocol.isAutoing()
                        && staProtocol.isInEnable()
                        && staProtocol.isEmptyMk()
                        && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999)
                        && staProtocol.isPakMk()) {
                        && staProtocol.isPakMk()
                        && staProtocol.getEmptyInType() == 1
                ) {
                    News.warnNoLog(""+mark+" - 0"+" - 开始执行:空栈板初始化入库,叉车入库站放货");
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        News.info(""+mark+" - 1"+" - {}号条码扫描器检测条码信息:{}", emptyInSta.getBarcode(), barcode);
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
                            News.info(""+mark+" - 2"+" - 扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
                            // led 异常显示
                            if (ledThread != null) {
                                String errorMsg = "扫码失败,请重试";
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                            }
                            continue;
                        }
                    } else {
                        News.info(""+mark+" - 3"+" - 扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "扫码失败,请重试";
                            MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
                    }
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -1649,6 +1680,7 @@
                        param.setIoType(10);
                        param.setSourceStaNo(emptyInSta.getStaNo());
                        param.setLocType1(locTypeDto.getLocType1());
                        param.setBarcode(barcode);
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
@@ -1668,31 +1700,7 @@
                                News.errorNoLog(""+mark+" - 1"+" - 更新plc站点信息失败");
                                throw new CoolException("更新plc站点信息失败");
                            }
                            if (ledThread != null) {
                                // 命令集合
                                List<LedCommand> commands = new ArrayList<>();
                                // 组装命令
                                LedCommand ledCommand = new LedCommand();
                                ledCommand.setWorkNo(dto.getWorkNo());
                                ledCommand.setIoType(1);
                                ledCommand.setTitle("全板入库");
                                ledCommand.setLocNo(dto.getLocNo());
                                ledCommand.setStaNo(dto.getStaNo());
                                commands.add(ledCommand);
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, commands));
//                                ledThread.errorReset();
                            }
                        } else {
                            staProtocol.setWorkNo((short)9992);
                            staProtocol.setStaNo(emptyInSta.getBackSta().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                News.errorNoLog(""+mark+" - 2"+" - 更新plc站点信息失败");
                                throw new CoolException("更新plc站点信息失败");
                            }
                            if (ledThread != null) {
                                String errorMsg = jsonObject.getString("msg");
                                if (!Cools.isEmpty(errorMsg)) {
@@ -1703,9 +1711,115 @@
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    }
                } else {
                    News.errorNoLog(""+mark+" - 4"+" - 站点信息不符合入库条件!!!"+" 自动信号:"+staProtocol.isAutoing()+"、可入信号:" + staProtocol.isInEnable()
                            +"、空板信号:"+ staProtocol.isEmptyMk()+"、工作号:" + staProtocol.getWorkNo()
                            +"、锁定标记"+ staProtocol.isPakMk());
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 空栈板初始化入库,叉车入库站放货执行完成");
    }
    /**
     * 空托盘入库-产线
     */
    public synchronized void storeEmptyPltLine(Integer mark) {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历空板入库口
            for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) {
                // 获取空板入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(emptyInSta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                LedThread ledThread = null;
                if (!Cools.isEmpty(emptyInSta.getLed()))  {
                    ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
                }
                if (!staProtocol.isLoading()){
                    continue;
                }
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode());
                if (barcodeThread == null) {
                    continue;
                }
                // 站点条件判断
                if (staProtocol.isAutoing()
                        && staProtocol.isInEnable()
                        && staProtocol.isEmptyMk()
                        && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999)
                        && staProtocol.isPakMk()
                        && staProtocol.getEmptyInType() == 2
                ) {
                    News.warnNoLog(""+mark+" - 0"+" - 开始执行:空栈板初始化入库,叉车入库站放货");
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        News.info(""+mark+" - 1"+" - {}号条码扫描器检测条码信息:{}", emptyInSta.getBarcode(), barcode);
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
                            News.info(""+mark+" - 2"+" - 扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
                            // led 异常显示
                            if (ledThread != null) {
                                String errorMsg = "扫码失败,请重试";
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                            }
                            continue;
                        }
                    } else {
                        News.info(""+mark+" - 3"+" - 扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "扫码失败,请重试";
                            MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
                    }
                    WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                            .eq("barcode", barcode)
                    );
                    if(wrkMast != null) {
                        continue;
                    }
                    int workNo = commonService.getWorkNo(3);
                    // 生成工作档
                    WrkMast wrkMast1 = new WrkMast();
                    wrkMast1.setWrkNo(workNo);
                    wrkMast1.setIoTime(new Date());
                    wrkMast1.setWrkSts(2L); // 工作状态:设备上走
                    wrkMast1.setIoType(3); // 入出库状态:3.站到站
                    wrkMast1.setIoPri(13D); // 优先级
                    wrkMast1.setSourceStaNo(emptyInSta.getStaNo());
                    wrkMast1.setStaNo(1007);
                    wrkMast1.setBarcode(barcode);
                    // 操作人员数据
                    wrkMast1.setAppeTime(new Date());
                    wrkMast1.setModiTime(new Date());
                    boolean res = wrkMastService.insert(wrkMast1);
                    if (!res) {
                        throw new CoolException("保存工作档失败");
                    }
                    // 更新站点信息 且 下发plc命令
                    staProtocol.setWorkNo((short) workNo);
                    staProtocol.setStaNo((short) 2003);
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    if (!result) {
                        News.errorNoLog(""+mark+" - 1"+" - 更新plc站点信息失败");
                        throw new CoolException("更新plc站点信息失败");
                    }
                } else {
                    News.errorNoLog(""+mark+" - 4"+" - 站点信息不符合入库条件!!!"+" 自动信号:"+staProtocol.isAutoing()+"、可入信号:" + staProtocol.isInEnable()
                            +"、空板信号:"+ staProtocol.isEmptyMk()+"、工作号:" + staProtocol.getWorkNo()
@@ -2429,6 +2543,11 @@
                    continue;
                }
                if (wrkMast.getIoType() == 3) {
                    //站到站走另外一个方法
                    continue;
                }
                Integer devpId = null;
                Integer devpStaNo = null;
                String locNo = null;
@@ -2478,6 +2597,86 @@
        News.infoNoLog(""+mark+" - 0"+" - 对工作档的完成操作执行完成");
    }
    // RGV  ===>> 执行对RGV工作档的完成操作 站到站
    public synchronized void rgvFinished2(Integer mark) {
        for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
            // 获取RGV信息
            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId());
            if (rgvThread == null) {
                continue;
            }
            RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
            if (rgvProtocol == null) {
                continue;
            }
            //  状态:等待确认 并且  任务完成位 = 1
            if (rgvProtocol.statusType1 == RgvStatusType.WAITING && rgvProtocol.getTaskNo1() != 0) {
                News.warnNoLog(""+mark+" - 0"+" - 开始执行对RGV工作档的完成操作");
                // 获取入库待确认工作档
                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue());
                if (wrkMast == null) {
                    News.error(""+mark+" - 1"+" - RGV处于等待确认且任务完成状态,但未找到工作档。RGV号={},工作号={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
                    continue;
                }
                if (wrkMast.getWrkSts() != 201) {
                    continue;
                }
                if (wrkMast.getIoType() != 3) {
                    //不是站到站
                    continue;
                }
                Integer devpId = 2;
                Integer devpStaNo = 2002;
                // 获取入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
                StaProtocol staProtocol = devpThread.getStation().get(devpStaNo);
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing()
                        && staProtocol.isLoading()
                        && staProtocol.getWorkNo() == 0
                ) {
                    short locType2 = 1;
                    String barcode = wrkMast.getBarcode();
                    if (barcode.startsWith("11")) {
                        locType2 = 1;
                    } else if (barcode.startsWith("13")) {
                        locType2 = 2;
                    } else if (barcode.startsWith("16")) {
                        locType2 = 3;
                    } else {
                        continue;
                    }
                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                    staProtocol.setPalletSize(locType2);
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devpId, new Task(2, staProtocol));
                    if (!result) {
                        throw new CoolException("更新plc站点信息失败");
                    }
                    rgvThread.setResetFlag1(true);
                    wrkMastService.delete(new EntityWrapper<WrkMast>()
                            .eq("wrk_no", wrkMast.getWrkNo()));
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 对工作档的完成操作执行完成");
    }
//    /**
//     * 入出库模式切换函数
//     */