维修管理优化 逻辑处理优化
This commit is contained in:
parent
8925b54d9c
commit
59d82ace10
|
|
@ -91,19 +91,19 @@ public class RepairServiceImpl implements RepairService {
|
||||||
try {
|
try {
|
||||||
BeanUtil.copyProperties(item, repairDeviceVO);
|
BeanUtil.copyProperties(item, repairDeviceVO);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 记录异常日志,并提供更详细的错误信息
|
|
||||||
System.err.println("复制属性时发生错误: {}" + e.getMessage());
|
System.err.println("复制属性时发生错误: {}" + e.getMessage());
|
||||||
throw new RuntimeException("复制属性时发生错误", e);
|
throw new RuntimeException("复制属性时发生错误", e);
|
||||||
}
|
}
|
||||||
if (item.getTypeNameId() == null) {
|
if (item.getTypeNameId() == null) {
|
||||||
// 处理 typeNameId 为空的情况
|
|
||||||
System.err.println("typeNameId 为空,跳过当前项: " + item);
|
System.err.println("typeNameId 为空,跳过当前项: " + item);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resultMap.computeIfAbsent(item.getTypeNameId(), origin -> item).getRepairDeviceList().add(repairDeviceVO);
|
resultMap.computeIfAbsent(item.getTypeNameId(), origin -> item).getRepairDeviceList().add(repairDeviceVO);
|
||||||
|
|
||||||
resultMap.computeIfPresent(item.getTypeNameId(), (origin, novel) -> {
|
resultMap.computeIfPresent(item.getTypeNameId(), (origin, novel) -> {
|
||||||
novel.setTotalCost(novel.getTotalCost().add(Optional.ofNullable(item.getTotalCost()).orElse(BigDecimal.ZERO)));
|
novel.setTotalCost(Optional.ofNullable(novel.getTotalCost()).orElse(BigDecimal.ZERO)
|
||||||
|
.add(Optional.ofNullable(item.getTotalCost()).orElse(BigDecimal.ZERO))
|
||||||
|
);
|
||||||
return novel;
|
return novel;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -150,17 +150,17 @@ public class RepairServiceImpl implements RepairService {
|
||||||
|
|
||||||
public static List<RepairPart> mergePartsNum(@NotNull List<RepairPart> devices) {
|
public static List<RepairPart> mergePartsNum(@NotNull List<RepairPart> devices) {
|
||||||
try {
|
try {
|
||||||
Map<String, RepairPart> map = devices.stream().filter(Objects::nonNull).collect(
|
Map<String, RepairPart> map = devices.stream().filter(Objects::nonNull).collect(
|
||||||
Collectors.toConcurrentMap(device -> device.getTypeId() + ":" + device.getPartCost() + ":" + device.getPartName(),
|
Collectors.toConcurrentMap(device -> device.getTypeId() + ":" + device.getPartCost() + ":" + device.getPartName(),
|
||||||
device -> device, (existing, recently) -> {
|
device -> device, (existing, recently) -> {
|
||||||
existing.setPartNum(existing.getPartNum() + recently.getPartNum());
|
existing.setPartNum(existing.getPartNum() + recently.getPartNum());
|
||||||
return existing;
|
return existing;
|
||||||
}, ConcurrentHashMap::new)
|
}, ConcurrentHashMap::new)
|
||||||
);
|
);
|
||||||
List<RepairPart> list = new ArrayList<>(map.values());
|
List<RepairPart> list = new ArrayList<>(map.values());
|
||||||
list.forEach(item -> {
|
list.forEach(item -> item.setPartCost(Optional.ofNullable(item.getPartPrice()).orElse(BigDecimal.ZERO)
|
||||||
item.setPartCost(Optional.ofNullable(item.getPartPrice()).orElse(BigDecimal.ZERO).multiply(new BigDecimal(item.getPartNum())));
|
.multiply(new BigDecimal(Optional.ofNullable(item.getPartNum()).orElse(0))))
|
||||||
});
|
);
|
||||||
return list;
|
return list;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException("Error merging parts" + e.getMessage());
|
throw new ServiceException("Error merging parts" + e.getMessage());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue