|
@@ -98,6 +98,9 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private AccountService accountService;
|
|
private AccountService accountService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private InventoryMapper inventoryMapper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @desc : 条件查询
|
|
* @desc : 条件查询
|
|
|
* @date : 2024/3/7 14:12
|
|
* @date : 2024/3/7 14:12
|
|
@@ -1279,6 +1282,245 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
return ResponseResultUtil.success();
|
|
return ResponseResultUtil.success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /*****************************************查库存*****************************************/
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 校验库存是否存在和库存量是否足够本次退货作废
|
|
|
|
|
+ * @date : 2024/7/6 10:52
|
|
|
|
|
+ * @author : 寇珊珊
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(
|
|
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
|
|
+ )
|
|
|
|
|
+ public void checkInventoryExist(List<InboundItemResponse> inboundItemResponseList) {
|
|
|
|
|
+ for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
|
|
|
|
|
+ //存在标识
|
|
|
|
|
+ //根据sku,仓库,非标号查询
|
|
|
|
|
+ InventoryResponse inventoryResponse = null;
|
|
|
|
|
+ if (inboundItemResponse.getSkuId() != null) {
|
|
|
|
|
+ inventoryResponse = inventoryMapper.selectByOther(new InventoryQuery()
|
|
|
|
|
+ .setSkuId(inboundItemResponse.getSkuId())
|
|
|
|
|
+ .setWhId(inboundItemResponse.getWhId())
|
|
|
|
|
+ .setNonStdCode(inboundItemResponse.getNonStdCode()));
|
|
|
|
|
+ }
|
|
|
|
|
+ //库存不存在
|
|
|
|
|
+ if (inventoryResponse == null) {
|
|
|
|
|
+ //当前出库商品中在库存中不存在
|
|
|
|
|
+ throw new BaseBusinessException(ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getCode(),
|
|
|
|
|
+ ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ //判断库存中的数量是否足够本次采购退货作废(采购退货作废等于出库)
|
|
|
|
|
+ if (inventoryResponse.getInvQty().compareTo(inboundItemResponse.getIntoQty()) < 0) {
|
|
|
|
|
+ //当前库存数量不足,不允许采购退货作废操作
|
|
|
|
|
+ throw new BaseBusinessException(ErrorCodeEnum.INSUFFICIENT_INVENTORY_NOT_ALLOW_PURCHASE_RETURN.getCode(),
|
|
|
|
|
+ ErrorCodeEnum.INSUFFICIENT_INVENTORY_NOT_ALLOW_PURCHASE_RETURN.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ /*****************************************先判断库存*****************************************/
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 一键作废
|
|
|
|
|
+ * @date : 2024/7/6 11:03
|
|
|
|
|
+ * @author : 寇珊珊
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
|
|
+ public ResponseResultVO<?> oneKeyPurchaseInboundRepeal(String orderId) {
|
|
|
|
|
+ List<InboundItemResponse> InboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setFromId(orderId));
|
|
|
|
|
+ if (InboundItemResponses != null && InboundItemResponses.size() > 0) {
|
|
|
|
|
+ Map<String, List<InboundItemResponse>> inboundItemMap = InboundItemResponses.stream().collect(Collectors.groupingBy(InboundItemResponse::getIntoId));
|
|
|
|
|
+ for (String str : inboundItemMap.keySet()) {
|
|
|
|
|
+ //region 查询总单 查询明细
|
|
|
|
|
+ //根据id查询 此条入库单的数据还未更改前的数据
|
|
|
|
|
+ InboundResponse inboundResponse = inboundMapper.selectById(str);
|
|
|
|
|
+ //根据总单id查询
|
|
|
|
|
+ List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setOutId(inboundResponse.getIntoId()));
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 已入库状态作废
|
|
|
|
|
+ if (Constant.IntoStatus.YIRUKU.getName().equals(inboundResponse.getIntoStatus())) {
|
|
|
|
|
+
|
|
|
|
|
+ //region 查询当前订单下的入库单的库存是否足够允许作废
|
|
|
|
|
+ this.checkInventoryExist(inboundItemResponseList);
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 退账
|
|
|
|
|
+ if (inboundResponse.getReceivableId() != null) {
|
|
|
|
|
+ accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 修改明细
|
|
|
|
|
+ for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
|
|
|
|
|
+
|
|
|
|
|
+ //region 将库存需要的参数赋值
|
|
|
|
|
+ inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
|
|
|
|
|
+ inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
|
|
|
|
|
+ inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
|
|
|
|
|
+ inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 编辑明细 赋值 赋值明细 防止作废的单据查不到明细 故注掉下面代码
|
|
|
|
|
+// InboundItem inboundItem = new InboundItem();
|
|
|
|
|
+// inboundItem.setItemId(inboundItemResponse.getItemId());
|
|
|
|
|
+// inboundItem.setFlgValid(false);
|
|
|
|
|
+// //修改
|
|
|
|
|
+// inboundItemMapper.update(inboundItem,
|
|
|
|
|
+// new UpdateWrapper<InboundItem>().lambda()
|
|
|
|
|
+// .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
|
|
|
|
|
+// );
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 销售明细
|
|
|
|
|
+ if (inboundItemResponse.getFromItemId() != null) {
|
|
|
|
|
+ //根据id查询
|
|
|
|
|
+ PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
|
|
|
|
|
+ PurchaseItem purchaseItem = new PurchaseItem();
|
|
|
|
|
+ purchaseItem.setItemId(inboundItemResponse.getFromItemId());
|
|
|
|
|
+ purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
|
|
|
|
|
+ purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
|
|
|
|
|
+ //入库状态
|
|
|
|
|
+ String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty(),
|
|
|
|
|
+ purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
|
|
|
|
|
+ purchaseItem.setIntoStatus(intoStatus);
|
|
|
|
|
+ int countRow = purchaseItemMapper.updateById(purchaseItem);
|
|
|
|
|
+ //数量超出
|
|
|
|
|
+ if (countRow == 0) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 修改入库总单
|
|
|
|
|
+ Inbound inbound = new Inbound();
|
|
|
|
|
+ inbound.setIntoId(inboundResponse.getIntoId());
|
|
|
|
|
+ inbound.setFlgValid(false);
|
|
|
|
|
+ //修改
|
|
|
|
|
+ inboundMapper.update(inbound,
|
|
|
|
|
+ new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
|
|
|
|
|
+ );
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 修改销售总单
|
|
|
|
|
+ if (inboundResponse.getFromId() != null) {
|
|
|
|
|
+ //根据id查询
|
|
|
|
|
+ PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
|
|
|
|
|
+ Purchase purchase = new Purchase();
|
|
|
|
|
+ purchase.setPurId(inboundResponse.getFromId());
|
|
|
|
|
+ purchase.setIntoQty(inboundResponse.getIntoQty().negate());
|
|
|
|
|
+ purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
|
|
|
|
|
+ //入库状态
|
|
|
|
|
+ String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty(),
|
|
|
|
|
+ purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
|
|
|
|
|
+ purchase.setIntoStatus(intoStatus);
|
|
|
|
|
+ //修改
|
|
|
|
|
+ int countRow = purchaseMapper.updateById(purchase);
|
|
|
|
|
+ //数量超出
|
|
|
|
|
+ if (countRow == 0) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 入账
|
|
|
|
|
+ if (inboundResponse.getReceivableId() != null) {
|
|
|
|
|
+ accountService.accPayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 调用库存
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("delIntoDetail", inboundItemResponseList);
|
|
|
|
|
+ inventoryService.operatingInventoryInformation(map);
|
|
|
|
|
+ //endregion
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 出库中、待出库状态作废
|
|
|
|
|
+ if (Constant.IntoStatus.DAIRUKU.getName().equals(inboundResponse.getIntoStatus()) ||
|
|
|
|
|
+ Constant.IntoStatus.RUKUZHONG.getName().equals(inboundResponse.getIntoStatus())) {
|
|
|
|
|
+
|
|
|
|
|
+ //region 修改明细
|
|
|
|
|
+ for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
|
|
|
|
|
+ //region 编辑明细 赋值
|
|
|
|
|
+ InboundItem inboundItem = new InboundItem();
|
|
|
|
|
+ inboundItem.setItemId(inboundItemResponse.getItemId());
|
|
|
|
|
+ inboundItem.setIntoingQty(BigDecimal.ZERO);
|
|
|
|
|
+ inboundItem.setIntoingAmt(BigDecimal.ZERO);
|
|
|
|
|
+// inboundItem.setFlgValid(false);
|
|
|
|
|
+ //修改
|
|
|
|
|
+ inboundItemMapper.update(inboundItem,
|
|
|
|
|
+ new UpdateWrapper<InboundItem>().lambda()
|
|
|
|
|
+ .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
|
|
|
|
|
+ );
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 销售明细
|
|
|
|
|
+ if (inboundItemResponse.getFromItemId() != null) {
|
|
|
|
|
+ //根据id查询
|
|
|
|
|
+ PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
|
|
|
|
|
+ PurchaseItem purchaseItem = new PurchaseItem();
|
|
|
|
|
+ purchaseItem.setItemId(inboundItemResponse.getFromItemId());
|
|
|
|
|
+ purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate());
|
|
|
|
|
+ purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate());
|
|
|
|
|
+ //入库状态
|
|
|
|
|
+ String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
|
|
|
|
|
+ purchaseItemResponse.getIntoQty(), purchaseItemResponse.getItemQty());
|
|
|
|
|
+ purchaseItem.setIntoStatus(intoStatus);
|
|
|
|
|
+ int countRow = purchaseItemMapper.updateById(purchaseItem);
|
|
|
|
|
+ //数量超出
|
|
|
|
|
+ if (countRow == 0) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 修改入库总单
|
|
|
|
|
+ Inbound inbound = new Inbound();
|
|
|
|
|
+ inbound.setIntoId(inboundResponse.getIntoId());
|
|
|
|
|
+ inbound.setIntoingQty(BigDecimal.ZERO);
|
|
|
|
|
+ inbound.setIntoAmt(BigDecimal.ZERO);
|
|
|
|
|
+ inbound.setFlgValid(false);
|
|
|
|
|
+ //修改
|
|
|
|
|
+ inboundMapper.update(inbound,
|
|
|
|
|
+ new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
|
|
|
|
|
+ );
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ //region 修改销售总单
|
|
|
|
|
+ if (inboundResponse.getFromId() != null) {
|
|
|
|
|
+ //根据id查询
|
|
|
|
|
+ PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
|
|
|
|
|
+ Purchase purchase = new Purchase();
|
|
|
|
|
+ purchase.setPurId(inboundResponse.getFromId());
|
|
|
|
|
+ purchase.setIntoingQty(inboundResponse.getIntoingQty().negate());
|
|
|
|
|
+ purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate());
|
|
|
|
|
+ //入库状态
|
|
|
|
|
+ String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
|
|
|
|
|
+ purchaseResponse.getIntoQty(), purchaseResponse.getSumQuantity());
|
|
|
|
|
+ purchase.setIntoStatus(intoStatus);
|
|
|
|
|
+ //修改
|
|
|
|
|
+ int countRow = purchaseMapper.updateById(purchase);
|
|
|
|
|
+ //数量超出
|
|
|
|
|
+ if (countRow == 0) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //endregion
|
|
|
|
|
+ }
|
|
|
|
|
+ //endregion
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResponseResultUtil.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @desc : 入库状态通用(目前本页面)
|
|
* @desc : 入库状态通用(目前本页面)
|
|
|
* @date : 2024/3/9 8:59
|
|
* @date : 2024/3/9 8:59
|