*
lsh
2025-04-30 1bde682d9149b5b55488cfaa277ec1deacab4bee
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -16,20 +16,21 @@
import com.zy.asrs.utils.RouteUtils;
import com.zy.asrs.utils.TrackRangeUtils;
import com.zy.asrs.utils.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 +43,7 @@
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
 * 立体仓库WCS系统主流程业务
@@ -192,7 +194,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 + "任务档存在");
@@ -515,7 +517,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())) {
@@ -603,7 +605,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);
@@ -795,7 +797,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()
@@ -915,7 +917,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()
@@ -1019,7 +1021,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()
@@ -1133,7 +1135,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);
@@ -1641,5 +1643,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显示器复位,显示默认信息");
    }
}