维修管理优化 逻辑处理优化

This commit is contained in:
syruan 2024-11-21 16:43:55 +08:00
parent 8925b54d9c
commit 59d82ace10
1 changed files with 8 additions and 8 deletions

View File

@ -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;
}); });
}); });
@ -158,9 +158,9 @@ public class RepairServiceImpl implements RepairService {
}, 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());