ZY
2025-04-07 4d285dd1ffcefbb51908a452e73477cc47300d91
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -15,9 +15,7 @@
import com.zy.asrs.mapper.TaskWrkMapper;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.CommandUtils;
import com.zy.asrs.utils.Utils;
import com.zy.common.service.CommonService;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
@@ -32,7 +30,6 @@
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.BarcodeThread;
import com.zy.core.thread.SiemensDevpThread;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -82,9 +79,6 @@
    @Autowired
    private CommonService commonService;
    @Autowired
    private ToWmsService toWmsService;
@@ -92,7 +86,8 @@
    private CrnController crnController;
    @Autowired
    private ConfigService configService;
    private TransferTaskService transferTaskService;
    public void generateStoreWrkFile1() throws IOException, InterruptedException {
        try {
@@ -375,7 +370,7 @@
                crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint()));     // 目标库位排
                crnCommand.setCommand((short) 1);
                log.info("堆垛机入库任务下发={}", crnCommand);
                if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) {
                if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令生成失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
                    throw new CoolException("堆垛机命令生成失败");
                } else {
@@ -482,7 +477,7 @@
                            taskWrk.setMarkStart(1);
                        }
                        if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command), false)) {
                        if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command))) {
                            log.error("堆垛机命令生成失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(command));
                            throw new CoolException("堆垛机命令生成失败");
                        } else {
@@ -555,7 +550,7 @@
                crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint()));     // 目标库位列
                crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint()));     // 目标库位层
                crnCommand.setCommand((short) 1);
                if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) {
                if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
                } else {
                    // 修改工作档状态 11.生成出库ID => 12.吊车出库中
@@ -835,6 +830,9 @@
        try {
            // 根据输送线plc遍历
            for (DevpSlave devp : slaveProperties.getDevp()) {
                if (devp.getId() == 2) {
                    continue;
                }
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                for (DevpSlave.Sta inSta : devp.getInSta()) {
                    WrkMast pakout = wrkMastMapper.selectWorkingPakout(inSta.getBackSta());
@@ -993,4 +991,82 @@
        }
    }
    /**
     * 转移任务下发
     */
    public void transferTaskStart() {
        for (DevpSlave.Sta sta : slaveProperties.getDevp().get(1).getInSta()) {
            try {
                // 获取入库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 2);
                StaProtocol staProtocol = devpThread.getStation().get(sta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == 0)) {
                    // 查询工作档
                    TransferTask transferTask = transferTaskService.selectByStartPoint(sta.getStaNo());
                    if (transferTask == null) {
                        continue;
                    }
                    log.info("下发输送线转移任务:taskWrk:" + JSON.toJSONString(transferTask));
                    staProtocol.setWorkNo(transferTask.getWrkNo().shortValue());
                    staProtocol.setStaNo(transferTask.getTargetPoint().shortValue());
                    boolean offer = false;
                    try {
                        offer = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
                    } catch (Exception e) {
                        log.error("下发输送线转移任务:异常:" + e);
                        log.error("下发输送线转移任务:异常:offer:" + offer);
                    }
                    if (offer) {
                        log.info("下发输送线任务成功:taskWrk:" + JSON.toJSONString(transferTask));
                        transferTask.setStatus(2);
                        transferTaskService.updateById(transferTask);
                    } else {
                        log.error("下发输送线任务失败:taskWrk:" + JSON.toJSONString(transferTask));
                    }
                }
            } catch (Exception e) {
                log.error("转移任务异常:异常信息:" + e);
            }
        }
    }
    /**
     * 转移任务完成
     */
    public void transferTaskEnd() {
        for (DevpSlave.Sta sta : slaveProperties.getDevp().get(1).getInSta()) {
            try {
                // 获取终点站
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 2);
                StaProtocol staProtocol = devpThread.getStation().get(sta.getOverSta());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == 0)) {
                    // 查询工作档
                    TransferTask transferTask = transferTaskService.selectByEndPoint(sta.getStaNo());
                    if (transferTask == null) {
                        continue;
                    }
                    log.info("转移任务完成:transferTask:" + JSON.toJSONString(transferTask));
                    transferTask.setStatus(5);
                    transferTaskService.updateById(transferTask);
                }
            } catch (Exception e) {
                log.error("转移任务异常:异常信息:" + e);
            }
        }
    }
}