修复 5.保存后的入库总金额和入库完后的总金额显示不一样(按照原进价核算的价格)
This commit is contained in:
1 parent
3c315f3ea0
commit
d98640df99
1 file changed
+17
-9
+17
-9
@@ -230,17 +230,26 @@ public class SmErpInventoryRecordsServiceImpl extends ServiceImpl<SmErpInventory
|
||||
List<SmErpInventoryRecordsItemEntity> cgPlanItemEntities = smErpInventoryRecordsItemMapper.selectList(smErpCgPlanItemEntityLambdaQueryWrapper);
|
||||
|
||||
// 按 inventoryId 分组并计算每个分组的 totalAmount 总和
|
||||
Map<Long, Integer> inventoryTotalAmountMap = cgPlanItemEntities.stream()
|
||||
// Map<Long, Integer> inventoryTotalAmountMap = cgPlanItemEntities.stream()
|
||||
// .collect(Collectors.groupingBy(
|
||||
// SmErpInventoryRecordsItemEntity::getInventoryId,
|
||||
// Collectors.summingInt(item ->
|
||||
// (int) (Math.abs(item.getQuantity()) * (item.getRealPrice()))
|
||||
// )
|
||||
// );
|
||||
|
||||
Map<Long, List<SmErpInventoryRecordsItemEntity>> smerpInventoryRecordsItemEntityMap= cgPlanItemEntities.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
SmErpInventoryRecordsItemEntity::getInventoryId,
|
||||
Collectors.summingInt(item ->
|
||||
(int) (Math.abs(item.getQuantity()) * item.getUnitPrice())
|
||||
)
|
||||
));
|
||||
SmErpInventoryRecordsItemEntity::getInventoryId));
|
||||
|
||||
// 将计算出的 totalAmount 总和设置回 pageData 的 records 中
|
||||
records.forEach(record -> {
|
||||
Integer totalAmount = inventoryTotalAmountMap.getOrDefault(record.getId(), 0);
|
||||
record.setTotalAmount(totalAmount);
|
||||
// if
|
||||
// Integer totalAmount = inventoryTotalAmountMap.getOrDefault(record.getId(), 0);
|
||||
List<SmErpInventoryRecordsItemEntity> smErpInventoryRecordsItemEntityList = smerpInventoryRecordsItemEntityMap.get(record.getId());
|
||||
// record.setTotalAmount(totalAmount);
|
||||
//todo 这里有一个问题就是出入库编辑的时候,没有更新主表的totalAmount,所以一直用的子表的totalAmount,子表的totalAmount又存在为空的情况,涉及到多个业务
|
||||
record.setTotalAmount(smErpInventoryRecordsItemEntityList.stream().mapToInt(item -> item.getTotalAmount()==null?0:item.getTotalAmount()).sum());
|
||||
});
|
||||
|
||||
Set<Long> erpSpuIds = cgPlanItemEntities.stream().map(SmErpInventoryRecordsItemEntity::getErpSpuId).collect(Collectors.toSet());
|
||||
@@ -477,7 +486,6 @@ public class SmErpInventoryRecordsServiceImpl extends ServiceImpl<SmErpInventory
|
||||
Set<Long> units = items.stream().map(s -> s.getUnitId()).collect(Collectors.toSet());
|
||||
List<SmErpUnitEntity> smErpUnitEntities = smErpUnitMapper.selectList(new LambdaQueryWrapper<SmErpUnitEntity>().in(SmErpUnitEntity::getId, units));
|
||||
Map<Long, SmErpUnitEntity> unitMap = smErpUnitEntities.stream().collect(Collectors.toMap(SmErpUnitEntity::getId, unit -> unit));
|
||||
|
||||
for (InventoryRecordEditItemDTO item : items){
|
||||
SmErpInventoryRecordsItemEntity smErpInventoryRecordsItemEntity = new SmErpInventoryRecordsItemEntity();
|
||||
org.springframework.beans.BeanUtils.copyProperties(item,smErpInventoryRecordsItemEntity);
|
||||
|
||||
Reference in new issue
Block a user