| | |
| | | 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.AsnOrder; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrderItem; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrderItemLog; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrderLog; |
| | | 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.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.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | public class OutStockServiceImpl extends ServiceImpl<AsnOrderMapper, AsnOrder> implements OutStockService { |
| | | |
| | | @Autowired |
| | | private ReceiveMsgService receiveMsgService; |
| | | @Autowired |
| | | private ReportMsgService reportMsgService; |
| | | @Resource |
| | | private PurchaseMapper purchaseMapper; |
| | | @Autowired |
| | | private AsnOrderItemService asnOrderItemService; |
| | | @Autowired |
| | | private AsnOrderLogService asnOrderLogService; |
| | | @Autowired |
| | | private AsnOrderItemLogService asnOrderItemLogService; |
| | | @Resource |
| | | private SerialRuleMapper serialRuleMapper; |
| | | @Autowired |
| | | private DeliveryItemService deliveryItemService; |
| | | @Autowired |
| | | private DeliveryService deliveryService; |
| | | @Autowired |
| | | private MatnrService matnrService; |
| | | @Autowired |
| | | private WaveService waveService; |
| | | @Autowired |
| | | private WaveItemService waveItemService; |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 更新或保存明细 |
| | | * @param |
| | | * @return |
| | | * @author Ryan |
| | | * @description 更新或保存明细 |
| | | * @time 2025/4/7 13:28 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | private void svaeOrUpdateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception{ |
| | | private void svaeOrUpdateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception { |
| | | AsnOrder orders = params.getOrders(); |
| | | |
| | | params.getItems().forEach(item -> { |
| | |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 删除原主单及明细,加入历史档 |
| | | * @param |
| | | * @return |
| | | * @author Ryan |
| | | * @description 删除原主单及明细,加入历史档 |
| | | * @time 2025/3/19 19:53 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | private void operateOrderLogs(AsnOrder asrder) throws Exception{ |
| | | private void operateOrderLogs(AsnOrder asrder) throws Exception { |
| | | if (Objects.isNull(asrder) || Objects.isNull(asrder.getId())) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 取消出库单据 |
| | | * @param |
| | | * @return |
| | | * @author Ryan |
| | | * @description 取消出库单据 |
| | | * @time 2025/4/22 10:40 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R cancelOutOrder(String id) { |
| | | //TODO 出库单取消流程,QMS(单据取消)->DO单->出库单->波次->判断是否全单据->全单据下发取消任务至WCS,非全单数据取消删除流程所有关联数据 |
| | | if (Cools.isEmpty(id)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | if (!order.getExceStatus().equals(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val)) { |
| | | throw new CoolException("当前单据状态为:" + AsnExceStatus.getExceStatus(order.getExceStatus()) + ", 不可执行取消操作!!"); |
| | | throw new CoolException("当前单据状态为" + AsnExceStatus.getExceStatus(order.getExceStatus()) + ", 不可执行取消操作!!"); |
| | | } |
| | | order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_CANCEL.val).setStatus(0); |
| | | |
| | |
| | | } |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @return |
| | | * @author Ryan |
| | | * @description 通过DO单生成出库单 |
| | | * @time 2025/4/23 16:24 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R genOutStock(List<Long> ids) { |
| | | if (Objects.isNull(ids) || ids.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | List<DeliveryItem> items = deliveryItemService.list(new LambdaQueryWrapper<DeliveryItem>().in(DeliveryItem::getId, ids)); |
| | | if (items.isEmpty()) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | Map<Long, List<DeliveryItem>> listMap = items.stream().collect(Collectors.groupingBy(DeliveryItem::getDeliveryId)); |
| | | listMap.keySet().forEach(key -> { |
| | | //TODO 判断单据是否已经存在,如存在则累加修改子表,不存在才新建 |
| | | Delivery delivery = deliveryService.getById(key); |
| | | if (Objects.isNull(delivery)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | AsnOrder order = new AsnOrder(); |
| | | BeanUtils.copyProperties(delivery, order); |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_OUT_STOCK_CODE, order); |
| | | if (Objects.isNull(ruleCode) || StringUtils.isBlank(ruleCode)) { |
| | | throw new CoolException("编码规则错误:请检查 「SYS_OUT_STOCK_CODE」编码是否设置成功"); |
| | | } |
| | | order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val) |
| | | .setCode(ruleCode) |
| | | .setPoId(delivery.getId()) |
| | | .setId(null) |
| | | .setPoCode(delivery.getCode()); |
| | | if (!this.save(order)) { |
| | | throw new CoolException("主单保存失败!!"); |
| | | } |
| | | List<AsnOrderItem> orderItems = new ArrayList<>(); |
| | | listMap.get(key).forEach(item -> { |
| | | AsnOrderItem orderItem = new AsnOrderItem(); |
| | | BeanUtils.copyProperties(item, orderItem); |
| | | orderItem.setId(null) |
| | | .setPoCode(order.getPoCode()) |
| | | .setAsnId(order.getId()) |
| | | .setAsnCode(order.getCode()) |
| | | .setPlatItemId(item.getPlatItemId()) |
| | | .setPoDetlId(item.getId()); |
| | | orderItems.add(orderItem); |
| | | }); |
| | | |
| | | double sum = orderItems.stream().mapToDouble(AsnOrderItem::getAnfme).sum(); |
| | | //修改计划数量 |
| | | order.setAnfme(sum); |
| | | if (!this.saveOrUpdate(order)) { |
| | | throw new CoolException("主单数量修改失败!!"); |
| | | } |
| | | if (!asnOrderItemService.saveBatch(orderItems)) { |
| | | 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(List<Long> ids) { |
| | | if (Objects.isNull(ids) || ids.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | List<AsnOrder> orders = this.listByIds(ids); |
| | | 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<WaveItem> items = new ArrayList<>(); |
| | | List<AsnOrderItem> orderItems = asnOrderItemService |
| | | .list(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .in(AsnOrderItem::getAsnId, list)); |
| | | |
| | | |
| | | for (AsnOrderItem item : orderItems) { |
| | | WaveItem waveItem = new WaveItem(); |
| | | BeanUtils.copyProperties(item, waveItem); |
| | | waveItem.setWaveId(wave.getId()) |
| | | .setWaveCode(wave.getCode()) |
| | | .setOrderId(item.getAsnId()) |
| | | .setOrderCode(item.getAsnCode()) |
| | | .setOrderItemId(item.getId()); |
| | | items.add(waveItem); |
| | | } |
| | | if (!waveItemService.saveBatch(items)) { |
| | | throw new CoolException("波次明细保存失败!!"); |
| | | } |
| | | return R.ok("操作完成!!"); |
| | | } |
| | | } |