cpT
2025-06-30 de4f2b6569689626176abfef75be69e72eba8ed8
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.core.common.Cools;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.controller.CrnController;
import com.zy.asrs.domain.enums.TaskStatusType;
@@ -106,6 +107,7 @@
    private TaskWrkLogServiceImpl taskWrkLogService;
    @Autowired
    private BasPlcerrorLogServiceImpl basPlcerrorLogService;
    public Long currentTimeMilliConnectCrnAuto= 0L;
    public void generateStoreWrkFile() {
        try {
@@ -721,26 +723,61 @@
                    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) {
                if (System.currentTimeMillis()-currentTimeMilliConnectCrnAuto<1000*60*10){
                    continue;
                }
                if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.statusType == CrnStatusType.IDLE && crnProtocol.getLoaded().equals((short)0) && crnProtocol.getLaneNo()!=0 && crnProtocol.getTaskNo() == 0 ) {
                    if (crnProtocol.getBay()!=1 || crnProtocol.getLevel()!=1){
                        //获取工作档
                        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());
                        if (!taskWrkLogs.isEmpty()) {
                            TaskWrkLog taskWrkLog = taskWrkLogs.get(0);
                            Date completeTime = taskWrkLog.getCompleteTime();
                            if (completeTime==null){
                                completeTime = taskWrkLog.getCancelTime();
                                if (completeTime==null){
                                    completeTime = taskWrkLog.getModiTime();
                                }
                            }
                            long differenceInSeconds = TimeCalculatorUtils.differenceInMilliseconds(completeTime, new Date());
                            if (differenceInSeconds <= 60*10*1000) {
                                return;
                            }
                        }
//                        long differenceInSeconds = TimeCalculatorUtils.differenceInMilliseconds(taskWrkLogs.get(0).getCompleteTime(), new Date());
//                        if (differenceInSeconds <= 1000) {
//                            return;
//                        }
                        // 命令下发区 --------------------------------------------------------------------------
                        CrnCommand crnCommand = new CrnCommand();
                        crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
                        crnCommand.setCrnNo(crnProtocol.getLaneNo()); // 堆垛机巷道编号
                        crnCommand.setTaskNo((short)999); // 工作号
                        crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                        crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式:  库位移转
                        crnCommand.setSourcePosX((short) 0);     // 源库位排
                        crnCommand.setSourcePosY((short) 0);     // 源库位列
                        crnCommand.setSourcePosZ((short) 0);   // 源库位层
                        int row = crnProtocol.getLaneNo() * 2;
                        crnCommand.setDestinationPosX((short) row);     // 目标库位排
                        crnCommand.setDestinationPosY((short) 1);     // 目标库位层
                        crnCommand.setDestinationPosZ((short) 1);     // 目标库位列
                        if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
                            log.error("堆垛机自动回源点失败,堆垛机号={}", crnProtocol.getCrnNo());
                            if (System.currentTimeMillis()-currentTimeMilliConnectCrnAuto>1000*60*10){
                                try{
                                    DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
                                    deviceErrorService.addDeviceError("CrnErr", crnProtocol.getCrnNo(), "堆垛机自动回源点失败");
                                } catch (Exception e2){
                                }
                                if (currentTimeMilliConnectCrnAuto == 0){
                                    currentTimeMilliConnectCrnAuto = System.currentTimeMillis()-1000*60*10-1;
                                } else {
                                    currentTimeMilliConnectCrnAuto = System.currentTimeMillis();
                                }
                            }
                        }
                    }
                }
            } catch (Exception e){
@@ -1517,10 +1554,10 @@
                        if (staProtocol == null) {
                            continue;
                        }
//                        if (staProtocol.isAutoing() != CrnModeType.STOP) {
//                        if (staProtocol.isAutoing()) {
//                            // 有任务
//                            if (crnProtocol.getTaskNo() != 0) {
//                                BasErrLog latest = basPlcerrorLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue());
//                            if (staProtocol.getWorkNo() != 0) {
////                                BasErrLog latest = basPlcerrorLogService.se(crn.getId(), crnProtocol.getTaskNo().intValue());
//                                // 有异常
//                                if (latest == null) {
//                                    if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {