#
1
2025-05-09 a09baeeeeeea5c36159952482a895eb79c5740f4
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -12,24 +12,22 @@
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.CommandUtils;
import com.zy.asrs.utils.RouteUtils;
import com.zy.asrs.utils.TrackRangeUtils;
import com.zy.asrs.utils.Utils;
import com.zy.asrs.utils.*;
import com.zy.common.model.MatDto;
import com.zy.common.service.CommonService;
import com.zy.common.utils.CollectionUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.*;
import com.zy.core.enums.*;
import com.zy.core.model.CrnSlave;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.RgvSlave;
import com.zy.core.model.Task;
import com.zy.core.model.*;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.command.LedCommand;
import com.zy.core.model.protocol.*;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.BarcodeThread;
import com.zy.core.thread.LedThread;
import com.zy.core.thread.RgvThread;
import com.zy.core.thread.SiemensDevpThread;
import lombok.extern.slf4j.Slf4j;
@@ -42,6 +40,7 @@
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
 * 立体仓库WCS系统主流程业务
@@ -192,7 +191,7 @@
                        String barcode = barcodeThread.getBarcode();
                        if (!Cools.isEmpty(barcode) && !barcode.equals("99999999")) {
                            // 请求wms接口,获取工作号和目标库位
                            ToWmsDTO toWmsDTO = new ToWmsDTO(barcode, staProtocol.getSiteId(), 0);
                            ToWmsDTO toWmsDTO = new ToWmsDTO(staProtocol.getSiteId(),staProtocol.getGrossWt(),barcode, 0);
                            TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode));
                            if (!Cools.isEmpty(taskWrk1)) {
                                log.info("托盘码:" + barcode + "任务档存在");
@@ -463,7 +462,8 @@
                    // 判断是否满足入库条件
                    if (staProtocol.isAutoing() && staProtocol.isLoading()
                            && staProtocol.isInEnable() && (workNo == 0 || (workNo>9000 && workNo<10000))
//                            && staProtocol.isInEnable()
                            && (workNo == 0 || (workNo>9000 && workNo<10000))
                            && staProtocol.isPakMkWalk()
                    ) {
                        if (inSta.isBarcodeSign()){
@@ -508,6 +508,7 @@
                                        } else {
                                            staProtocol.setWorkNo(taskWrk1.getWrkNo());
                                            staProtocol.setStaNo(staDesc.getCrnStn());
                                            devpThread.setPakMkWalk(staProtocol.getSiteId(), false);
                                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                                        }
                                    }
@@ -515,7 +516,7 @@
                                }
                            }
                        } else {
                            TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>());
                            TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("IO_TYPE",1).eq("WRK_STS",1).eq("START_POINT",staProtocol.getSiteId().toString()));
                            if (!Cools.isEmpty(taskWrk1)) {
                                if (taskWrk1.getIoType() == 1 && taskWrk1.getStartPoint().equals(staProtocol.getSiteId().toString())) {
@@ -526,8 +527,21 @@
                                        return;
                                    } else {
                                        staProtocol.setWorkNo(taskWrk1.getWrkNo());
                                        staProtocol.setStaNo(staDesc.getCrnStn());
                                        staProtocol.setStaNo(BarcodeUtils.getStaNo(staProtocol.getSiteId()));
                                        devpThread.setPakMkWalk(staProtocol.getSiteId(), false);
                                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                                        Date now = new Date();
//                                        taskWrk1.setStatus(TaskStatusType.DISTRIBUTE.id);//派发状态
//                taskWrk.setAssignTime(now);//派发时间
                                        taskWrk1.setExecuteTime(now);
                                        taskWrk1.setWrkSts(2);//工作状态 3.吊车入库
                                        taskWrk1.setCrnNo(staDesc.getCrnNo());//堆垛机号
                                        taskWrk1.setModiTime(now);
                                        taskWrk1.setModiUser(9988L);
                                        taskWrkService.updateById(taskWrk1);
                                    }
                                }
                                return;
@@ -591,7 +605,7 @@
                            log.info("下发输送线任务:taskWrk:" + JSON.toJSONString(taskWrk));
