| | |
| | | package com.zy.core.plugin; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.core.common.Cools; |
| | | import com.zy.asrs.domain.param.CreateInTaskParam; |
| | | import com.zy.asrs.domain.param.CreateOutTaskParam; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.entity.FindCrnNoResult; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.dispatch.StationCommandDispatchResult; |
| | | import com.zy.core.dispatch.StationCommandDispatcher; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.StationObjModel; |
| | |
| | | import com.zy.core.model.command.CrnCommand; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.protocol.DualCrnProtocol; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.network.fake.FakeConfigKeys; |
| | | import com.zy.core.network.fake.FakeConfigSupport; |
| | | import com.zy.core.plugin.api.MainProcessPluginApi; |
| | | import com.zy.core.plugin.station.FakeStationMonitor; |
| | | import com.zy.core.plugin.station.FakeTaskGenerator; |
| | | import com.zy.core.plugin.store.StoreInTaskContext; |
| | | import com.zy.core.plugin.store.StoreInTaskGenerationService; |
| | | import com.zy.core.plugin.store.StoreInTaskPolicy; |
| | | import com.zy.core.task.MainProcessLane; |
| | | import com.zy.core.task.MainProcessTaskSubmitter; |
| | | import com.zy.core.thread.CrnThread; |
| | | import com.zy.core.thread.DualCrnThread; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.core.utils.CrnOperateProcessUtils; |
| | | import com.zy.core.utils.DualCrnOperateProcessUtils; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class FakeProcess implements MainProcessPluginApi, StoreInTaskPolicy { |
| | | private static final long MAIN_DISPATCH_INTERVAL_MS = 200L; |
| | | private static final long ASYNC_DISPATCH_INTERVAL_MS = 50L; |
| | | private long getMainDispatchIntervalMs() { |
| | | return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_STATION_IDLE_LOOP_DELAY_MS, 200L); |
| | | } |
| | | |
| | | private static final Map<Integer, Long> stationStayTimeMap = new ConcurrentHashMap<>(); |
| | | private long getAsyncDispatchIntervalMs() { |
| | | return Math.max(50L, FakeConfigSupport.getLong(FakeConfigKeys.FAKE_STATION_INITIALIZE_DELAY_MS, 50L)); |
| | | } |
| | | |
| | | private long getOutStationStayTimeoutMs() { |
| | | return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_OUT_STATION_STAY_TIMEOUT_MS, 3000L); |
| | | } |
| | | |
| | | private static volatile String enableFake = "N"; |
| | | |
| | | private static volatile String fakeRealTaskRequestWms = "N"; |
| | | private static volatile String fakeGenerateInTask = "Y"; |
| | | private static volatile String fakeGenerateOutTask = "Y"; |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | private static final Map<Integer, Long> OUT_STATION_STAY_MARKER = new HashMap<Integer, Long>(); |
| | | |
| | | private final Object outStationStayLock = new Object(); |
| | | |
| | | private boolean shouldDispatchOutStationWriteInfo(Integer wrkNo) { |
| | | long now = System.currentTimeMillis(); |
| | | long timeoutMs = getOutStationStayTimeoutMs(); |
| | | synchronized (outStationStayLock) { |
| | | Long lastTime = OUT_STATION_STAY_MARKER.get(wrkNo); |
| | | if (lastTime == null || now - lastTime >= timeoutMs) { |
| | | OUT_STATION_STAY_MARKER.put(wrkNo, now); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | private void clearOutStationStayMarker(Integer wrkNo) { |
| | | synchronized (outStationStayLock) { |
| | | OUT_STATION_STAY_MARKER.remove(wrkNo); |
| | | } |
| | | } |
| | | |
| | | private void dispatchOutStationWriteInfoIfReady(WrkMast wrkMast, BasCrnp basCrnp) { |
| | | Integer wrkNo = wrkMast == null ? null : wrkMast.getWrkNo(); |
| | | if (wrkNo == null) { |
| | | News.error("仿真出库站点写入跳过,WCS任务号为空。sourceStaNo={},crnNo={}", |
| | | wrkMast == null ? null : wrkMast.getSourceStaNo(), |
| | | basCrnp == null ? null : basCrnp.getCrnNo()); |
| | | return; |
| | | } |
| | | if (!shouldDispatchOutStationWriteInfo(wrkNo)) { |
| | | News.error("仿真出库站点写入跳过,命中节流限制。wrkNo={},sourceStaNo={},crnNo={}", |
| | | wrkNo, |
| | | wrkMast == null ? null : wrkMast.getSourceStaNo(), |
| | | basCrnp == null ? null : basCrnp.getCrnNo()); |
| | | return; |
| | | } |
| | | String taskNo = String.valueOf(wrkNo); |
| | | List<StationObjModel> outStationList = basCrnp.getOutStationList$(); |
| | | if (outStationList.isEmpty()) { |
| | | News.error("仿真出库站点写入失败,堆垛机未配置出库站点。crnNo={},wrkNo={},taskNo={}", |
| | | basCrnp.getCrnNo(), wrkMast == null ? null : wrkMast.getWrkNo(), taskNo); |
| | | return; |
| | | } |
| | | boolean matched = false; |
| | | for (StationObjModel stationObjModel : outStationList) { |
| | | if (!stationObjModel.getStationId().equals(wrkMast.getSourceStaNo())) { |
| | | continue; |
| | | } |
| | | matched = true; |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | News.error("仿真出库站点写入失败,站点线程不存在。taskNo={},wrkNo={},stationId={},deviceNo={}", |
| | | taskNo, wrkMast.getWrkNo(), stationObjModel.getStationId(), stationObjModel.getDeviceNo()); |
| | | continue; |
| | | } |
| | | StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998, |
| | | wrkMast.getSourceStaNo(), 0, 0); |
| | | StationCommandDispatchResult dispatchResult = stationCommandDispatcher.dispatch( |
| | | stationObjModel.getDeviceNo(), command, "fake-process", "crn-out-complete-write-info"); |
| | | News.info("仿真出库站点写入命令分发结果。taskNo={},wrkNo={},crnNo={},stationId={},deviceNo={},accepted={},reason={},queueDepth={}", |
| | | taskNo, |
| | | wrkMast.getWrkNo(), |
| | | basCrnp.getCrnNo(), |
| | | stationObjModel.getStationId(), |
| | | stationObjModel.getDeviceNo(), |
| | | dispatchResult != null && dispatchResult.isAccepted(), |
| | | dispatchResult == null ? null : dispatchResult.getReason(), |
| | | dispatchResult == null ? null : dispatchResult.getQueueDepth()); |
| | | } |
| | | if (!matched) { |
| | | News.error("仿真出库站点写入失败,未匹配到sourceStaNo对应出库站点。taskNo={},wrkNo={},sourceStaNo={},crnNo={}", |
| | | taskNo, |
| | | wrkMast == null ? null : wrkMast.getWrkNo(), |
| | | wrkMast == null ? null : wrkMast.getSourceStaNo(), |
| | | basCrnp == null ? null : basCrnp.getCrnNo()); |
| | | } |
| | | } |
| | | |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | private WrkAnalysisService wrkAnalysisService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private BasDualCrnpService basDualCrnpService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private StationOperateProcessUtils stationOperateProcessUtils; |
| | | @Autowired |
| | | private WrkAnalysisService wrkAnalysisService; |
| | | @Autowired |
| | | private DualCrnOperateProcessUtils dualCrnOperateProcessUtils; |
| | | @Autowired |
| | | private StoreInTaskGenerationService storeInTaskGenerationService; |
| | | @Autowired |
| | | private StationCommandDispatcher stationCommandDispatcher; |
| | | @Autowired |
| | | private MainProcessTaskSubmitter mainProcessTaskSubmitter; |
| | | @Autowired |
| | | private FakeStationMonitor fakeStationMonitor; |
| | | @Autowired |
| | | private FakeTaskGenerator fakeTaskGenerator; |
| | | |
| | | @Override |
| | | public void run() { |
| | | long startTime = System.currentTimeMillis(); |
| | | refreshFakeConfig(); |
| | | syncConfigToComponents(); |
| | | |
| | | long asyncDispatchIntervalMs = getAsyncDispatchIntervalMs(); |
| | | long mainDispatchIntervalMs = getMainDispatchIntervalMs(); |
| | | // 仿真异步任务 |
| | | submitAsyncTasks(ASYNC_DISPATCH_INTERVAL_MS); |
| | | fakeStationMonitor.submitMonitorTasks(asyncDispatchIntervalMs); |
| | | // 仿真输送线堵塞检测 |
| | | stationOperateProcessUtils.submitCheckStationRunBlockTasks(MainProcessLane.FAKE_STATION_RUN_BLOCK, ASYNC_DISPATCH_INTERVAL_MS); |
| | | stationOperateProcessUtils.submitCheckStationRunBlockTasks(MainProcessLane.FAKE_STATION_RUN_BLOCK, asyncDispatchIntervalMs); |
| | | |
| | | // 请求生成入库任务 |
| | | generateStoreWrkFile(); |
| | | fakeTaskGenerator.submitGenerateTasks(); |
| | | |
| | | // 执行堆垛机任务 |
| | | crnOperateUtils.submitCrnIoTasks(MainProcessLane.FAKE_CRN_IO, MAIN_DISPATCH_INTERVAL_MS); |
| | | crnOperateUtils.submitCrnIoTasks(MainProcessLane.FAKE_CRN_IO, mainDispatchIntervalMs); |
| | | // 堆垛机任务执行完成 |
| | | submitCrnIoExecuteFinishTasks(MAIN_DISPATCH_INTERVAL_MS); |
| | | submitCrnIoExecuteFinishTasks(mainDispatchIntervalMs); |
| | | // 执行输送站点入库任务 |
| | | stationOperateProcessUtils.submitStationInTasks(MainProcessLane.FAKE_STATION_IN, MAIN_DISPATCH_INTERVAL_MS); |
| | | stationOperateProcessUtils.submitStationInTasks(MainProcessLane.FAKE_STATION_IN, mainDispatchIntervalMs); |
| | | // 检测入库任务是否已经到达目标站台 |
| | | stationOperateProcessUtils.submitInboundStationArrivalTasks(MAIN_DISPATCH_INTERVAL_MS); |
| | | stationOperateProcessUtils.submitInboundStationArrivalTasks(mainDispatchIntervalMs); |
| | | // 输送线执行堆垛机出库后的站台流转 |
| | | stationOperateProcessUtils.submitCrnStationOutTasks(MainProcessLane.FAKE_STATION_OUT, MAIN_DISPATCH_INTERVAL_MS); |
| | | stationOperateProcessUtils.submitCrnStationOutTasks(MainProcessLane.FAKE_STATION_OUT, mainDispatchIntervalMs); |
| | | // 检测出库任务是否已经到达目标站台 |
| | | stationOperateProcessUtils.submitStationOutExecuteFinishTasks(MAIN_DISPATCH_INTERVAL_MS); |
| | | stationOperateProcessUtils.submitStationOutExecuteFinishTasks(mainDispatchIntervalMs); |
| | | // 检测站台运行完成后的任务转完成 |
| | | stationOperateProcessUtils.submitCheckTaskToCompleteTasks(MAIN_DISPATCH_INTERVAL_MS); |
| | | stationOperateProcessUtils.submitCheckTaskToCompleteTasks(mainDispatchIntervalMs); |
| | | // 检测并处理出库排序 |
| | | stationOperateProcessUtils.submitCheckStationOutOrderTasks(MainProcessLane.FAKE_STATION_OUT_ORDER, MAIN_DISPATCH_INTERVAL_MS); |
| | | // 监控输送线绕圈站点 |
| | | stationOperateProcessUtils.submitWatchCircleStationTasks(MainProcessLane.FAKE_STATION_WATCH_CIRCLE, MAIN_DISPATCH_INTERVAL_MS); |
| | | stationOperateProcessUtils.submitCheckStationOutOrderTasks(MainProcessLane.FAKE_STATION_OUT_ORDER, mainDispatchIntervalMs); |
| | | // 执行双工位堆垛机任务 |
| | | dualCrnOperateProcessUtils.submitDualCrnIoTasks(MainProcessLane.FAKE_DUAL_CRN_IO, MAIN_DISPATCH_INTERVAL_MS); |
| | | dualCrnOperateProcessUtils.submitDualCrnIoTasks(MainProcessLane.FAKE_DUAL_CRN_IO, mainDispatchIntervalMs); |
| | | // 双工位堆垛机任务执行完成 |
| | | dualCrnOperateProcessUtils.submitDualCrnIoExecuteFinishTasks(MainProcessLane.FAKE_DUAL_CRN_IO_FINISH, MAIN_DISPATCH_INTERVAL_MS); |
| | | dualCrnOperateProcessUtils.submitDualCrnIoExecuteFinishTasks(MainProcessLane.FAKE_DUAL_CRN_IO_FINISH, mainDispatchIntervalMs); |
| | | |
| | | News.info("[WCS Debug] 主线程Run执行完成,耗时:{}ms", System.currentTimeMillis() - startTime); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void submitAsyncTasks(long minIntervalMs) { |
| | | submitAsyncTask("checkInStationHasTask", minIntervalMs, this::checkInStationHasTask); |
| | | submitAsyncTask("generateFakeInTask", minIntervalMs, this::generateFakeInTask); |
| | | submitAsyncTask("generateFakeOutTask", minIntervalMs, this::generateFakeOutTask); |
| | | submitAsyncTask("calcAllStationStayTime", minIntervalMs, this::calcAllStationStayTime); |
| | | submitAsyncTask("checkOutStationStayTimeOut", minIntervalMs, this::checkOutStationStayTimeOut); |
| | | submitAsyncTask("checkInStationCrnTake", minIntervalMs, this::checkInStationCrnTake); |
| | | } |
| | | |
| | | private void submitAsyncTask(String taskName, long minIntervalMs, Runnable task) { |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | MainProcessLane.FAKE_ASYNC, |
| | | taskName, |
| | | taskName, |
| | | minIntervalMs, |
| | | task |
| | | ); |
| | | private void syncConfigToComponents() { |
| | | fakeStationMonitor.setEnableFake(enableFake); |
| | | fakeStationMonitor.setFakeGenerateInTask(fakeGenerateInTask); |
| | | fakeTaskGenerator.setFakeRealTaskRequestWms(fakeRealTaskRequestWms); |
| | | fakeTaskGenerator.setFakeGenerateInTask(fakeGenerateInTask); |
| | | fakeTaskGenerator.setFakeGenerateOutTask(fakeGenerateOutTask); |
| | | } |
| | | |
| | | private void submitCrnIoExecuteFinishTasks(long minIntervalMs) { |
| | |
| | | } |
| | | } |
| | | |
| | | private void submitGenerateStoreTasks() { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | List<StationObjModel> barcodeStations = getBarcodeStations(basDevp); |
| | | for (StationObjModel stationObjModel : barcodeStations) { |
| | | Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId(); |
| | | if (stationId == null) { |
| | | continue; |
| | | } |
| | | storeInTaskGenerationService.submitGenerateStoreTask( |
| | | this, |
| | | basDevp, |
| | | stationObjModel, |
| | | MainProcessLane.FAKE_GENERATE_STORE, |
| | | MAIN_DISPATCH_INTERVAL_MS, |
| | | () -> storeInTaskGenerationService.generate(this, basDevp, stationObjModel) |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 检测入库站是否有任务生成,并仿真生成模拟入库站点数据 |
| | | private void checkInStationHasTask() { |
| | | if (!enableFake.equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | if (!fakeGenerateInTask.equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> list = basDevp.getInStationList$(); |
| | | for (StationObjModel entity : list) { |
| | | Integer stationId = entity.getStationId(); |
| | | if (!stationMap.containsKey(stationId)) { |
| | | continue; |
| | | } |
| | | |
| | | StationProtocol stationProtocol = stationMap.get(stationId); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId); |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | |
| | | // 满足自动、无物、工作号0,生成入库数据 |
| | | if (stationProtocol.isAutoing() |
| | | && !stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 0) { |
| | | StationCommand command = stationThread.getCommand(StationCommandType.MOVE, |
| | | commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, |
| | | entity.getBarcodeStation().getStationId(), 0); |
| | | stationCommandDispatcher.dispatch(basDevp.getDevpNo(), command, "fake-process", "fake-enable-in"); |
| | | if (entity.getBarcodeStation() != null && entity.getBarcodeStation().getStationId() != null) { |
| | | Utils.precomputeInTaskEnableRow(entity.getBarcodeStation().getStationId()); |
| | | } |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 5); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 生成仿真模拟入库任务 |
| | | private void generateFakeInTask() { |
| | | if (!enableFake.equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | if (fakeRealTaskRequestWms.equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | if (!fakeGenerateInTask.equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> list = basDevp.getBarcodeStationList$(); |
| | | for (StationObjModel model : list) { |
| | | Integer stationId = model.getStationId(); |
| | | if (!stationMap.containsKey(stationId)) { |
| | | continue; |
| | | } |
| | | |
| | | StationProtocol stationProtocol = stationMap.get(stationId); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_TASK_LIMIT.key + stationId); |
| | | if (object != null) { |
| | | continue; |
| | | } |
| | | |
| | | // 满足自动、有物、有工作号,生成入库数据 |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() > 0) { |
| | | if (Cools.isEmpty(stationProtocol.getBarcode())) { |
| | | continue; |
| | | } |
| | | |
| | | // 检测任务是否生成 |
| | | List<WrkMast> wrkMasts = wrkMastService |
| | | .list(new QueryWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | | if (!wrkMasts.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | List<LocMast> locMastList = locMastService |
| | | .list(new QueryWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O))); |
| | | if (locMastList.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | int nextInt = new Random().nextInt(locMastList.size()); |
| | | LocMast locMast = locMastList.get(nextInt); |
| | | |
| | | FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locMast.getLocNo()); |
| | | if (findCrnNoResult == null) { |
| | | continue; |
| | | } |
| | | |
| | | Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationId); |
| | | if (targetStationId == null) { |
| | | continue; |
| | | } |
| | | |
| | | CreateInTaskParam taskParam = new CreateInTaskParam(); |
| | | taskParam.setTaskNo(String.valueOf(commonService.getWorkNo(WrkIoType.IN.id))); |
| | | taskParam.setSourceStaNo(stationId); |
| | | taskParam.setStaNo(targetStationId); |
| | | taskParam.setLocNo(locMast.getLocNo()); |
| | | taskParam.setBarcode(stationProtocol.getBarcode()); |
| | | WrkMast wrkMast = commonService.createInTask(taskParam); |
| | | |
| | | StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), |
| | | stationId, stationId, 0); |
| | | if (command == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | | } |
| | | stationCommandDispatcher.dispatch(basDevp.getDevpNo(), command, "fake-process", "fake-in-task"); |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_TASK_LIMIT.key + stationId, "lock", 5); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 生成仿真模拟出库任务 |
| | | private void generateFakeOutTask() { |
| | | try { |
| | | if (!enableFake.equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | if (fakeRealTaskRequestWms.equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | if (!fakeGenerateOutTask.equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> list = basDevp.getOutStationList$(); |
| | | for (StationObjModel entity : list) { |
| | | Integer stationId = entity.getStationId(); |
| | | if (!stationMap.containsKey(stationId)) { |
| | | continue; |
| | | } |
| | | |
| | | StationProtocol stationProtocol = stationMap.get(stationId); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_OUT_TASK_LIMIT.key + stationId); |
| | | if (object != null) { |
| | | return; |
| | | } |
| | | |
| | | // 满足自动、无物、工作号0,生成出库数据 |
| | | if (stationProtocol.isAutoing() |
| | | && !stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 0) { |
| | | List<LocMast> locMastList = locMastService |
| | | .list(new QueryWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F))); |
| | | if (locMastList.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | LocMast locMast = locMastList.get(0); |
| | | |
| | | CreateOutTaskParam taskParam = new CreateOutTaskParam(); |
| | | taskParam.setTaskNo(String.valueOf(commonService.getWorkNo(WrkIoType.OUT.id))); |
| | | taskParam.setStaNo(stationId); |
| | | taskParam.setLocNo(locMast.getLocNo()); |
| | | boolean result = commonService.createOutTask(taskParam); |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_OUT_TASK_LIMIT.key + stationId, "lock", 10); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("generateFakeOutTask execute error", e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 请求生成入库任务 |
| | | * 入库站,根据条码扫描生成入库工作档 |
| | | */ |
| | | public void generateStoreWrkFile() { |
| | | submitGenerateStoreTasks(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isEnabled() { |
| | | return !"N".equals(fakeRealTaskRequestWms); |
| | | } |
| | | |
| | | @Override |
| | | public boolean matchCandidate(StoreInTaskContext context) { |
| | | StationProtocol stationProtocol = context.getStationProtocol(); |
| | | return stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() > 0 |
| | | && !Cools.isEmpty(stationProtocol.getBarcode()); |
| | | return fakeTaskGenerator.isEnabled(); |
| | | } |
| | | |
| | | @Override |
| | | public void onRequestPermitGranted(StoreInTaskContext context) { |
| | | redisUtil.set(getGenerateLockKey(context), "lock", 3); |
| | | fakeTaskGenerator.onRequestPermitGranted(context); |
| | | } |
| | | |
| | | @Override |
| | | public void afterTaskCreated(StoreInTaskContext context, WrkMast wrkMast) { |
| | | Integer stationId = context.getStationObjModel().getStationId(); |
| | | StationCommand command = context.getStationThread().getCommand(StationCommandType.WRITE_INFO, |
| | | wrkMast.getWrkNo(), stationId, stationId, 0); |
| | | if (command == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | return; |
| | | } |
| | | stationCommandDispatcher.dispatch(context.getBasDevp().getDevpNo(), command, "fake-process", "write-info"); |
| | | } |
| | | |
| | | // 计算所有站点停留时间 |
| | | public void calcAllStationStayTime() { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | List<StationProtocol> list = stationThread.getStatus(); |
| | | for (StationProtocol stationProtocol : list) { |
| | | if (stationProtocol.getTaskNo() > 0 |
| | | && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) { |
| | | stationStayTimeMap.put(stationProtocol.getStationId(), System.currentTimeMillis()); |
| | | } |
| | | |
| | | if (stationProtocol.getTaskNo() <= 0 |
| | | && stationStayTimeMap.containsKey(stationProtocol.getStationId())) { |
| | | stationStayTimeMap.remove(stationProtocol.getStationId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 检测出库站点停留是否超时 |
| | | public void checkOutStationStayTimeOut() { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | List<StationObjModel> outStationList = basDevp.getOutStationList$(); |
| | | if (outStationList.isEmpty()) { |
| | | News.info("输送线:{} 出库站点未设置", basDevp.getDevpNo()); |
| | | continue; |
| | | } |
| | | |
| | | for (StationObjModel stationObjModel : outStationList) { |
| | | Object lock = redisUtil |
| | | .get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId()); |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | |
| | | Long stayTime = stationStayTimeMap.get(stationObjModel.getStationId()); |
| | | if (stayTime == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (System.currentTimeMillis() - stayTime > 1000 * 60) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, |
| | | stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, |
| | | stationObjModel.getStationId(), 0, 0); |
| | | if (command == null) { |
| | | continue; |
| | | } |
| | | |
| | | stationCommandDispatcher.dispatch(stationObjModel.getDeviceNo(), command, "fake-process", "out-station-reset"); |
| | | redisUtil.set( |
| | | RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), |
| | | "lock", 10); |
| | | News.info("输送站点出库重置命令下发成功,站点号={},命令数据={}", stationObjModel.getStationId(), |
| | | JSON.toJSONString(command)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 检测入库站点堆垛机是否取走货物 |
| | | public void checkInStationCrnTake() { |
| | | List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>()); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | List<StationObjModel> inStationList = basCrnp.getInStationList$(); |
| | | if (inStationList.isEmpty()) { |
| | | News.info("堆垛机:{} 入库站点未设置", basCrnp.getCrnNo()); |
| | | continue; |
| | | } |
| | | checkInStationListCrnTake(inStationList); |
| | | } |
| | | |
| | | List<BasDualCrnp> basDualCrnps = basDualCrnpService.list(new QueryWrapper<>()); |
| | | for (BasDualCrnp basDualCrnp : basDualCrnps) { |
| | | List<StationObjModel> inStationList = basDualCrnp.getInStationList$(); |
| | | if (inStationList.isEmpty()) { |
| | | News.info("双工位堆垛机:{} 入库站点未设置", basDualCrnp.getCrnNo()); |
| | | continue; |
| | | } |
| | | checkInStationListCrnTake(inStationList); |
| | | } |
| | | } |
| | | |
| | | private void checkInStationListCrnTake(List<StationObjModel> inStationList) { |
| | | for (StationObjModel stationObjModel : inStationList) { |
| | | Object lock = redisUtil |
| | | .get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId()); |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, |
| | | stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (stationProtocol.getTaskNo() > 0) { |
| | | StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, |
| | | stationObjModel.getStationId(), 0, 0); |
| | | if (command == null) { |
| | | continue; |
| | | } |
| | | |
| | | WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo()); |
| | | if (wrkMast == null) { |
| | | stationCommandDispatcher.dispatch(stationObjModel.getDeviceNo(), command, "fake-process", "in-station-reset-task-over"); |
| | | redisUtil.set( |
| | | RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), |
| | | "lock", 10); |
| | | News.info("输送站点重置命令下发成功(task_over),站点号={},命令数据={}", stationObjModel.getStationId(), |
| | | JSON.toJSONString(command)); |
| | | } else { |
| | | if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts |
| | | && wrkMast.getWrkSts() != WrkStsType.INBOUND_STATION_RUN.sts) { |
| | | Integer crnNo = wrkMast.getCrnNo(); |
| | | if (crnNo != null) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo); |
| | | if (crnThread == null) { |
| | | continue; |
| | | } |
| | | CrnProtocol crnProtocol = crnThread.getStatus(); |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING) |
| | | && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) { |
| | | continue; |
| | | } |
| | | |
| | | stationCommandDispatcher.dispatch(stationObjModel.getDeviceNo(), command, "fake-process", "in-station-reset-crn-fetch"); |
| | | redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key |
| | | + stationObjModel.getStationId(), "lock", 10); |
| | | News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(), |
| | | JSON.toJSONString(command)); |
| | | } else { |
| | | Integer dualCrnNo = wrkMast.getDualCrnNo(); |
| | | DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, |
| | | dualCrnNo); |
| | | if (dualCrnThread == null) { |
| | | continue; |
| | | } |
| | | DualCrnProtocol dualCrnProtocol = dualCrnThread.getStatus(); |
| | | |
| | | boolean reset = false; |
| | | if (dualCrnProtocol.getTaskNo() > 0 && dualCrnProtocol.getLoaded() == 1) { |
| | | reset = true; |
| | | } |
| | | |
| | | if (dualCrnProtocol.getTaskNoTwo() > 0 && dualCrnProtocol.getLoadedTwo() == 1) { |
| | | reset = true; |
| | | } |
| | | |
| | | if (!reset) { |
| | | continue; |
| | | } |
| | | |
| | | stationCommandDispatcher.dispatch(stationObjModel.getDeviceNo(), command, "fake-process", "in-station-reset-dual-crn-fetch"); |
| | | redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key |
| | | + stationObjModel.getStationId(), "lock", 10); |
| | | News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(), |
| | | JSON.toJSONString(command)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | fakeTaskGenerator.afterTaskCreated(context, wrkMast); |
| | | } |
| | | |
| | | // 堆垛机任务执行完成 |
| | |
| | | } else if (wrkMast.getWrkSts() == WrkStsType.OUTBOUND_RUN.sts) { |
| | | updateWrkSts = WrkStsType.OUTBOUND_RUN_COMPLETE.sts; |
| | | |
| | | // 生成仿真站点数据 |
| | | List<StationObjModel> outStationList = basCrnp.getOutStationList$(); |
| | | if (outStationList.isEmpty()) { |
| | | News.info("堆垛机:{} 出库站点未设置", basCrnp.getCrnNo()); |
| | | return; |
| | | } |
| | | |
| | | for (StationObjModel stationObjModel : outStationList) { |
| | | if (!stationObjModel.getStationId().equals(wrkMast.getSourceStaNo())) { |
| | | continue; |
| | | } |
| | | |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, |
| | | stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | // 生成仿真站点数据 |
| | | StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998, |
| | | wrkMast.getSourceStaNo(), 0, 0); |
| | | stationCommandDispatcher.dispatch(stationObjModel.getDeviceNo(), command, "fake-process", "crn-out-complete-write-info"); |
| | | redisUtil.set(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo(), JSON.toJSONString(stationObjModel, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24); |
| | | } |
| | | dispatchOutStationWriteInfoIfReady(wrkMast, basCrnp); |
| | | } else if (wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_RUN.sts) { |
| | | updateWrkSts = WrkStsType.COMPLETE_LOC_MOVE.sts; |
| | | } else if (wrkMast.getWrkSts() == WrkStsType.CRN_MOVE_RUN.sts) { |
| | |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | clearOutStationStayMarker(wrkMast.getWrkNo()); |
| | | wrkAnalysisService.markCraneComplete(wrkMast, now, updateWrkSts); |
| | | CrnCommand resetCommand = crnThread.getResetCommand(crnProtocol.getTaskNo(), crnProtocol.getCrnNo()); |
| | | MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, resetCommand)); |