| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wms.asrs.entity.dto.*; |
| | | import com.zy.asrs.wms.asrs.entity.enums.LocStsType; |
| | | import com.zy.asrs.wms.asrs.entity.enums.OrderSettleType; |
| | | import com.zy.asrs.wms.asrs.entity.dto.OrderOutMergeDto; |
| | | import com.zy.asrs.wms.asrs.entity.enums.*; |
| | | import com.zy.asrs.wms.asrs.entity.param.*; |
| | | import com.zy.asrs.wms.asrs.entity.*; |
| | | import com.zy.asrs.wms.asrs.service.*; |
| | |
| | | private WaveService waveService; |
| | | @Autowired |
| | | private WaveDetlService waveDetlService; |
| | | @Autowired |
| | | private CacheSiteService cacheSiteService; |
| | | @Autowired |
| | | private WaveSeedService waveSeedService; |
| | | |
| | | /** |
| | | * 出库 |
| | |
| | | |
| | | Task task = new Task(); |
| | | task.setTaskNo(workService.generateTaskNo(1L)); |
| | | task.setTaskSts(101L); |
| | | task.setTaskSts(TaskStsType.GENERATE_OUT.id); |
| | | task.setTaskType(taskType); |
| | | task.setIoPri(workService.generateIoPri(taskType)); |
| | | task.setOriginLoc(loc.getLocNo()); |
| | |
| | | TaskDetl taskDetl = new TaskDetl(); |
| | | taskDetl.sync(locDetl); |
| | | taskDetl.setTaskId(task.getId()); |
| | | taskDetl.setTaskNo(task.getTaskNo()); |
| | | taskDetl.setAnfme(detl.getAnfme()); |
| | | taskDetl.setStock(detl.getStock()); |
| | | taskDetl.setOrderId(null); |
| | |
| | | |
| | | Task task = new Task(); |
| | | task.setTaskNo(workService.generateTaskNo(taskType)); |
| | | task.setTaskSts(101L); |
| | | task.setTaskSts(TaskStsType.GENERATE_OUT.id); |
| | | task.setTaskType(taskType); |
| | | task.setIoPri(workService.generateIoPri(taskType)); |
| | | task.setOriginLoc(loc.getLocNo()); |
| | |
| | | taskDetl.sync(locDetl); |
| | | taskDetl.setId(null); |
| | | taskDetl.setTaskId(task.getId()); |
| | | taskDetl.setTaskNo(task.getTaskNo()); |
| | | taskDetl.setAnfme(dto.getAnfme()); |
| | | taskDetl.setStock(locDetl.getAnfme()); |
| | | taskDetl.setOrderId(orderDetl.getOrderId()); |
| | |
| | | for (MergePreviewDto dto : param) { |
| | | List<LocDetl> locDetls = locDetlService.queryStock(dto.getMatnr(), dto.getBatch(), dto.getFieldParams(), sortParams); |
| | | if(locDetls.isEmpty()){ |
| | | MergePreviewResultDto resultDto = new MergePreviewResultDto(); |
| | | resultDto.sync(dto); |
| | | resultDto.setLocs(new ArrayList<>()); |
| | | resultDto.setOrderIds(dto.getOrderIds()); |
| | | resultDto.setAnfme(dto.getAnfme()); |
| | | resultDtos.add(resultDto); |
| | | continue; |
| | | } |
| | | |
| | |
| | | |
| | | Double anfme = dto.getAnfme(); |
| | | for (LocDetl locDetl : locDetls) { |
| | | Loc loc = locService.getById(locDetl.getLocId()); |
| | | if (loc == null) { |
| | | throw new CoolException("库位数据不存在"); |
| | | } |
| | | |
| | | if (loc.getLocStsId() != LocStsType.F.val()) { |
| | | continue; |
| | | } |
| | | |
| | | MergePreviewResultLocDto locDto = new MergePreviewResultLocDto(); |
| | | locDto.setLocId(locDetl.getLocId()); |
| | | locDto.setLocNo(locDetl.getLocNo()); |
| | |
| | | locDto.setAnfme(locDetl.getAnfme()); |
| | | anfme -= locDetl.getAnfme(); |
| | | } |
| | | resultDto.setAnfme(anfme < 0 ? 0 : anfme); |
| | | |
| | | List<MergePreviewResultLocDto> otherLocDtos = new ArrayList<>(); |
| | | for (LocDetl locDetl : locDetls) { |
| | | Loc loc = locService.getById(locDetl.getLocId()); |
| | | if (loc == null) { |
| | | throw new CoolException("库位数据不存在"); |
| | | } |
| | | |
| | | if (loc.getLocStsId() != LocStsType.F.val()) { |
| | | continue; |
| | | } |
| | | |
| | | MergePreviewResultLocDto locDto = new MergePreviewResultLocDto(); |
| | | locDto.setLocId(locDetl.getLocId()); |
| | | locDto.setLocNo(locDetl.getLocNo()); |
| | | locDto.setLocDetlId(locDetl.getId()); |
| | | locDto.setAnfme(locDetl.getAnfme()); |
| | | otherLocDtos.add(locDto); |
| | | } |
| | | resultDto.setOtherLocs(otherLocDtos); |
| | | |
| | | resultDto.setAnfme(dto.getAnfme()); |
| | | |
| | | resultDtos.add(resultDto); |
| | | } |
| | |
| | | } |
| | | |
| | | @Transactional |
| | | public void orderOutMerge(List<OrderOutMergeParam> params) { |
| | | if(params == null){ |
| | | public void orderOutMerge(OrderOutMergeParamDto dto) { |
| | | if(dto == null){ |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | List<OrderOutMergeParam> params = dto.getList(); |
| | | |
| | | if (params.isEmpty()) { |
| | | throw new CoolException("参数不能为空"); |
| | |
| | | map.put(orderOutMergeDto.getLocId(), list); |
| | | } |
| | | |
| | | List<TaskDetl> taskDetls = new ArrayList<>(); |
| | | for (Map.Entry<Long, List<OrderOutMergeDto>> entry : map.entrySet()) { |
| | | Long locId = entry.getKey(); |
| | | List<OrderOutMergeDto> list = entry.getValue(); |
| | |
| | | |
| | | Task task = new Task(); |
| | | task.setTaskNo(workService.generateTaskNo(taskType)); |
| | | task.setTaskSts(101L); |
| | | task.setTaskSts(TaskStsType.GENERATE_OUT.id); |
| | | task.setTaskType(taskType); |
| | | task.setIoPri(workService.generateIoPri(taskType)); |
| | | task.setOriginLoc(loc.getLocNo()); |
| | |
| | | taskDetl.sync(locDetl); |
| | | taskDetl.setId(null); |
| | | taskDetl.setTaskId(task.getId()); |
| | | taskDetl.setTaskNo(task.getTaskNo()); |
| | | taskDetl.setAnfme(merge.getAnfme()); |
| | | taskDetl.setStock(locDetl.getAnfme()); |
| | | taskDetl.setOrderId(orderDetl.getOrderId()); |
| | |
| | | throw new CoolException("明细扩展生成失败"); |
| | | } |
| | | } |
| | | |
| | | taskDetls.add(taskDetl); |
| | | } |
| | | |
| | | //库位F => R |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | public void generateWave(List<Long> orderIds) { |
| | | if (orderIds == null) { |
| | | public void orderOutMergeWave(OrderOutMergeParamDto dto) { |
| | | if(dto == null){ |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | if (orderIds.isEmpty()) { |
| | | if (dto.getWaveId() == null) { |
| | | throw new CoolException("未生成波次"); |
| | | } |
| | | |
| | | List<OrderOutMergeParam> params = dto.getList(); |
| | | |
| | | if (params.isEmpty()) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | Long waveId = dto.getWaveId(); |
| | | |
| | | List<Long> filterParamsList = new ArrayList<>(); |
| | | List<OrderOutMergeParam> filterParams = new ArrayList<>(); |
| | | for (OrderOutMergeParam param : params) { |
| | | if (param.getLocId() == null) { |
| | | continue; |
| | | } |
| | | |
| | | if(!filterParamsList.contains(param.getLocId())){ |
| | | filterParamsList.add(param.getLocId()); |
| | | filterParams.add(param); |
| | | } |
| | | } |
| | | |
| | | HashMap<String, Double> stockMap = new HashMap<>(); |
| | | for (OrderOutMergeParam param : filterParams) { |
| | | String matUniqueKey = Utils.getMatUniqueKey(param.getMatnr(), param.getBatch(), param.getFieldParams()); |
| | | WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getStockIndex, matUniqueKey).eq(WaveDetl::getWaveId, waveId)); |
| | | if(waveDetl == null){ |
| | | throw new CoolException("波次数据不存在"); |
| | | } |
| | | |
| | | double issued = Optional.of(waveDetl.getAnfme() - waveDetl.getWorkQty()).orElse(0.0D); |
| | | if(!stockMap.containsKey(matUniqueKey)){ |
| | | stockMap.put(matUniqueKey, issued); |
| | | } |
| | | } |
| | | |
| | | HashMap<Long, List<OrderOutMergeDto>> map = new HashMap<>(); |
| | | for (OrderOutMergeParam param : filterParams) { |
| | | LocDetl locDetl = locDetlService.getById(param.getLocDetlId()); |
| | | if(locDetl == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (locDetl.getAnfme() - param.getAnfme() < 0) { |
| | | continue; |
| | | } |
| | | |
| | | OrderOutMergeDto orderOutMergeDto = new OrderOutMergeDto(); |
| | | orderOutMergeDto.sync(param); |
| | | |
| | | String matUniqueKey = Utils.getMatUniqueKey(param.getMatnr(), param.getBatch(), param.getFieldParams()); |
| | | Double issued = stockMap.get(matUniqueKey); |
| | | if (issued - orderOutMergeDto.getAnfme() < 0) { |
| | | orderOutMergeDto.setAnfme(issued); |
| | | issued = 0D; |
| | | }else { |
| | | issued -= orderOutMergeDto.getAnfme(); |
| | | } |
| | | stockMap.put(matUniqueKey, issued); |
| | | |
| | | List<OrderOutMergeDto> list = null; |
| | | if (map.containsKey(orderOutMergeDto.getLocId())) { |
| | | list = map.get(orderOutMergeDto.getLocId()); |
| | | }else { |
| | | list = new ArrayList<>(); |
| | | } |
| | | list.add(orderOutMergeDto); |
| | | map.put(orderOutMergeDto.getLocId(), list); |
| | | } |
| | | |
| | | if (map.isEmpty()) { |
| | | throw new CoolException("库存不足"); |
| | | } |
| | | |
| | | for (Map.Entry<Long, List<OrderOutMergeDto>> entry : map.entrySet()) { |
| | | Long locId = entry.getKey(); |
| | | List<OrderOutMergeDto> list = entry.getValue(); |
| | | Boolean all = outUtils.isAllForMerge(locId, list); |
| | | OrderOutMergeDto param = list.get(0); |
| | | Long operationPortId = param.getOperationPort(); |
| | | |
| | | Loc loc = locService.getById(locId); |
| | | if (loc == null) { |
| | | throw new CoolException("库位不存在"); |
| | | } |
| | | |
| | | if (!loc.getLocStsId().equals(LocStsType.F.val())) { |
| | | throw new CoolException(loc.getLocNo() + "库位状态异常"); |
| | | } |
| | | |
| | | OperationPort operationPort = operationPortService.getById(operationPortId); |
| | | if (operationPort == null) { |
| | | throw new CoolException("作业口不存在"); |
| | | } |
| | | |
| | | long taskType = all ? 101L : 103L; |
| | | |
| | | Task task = new Task(); |
| | | task.setTaskNo(workService.generateTaskNo(taskType)); |
| | | task.setTaskSts(TaskStsType.GENERATE_OUT.id); |
| | | task.setTaskType(taskType); |
| | | task.setIoPri(workService.generateIoPri(taskType)); |
| | | task.setOriginLoc(loc.getLocNo()); |
| | | task.setTargetSite(operationPort.getFlag()); |
| | | task.setBarcode(loc.getBarcode()); |
| | | boolean res = taskService.save(task); |
| | | if (!res) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | |
| | | for (OrderOutMergeDto merge : list) { |
| | | LocDetl locDetl = locDetlService.getById(merge.getLocDetlId()); |
| | | if(locDetl == null) { |
| | | throw new CoolException("明细不存在"); |
| | | } |
| | | |
| | | TaskDetl taskDetl = new TaskDetl(); |
| | | taskDetl.sync(locDetl); |
| | | taskDetl.setId(null); |
| | | taskDetl.setTaskId(task.getId()); |
| | | taskDetl.setTaskNo(task.getTaskNo()); |
| | | taskDetl.setAnfme(merge.getAnfme()); |
| | | taskDetl.setStock(locDetl.getAnfme()); |
| | | taskDetl.setWaveId(waveId); |
| | | taskDetl.setOrderId(null); |
| | | taskDetl.setOrderNo(null); |
| | | if (!taskDetlService.save(taskDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | |
| | | List<LocDetlField> locDetlFields = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId())); |
| | | for (LocDetlField locDetlField : locDetlFields) { |
| | | TaskDetlField taskDetlField = new TaskDetlField(); |
| | | taskDetlField.sync(locDetlField); |
| | | taskDetlField.setId(null); |
| | | taskDetlField.setDetlId(taskDetl.getId()); |
| | | boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField); |
| | | if(!taskDetlFieldSave){ |
| | | throw new CoolException("明细扩展生成失败"); |
| | | } |
| | | } |
| | | |
| | | String matUniqueKey = Utils.getMatUniqueKey(taskDetl.getMatnr(), taskDetl.getBatch(), taskDetl.getUniqueField()); |
| | | WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getStockIndex, matUniqueKey).eq(WaveDetl::getWaveId, waveId)); |
| | | if (waveDetl == null) { |
| | | throw new CoolException("波次数据不存在"); |
| | | } |
| | | waveDetl.setWorkQty(waveDetl.getWorkQty() + taskDetl.getAnfme()); |
| | | waveDetl.setUpdateTime(new Date()); |
| | | if (!waveDetlService.updateById(waveDetl)) { |
| | | throw new CoolException("波次数据更新失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | //库位F => R |
| | | loc.setLocStsId(LocStsType.R.val()); |
| | | loc.setUpdateTime(new Date()); |
| | | boolean locUpdate = locService.updateById(loc); |
| | | if(!locUpdate){ |
| | | throw new CoolException("库位状态更新失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | Wave wave = waveService.getById(waveId); |
| | | if (wave == null) { |
| | | throw new CoolException("波次不存在"); |
| | | } |
| | | |
| | | wave.setWaveStatus(WaveStatusType.GENERATE.id); |
| | | wave.setUpdateTime(new Date()); |
| | | if (!waveService.updateById(wave)) { |
| | | throw new CoolException("波次更新失败"); |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | public void generateWave(GenerateWaveParam param) { |
| | | if (param == null) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | List<String> channels = param.getChannels(); |
| | | if (channels == null) { |
| | | throw new CoolException("通道参数不能为空"); |
| | | } |
| | | |
| | | if (channels.isEmpty()) { |
| | | throw new CoolException("通道参数不能为空"); |
| | | } |
| | | |
| | | for (String channel : channels) { |
| | | long count = cacheSiteService.count(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getChannel, channel).ne(CacheSite::getSiteStatus, 0)); |
| | | if (count > 0) { |
| | | throw new CoolException(channel + "通道已经分配波次"); |
| | | } |
| | | } |
| | | |
| | | |
| | | List<Long> orderIds = param.getOrderIds(); |
| | | if (orderIds == null) { |
| | | throw new CoolException("订单参数不能为空"); |
| | | } |
| | | |
| | | if (orderIds.isEmpty()) { |
| | | throw new CoolException("订单参数不能为空"); |
| | | } |
| | | |
| | | List<Order> orderList = orderService.listByIds(orderIds); |
| | |
| | | Wave wave = new Wave(); |
| | | wave.setWaveNo(waveNo); |
| | | wave.setWaveType(0); |
| | | wave.setWaveStatus(WaveStatusType.INIT.id); |
| | | if (!waveService.save(wave)) { |
| | | throw new CoolException("波次生成失败"); |
| | | } |
| | | |
| | | HashMap<String, List<OrderDetl>> map = new HashMap<>(); |
| | | for (Order order : orderList) { |
| | | WaveDetl waveDetl = new WaveDetl(); |
| | | waveDetl.setWaveNo(waveNo); |
| | | waveDetl.setWaveId(wave.getId()); |
| | | waveDetl.setOrderId(order.getId()); |
| | | waveDetl.setOrderNo(order.getOrderNo()); |
| | | if (!waveDetlService.save(waveDetl)) { |
| | | throw new CoolException("波次明细生成失败"); |
| | | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getOrderId, order.getId())); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | List<OrderDetl> list = map.get(orderDetl.getStockIndex()); |
| | | if (list == null) { |
| | | list = new ArrayList<>(); |
| | | } |
| | | list.add(orderDetl); |
| | | map.put(orderDetl.getStockIndex(), list); |
| | | } |
| | | |
| | | order.setOrderSettle(OrderSettleType.WAVE.val()); |
| | | order.setWaveId(wave.getId()); |
| | | order.setWaveNo(waveNo); |
| | | order.setHasWave(1); |
| | | order.setUpdateTime(new Date()); |
| | | if (!orderService.updateById(order)) { |
| | | throw new CoolException("订单反写波次失败"); |
| | | } |
| | | |
| | | List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getSiteStatus, CacheSiteStatusType.O.id).in(CacheSite::getChannel, channels).orderBy(true, true, CacheSite::getChannel)); |
| | | if (cacheSites.isEmpty()) { |
| | | throw new CoolException("缓存站空间不足,请稍后再试"); |
| | | } |
| | | |
| | | CacheSite cacheSite = cacheSites.get(0); |
| | | cacheSite.setOrderId(order.getId()); |
| | | cacheSite.setOrderNo(order.getOrderNo()); |
| | | cacheSite.setSiteStatus(CacheSiteStatusType.R.id); |
| | | cacheSite.setUpdateTime(new Date()); |
| | | if (!cacheSiteService.updateById(cacheSite)) { |
| | | throw new CoolException("缓存站更新失败"); |
| | | } |
| | | } |
| | | |
| | | for (Map.Entry<String, List<OrderDetl>> entry : map.entrySet()) { |
| | | String stockIndex = entry.getKey(); |
| | | List<OrderDetl> orderDetls = entry.getValue(); |
| | | Double anfme = 0D; |
| | | Long matId = null; |
| | | String matnr = null; |
| | | String batch = null; |
| | | List<FieldParam> uniqueField = null; |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | anfme += orderDetl.getAnfme(); |
| | | matId = orderDetl.getMatId(); |
| | | matnr = orderDetl.getMat$().getMatnr(); |
| | | batch = orderDetl.getBatch(); |
| | | uniqueField = orderDetl.getUniqueField(); |
| | | } |
| | | |
| | | WaveDetl waveDetl = new WaveDetl(); |
| | | waveDetl.setWaveNo(waveNo); |
| | | waveDetl.setWaveId(wave.getId()); |
| | | waveDetl.setStockIndex(stockIndex); |
| | | waveDetl.setMatId(matId); |
| | | waveDetl.setMatnr(matnr); |
| | | waveDetl.setBatch(batch); |
| | | waveDetl.setAnfme(anfme); |
| | | waveDetl.setWorkQty(0D); |
| | | waveDetl.setFieldParams(JSON.toJSONString(uniqueField)); |
| | | if (!waveDetlService.save(waveDetl)) { |
| | | throw new CoolException("波次明细生成失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | for (Wave wave : waves) { |
| | | List<WaveDetl> waveDetls = waveDetlService.list(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getWaveId, wave.getId())); |
| | | for (WaveDetl waveDetl : waveDetls) { |
| | | Order order = orderService.getById(waveDetl.getOrderId()); |
| | | order.setWaveId(null); |
| | | order.setWaveNo(null); |
| | | if (!orderService.updateById(order)) { |
| | | throw new CoolException("订单反写失败"); |
| | | long count = taskDetlService.count(new LambdaQueryWrapper<TaskDetl>().eq(TaskDetl::getWaveId, wave.getId())); |
| | | if (count > 0) { |
| | | throw new CoolException("已存在任务,禁止取消波次"); |
| | | } |
| | | |
| | | List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getWaveId, wave.getId())); |
| | | for (Order order : orders) { |
| | | order.setWaveId(null); |
| | | order.setWaveNo(null); |
| | | order.setHasWave(0); |
| | | if(order.getOrderSettle().equals(OrderSettleType.WAVE.val())){ |
| | | order.setOrderSettle(OrderSettleType.WAIT.val()); |
| | | } |
| | | if (!orderService.updateById(order)) { |
| | | throw new CoolException("订单反写失败"); |
| | | } |
| | | |
| | | CacheSite cacheSite = cacheSiteService.getOne(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getOrderId, order.getId())); |
| | | if (cacheSite == null) { |
| | | throw new CoolException("缓存站不存在"); |
| | | } |
| | | cacheSite.setSiteStatus(CacheSiteStatusType.O.id); |
| | | cacheSite.setOrderId(null); |
| | | cacheSite.setOrderNo(null); |
| | | cacheSite.setUpdateTime(new Date()); |
| | | if (!cacheSiteService.updateById(cacheSite)) { |
| | | throw new CoolException("缓存站清空失败"); |
| | | } |
| | | } |
| | | |
| | | waveDetlService.removeById(waveDetl.getId()); |