//                            R r = siteController.siteDetlUpdate(Integer.valueOf(taskWrk.getTargetPoint()), taskWrk.getWrkNo().shortValue(), (short) 0, "Y", false, false);
                            staProtocol.setWorkNo(taskWrk.getWrkNo());
                            staProtocol.setStaNo(staDesc.getCrnStn());
                            staProtocol.setStaNo(BarcodeUtils.getStaNo(staProtocol.getSiteId()));
                            boolean offer = false;
                            try {
                                offer = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
@@ -603,7 +617,7 @@
                            if (offer) {
                                log.info("下发输送线任务成功:taskWrk:" + JSON.toJSONString(taskWrk));
                                Date now = new Date();
                                taskWrk.setStatus(5);
                                taskWrk.setStatus(9);
                                taskWrk.setWrkSts(14);
                                taskWrk.setModiTime(now);
                                taskWrk.setCompleteTime(now);
@@ -781,7 +795,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));
                    throw new CoolException("堆垛机命令生成失败");
                } else {
@@ -795,7 +809,7 @@
                        HashMap<String, Object> headParam = new HashMap<>();
                        headParam.put("taskNo", taskWrk.getTaskNo());
                        headParam.put("status", taskWrk.getStatus());
                        headParam.put("ioType", taskWrk.getIoType());
                        headParam.put("ioType", taskWrk.getIoTypeWms());
                        headParam.put("barcode", taskWrk.getBarcode());
                        String response;
                        response = new HttpHandler.Builder()
@@ -893,7 +907,7 @@
                        command.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
                        command.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
                        command.setCommand((short) 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("堆垛机命令生成失败,堆垛机号={},巷道={},任务数据={}", slave.getId(), taskWrk.getCrnNo(), JSON.toJSON(command));
                            throw new CoolException("堆垛机命令生成失败");
                        } else {
@@ -915,7 +929,7 @@
                                HashMap<String, Object> headParam = new HashMap<>();
                                headParam.put("taskNo", taskWrk.getTaskNo());
                                headParam.put("status", taskWrk.getStatus());
                                headParam.put("ioType", taskWrk.getIoType());
                                headParam.put("ioType", taskWrk.getIoTypeWms());
                                headParam.put("barcode", taskWrk.getBarcode());
                                String response;
                                response = new HttpHandler.Builder()
@@ -1003,7 +1017,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.吊车出库中
@@ -1019,7 +1033,7 @@
                        HashMap<String, Object> headParam = new HashMap<>();
                        headParam.put("taskNo", taskWrk.getTaskNo());
                        headParam.put("status", taskWrk.getStatus());
                        headParam.put("ioType", taskWrk.getIoType());
                        headParam.put("ioType", taskWrk.getIoTypeWms());
                        headParam.put("barcode", taskWrk.getBarcode());
                        String response;
                        response = new HttpHandler.Builder()
@@ -1071,14 +1085,14 @@
            }
            //  状态:等待确认 并且  任务完成位 = 1
            if (!Cools.isEmpty(crnProtocol.getTaskFinish()) && crnProtocol.getTaskFinish() == 0 && crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
            if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
                //获取入库待确认工作档
                TaskWrk taskWrk = taskWrkMapper.selectCrnNoInWorking(crnProtocol.getLaneNo(), crnProtocol.getTaskNo().intValue());
                if (Cools.isEmpty(taskWrk) && crnProtocol.getTaskNo() != 999) {
                    log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},巷道号={},工作号={}", crn.getId(), crnProtocol.getLaneNo(), crnProtocol.getTaskNo());
                    continue;
                }
                Thread.sleep(300);
//                Thread.sleep(300);
                //确认完成信号
                CrnOperatorParam crnOperatorParam = new CrnOperatorParam();
                crnOperatorParam.setCrnNo(crn.getId());
@@ -1133,7 +1147,7 @@
                        HashMap<String, Object> headParam = new HashMap<>();
                        headParam.put("taskNo", taskWrk.getTaskNo());
                        headParam.put("status", taskWrk.getStatus());
                        headParam.put("ioType", taskWrk.getIoType());
                        headParam.put("ioType", taskWrk.getIoTypeWms());
                        headParam.put("barcode", taskWrk.getBarcode());
                        String response;
                        log.error("wcs完结任务上报wms==》", headParam);
@@ -1341,7 +1355,7 @@
        if (rgvProtocol == null || rgvTaskProtocol == null) {
            return false;
        }
        if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO) || rgvProtocol.getRgvPos().equals(0L) || rgvTaskProtocol.getAvoid() == -1 || rgvProtocol.getRgvPosDestination() == 0L
        if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO) || rgvProtocol.getRgvPos().equals(0L) || rgvTaskProtocol.getAvoid() == -1
                || (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE) && !rgvProtocol.getStatusType().equals(RgvStatusType.ROAM))) {
            return false;
        }
