feat: 单据明细添加当前库存字段

This commit is contained in:
2024-11-11 20:55:14 +08:00
parent 202a4b8351
commit bf0492b060
4 changed files with 28 additions and 3 deletions

View File

@@ -80,7 +80,7 @@ public class WarehouseGoodsService
public Integer goodsCount(GoodsCountRequest request) {
return commonMapper.toInt((em.createQuery(
"select sum(case when receipt.receiptType = '0' then number when receipt.receiptType = '1' then number * -1 end ) from WarehouseReceiptDetailEntity where warehouse.id = :warehouseId and goods.id = :goodsIds")
"select sum(case when receiptType = '0' then number when receiptType = '1' then number * -1 end ) from WarehouseReceiptDetailEntity where warehouse.id = :warehouseId and goods.id = :goodsIds")
.setParameter("warehouseId", request.getWarehouseId())
.setParameter("goodsIds", request.getGoodsId())
.getSingleResult() + ""));

View File

@@ -3,6 +3,9 @@ package cn.lihongjie.coal.warehouseReceipt.service;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.exception.BizException;
import cn.lihongjie.coal.warehouseGoods.dto.GoodsCountRequest;
import cn.lihongjie.coal.warehouseGoods.service.WarehouseGoodsService;
import cn.lihongjie.coal.warehouseReceipt.dto.CreateWarehouseReceiptDto;
import cn.lihongjie.coal.warehouseReceipt.dto.UpdateWarehouseReceiptDto;
import cn.lihongjie.coal.warehouseReceipt.dto.WarehouseReceiptDto;
@@ -49,6 +52,8 @@ public class WarehouseReceiptService
@Autowired
WarehouseReceiptDetailRepository warehouseReceiptDetailRepository;
@Autowired
private WarehouseGoodsService warehouseGoodsService;
public WarehouseReceiptDto create(CreateWarehouseReceiptDto request) {
@@ -86,6 +91,23 @@ public class WarehouseReceiptService
warehouseReceiptDetailEntity.getAmount(), 0.0))
.setScale(2, RoundingMode.HALF_UP)
.doubleValue());
warehouseReceiptDetailEntity.setReceiptType(entity.getReceiptType());
GoodsCountRequest request = new GoodsCountRequest();
request.setGoodsId(warehouseReceiptDetailEntity.getGoods().getId());
request.setWarehouseId(warehouseReceiptDetailEntity.getWarehouse().getId());
Integer goodsCount = warehouseGoodsService.goodsCount(request);
if (ObjectUtils.notEqual(goodsCount, warehouseReceiptDetailEntity.getNumber())){
throw new BizException("商品 " +
warehouseGoodsService.getById(warehouseReceiptDetailEntity.getGoods().getId()).getName() +
"库存数量发生变化, 请重新操作");
}
}

View File

@@ -26,7 +26,8 @@ public class CreateWarehouseReceiptDetailDto extends OrgCommonDto {
@Comment("数量")
private Double number;
@Comment("现有数量")
private Double stock;
@Comment("单价")
private Double price;

View File

@@ -43,11 +43,13 @@ public class WarehouseReceiptDetailEntity extends OrgCommonEntity {
@ManyToOne
private WarehouseReceiptEntity receipt;
@Comment("现有库存")
private Double stock;
@Comment("数量")
private Double number;
@Comment("单据类型")
private String receiptType;