|
@@ -151,7 +151,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (itemVO.getInboundItemId() == null) {
|
|
if (itemVO.getInboundItemId() == null) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "必须指定退回的入库批次");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "必须指定退回的入库批次");
|
|
|
}
|
|
}
|
|
|
- if (itemVO.getQuantity() == null || itemVO.getQuantity() <= 0) {
|
|
|
|
|
|
|
+ if (itemVO.getQuantity() == null || itemVO.getQuantity().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量必须大于0");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量必须大于0");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -163,13 +163,13 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (outboundItem == null) {
|
|
if (outboundItem == null) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "原出库明细不存在");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "原出库明细不存在");
|
|
|
}
|
|
}
|
|
|
- int originalOutQty = outboundItem.getQuantity() == null ? 0 : outboundItem.getQuantity();
|
|
|
|
|
- if (originalOutQty < itemVO.getQuantity()) {
|
|
|
|
|
|
|
+ BigDecimal originalOutQty = outboundItem.getQuantity() == null ? BigDecimal.ZERO : outboundItem.getQuantity();
|
|
|
|
|
+ if (originalOutQty.compareTo(itemVO.getQuantity()) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量不能大于原出库数量");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量不能大于原出库数量");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 出库退回应当对出库数量进行回扣:减少出库明细数量
|
|
// 出库退回应当对出库数量进行回扣:减少出库明细数量
|
|
|
- outboundItem.setQuantity(originalOutQty - itemVO.getQuantity());
|
|
|
|
|
|
|
+ outboundItem.setQuantity(originalOutQty.subtract(itemVO.getQuantity()));
|
|
|
outboundOrderItemMapper.updateById(outboundItem);
|
|
outboundOrderItemMapper.updateById(outboundItem);
|
|
|
|
|
|
|
|
// 4.3 更新批次信息(回补)
|
|
// 4.3 更新批次信息(回补)
|
|
@@ -225,7 +225,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (itemVO.getInboundItemId() == null) {
|
|
if (itemVO.getInboundItemId() == null) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "必须指定扣减的入库批次");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "必须指定扣减的入库批次");
|
|
|
}
|
|
}
|
|
|
- if (itemVO.getQuantity() == null || itemVO.getQuantity() <= 0) {
|
|
|
|
|
|
|
+ if (itemVO.getQuantity() == null || itemVO.getQuantity().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量必须大于0");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量必须大于0");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -233,7 +233,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
MaterialInboundOrderItemDO inboundItem = getInboundItemOrThrow(itemVO.getInboundItemId());
|
|
MaterialInboundOrderItemDO inboundItem = getInboundItemOrThrow(itemVO.getInboundItemId());
|
|
|
|
|
|
|
|
// 4.3 校验可用数量
|
|
// 4.3 校验可用数量
|
|
|
- if (inboundItem.getAvailableQty() < itemVO.getQuantity()) {
|
|
|
|
|
|
|
+ if (inboundItem.getAvailableQty().compareTo(itemVO.getQuantity()) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "批次可用数量不足");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "批次可用数量不足");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -241,7 +241,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
applyInboundReturnToBatch(inboundItem, itemVO.getQuantity());
|
|
applyInboundReturnToBatch(inboundItem, itemVO.getQuantity());
|
|
|
|
|
|
|
|
// 4.5 更新总库存
|
|
// 4.5 更新总库存
|
|
|
- updateMaterialStock(itemVO.getMaterialId(), -itemVO.getQuantity());
|
|
|
|
|
|
|
+ updateMaterialStock(itemVO.getMaterialId(), itemVO.getQuantity().negate());
|
|
|
|
|
|
|
|
// 4.6 保存退回明细
|
|
// 4.6 保存退回明细
|
|
|
MaterialInboundReturnOrderItemDO item = MaterialInboundReturnOrderItemDO.builder()
|
|
MaterialInboundReturnOrderItemDO item = MaterialInboundReturnOrderItemDO.builder()
|
|
@@ -279,7 +279,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
MaterialInboundOrderItemDO item = BeanUtils.toBean(itemVO, MaterialInboundOrderItemDO.class);
|
|
MaterialInboundOrderItemDO item = BeanUtils.toBean(itemVO, MaterialInboundOrderItemDO.class);
|
|
|
item.setInboundOrderId(order.getId());
|
|
item.setInboundOrderId(order.getId());
|
|
|
item.setInQty(itemVO.getQuantity());
|
|
item.setInQty(itemVO.getQuantity());
|
|
|
- item.setOutQty(0);
|
|
|
|
|
|
|
+ item.setOutQty(BigDecimal.ZERO);
|
|
|
item.setAvailableQty(itemVO.getQuantity());
|
|
item.setAvailableQty(itemVO.getQuantity());
|
|
|
item.setTenantId(createReqVO.getTenantId());
|
|
item.setTenantId(createReqVO.getTenantId());
|
|
|
item.setStoreId(itemVO.getRefInStoreId());
|
|
item.setStoreId(itemVO.getRefInStoreId());
|
|
@@ -314,7 +314,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (inboundItem == null) {
|
|
if (inboundItem == null) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "入库批次不存在");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "入库批次不存在");
|
|
|
}
|
|
}
|
|
|
- if (inboundItem.getAvailableQty() < itemVO.getQuantity()) {
|
|
|
|
|
|
|
+ if (inboundItem.getAvailableQty().compareTo(itemVO.getQuantity()) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "批次可用数量不足");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "批次可用数量不足");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -328,8 +328,8 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
outboundOrderItemMapper.insert(outboundItem);
|
|
outboundOrderItemMapper.insert(outboundItem);
|
|
|
|
|
|
|
|
// 更新批次余额
|
|
// 更新批次余额
|
|
|
- inboundItem.setOutQty(inboundItem.getOutQty() + itemVO.getQuantity());
|
|
|
|
|
- inboundItem.setAvailableQty(inboundItem.getAvailableQty() - itemVO.getQuantity());
|
|
|
|
|
|
|
+ inboundItem.setOutQty(inboundItem.getOutQty().add(itemVO.getQuantity()));
|
|
|
|
|
+ inboundItem.setAvailableQty(inboundItem.getAvailableQty().subtract(itemVO.getQuantity()));
|
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -406,7 +406,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
// 恢复库存:删除入库明细等价于减少入库数量
|
|
// 恢复库存:删除入库明细等价于减少入库数量
|
|
|
MaterialInfoDO material = materialInfoMapper.selectById(oldItem.getMaterialId());
|
|
MaterialInfoDO material = materialInfoMapper.selectById(oldItem.getMaterialId());
|
|
|
if (material != null) {
|
|
if (material != null) {
|
|
|
- material.setMaterialCount(material.getMaterialCount() - oldItem.getInQty());
|
|
|
|
|
|
|
+ material.setMaterialCount(material.getMaterialCount().subtract(oldItem.getInQty()));
|
|
|
materialInfoMapper.updateById(material);
|
|
materialInfoMapper.updateById(material);
|
|
|
}
|
|
}
|
|
|
inboundOrderItemMapper.deleteById(deleteId);
|
|
inboundOrderItemMapper.deleteById(deleteId);
|
|
@@ -418,7 +418,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
inboundOrderMapper.updateById(updateObj);
|
|
inboundOrderMapper.updateById(updateObj);
|
|
|
|
|
|
|
|
// 6. 更新已有明细(不允许修改 materialId;允许修改数量但需 >= outQty)
|
|
// 6. 更新已有明细(不允许修改 materialId;允许修改数量但需 >= outQty)
|
|
|
- Map<Long, Integer> materialDeltaMap = new HashMap<>();
|
|
|
|
|
|
|
+ Map<Long, BigDecimal> materialDeltaMap = new HashMap<>();
|
|
|
// 更新物资信息的入库单价
|
|
// 更新物资信息的入库单价
|
|
|
List<MaterialInfoDO> updateMaterialPriceList = new ArrayList<>();
|
|
List<MaterialInfoDO> updateMaterialPriceList = new ArrayList<>();
|
|
|
for (Map.Entry<Long, MaterialIoOrderItemSaveReqVO> entry : updateReqMap.entrySet()) {
|
|
for (Map.Entry<Long, MaterialIoOrderItemSaveReqVO> entry : updateReqMap.entrySet()) {
|
|
@@ -434,26 +434,25 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "入库明细已存在,不允许修改物资");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "入库明细已存在,不允许修改物资");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Integer newInQty = itemVO.getQuantity();
|
|
|
|
|
|
|
+ BigDecimal newInQty = itemVO.getQuantity();
|
|
|
if (newInQty == null) {
|
|
if (newInQty == null) {
|
|
|
- newInQty = 0;
|
|
|
|
|
|
|
+ newInQty = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
- Integer outQty = oldItem.getOutQty() == null ? 0 : oldItem.getOutQty();
|
|
|
|
|
- if (newInQty < outQty) {
|
|
|
|
|
|
|
+ BigDecimal outQty = oldItem.getOutQty() == null ? BigDecimal.ZERO : oldItem.getOutQty();
|
|
|
|
|
+ if (newInQty.compareTo(outQty) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "入库数量不能小于已出库数量");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "入库数量不能小于已出库数量");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- int oldInQty = oldItem.getInQty() == null ? 0 : oldItem.getInQty();
|
|
|
|
|
- int delta = newInQty - oldInQty;
|
|
|
|
|
- if (delta != 0) {
|
|
|
|
|
- materialDeltaMap.merge(oldItem.getMaterialId(), delta, Integer::sum);
|
|
|
|
|
|
|
+ BigDecimal oldInQty = oldItem.getInQty() == null ? BigDecimal.ZERO : oldItem.getInQty();
|
|
|
|
|
+ BigDecimal delta = newInQty.subtract(oldInQty);
|
|
|
|
|
+ if (delta.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
|
+ materialDeltaMap.merge(oldItem.getMaterialId(), delta, BigDecimal::add);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
MaterialInboundOrderItemDO updateItem = BeanUtils.toBean(itemVO, MaterialInboundOrderItemDO.class);
|
|
MaterialInboundOrderItemDO updateItem = BeanUtils.toBean(itemVO, MaterialInboundOrderItemDO.class);
|
|
|
updateItem.setId(itemId);
|
|
updateItem.setId(itemId);
|
|
|
updateItem.setInboundOrderId(order.getId());
|
|
updateItem.setInboundOrderId(order.getId());
|
|
|
updateItem.setInQty(newInQty);
|
|
updateItem.setInQty(newInQty);
|
|
|
- updateItem.setAvailableQty(newInQty - outQty);
|
|
|
|
|
|
|
+ updateItem.setAvailableQty(newInQty.subtract(outQty));
|
|
|
updateItem.setOutQty(outQty);
|
|
updateItem.setOutQty(outQty);
|
|
|
updateItem.setTenantId(updateReqVO.getTenantId());
|
|
updateItem.setTenantId(updateReqVO.getTenantId());
|
|
|
updateItem.setStoreId(itemVO.getRefInStoreId());
|
|
updateItem.setStoreId(itemVO.getRefInStoreId());
|
|
@@ -469,23 +468,23 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
MaterialInboundOrderItemDO item = BeanUtils.toBean(itemVO, MaterialInboundOrderItemDO.class);
|
|
MaterialInboundOrderItemDO item = BeanUtils.toBean(itemVO, MaterialInboundOrderItemDO.class);
|
|
|
item.setInboundOrderId(order.getId());
|
|
item.setInboundOrderId(order.getId());
|
|
|
item.setInQty(itemVO.getQuantity());
|
|
item.setInQty(itemVO.getQuantity());
|
|
|
- item.setOutQty(0);
|
|
|
|
|
|
|
+ item.setOutQty(BigDecimal.ZERO);
|
|
|
item.setAvailableQty(itemVO.getQuantity());
|
|
item.setAvailableQty(itemVO.getQuantity());
|
|
|
item.setTenantId(updateReqVO.getTenantId());
|
|
item.setTenantId(updateReqVO.getTenantId());
|
|
|
item.setStoreId(itemVO.getRefInStoreId());
|
|
item.setStoreId(itemVO.getRefInStoreId());
|
|
|
inboundOrderItemMapper.insert(item);
|
|
inboundOrderItemMapper.insert(item);
|
|
|
updateMaterialPriceList.add(new MaterialInfoDO().setId(itemVO.getMaterialId()).setMaterialInPrice(itemVO.getInUnitPrice()));
|
|
updateMaterialPriceList.add(new MaterialInfoDO().setId(itemVO.getMaterialId()).setMaterialInPrice(itemVO.getInUnitPrice()));
|
|
|
- int addQty = itemVO.getQuantity() == null ? 0 : itemVO.getQuantity();
|
|
|
|
|
- if (addQty != 0) {
|
|
|
|
|
- materialDeltaMap.merge(itemVO.getMaterialId(), addQty, Integer::sum);
|
|
|
|
|
|
|
+ BigDecimal addQty = itemVO.getQuantity() == null ? BigDecimal.ZERO : itemVO.getQuantity();
|
|
|
|
|
+ if (addQty.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
|
+ materialDeltaMap.merge(itemVO.getMaterialId(), addQty, BigDecimal::add);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 8. 按差量更新物资总库存
|
|
// 8. 按差量更新物资总库存
|
|
|
- for (Map.Entry<Long, Integer> entry : materialDeltaMap.entrySet()) {
|
|
|
|
|
|
|
+ for (Map.Entry<Long, BigDecimal> entry : materialDeltaMap.entrySet()) {
|
|
|
MaterialInfoDO material = materialInfoMapper.selectById(entry.getKey());
|
|
MaterialInfoDO material = materialInfoMapper.selectById(entry.getKey());
|
|
|
if (material != null) {
|
|
if (material != null) {
|
|
|
- material.setMaterialCount(material.getMaterialCount() + entry.getValue());
|
|
|
|
|
|
|
+ material.setMaterialCount(material.getMaterialCount().add(entry.getValue()));
|
|
|
materialInfoMapper.updateById(material);
|
|
materialInfoMapper.updateById(material);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -508,14 +507,14 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
for (MaterialOutboundOrderItemDO oldItem : oldItems) {
|
|
for (MaterialOutboundOrderItemDO oldItem : oldItems) {
|
|
|
MaterialInboundOrderItemDO inboundItem = inboundOrderItemMapper.selectById(oldItem.getRefInboundItemId());
|
|
MaterialInboundOrderItemDO inboundItem = inboundOrderItemMapper.selectById(oldItem.getRefInboundItemId());
|
|
|
if (inboundItem != null) {
|
|
if (inboundItem != null) {
|
|
|
- inboundItem.setOutQty(inboundItem.getOutQty() - oldItem.getQuantity());
|
|
|
|
|
- inboundItem.setAvailableQty(inboundItem.getAvailableQty() + oldItem.getQuantity());
|
|
|
|
|
|
|
+ inboundItem.setOutQty(inboundItem.getOutQty().subtract(oldItem.getQuantity()));
|
|
|
|
|
+ inboundItem.setAvailableQty(inboundItem.getAvailableQty().add(oldItem.getQuantity()));
|
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
MaterialInfoDO material = materialInfoMapper.selectById(oldItem.getMaterialId());
|
|
MaterialInfoDO material = materialInfoMapper.selectById(oldItem.getMaterialId());
|
|
|
if (material != null) {
|
|
if (material != null) {
|
|
|
- material.setMaterialCount(material.getMaterialCount() + oldItem.getQuantity());
|
|
|
|
|
|
|
+ material.setMaterialCount(material.getMaterialCount().add(oldItem.getQuantity()));
|
|
|
materialInfoMapper.updateById(material);
|
|
materialInfoMapper.updateById(material);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -534,7 +533,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (inboundItem == null) {
|
|
if (inboundItem == null) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "入库批次不存在");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "入库批次不存在");
|
|
|
}
|
|
}
|
|
|
- if (inboundItem.getAvailableQty() < itemVO.getQuantity()) {
|
|
|
|
|
|
|
+ if (inboundItem.getAvailableQty().compareTo(itemVO.getQuantity()) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "批次可用数量不足");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "批次可用数量不足");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -546,8 +545,8 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
outboundItem.setTenantId(updateReqVO.getTenantId());
|
|
outboundItem.setTenantId(updateReqVO.getTenantId());
|
|
|
outboundOrderItemMapper.insert(outboundItem);
|
|
outboundOrderItemMapper.insert(outboundItem);
|
|
|
|
|
|
|
|
- inboundItem.setOutQty(inboundItem.getOutQty() + itemVO.getQuantity());
|
|
|
|
|
- inboundItem.setAvailableQty(inboundItem.getAvailableQty() - itemVO.getQuantity());
|
|
|
|
|
|
|
+ inboundItem.setOutQty(inboundItem.getOutQty().add(itemVO.getQuantity()));
|
|
|
|
|
+ inboundItem.setAvailableQty(inboundItem.getAvailableQty().subtract(itemVO.getQuantity()));
|
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -586,7 +585,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
// 5. 插入新明细并重新计算库存和批次
|
|
// 5. 插入新明细并重新计算库存和批次
|
|
|
for (MaterialIoOrderItemSaveReqVO itemVO : updateReqVO.getItems()) {
|
|
for (MaterialIoOrderItemSaveReqVO itemVO : updateReqVO.getItems()) {
|
|
|
MaterialInboundOrderItemDO inboundItem = getInboundItemOrThrow(itemVO.getInboundItemId());
|
|
MaterialInboundOrderItemDO inboundItem = getInboundItemOrThrow(itemVO.getInboundItemId());
|
|
|
- if (inboundItem.getAvailableQty() < itemVO.getQuantity()) {
|
|
|
|
|
|
|
+ if (inboundItem.getAvailableQty().compareTo(itemVO.getQuantity()) < 0) {
|
|
|
throw exception(COMMON_NOT_FOUND, "批次可用数量不足");
|
|
throw exception(COMMON_NOT_FOUND, "批次可用数量不足");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -594,7 +593,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
applyInboundReturnToBatch(inboundItem, itemVO.getQuantity());
|
|
applyInboundReturnToBatch(inboundItem, itemVO.getQuantity());
|
|
|
|
|
|
|
|
// 更新库存(减少)
|
|
// 更新库存(减少)
|
|
|
- updateMaterialStock(itemVO.getMaterialId(), -itemVO.getQuantity());
|
|
|
|
|
|
|
+ updateMaterialStock(itemVO.getMaterialId(), itemVO.getQuantity().negate());
|
|
|
|
|
|
|
|
// 插入新明细
|
|
// 插入新明细
|
|
|
MaterialInboundReturnOrderItemDO newItem = BeanUtils.toBean(itemVO, MaterialInboundReturnOrderItemDO.class);
|
|
MaterialInboundReturnOrderItemDO newItem = BeanUtils.toBean(itemVO, MaterialInboundReturnOrderItemDO.class);
|
|
@@ -622,13 +621,13 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
rollbackOutboundReturnOnBatch(inboundItem, oldItem.getQuantity());
|
|
rollbackOutboundReturnOnBatch(inboundItem, oldItem.getQuantity());
|
|
|
}
|
|
}
|
|
|
// 回滚库存:出库退回是增加,回滚就是减少
|
|
// 回滚库存:出库退回是增加,回滚就是减少
|
|
|
- updateMaterialStock(oldItem.getMaterialId(), -oldItem.getQuantity());
|
|
|
|
|
|
|
+ updateMaterialStock(oldItem.getMaterialId(), oldItem.getQuantity().negate());
|
|
|
|
|
|
|
|
// 回滚出库明细:把之前扣掉的出库数量加回来
|
|
// 回滚出库明细:把之前扣掉的出库数量加回来
|
|
|
MaterialOutboundOrderItemDO outboundItem = outboundOrderItemMapper.selectById(oldItem.getOutboundItemId());
|
|
MaterialOutboundOrderItemDO outboundItem = outboundOrderItemMapper.selectById(oldItem.getOutboundItemId());
|
|
|
if (outboundItem != null) {
|
|
if (outboundItem != null) {
|
|
|
- int currentQty = outboundItem.getQuantity() == null ? 0 : outboundItem.getQuantity();
|
|
|
|
|
- outboundItem.setQuantity(currentQty + oldItem.getQuantity());
|
|
|
|
|
|
|
+ BigDecimal currentQty = outboundItem.getQuantity() == null ? BigDecimal.ZERO : outboundItem.getQuantity();
|
|
|
|
|
+ outboundItem.setQuantity(currentQty.add(oldItem.getQuantity()));
|
|
|
outboundOrderItemMapper.updateById(outboundItem);
|
|
outboundOrderItemMapper.updateById(outboundItem);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -650,13 +649,13 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (outboundItem == null) {
|
|
if (outboundItem == null) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "原出库明细不存在");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "原出库明细不存在");
|
|
|
}
|
|
}
|
|
|
- int currentOutQty = outboundItem.getQuantity() == null ? 0 : outboundItem.getQuantity();
|
|
|
|
|
- if (currentOutQty < itemVO.getQuantity()) {
|
|
|
|
|
|
|
+ BigDecimal currentOutQty = outboundItem.getQuantity() == null ? BigDecimal.ZERO : outboundItem.getQuantity();
|
|
|
|
|
+ if (currentOutQty.compareTo(itemVO.getQuantity()) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量不能大于原出库数量");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量不能大于原出库数量");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 回扣出库明细数量
|
|
// 回扣出库明细数量
|
|
|
- outboundItem.setQuantity(currentOutQty - itemVO.getQuantity());
|
|
|
|
|
|
|
+ outboundItem.setQuantity(currentOutQty.subtract(itemVO.getQuantity()));
|
|
|
outboundOrderItemMapper.updateById(outboundItem);
|
|
outboundOrderItemMapper.updateById(outboundItem);
|
|
|
|
|
|
|
|
// 更新批次(增加)
|
|
// 更新批次(增加)
|
|
@@ -722,7 +721,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
for (MaterialInboundOrderItemDO item : items) {
|
|
for (MaterialInboundOrderItemDO item : items) {
|
|
|
MaterialInfoDO material = materialInfoMapper.selectById(item.getMaterialId());
|
|
MaterialInfoDO material = materialInfoMapper.selectById(item.getMaterialId());
|
|
|
if (material != null) {
|
|
if (material != null) {
|
|
|
- material.setMaterialCount(material.getMaterialCount() - item.getInQty());
|
|
|
|
|
|
|
+ material.setMaterialCount(material.getMaterialCount().subtract(item.getInQty()));
|
|
|
materialInfoMapper.updateById(material);
|
|
materialInfoMapper.updateById(material);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -752,14 +751,14 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
for (MaterialOutboundOrderItemDO item : items) {
|
|
for (MaterialOutboundOrderItemDO item : items) {
|
|
|
MaterialInboundOrderItemDO inboundItem = inboundOrderItemMapper.selectById(item.getRefInboundItemId());
|
|
MaterialInboundOrderItemDO inboundItem = inboundOrderItemMapper.selectById(item.getRefInboundItemId());
|
|
|
if (inboundItem != null) {
|
|
if (inboundItem != null) {
|
|
|
- inboundItem.setOutQty(inboundItem.getOutQty() - item.getQuantity());
|
|
|
|
|
- inboundItem.setAvailableQty(inboundItem.getAvailableQty() + item.getQuantity());
|
|
|
|
|
|
|
+ inboundItem.setOutQty(inboundItem.getOutQty().subtract(item.getQuantity()));
|
|
|
|
|
+ inboundItem.setAvailableQty(inboundItem.getAvailableQty().add(item.getQuantity()));
|
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
MaterialInfoDO material = materialInfoMapper.selectById(item.getMaterialId());
|
|
MaterialInfoDO material = materialInfoMapper.selectById(item.getMaterialId());
|
|
|
if (material != null) {
|
|
if (material != null) {
|
|
|
- material.setMaterialCount(material.getMaterialCount() + item.getQuantity());
|
|
|
|
|
|
|
+ material.setMaterialCount(material.getMaterialCount().add(item.getQuantity()));
|
|
|
materialInfoMapper.updateById(material);
|
|
materialInfoMapper.updateById(material);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -805,7 +804,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
itemRespVO.setProduceDate(item.getProduceDate());
|
|
itemRespVO.setProduceDate(item.getProduceDate());
|
|
|
// 计算金额
|
|
// 计算金额
|
|
|
if (item.getInQty() != null && item.getInUnitPrice() != null) {
|
|
if (item.getInQty() != null && item.getInUnitPrice() != null) {
|
|
|
- itemRespVO.setAmount(item.getInUnitPrice().multiply(new java.math.BigDecimal(item.getInQty())));
|
|
|
|
|
|
|
+ itemRespVO.setAmount(item.getInUnitPrice().multiply(item.getInQty()));
|
|
|
}
|
|
}
|
|
|
itemRespVOs.add(itemRespVO);
|
|
itemRespVOs.add(itemRespVO);
|
|
|
|
|
|
|
@@ -938,7 +937,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
itemRespVO.setInUnitPrice(inboundItem.getInUnitPrice());
|
|
itemRespVO.setInUnitPrice(inboundItem.getInUnitPrice());
|
|
|
itemRespVO.setSaleUnitPrice(inboundItem.getSaleUnitPrice());
|
|
itemRespVO.setSaleUnitPrice(inboundItem.getSaleUnitPrice());
|
|
|
itemRespVO.setProduceDate(inboundItem.getProduceDate());
|
|
itemRespVO.setProduceDate(inboundItem.getProduceDate());
|
|
|
- itemRespVO.setLatestAvailableQty(inboundItem.getAvailableQty() + itemRespVO.getQuantity());
|
|
|
|
|
|
|
+ itemRespVO.setLatestAvailableQty(inboundItem.getAvailableQty().add(itemRespVO.getQuantity()));
|
|
|
// 填充入库单号
|
|
// 填充入库单号
|
|
|
MaterialInboundOrderDO inboundOrder = inboundOrderMap.get(inboundItem.getInboundOrderId());
|
|
MaterialInboundOrderDO inboundOrder = inboundOrderMap.get(inboundItem.getInboundOrderId());
|
|
|
if (inboundOrder != null) {
|
|
if (inboundOrder != null) {
|
|
@@ -946,7 +945,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
}
|
|
}
|
|
|
// 计算金额
|
|
// 计算金额
|
|
|
if (itemRespVO.getQuantity() != null && itemRespVO.getInUnitPrice() != null) {
|
|
if (itemRespVO.getQuantity() != null && itemRespVO.getInUnitPrice() != null) {
|
|
|
- itemRespVO.setAmount(itemRespVO.getInUnitPrice().multiply(new java.math.BigDecimal(itemRespVO.getQuantity())));
|
|
|
|
|
|
|
+ itemRespVO.setAmount(itemRespVO.getInUnitPrice().multiply(itemRespVO.getQuantity()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1274,7 +1273,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (inboundItem != null) {
|
|
if (inboundItem != null) {
|
|
|
itemVO.setInUnitPrice(inboundItem.getInUnitPrice());
|
|
itemVO.setInUnitPrice(inboundItem.getInUnitPrice());
|
|
|
if (inboundItem.getInUnitPrice() != null && item.getQuantity() != null) {
|
|
if (inboundItem.getInUnitPrice() != null && item.getQuantity() != null) {
|
|
|
- itemVO.setAmount(inboundItem.getInUnitPrice().multiply(new BigDecimal(item.getQuantity())));
|
|
|
|
|
|
|
+ itemVO.setAmount(inboundItem.getInUnitPrice().multiply(item.getQuantity()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1341,9 +1340,9 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
MaterialInboundOrderItemDO inboundItem = inboundItemMap.get(item.getRefInboundItemId());
|
|
MaterialInboundOrderItemDO inboundItem = inboundItemMap.get(item.getRefInboundItemId());
|
|
|
if (inboundItem != null) {
|
|
if (inboundItem != null) {
|
|
|
itemVO.setInUnitPrice(inboundItem.getInUnitPrice());
|
|
itemVO.setInUnitPrice(inboundItem.getInUnitPrice());
|
|
|
- itemVO.setAvailableQty(inboundItem.getAvailableQty() + item.getQuantity());
|
|
|
|
|
|
|
+ itemVO.setAvailableQty(inboundItem.getAvailableQty().add(item.getQuantity()));
|
|
|
if (inboundItem.getInUnitPrice() != null && item.getQuantity() != null) {
|
|
if (inboundItem.getInUnitPrice() != null && item.getQuantity() != null) {
|
|
|
- itemVO.setAmount(inboundItem.getInUnitPrice().multiply(new BigDecimal(item.getQuantity())));
|
|
|
|
|
|
|
+ itemVO.setAmount(inboundItem.getInUnitPrice().multiply(item.getQuantity()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1563,7 +1562,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (item.getInQty() != null && item.getInUnitPrice() != null) {
|
|
if (item.getInQty() != null && item.getInUnitPrice() != null) {
|
|
|
- vo.setTotalAmount(vo.getTotalAmount().add(item.getInUnitPrice().multiply(new BigDecimal(item.getInQty()))));
|
|
|
|
|
|
|
+ vo.setTotalAmount(vo.getTotalAmount().add(item.getInUnitPrice().multiply(item.getInQty())));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1674,7 +1673,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
vo.setQuantity(item.getInQty());
|
|
vo.setQuantity(item.getInQty());
|
|
|
vo.setInUnitPrice(item.getInUnitPrice());
|
|
vo.setInUnitPrice(item.getInUnitPrice());
|
|
|
if (item.getInQty() != null && item.getInUnitPrice() != null) {
|
|
if (item.getInQty() != null && item.getInUnitPrice() != null) {
|
|
|
- vo.setAmount(item.getInUnitPrice().multiply(new BigDecimal(item.getInQty())));
|
|
|
|
|
|
|
+ vo.setAmount(item.getInUnitPrice().multiply(item.getInQty()));
|
|
|
}
|
|
}
|
|
|
return vo;
|
|
return vo;
|
|
|
})
|
|
})
|
|
@@ -1787,7 +1786,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
|
|
|
|
|
MaterialInboundOrderItemDO inboundItem = inboundItemMap.get(item.getRefInboundItemId());
|
|
MaterialInboundOrderItemDO inboundItem = inboundItemMap.get(item.getRefInboundItemId());
|
|
|
if (inboundItem != null && inboundItem.getInUnitPrice() != null && item.getQuantity() != null) {
|
|
if (inboundItem != null && inboundItem.getInUnitPrice() != null && item.getQuantity() != null) {
|
|
|
- vo.setTotalAmount(vo.getTotalAmount().add(inboundItem.getInUnitPrice().multiply(new BigDecimal(item.getQuantity()))));
|
|
|
|
|
|
|
+ vo.setTotalAmount(vo.getTotalAmount().add(inboundItem.getInUnitPrice().multiply(item.getQuantity())));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1884,7 +1883,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (inboundItem != null) {
|
|
if (inboundItem != null) {
|
|
|
vo.setInUnitPrice(inboundItem.getInUnitPrice());
|
|
vo.setInUnitPrice(inboundItem.getInUnitPrice());
|
|
|
if (inboundItem.getInUnitPrice() != null && item.getQuantity() != null) {
|
|
if (inboundItem.getInUnitPrice() != null && item.getQuantity() != null) {
|
|
|
- vo.setAmount(inboundItem.getInUnitPrice().multiply(new BigDecimal(item.getQuantity())));
|
|
|
|
|
|
|
+ vo.setAmount(inboundItem.getInUnitPrice().multiply(item.getQuantity()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return vo;
|
|
return vo;
|
|
@@ -2012,7 +2011,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
private List<MaterialInventoryReportRespVO> buildInventoryReportResp(LocalDate monthStart, LocalDate nextMonthStart,
|
|
private List<MaterialInventoryReportRespVO> buildInventoryReportResp(LocalDate monthStart, LocalDate nextMonthStart,
|
|
|
List<MaterialInboundOrderItemDO> records) {
|
|
List<MaterialInboundOrderItemDO> records) {
|
|
|
Set<Long> inboundItemIds = records.stream().map(MaterialInboundOrderItemDO::getId).collect(Collectors.toSet());
|
|
Set<Long> inboundItemIds = records.stream().map(MaterialInboundOrderItemDO::getId).collect(Collectors.toSet());
|
|
|
- Map<Long, Integer> outQtyMap = getOutboundQtySumByInboundItemIds(monthStart, nextMonthStart, inboundItemIds);
|
|
|
|
|
|
|
+ Map<Long, BigDecimal> outQtyMap = getOutboundQtySumByInboundItemIds(monthStart, nextMonthStart, inboundItemIds);
|
|
|
|
|
|
|
|
Set<Long> materialIds = records.stream().map(MaterialInboundOrderItemDO::getMaterialId).collect(Collectors.toSet());
|
|
Set<Long> materialIds = records.stream().map(MaterialInboundOrderItemDO::getMaterialId).collect(Collectors.toSet());
|
|
|
Map<Long, MaterialInfoDO> materialMap = materialIds.isEmpty() ? Collections.emptyMap()
|
|
Map<Long, MaterialInfoDO> materialMap = materialIds.isEmpty() ? Collections.emptyMap()
|
|
@@ -2051,25 +2050,25 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
BigDecimal price = item.getInUnitPrice() != null ? item.getInUnitPrice() : BigDecimal.ZERO;
|
|
BigDecimal price = item.getInUnitPrice() != null ? item.getInUnitPrice() : BigDecimal.ZERO;
|
|
|
- int inQty = item.getInQty() != null ? item.getInQty() : 0;
|
|
|
|
|
- int outQty = outQtyMap.getOrDefault(item.getId(), 0);
|
|
|
|
|
- int endQty = inQty - outQty;
|
|
|
|
|
|
|
+ BigDecimal inQty = item.getInQty() != null ? item.getInQty() : BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal outQty = outQtyMap.getOrDefault(item.getId(), BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal endQty = inQty.subtract(outQty);
|
|
|
|
|
|
|
|
- vo.setBeginQty(0);
|
|
|
|
|
|
|
+ vo.setBeginQty(BigDecimal.ZERO);
|
|
|
vo.setBeginPrice(price);
|
|
vo.setBeginPrice(price);
|
|
|
vo.setBeginAmount(BigDecimal.ZERO);
|
|
vo.setBeginAmount(BigDecimal.ZERO);
|
|
|
|
|
|
|
|
vo.setInQty(inQty);
|
|
vo.setInQty(inQty);
|
|
|
vo.setInPrice(price);
|
|
vo.setInPrice(price);
|
|
|
- vo.setInAmount(price.multiply(BigDecimal.valueOf(inQty)));
|
|
|
|
|
|
|
+ vo.setInAmount(price.multiply(inQty));
|
|
|
|
|
|
|
|
vo.setOutQty(outQty);
|
|
vo.setOutQty(outQty);
|
|
|
vo.setOutPrice(price);
|
|
vo.setOutPrice(price);
|
|
|
- vo.setOutAmount(price.multiply(BigDecimal.valueOf(outQty)));
|
|
|
|
|
|
|
+ vo.setOutAmount(price.multiply(outQty));
|
|
|
|
|
|
|
|
vo.setEndQty(endQty);
|
|
vo.setEndQty(endQty);
|
|
|
vo.setEndPrice(price);
|
|
vo.setEndPrice(price);
|
|
|
- vo.setEndAmount(price.multiply(BigDecimal.valueOf(endQty)));
|
|
|
|
|
|
|
+ vo.setEndAmount(price.multiply(endQty));
|
|
|
|
|
|
|
|
return vo;
|
|
return vo;
|
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
@@ -2116,7 +2115,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
MaterialInventoryFlowRespVO.InventoryInfo inventoryInfo = new MaterialInventoryFlowRespVO.InventoryInfo();
|
|
MaterialInventoryFlowRespVO.InventoryInfo inventoryInfo = new MaterialInventoryFlowRespVO.InventoryInfo();
|
|
|
inventoryInfo.setStoreName(store != null ? store.getStoreName() : null);
|
|
inventoryInfo.setStoreName(store != null ? store.getStoreName() : null);
|
|
|
inventoryInfo.setMaterialName(material.getMaterialName());
|
|
inventoryInfo.setMaterialName(material.getMaterialName());
|
|
|
- inventoryInfo.setInventoryQty(inboundItem.getAvailableQty() != null ? inboundItem.getAvailableQty() : 0);
|
|
|
|
|
|
|
+ inventoryInfo.setInventoryQty(inboundItem.getAvailableQty() != null ? inboundItem.getAvailableQty() : BigDecimal.ZERO);
|
|
|
inventoryInfo.setCategoryName(category != null ? category.getCategoryName() : null);
|
|
inventoryInfo.setCategoryName(category != null ? category.getCategoryName() : null);
|
|
|
inventoryInfo.setSpecification(material.getSpecification());
|
|
inventoryInfo.setSpecification(material.getSpecification());
|
|
|
inventoryInfo.setMaterialUnit(material.getMaterialUnit());
|
|
inventoryInfo.setMaterialUnit(material.getMaterialUnit());
|
|
@@ -2183,7 +2182,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
/**
|
|
/**
|
|
|
* 统计一批入库明细(批次)在指定时间范围内的出库总数量
|
|
* 统计一批入库明细(批次)在指定时间范围内的出库总数量
|
|
|
*/
|
|
*/
|
|
|
- private Map<Long, Integer> getOutboundQtySumByInboundItemIds(LocalDate start, LocalDate end, Set<Long> inboundItemIds) {
|
|
|
|
|
|
|
+ private Map<Long, BigDecimal> getOutboundQtySumByInboundItemIds(LocalDate start, LocalDate end, Set<Long> inboundItemIds) {
|
|
|
if (inboundItemIds == null || inboundItemIds.isEmpty()) {
|
|
if (inboundItemIds == null || inboundItemIds.isEmpty()) {
|
|
|
return Collections.emptyMap();
|
|
return Collections.emptyMap();
|
|
|
}
|
|
}
|
|
@@ -2193,7 +2192,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
}
|
|
}
|
|
|
return result.stream().collect(Collectors.toMap(
|
|
return result.stream().collect(Collectors.toMap(
|
|
|
m -> ((Number) m.get("refInboundItemId")).longValue(),
|
|
m -> ((Number) m.get("refInboundItemId")).longValue(),
|
|
|
- m -> ((Number) m.get("totalQty")).intValue()
|
|
|
|
|
|
|
+ m -> ((BigDecimal) m.get("totalQty"))
|
|
|
));
|
|
));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2201,15 +2200,14 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
* 更新物资总库存(入库)
|
|
* 更新物资总库存(入库)
|
|
|
*/
|
|
*/
|
|
|
private void updateMaterialStockForInbound(List<MaterialIoOrderItemSaveReqVO> items) {
|
|
private void updateMaterialStockForInbound(List<MaterialIoOrderItemSaveReqVO> items) {
|
|
|
- Map<Long, Integer> materialQtyMap = items.stream()
|
|
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
|
|
- MaterialIoOrderItemSaveReqVO::getMaterialId,
|
|
|
|
|
- Collectors.summingInt(MaterialIoOrderItemSaveReqVO::getQuantity)));
|
|
|
|
|
-
|
|
|
|
|
- for (Map.Entry<Long, Integer> entry : materialQtyMap.entrySet()) {
|
|
|
|
|
|
|
+ Map<Long, BigDecimal> materialQtyMap = items.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(MaterialIoOrderItemSaveReqVO::getMaterialId,
|
|
|
|
|
+ MaterialIoOrderItemSaveReqVO::getQuantity,
|
|
|
|
|
+ BigDecimal::add));
|
|
|
|
|
+ for (Map.Entry<Long, BigDecimal> entry : materialQtyMap.entrySet()) {
|
|
|
MaterialInfoDO material = materialInfoMapper.selectById(entry.getKey());
|
|
MaterialInfoDO material = materialInfoMapper.selectById(entry.getKey());
|
|
|
if (material != null) {
|
|
if (material != null) {
|
|
|
- material.setMaterialCount(material.getMaterialCount() + entry.getValue());
|
|
|
|
|
|
|
+ material.setMaterialCount(material.getMaterialCount().add(entry.getValue()));
|
|
|
materialInfoMapper.updateById(material);
|
|
materialInfoMapper.updateById(material);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -2219,18 +2217,19 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
* 更新物资总库存(出库)
|
|
* 更新物资总库存(出库)
|
|
|
*/
|
|
*/
|
|
|
private void updateMaterialStockForOutbound(List<MaterialIoOrderItemSaveReqVO> items, Long tenantId) {
|
|
private void updateMaterialStockForOutbound(List<MaterialIoOrderItemSaveReqVO> items, Long tenantId) {
|
|
|
- Map<Long, Integer> materialQtyMap = items.stream()
|
|
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
|
|
|
|
+ Map<Long, BigDecimal> materialQtyMap = items.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
MaterialIoOrderItemSaveReqVO::getMaterialId,
|
|
MaterialIoOrderItemSaveReqVO::getMaterialId,
|
|
|
- Collectors.summingInt(MaterialIoOrderItemSaveReqVO::getQuantity)));
|
|
|
|
|
|
|
+ MaterialIoOrderItemSaveReqVO::getQuantity,
|
|
|
|
|
+ BigDecimal::add));
|
|
|
|
|
|
|
|
- for (Map.Entry<Long, Integer> entry : materialQtyMap.entrySet()) {
|
|
|
|
|
|
|
+ for (Map.Entry<Long, BigDecimal> entry : materialQtyMap.entrySet()) {
|
|
|
MaterialInfoDO material = materialInfoMapper.selectById(entry.getKey());
|
|
MaterialInfoDO material = materialInfoMapper.selectById(entry.getKey());
|
|
|
if (material != null) {
|
|
if (material != null) {
|
|
|
- if (material.getMaterialCount() < entry.getValue()) {
|
|
|
|
|
|
|
+ if (material.getMaterialCount().compareTo( entry.getValue()) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "物资库存不足: " + material.getMaterialName());
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "物资库存不足: " + material.getMaterialName());
|
|
|
}
|
|
}
|
|
|
- material.setMaterialCount(material.getMaterialCount() - entry.getValue());
|
|
|
|
|
|
|
+ material.setMaterialCount(material.getMaterialCount().subtract(entry.getValue()));
|
|
|
materialInfoMapper.updateById(material);
|
|
materialInfoMapper.updateById(material);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -2254,17 +2253,17 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
* @param materialId 物资ID
|
|
* @param materialId 物资ID
|
|
|
* @param quantityDelta 数量变化量(正数为增加,负数为减少)
|
|
* @param quantityDelta 数量变化量(正数为增加,负数为减少)
|
|
|
*/
|
|
*/
|
|
|
- private void updateMaterialStock(Long materialId, int quantityDelta) {
|
|
|
|
|
- if (quantityDelta == 0) {
|
|
|
|
|
|
|
+ private void updateMaterialStock(Long materialId, BigDecimal quantityDelta) {
|
|
|
|
|
+ if (quantityDelta.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
MaterialInfoDO material = materialInfoMapper.selectById(materialId);
|
|
MaterialInfoDO material = materialInfoMapper.selectById(materialId);
|
|
|
if (material == null) {
|
|
if (material == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- int current = material.getMaterialCount() == null ? 0 : material.getMaterialCount();
|
|
|
|
|
- int newStock = current + quantityDelta;
|
|
|
|
|
- if (newStock < 0) {
|
|
|
|
|
|
|
+ BigDecimal current = material.getMaterialCount() == null ? BigDecimal.ZERO : material.getMaterialCount();
|
|
|
|
|
+ BigDecimal newStock = current.add(quantityDelta);
|
|
|
|
|
+ if (newStock.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "物资库存不足: " + material.getMaterialName());
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "物资库存不足: " + material.getMaterialName());
|
|
|
}
|
|
}
|
|
|
material.setMaterialCount(newStock);
|
|
material.setMaterialCount(newStock);
|
|
@@ -2274,55 +2273,54 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
/**
|
|
/**
|
|
|
* 应用入库退回对批次的影响(减少 inQty)
|
|
* 应用入库退回对批次的影响(减少 inQty)
|
|
|
*/
|
|
*/
|
|
|
- private void applyInboundReturnToBatch(MaterialInboundOrderItemDO inboundItem, int returnQty) {
|
|
|
|
|
- int oldInQty = inboundItem.getInQty() == null ? 0 : inboundItem.getInQty();
|
|
|
|
|
- int outQty = inboundItem.getOutQty() == null ? 0 : inboundItem.getOutQty();
|
|
|
|
|
- int newInQty = oldInQty - returnQty;
|
|
|
|
|
- if (newInQty < outQty) {
|
|
|
|
|
|
|
+ private void applyInboundReturnToBatch(MaterialInboundOrderItemDO inboundItem, BigDecimal returnQty) {
|
|
|
|
|
+ BigDecimal oldInQty = inboundItem.getInQty() == null ? BigDecimal.ZERO : inboundItem.getInQty();
|
|
|
|
|
+ BigDecimal outQty = inboundItem.getOutQty() == null ? BigDecimal.ZERO : inboundItem.getOutQty();
|
|
|
|
|
+ BigDecimal newInQty = oldInQty.subtract(returnQty);
|
|
|
|
|
+ if (newInQty.compareTo(outQty) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回后入库数量不能小于已出库数量");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回后入库数量不能小于已出库数量");
|
|
|
}
|
|
}
|
|
|
inboundItem.setInQty(newInQty);
|
|
inboundItem.setInQty(newInQty);
|
|
|
- inboundItem.setAvailableQty(newInQty - outQty);
|
|
|
|
|
|
|
+ inboundItem.setAvailableQty(newInQty.subtract(outQty));
|
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 回滚入库退回对批次的影响(恢复 inQty)
|
|
* 回滚入库退回对批次的影响(恢复 inQty)
|
|
|
*/
|
|
*/
|
|
|
- private void rollbackInboundReturnOnBatch(MaterialInboundOrderItemDO inboundItem, int returnQty) {
|
|
|
|
|
- int oldInQty = inboundItem.getInQty() == null ? 0 : inboundItem.getInQty();
|
|
|
|
|
- int outQty = inboundItem.getOutQty() == null ? 0 : inboundItem.getOutQty();
|
|
|
|
|
- int newInQty = oldInQty + returnQty;
|
|
|
|
|
|
|
+ private void rollbackInboundReturnOnBatch(MaterialInboundOrderItemDO inboundItem, BigDecimal returnQty) {
|
|
|
|
|
+ BigDecimal oldInQty = inboundItem.getInQty() == null ? BigDecimal.ZERO : inboundItem.getInQty();
|
|
|
|
|
+ BigDecimal outQty = inboundItem.getOutQty() == null ? BigDecimal.ZERO : inboundItem.getOutQty();
|
|
|
|
|
+ BigDecimal newInQty = oldInQty.add(returnQty);
|
|
|
inboundItem.setInQty(newInQty);
|
|
inboundItem.setInQty(newInQty);
|
|
|
- inboundItem.setAvailableQty(newInQty - outQty);
|
|
|
|
|
|
|
+ inboundItem.setAvailableQty(newInQty.subtract(outQty));
|
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 应用出库退回对批次的影响(减少 outQty)
|
|
* 应用出库退回对批次的影响(减少 outQty)
|
|
|
*/
|
|
*/
|
|
|
- private void applyOutboundReturnToBatch(MaterialInboundOrderItemDO inboundItem, int returnQty) {
|
|
|
|
|
- int outQty = inboundItem.getOutQty() == null ? 0 : inboundItem.getOutQty();
|
|
|
|
|
- int availableQty = inboundItem.getAvailableQty() == null ? 0 : inboundItem.getAvailableQty();
|
|
|
|
|
-
|
|
|
|
|
- int newOutQty = outQty - returnQty;
|
|
|
|
|
- if (newOutQty < 0) {
|
|
|
|
|
|
|
+ private void applyOutboundReturnToBatch(MaterialInboundOrderItemDO inboundItem, BigDecimal returnQty) {
|
|
|
|
|
+ BigDecimal outQty = inboundItem.getOutQty() == null ? BigDecimal.ZERO : inboundItem.getOutQty();
|
|
|
|
|
+ BigDecimal availableQty = inboundItem.getAvailableQty() == null ? BigDecimal.ZERO : inboundItem.getAvailableQty();
|
|
|
|
|
+ BigDecimal newOutQty = outQty.subtract(returnQty);
|
|
|
|
|
+ if (newOutQty.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量不能大于该批次已出库数量");
|
|
throw exceptionCustomMsg(COMMON_NOT_FOUND, "退回数量不能大于该批次已出库数量");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inboundItem.setOutQty(newOutQty);
|
|
inboundItem.setOutQty(newOutQty);
|
|
|
- inboundItem.setAvailableQty(availableQty + returnQty);
|
|
|
|
|
|
|
+ inboundItem.setAvailableQty(availableQty.add(returnQty));
|
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 回滚出库退回对批次的影响(恢复 outQty)
|
|
* 回滚出库退回对批次的影响(恢复 outQty)
|
|
|
*/
|
|
*/
|
|
|
- private void rollbackOutboundReturnOnBatch(MaterialInboundOrderItemDO inboundItem, int returnQty) {
|
|
|
|
|
- int outQty = inboundItem.getOutQty() == null ? 0 : inboundItem.getOutQty();
|
|
|
|
|
- int availableQty = inboundItem.getAvailableQty() == null ? 0 : inboundItem.getAvailableQty();
|
|
|
|
|
- inboundItem.setOutQty(outQty + returnQty);
|
|
|
|
|
- inboundItem.setAvailableQty(availableQty - returnQty);
|
|
|
|
|
|
|
+ private void rollbackOutboundReturnOnBatch(MaterialInboundOrderItemDO inboundItem, BigDecimal returnQty) {
|
|
|
|
|
+ BigDecimal outQty = inboundItem.getOutQty() == null ? BigDecimal.ZERO : inboundItem.getOutQty();
|
|
|
|
|
+ BigDecimal availableQty = inboundItem.getAvailableQty() == null ? BigDecimal.ZERO : inboundItem.getAvailableQty();
|
|
|
|
|
+ inboundItem.setOutQty(outQty.add(returnQty));
|
|
|
|
|
+ inboundItem.setAvailableQty(availableQty.subtract(returnQty));
|
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
inboundOrderItemMapper.updateById(inboundItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2420,7 +2418,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (!Objects.equals(StringUtils.trimToEmpty(head.getRemark()), StringUtils.trimToEmpty(row.getRemark()))) {
|
|
if (!Objects.equals(StringUtils.trimToEmpty(head.getRemark()), StringUtils.trimToEmpty(row.getRemark()))) {
|
|
|
throw new IllegalArgumentException("同单号的备注必须一致");
|
|
throw new IllegalArgumentException("同单号的备注必须一致");
|
|
|
}
|
|
}
|
|
|
- if (row.getQuantity() == null || row.getQuantity() <= 0) {
|
|
|
|
|
|
|
+ if (row.getQuantity() == null || row.getQuantity().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
throw new IllegalArgumentException("入库明细数量必须填写且数量大于0");
|
|
throw new IllegalArgumentException("入库明细数量必须填写且数量大于0");
|
|
|
}
|
|
}
|
|
|
Long materialId = resolveMaterialId(row.getMaterialNumber(), null);
|
|
Long materialId = resolveMaterialId(row.getMaterialNumber(), null);
|
|
@@ -2474,7 +2472,7 @@ public class MaterialIoServiceImpl implements MaterialIoService {
|
|
|
if (!Objects.equals(StringUtils.trimToEmpty(head.getRemark()), StringUtils.trimToEmpty(row.getRemark()))) {
|
|
if (!Objects.equals(StringUtils.trimToEmpty(head.getRemark()), StringUtils.trimToEmpty(row.getRemark()))) {
|
|
|
throw new IllegalArgumentException("同单号的备注必须一致");
|
|
throw new IllegalArgumentException("同单号的备注必须一致");
|
|
|
}
|
|
}
|
|
|
- if (row.getQuantity() == null || row.getQuantity() <= 0) {
|
|
|
|
|
|
|
+ if (row.getQuantity() == null || row.getQuantity().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
throw new IllegalArgumentException("出库明细数量必须填写且数量大于0");
|
|
throw new IllegalArgumentException("出库明细数量必须填写且数量大于0");
|
|
|
}
|
|
}
|
|
|
|
|
|