package com.vincent.rsf.server.manager.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.vincent.rsf.framework.common.Cools; import com.vincent.rsf.framework.common.R; import com.vincent.rsf.framework.exception.CoolException; import com.vincent.rsf.server.api.utils.LocUtils; import com.vincent.rsf.server.common.constant.Constants; import com.vincent.rsf.server.manager.controller.dto.ExistDto; import com.vincent.rsf.server.manager.controller.dto.OrderOutItemDto; import com.vincent.rsf.server.manager.controller.params.*; import com.vincent.rsf.server.manager.enums.*; import com.vincent.rsf.server.manager.entity.*; import com.vincent.rsf.server.manager.mapper.AsnOrderMapper; import com.vincent.rsf.server.manager.service.*; import com.vincent.rsf.server.manager.utils.LocManageUtil; import com.vincent.rsf.server.manager.utils.OptimalAlgorithmUtil; import com.vincent.rsf.server.system.constant.SerialRuleCode; import com.vincent.rsf.server.system.utils.SerialRuleUtils; import org.apache.commons.lang3.StringUtils; 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.util.*; import java.util.stream.Collectors; import com.vincent.rsf.server.manager.enums.WaveRuleType; /** * @author Ryan * @description * @throws * @return * @time 2025/3/7 08:02 */ @Service("outStockServiceImpl") public class OutStockServiceImpl extends ServiceImpl implements OutStockService { public Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private AsnOrderItemService asnOrderItemService; @Autowired private AsnOrderLogService asnOrderLogService; @Autowired private AsnOrderItemLogService asnOrderItemLogService; @Autowired private DeliveryItemService deliveryItemService; @Autowired private DeliveryService deliveryService; @Autowired private MatnrService matnrService; @Autowired private WaveService waveService; @Autowired private WaveItemService waveItemService; @Autowired private OutStockItemService outStockItemService; @Autowired private OutStockService outStockService; @Autowired private WaveRuleService waveRuleService; @Autowired private LocItemService locItemService; @Autowired private DeviceSiteService deviceSiteService; @Autowired private LocService locService; @Autowired private WaveOrderRelaServiceImpl waveOrderRelaService; /** * @param * @return * @author Ryan * @description 更新或保存明细 * @time 2025/4/7 13:28 */ @Transactional(rollbackFor = Exception.class) public void svaeOrUpdateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception { WkOrder orders = params.getOrders(); params.getItems().forEach(item -> { item.put("orderId", orders.getId()); item.put("orderCode", orders.getCode()); item.put("poCode", orders.getPoCode()); item.put("createBy", loginUserId); item.put("updateBy", loginUserId); if (!asnOrderItemService.fieldsSave(item, loginUserId)) { throw new CoolException("明细保存失败!!"); } }); List orderItems = asnOrderItemService.list(new LambdaQueryWrapper() .eq(WkOrderItem::getOrderId, params.getOrders().getId())); Double sum = orderItems.stream().mapToDouble(WkOrderItem::getAnfme).sum(); orders.setAnfme(sum); if (!this.updateById(orders)) { throw new CoolException("计划收货数量修改失败!!"); } } /** * @param * @return * @author Ryan * @description 取消出库单据 * @time 2025/4/22 10:40 */ @Override @Transactional(rollbackFor = Exception.class) public R cancelOutOrder(String id) { if (Cools.isEmpty(id)) { throw new CoolException("参数不能为空!!"); } WkOrder order = this.getById(id); if (Objects.isNull(order)) { throw new CoolException("单据不存在!!"); } if (!order.getExceStatus().equals(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)) { throw new CoolException("当前单据状态为" + AsnExceStatus.getExceStatus(order.getExceStatus()) + ", 不可执行取消操作!!"); } List orderItems = outStockItemService.list(new LambdaQueryWrapper().eq(WkOrderItem::getOrderId, id)); if (!orderItems.isEmpty()) { for (WkOrderItem orderItem : orderItems) { if (!Objects.isNull(orderItem.getPoDetlId())) { DeliveryItem deliveryItem = deliveryItemService.getById(orderItem.getPoDetlId()); Double workQty = Math.round((deliveryItem.getWorkQty() - orderItem.getAnfme()) * 10000) / 10000.0; deliveryItem.setWorkQty(workQty.compareTo(0.0) >= 0 ? workQty : 0); if (!deliveryItemService.updateById(deliveryItem)) { throw new CoolException("DO单明细更新失败!!"); } Delivery delivery = deliveryService.getOne(new LambdaQueryWrapper().eq(Delivery::getCode, orderItem.getPoCode())); if (!Objects.isNull(delivery)) { Double wkQty = Math.round((delivery.getWorkQty() - delivery.getAnfme()) * 10000) / 10000.0; delivery.setWorkQty(wkQty.compareTo(0.0) >= 0 ? wkQty : 0).setExceStatus(POExceStatus.PO_EXCE_STATUS_UN_EXCE.val); if (!deliveryService.updateById(delivery)) { throw new CoolException("DO单据修改失败!!"); } } } } } if (!this.remove(new LambdaQueryWrapper().eq(WkOrder::getId, id))) { throw new CoolException("主单删除失败!!"); } if (!outStockItemService.remove(new LambdaQueryWrapper().eq(WkOrderItem::getOrderId, id))) { throw new CoolException("单据明细删除失败!!"); } return R.ok("操作成功"); } /** * @param * @param loginUserId * @return * @author Ryan * @description 通过DO单生成出库单 * @time 2025/4/23 16:24 */ @Override @Transactional(rollbackFor = Exception.class) public R genOutStock(List items, Long loginUserId) { if (items.isEmpty()) { throw new CoolException("参数不能为空!!"); } Map> listMap = items.stream().collect(Collectors.groupingBy(DeliveryItem::getDeliveryId)); listMap.keySet().forEach(key -> { Delivery delivery = deliveryService.getById(key); if (Objects.isNull(delivery)) { throw new CoolException("单据不存在!!"); } WkOrder order = new WkOrder(); BeanUtils.copyProperties(delivery, order); String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_OUT_STOCK_CODE, order); if (StringUtils.isBlank(ruleCode)) { throw new CoolException("编码规则错误:请检查 「SYS_OUT_STOCK_CODE」编码是否设置成功"); } order.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val) .setType(delivery.getType()) .setWkType(delivery.getWkType()) .setCode(ruleCode) .setPoId(delivery.getId()) .setId(null) .setUpdateBy(loginUserId) .setCreateBy(loginUserId) .setCreateTime(new Date()) .setUpdateTime(new Date()) .setPoCode(delivery.getCode()); if (!this.save(order)) { throw new CoolException("主单保存失败!!"); } List orderItems = new ArrayList<>(); listMap.get(key).forEach(item -> { DeliveryItem deliveryItem = deliveryItemService.getById(item.getId()); WkOrderItem orderItem = new WkOrderItem(); if (item.getAnfme().compareTo(0.0) <= 0) { throw new CoolException("出库数量不能小于或等于零!!"); } Double anfme = Math.round((deliveryItem.getAnfme() - item.getAnfme()) * 10000) / 10000.0; if (anfme.compareTo(0.0) < 0) { throw new CoolException("出库数量不足!!"); } BeanUtils.copyProperties(item, orderItem); orderItem.setId(null) .setPoCode(order.getPoCode()) .setMaktx(item.getMaktx()) .setMatnrCode(item.getMatnrCode()) .setFieldsIndex(item.getFieldsIndex()) .setAnfme(item.getAnfme()) .setWorkQty(0.0) .setOrderId(order.getId()) .setOrderCode(order.getCode()) .setStockUnit(item.getUnit()) .setPurUnit(item.getUnit()) .setPlatWorkCode(item.getPlatWorkCode()) .setPlatOrderCode(item.getPlatOrderCode()) .setProjectCode(item.getProjectCode()) .setPlatItemId(item.getPlatItemId()) .setUpdateBy(loginUserId) .setCreateBy(loginUserId) .setPoDetlId(item.getId()); orderItems.add(orderItem); if (!deliveryItemService.update(new LambdaUpdateWrapper() .set(DeliveryItem::getWorkQty, item.getAnfme()) .eq(DeliveryItem::getId, item.getId()))) { throw new CoolException("DO单明细修改失败!!"); } }); Double sum = orderItems.stream().mapToDouble(WkOrderItem::getAnfme).sum(); //修改计划数量 order.setAnfme(sum).setWorkQty(0.0); if (!this.saveOrUpdate(order)) { throw new CoolException("主单数量修改失败!!"); } if (!asnOrderItemService.saveBatch(orderItems)) { throw new CoolException("明细保存失败!!"); } Short exceStatus = POExceStatus.PO_EXCE_STATUS_SECTION_DONE.val; if (delivery.getAnfme().compareTo(order.getAnfme()) <= 0) { exceStatus = AsnExceStatus.ASN_EXCE_STATUS_TASK_DONE.val; } Double wkQty = Math.round((delivery.getWorkQty() + sum) * 10000) / 10000.0; if (!deliveryService.update(new LambdaUpdateWrapper() .set(Delivery::getExceStatus, exceStatus) .set(Delivery::getWorkQty, wkQty) .eq(Delivery::getId, key))) { throw new CoolException("主单修改失败!!"); } }); return R.ok(); } /** * @param * @return * @author Ryan * @description 生成波次 * @time 2025/4/24 15:04 */ @Override @Transactional(rollbackFor = Exception.class) public R generateWaves(GenWaveParams params) { if (Objects.isNull(params.getIds()) || params.getIds().isEmpty()) { throw new CoolException("参数不能为空!!"); } List orders = this.list(new LambdaQueryWrapper() .eq(WkOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val) .in(WkOrder::getId, params.getIds())); if (orders.isEmpty()) { throw new CoolException("当前单据状态不能执行波次生成操作!!"); } Double sum = orders.stream().mapToDouble(WkOrder::getAnfme).sum(); Double workQty = orders.stream().mapToDouble(WkOrder::getWorkQty).sum(); Double anfme = Math.round((sum - workQty) * 10000) / 10000.0; Wave wave = new Wave(); String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_WAVE_TYPE, null); if (StringUtils.isBlank(ruleCode)) { throw new CoolException("编码规则错误:请要查看「SYS_WAVE_TYPE」是否设置成功!!"); } wave.setOrderNum(params.getIds().size()) .setType(Short.parseShort("1")) .setCode(ruleCode) .setExceStatus(WaveExceStatus.WAVE_EXCE_STATUS_INIT.val) .setAnfme(anfme); if (!waveService.save(wave)) { throw new CoolException("波次保存失败!!"); } List list = orders.stream().map(WkOrder::getId).collect(Collectors.toList()); List orderItems = asnOrderItemService .list(new LambdaQueryWrapper() .in(WkOrderItem::getOrderId, list).apply("anfme > work_qty")); if (orderItems.isEmpty()) { throw new CoolException("单据不存在!!"); } //合并物料,生成波次明细 List waveItems = mergeWave(orderItems, wave); if (!waveItemService.saveBatch(waveItems)) { throw new CoolException("波次明细保存失败!!"); } double sum1 = waveItems.stream().mapToDouble(WaveItem::getAnfme).sum(); wave.setAnfme(sum1).setGroupQty(waveItems.size()); if (!waveService.saveOrUpdate(wave)) { throw new CoolException("主单修改失败!!"); } for (int i = 0; i < orderItems.size(); i++) { orderItems.get(i).setWorkQty(orderItems.get(i).getAnfme()); } /** *订单信息存储至逻辑关联表 */ for (WaveItem item : waveItems) { List items = orderItems.stream() .filter(orderItem -> item.getMatnrId() .equals(orderItem.getMatnrId())) .collect(Collectors.toList()); items.forEach(orderItem -> { WaveOrderRela orderRela = new WaveOrderRela(); orderRela.setId(null) .setOrderId(orderItem.getOrderId()) .setOrderItemId(orderItem.getId()) .setWaveId(wave.getId()) .setWaveItemId(item.getId()); if (!waveOrderRelaService.saveOrUpdate(orderRela)) { throw new CoolException(""); } }); } if (!asnOrderItemService.saveOrUpdateBatch(orderItems)) { throw new CoolException("出库单执行数量修改失败!!"); } for (WkOrder order : orders) { Double wkQty = Math.round((order.getWorkQty() + order.getAnfme()) * 10000) / 10000.0; if (!this.update(new LambdaUpdateWrapper() .set(WkOrder::getWaveId, wave.getId()) .set(WkOrder::getWorkQty, wkQty) .set(WkOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_WAVE.val) .eq(WkOrder::getId, order.getId()))) { throw new CoolException("执行状态修改修改失败!!"); } } return R.ok("操作完成!!"); } /** * @param * @return * @author Ryan * @description 保存出库主单及明细 * @time 2025/4/29 13:47 */ @Override @Transactional(rollbackFor = Exception.class) public R saveOutStock(AsnOrderAndItemsParams params, Long loginUserId) { if (Objects.isNull(params.getOrders())) { throw new CoolException("主单信息不能为空"); } WkOrder orders = params.getOrders(); if (StringUtils.isBlank(orders.getWkType())) { throw new CoolException("业务类型不能为空!!"); } String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_OUT_STOCK_CODE, orders); if (StringUtils.isBlank(ruleCode)) { throw new CoolException("编码规则错误:请检查「SYS_OUT_STOCK_CODE」是否设置正确!!"); } orders.setCode(ruleCode) .setType(OrderType.ORDER_OUT.type) .setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val) .setUpdateBy(loginUserId) .setCreateBy(loginUserId); if (!this.save(orders)) { throw new CoolException("主单保存失败!!"); } if (params.getItems().isEmpty()) { throw new CoolException("收货通知单明细不能为空!!"); } params.setOrders(orders); try { svaeOrUpdateOrderItem(params, loginUserId); } catch (Exception e) { throw new CoolException(e.getMessage()); } return R.ok(); } /** * @param * @return * @author Ryan * @description 修改主单及明细 * @time 2025/4/29 13:47 */ @Override public R updateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) { WkOrder orders = params.getOrders(); if (Objects.isNull(orders)) { throw new CoolException("主单信息不能为空!!"); } if (Objects.isNull(orders.getId())) { throw new CoolException("数据错误:单据ID不能为空!!"); } if (!this.updateById(orders)) { throw new CoolException("主单修改失败!!"); } if (Objects.isNull(params.getItems()) || params.getItems().isEmpty()) { throw new CoolException("明细参数不能为空!!"); } try { svaeOrUpdateOrderItem(params, loginUserId); } catch (Exception e) { throw new CoolException(e.getMessage()); } return R.ok(); } @Override public R getOrderOutTaskItem(OrderOutTaskParam param) { if (Cools.isEmpty(param.getWaveId())) { throw new CoolException("策略参数为空"); } if (Cools.isEmpty(param.getOrderId())) { throw new CoolException("单据ID为空"); } WaveRule waveRule = waveRuleService.getOne(new LambdaQueryWrapper() .eq(WaveRule::getId, param.getWaveId())); if (Cools.isEmpty(waveRule)) { throw new CoolException("未找到当前策略"); } List locItems = null; locItems = getOutOrderList(param.getOrderId(), waveRule); return R.ok(locItems); } /** * 生成出库任务 * * @param params * @param outId * @return */ @Override @Transactional(rollbackFor = Exception.class) public R genOutStockTask(List params, Long loginUserId, Long outId) { if (params.isEmpty()) { throw new CoolException("参数不能为空!!"); } //优先生成浅库位任务 List Items = params.stream() .sorted(Comparator.comparing(OutStockToTaskParams::getLocCode) .thenComparing(item -> { return LocUtils.isShallowLoc(item.getLocCode()) ? 1 : 0; }).reversed()).collect(Collectors.toList()); for (OutStockToTaskParams param : Items) { if (Objects.isNull(param) || StringUtils.isBlank(param.getLocCode())) { continue; } Loc loc = locService.getOne(new LambdaQueryWrapper().eq(Loc::getCode, param.getLocCode()).eq(Loc::getBarcode, param.getBarcode())); if (!Objects.isNull(loc)) { List locItems = new ArrayList<>(); LocItem locItem = locItemService.getById(param.getId()); WkOrderItem orderItem = outStockItemService.getOne(new LambdaQueryWrapper() .eq(WkOrderItem::getOrderId, outId) .eq(StringUtils.isNotBlank(locItem.getBatch()), WkOrderItem::getSplrBatch, locItem.getBatch()) .eq(StringUtils.isNotBlank(locItem.getFieldsIndex()), WkOrderItem::getFieldsIndex, locItem.getFieldsIndex()) .eq(WkOrderItem::getMatnrId, locItem.getMatnrId())); if (Objects.isNull(orderItem)) { throw new CoolException("单据明细不存在!!"); } locItem.setOutQty(param.getOutQty()) .setBatch(param.getBatch()) .setSourceId(outId) .setSourceCode(orderItem.getOrderCode()) .setSource(orderItem.getId()); locItems.add(locItem); LocToTaskParams taskParams = new LocToTaskParams(); taskParams.setType(Constants.TASK_TYPE_ORDER_OUT_STOCK) .setOrgLoc(loc.getCode()) .setItems(locItems) .setSourceId(outId) .setSiteNo(param.getSiteNo()); try { //生成出库任务 locItemService.generateTask(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val, taskParams, loginUserId); } catch (Exception e) { logger.error("UNK", e); throw new CoolException(e.getMessage()); } Double workQty = Math.round((orderItem.getWorkQty() + locItem.getOutQty()) * 10000) / 10000.0; orderItem.setUpdateBy(loginUserId).setUpdateTime(new Date()).setWorkQty(workQty); if (!outStockItemService.updateById(orderItem)) { throw new CoolException("单据明细修改失败!!"); } } } Double sum = Items.stream().mapToDouble(OutStockToTaskParams::getOutQty).sum(); //更新出库单明细及主单 WkOrder outOrder = outStockService.getById(outId); if (Objects.isNull(outOrder)) { throw new CoolException("出库单据不存在!!"); } Double workQty = Math.round((outOrder.getWorkQty() + sum) * 10000) / 10000.0; outOrder.setWorkQty(workQty).setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_CREATE.val); if (!outStockService.updateById(outOrder)) { throw new CoolException("出库单状态修改失败!!"); } return R.ok(); } /** * 获取出库站点 * * @return */ @Override public R getSiteNos() { List list = Arrays.asList(TaskType.TASK_TYPE_MERGE_OUT.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type, TaskType.TASK_TYPE_PICK_AGAIN_OUT.type); List sites = deviceSiteService.list(new LambdaQueryWrapper().in(DeviceSite::getType, list).groupBy(DeviceSite::getSite)); return R.ok(sites); } @Override @Transactional(rollbackFor = Exception.class) public R cancelOutOrderByItems(List orderItems) { Map> listMap = orderItems.stream().collect(Collectors.groupingBy(WkOrderItem::getOrderId)); for (Long key : listMap.keySet()) { WkOrder order = this.getById(key); if (Objects.isNull(order)) { throw new CoolException("单据不存在!!"); } List items = listMap.get(key); if (!items.isEmpty()) { for (WkOrderItem orderItem : items) { DeliveryItem deliveryItem = deliveryItemService.getById(orderItem.getPoDetlId()); Double workQty = Math.round((deliveryItem.getWorkQty() - orderItem.getAnfme()) * 10000) / 10000.0; deliveryItem.setWorkQty(workQty.compareTo(0.0) >= 0 ? workQty : 0); if (!deliveryItemService.updateById(deliveryItem)) { throw new CoolException("DO单明细更新失败!!"); } Delivery delivery = deliveryService.getOne(new LambdaQueryWrapper().eq(Delivery::getCode, orderItem.getPoCode())); if (!Objects.isNull(delivery)) { Double wkQty = Math.round((delivery.getWorkQty() - delivery.getAnfme()) * 10000) / 10000.0; delivery.setWorkQty(wkQty.compareTo(0.0) >= 0 ? wkQty : 0).setExceStatus(POExceStatus.PO_EXCE_STATUS_UN_EXCE.val); if (!deliveryService.updateById(delivery)) { throw new CoolException("DO单据修改失败!!"); } } } } if (!this.remove(new LambdaQueryWrapper().eq(WkOrder::getId, key))) { throw new CoolException("主单删除失败!!"); } if (!outStockItemService.remove(new LambdaQueryWrapper() .eq(WkOrderItem::getOrderId, key))) { throw new CoolException("单据明细删除失败!!"); } } return R.ok("操作成功"); } private List getOutOrderList(Long orderId, WaveRule waveRule) { List wkOrderItems = asnOrderItemService.list(new LambdaQueryWrapper() .eq(WkOrderItem::getOrderId, orderId)); List list = new ArrayList<>(); Set existDtos = new HashSet<>(); for (WkOrderItem wkOrderItem : wkOrderItems) { BigDecimal issued = new BigDecimal(wkOrderItem.getAnfme().toString()) .subtract(new BigDecimal(wkOrderItem.getWorkQty().toString()) ); if (issued.doubleValue() <= 0) { continue; } List locItems = new ArrayList<>(); if (WaveRuleType.Efficiency_First.type.equals(waveRule.getType())) { locItems = LocManageUtil.getEfficiencyFirstItemList(wkOrderItem.getMatnrCode(), wkOrderItem.getSplrBatch(), wkOrderItem.getAnfme()); } else if (WaveRuleType.First_In_First_Out.type.equals(waveRule.getType())) { locItems = LocManageUtil.getFirstInFirstOutItemList(wkOrderItem.getMatnrCode(), wkOrderItem.getSplrBatch(), wkOrderItem.getAnfme()); } else { locItems = LocManageUtil.getFirstInFirstOutItemList(wkOrderItem.getMatnrCode(), wkOrderItem.getSplrBatch(), wkOrderItem.getAnfme()); } for (LocItem locItem : locItems) { Loc loc = locService.getById(locItem.getLocId()); List itemList = locItemService.list(new LambdaQueryWrapper().eq(LocItem::getLocCode, locItem.getLocCode())); if (issued.doubleValue() > 0) { ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode()); if (existDtos.add(existDto)) { locItem.setOutQty(issued.doubleValue() >= locItem.getAnfme() ? locItem.getAnfme() : issued.doubleValue()); locItem.setBarcode(loc.getBarcode()); OrderOutItemDto orderOutItemDto = new OrderOutItemDto(); orderOutItemDto.setLocItem(locItem); List deviceSites = deviceSiteService.list(new LambdaQueryWrapper() .eq(DeviceSite::getChannel, loc.getChannel()) .eq(DeviceSite::getType, issued.doubleValue() >= locItem.getAnfme() && itemList.size() == 1 ? TaskType.TASK_TYPE_OUT.type : TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) ); if (!deviceSites.isEmpty()) { List maps = new ArrayList<>(); for (DeviceSite sta : deviceSites) { OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto(); staListDto.setStaNo(sta.getSite()); staListDto.setStaName(sta.getSite()); maps.add(staListDto); } orderOutItemDto.setStaNos(maps); //默认获取第一站点 DeviceSite deviceSite = deviceSites.stream().findFirst().get(); orderOutItemDto.setSiteNo(deviceSite.getSite()); } list.add(orderOutItemDto); issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString())); } } } if (issued.doubleValue() > 0) { LocItem locItem = new LocItem() .setId(new Random().nextLong()) .setMatnrCode(wkOrderItem.getMatnrCode()) .setMaktx(wkOrderItem.getMaktx()) .setAnfme(0.00) .setWorkQty(issued.doubleValue()) .setOutQty(issued.doubleValue()) .setUnit(wkOrderItem.getStockUnit()) .setBatch(wkOrderItem.getSplrBatch()); OrderOutItemDto orderOutItemDto = new OrderOutItemDto(); orderOutItemDto.setLocItem(locItem); list.add(orderOutItemDto); } } return list; } /** * @param * @param wave * @return * @author Ryan * @description 合并生成波次 * @time 2025/4/25 10:07 */ private List mergeWave(List orderItems, Wave wave) { List items = new ArrayList<>(); orderItems.forEach(order -> { Double anfme = Math.round((order.getAnfme() - order.getWorkQty()) * 10000) / 10000.0; WaveItem item = new WaveItem(); BeanUtils.copyProperties(order, item); item.setId(null) .setAnfme(anfme) .setMatnrId(order.getMatnrId()) .setMaktx(order.getMaktx()) .setWaveId(wave.getId()) .setWaveCode(wave.getCode()); items.add(item); }); List waveItems = OptimalAlgorithmUtil.groupAndMerge(items, (p1, p2) -> new WaveItem( p1.getWaveId(), p1.getWaveCode(), p1.getMatnrId(), p1.getMaktx(), p1.getMatnrCode(), p1.getBatch(), p1.getSplrBatch(), p1.getOrderCode(), p1.getOrderId(), p1.getOrderItemId(), p1.getUnit(), p1.getTrackCode(), p1.getFieldsIndex(), Math.round((p1.getAnfme() + p2.getAnfme()) * 10000) / 10000.0, p1.getWorkQty(), p1.getTenantId(), p1.getStatus(), p1.getDeleted(), p1.getCreateTime(), p1.getCreateBy(), p1.getUpdateTime(), p1.getUpdateBy(), p1.getMemo() ), WaveItem::getSplrBatch, WaveItem::getMatnrCode, WaveItem::getFieldsIndex ); return waveItems; } }