#
zjj
2025-07-02 d3f3d4b309cfb285fcbbc48b91c4046111c7e9cd
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -5,6 +5,7 @@
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.domain.enums.TaskStatusType;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.TaskOverToWms;
@@ -213,6 +214,9 @@
                            if (taskWrk.getStatus() != 2){
                                continue;
                            }
                            if (!staProtocol.isPakMk()){
                                continue;
                            }
                            //获取堆垛机站点
                            StaDesc staDesc = new StaDesc();
                            if (devp.getId() <= 1){
@@ -222,9 +226,11 @@
                                staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>()
                                        .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).lt("stn_no", 400).ge("stn_no", 250));
                            }
                            staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue());
                            staProtocol.setStaNo(staDesc.getCrnStn().shortValue());
                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            Thread.sleep(500);
                        }else {
                            //TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo());
@@ -313,7 +319,6 @@
    /**
     * 堆垛机站出库到出库站
     */
    @Async
    public void crnStnToOutStn() {
        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
            // 遍历堆垛机出库站
@@ -349,23 +354,28 @@
                                    && crnProtocol.forkPosType == CrnForkPosType.HOME) {
                                // 命令下发区 --------------------------------------------------------------------------
                                //取出输送线命令
                                List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo());
                                if (commandInfos.isEmpty()) {
                                    continue;//命令空
                                }
                                try {
                                    //取出输送线命令
                                    List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo());
                                    if (commandInfos.isEmpty()) {
                                        continue;//命令空
                                    }
//                                CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文
//                                CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class);
                                Integer commandStep = taskWrk.getCommandStep();
                                CommandInfo commandInfo = commandInfos.get(commandStep);
                                CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文
                                //StaProtocol staProtocol1 = JSON.parseObject(commandInfo.getCommand(), StaProtocol.class);
                                StaProtocol staProtocol1 = JSON.parseObject(commandPackage.getCommand().toString(), StaProtocol.class);
                                if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol1))) {
                                    log.error("输送线命令下方失败!!! [工作号:{}]", taskWrk.getWrkNo());
                                    continue;//命令下发失败
                                    Integer commandStep = taskWrk.getCommandStep();
                                    CommandInfo commandInfo = commandInfos.get(commandStep);
                                    CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文
                                    //StaProtocol staProtocol1 = JSON.parseObject(commandInfo.getCommand(), StaProtocol.class);
                                    StaProtocol staProtocol1 = JSON.parseObject(commandPackage.getCommand().toString(), StaProtocol.class);
                                    if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol1))) {
                                        log.error("输送线命令下方失败!!! [工作号:{}]", taskWrk.getWrkNo());
                                        continue;//命令下发失败
                                    }
                                }catch (Exception e){
                                    throw new CoolException("取出输送线命令失败");
                                }
                                // 复位堆垛机
                                crnThread.setResetFlag(true);
@@ -489,11 +499,10 @@
                    log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo());
                }
                TaskWrk taskWrk2 = taskWrkService.selectByWrkNo(taskWrk.getWrkNo());
                if (taskWrk2.getWrkSts() != 3){
                    continue;
                }
                log.error("进入修改工作档流程完成,taskWrk=", taskWrk.getWrkNo());
                log.error("进入修改工作档流程完成,taskWrk="+ taskWrk.getWrkNo());
                //取出命令
