| | |
| | | package com.zy.asrs.wms.asrs.manage; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.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.*; |
| | | import com.zy.asrs.wms.utils.OrderUtils; |
| | | import com.zy.asrs.wms.utils.OutUtils; |
| | | import com.zy.asrs.wms.utils.Utils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 出库管理 |
| | | */ |
| | | @Service |
| | | public class OutManage { |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(LocManage.class); |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private TaskDetlService taskDetlService; |
| | | @Autowired |
| | | private TaskDetlFieldService taskDetlFieldService; |
| | | @Autowired |
| | | private LocService locService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private LocDetlFieldService locDetlFieldService; |
| | | @Autowired |
| | | private WorkService workService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private OutUtils outUtils; |
| | | @Autowired |
| | | private OperationPortService operationPortService; |
| | | @Autowired |
| | | private OrderUtils orderUtils; |
| | | @Autowired |
| | | private OrderNoRuleService orderNoRuleService; |
| | | @Autowired |
| | | private WaveService waveService; |
| | | @Autowired |
| | | private WaveDetlService waveDetlService; |
| | | @Autowired |
| | | private CacheSiteService cacheSiteService; |
| | | @Autowired |
| | | private WaveSeedService waveSeedService; |
| | | |
| | | /** |
| | | * 出库 |
| | | */ |
| | | @Transactional |
| | | public void out(OutParam outParam) { |
| | | if (outParam.getOperationPort() == null) { |
| | | throw new CoolException("作业口不存在"); |
| | | } |
| | | |
| | | List<OutLocDto> list = outUtils.merge(outParam); |
| | | processTask(list); |
| | | } |
| | | |
| | | private void processTask(List<OutLocDto> list) { |
| | | for (OutLocDto locDto : list) { |
| | | long taskType = locDto.getAll() ? 101L : 103L; |
| | | |
| | | Loc loc = locService.getById(locDto.getLocId()); |
| | | if(loc == null) { |
| | | throw new CoolException("库位不存在"); |
| | | } |
| | | |
| | | if (!loc.getLocStsId().equals(LocStsType.F.val())) { |
| | | throw new CoolException("库位状态不在库"); |
| | | } |
| | | |
| | | Task task = new Task(); |
| | | task.setTaskNo(workService.generateTaskNo(1L)); |
| | | task.setTaskSts(TaskStsType.GENERATE_OUT.id); |
| | | task.setTaskType(taskType); |
| | | task.setIoPri(workService.generateIoPri(taskType)); |
| | | task.setOriginLoc(loc.getLocNo()); |
| | | task.setTargetSite(locDto.getOperationPort()); |
| | | task.setBarcode(loc.getBarcode()); |
| | | boolean res = taskService.save(task); |
| | | if (!res) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | | for (OutDetlDto detl : locDto.getDetls()) { |
| | | LocDetl locDetl = locDetlService.getById(detl.getDetlId()); |
| | | if(locDetl == null) { |
| | | throw new CoolException("明细不存在"); |
| | | } |
| | | |
| | | 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); |
| | | 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.setDetlId(taskDetl.getId()); |
| | | boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField); |
| | | if(!taskDetlFieldSave){ |
| | | throw new CoolException("明细扩展生成失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //库位F => R |
| | | loc.setLocStsId(LocStsType.R.val()); |
| | | loc.setUpdateTime(new Date()); |
| | | boolean locUpdate = locService.updateById(loc); |
| | | if(!locUpdate){ |
| | | throw new CoolException("库位状态更新失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public List<OrderOutBatchPreviewDto> orderOutBatchPreview(OrderOutBatchPreviewParam param) { |
| | | List<Long> orderDetlIds = param.getOrderDetlIds(); |
| | | if (orderDetlIds.isEmpty()) { |
| | | throw new CoolException("订单明细不能为空"); |
| | | } |
| | | |
| | | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getId, orderDetlIds).orderByAsc(OrderDetl::getOrderNo, OrderDetl::getCreateTime)); |
| | | if (orderDetls.isEmpty()) { |
| | | throw new CoolException("订单明细不存在"); |
| | | } |
| | | orderDetls = orderDetlService.parseDetl(orderDetls); |
| | | |
| | | HashMap<Long, List<LocDetl>> orderDetlLocMap = new HashMap<>(); |
| | | List<OutDetlDto> detlDtos = new ArrayList<>(); |
| | | |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | if (issued <= 0.0D) { continue; } |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMat$().getMatnr(), orderDetl.getBatch(), orderDetl.getUniqueField()); |
| | | orderDetlLocMap.put(orderDetl.getId(), locDetls); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | OutDetlDto outDetlDto = new OutDetlDto(); |
| | | outDetlDto.setDetlId(locDetl.getId()); |
| | | outDetlDto.setAnfme(issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued); |
| | | outDetlDto.setStock(locDetl.getAnfme()); |
| | | outDetlDto.setOrderDetlId(orderDetl.getId()); |
| | | detlDtos.add(outDetlDto); |
| | | issued = issued - outDetlDto.getAnfme(); |
| | | }else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | HashMap<Long, List<OutDetlDto>> map = new HashMap<>(); |
| | | for (OutDetlDto detlDto : detlDtos) { |
| | | LocDetl locDetl = locDetlService.getById(detlDto.getDetlId()); |
| | | List<OutDetlDto> dtos = map.get(locDetl.getLocId()); |
| | | if (dtos == null) { |
| | | dtos = new ArrayList<>(); |
| | | dtos.add(detlDto); |
| | | }else { |
| | | dtos.add(detlDto); |
| | | } |
| | | map.put(locDetl.getLocId(), dtos); |
| | | } |
| | | |
| | | List<Long> orderDetlIdsTmp = param.getOrderDetlIds(); |
| | | List<OrderOutBatchPreviewDto> previewDtos = new ArrayList<>(); |
| | | for (Map.Entry<Long, List<OutDetlDto>> entry : map.entrySet()) { |
| | | Long locId = entry.getKey(); |
| | | Loc loc = locService.getById(locId); |
| | | |
| | | List<OutDetlDto> outDetlDtos = entry.getValue(); |
| | | for (OutDetlDto outDetlDto : outDetlDtos) { |
| | | orderDetlIdsTmp.remove(outDetlDto.getOrderDetlId()); |
| | | } |
| | | Boolean all = outUtils.isAllForOut(locId, outDetlDtos); |
| | | |
| | | for (OutDetlDto outDetlDto : outDetlDtos) { |
| | | OrderOutBatchPreviewDto previewDto = new OrderOutBatchPreviewDto(); |
| | | previewDto.setLocId(locId); |
| | | previewDto.setLocNo(loc.getLocNo()); |
| | | previewDto.setLocDetlId(outDetlDto.getDetlId()); |
| | | previewDto.setAll(all); |
| | | previewDto.setAnfme(outDetlDto.getAnfme()); |
| | | previewDto.setStock(outDetlDto.getStock()); |
| | | previewDto.setOrderDetlId(outDetlDto.getOrderDetlId()); |
| | | previewDtos.add(previewDto); |
| | | |
| | | |
| | | List<BatchPreviewOtherLocDto> otherLocs = new ArrayList<>(); |
| | | previewDto.setOtherLoc(otherLocs); |
| | | |
| | | List<LocDetl> locDetls = orderDetlLocMap.get(outDetlDto.getOrderDetlId()); |
| | | for (LocDetl locDetl : locDetls) { |
| | | BatchPreviewOtherLocDto otherLocDto = new BatchPreviewOtherLocDto(); |
| | | otherLocDto.setLocId(locDetl.getLocId()); |
| | | otherLocDto.setLocNo(locDetl.getLocNo()); |
| | | otherLocDto.setStock(locDetl.getAnfme()); |
| | | otherLocDto.setLocDetlId(locDetl.getId()); |
| | | |
| | | if (locDetl.getLocId().equals(locId)) { |
| | | otherLocs.add(0, otherLocDto); |
| | | continue; |
| | | } |
| | | |
| | | if (otherLocs.isEmpty()) { |
| | | otherLocs.add(otherLocDto); |
| | | } |
| | | |
| | | for (int i = 0; i < otherLocs.size(); i++) { |
| | | BatchPreviewOtherLocDto locDto = otherLocs.get(i); |
| | | if (locDto.getLocId().equals(locDetl.getLocId())) { |
| | | break; |
| | | } |
| | | otherLocs.add(otherLocDto); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | for (Long id : orderDetlIdsTmp) { |
| | | OrderDetl orderDetl = orderDetlService.getById(id); |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | |
| | | OrderOutBatchPreviewDto previewDto = new OrderOutBatchPreviewDto(); |
| | | previewDto.setLocId(null); |
| | | previewDto.setLocNo(null); |
| | | previewDto.setLocDetlId(null); |
| | | previewDto.setAll(null); |
| | | previewDto.setAnfme(issued); |
| | | previewDto.setStock(0D); |
| | | previewDto.setOrderDetlId(orderDetl.getId()); |
| | | |
| | | previewDtos.add(previewDto); |
| | | } |
| | | |
| | | return previewDtos; |
| | | } |
| | | |
| | | @Transactional |
| | | public void orderOutBatch(List<OrderOutBatchPreviewDto> param) { |
| | | if (param == null) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | if (param.isEmpty()) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | boolean noStock = true; |
| | | for (OrderOutBatchPreviewDto dto : param) { |
| | | if (dto.getStock() > 0) { |
| | | noStock = false; |
| | | break; |
| | | } |
| | | } |
| | | if (noStock) { |
| | | throw new CoolException("库存不足"); |
| | | } |
| | | |
| | | |
| | | HashMap<Long, List<OrderOutBatchPreviewDto>> detlMap = new HashMap<>(); |
| | | for (OrderOutBatchPreviewDto previewDto : param) { |
| | | if (previewDto.getLocId() == null) { |
| | | continue; |
| | | } |
| | | |
| | | if(detlMap.containsKey(previewDto.getLocDetlId())) { |
| | | List<OrderOutBatchPreviewDto> previewDtos = detlMap.get(previewDto.getLocDetlId()); |
| | | previewDtos.add(previewDto); |
| | | detlMap.put(previewDto.getLocDetlId(), previewDtos); |
| | | }else { |
| | | List<OrderOutBatchPreviewDto> previewDtos = new ArrayList<>(); |
| | | previewDtos.add(previewDto); |
| | | detlMap.put(previewDto.getLocDetlId(), previewDtos); |
| | | } |
| | | } |
| | | |
| | | List<OrderOutBatchPreviewDto> dtos = new ArrayList<>(); |
| | | for (Map.Entry<Long, List<OrderOutBatchPreviewDto>> entry : detlMap.entrySet()) { |
| | | Long locDetlId = entry.getKey(); |
| | | LocDetl locDetl = locDetlService.getById(locDetlId); |
| | | if (locDetl == null) { |
| | | continue; |
| | | } |
| | | |
| | | Double stock = locDetl.getAnfme(); |
| | | for (OrderOutBatchPreviewDto dto : entry.getValue()) { |
| | | stock = stock - dto.getAnfme(); |
| | | if (stock >= 0) { |
| | | dtos.add(dto); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | HashMap<Long, List<OrderOutBatchPreviewDto>> map = new HashMap<>(); |
| | | |
| | | for (OrderOutBatchPreviewDto previewDto : dtos) { |
| | | if(map.containsKey(previewDto.getLocId())) { |
| | | List<OrderOutBatchPreviewDto> previewDtos = map.get(previewDto.getLocId()); |
| | | previewDtos.add(previewDto); |
| | | map.put(previewDto.getLocId(), previewDtos); |
| | | }else { |
| | | List<OrderOutBatchPreviewDto> previewDtos = new ArrayList<>(); |
| | | previewDtos.add(previewDto); |
| | | map.put(previewDto.getLocId(), previewDtos); |
| | | } |
| | | } |
| | | |
| | | for (Map.Entry<Long, List<OrderOutBatchPreviewDto>> entry : map.entrySet()) { |
| | | Long locId = entry.getKey(); |
| | | List<OrderOutBatchPreviewDto> previewDtos = entry.getValue(); |
| | | Boolean all = outUtils.isAllForPreview(locId, previewDtos); |
| | | OrderOutBatchPreviewDto previewDto = previewDtos.get(0); |
| | | Long operationPortId = previewDto.getOperationPort(); |
| | | |
| | | Loc loc = locService.getById(locId); |
| | | if (loc == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (!loc.getLocStsId().equals(LocStsType.F.val())) { |
| | | continue; |
| | | } |
| | | |
| | | 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 (OrderOutBatchPreviewDto dto : previewDtos) { |
| | | LocDetl locDetl = locDetlService.getById(dto.getLocDetlId()); |
| | | if(locDetl == null) { |
| | | throw new CoolException("明细不存在"); |
| | | } |
| | | |
| | | OrderDetl orderDetl = orderDetlService.getById(dto.getOrderDetlId()); |
| | | if(orderDetl == null) { |
| | | throw new CoolException("订单明细不存在"); |
| | | } |
| | | orderUtils.updateWorkQty(dto.getOrderDetlId(), dto.getAnfme()); |
| | | |
| | | TaskDetl taskDetl = new TaskDetl(); |
| | | 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()); |
| | | taskDetl.setOrderNo(orderDetl.getOrderNo()); |
| | | taskDetl.setDetlId(orderDetl.getId()); |
| | | 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("明细扩展生成失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //库位F => R |
| | | loc.setLocStsId(LocStsType.R.val()); |
| | | loc.setUpdateTime(new Date()); |
| | | boolean locUpdate = locService.updateById(loc); |
| | | if(!locUpdate){ |
| | | throw new CoolException("库位状态更新失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | public List<MergePreviewDto> orderOutMergePreview(OrderOutMergePreviewParam param) { |
| | | if (param == null) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | List<Long> orderIds = param.getOrderIds(); |
| | | if (orderIds.isEmpty()) { |
| | | throw new CoolException("订单不能为空"); |
| | | } |
| | | |
| | | List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getId, orderIds)); |
| | | if (orders.isEmpty()) { |
| | | throw new CoolException("订单不存在"); |
| | | } |
| | | |
| | | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, orderIds)); |
| | | if(orderDetls.isEmpty()){ |
| | | throw new CoolException("订单明细不存在"); |
| | | } |
| | | orderDetls = orderDetlService.parseDetl(orderDetls); |
| | | |
| | | HashMap<String, Double> locDetlStockMap = new HashMap<>(); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | String matUniqueKey = Utils.getMatUniqueKey(orderDetl.getMat$().getMatnr(), orderDetl.getBatch(), orderDetl.getUniqueField()); |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | if (locDetlStockMap.containsKey(matUniqueKey)) { |
| | | Double anfme = locDetlStockMap.get(matUniqueKey); |
| | | anfme += issued; |
| | | locDetlStockMap.put(matUniqueKey, anfme); |
| | | }else { |
| | | locDetlStockMap.put(matUniqueKey, issued); |
| | | } |
| | | } |
| | | |
| | | List<MergePreviewDto> mergePreviewDtos = new ArrayList<>(); |
| | | for (Map.Entry<String, Double> entry : locDetlStockMap.entrySet()) { |
| | | String matUniqueKey = entry.getKey(); |
| | | Double anfme = entry.getValue(); |
| | | |
| | | MatUniqueObjDto matUniqueObj = Utils.getMatUniqueObj(matUniqueKey); |
| | | HashMap<String, Object> dynamicFields = new HashMap<>(); |
| | | for (FieldParam fieldParam : matUniqueObj.getParams()) { |
| | | dynamicFields.put(fieldParam.getName(), fieldParam.getValue()); |
| | | } |
| | | |
| | | MergePreviewDto dto = new MergePreviewDto(); |
| | | dto.setMatnr(matUniqueObj.getMatnr()); |
| | | dto.setBatch(matUniqueObj.getBatch()); |
| | | dto.setAnfme(anfme); |
| | | dto.setOrderIds(orderIds); |
| | | dto.setFieldParamsEncode(JSON.toJSONString(matUniqueObj.getParams())); |
| | | dto.setDynamicFields(dynamicFields); |
| | | mergePreviewDtos.add(dto); |
| | | } |
| | | |
| | | |
| | | return mergePreviewDtos; |
| | | } |
| | | |
| | | @Transactional |
| | | public List<MergePreviewResultDto> orderOutMergeLocPreview(List<MergePreviewDto> param) { |
| | | if (param == null) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | if (param.isEmpty()) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | for (MergePreviewDto dto : param) { |
| | | List<FieldParam> fieldParams = JSON.parseArray(dto.getFieldParamsEncode(), FieldParam.class); |
| | | dto.setFieldParams(fieldParams); |
| | | } |
| | | |
| | | FieldSortParam sortParam = new FieldSortParam("anfme","desc"); |
| | | List<FieldSortParam> sortParams = new ArrayList<>(); |
| | | sortParams.add(sortParam); |
| | | |
| | | List<MergePreviewResultDto> resultDtos = new ArrayList<>(); |
| | | 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; |
| | | } |
| | | |
| | | List<MergePreviewResultLocDto> locDtos = new ArrayList<>(); |
| | | |
| | | MergePreviewResultDto resultDto = new MergePreviewResultDto(); |
| | | resultDto.sync(dto); |
| | | resultDto.setLocs(locDtos); |
| | | resultDto.setOrderIds(dto.getOrderIds()); |
| | | |
| | | 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.setLocDetlId(locDetl.getId()); |
| | | |
| | | locDtos.add(locDto); |
| | | if (anfme - locDetl.getAnfme() < 0) { |
| | | locDto.setAnfme(anfme); |
| | | break; |
| | | } |
| | | locDto.setAnfme(locDetl.getAnfme()); |
| | | anfme -= locDetl.getAnfme(); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | return resultDtos; |
| | | } |
| | | |
| | | @Transactional |
| | | public void orderOutMerge(OrderOutMergeParamDto dto) { |
| | | if(dto == null){ |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | List<OrderOutMergeParam> params = dto.getList(); |
| | | |
| | | if (params.isEmpty()) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | List<Long> orderIds = null; |
| | | |
| | | List<OrderOutMergeParam> filterParam = new ArrayList<>(); |
| | | HashMap<String, OrderOutMergeParam> paramMap = new HashMap<>(); |
| | | for (OrderOutMergeParam param : params) { |
| | | if (param.getLocId() == null) { |
| | | continue; |
| | | } |
| | | |
| | | filterParam.add(param); |
| | | |
| | | String matUniqueKey = Utils.getMatUniqueKey(param.getMatnr(), param.getBatch(), param.getFieldParams()); |
| | | paramMap.put(matUniqueKey, param); |
| | | |
| | | if (orderIds == null) { |
| | | orderIds = param.getOrderIds(); |
| | | } |
| | | } |
| | | |
| | | if (orderIds == null) { |
| | | throw new CoolException("订单不存在"); |
| | | } |
| | | |
| | | List<Order> orderList = orderService.listByIds(orderIds); |
| | | if (orderList.isEmpty()) { |
| | | throw new CoolException("订单不存在"); |
| | | } |
| | | |
| | | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, orderIds)); |
| | | if (orderDetls.isEmpty()) { |
| | | throw new CoolException("订单明细不存在"); |
| | | } |
| | | |
| | | HashMap<String, List<OrderDetl>> detlMap = new HashMap<>(); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | String matUniqueKey = Utils.getMatUniqueKey(orderDetl.getMat$().getMatnr(), orderDetl.getBatch(), orderDetl.getUniqueField()); |
| | | if (detlMap.containsKey(matUniqueKey)) { |
| | | List<OrderDetl> detls = detlMap.get(matUniqueKey); |
| | | detls.add(orderDetl); |
| | | detlMap.put(matUniqueKey, detls); |
| | | }else { |
| | | List<OrderDetl> detls = new ArrayList<>(); |
| | | detls.add(orderDetl); |
| | | detlMap.put(matUniqueKey, detls); |
| | | } |
| | | } |
| | | |
| | | List<OrderOutMergeDto> orderOutMergeDtos = new ArrayList<>(); |
| | | for (OrderOutMergeParam param : filterParam) { |
| | | String matUniqueKey = Utils.getMatUniqueKey(param.getMatnr(), param.getBatch(), param.getFieldParams()); |
| | | if (!detlMap.containsKey(matUniqueKey)) { |
| | | continue; |
| | | } |
| | | |
| | | Double requireAnfme = param.getAnfme(); |
| | | |
| | | List<OrderDetl> orderDetlList = detlMap.get(matUniqueKey); |
| | | for (OrderDetl orderDetl : orderDetlList) { |
| | | orderDetl = orderDetlService.getById(orderDetl); |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | if (issued <= 0D) { |
| | | continue; |
| | | } |
| | | |
| | | OrderOutMergeDto orderOutMergeDto = new OrderOutMergeDto(); |
| | | orderOutMergeDto.sync(param); |
| | | orderOutMergeDto.setOrderDetlId(orderDetl.getId()); |
| | | |
| | | Double updateWorkQty = null; |
| | | |
| | | if (requireAnfme > issued) { |
| | | orderOutMergeDto.setAnfme(issued); |
| | | updateWorkQty = issued; |
| | | requireAnfme -= issued; |
| | | }else { |
| | | orderOutMergeDto.setAnfme(requireAnfme); |
| | | updateWorkQty = requireAnfme; |
| | | requireAnfme -= requireAnfme; |
| | | } |
| | | |
| | | orderOutMergeDtos.add(orderOutMergeDto); |
| | | |
| | | orderUtils.updateWorkQty(orderDetl.getId(), updateWorkQty); |
| | | if (requireAnfme <= 0) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | HashMap<Long, List<OrderOutMergeDto>> map = new HashMap<>(); |
| | | for (OrderOutMergeDto orderOutMergeDto : orderOutMergeDtos) { |
| | | 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); |
| | | } |
| | | |
| | | List<TaskDetl> taskDetls = new ArrayList<>(); |
| | | 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("明细不存在"); |
| | | } |
| | | |
| | | OrderDetl orderDetl = orderDetlService.getById(merge.getOrderDetlId()); |
| | | if(orderDetl == 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.setOrderId(orderDetl.getOrderId()); |
| | | taskDetl.setOrderNo(orderDetl.getOrderNo()); |
| | | taskDetl.setDetlId(orderDetl.getId()); |
| | | 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("明细扩展生成失败"); |
| | | } |
| | | } |
| | | |
| | | taskDetls.add(taskDetl); |
| | | } |
| | | |
| | | //库位F => R |
| | | loc.setLocStsId(LocStsType.R.val()); |
| | | loc.setUpdateTime(new Date()); |
| | | boolean locUpdate = locService.updateById(loc); |
| | | if(!locUpdate){ |
| | | throw new CoolException("库位状态更新失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | public void orderOutMergeWave(OrderOutMergeParamDto dto) { |
| | | if(dto == null){ |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | 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); |
| | | if (orderList.isEmpty()) { |
| | | throw new CoolException("订单不存在"); |
| | | } |
| | | |
| | | for (Order order : orderList) { |
| | | if (order.getWaveId() != null) { |
| | | throw new CoolException("当前订单中已经生成波次"); |
| | | } |
| | | } |
| | | |
| | | String waveNo = orderNoRuleService.getOrderNo(3); |
| | | 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) { |
| | | 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("波次明细生成失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | public void cancelWave(List<Long> waveIds) { |
| | | if (waveIds == null) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | if (waveIds.isEmpty()) { |
| | | throw new CoolException("参数不能为空"); |
| | | } |
| | | |
| | | List<Wave> waves = waveService.listByIds(waveIds); |
| | | if (waves.isEmpty()) { |
| | | throw new CoolException("波次不存在"); |
| | | } |
| | | |
| | | for (Wave wave : waves) { |
| | | List<WaveDetl> waveDetls = waveDetlService.list(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getWaveId, wave.getId())); |
| | | for (WaveDetl waveDetl : waveDetls) { |
| | | 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()); |
| | | } |
| | | |
| | | waveService.removeById(wave.getId()); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | package com.zy.asrs.wms.asrs.manage;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | 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.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.*;
|
| | | import com.zy.asrs.wms.utils.OrderUtils;
|
| | | import com.zy.asrs.wms.utils.OutUtils;
|
| | | import com.zy.asrs.wms.utils.Utils;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import java.util.*;
|
| | |
|
| | | /**
|
| | | * 出库管理
|
| | | */
|
| | | @Service
|
| | | public class OutManage {
|
| | |
|
| | | private static Logger logger = LoggerFactory.getLogger(LocManage.class);
|
| | |
|
| | | @Autowired
|
| | | private TaskService taskService;
|
| | | @Autowired
|
| | | private TaskDetlService taskDetlService;
|
| | | @Autowired
|
| | | private TaskDetlFieldService taskDetlFieldService;
|
| | | @Autowired
|
| | | private LocService locService;
|
| | | @Autowired
|
| | | private LocDetlService locDetlService;
|
| | | @Autowired
|
| | | private LocDetlFieldService locDetlFieldService;
|
| | | @Autowired
|
| | | private WorkService workService;
|
| | | @Autowired
|
| | | private OrderService orderService;
|
| | | @Autowired
|
| | | private OrderDetlService orderDetlService;
|
| | | @Autowired
|
| | | private OutUtils outUtils;
|
| | | @Autowired
|
| | | private OperationPortService operationPortService;
|
| | | @Autowired
|
| | | private OrderUtils orderUtils;
|
| | | @Autowired
|
| | | private OrderNoRuleService orderNoRuleService;
|
| | | @Autowired
|
| | | private WaveService waveService;
|
| | | @Autowired
|
| | | private WaveDetlService waveDetlService;
|
| | | @Autowired
|
| | | private CacheSiteService cacheSiteService;
|
| | | @Autowired
|
| | | private WaveSeedService waveSeedService;
|
| | |
|
| | | /**
|
| | | * 出库
|
| | | */
|
| | | @Transactional
|
| | | public void out(OutParam outParam) {
|
| | | if (outParam.getOperationPort() == null) {
|
| | | throw new CoolException("作业口不存在");
|
| | | }
|
| | |
|
| | | List<OutLocDto> list = outUtils.merge(outParam);
|
| | | processTask(list);
|
| | | }
|
| | |
|
| | | private void processTask(List<OutLocDto> list) {
|
| | | for (OutLocDto locDto : list) {
|
| | | long taskType = locDto.getAll() ? 101L : 103L;
|
| | |
|
| | | Loc loc = locService.getById(locDto.getLocId());
|
| | | if(loc == null) {
|
| | | throw new CoolException("库位不存在");
|
| | | }
|
| | |
|
| | | if (!loc.getLocStsId().equals(LocStsType.F.val())) {
|
| | | throw new CoolException("库位状态不在库");
|
| | | }
|
| | |
|
| | | Task task = new Task();
|
| | | task.setTaskNo(workService.generateTaskNo(1L));
|
| | | task.setTaskSts(TaskStsType.GENERATE_OUT.id);
|
| | | task.setTaskType(taskType);
|
| | | task.setIoPri(workService.generateIoPri(taskType));
|
| | | task.setOriginLoc(loc.getLocNo());
|
| | | task.setTargetSite(locDto.getOperationPort());
|
| | | task.setBarcode(loc.getBarcode());
|
| | | boolean res = taskService.save(task);
|
| | | if (!res) {
|
| | | throw new CoolException("保存工作档失败");
|
| | | }
|
| | | // 工作档明细保存
|
| | | for (OutDetlDto detl : locDto.getDetls()) {
|
| | | LocDetl locDetl = locDetlService.getById(detl.getDetlId());
|
| | | if(locDetl == null) {
|
| | | throw new CoolException("明细不存在");
|
| | | }
|
| | |
|
| | | 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);
|
| | | 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.setDetlId(taskDetl.getId());
|
| | | boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
|
| | | if(!taskDetlFieldSave){
|
| | | throw new CoolException("明细扩展生成失败");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //库位F => R
|
| | | loc.setLocStsId(LocStsType.R.val());
|
| | | loc.setUpdateTime(new Date());
|
| | | boolean locUpdate = locService.updateById(loc);
|
| | | if(!locUpdate){
|
| | | throw new CoolException("库位状态更新失败");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public List<OrderOutBatchPreviewDto> orderOutBatchPreview(OrderOutBatchPreviewParam param) {
|
| | | List<Long> orderDetlIds = param.getOrderDetlIds();
|
| | | if (orderDetlIds.isEmpty()) {
|
| | | throw new CoolException("订单明细不能为空");
|
| | | }
|
| | |
|
| | | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getId, orderDetlIds).orderByAsc(OrderDetl::getOrderNo, OrderDetl::getCreateTime));
|
| | | if (orderDetls.isEmpty()) {
|
| | | throw new CoolException("订单明细不存在");
|
| | | }
|
| | | orderDetls = orderDetlService.parseDetl(orderDetls);
|
| | |
|
| | | HashMap<Long, List<LocDetl>> orderDetlLocMap = new HashMap<>();
|
| | | List<OutDetlDto> detlDtos = new ArrayList<>();
|
| | |
|
| | | for (OrderDetl orderDetl : orderDetls) {
|
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D);
|
| | | if (issued <= 0.0D) { continue; }
|
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMat$().getMatnr(), orderDetl.getBatch(), orderDetl.getUniqueField());
|
| | | orderDetlLocMap.put(orderDetl.getId(), locDetls);
|
| | | for (LocDetl locDetl : locDetls) {
|
| | | if (issued > 0) {
|
| | | OutDetlDto outDetlDto = new OutDetlDto();
|
| | | outDetlDto.setDetlId(locDetl.getId());
|
| | | outDetlDto.setAnfme(issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued);
|
| | | outDetlDto.setStock(locDetl.getAnfme());
|
| | | outDetlDto.setOrderDetlId(orderDetl.getId());
|
| | | detlDtos.add(outDetlDto);
|
| | | issued = issued - outDetlDto.getAnfme();
|
| | | }else {
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | HashMap<Long, List<OutDetlDto>> map = new HashMap<>();
|
| | | for (OutDetlDto detlDto : detlDtos) {
|
| | | LocDetl locDetl = locDetlService.getById(detlDto.getDetlId());
|
| | | List<OutDetlDto> dtos = map.get(locDetl.getLocId());
|
| | | if (dtos == null) {
|
| | | dtos = new ArrayList<>();
|
| | | dtos.add(detlDto);
|
| | | }else {
|
| | | dtos.add(detlDto);
|
| | | }
|
| | | map.put(locDetl.getLocId(), dtos);
|
| | | }
|
| | |
|
| | | List<Long> orderDetlIdsTmp = param.getOrderDetlIds();
|
| | | List<OrderOutBatchPreviewDto> previewDtos = new ArrayList<>();
|
| | | for (Map.Entry<Long, List<OutDetlDto>> entry : map.entrySet()) {
|
| | | Long locId = entry.getKey();
|
| | | Loc loc = locService.getById(locId);
|
| | |
|
| | | List<OutDetlDto> outDetlDtos = entry.getValue();
|
| | | for (OutDetlDto outDetlDto : outDetlDtos) {
|
| | | orderDetlIdsTmp.remove(outDetlDto.getOrderDetlId());
|
| | | }
|
| | | Boolean all = outUtils.isAllForOut(locId, outDetlDtos);
|
| | |
|
| | | for (OutDetlDto outDetlDto : outDetlDtos) {
|
| | | OrderOutBatchPreviewDto previewDto = new OrderOutBatchPreviewDto();
|
| | | previewDto.setLocId(locId);
|
| | | previewDto.setLocNo(loc.getLocNo());
|
| | | previewDto.setLocDetlId(outDetlDto.getDetlId());
|
| | | previewDto.setAll(all);
|
| | | previewDto.setAnfme(outDetlDto.getAnfme());
|
| | | previewDto.setStock(outDetlDto.getStock());
|
| | | previewDto.setOrderDetlId(outDetlDto.getOrderDetlId());
|
| | | previewDtos.add(previewDto);
|
| | |
|
| | |
|
| | | List<BatchPreviewOtherLocDto> otherLocs = new ArrayList<>();
|
| | | previewDto.setOtherLoc(otherLocs);
|
| | |
|
| | | List<LocDetl> locDetls = orderDetlLocMap.get(outDetlDto.getOrderDetlId());
|
| | | for (LocDetl locDetl : locDetls) {
|
| | | BatchPreviewOtherLocDto otherLocDto = new BatchPreviewOtherLocDto();
|
| | | otherLocDto.setLocId(locDetl.getLocId());
|
| | | otherLocDto.setLocNo(locDetl.getLocNo());
|
| | | otherLocDto.setStock(locDetl.getAnfme());
|
| | | otherLocDto.setLocDetlId(locDetl.getId());
|
| | |
|
| | | if (locDetl.getLocId().equals(locId)) {
|
| | | otherLocs.add(0, otherLocDto);
|
| | | continue;
|
| | | }
|
| | |
|
| | | if (otherLocs.isEmpty()) {
|
| | | otherLocs.add(otherLocDto);
|
| | | }
|
| | |
|
| | | for (int i = 0; i < otherLocs.size(); i++) {
|
| | | BatchPreviewOtherLocDto locDto = otherLocs.get(i);
|
| | | if (locDto.getLocId().equals(locDetl.getLocId())) {
|
| | | break;
|
| | | }
|
| | | otherLocs.add(otherLocDto);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | for (Long id : orderDetlIdsTmp) {
|
| | | OrderDetl orderDetl = orderDetlService.getById(id);
|
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D);
|
| | |
|
| | | OrderOutBatchPreviewDto previewDto = new OrderOutBatchPreviewDto();
|
| | | previewDto.setLocId(null);
|
| | | previewDto.setLocNo(null);
|
| | | previewDto.setLocDetlId(null);
|
| | | previewDto.setAll(null);
|
| | | previewDto.setAnfme(issued);
|
| | | previewDto.setStock(0D);
|
| | | previewDto.setOrderDetlId(orderDetl.getId());
|
| | |
|
| | | previewDtos.add(previewDto);
|
| | | }
|
| | |
|
| | | return previewDtos;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void orderOutBatch(List<OrderOutBatchPreviewDto> param) {
|
| | | if (param == null) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | if (param.isEmpty()) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | boolean noStock = true;
|
| | | for (OrderOutBatchPreviewDto dto : param) {
|
| | | if (dto.getStock() > 0) {
|
| | | noStock = false;
|
| | | break;
|
| | | }
|
| | | }
|
| | | if (noStock) {
|
| | | throw new CoolException("库存不足");
|
| | | }
|
| | |
|
| | |
|
| | | HashMap<Long, List<OrderOutBatchPreviewDto>> detlMap = new HashMap<>();
|
| | | for (OrderOutBatchPreviewDto previewDto : param) {
|
| | | if (previewDto.getLocId() == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | if(detlMap.containsKey(previewDto.getLocDetlId())) {
|
| | | List<OrderOutBatchPreviewDto> previewDtos = detlMap.get(previewDto.getLocDetlId());
|
| | | previewDtos.add(previewDto);
|
| | | detlMap.put(previewDto.getLocDetlId(), previewDtos);
|
| | | }else {
|
| | | List<OrderOutBatchPreviewDto> previewDtos = new ArrayList<>();
|
| | | previewDtos.add(previewDto);
|
| | | detlMap.put(previewDto.getLocDetlId(), previewDtos);
|
| | | }
|
| | | }
|
| | |
|
| | | List<OrderOutBatchPreviewDto> dtos = new ArrayList<>();
|
| | | for (Map.Entry<Long, List<OrderOutBatchPreviewDto>> entry : detlMap.entrySet()) {
|
| | | Long locDetlId = entry.getKey();
|
| | | LocDetl locDetl = locDetlService.getById(locDetlId);
|
| | | if (locDetl == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | Double stock = locDetl.getAnfme();
|
| | | for (OrderOutBatchPreviewDto dto : entry.getValue()) {
|
| | | stock = stock - dto.getAnfme();
|
| | | if (stock >= 0) {
|
| | | dtos.add(dto);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | HashMap<Long, List<OrderOutBatchPreviewDto>> map = new HashMap<>();
|
| | |
|
| | | for (OrderOutBatchPreviewDto previewDto : dtos) {
|
| | | if(map.containsKey(previewDto.getLocId())) {
|
| | | List<OrderOutBatchPreviewDto> previewDtos = map.get(previewDto.getLocId());
|
| | | previewDtos.add(previewDto);
|
| | | map.put(previewDto.getLocId(), previewDtos);
|
| | | }else {
|
| | | List<OrderOutBatchPreviewDto> previewDtos = new ArrayList<>();
|
| | | previewDtos.add(previewDto);
|
| | | map.put(previewDto.getLocId(), previewDtos);
|
| | | }
|
| | | }
|
| | |
|
| | | for (Map.Entry<Long, List<OrderOutBatchPreviewDto>> entry : map.entrySet()) {
|
| | | Long locId = entry.getKey();
|
| | | List<OrderOutBatchPreviewDto> previewDtos = entry.getValue();
|
| | | Boolean all = outUtils.isAllForPreview(locId, previewDtos);
|
| | | OrderOutBatchPreviewDto previewDto = previewDtos.get(0);
|
| | | Long operationPortId = previewDto.getOperationPort();
|
| | |
|
| | | Loc loc = locService.getById(locId);
|
| | | if (loc == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | if (!loc.getLocStsId().equals(LocStsType.F.val())) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | 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 (OrderOutBatchPreviewDto dto : previewDtos) {
|
| | | LocDetl locDetl = locDetlService.getById(dto.getLocDetlId());
|
| | | if(locDetl == null) {
|
| | | throw new CoolException("明细不存在");
|
| | | }
|
| | |
|
| | | OrderDetl orderDetl = orderDetlService.getById(dto.getOrderDetlId());
|
| | | if(orderDetl == null) {
|
| | | throw new CoolException("订单明细不存在");
|
| | | }
|
| | | orderUtils.updateWorkQty(dto.getOrderDetlId(), dto.getAnfme());
|
| | |
|
| | | TaskDetl taskDetl = new TaskDetl();
|
| | | 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());
|
| | | taskDetl.setOrderNo(orderDetl.getOrderNo());
|
| | | taskDetl.setDetlId(orderDetl.getId());
|
| | | 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("明细扩展生成失败");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //库位F => R
|
| | | loc.setLocStsId(LocStsType.R.val());
|
| | | loc.setUpdateTime(new Date());
|
| | | boolean locUpdate = locService.updateById(loc);
|
| | | if(!locUpdate){
|
| | | throw new CoolException("库位状态更新失败");
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public List<MergePreviewDto> orderOutMergePreview(OrderOutMergePreviewParam param) {
|
| | | if (param == null) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | List<Long> orderIds = param.getOrderIds();
|
| | | if (orderIds.isEmpty()) {
|
| | | throw new CoolException("订单不能为空");
|
| | | }
|
| | |
|
| | | List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getId, orderIds));
|
| | | if (orders.isEmpty()) {
|
| | | throw new CoolException("订单不存在");
|
| | | }
|
| | |
|
| | | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, orderIds));
|
| | | if(orderDetls.isEmpty()){
|
| | | throw new CoolException("订单明细不存在");
|
| | | }
|
| | | orderDetls = orderDetlService.parseDetl(orderDetls);
|
| | |
|
| | | HashMap<String, Double> locDetlStockMap = new HashMap<>();
|
| | | for (OrderDetl orderDetl : orderDetls) {
|
| | | String matUniqueKey = Utils.getMatUniqueKey(orderDetl.getMat$().getMatnr(), orderDetl.getBatch(), orderDetl.getUniqueField());
|
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D);
|
| | | if (locDetlStockMap.containsKey(matUniqueKey)) {
|
| | | Double anfme = locDetlStockMap.get(matUniqueKey);
|
| | | anfme += issued;
|
| | | locDetlStockMap.put(matUniqueKey, anfme);
|
| | | }else {
|
| | | locDetlStockMap.put(matUniqueKey, issued);
|
| | | }
|
| | | }
|
| | |
|
| | | List<MergePreviewDto> mergePreviewDtos = new ArrayList<>();
|
| | | for (Map.Entry<String, Double> entry : locDetlStockMap.entrySet()) {
|
| | | String matUniqueKey = entry.getKey();
|
| | | Double anfme = entry.getValue();
|
| | |
|
| | | MatUniqueObjDto matUniqueObj = Utils.getMatUniqueObj(matUniqueKey);
|
| | | HashMap<String, Object> dynamicFields = new HashMap<>();
|
| | | for (FieldParam fieldParam : matUniqueObj.getParams()) {
|
| | | dynamicFields.put(fieldParam.getName(), fieldParam.getValue());
|
| | | }
|
| | |
|
| | | MergePreviewDto dto = new MergePreviewDto();
|
| | | dto.setMatnr(matUniqueObj.getMatnr());
|
| | | dto.setBatch(matUniqueObj.getBatch());
|
| | | dto.setAnfme(anfme);
|
| | | dto.setOrderIds(orderIds);
|
| | | dto.setFieldParamsEncode(JSON.toJSONString(matUniqueObj.getParams()));
|
| | | dto.setDynamicFields(dynamicFields);
|
| | | mergePreviewDtos.add(dto);
|
| | | }
|
| | |
|
| | |
|
| | | return mergePreviewDtos;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public List<MergePreviewResultDto> orderOutMergeLocPreview(List<MergePreviewDto> param) {
|
| | | if (param == null) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | if (param.isEmpty()) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | for (MergePreviewDto dto : param) {
|
| | | List<FieldParam> fieldParams = JSON.parseArray(dto.getFieldParamsEncode(), FieldParam.class);
|
| | | dto.setFieldParams(fieldParams);
|
| | | }
|
| | |
|
| | | FieldSortParam sortParam = new FieldSortParam("anfme","desc");
|
| | | List<FieldSortParam> sortParams = new ArrayList<>();
|
| | | sortParams.add(sortParam);
|
| | |
|
| | | List<MergePreviewResultDto> resultDtos = new ArrayList<>();
|
| | | 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;
|
| | | }
|
| | |
|
| | | List<MergePreviewResultLocDto> locDtos = new ArrayList<>();
|
| | |
|
| | | MergePreviewResultDto resultDto = new MergePreviewResultDto();
|
| | | resultDto.sync(dto);
|
| | | resultDto.setLocs(locDtos);
|
| | | resultDto.setOrderIds(dto.getOrderIds());
|
| | |
|
| | | 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.setLocDetlId(locDetl.getId());
|
| | |
|
| | | locDtos.add(locDto);
|
| | | if (anfme - locDetl.getAnfme() < 0) {
|
| | | locDto.setAnfme(anfme);
|
| | | break;
|
| | | }
|
| | | locDto.setAnfme(locDetl.getAnfme());
|
| | | anfme -= locDetl.getAnfme();
|
| | | }
|
| | |
|
| | | 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);
|
| | | }
|
| | |
|
| | | return resultDtos;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void orderOutMerge(OrderOutMergeParamDto dto) {
|
| | | if(dto == null){
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | List<OrderOutMergeParam> params = dto.getList();
|
| | |
|
| | | if (params.isEmpty()) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | List<Long> orderIds = null;
|
| | |
|
| | | List<OrderOutMergeParam> filterParam = new ArrayList<>();
|
| | | HashMap<String, OrderOutMergeParam> paramMap = new HashMap<>();
|
| | | for (OrderOutMergeParam param : params) {
|
| | | if (param.getLocId() == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | filterParam.add(param);
|
| | |
|
| | | String matUniqueKey = Utils.getMatUniqueKey(param.getMatnr(), param.getBatch(), param.getFieldParams());
|
| | | paramMap.put(matUniqueKey, param);
|
| | |
|
| | | if (orderIds == null) {
|
| | | orderIds = param.getOrderIds();
|
| | | }
|
| | | }
|
| | |
|
| | | if (orderIds == null) {
|
| | | throw new CoolException("订单不存在");
|
| | | }
|
| | |
|
| | | List<Order> orderList = orderService.listByIds(orderIds);
|
| | | if (orderList.isEmpty()) {
|
| | | throw new CoolException("订单不存在");
|
| | | }
|
| | |
|
| | | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, orderIds));
|
| | | if (orderDetls.isEmpty()) {
|
| | | throw new CoolException("订单明细不存在");
|
| | | }
|
| | |
|
| | | HashMap<String, List<OrderDetl>> detlMap = new HashMap<>();
|
| | | for (OrderDetl orderDetl : orderDetls) {
|
| | | String matUniqueKey = Utils.getMatUniqueKey(orderDetl.getMat$().getMatnr(), orderDetl.getBatch(), orderDetl.getUniqueField());
|
| | | if (detlMap.containsKey(matUniqueKey)) {
|
| | | List<OrderDetl> detls = detlMap.get(matUniqueKey);
|
| | | detls.add(orderDetl);
|
| | | detlMap.put(matUniqueKey, detls);
|
| | | }else {
|
| | | List<OrderDetl> detls = new ArrayList<>();
|
| | | detls.add(orderDetl);
|
| | | detlMap.put(matUniqueKey, detls);
|
| | | }
|
| | | }
|
| | |
|
| | | List<OrderOutMergeDto> orderOutMergeDtos = new ArrayList<>();
|
| | | for (OrderOutMergeParam param : filterParam) {
|
| | | String matUniqueKey = Utils.getMatUniqueKey(param.getMatnr(), param.getBatch(), param.getFieldParams());
|
| | | if (!detlMap.containsKey(matUniqueKey)) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | Double requireAnfme = param.getAnfme();
|
| | |
|
| | | List<OrderDetl> orderDetlList = detlMap.get(matUniqueKey);
|
| | | for (OrderDetl orderDetl : orderDetlList) {
|
| | | orderDetl = orderDetlService.getById(orderDetl);
|
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D);
|
| | | if (issued <= 0D) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | OrderOutMergeDto orderOutMergeDto = new OrderOutMergeDto();
|
| | | orderOutMergeDto.sync(param);
|
| | | orderOutMergeDto.setOrderDetlId(orderDetl.getId());
|
| | |
|
| | | Double updateWorkQty = null;
|
| | |
|
| | | if (requireAnfme > issued) {
|
| | | orderOutMergeDto.setAnfme(issued);
|
| | | updateWorkQty = issued;
|
| | | requireAnfme -= issued;
|
| | | }else {
|
| | | orderOutMergeDto.setAnfme(requireAnfme);
|
| | | updateWorkQty = requireAnfme;
|
| | | requireAnfme -= requireAnfme;
|
| | | }
|
| | |
|
| | | orderOutMergeDtos.add(orderOutMergeDto);
|
| | |
|
| | | orderUtils.updateWorkQty(orderDetl.getId(), updateWorkQty);
|
| | | if (requireAnfme <= 0) {
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | HashMap<Long, List<OrderOutMergeDto>> map = new HashMap<>();
|
| | | for (OrderOutMergeDto orderOutMergeDto : orderOutMergeDtos) {
|
| | | 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);
|
| | | }
|
| | |
|
| | | List<TaskDetl> taskDetls = new ArrayList<>();
|
| | | 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("明细不存在");
|
| | | }
|
| | |
|
| | | OrderDetl orderDetl = orderDetlService.getById(merge.getOrderDetlId());
|
| | | if(orderDetl == 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.setOrderId(orderDetl.getOrderId());
|
| | | taskDetl.setOrderNo(orderDetl.getOrderNo());
|
| | | taskDetl.setDetlId(orderDetl.getId());
|
| | | 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("明细扩展生成失败");
|
| | | }
|
| | | }
|
| | |
|
| | | taskDetls.add(taskDetl);
|
| | | }
|
| | |
|
| | | //库位F => R
|
| | | loc.setLocStsId(LocStsType.R.val());
|
| | | loc.setUpdateTime(new Date());
|
| | | boolean locUpdate = locService.updateById(loc);
|
| | | if(!locUpdate){
|
| | | throw new CoolException("库位状态更新失败");
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void orderOutMergeWave(OrderOutMergeParamDto dto) {
|
| | | if(dto == null){
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | 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);
|
| | | if (orderList.isEmpty()) {
|
| | | throw new CoolException("订单不存在");
|
| | | }
|
| | |
|
| | | for (Order order : orderList) {
|
| | | if (order.getWaveId() != null) {
|
| | | throw new CoolException("当前订单中已经生成波次");
|
| | | }
|
| | | }
|
| | |
|
| | | String waveNo = orderNoRuleService.getOrderNo(3);
|
| | | 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) {
|
| | | 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("波次明细生成失败");
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void cancelWave(List<Long> waveIds) {
|
| | | if (waveIds == null) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | if (waveIds.isEmpty()) {
|
| | | throw new CoolException("参数不能为空");
|
| | | }
|
| | |
|
| | | List<Wave> waves = waveService.listByIds(waveIds);
|
| | | if (waves.isEmpty()) {
|
| | | throw new CoolException("波次不存在");
|
| | | }
|
| | |
|
| | | for (Wave wave : waves) {
|
| | | List<WaveDetl> waveDetls = waveDetlService.list(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getWaveId, wave.getId()));
|
| | | for (WaveDetl waveDetl : waveDetls) {
|
| | | 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());
|
| | | }
|
| | |
|
| | | waveService.removeById(wave.getId());
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|