|
|
@@ -17,20 +17,28 @@ import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
|
|
|
import com.dk.mdm.mapper.common.CommonMapper;
|
|
|
import com.dk.mdm.mapper.ivt.InboundItemMapper;
|
|
|
import com.dk.mdm.mapper.ivt.InboundMapper;
|
|
|
+import com.dk.mdm.mapper.ivt.InventoryMapper;
|
|
|
import com.dk.mdm.mapper.pur.PurchaseItemMapper;
|
|
|
import com.dk.mdm.mapper.pur.PurchaseMapper;
|
|
|
import com.dk.mdm.model.pojo.ivt.Inbound;
|
|
|
import com.dk.mdm.model.pojo.ivt.InboundItem;
|
|
|
+import com.dk.mdm.model.pojo.ivt.Outbound;
|
|
|
+import com.dk.mdm.model.pojo.ivt.OutboundItem;
|
|
|
import com.dk.mdm.model.pojo.pur.Purchase;
|
|
|
import com.dk.mdm.model.pojo.pur.PurchaseItem;
|
|
|
+import com.dk.mdm.model.pojo.sale.OrderItem;
|
|
|
import com.dk.mdm.model.query.ivt.InboundItemQuery;
|
|
|
import com.dk.mdm.model.query.ivt.InboundQuery;
|
|
|
-import com.dk.mdm.model.response.ivt.InboundItemResponse;
|
|
|
-import com.dk.mdm.model.response.ivt.InboundResponse;
|
|
|
+import com.dk.mdm.model.query.ivt.InventoryQuery;
|
|
|
+import com.dk.mdm.model.query.ivt.OutboundItemQuery;
|
|
|
+import com.dk.mdm.model.response.ivt.*;
|
|
|
import com.dk.mdm.model.response.pur.PurchaseItemResponse;
|
|
|
import com.dk.mdm.model.response.pur.PurchaseResponse;
|
|
|
+import com.dk.mdm.model.response.sale.OrderItemResponse;
|
|
|
import com.dk.mdm.model.vo.ivt.InboundItemVO;
|
|
|
import com.dk.mdm.model.vo.ivt.InboundVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.OutboundItemVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.OutboundVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
|
import com.dk.mdm.service.ivt.inventory.InventoryService;
|
|
|
import com.dk.mdm.service.mac.AccountService;
|
|
|
@@ -44,6 +52,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -89,6 +98,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
@Autowired
|
|
|
private AccountService accountService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InventoryMapper inventoryMapper;
|
|
|
|
|
|
/**
|
|
|
* @desc : 条件查询
|
|
|
@@ -119,8 +130,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @desc : 查询入库价
|
|
|
- * @date : 2024/7/1 11:29
|
|
|
+ * @desc : 查询入库价
|
|
|
+ * @date : 2024/7/1 11:29
|
|
|
* @author : 寇珊珊
|
|
|
*/
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
@@ -153,7 +164,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
//region 查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细
|
|
|
Boolean priceIntoFlag = false;
|
|
|
for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
|
|
|
- if(inboundItemVO.getCostPrice() == null || inboundItemVO.getCostPrice().compareTo(BigDecimal.ZERO)==0){
|
|
|
+ if (inboundItemVO.getCostPrice() == null || inboundItemVO.getCostPrice().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
priceIntoFlag = true;
|
|
|
//查询库存批次最近一条入库价
|
|
|
InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO);
|
|
|
@@ -164,7 +175,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
inboundItemVO.setCostAmt(inboundItemResponse != null ? inboundItemResponse.getCostPrice().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
|
|
|
}
|
|
|
}
|
|
|
- if(priceIntoFlag){
|
|
|
+ if (priceIntoFlag) {
|
|
|
BigDecimal intoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
inboundVO.setIntoingAmt(intoingAmt);
|
|
|
}
|
|
|
@@ -194,7 +205,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
//已入库
|
|
|
inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
|
|
|
//入库日期
|
|
|
- inboundVO.setIntoDate( inboundVO.getIntoDate()==null ? LocalDate.now() : inboundVO.getIntoDate() );
|
|
|
+ inboundVO.setIntoDate(inboundVO.getIntoDate() == null ? LocalDate.now() : inboundVO.getIntoDate());
|
|
|
} else {
|
|
|
//入库中
|
|
|
inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
|
|
|
@@ -567,8 +578,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
map.put("delIntoDetail", inboundVO.getDeleteItemList());
|
|
|
inventoryService.operatingInventoryInformation(map);
|
|
|
//endregion
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage());
|
|
|
}
|
|
|
//endregion
|
|
|
@@ -712,8 +722,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
}
|
|
|
}
|
|
|
//endregion
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage());
|
|
|
}
|
|
|
//endregion
|
|
|
@@ -975,7 +984,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
|
|
|
inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
|
|
|
//编辑之前的数
|
|
|
- if(inboundItemResponse.getIntoQty().compareTo(BigDecimal.ZERO)>0) {
|
|
|
+ if (inboundItemResponse.getIntoQty().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty());
|
|
|
inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt());
|
|
|
}
|
|
|
@@ -1014,7 +1023,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
//endregion
|
|
|
|
|
|
//region 采购明细
|
|
|
- if(inboundItemVO.getFromItemId()!=null){
|
|
|
+ if (inboundItemVO.getFromItemId() != null) {
|
|
|
//根据id查询
|
|
|
PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
|
|
|
//赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
|
|
|
@@ -1273,6 +1282,245 @@ public class InboundPurchaseService extends BaseService<Inbound> {
|
|
|
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 : 入库状态通用(目前本页面)
|
|
|
* @date : 2024/3/9 8:59
|