| | |
| | | |
| | | /** |
| | | * 带超时保护执行方法 |
| | | * |
| | | * @param taskName 任务名称(用于日志) |
| | | * @param task 要执行的任务 |
| | | */ |
| | |
| | | asyncFakeRunThread = new Thread(() -> { |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | Config enableFakeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake")); |
| | | Config enableFakeConfig = configService |
| | | .selectOne(new EntityWrapper<Config>().eq("code", "enableFake")); |
| | | if (enableFakeConfig != null) { |
| | | enableFake = enableFakeConfig.getValue(); |
| | | } |
| | | |
| | | Config fakeRealTaskRequestWmsConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms")); |
| | | Config fakeRealTaskRequestWmsConfig = configService |
| | | .selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms")); |
| | | if (fakeRealTaskRequestWmsConfig != null) { |
| | | fakeRealTaskRequestWms = fakeRealTaskRequestWmsConfig.getValue(); |
| | | } |
| | | |
| | | Config fakeGenerateInTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateInTask")); |
| | | Config fakeGenerateInTaskConfig = configService |
| | | .selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateInTask")); |
| | | if (fakeGenerateInTaskConfig != null) { |
| | | fakeGenerateInTask = fakeGenerateInTaskConfig.getValue(); |
| | | } |
| | | |
| | | Config fakeGenerateOutTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask")); |
| | | Config fakeGenerateOutTaskConfig = configService |
| | | .selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask")); |
| | | if (fakeGenerateOutTaskConfig != null) { |
| | | fakeGenerateOutTask = fakeGenerateOutTaskConfig.getValue(); |
| | | } |
| | |
| | | } |
| | | |
| | | //检测入库站是否有任务生成,并仿真生成模拟入库站点数据 |
| | | private void checkInStationHasTask() { |
| | | private synchronized void checkInStationHasTask() { |
| | | if (!enableFake.equals("Y")) { |
| | | return; |
| | | } |
| | |
| | | //满足自动、无物、工作号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); |
| | | && stationProtocol.getTaskNo() == 0) { |
| | | StationCommand command = stationThread.getCommand(StationCommandType.MOVE, |
| | | commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, |
| | | entity.getBarcodeStation().getStationId(), 0); |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 5); |
| | | } |
| | |
| | | } |
| | | |
| | | //生成仿真模拟入库任务 |
| | | private void generateFakeInTask() { |
| | | private synchronized void generateFakeInTask() { |
| | | if (!enableFake.equals("Y")) { |
| | | return; |
| | | } |
| | |
| | | //满足自动、有物、有工作号,生成入库数据 |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() > 0 |
| | | ) { |
| | | && stationProtocol.getTaskNo() > 0) { |
| | | if (Cools.isEmpty(stationProtocol.getBarcode())) { |
| | | continue; |
| | | } |
| | | |
| | | //检测任务是否生成 |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | | List<WrkMast> wrkMasts = wrkMastService |
| | | .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | | if (!wrkMasts.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O))); |
| | | List<LocMast> locMastList = locMastService |
| | | .selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O))); |
| | | if (locMastList.isEmpty()) { |
| | | continue; |
| | | } |
| | |
| | | taskParam.setBarcode(stationProtocol.getBarcode()); |
| | | WrkMast wrkMast = commonService.createInTask(taskParam); |
| | | |
| | | StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, stationId, 0); |
| | | StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), |
| | | stationId, stationId, 0); |
| | | if(command == null){ |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | |
| | | } |
| | | |
| | | //生成仿真模拟出库任务 |
| | | private void generateFakeOutTask() { |
| | | private synchronized void generateFakeOutTask() { |
| | | if (!enableFake.equals("Y")) { |
| | | return; |
| | | } |
| | |
| | | //满足自动、无物、工作号0,生成出库数据 |
| | | if (stationProtocol.isAutoing() |
| | | && !stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 0 |
| | | ) { |
| | | List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F))); |
| | | && stationProtocol.getTaskNo() == 0) { |
| | | List<LocMast> locMastList = locMastService |
| | | .selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F))); |
| | | if (locMastList.isEmpty()) { |
| | | continue; |
| | | } |
| | |
| | | //满足自动、有物、有工作号,生成入库数据 |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() > 0 |
| | | ) { |
| | | && stationProtocol.getTaskNo() > 0) { |
| | | if (Cools.isEmpty(stationProtocol.getBarcode())) { |
| | | continue; |
| | | } |
| | | |
| | | //检测任务是否生成 |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | | List<WrkMast> wrkMasts = wrkMastService |
| | | .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | | if (!wrkMasts.isEmpty()) { |
| | | continue; |
| | | } |
| | |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2); |
| | | |
| | | String response = wmsOperateUtils.applyInTask(stationProtocol.getBarcode(), stationProtocol.getStationId(), stationProtocol.getPalletHeight()); |
| | | if (response == null) { |
| | | News.error("请求WMS入库接口失败,接口未响应!!!response:{}", response); |
| | | String barcode = stationProtocol.getBarcode(); |
| | | Integer stationIdVal = stationProtocol.getStationId(); |
| | | |
| | | // 1. 首先查询是否有已完成的异步响应 |
| | | String response = wmsOperateUtils.queryAsyncInTaskResponse(barcode, stationIdVal); |
| | | |
| | | if (response != null) { |
| | | // 2. 有响应结果,处理响应 |
| | | if (response.equals("FAILED") || response.startsWith("ERROR:")) { |
| | | // 请求失败,重新发起异步请求 |
| | | News.error("WMS入库请求失败,重新发起请求,barcode={},stationId={},response={}", barcode, |
| | | stationIdVal, response); |
| | | wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal, |
| | | stationProtocol.getPalletHeight()); |
| | | redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2); |
| | | continue; |
| | | } |
| | | |
| | | // 解析响应 |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | |
| | | taskParam.setTaskNo(dto.getTaskNo()); |
| | | taskParam.setLocNo(dto.getLocNo()); |
| | | taskParam.setTaskPri(dto.getTaskPri()); |
| | | taskParam.setBarcode(stationProtocol.getBarcode()); |
| | | taskParam.setBarcode(barcode); |
| | | WrkMast wrkMast = commonService.createInTask(taskParam); |
| | | |
| | | StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, wrkMast.getWrkNo(), stationId, stationId, 0); |
| | | StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, |
| | | wrkMast.getWrkNo(), stationId, stationId, 0); |
| | | if (command == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | | } |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | } else { |
| | | // 接口返回非200,重新发起请求 |
| | | News.error("WMS入库接口返回非200,重新发起请求,barcode={},stationId={},response={}", barcode, |
| | | stationIdVal, response); |
| | | wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal, |
| | | stationProtocol.getPalletHeight()); |
| | | redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2); |
| | | } |
| | | } else { |
| | | // 3. 没有响应结果,检查是否有请求正在进行中 |
| | | if (!wmsOperateUtils.isAsyncRequestInProgress(barcode, stationIdVal)) { |
| | | // 没有请求进行中,发起新的异步请求 |
| | | News.info("发起异步WMS入库请求,barcode={},stationId={}", barcode, stationIdVal); |
| | | wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal, |
| | | stationProtocol.getPalletHeight()); |
| | | redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2); |
| | | } |
| | | // 如果有请求进行中,等待下次循环再检查 |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | //计算所有站点停留时间 |
| | | public void calcAllStationStayTime() { |
| | | public synchronized void calcAllStationStayTime() { |
| | | List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | |
| | | |
| | | List<StationProtocol> list = stationThread.getStatus(); |
| | | for (StationProtocol stationProtocol : list) { |
| | | if (stationProtocol.getTaskNo() > 0 && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) { |
| | | if (stationProtocol.getTaskNo() > 0 |
| | | && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) { |
| | | stationStayTimeMap.put(stationProtocol.getStationId(), System.currentTimeMillis()); |
| | | } |
| | | |
| | | if(stationProtocol.getTaskNo() <= 0 && stationStayTimeMap.containsKey(stationProtocol.getStationId())) { |
| | | if (stationProtocol.getTaskNo() <= 0 |
| | | && stationStayTimeMap.containsKey(stationProtocol.getStationId())) { |
| | | stationStayTimeMap.remove(stationProtocol.getStationId()); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | //检测出库站点停留是否超时 |
| | | public void checkOutStationStayTimeOut() { |
| | | public synchronized void checkOutStationStayTimeOut() { |
| | | List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | List<StationObjModel> outStationList = basDevp.getOutStationList$(); |
| | |
| | | } |
| | | |
| | | for (StationObjModel stationObjModel : outStationList) { |
| | | Object lock = redisUtil.get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId()); |
| | | Object lock = redisUtil |
| | | .get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId()); |
| | | if(lock != null){ |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | if(System.currentTimeMillis() - stayTime > 1000 * 15) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, |
| | | stationObjModel.getDeviceNo()); |
| | | if(stationThread == null){ |
| | | continue; |
| | | } |
| | | |
| | | StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, stationObjModel.getStationId(), 0, 0); |
| | | StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, |
| | | stationObjModel.getStationId(), 0, 0); |
| | | if(command == null){ |
| | | continue; |
| | | } |
| | | |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10); |
| | | News.info("输送站点出库重置命令下发成功,站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command)); |
| | | 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() { |
| | | public synchronized void checkInStationCrnTake() { |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | List<StationObjModel> inStationList = basCrnp.getInStationList$(); |
| | |
| | | } |
| | | } |
| | | |
| | | private void checkInStationListCrnTake(List<StationObjModel> inStationList) { |
| | | private synchronized void checkInStationListCrnTake(List<StationObjModel> inStationList) { |
| | | for (StationObjModel stationObjModel : inStationList) { |
| | | Object lock = redisUtil.get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId()); |
| | | 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()); |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, |
| | | stationObjModel.getDeviceNo()); |
| | | if(stationThread == null){ |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | if(stationProtocol.getTaskNo() > 0) { |
| | | StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, stationObjModel.getStationId(), 0, 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) { |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10); |
| | | News.info("输送站点重置命令下发成功(task_over),站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command)); |
| | | 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_DEVICE_RUN.sts) { |
| | | if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts |
| | | && wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) { |
| | | Integer crnNo = wrkMast.getCrnNo(); |
| | | if (crnNo != null) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo); |
| | |
| | | continue; |
| | | } |
| | | CrnProtocol crnProtocol = crnThread.getStatus(); |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING) && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) { |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING) |
| | | && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) { |
| | | continue; |
| | | } |
| | | |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10); |
| | | News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command)); |
| | | 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); |
| | | DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, |
| | | dualCrnNo); |
| | | if (dualCrnThread == null) { |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10); |
| | | News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command)); |
| | | redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key |
| | | + stationObjModel.getStationId(), "lock", 10); |
| | | News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(), |
| | | JSON.toJSONString(command)); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | //堆垛机任务执行完成 |
| | | public void crnIoExecuteFinish() { |
| | | public synchronized void crnIoExecuteFinish() { |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); |
| | |
| | | |
| | | if (crnProtocol.getMode() == CrnModeType.AUTO.id |
| | | && crnProtocol.getTaskNo() > 0 |
| | | && crnProtocol.getStatus() == CrnStatusType.WAITING.id |
| | | ) { |
| | | && crnProtocol.getStatus() == CrnStatusType.WAITING.id) { |
| | | Object lock = redisUtil.get(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo()); |
| | | if(lock != null){ |
| | | continue; |
| | |
| | | continue; |
| | | } |
| | | |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | 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); |
| | | StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998, |
| | | wrkMast.getSourceStaNo(), 0, 0); |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | } |
| | | }else if(wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_RUN.sts){ |