@@ -509,15 +518,20 @@
                if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
                } else {
                    //开始运行
                    String response = CrnStartRunning(taskWrk);
                    JSONObject jsonObject = JSON.parseObject(response);
                    if (jsonObject.getInteger("code").equals(200)) {
                    try {
                        //开始运行
                        String response = CrnStartRunning(taskWrk);
                        JSONObject jsonObject = JSON.parseObject(response);
                        if (jsonObject.getInteger("code").equals(200)) {
                    }else {
                        log.error("入库开始运行通讯失败,"+jsonObject.get("msg"));
                        }else {
                            log.error("入库开始运行wms报错,"+jsonObject.get("msg"));
                        }
                    }catch (Exception e) {
                        log.error("入库开始运行wms报错");
                    }
                }
//                // 命令下发区 --------------------------------------------------------------------------
@@ -609,13 +623,16 @@
                            // 获取浅库位,状态为S直接出,状态为R,则找到这个库位的工作档,提升优先级先出
                            String shallowLoc = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint());
                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", shallowLoc));
                            if (locMast.getLocSts().equals("R")) {
                                List<TaskWrk> wrkMastList = taskWrkMapper.selectList(new EntityWrapper<TaskWrk>().eq("source_loc_no", locMast.getLocNo()));
                            if (locMast.getLocSts().equals("Z")) {
                                List<TaskWrk> wrkMastList = taskWrkMapper.selectList(new EntityWrapper<TaskWrk>().eq("start_point", locMast.getLocNo()));
                                if (!wrkMastList.isEmpty()) {
                                    TaskWrk wrkMast = wrkMastList.get(0);
                                    wrkMast.setIoPri(99);
                                    taskWrkMapper.updateById(wrkMast);
                                    log.warn("{}对应浅库位有货,提升{}库位优先级",taskWrk.getStartPoint(),wrkMast.getStartPoint());
                                    continue;
                                } else {
                                    log.error("{}对应浅库位有货,但没有移库任务",taskWrk.getStartPoint());
                                }
                            }
@@ -678,16 +695,23 @@
                            taskWrk.setModiTime(now);
                            if (taskWrkMapper.updateById(taskWrk) == 0) {
                                log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo());
                            }
                            //开始运行
                            String response = CrnStartRunning(taskWrk);
                            JSONObject jsonObject = JSON.parseObject(response);
                            if (jsonObject.getInteger("code").equals(200)) {
                            }else {
                                log.error("出库开始运行通讯失败,"+jsonObject.get("msg"));
                                log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中!!,工作号={}", taskWrk.getWrkNo());
                            }
                            try {
                                //开始运行
                                String response = CrnStartRunning(taskWrk);
                                JSONObject jsonObject = JSON.parseObject(response);
                                if (jsonObject.getInteger("code").equals(200)) {
                                }else {
                                    log.error("出库开始运行wms失败,"+jsonObject.get("msg"));
                                }
                            }catch (Exception e){
                                log.error("出库开始运行wms失败,");
                            }
                        }
                    }
@@ -707,7 +731,6 @@
                    .eq("wrk_sts",11)
                    .eq("io_type",3));
            for (TaskWrk taskWrk : taskWrks){
                // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) {
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint());
@@ -717,7 +740,7 @@
                    }
                }
                // 堆垛机控制过滤
                if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                if (!crnProtocol.getModeType().equals(CrnModeType.AUTO) || !crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                    continue;
                }
@@ -799,16 +822,23 @@
                    taskWrk.setModiTime(now);
                    if (taskWrkMapper.updateById(taskWrk) == 0) {
                        log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo());
                    }else{
                        log.info("移库任务下发任务成功,修改工作档状态 11.生成出库ID => 12.吊车出库中 ,工作号={}", taskWrk.getWrkNo());
                    }
                    //开始运行
                    String response = CrnStartRunning(taskWrk);
                    JSONObject jsonObject = JSON.parseObject(response);
                    if (jsonObject.getInteger("code").equals(200)) {
                    try{
                        String response = CrnStartRunning(taskWrk);
                        JSONObject jsonObject = JSON.parseObject(response);
                        if (jsonObject.getInteger("code").equals(200)) {
                    }else {
                        log.error("移库任务开始运行通讯失败,"+jsonObject.get("msg"));
                        continue;
                        }else {
                            log.error("移库任务开始运行wms返回失败,"+jsonObject.get("msg"));
                            continue;
                        }
                    }catch (Exception e){
                        log.error("移库任务开始运行请求wms报错,"+e.getMessage());
                    }
                    break;
                }
                return;
@@ -820,7 +850,7 @@
    /**
     * 执行对工作档的完成操作
     */
    @Async
    public void storeFinished() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            // 获取堆垛机信息
@@ -832,12 +862,12 @@
            if (crnProtocol.getTaskFinish() == 0 && crnProtocol.statusType == CrnStatusType.HANDLING_COMPLETED && crnProtocol.getTaskNo() != 0) {
                //获取入库待确认工作档
                TaskWrk taskWrk = taskWrkMapper.selectCrnNoInWorking(crn.getId(),crnProtocol.getTaskNo().intValue());
                log.info("收到申请完成请求:" + taskWrk.toString());
                if (Cools.isEmpty(taskWrk)) {
//                    log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                    continue;
                }
                log.info("收到申请完成请求:" + taskWrk);
                //获取指令ID
//                Integer commandId = crnProtocol.getCommandId();
//                CommandInfo commandInfo = new CommandInfo();
@@ -924,7 +954,7 @@
    /**
     * 堆垛机异常信息记录
     */
    @Async
    public void recCrnErr(){
        Date now = new Date();
        for (CrnSlave crn : slaveProperties.getCrn()) {