| | |
| | | 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.enums.OrderType; |
| | | import com.vincent.rsf.server.manager.enums.OrderType; |
| | | import com.vincent.rsf.server.manager.controller.params.AsnOrderAndItemsParams; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.AsnExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.POExceStatus; |
| | | import com.vincent.rsf.server.manager.enums.WaveExceStatus; |
| | | import com.vincent.rsf.server.manager.mapper.AsnOrderMapper; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | |
| | | private WaveService waveService; |
| | | @Autowired |
| | | private WaveItemService waveItemService; |
| | | @Autowired |
| | | private OutStockItemService outStockItemService; |
| | | @Autowired |
| | | private OutStockService outStockService; |
| | | |
| | | |
| | | /** |
| | |
| | | * @time 2025/4/7 13:28 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | private void svaeOrUpdateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception { |
| | | public void svaeOrUpdateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception { |
| | | AsnOrder orders = params.getOrders(); |
| | | params.getItems().forEach(item -> { |
| | | item.put("asnId", orders.getId()); |
| | |
| | | if (Objects.isNull(order)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | if (!order.getExceStatus().equals(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val)) { |
| | | if (!order.getExceStatus().equals(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)) { |
| | | throw new CoolException("当前单据状态为" + AsnExceStatus.getExceStatus(order.getExceStatus()) + ", 不可执行取消操作!!"); |
| | | } |
| | | order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_CANCEL.val).setStatus(0); |
| | | |
| | | if (!this.saveOrUpdate(order)) { |
| | | throw new CoolException("单据取消失败!!"); |
| | | List<AsnOrderItem> orderItems = outStockItemService.list(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, id)); |
| | | if (!orderItems.isEmpty()) { |
| | | for (AsnOrderItem 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单明细更新失败!!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!Objects.isNull(order.getPoId())) { |
| | | Delivery delivery = deliveryService.getById(order.getPoId()); |
| | | if (!Objects.isNull(delivery)) { |
| | | Double sum = orderItems.stream().mapToDouble(AsnOrderItem::getAnfme).sum(); |
| | | Double workQty = Math.round((delivery.getWorkQty() - sum) * 10000) / 10000.0; |
| | | delivery.setWorkQty(workQty.compareTo(0.0) >= 0 ? workQty : 0).setExceStatus(POExceStatus.PO_EXCE_STATUS_UN_EXCE.val); |
| | | if (!deliveryService.updateById(delivery)) { |
| | | throw new CoolException("DO单据修改失败!!"); |
| | | } |
| | | } |
| | | } |
| | | if (!this.remove(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getId, id))) { |
| | | throw new CoolException("主单删除失败!!"); |
| | | } |
| | | if (!outStockItemService.remove(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, id))) { |
| | | throw new CoolException("单据明细删除失败!!"); |
| | | } |
| | | // if (!this.saveOrUpdate(order)) { |
| | | // throw new CoolException("单据取消失败!!"); |
| | | // } |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @param loginUserId |
| | | * @return |
| | | * @author Ryan |
| | | * @description 通过DO单生成出库单 |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R genOutStock(List<Long> ids) { |
| | | public R genOutStock(List<Long> ids, Long loginUserId) { |
| | | if (Objects.isNull(ids) || ids.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | |
| | | 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) |
| | | .setPoCode(delivery.getCode()); |
| | | if (!this.save(order)) { |
| | | throw new CoolException("主单保存失败!!"); |
| | |
| | | .setFieldsIndex(item.getFieldsIndex()) |
| | | .setAsnId(order.getId()) |
| | | .setAsnCode(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<DeliveryItem>() |
| | | .set(DeliveryItem::getWorkQty, item.getAnfme()) |
| | | .eq(DeliveryItem::getId, item.getId()))) { |
| | | throw new CoolException("DO单明细修改失败!!"); |
| | | } |
| | | }); |
| | | |
| | | double sum = orderItems.stream().mapToDouble(AsnOrderItem::getAnfme).sum(); |
| | | Double sum = orderItems.stream().mapToDouble(AsnOrderItem::getAnfme).sum(); |
| | | //修改计划数量 |
| | | order.setAnfme(sum); |
| | | if (!this.saveOrUpdate(order)) { |
| | |
| | | if (!asnOrderItemService.saveBatch(orderItems)) { |
| | | throw new CoolException("明细保存失败!!"); |
| | | } |
| | | |
| | | if (!deliveryService.update(new LambdaUpdateWrapper<Delivery>() |
| | | .set(Delivery::getExceStatus, POExceStatus.PO_EXCE_STATUS_EXCE_ING.val) |
| | | .set(Delivery::getWorkQty, sum) |
| | | .eq(Delivery::getId, key))) { |
| | | throw new CoolException("主单修改失败!!"); |
| | | } |
| | | |
| | | }); |
| | | return R.ok(); |
| | | } |
| | |
| | | p1.getUnit(), |
| | | p1.getTrackCode(), |
| | | p1.getFieldsIndex(), |
| | | p1.getAnfme() + p2.getAnfme(), |
| | | Math.round((p1.getAnfme() + p2.getAnfme()) * 10000) / 10000.0, |
| | | p1.getWorkQty(), |
| | | p1.getTenantId(), |
| | | p1.getStatus(), |