cpT
2025-06-27 830527d30361c5d69065546562cc73d9afc4d0f7
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -31,7 +31,6 @@
import com.zy.core.thread.RgvThread;
import com.zy.core.thread.SiemensDevpThread;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -55,8 +54,6 @@
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private WrkMastMapper wrkMastMapper;
    @Autowired
    private LocMastService locMastService;
    @Autowired
@@ -105,6 +102,8 @@
    @Value("${constant-parameters.avoidDistance}")
    private Long avoidDistance;
    @Autowired
    private TaskWrkLogServiceImpl taskWrkLogService;
    public void generateStoreWrkFile() {
        try {
@@ -130,7 +129,7 @@
                    boolean back = false;
                    String errMsg = "-";
                    if (staProtocol.getGrossWt()>=600){
                        errMsg = "超重";
                        errMsg = "超重:"+staProtocol.getGrossWt()+"kg";
                        back = true;
                    }
                    if (staProtocol.isFrontErr()) {
@@ -153,10 +152,10 @@
                        errMsg = "右超限";
                        back = true;
                    }
                    if (!back && staProtocol.isWeightErr()) {
                        errMsg = "超重";
                        back = true;
                    }
//                    if (!back && staProtocol.isWeightErr()) {
//                        errMsg = "超重";
//                        back = true;
//                    }
                    if (!back && staProtocol.isBarcodeErr()) {
                        errMsg = "扫码失败";
                        back = true;
@@ -385,10 +384,10 @@
                        errMsg = "右超限";
                        back = true;
                    }
                    if (!back && staProtocol.isWeightErr()) {
                        errMsg = "超重";
                        back = true;
                    }
//                    if (!back && staProtocol.isWeightErr()) {
//                        errMsg = "超重";
//                        back = true;
//                    }
                    // 退回
                    if (back) {
                        if (stano == inSta.getBackSta().shortValue()) {
@@ -704,6 +703,51 @@
    }
    /**
     * 堆垛机5分钟无任务则回到源点
     */
    public void crnStnToOutStnSou() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            try{
                // 获取堆垛机信息
                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.getLaneNo()!=0 && (crnProtocol.getBay()!=1 || crnProtocol.getLevel()!=1)){
                    if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.statusType == CrnStatusType.IDLE && crnProtocol.getTaskNo() != 0) {
                        //获取工作档
                        List<TaskWrk> taskWrks = taskWrkMapper.selectByLaneNo(crnProtocol.getLaneNo());
                        if (!taskWrks.isEmpty()) {
                            continue;
                        }
                        List<TaskWrkLog> taskWrkLogs = taskWrkLogService.selectList(new EntityWrapper<TaskWrkLog>().eq("CRN_NO",crnProtocol.getLaneNo()).orderBy("COMPLETE_TIME",true));
                        if (taskWrkLogs.isEmpty()) {
                            CrnCommand command = new CrnCommand();
                            if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(4, command))) {
                                log.error("堆垛机自动回源点失败,堆垛机号={}", crnProtocol.getCrnNo());
                            }
                        }
//                        long differenceInSeconds = TimeCalculatorUtils.differenceInMilliseconds(taskWrkLogs.get(0).getCompleteTime(), new Date());
//                        if (differenceInSeconds <= 1000) {
//                            return;
//                        }
                    }
                }
            } catch (Exception e){
            }
        }
    }
    /**
     * 入出库  ===>>  堆垛机入出库作业下发
     */
    public synchronized void crnIoExecute() throws IOException {
@@ -979,8 +1023,11 @@
                    }
                    // 判断堆垛机出库站状态
                    if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")
                            && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
                    if (staProtocol.isAutoing() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")) {
//                    // 判断堆垛机出库站状态
//                    if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")
//                            && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
                        // 命令下发区 --------------------------------------------------------------------------
                        // 堆垛机控制过滤
@@ -1082,6 +1129,8 @@
                            if (staProtocol.isOutEnable()){
                                CrnErrCache.updateCrnErr(crnProtocol.getCrnNo(), "没有可出");
                            }
                        } else {
                            CrnErrCache.updateCrnErr(crnProtocol.getCrnNo(), "出库站点:非自动");
                        }
                    }
                }
