|  |  | 
 |  |  | package com.zy.asrs.wms.asrs.manage;
 | 
 |  |  | 
 | 
 |  |  | import com.alibaba.fastjson.JSON;
 | 
 |  |  | import com.alibaba.fastjson.JSONObject;
 | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
 |  |  | import com.mysql.cj.util.StringUtils;
 | 
 |  |  | import com.zy.asrs.wms.asrs.entity.param.StockOutParam;
 | 
 |  |  | import com.zy.asrs.framework.exception.CoolException;
 | 
 |  |  | import com.zy.asrs.wms.asrs.entity.*;
 | 
 |  |  | 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.BeanUtils;
 | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
 |  |  | import org.springframework.stereotype.Service;
 | 
 |  |  | import org.springframework.transaction.annotation.Transactional;
 | 
 |  |  | 
 | 
 |  |  | import java.math.BigDecimal;
 | 
 |  |  | import java.text.SimpleDateFormat;
 | 
 |  |  | import java.util.*;
 | 
 |  |  | import java.util.stream.Collectors;
 | 
 |  |  | 
 | 
 |  |  | /**
 | 
 |  |  |  * 出库管理
 | 
 |  |  | 
 |  |  |     private CacheSiteService cacheSiteService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private WaveSeedService waveSeedService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private PickSheetService pickSheetService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private PickSheetDetlService pickSheetDetlService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private MatService matService;
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * 出库
 | 
 |  |  |      */
 | 
 |  |  |     @Transactional
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void out(OutParam outParam) {
 | 
 |  |  |         if (outParam.getOperationPort() == null) {
 | 
 |  |  |             throw new CoolException("作业口不存在");
 | 
 |  |  | 
 |  |  |             long taskType = locDto.getAll() ? 101L : 103L;
 | 
 |  |  | 
 | 
 |  |  |             Loc loc = locService.getById(locDto.getLocId());
 | 
 |  |  |             if(loc == null) {
 | 
 |  |  |             if (loc == null) {
 | 
 |  |  |                 throw new CoolException("库位不存在");
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  |             // 工作档明细保存
 | 
 |  |  |             for (OutDetlDto detl : locDto.getDetls()) {
 | 
 |  |  |                 LocDetl locDetl = locDetlService.getById(detl.getDetlId());
 | 
 |  |  |                 if(locDetl == null) {
 | 
 |  |  |                 if (locDetl == null) {
 | 
 |  |  |                     throw new CoolException("明细不存在");
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  |                     taskDetlField.sync(locDetlField);
 | 
 |  |  |                     taskDetlField.setDetlId(taskDetl.getId());
 | 
 |  |  |                     boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
 | 
 |  |  |                     if(!taskDetlFieldSave){
 | 
 |  |  |                     if (!taskDetlFieldSave) {
 | 
 |  |  |                         throw new CoolException("明细扩展生成失败");
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  | 
 |  |  |             loc.setLocStsId(LocStsType.R.val());
 | 
 |  |  |             loc.setUpdateTime(new Date());
 | 
 |  |  |             boolean locUpdate = locService.updateById(loc);
 | 
 |  |  |             if(!locUpdate){
 | 
 |  |  |             if (!locUpdate) {
 | 
 |  |  |                 throw new CoolException("库位状态更新失败");
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  | 
 |  |  |         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<>();
 | 
 |  |  | //        //获取平仓中符合条件的所有库位
 | 
 |  |  | //        orderDetls.forEach(detl -> {
 | 
 |  |  | //            double issued = Optional.of(detl.getAnfme() - detl.getQty() - detl.getWorkQty()).orElse(0.0D);
 | 
 |  |  | //            if (issued <= 0.0D) {
 | 
 |  |  | //                return;
 | 
 |  |  | //            }
 | 
 |  |  | //            List<LocDetl> locs = locDetlService.queryFlatStock(detl.getMat$().getMatnr(), detl.getBatch(), detl.getUniqueField());
 | 
 |  |  | //            //平库有当明物料优先出库
 | 
 |  |  | //            if (!locs.isEmpty()) {
 | 
 |  |  | //                for (LocDetl locDetl : locs) {
 | 
 |  |  | //                    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(locDetl.getId());
 | 
 |  |  | //                        detlDtos.add(outDetlDto);
 | 
 |  |  | //                        issued = issued - outDetlDto.getAnfme();
 | 
 |  |  | //                    }
 | 
 |  |  | //                }
 | 
 |  |  | //                //订单明细需出库数量
 | 
 |  |  | //                double workQty = Optional.of(detl.getAnfme() - detl.getQty() - detl.getWorkQty()).orElse(0.0D);
 | 
 |  |  | //                //更新平库订单明细的实际可用数量
 | 
 |  |  | //                detl.setWorkQty(workQty - issued);
 | 
 |  |  | //            }
 | 
 |  |  | //        });
 | 
 |  |  | 
 | 
 |  |  |         /**
 | 
 |  |  |          * 平库优先出库完成后,当订单明细workQty + qty 还不等于anfme时,查询TCU库
 | 
 |  |  |          */
 | 
 |  |  |         //获取TCU符合条件库位
 | 
 |  |  |         for (OrderDetl orderDetl : orderDetls) {
 | 
 |  |  |             double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty() - orderDetl.getWorkQty()).orElse(0.0D);
 | 
 |  |  |             if (issued <= 0.0D) { continue; }
 | 
 |  |  |             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) {
 | 
 |  |  | 
 |  |  |                     outDetlDto.setOrderDetlId(orderDetl.getId());
 | 
 |  |  |                     detlDtos.add(outDetlDto);
 | 
 |  |  |                     issued = issued - outDetlDto.getAnfme();
 | 
 |  |  |                 }else {
 | 
 |  |  |                 } else {
 | 
 |  |  |                     break;
 | 
 |  |  |                 }
 | 
 |  |  |             }
 | 
 |  |  | 
 |  |  |             if (dtos == null) {
 | 
 |  |  |                 dtos = new ArrayList<>();
 | 
 |  |  |                 dtos.add(detlDto);
 | 
 |  |  |             }else {
 | 
 |  |  |             } else {
 | 
 |  |  |                 dtos.add(detlDto);
 | 
 |  |  |             }
 | 
 |  |  |             map.put(locDetl.getLocId(), dtos);
 | 
 |  |  | 
 |  |  |         return previewDtos;
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @Transactional
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void orderOutBatch(List<OrderOutBatchPreviewDto> param) {
 | 
 |  |  |         if (param == null) {
 | 
 |  |  |             throw new CoolException("参数不能为空");
 | 
 |  |  | 
 |  |  |                 continue;
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             if(detlMap.containsKey(previewDto.getLocDetlId())) {
 | 
 |  |  |             if (detlMap.containsKey(previewDto.getLocDetlId())) {
 | 
 |  |  |                 List<OrderOutBatchPreviewDto> previewDtos = detlMap.get(previewDto.getLocDetlId());
 | 
 |  |  |                 previewDtos.add(previewDto);
 | 
 |  |  |                 detlMap.put(previewDto.getLocDetlId(), previewDtos);
 | 
 |  |  |             }else {
 | 
 |  |  |             } else {
 | 
 |  |  |                 List<OrderOutBatchPreviewDto> previewDtos = new ArrayList<>();
 | 
 |  |  |                 previewDtos.add(previewDto);
 | 
 |  |  |                 detlMap.put(previewDto.getLocDetlId(), previewDtos);
 | 
 |  |  | 
 |  |  |         HashMap<Long, List<OrderOutBatchPreviewDto>> map = new HashMap<>();
 | 
 |  |  | 
 | 
 |  |  |         for (OrderOutBatchPreviewDto previewDto : dtos) {
 | 
 |  |  |             if(map.containsKey(previewDto.getLocId())) {
 | 
 |  |  |             if (map.containsKey(previewDto.getLocId())) {
 | 
 |  |  |                 List<OrderOutBatchPreviewDto> previewDtos = map.get(previewDto.getLocId());
 | 
 |  |  |                 previewDtos.add(previewDto);
 | 
 |  |  |                 map.put(previewDto.getLocId(), previewDtos);
 | 
 |  |  |             }else {
 | 
 |  |  |             } else {
 | 
 |  |  |                 List<OrderOutBatchPreviewDto> previewDtos = new ArrayList<>();
 | 
 |  |  |                 previewDtos.add(previewDto);
 | 
 |  |  |                 map.put(previewDto.getLocId(), previewDtos);
 | 
 |  |  | 
 |  |  | 
 | 
 |  |  |             for (OrderOutBatchPreviewDto dto : previewDtos) {
 | 
 |  |  |                 LocDetl locDetl = locDetlService.getById(dto.getLocDetlId());
 | 
 |  |  |                 if(locDetl == null) {
 | 
 |  |  |                 if (locDetl == null) {
 | 
 |  |  |                     throw new CoolException("明细不存在");
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  |                 OrderDetl orderDetl = orderDetlService.getById(dto.getOrderDetlId());
 | 
 |  |  |                 if(orderDetl == null) {
 | 
 |  |  |                 if (orderDetl == null) {
 | 
 |  |  |                     throw new CoolException("订单明细不存在");
 | 
 |  |  |                 }
 | 
 |  |  |                 orderUtils.updateWorkQty(dto.getOrderDetlId(), dto.getAnfme());
 | 
 |  |  | 
 |  |  |                     taskDetlField.setId(null);
 | 
 |  |  |                     taskDetlField.setDetlId(taskDetl.getId());
 | 
 |  |  |                     boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
 | 
 |  |  |                     if(!taskDetlFieldSave){
 | 
 |  |  |                     if (!taskDetlFieldSave) {
 | 
 |  |  |                         throw new CoolException("明细扩展生成失败");
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  | 
 |  |  |             loc.setLocStsId(LocStsType.R.val());
 | 
 |  |  |             loc.setUpdateTime(new Date());
 | 
 |  |  |             boolean locUpdate = locService.updateById(loc);
 | 
 |  |  |             if(!locUpdate){
 | 
 |  |  |             if (!locUpdate) {
 | 
 |  |  |                 throw new CoolException("库位状态更新失败");
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, orderIds));
 | 
 |  |  |         if(orderDetls.isEmpty()){
 | 
 |  |  |         if (orderDetls.isEmpty()) {
 | 
 |  |  |             throw new CoolException("订单明细不存在");
 | 
 |  |  |         }
 | 
 |  |  |         orderDetls = orderDetlService.parseDetl(orderDetls);
 | 
 |  |  | 
 |  |  |                 Double anfme = locDetlStockMap.get(matUniqueKey);
 | 
 |  |  |                 anfme += issued;
 | 
 |  |  |                 locDetlStockMap.put(matUniqueKey, anfme);
 | 
 |  |  |             }else {
 | 
 |  |  |             } else {
 | 
 |  |  |                 locDetlStockMap.put(matUniqueKey, issued);
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  | 
 |  |  |             mergePreviewDtos.add(dto);
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  |         return mergePreviewDtos;
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @Transactional
 | 
 |  |  |     /**
 | 
 |  |  |      * 波次出库预览
 | 
 |  |  |      *
 | 
 |  |  |      * @param param
 | 
 |  |  |      * @return
 | 
 |  |  |      */
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public List<MergePreviewResultDto> orderOutMergeLocPreview(List<MergePreviewDto> param) {
 | 
 |  |  |         if (param == null) {
 | 
 |  |  |             throw new CoolException("参数不能为空");
 | 
 |  |  | 
 |  |  |             dto.setFieldParams(fieldParams);
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         FieldSortParam sortParam = new FieldSortParam("anfme","desc");
 | 
 |  |  |         FieldSortParam sortParam = new FieldSortParam("anfme", "desc");
 | 
 |  |  |         List<FieldSortParam> sortParams = new ArrayList<>();
 | 
 |  |  |         sortParams.add(sortParam);
 | 
 |  |  | 
 | 
 |  |  |         List<MergePreviewResultDto> resultDtos = new ArrayList<>();
 | 
 |  |  |         //优先查询平库数据
 | 
 |  |  |         param.forEach(pars -> {
 | 
 |  |  |             if (pars.getStatus() == 1) {
 | 
 |  |  |                 return;
 | 
 |  |  |             }
 | 
 |  |  |             List<MergePreviewResultLocDto> locDtos = new ArrayList<>();
 | 
 |  |  |             MergePreviewResultDto resultDto = new MergePreviewResultDto();
 | 
 |  |  |             resultDto.sync(pars);
 | 
 |  |  |             resultDto.setOrderIds(pars.getOrderIds());
 | 
 |  |  |             //总需求数量
 | 
 |  |  |             resultDto.setAnfme(pars.getAnfme());
 | 
 |  |  |             resultDto.setLocs(locDtos);
 | 
 |  |  |             //查询平库中符合条件的库存
 | 
 |  |  |             List<LocDetl> locs = locDetlService.queryFlatStock(pars.getMatnr(), pars.getBatch(), pars.getFieldParams());
 | 
 |  |  |             if (!locs.isEmpty()) {
 | 
 |  |  |                 Double anfme = pars.getAnfme() - pars.getWorkQty();
 | 
 |  |  |                 for (LocDetl detl : locs) {
 | 
 |  |  |                     Loc loc = locService.getById(detl.getLocId());
 | 
 |  |  |                     if (loc == null) {
 | 
 |  |  |                         throw new CoolException("库位数据不存在");
 | 
 |  |  |                     }
 | 
 |  |  | 
 | 
 |  |  |                     if (loc.getLocStsId() != LocStsType.F.val()) {
 | 
 |  |  |                         continue;
 | 
 |  |  |                     }
 | 
 |  |  |                     MergePreviewResultLocDto locDto = new MergePreviewResultLocDto();
 | 
 |  |  |                     locDto.setLocId(detl.getLocId());
 | 
 |  |  |                     locDto.setLocNo(detl.getLocNo());
 | 
 |  |  |                     locDto.setTypeId(LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id);
 | 
 |  |  |                     locDto.setLocDetlId(detl.getId());
 | 
 |  |  |                     locDto.setAnfme(detl.getAnfme() - detl.getWorkQty());
 | 
 |  |  |                     locDto.setWorkQty(detl.getWorkQty());
 | 
 |  |  |                     locDtos.add(locDto);
 | 
 |  |  |                     //库位实际可用数量
 | 
 |  |  |                     Double surplusQty = Math.round((detl.getAnfme() - detl.getWorkQty()) * 10000) / 10000.0;
 | 
 |  |  |                     if (surplusQty <= 0) {
 | 
 |  |  |                         continue;
 | 
 |  |  |                     }
 | 
 |  |  |                     //波次数量减去库位可用数量后,盈余数量
 | 
 |  |  |                     anfme = Math.round((anfme - surplusQty) * 10000) / 10000.0;
 | 
 |  |  |                     if (anfme.compareTo(0.0) > 0) {
 | 
 |  |  |                         //当前可使用数量
 | 
 |  |  |                         resultDto.setFetchQty(surplusQty);
 | 
 |  |  |                         //余下需求数量
 | 
 |  |  |                         pars.setStatus(2);
 | 
 |  |  |                         pars.setWorkQty(pars.getWorkQty() + surplusQty);
 | 
 |  |  |                         pars.setAnfme(anfme);
 | 
 |  |  |                     } else {
 | 
 |  |  |                         //当前使用数量
 | 
 |  |  |                         resultDto.setFetchQty(pars.getAnfme());
 | 
 |  |  |                         //余下需求
 | 
 |  |  |                         pars.setWorkQty(pars.getWorkQty() + pars.getAnfme());
 | 
 |  |  |                         pars.setStatus(1);
 | 
 |  |  |                         pars.setAnfme(0.0);
 | 
 |  |  |                         break;
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  |                 if (!Objects.isNull(resultDto.getFetchQty()) && !(new BigDecimal(resultDto.getFetchQty()).compareTo(new BigDecimal("0.00")) == 0)) {
 | 
 |  |  |                     resultDto.setOtherLocs(new ArrayList<>());
 | 
 |  |  | 
 | 
 |  |  |                     resultDto.setType(LocAreaTypeSts.LOC_AREA_TYPE_FLAT.desc);
 | 
 |  |  | 
 | 
 |  |  |                     resultDtos.add(resultDto);
 | 
 |  |  |                 }
 | 
 |  |  |             }
 | 
 |  |  |         });
 | 
 |  |  | 
 | 
 |  |  |         //平库查询完成后,再查询TCU
 | 
 |  |  |         for (MergePreviewDto dto : param) {
 | 
 |  |  |             //单据已完成,跳出
 | 
 |  |  |             if (dto.getStatus() == 1) {
 | 
 |  |  |                 continue;
 | 
 |  |  |             }
 | 
 |  |  | //            Double anfme = dto.getAnfme() - dto.getWorkQty();
 | 
 |  |  | //            //减去平库数量后,小于等于0,跳出处理
 | 
 |  |  | //            if (anfme <= 0) {
 | 
 |  |  | //                continue;
 | 
 |  |  | //            }
 | 
 |  |  |             List<LocDetl> locDetls = locDetlService.queryStock(dto.getMatnr(), dto.getBatch(), dto.getFieldParams(), sortParams);
 | 
 |  |  |             if(locDetls.isEmpty()){
 | 
 |  |  |             if (locDetls.isEmpty()) {
 | 
 |  |  |                 MergePreviewResultDto resultDto = new MergePreviewResultDto();
 | 
 |  |  |                 resultDto.sync(dto);
 | 
 |  |  |                 resultDto.setLocs(new ArrayList<>());
 | 
 |  |  |                 resultDto.setType(LocAreaTypeSts.LOC_AREA_TYPE_UTC.desc);
 | 
 |  |  |                 resultDto.setOrderIds(dto.getOrderIds());
 | 
 |  |  |                 resultDto.setAnfme(dto.getAnfme());
 | 
 |  |  |                 resultDtos.add(resultDto);
 | 
 |  |  | 
 |  |  | 
 | 
 |  |  |             MergePreviewResultDto resultDto = new MergePreviewResultDto();
 | 
 |  |  |             resultDto.sync(dto);
 | 
 |  |  |             resultDto.setLocs(locDtos);
 | 
 |  |  |             resultDto.setOrderIds(dto.getOrderIds());
 | 
 |  |  | 
 | 
 |  |  |             Double anfme = dto.getAnfme();
 | 
 |  |  |             resultDto.setLocs(locDtos);
 | 
 |  |  |             for (LocDetl locDetl : locDetls) {
 | 
 |  |  |                 Loc loc = locService.getById(locDetl.getLocId());
 | 
 |  |  |                 if (loc == null) {
 | 
 |  |  | 
 |  |  |                 locDto.setLocId(locDetl.getLocId());
 | 
 |  |  |                 locDto.setLocNo(locDetl.getLocNo());
 | 
 |  |  |                 locDto.setLocDetlId(locDetl.getId());
 | 
 |  |  | 
 | 
 |  |  |                 locDto.setTypeId(LocAreaTypeSts.LOC_AREA_TYPE_UTC.id);
 | 
 |  |  |                 locDtos.add(locDto);
 | 
 |  |  |                 if (anfme - locDetl.getAnfme() < 0) {
 | 
 |  |  |                     locDto.setAnfme(anfme);
 | 
 |  |  | 
 |  |  |                 MergePreviewResultLocDto locDto = new MergePreviewResultLocDto();
 | 
 |  |  |                 locDto.setLocId(locDetl.getLocId());
 | 
 |  |  |                 locDto.setLocNo(locDetl.getLocNo());
 | 
 |  |  |                 locDto.setTypeId(LocAreaTypeSts.LOC_AREA_TYPE_UTC.id);
 | 
 |  |  |                 locDto.setLocDetlId(locDetl.getId());
 | 
 |  |  |                 locDto.setAnfme(locDetl.getAnfme());
 | 
 |  |  |                 otherLocDtos.add(locDto);
 | 
 |  |  | 
 |  |  | 
 | 
 |  |  |             resultDto.setAnfme(dto.getAnfme());
 | 
 |  |  | 
 | 
 |  |  |             resultDto.setType(LocAreaTypeSts.LOC_AREA_TYPE_UTC.desc);
 | 
 |  |  | 
 | 
 |  |  |             resultDtos.add(resultDto);
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         return resultDtos;
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @Transactional
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void orderOutMerge(OrderOutMergeParamDto dto) {
 | 
 |  |  |         if(dto == null){
 | 
 |  |  |         if (dto == null) {
 | 
 |  |  |             throw new CoolException("参数不能为空");
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  |                 List<OrderDetl> detls = detlMap.get(matUniqueKey);
 | 
 |  |  |                 detls.add(orderDetl);
 | 
 |  |  |                 detlMap.put(matUniqueKey, detls);
 | 
 |  |  |             }else {
 | 
 |  |  |             } else {
 | 
 |  |  |                 List<OrderDetl> detls = new ArrayList<>();
 | 
 |  |  |                 detls.add(orderDetl);
 | 
 |  |  |                 detlMap.put(matUniqueKey, detls);
 | 
 |  |  | 
 |  |  |                     orderOutMergeDto.setAnfme(issued);
 | 
 |  |  |                     updateWorkQty = issued;
 | 
 |  |  |                     requireAnfme -= issued;
 | 
 |  |  |                 }else {
 | 
 |  |  |                 } else {
 | 
 |  |  |                     orderOutMergeDto.setAnfme(requireAnfme);
 | 
 |  |  |                     updateWorkQty = requireAnfme;
 | 
 |  |  |                     requireAnfme -= requireAnfme;
 | 
 |  |  | 
 |  |  |             List<OrderOutMergeDto> list = null;
 | 
 |  |  |             if (map.containsKey(orderOutMergeDto.getLocId())) {
 | 
 |  |  |                 list = map.get(orderOutMergeDto.getLocId());
 | 
 |  |  |             }else {
 | 
 |  |  |             } else {
 | 
 |  |  |                 list = new ArrayList<>();
 | 
 |  |  |             }
 | 
 |  |  |             list.add(orderOutMergeDto);
 | 
 |  |  | 
 |  |  | 
 | 
 |  |  |             for (OrderOutMergeDto merge : list) {
 | 
 |  |  |                 LocDetl locDetl = locDetlService.getById(merge.getLocDetlId());
 | 
 |  |  |                 if(locDetl == null) {
 | 
 |  |  |                 if (locDetl == null) {
 | 
 |  |  |                     throw new CoolException("明细不存在");
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  |                 OrderDetl orderDetl = orderDetlService.getById(merge.getOrderDetlId());
 | 
 |  |  |                 if(orderDetl == null) {
 | 
 |  |  |                 if (orderDetl == null) {
 | 
 |  |  |                     throw new CoolException("订单明细不存在");
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  |                     taskDetlField.setId(null);
 | 
 |  |  |                     taskDetlField.setDetlId(taskDetl.getId());
 | 
 |  |  |                     boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
 | 
 |  |  |                     if(!taskDetlFieldSave){
 | 
 |  |  |                     if (!taskDetlFieldSave) {
 | 
 |  |  |                         throw new CoolException("明细扩展生成失败");
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  | 
 |  |  |             loc.setLocStsId(LocStsType.R.val());
 | 
 |  |  |             loc.setUpdateTime(new Date());
 | 
 |  |  |             boolean locUpdate = locService.updateById(loc);
 | 
 |  |  |             if(!locUpdate){
 | 
 |  |  |             if (!locUpdate) {
 | 
 |  |  |                 throw new CoolException("库位状态更新失败");
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  | 
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * 波次生成出库任务
 | 
 |  |  |      * UTC出库任务逻辑不变,添加平库判别逻辑
 | 
 |  |  |      * 1. 获取波次订单明细,判别是否为平库订单
 | 
 |  |  |      * 2. 平库订单生成拣货单, UTC订单生成出库任务
 | 
 |  |  |      * 3. 平库单据明细所占库位物料数量加锁
 | 
 |  |  |      * 4. 生成出库单PDA端,统一出库扣减库存
 | 
 |  |  |      * 5. 生成拣货单历史档,出库单据加入历史档,删除原单据
 | 
 |  |  |      * 6. 删除波次列表数据
 | 
 |  |  |      *
 | 
 |  |  |      * @param dto
 | 
 |  |  |      */
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void orderOutMergeWave(OrderOutMergeParamDto dto) {
 | 
 |  |  |         if(dto == null){
 | 
 |  |  |         if (dto == null) {
 | 
 |  |  |             throw new CoolException("参数不能为空");
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  |             throw new CoolException("波次不存在");
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         List<OrderOutMergeParam> params = dto.getList();
 | 
 |  |  |         /**
 | 
 |  |  |          * 波次合并出库
 | 
 |  |  |          * 1. 判断是平库还CTU库
 | 
 |  |  |          * 2. 平库生成拣货单
 | 
 |  |  |          * 3. CTU库生成任务单
 | 
 |  |  |          */
 | 
 |  |  |         outStockByArea(dto, wave);
 | 
 |  |  | 
 | 
 |  |  |         if (params.isEmpty()) {
 | 
 |  |  |             throw new CoolException("参数不能为空");
 | 
 |  |  |         //波次状态修改为--生成任务
 | 
 |  |  |         wave.setWaveStatus(WaveStatusType.GENERATE.id);
 | 
 |  |  |         wave.setUpdateTime(new Date());
 | 
 |  |  |         if (!waveService.updateById(wave)) {
 | 
 |  |  |             throw new CoolException("波次更新失败");
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  | //        Long waveId = dto.getWaveId();
 | 
 |  |  | //        String waveNo = dto.getw
 | 
 |  |  | 
 | 
 |  |  |         List<Long> filterParamsList = new ArrayList<>();
 | 
 |  |  |         List<OrderOutMergeParam> filterParams = new ArrayList<>();
 | 
 |  |  | 
 | 
 |  |  |         params.forEach(action -> {
 | 
 |  |  |             if (action.getLocId() != null) {
 | 
 |  |  |                 filterParamsList.add(action.getLocId());
 | 
 |  |  |                 filterParams.add(action);
 | 
 |  |  |             }
 | 
 |  |  |         });
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * 1. 判断当波次及库位明细是否存在
 | 
 |  |  |      * 2. 组合key-value(list)形式数据
 | 
 |  |  |      *
 | 
 |  |  |      * @param mergeParams
 | 
 |  |  |      * @param wave
 | 
 |  |  |      * @return
 | 
 |  |  |      */
 | 
 |  |  |     private Map<Long, List<OrderOutMergeDto>> checkLoc(List<OrderOutMergeParam> mergeParams, Wave wave) {
 | 
 |  |  |         HashMap<String, Double> stockMap = new HashMap<>();
 | 
 |  |  |         for (OrderOutMergeParam param : filterParams) {
 | 
 |  |  |         for (OrderOutMergeParam param : mergeParams) {
 | 
 |  |  |             String matUniqueKey = Utils.getMatUniqueKey(param.getMatnr(), param.getBatch(), param.getFieldParams());
 | 
 |  |  |             WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getStockIndex, matUniqueKey).eq(WaveDetl::getWaveId, wave.getId()));
 | 
 |  |  |             if(waveDetl == null){
 | 
 |  |  |             if (waveDetl == null) {
 | 
 |  |  |                 throw new CoolException("波次数据不存在");
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             //获取当前需要执行数量
 | 
 |  |  |             double issued = Optional.of(waveDetl.getAnfme() - waveDetl.getWorkQty()).orElse(0.0D);
 | 
 |  |  |             if(!stockMap.containsKey(matUniqueKey)){
 | 
 |  |  |             if (!stockMap.containsKey(matUniqueKey)) {
 | 
 |  |  |                 stockMap.put(matUniqueKey, issued);
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         HashMap<Long, List<OrderOutMergeDto>> map = new HashMap<>();
 | 
 |  |  |         for (OrderOutMergeParam param : filterParams) {
 | 
 |  |  |         for (OrderOutMergeParam param : mergeParams) {
 | 
 |  |  |             LocDetl locDetl = locDetlService.getById(param.getLocDetlId());
 | 
 |  |  |             if(locDetl == null) {
 | 
 |  |  |             if (locDetl == null) {
 | 
 |  |  |                 continue;
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             if (locDetl.getAnfme() - param.getAnfme() < 0) {
 | 
 |  |  |             //库位数量小于出库数量 //新增workQty用于平库锁库存
 | 
 |  |  |             if (locDetl.getAnfme() - locDetl.getWorkQty() - param.getAnfme() < 0) {
 | 
 |  |  |                 continue;
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             OrderOutMergeDto orderOutMergeDto = new OrderOutMergeDto();
 | 
 |  |  |             orderOutMergeDto.sync(param);
 | 
 |  |  | 
 | 
 |  |  |             //fixme 确认stockMap是否有用,此处入值后却没有使用
 | 
 |  |  |             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 {
 | 
 |  |  |             } else {
 | 
 |  |  |                 issued -= orderOutMergeDto.getAnfme();
 | 
 |  |  |             }
 | 
 |  |  |             stockMap.put(matUniqueKey, issued);
 | 
 |  |  | 
 | 
 |  |  |             stockMap.put(matUniqueKey, issued);
 | 
 |  |  |             //根据库位做分类,可使用stream().groupby
 | 
 |  |  |             List<OrderOutMergeDto> list = null;
 | 
 |  |  |             if (map.containsKey(orderOutMergeDto.getLocId())) {
 | 
 |  |  |                 list = map.get(orderOutMergeDto.getLocId());
 | 
 |  |  |             }else {
 | 
 |  |  |             } else {
 | 
 |  |  |                 list = new ArrayList<>();
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             list.add(orderOutMergeDto);
 | 
 |  |  |             map.put(orderOutMergeDto.getLocId(), list);
 | 
 |  |  |         }
 | 
 |  |  | 
 |  |  |             throw new CoolException("库存不足");
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         return map;
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * 根据不同库位类型生成出库拣货单或CTU任务档
 | 
 |  |  |      *
 | 
 |  |  |      * @param dto
 | 
 |  |  |      * @param
 | 
 |  |  |      */
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void outStockByArea(OrderOutMergeParamDto dto, Wave wave) {
 | 
 |  |  |         List<OrderOutMergeParam> params = dto.getList();
 | 
 |  |  |         if (params.isEmpty()) {
 | 
 |  |  |             throw new CoolException("参数不能为空");
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         //平库数据源
 | 
 |  |  |         List<OrderOutMergeParam> flatOrders = new ArrayList<>();// listMap.get(LocAreaTypeSts.LOC_AREA_TYPE_FLAT);
 | 
 |  |  |         //CTU数据源
 | 
 |  |  |         List<OrderOutMergeParam> tucOrders = new ArrayList<>();//listMap.get(LocAreaTypeSts.LOC_AREA_TYPE_UTC);
 | 
 |  |  |         //按库位类型分类
 | 
 |  |  |         List<OrderOutMergeParam> mergeParam = params.stream().filter(par -> {
 | 
 |  |  |             return !StringUtils.isNullOrEmpty(par.getLocNo());
 | 
 |  |  |         }).collect(Collectors.toList());
 | 
 |  |  |         //数据分类 1.平库数据  2. CTU数据
 | 
 |  |  |         Map<Long, List<OrderOutMergeParam>> listMap = mergeParam.stream().collect(Collectors.groupingBy(OrderOutMergeParam::getTypeId));
 | 
 |  |  | 
 | 
 |  |  |         listMap.keySet().forEach(key -> {
 | 
 |  |  |             if (key == LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id) {
 | 
 |  |  |                 flatOrders.addAll(listMap.get(key));
 | 
 |  |  |             } else {
 | 
 |  |  |                 tucOrders.addAll(listMap.get(key));
 | 
 |  |  |             }
 | 
 |  |  |         });
 | 
 |  |  |         if (!flatOrders.isEmpty()) {
 | 
 |  |  |             //平库出库
 | 
 |  |  |             outStockByFlat(flatOrders, wave);
 | 
 |  |  |         }
 | 
 |  |  |         if (!tucOrders.isEmpty()) {
 | 
 |  |  |             //CTU出库
 | 
 |  |  |             outStockByCTU(tucOrders, wave);
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * CTU出库--生成出库任务档
 | 
 |  |  |      *
 | 
 |  |  |      * @param tucOrders
 | 
 |  |  |      * @param wave
 | 
 |  |  |      */
 | 
 |  |  |     private void outStockByCTU(List<OrderOutMergeParam> tucOrders, Wave wave) {
 | 
 |  |  |         Map<Long, List<OrderOutMergeDto>> map = checkLoc(tucOrders, wave);
 | 
 |  |  | 
 | 
 |  |  |         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();
 | 
 |  |  | 
 |  |  |             if (operationPort == null) {
 | 
 |  |  |                 throw new CoolException("作业口不存在");
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             //101 全拖出库   103 拣货出库
 | 
 |  |  |             long taskType = all ? 101L : 103L;
 | 
 |  |  | 
 | 
 |  |  |             Task task = new Task();
 | 
 |  |  | 
 |  |  |                 throw new CoolException("保存工作档失败");
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             wave.setSite(operationPort.getFlag());
 | 
 |  |  |             if (!waveService.updateById(wave)) {
 | 
 |  |  |                 throw new CoolException("波次站口状态更新失败!!");
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             for (OrderOutMergeDto merge : list) {
 | 
 |  |  |                 LocDetl locDetl = locDetlService.getById(merge.getLocDetlId());
 | 
 |  |  |                 if(locDetl == null) {
 | 
 |  |  |                 if (locDetl == null) {
 | 
 |  |  |                     throw new CoolException("明细不存在");
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  |                     taskDetlField.setId(null);
 | 
 |  |  |                     taskDetlField.setDetlId(taskDetl.getId());
 | 
 |  |  |                     boolean taskDetlFieldSave = taskDetlFieldService.save(taskDetlField);
 | 
 |  |  |                     if(!taskDetlFieldSave){
 | 
 |  |  |                     if (!taskDetlFieldSave) {
 | 
 |  |  |                         throw new CoolException("明细扩展生成失败");
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  |                 //TODO 确认后,需将注释打开
 | 
 |  |  |                 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));
 | 
 |  |  |                 WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getWaveId, wave.getId()), false);
 | 
 |  |  |                 logger.error("Matnr------>{}", taskDetl.getMatnr());
 | 
 |  |  |                 WaveDetl waveDetl = waveDetlService.getOne(new LambdaQueryWrapper<WaveDetl>()
 | 
 |  |  |                         .eq(WaveDetl::getStockIndex, matUniqueKey)
 | 
 |  |  |                         .eq(WaveDetl::getWaveId, wave.getId()));
 | 
 |  |  |                 if (waveDetl == null) {
 | 
 |  |  |                     throw new CoolException("波次数据不存在");
 | 
 |  |  |                     throw new CoolException("waveId:" + wave.getId() + "物料:" + taskDetl.getMatnr() + "波次数据不存在");
 | 
 |  |  |                 }
 | 
 |  |  |                 waveDetl.setWorkQty(waveDetl.getWorkQty() + taskDetl.getAnfme());
 | 
 |  |  |                 waveDetl.setUpdateTime(new Date());
 | 
 |  |  | 
 |  |  |                 }
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  |             //出库库存更新逻辑
 | 
 |  |  | //            List<Long> orderIds = dto.getList().stream().findFirst().get().getOrderIds();
 | 
 |  |  | //            List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, orderIds));
 | 
 |  |  | //            orderDetls.forEach(orderDetl -> {
 | 
 |  |  | //                orderUtils.updateWorkQty(orderDetl.getId(), orderDetl.getAnfme());
 | 
 |  |  | //            });
 | 
 |  |  |             List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getWaveNo, wave.getWaveNo()));
 | 
 |  |  |             if (orders.isEmpty()) {
 | 
 |  |  |                 throw new CoolException("当前波次订单不存在!!");
 | 
 |  |  |             }
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  | //            List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>()
 | 
 |  |  | //                    .eq(CacheSite::getSiteStatus, CacheSiteStatusType.O.id).eq(CacheSite::getChannel, task.getTargetSite()));
 | 
 |  |  | //
 | 
 |  |  | //            if (cacheSites.isEmpty()) {
 | 
 |  |  | //                throw new CoolException("缓存站空间不足,请稍后再试");
 | 
 |  |  | //            }
 | 
 |  |  | //
 | 
 |  |  | //            if (cacheSites.size() < orders.size()) {
 | 
 |  |  | //                throw new CoolException("缓存站空间不足,请稍后再试");
 | 
 |  |  | //            }
 | 
 |  |  | 
 | 
 |  |  | //            for (int i = 0; i < orders.size(); i++) {
 | 
 |  |  | //                CacheSite cacheSite = cacheSiteService.getOne(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getOrderId, orders.get(i).getId()));
 | 
 |  |  | //                if (Objects.isNull(cacheSite)) {
 | 
 |  |  | //                    cacheSite.setOrderId(orders.get(i).getId());
 | 
 |  |  | //                    cacheSite.setOrderNo(orders.get(i).getOrderNo());
 | 
 |  |  | //                    cacheSite.setSiteStatus(CacheSiteStatusType.R.id);
 | 
 |  |  | //                    cacheSite.setBarcode(loc.getBarcode());
 | 
 |  |  | //                    cacheSite.setUpdateTime(new Date());
 | 
 |  |  | //                    if (!cacheSiteService.updateById(cacheSite)) {
 | 
 |  |  | //                        throw new CoolException("缓存站更新失败");
 | 
 |  |  | //                    }
 | 
 |  |  | //                }
 | 
 |  |  | //            }
 | 
 |  |  | 
 | 
 |  |  |             //库位F => R
 | 
 |  |  |             loc.setLocStsId(LocStsType.R.val());
 | 
 |  |  |             loc.setUpdateTime(new Date());
 | 
 |  |  |             boolean locUpdate = locService.updateById(loc);
 | 
 |  |  |             if(!locUpdate){
 | 
 |  |  |             if (!locUpdate) {
 | 
 |  |  |                 throw new CoolException("库位状态更新失败");
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  | //        Wave wave = waveService.getById(dto.getWaveId());
 | 
 |  |  | //        if (wave == null) {
 | 
 |  |  | //            throw new CoolException("波次不存在");
 | 
 |  |  | //        }
 | 
 |  |  |     /**
 | 
 |  |  |      * 平库出库--生成出库拣货单
 | 
 |  |  |      * 1. 判断当前库位是否存在
 | 
 |  |  |      * 2. 一张单据一个波次
 | 
 |  |  |      * 3. 一个波次多条订单
 | 
 |  |  |      * 4. 一个库位可多条明细
 | 
 |  |  |      * 5. 拣货单完成后,释放库位明细锁定数量
 | 
 |  |  |      *
 | 
 |  |  |      * @param flatOrders
 | 
 |  |  |      * @param wave
 | 
 |  |  |      */
 | 
 |  |  |     private void outStockByFlat(List<OrderOutMergeParam> flatOrders, Wave wave) {
 | 
 |  |  |         //校验库存数量
 | 
 |  |  |         Map<Long, List<OrderOutMergeDto>> map = checkLoc(flatOrders, wave);
 | 
 |  |  |         //生成拣货单
 | 
 |  |  |         PickSheet pickSheet = new PickSheet();
 | 
 |  |  |         //波次数量汇总
 | 
 |  |  |         double sum = flatOrders.stream().mapToDouble(OrderOutMergeParam::getAnfme).sum();
 | 
 |  |  |         //生成拣货单号
 | 
 |  |  |         String pickNo = generatePickNO();
 | 
 |  |  |         pickSheet.setId(null)
 | 
 |  |  |                 .setPickNo(pickNo)
 | 
 |  |  |                 .setMemo(wave.getMemo())
 | 
 |  |  |                 .setAnfme(sum)
 | 
 |  |  |                 .setWaveId(wave.getId())
 | 
 |  |  |                 .setWaveNo(wave.getWaveNo());
 | 
 |  |  | 
 | 
 |  |  |         wave.setWaveStatus(WaveStatusType.GENERATE.id);
 | 
 |  |  |         wave.setUpdateTime(new Date());
 | 
 |  |  |         if (!waveService.updateById(wave)) {
 | 
 |  |  |             throw new CoolException("波次更新失败");
 | 
 |  |  |         if (!pickSheetService.save(pickSheet)) {
 | 
 |  |  |             throw new CoolException("拣货单写入失败!!");
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         //根据库位ID分组
 | 
 |  |  |         Map<Long, List<OrderOutMergeParam>> listMap = flatOrders.stream().collect(Collectors.groupingBy(OrderOutMergeParam::getLocId));
 | 
 |  |  | 
 | 
 |  |  |         genPickSheet(listMap, pickSheet);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * @author Ryan
 | 
 |  |  |      * @date 2025/7/4
 | 
 |  |  |      * @description: 生成拣货明细
 | 
 |  |  |      * @version 1.0
 | 
 |  |  |      */
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void genPickSheet(Map<Long, List<OrderOutMergeParam>> listMap, PickSheet pickSheet) {
 | 
 |  |  |         //生成拣货明细
 | 
 |  |  |         listMap.keySet().forEach(key -> {
 | 
 |  |  |             Loc curLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getId, key));
 | 
 |  |  |             if (Objects.isNull(curLoc)) {
 | 
 |  |  |                 throw new CoolException("主键." + key + "的库位不存在!!");
 | 
 |  |  |             }
 | 
 |  |  |             listMap.get(key).forEach(outOder -> {
 | 
 |  |  |                 //获取库位明细信息
 | 
 |  |  |                 LocDetl locDetl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getId, outOder.getLocDetlId()));
 | 
 |  |  |                 PickSheetDetl sheetDetl = new PickSheetDetl();
 | 
 |  |  |                 BeanUtils.copyProperties(outOder, sheetDetl);
 | 
 |  |  |                 //获取物料信息
 | 
 |  |  |                 Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, outOder.getMatnr()));
 | 
 |  |  |                 //拣货单明细
 | 
 |  |  |                 sheetDetl.setBarcode(curLoc.getBarcode())
 | 
 |  |  |                         .setPickId(pickSheet.getId())
 | 
 |  |  |                         .setAnfme(BigDecimal.valueOf(outOder.getAnfme()))
 | 
 |  |  |                         .setLocDetlId(locDetl.getId())
 | 
 |  |  |                         .setMaktx(mat.getMaktx())
 | 
 |  |  |                         .setMatId(mat.getId());
 | 
 |  |  |                 if (!pickSheetDetlService.save(sheetDetl)) {
 | 
 |  |  |                     throw new CoolException("拣货明细列新失败");
 | 
 |  |  |                 }
 | 
 |  |  |                 //锁定库存量
 | 
 |  |  |                 locDetl.setWorkQty(locDetl.getWorkQty() + outOder.getAnfme());
 | 
 |  |  | 
 | 
 |  |  |                 if (!locDetlService.updateById(locDetl)) {
 | 
 |  |  |                     throw new CoolException("库存加锁失败!!");
 | 
 |  |  |                 }
 | 
 |  |  |             });
 | 
 |  |  | 
 | 
 |  |  |             curLoc.setLocStsId(LocStsType.R.val());
 | 
 |  |  | 
 | 
 |  |  |             if (!locService.updateById(curLoc)) {
 | 
 |  |  |                 throw new CoolException("库位状态修改失败!!");
 | 
 |  |  |             }
 | 
 |  |  |         });
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * 生成拣货单号
 | 
 |  |  |      *
 | 
 |  |  |      * @return
 | 
 |  |  |      */
 | 
 |  |  |     private String generatePickNO() {
 | 
 |  |  |         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
 | 
 |  |  |         String format = simpleDateFormat.format(new Date());
 | 
 |  |  |         Random random = new Random();
 | 
 |  |  |         return "PN" + format + random.nextInt(10000);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  | 
 |  |  |         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 + "通道已经分配波次");
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  | //        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("订单参数不能为空");
 | 
 |  |  | 
 |  |  |                 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("缓存站更新失败");
 | 
 |  |  |             }
 | 
 |  |  | //            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()) {
 | 
 |  |  | 
 |  |  | 
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @Transactional
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void cancelWave(List<Long> waveIds) {
 | 
 |  |  |         if (waveIds == null) {
 | 
 |  |  |             throw new CoolException("参数不能为空");
 | 
 |  |  | 
 |  |  |                     throw new CoolException("已存在任务,禁止取消波次");
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  |                 List<PickSheet> pickSheets = pickSheetService.list(new LambdaQueryWrapper<PickSheet>()
 | 
 |  |  |                         .eq(PickSheet::getWaveNo, wave.getWaveNo())
 | 
 |  |  |                         .eq(PickSheet::getDeleted, 0)
 | 
 |  |  |                         .eq(PickSheet::getStatus, 1));
 | 
 |  |  |                 if (!pickSheets.isEmpty()) {
 | 
 |  |  |                     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())){
 | 
 |  |  |                     if (order.getOrderSettle().equals(OrderSettleType.WAVE.val())) {
 | 
 |  |  |                         order.setOrderSettle(OrderSettleType.WAIT.val());
 | 
 |  |  |                     }
 | 
 |  |  |                     if (!orderService.updateById(order)) {
 | 
 |  |  | 
 |  |  |                     }
 | 
 |  |  | 
 | 
 |  |  |                     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("缓存站清空失败");
 | 
 |  |  |                     if (cacheSite != null) {
 | 
 |  |  |                         cacheSite.setSiteStatus(CacheSiteStatusType.O.id);
 | 
 |  |  |                         cacheSite.setOrderId(null);
 | 
 |  |  |                         cacheSite.setOrderNo(null);
 | 
 |  |  |                         cacheSite.setBarcode(null);
 | 
 |  |  |                         cacheSite.setUpdateTime(new Date());
 | 
 |  |  |                         if (!cacheSiteService.updateById(cacheSite)) {
 | 
 |  |  |                             throw new CoolException("缓存站清空失败");
 | 
 |  |  |                         }
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  | 
 | 
 |  |  |             waveService.removeById(wave.getId());
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * @author Ryan
 | 
 |  |  |      * @date 2025/7/3
 | 
 |  |  |      * @description: 库存出库信息
 | 
 |  |  |      * @version 1.0
 | 
 |  |  |      */
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void outLocStock(StockOutParam param) {
 | 
 |  |  |         System.out.println(JSONObject.toJSONString(param));
 | 
 |  |  |         if (param.getOutType().equals(1)) {
 | 
 |  |  |             //拣货单
 | 
 |  |  |             outFlatStock(param);
 | 
 |  |  |         } else {
 | 
 |  |  |             //生成任务档
 | 
 |  |  |             generateTask(param);
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * @author Ryan
 | 
 |  |  |      * @param: []
 | 
 |  |  |      * @return: void
 | 
 |  |  |      * @date: 2025/7/4
 | 
 |  |  |      * @description: 手动出库生成任务
 | 
 |  |  |      */
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void generateTask(StockOutParam outParam) {
 | 
 |  |  |         for (LocDetl outLocDetl : outParam.getLocDetls()) {
 | 
 |  |  |             List<OrderOutMergeDto> orders = new ArrayList<>();
 | 
 |  |  |             LocDetl detl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getId, outLocDetl.getId()));
 | 
 |  |  |             if (Objects.isNull(detl)) {
 | 
 |  |  |                 continue;
 | 
 |  |  |             }
 | 
 |  |  |             OrderOutMergeDto outMergeParam = new OrderOutMergeDto();
 | 
 |  |  |             outMergeParam.setAnfme(outLocDetl.getAnfme());
 | 
 |  |  |             outMergeParam.setLocNo(outLocDetl.getLocNo());
 | 
 |  |  |             outMergeParam.setLocDetlId(detl.getId());
 | 
 |  |  |             outMergeParam.setLocId(detl.getLocId());
 | 
 |  |  |             outMergeParam.setMatnr(outLocDetl.getMatnr());
 | 
 |  |  |             outMergeParam.setBatch(detl.getBatch());
 | 
 |  |  |             orders.add(outMergeParam);
 | 
 |  |  | 
 | 
 |  |  |             //根据库位ID分组
 | 
 |  |  |             Map<Long, List<OrderOutMergeDto>> listMap = orders.stream().collect(Collectors.groupingBy(OrderOutMergeDto::getLocId));
 | 
 |  |  |             //生成拣货单明细
 | 
 |  |  |             for (Map.Entry<Long, List<OrderOutMergeDto>> entry : listMap.entrySet()) {
 | 
 |  |  |                 Long locId = entry.getKey();
 | 
 |  |  |                 List<OrderOutMergeDto> list = entry.getValue();
 | 
 |  |  |                 //判断是否全仓出库
 | 
 |  |  |                 Boolean all = outUtils.isAllForMerge(locId, list);
 | 
 |  |  |                 OrderOutMergeDto param = list.stream().findFirst().get();
 | 
 |  |  | 
 | 
 |  |  |                 List<CacheSite> sites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>()
 | 
 |  |  |                         .isNotNull(CacheSite::getOrderId));
 | 
 |  |  |                 if (!sites.isEmpty()) {
 | 
 |  |  |                     Map<String, Long> longMap = sites.stream().collect(Collectors.groupingBy(CacheSite::getChannel, Collectors.counting()));
 | 
 |  |  |                     Map.Entry<String, Long> entry1 = longMap.entrySet().stream().min(Map.Entry.comparingByValue()).get();
 | 
 |  |  |                     param.setPortSite(entry1.getKey());
 | 
 |  |  |                 } else {
 | 
 |  |  |                     CacheSite cacheSite = cacheSiteService.getOne(new LambdaQueryWrapper<CacheSite>().last("limit 1"));
 | 
 |  |  |                     param.setPortSite(cacheSite.getChannel());
 | 
 |  |  |                 }
 | 
 |  |  |                 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
 | 
 |  |  |                         .getOne(new LambdaQueryWrapper<OperationPort>()
 | 
 |  |  |                                 .eq(OperationPort::getFlag, param.getPortSite()));
 | 
 |  |  |                 if (Objects.isNull(operationPort)) {
 | 
 |  |  |                     throw new CoolException("作业口不存在");
 | 
 |  |  |                 }
 | 
 |  |  |                 //101 全拖出库   103 拣货出库
 | 
 |  |  |                 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.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("明细扩展生成失败");
 | 
 |  |  |                         }
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  |                 //库位F => R
 | 
 |  |  |                 loc.setLocStsId(LocStsType.R.val());
 | 
 |  |  |                 loc.setUpdateTime(new Date());
 | 
 |  |  |                 boolean locUpdate = locService.updateById(loc);
 | 
 |  |  |                 if (!locUpdate) {
 | 
 |  |  |                     throw new CoolException("库位状态更新失败");
 | 
 |  |  |                 }
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  |     /**
 | 
 |  |  |      * @author Ryan
 | 
 |  |  |      * @date 2025/7/4
 | 
 |  |  |      * @description: 平库库存出库
 | 
 |  |  |      * @version 1.0
 | 
 |  |  |      */
 | 
 |  |  |     @Transactional(rollbackFor = Exception.class)
 | 
 |  |  |     public void outFlatStock(StockOutParam param) {
 | 
 |  |  |         //生成拣货单
 | 
 |  |  |         PickSheet pickSheet = new PickSheet();
 | 
 |  |  |         //波次数量汇总
 | 
 |  |  |         Double sum = param.getLocDetls().stream().mapToDouble(LocDetl::getAnfme).sum();
 | 
 |  |  |         //生成拣货单号
 | 
 |  |  |         String pickNo = generatePickNO();
 | 
 |  |  |         pickSheet.setId(null)
 | 
 |  |  |                 .setPickNo(pickNo)
 | 
 |  |  |                 .setMemo("库存出库")
 | 
 |  |  |                 .setAnfme(sum)
 | 
 |  |  |                 .setType(2);
 | 
 |  |  | 
 | 
 |  |  |         if (!pickSheetService.save(pickSheet)) {
 | 
 |  |  |             throw new CoolException("拣货单写入失败!!");
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         for (LocDetl locDetl : param.getLocDetls()) {
 | 
 |  |  |             List<OrderOutMergeParam> orders = new ArrayList<>();
 | 
 |  |  |             LocDetl detl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>()
 | 
 |  |  |                     .eq(LocDetl::getMatId, locDetl.getMatId())
 | 
 |  |  |                     .eq(LocDetl::getBatch, locDetl.getBatch())
 | 
 |  |  |                     .eq(LocDetl::getLocNo, locDetl.getLocNo()));
 | 
 |  |  |             if (Objects.isNull(detl)) {
 | 
 |  |  |                 continue;
 | 
 |  |  |             }
 | 
 |  |  |             OrderOutMergeParam outMergeParam = new OrderOutMergeParam();
 | 
 |  |  |             outMergeParam.setAnfme(locDetl.getAnfme())
 | 
 |  |  |                     .setLocNo(locDetl.getLocNo())
 | 
 |  |  |                     .setLocId(detl.getLocId())
 | 
 |  |  |                     .setLocDetlId(detl.getId())
 | 
 |  |  |                     .setMatnr(locDetl.getMatnr())
 | 
 |  |  |                     .setBatch(detl.getBatch());
 | 
 |  |  |             orders.add(outMergeParam);
 | 
 |  |  | 
 | 
 |  |  |             //根据库位ID分组
 | 
 |  |  |             Map<Long, List<OrderOutMergeParam>> listMap = orders.stream().collect(Collectors.groupingBy(OrderOutMergeParam::getLocId));
 | 
 |  |  |             //生成拣货单明细
 | 
 |  |  |             genPickSheet(listMap, pickSheet);
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  | }
 |