@@ -1369,8 +1383,9 @@
        // 判断是否满足取货条件
        if (staProtocol.isAutoing()
//                && staProtocol.isLoading()
                && staProtocol.isStaOk()
                && staProtocol.getWorkNo() != 0) {
            TaskWrk taskWrk = taskWrkService.selectByTaskNo(staProtocol.getWorkNo().toString());
            TaskWrk taskWrk = taskWrkService.selectByWrkNo(staProtocol.getWorkNo());
            if (taskWrk != null) {
                return taskWrk;
            }
@@ -1592,12 +1607,9 @@
                if (taskWrk == null) {
                    return false;
                }
                Integer targetPointConvert = taskWrk.getTargetPointConvert();
//                Integer targetPointConvert = taskWrk.getTargetPointConvert();
                Integer targetPointConvert = BarcodeUtils.getOutStaNo(taskWrk.getOriginTargetPoint());
                if (targetPointConvert == null) {
                    return false;
                }
                RgvSlave.RgvStn rgvStnEnd = getRgvStnNow(rgvSlave, targetPointConvert);
                if (rgvStnEnd == null) {
                    return false;
                }
@@ -1605,19 +1617,19 @@
                BasDevpPosition basDevpPositionEnd = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", targetPointConvert));
                //执行
                issuedTake.setTaskNo(Long.valueOf(taskWrk.getTaskNo()));
                issuedTake.setTaskStatus(1);
                issuedTake.setTaskStatus(2);
                issuedTake.setTaskNoDirection(issuedTake.gettaskNoDirection$(issuedTake.getTaskNo(), issuedTake.getTaskStatus()));
                issuedTake.setTargetPosition(basDevpPositionSou.getPlcPosition());
                issuedTake.setIsRunning(1);
                issuedTake.setDirection(rgvStn.isDirection());
                issuedTake.setDirection(basDevpPositionSou.getRgvSign()==1);
                issuedPut.setTaskNo(Long.valueOf(taskWrk.getTaskNo()));
                issuedPut.setTaskStatus(2);
                issuedPut.setTaskStatus(3);
                issuedPut.setTaskNoDirection(issuedPut.gettaskNoDirection$(issuedPut.getTaskNo(), issuedPut.getTaskStatus()));
                issuedPut.setTargetPosition(basDevpPositionEnd.getPlcPosition());
                issuedPut.setIsRunning(1);
                issuedPut.setDirection(rgvStnEnd.isDirection());
                issuedPut.setDirection(basDevpPositionEnd.getRgvSign()==1);
            } catch (Exception e) {
                log.error("任务生成失败issued1===》异常信息:{}", e.getMessage());
                return false;
@@ -1641,5 +1653,118 @@
        return true;
    }
    /**
     * 出库  ===>> 工作档信息写入led显示器
     */
    public synchronized void ledExecute(Integer mark) {
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
            // 命令集合
            List<LedCommand> commands = new ArrayList<>();
            // 工作档集合
            List<WrkMast> wrkMasts = new ArrayList<>();
            for (Integer staNo : led.getStaArr()) {
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
                if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                // 获取工作档数据
                LedCommand ledCommand = new LedCommand();
//
//                ledCommand.setWorkNo(wrkMast.getWrkNo());
//                ledCommand.setIoType(wrkMast.getIoType());
//                ledCommand.setTitle("空板出库");
//                ledCommand.setEmptyMk(true);
//                ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
//                ledCommand.setLocNo(wrkMast.getLocNo());
//                ledCommand.setStaNo(wrkMast.getStaNo());
                MatDto matDto = new MatDto();
                ledCommand.getMatDtos().add(matDto);
                commands.add(ledCommand);
            }
            Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
            // 获取LED线程
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
            // 相同工作号集合则过滤
            if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
                continue;
            }
            // 命令下发 -------------------------------------------------------------------------------
            if (!commands.isEmpty()) {
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
//                    News.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    continue;
                }else {
                    ledThread.setLedMk(false);
                }
            }
            try {
                // 修改主档led标记
                for (WrkMast wrkMast : wrkMasts) {
                    wrkMast.setOveMk("Y");
                    wrkMast.setModiTime(new Date());
                    if (wrkMastMapper.updateById(wrkMast) == 0) {
//                        News.errorNoLog(""+mark+" - 4"+" - 更新工作档失败");
                        throw new CoolException("更新工作档失败");
                    }
                }
                // 更新线程当前工作号集合
                ledThread.setWorkNos(workNos);
            } catch (Exception e) {
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
        }
//        News.infoNoLog(""+mark+" - 0"+" - 出库  ===>> 工作档信息写入led显示器执行完成");
    }
    /**
     * 其他  ===>> LED显示器复位,显示默认信息
     */
    public synchronized void ledReset(Integer mark) {
//        News.warnNoLog(""+mark+" - 0"+" - 开始执行:其他  ===>> LED显示器复位,显示默认信息");
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
            // 命令集合
            boolean reset = true;
            for (Integer staNo : led.getStaArr()) {
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
                if (staProtocol == null) {
                    continue;
                }
                if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) {
                    reset = false;
                    break;
                }
            }
            // 获取led线程
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
            // led显示默认内容
            if (reset && !ledThread.isLedMk()) {
                ledThread.setLedMk(true);
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
//                    News.error(""+mark+" - 1"+" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                } else {
                }
            }
        }
//        News.infoNoLog(""+mark+" - 0"+" - 执行完成:其他  ===>> LED显示器复位,显示默认信息");
    }
}