@@ -1335,34 +1384,33 @@
            if (crnProtocol == null) {
                continue;
            }
            if (false) {
//            if (crnProtocol.getModeType() != CrnModeType.STOP) {
            if (crnProtocol.getModeType() != CrnModeType.STOP) {
                // 有任务
                if (crnProtocol.getTaskNo() != 0) {
                    BasErrLog latest = basErrLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue());
                    // 有异常
                    if (latest == null) {
                        if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
                            WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo());
                            if (wrkMast == null) {
                            TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(crnProtocol.getTaskNo()));
                            if (taskWrk == null) {
                                continue;
                            }
                            BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm());
                            BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm().intValue());
                            String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName();
                            BasErrLog basErrLog = new BasErrLog(
                                    null,    // 编号
                                    wrkMast.getWrkNo(),    // 工作号
                                    taskWrk.getWrkNo(),    // 工作号
                                    now,    // 发生时间
                                    null,    // 结束时间
                                    wrkMast.getWrkSts(),    // 工作状态
                                    wrkMast.getIoType(),    // 入出库类型
                                    taskWrk.getWrkSts().longValue(),    // 工作状态
                                    taskWrk.getIoType(),    // 入出库类型
                                    crn.getId(),    // 堆垛机
                                    null,    // plc
                                    wrkMast.getLocNo(),    // 目标库位
                                    wrkMast.getStaNo(),    // 目标站
                                    wrkMast.getSourceStaNo(),    // 源站
                                    wrkMast.getSourceLocNo(),    // 源库位
                                    wrkMast.getBarcode(),    // 条码
                                    taskWrk.getTargetPoint(),    // 目标库位
                                    0,    // 目标站
                                    0,    // 源站
                                    taskWrk.getStartPoint(),    // 源库位
                                    taskWrk.getBarcode(),    // 条码
                                    (int) crnProtocol.getAlarm(),    // 异常码
                                    errName,    // 异常
                                    1,    // 异常情况
@@ -1568,9 +1616,15 @@
        }
        if (rgvProtocolOther.statusEnable) {
            BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", staNo));
            if (Math.abs(basDevpPosition.getPlcPosition()-rgvProtocol.getRgvPos())
            long abs = Math.abs(Math.abs(basDevpPosition.getPlcPosition() - rgvProtocol.getRgvPos())
                    -
                    Math.abs(basDevpPosition.getPlcPosition() - rgvProtocolOther.getRgvPos()));
            if (abs<100){
                return true;
            }
            if (Math.abs(basDevpPosition.getPlcPosition() - rgvProtocol.getRgvPos())
                    >=
                    Math.abs(basDevpPosition.getPlcPosition()-rgvProtocolOther.getRgvPos())){
                    Math.abs(basDevpPosition.getPlcPosition() - rgvProtocolOther.getRgvPos())){
                return false;
            }
        }
@@ -1594,6 +1648,12 @@
        }
        if (rgvProtocolOther.statusEnable) {
            BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", staNo));
            long abs = Math.abs(Math.abs(basDevpPosition.getPlcPosition() - rgvProtocol.getRgvPos())
                    -
                    Math.abs(basDevpPosition.getPlcPosition() - rgvProtocolOther.getRgvPos()));
            if (abs<100){
                return true;
            }
            if (Math.abs(basDevpPosition.getPlcPosition()-rgvProtocol.getRgvPos())
                    >=
                    Math.abs(basDevpPosition.getPlcPosition()-rgvProtocolOther.getRgvPos())){
@@ -1618,14 +1678,13 @@
            TaskWrk taskWrk = taskWrkService.selectByWrkNo(staProtocol.getWorkNo());
            if (taskWrk != null) {
                Integer stano = staProtocol.getStaNo();
                if (staProtocol.getSiteId() == 1004 || staProtocol.getSiteId()==1020){
                    // 尺寸检测异常
                    boolean back = false;
                    String errMsg = "-";
                    if (staProtocol.getGrossWt()>=600){
                        errMsg = "超重";
                        errMsg = "超重:"+staProtocol.getGrossWt()+"kg";
                        back = true;
                    }
                    if (staProtocol.isFrontErr()) {
@@ -1648,10 +1707,10 @@
                        errMsg = "右超限";
                        back = true;
                    }
                    if (!back && staProtocol.isWeightErr()) {
                        errMsg = "超重";
                        back = true;
                    }
//                    if (!back && staProtocol.isWeightErr()) {
//                        errMsg = "超重";
//                        back = true;
//                    }
                    if (!back && staProtocol.isBarcodeErr()) {
                        errMsg = "扫码失败";
                        back = true;
@@ -1682,6 +1741,21 @@
                    }
                }
                return taskWrk;
            }
        } else if (staProtocol.isAutoing() && staProtocol.getWorkNo() == 0 && !staProtocol.isLoading()){
            if (inSta.isDirectionOther()){
                StaProtocol staProtocolOther = devpThread.getStation().get(inSta.getStaNoOther());
                if (staProtocolOther == null) {
                    return null;
                }
                // 判断是否满足取货条件
                if (staProtocolOther.isAutoing()
                        && staProtocolOther.getWorkNo() != 0) {
                    TaskWrk taskWrkOther = taskWrkService.selectByWrkNo(staProtocolOther.getWorkNo());
                    if (taskWrkOther != null) {
                        return taskWrkOther;
                    }
                }
            }
        }
        return null;
@@ -1828,7 +1902,6 @@
                            if (rgvOtherIDLEOther2(rgvSlave)){
                                if (!rgvOtherIDLE2(rgvSlave,staList.get(0))){
                                    System.out.println("运行就近跳过==="+rgvSlave.getId()+"===");
                                    sign=true;
                                }
                            }
@@ -2145,7 +2218,7 @@
            // 命令集合
            List<LedCommand> commands = new ArrayList<>();
            // 工作档集合
            List<WrkMast> wrkMasts = new ArrayList<>();
            List<TaskWrk> taskWrks = new ArrayList<>();
            for (Integer staNo : led.getStaArr()) {
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
@@ -2169,7 +2242,7 @@
                ledCommand.getMatDtos().add(matDto);
                commands.add(ledCommand);
            }
            Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
            Set<Integer> workNos = taskWrks.stream().map(TaskWrk::getWrkNo).collect(Collectors.toSet());
            // 获取LED线程
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
            // 相同工作号集合则过滤
@@ -2188,10 +2261,10 @@
            try {
                // 修改主档led标记
                for (WrkMast wrkMast : wrkMasts) {
                    wrkMast.setOveMk("Y");
                    wrkMast.setModiTime(new Date());
                    if (wrkMastMapper.updateById(wrkMast) == 0) {
                for (TaskWrk taskWrk : taskWrks) {
//                    taskWrk.setOveMk("Y");
                    taskWrk.setModiTime(new Date());
                    if (taskWrkMapper.updateById(taskWrk) == 0) {
//                        News.errorNoLog(""+mark+" - 4"+" - 更新工作档失败");
                        throw new CoolException("更新工作档失败");
                    }