| | |
| | | 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.mapper.AsnOrderMapper; |
| | | import com.vincent.rsf.server.manager.mapper.PurchaseMapper; |
| | |
| | | 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; |
| | | |
| | | |
| | | |
| | | /** |
| | | * @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 |
| | |
| | | } |
| | | 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(); |
| | | } |
| | | } |