Commit b0abec2333d2bb0a9ee95f4248046d2695340b31

Authored by 曾国涛
1 parent c1876224

refactor(order): 优化订单成本信息编辑逻辑

- 修改了编辑逻辑,根据订单 ID 查询成本信息
- 使用 Optional 处理可能的空值情况,提高代码可读性
- 在复制属性时添加了忽略空值的选项,避免不必要的覆盖
src/main/java/com/order/erp/service/order/impl/OrderCostInfoServiceImpl.java
1 1 package com.order.erp.service.order.impl;
2 2  
3 3 import cn.hutool.core.bean.BeanUtil;
  4 +import cn.hutool.core.bean.copier.CopyOptions;
4 5 import cn.hutool.core.collection.CollUtil;
5 6 import com.alibaba.fastjson.JSONObject;
6 7 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
... ... @@ -36,10 +37,7 @@ import org.springframework.stereotype.Service;
36 37 import javax.annotation.Resource;
37 38 import java.math.BigDecimal;
38 39 import java.math.RoundingMode;
39   -import java.util.List;
40   -import java.util.Map;
41   -import java.util.Objects;
42   -import java.util.Set;
  40 +import java.util.*;
43 41 import java.util.stream.Collectors;
44 42  
45 43 /**
... ... @@ -67,14 +65,19 @@ public class OrderCostInfoServiceImpl extends ServiceImpl<OrderCostInfoMapper, O
67 65  
68 66 @Override
69 67 public ServerResult edit(OrderCostInfoVO vo) {
70   - Long id = vo.getId();
71   - OrderCostInfoDO byId = this.getById(id);
72   - if (Objects.isNull(byId)) {
73   - byId = BeanUtil.copyProperties(vo, OrderCostInfoDO.class);
  68 + Long id = vo.getOrderId();
  69 + Optional<OrderCostInfoDO> orderCostInfoDOOpt = this.lambdaQuery()
  70 + .eq(OrderCostInfoDO::getOrderId, id)
  71 + .last(" limit 1 ")
  72 + .oneOpt();
  73 + OrderCostInfoDO orderCostInfoDO = null;
  74 + if (!orderCostInfoDOOpt.isPresent()) {
  75 + orderCostInfoDO = BeanUtil.copyProperties(vo, OrderCostInfoDO.class);
74 76 }else {
75   - BeanUtil.copyProperties(vo, byId);
  77 + orderCostInfoDO = orderCostInfoDOOpt.get();
  78 + BeanUtil.copyProperties(vo, orderCostInfoDO, CopyOptions.create().ignoreNullValue());
76 79 }
77   - return ServerResult.success(this.saveOrUpdate(byId));
  80 + return ServerResult.success(this.saveOrUpdate(orderCostInfoDO));
78 81 }
79 82 @Override
80 83 public ServerResult applyEditFileds(OrderCostInfolockFieldVO vo) {
... ...