| | |
| | | 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.entity.dto.PoItemsDto; |
| | | import com.vincent.rsf.server.api.service.ReceiveMsgService; |
| | | import com.vincent.rsf.server.api.service.ReportMsgService; |
| | | import com.vincent.rsf.server.manager.controller.params.AsnOrderAndItemsParams; |
| | | import com.vincent.rsf.server.manager.controller.params.BatchUpdateParam; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.AsnExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.WaveExceStatus; |
| | | import com.vincent.rsf.server.manager.mapper.AsnOrderMapper; |
| | | import com.vincent.rsf.server.manager.mapper.PurchaseMapper; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.manager.utils.OptimalAlgorithmUtil; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.mapper.SerialRuleMapper; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | 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; |
| | | |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R cancelOutOrder(String id) { |
| | | //TODO 出库单取消流程,QMS(单据取消)->DO单->出库单->波次->判断是否全单据->全单据下发取消任务至WCS,非全单数据取消删除流程所有关联数据 |
| | | if (Cools.isEmpty(id)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | |
| | | if (Objects.isNull(ruleCode) || StringUtils.isBlank(ruleCode)) { |
| | | throw new CoolException("编码规则错误:请检查 「SYS_OUT_STOCK_CODE」编码是否设置成功"); |
| | | } |
| | | order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val) |
| | | order.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val) |
| | | .setCode(ruleCode) |
| | | .setPoId(delivery.getId()) |
| | | .setId(null) |
| | |
| | | BeanUtils.copyProperties(item, orderItem); |
| | | orderItem.setId(null) |
| | | .setPoCode(order.getPoCode()) |
| | | .setMaktx(item.getMaktx()) |
| | | .setMatnrCode(item.getMatnrCode()) |
| | | .setFieldsIndex(item.getFieldsIndex()) |
| | | .setAsnId(order.getId()) |
| | | .setAsnCode(order.getCode()) |
| | | .setPlatItemId(item.getPlatItemId()) |
| | |
| | | }); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @return |
| | | * @author Ryan |
| | | * @description 生成波次 |
| | | * @time 2025/4/24 15:04 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R generateWaves(List<Long> ids) { |
| | | if (Objects.isNull(ids) || ids.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | List<AsnOrder> orders = this.list(new LambdaQueryWrapper<AsnOrder>() |
| | | .in(AsnOrder::getId, ids) |
| | | .eq(AsnOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)); |
| | | if (orders.isEmpty()) { |
| | | throw new CoolException("当前单据状态不能执行波次生成操作!!"); |
| | | } |
| | | double sum = orders.stream().mapToDouble(AsnOrder::getAnfme).sum(); |
| | | Wave wave = new Wave(); |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_WAVE_TYPE, null); |
| | | if (Objects.isNull(ruleCode) || StringUtils.isBlank(ruleCode)) { |
| | | throw new CoolException("编码规则错误:请要查看「SYS_WAVE_TYPE」是否设置成功!!"); |
| | | } |
| | | wave.setOrderNum(ids.size()) |
| | | .setType(Short.parseShort("1")) |
| | | .setCode(ruleCode) |
| | | .setExceStatus(WaveExceStatus.WAVE_EXCE_STATUS_INIT.val) |
| | | .setAnfme(sum); |
| | | if (!waveService.save(wave)) { |
| | | throw new CoolException("波次保存失败!!"); |
| | | } |
| | | List<Long> list = orders.stream().map(AsnOrder::getId).collect(Collectors.toList()); |
| | | List<AsnOrderItem> orderItems = asnOrderItemService |
| | | .list(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .in(AsnOrderItem::getAsnId, list)); |
| | | if (orderItems.isEmpty()) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | |
| | | List<WaveItem> waveItems = mergeWave(orderItems, wave); |
| | | if (!waveItemService.saveBatch(waveItems)) { |
| | | throw new CoolException("波次明细保存失败!!"); |
| | | } |
| | | double sum1 = waveItems.stream().mapToDouble(WaveItem::getAnfme).sum(); |
| | | wave.setAnfme(sum1); |
| | | if (!waveService.saveOrUpdate(wave)) { |
| | | throw new CoolException("主单修改失败!!"); |
| | | } |
| | | |
| | | if (!this.update(new LambdaUpdateWrapper<AsnOrder>() |
| | | .set(AsnOrder::getWaveId, wave.getId()) |
| | | .set(AsnOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_WAVE.val) |
| | | .in(AsnOrder::getId, ids))) { |
| | | throw new CoolException("执行状态修改修改失败!!"); |
| | | } |
| | | return R.ok("操作完成!!"); |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @param wave |
| | | * @return |
| | | * @author Ryan |
| | | * @description 合并生成波次 |
| | | * @time 2025/4/25 10:07 |
| | | */ |
| | | private List<WaveItem> mergeWave(List<AsnOrderItem> orderItems, Wave wave) { |
| | | List<WaveItem> items = new ArrayList<>(); |
| | | orderItems.forEach(order -> { |
| | | WaveItem item = new WaveItem(); |
| | | BeanUtils.copyProperties(order, item); |
| | | item.setOrderItemId(order.getId()) |
| | | .setId(null) |
| | | .setOrderCode(order.getAsnCode()) |
| | | .setOrderId(order.getAsnId()) |
| | | .setMatnrId(order.getMatnrId()) |
| | | .setMaktx(order.getMaktx()) |
| | | .setWaveId(wave.getId()) |
| | | .setWaveCode(wave.getCode()); |
| | | items.add(item); |
| | | }); |
| | | List<WaveItem> 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(), |
| | | p1.getAnfme() + p2.getAnfme(), |
| | | 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; |
| | | } |
| | | } |