| | |
| | | package com.zy.common.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.domain.Result.CancelTaskBatchResult; |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class CommonService { |
| | | |
| | | private static final long OUT_STATION_ROUTE_CACHE_SECONDS = 60 * 60 * 24 * 30; |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | |
| | | wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts); |
| | | } else if (wrkMast.getIoType() == WrkIoType.LOC_MOVE.id) { |
| | | wrkMast.setWrkSts(WrkStsType.COMPLETE_LOC_MOVE.sts); |
| | | } else if (wrkMast.getIoType() == WrkIoType.CRN_MOVE.id) { |
| | | wrkMast.setWrkSts(WrkStsType.COMPLETE_CRN_MOVE.sts); |
| | | } |
| | | |
| | | wrkMast.setModiTime(new Date()); |
| | |
| | | } else if (wrkMast.getIoType().equals(WrkIoType.OUT.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_OUTBOUND.sts)) { |
| | | cancelSuccess = true; |
| | | } else if (wrkMast.getIoType().equals(WrkIoType.LOC_MOVE.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_LOC_MOVE.sts)) { |
| | | cancelSuccess = true; |
| | | } else if (wrkMast.getIoType().equals(WrkIoType.CRN_MOVE.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_CRN_MOVE.sts)) { |
| | | cancelSuccess = true; |
| | | } |
| | | |
| | |
| | | wrkMast.setModiTime(new Date()); |
| | | wrkMastService.updateById(wrkMast); |
| | | return true; |
| | | } |
| | | |
| | | public CancelTaskBatchResult cancelOutTaskBatchInfo(CancelTaskBatchParam param) { |
| | | if (param == null) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | List<CancelTaskParam> taskList = param.getTaskList(); |
| | | if (taskList == null || taskList.isEmpty()) { |
| | | throw new CoolException("任务参数列表为空"); |
| | | } |
| | | |
| | | List<String> successList = new ArrayList<>(); |
| | | List<String> failList = new ArrayList<>(); |
| | | for (CancelTaskParam taskParam : taskList) { |
| | | if (taskParam == null) { |
| | | throw new CoolException("任务参数不能为空"); |
| | | } |
| | | boolean cancelStatus = false; |
| | | try { |
| | | cancelStatus = cancelSingleOutTaskBatchInfo(taskParam); |
| | | } catch (Exception e) { |
| | | } |
| | | |
| | | if (cancelStatus) { |
| | | successList.add(resolveTaskIdentifier(taskParam)); |
| | | } else { |
| | | failList.add(resolveTaskIdentifier(taskParam)); |
| | | } |
| | | } |
| | | |
| | | CancelTaskBatchResult result = new CancelTaskBatchResult(); |
| | | result.setSuccessList(successList); |
| | | result.setFailList(failList); |
| | | return result; |
| | | } |
| | | |
| | | private boolean cancelSingleOutTaskBatchInfo(CancelTaskParam param) { |
| | | WrkMast wrkMast = null; |
| | | Integer wrkNo = param.getWrkNo(); |
| | | String taskNo = param.getTaskNo(); |
| | | if (wrkNo == null) { |
| | | if (Cools.isEmpty(taskNo)) { |
| | | throw new CoolException("WMS任务号不能为空"); |
| | | } |
| | | wrkMast = wrkMastService.getOne(new QueryWrapper<WrkMast>().eq("wms_wrk_no", taskNo)); |
| | | } else { |
| | | wrkMast = wrkMastService.selectByWorkNo(wrkNo); |
| | | } |
| | | if (wrkMast == null) { |
| | | throw new CoolException("任务不存在"); |
| | | } |
| | | if (!wrkMast.getIoType().equals(WrkIoType.OUT.id)) { |
| | | throw new CoolException("仅支持出库任务"); |
| | | } |
| | | |
| | | boolean updated = wrkMast.getWrkNo() != null && wrkMastService.update(null, new UpdateWrapper<WrkMast>() |
| | | .eq("wrk_no", wrkMast.getWrkNo()) |
| | | .set("batch", null) |
| | | .set("batch_seq", null) |
| | | .set("modi_time", new Date())); |
| | | if (!updated) { |
| | | throw new CoolException("取消出库任务批次和批次序号失败"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private String resolveTaskIdentifier(CancelTaskParam param) { |
| | | if (!Cools.isEmpty(param.getTaskNo())) { |
| | | return param.getTaskNo(); |
| | | } |
| | | if (param.getWrkNo() != null) { |
| | | return String.valueOf(param.getWrkNo()); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | public CancelTaskBatchResult cancelTaskBatch(CancelTaskBatchParam param) { |
| | |
| | | stationList = basDualCrnp.getInStationList$(); |
| | | } |
| | | |
| | | Integer cachedTargetStationId = resolveCachedInStationId(findCrnNoResult, sourceStationId, stationList); |
| | | if (cachedTargetStationId != null) { |
| | | return cachedTargetStationId; |
| | | } |
| | | |
| | | Integer targetStationId = null; |
| | | for (StationObjModel stationObjModel : stationList) { |
| | | try { |
| | | List<NavigateNode> navigateNodes = navigateUtils.calcReachablePathByStationId(sourceStationId, stationObjModel.getStationId()); |
| | | if(!navigateNodes.isEmpty()) { |
| | | targetStationId = stationObjModel.getStationId(); |
| | | cacheInStationId(findCrnNoResult, sourceStationId, targetStationId); |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | stationList = basDualCrnp.getOutStationList$(); |
| | | } |
| | | |
| | | Integer cachedSourceStationId = resolveCachedOutStationId(findCrnNoResult, targetStationId, stationList); |
| | | if (cachedSourceStationId != null) { |
| | | return cachedSourceStationId; |
| | | } |
| | | |
| | | Integer finalSourceStationId = null; |
| | | for (StationObjModel stationObjModel : stationList) { |
| | | try { |
| | | List<NavigateNode> navigateNodes = navigateUtils.calcReachablePathByStationId(stationObjModel.getStationId(), targetStationId); |
| | | if(!navigateNodes.isEmpty()) { |
| | | finalSourceStationId = stationObjModel.getStationId(); |
| | | cacheOutStationId(findCrnNoResult, targetStationId, finalSourceStationId); |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | return finalSourceStationId; |
| | | } |
| | | |
| | | /** |
| | | * 入库路径搜索同样代价较高,只缓存已确认可达的目标站点结果,并通过 TTL 限制陈旧风险。 |
| | | */ |
| | | private Integer resolveCachedInStationId(FindCrnNoResult findCrnNoResult, |
| | | Integer sourceStationId, |
| | | List<StationObjModel> stationList) { |
| | | if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null |
| | | || findCrnNoResult.getCrnNo() == null || sourceStationId == null |
| | | || stationList == null || stationList.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | Object cacheValue = redisUtil.get(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId)); |
| | | if (cacheValue == null) { |
| | | return null; |
| | | } |
| | | |
| | | Integer cachedStationId = parseInteger(cacheValue); |
| | | if (cachedStationId == null) { |
| | | return null; |
| | | } |
| | | |
| | | for (StationObjModel stationObjModel : stationList) { |
| | | if (stationObjModel != null && cachedStationId.equals(stationObjModel.getStationId())) { |
| | | return cachedStationId; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private void cacheInStationId(FindCrnNoResult findCrnNoResult, |
| | | Integer sourceStationId, |
| | | Integer targetStationId) { |
| | | if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null |
| | | || findCrnNoResult.getCrnNo() == null || sourceStationId == null |
| | | || targetStationId == null) { |
| | | return; |
| | | } |
| | | redisUtil.set(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId), |
| | | targetStationId, |
| | | OUT_STATION_ROUTE_CACHE_SECONDS); |
| | | } |
| | | |
| | | private String buildInStationRouteCacheKey(FindCrnNoResult findCrnNoResult, Integer sourceStationId) { |
| | | return RedisKeyType.IN_STATION_ROUTE_CACHE.key |
| | | + findCrnNoResult.getCrnType().name() |
| | | + "_" |
| | | + findCrnNoResult.getCrnNo() |
| | | + "_" |
| | | + sourceStationId; |
| | | } |
| | | |
| | | /** |
| | | * 出库路径搜索代价较高,只缓存已确认可达的站点结果,并通过 TTL 控制陈旧风险。 |
| | | */ |
| | | private Integer resolveCachedOutStationId(FindCrnNoResult findCrnNoResult, |
| | | Integer targetStationId, |
| | | List<StationObjModel> stationList) { |
| | | if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null |
| | | || findCrnNoResult.getCrnNo() == null || targetStationId == null |
| | | || stationList == null || stationList.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | Object cacheValue = redisUtil.get(buildOutStationRouteCacheKey(findCrnNoResult, targetStationId)); |
| | | if (cacheValue == null) { |
| | | return null; |
| | | } |
| | | |
| | | Integer cachedStationId = parseInteger(cacheValue); |
| | | if (cachedStationId == null) { |
| | | return null; |
| | | } |
| | | |
| | | for (StationObjModel stationObjModel : stationList) { |
| | | if (stationObjModel != null && cachedStationId.equals(stationObjModel.getStationId())) { |
| | | return cachedStationId; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private void cacheOutStationId(FindCrnNoResult findCrnNoResult, |
| | | Integer targetStationId, |
| | | Integer sourceStationId) { |
| | | if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null |
| | | || findCrnNoResult.getCrnNo() == null || targetStationId == null |
| | | || sourceStationId == null) { |
| | | return; |
| | | } |
| | | redisUtil.set(buildOutStationRouteCacheKey(findCrnNoResult, targetStationId), |
| | | sourceStationId, |
| | | OUT_STATION_ROUTE_CACHE_SECONDS); |
| | | } |
| | | |
| | | private String buildOutStationRouteCacheKey(FindCrnNoResult findCrnNoResult, Integer targetStationId) { |
| | | return RedisKeyType.OUT_STATION_ROUTE_CACHE.key |
| | | + findCrnNoResult.getCrnType().name() |
| | | + "_" |
| | | + findCrnNoResult.getCrnNo() |
| | | + "_" |
| | | + targetStationId; |
| | | } |
| | | |
| | | private Integer parseInteger(Object value) { |
| | | if (value == null) { |
| | | return null; |
| | | } |
| | | if (value instanceof Integer) { |
| | | return (Integer) value; |
| | | } |
| | | if (value instanceof Number) { |
| | | return ((Number) value).intValue(); |
| | | } |
| | | try { |
| | | return Integer.parseInt(String.valueOf(value)); |
| | | } catch (Exception ignore) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | } |