Ver código fonte

fix(customer): 修复客户信息管理中的异常处理和剩余配额计算问题

- 添加 ObjectUtils 导入用于空值检查
- 修复客户销售信息中剩余配额的计算逻辑
- 修复新增客户失败时的异常抛出机制
- 添加客户编号用于联系人编号生成
- 修复销售信息中剩余配额的赋值逻辑
- 添加联系人编号的自动生成功能
hurx 3 semanas atrás
pai
commit
9483fbabb4

+ 13 - 7
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerInfoServiceImpl.java

@@ -16,6 +16,7 @@ import org.dromara.common.core.enums.IsDefault;
 import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.DateUtils;
 import org.dromara.common.core.utils.MapstructUtils;
+import org.dromara.common.core.utils.ObjectUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -122,7 +123,9 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
             vo.setCustomerSalesInfoVo(null);
             return vo;
         }
-
+        if (ObjectUtils.isNotEmpty(customerSalesInfo.getCreditAmount()) && ObjectUtils.isNotEmpty(customerSalesInfo.getTemporaryQuota())) {
+            customerSalesInfo.setRemainingQuota(customerSalesInfo.getCreditAmount().add(customerSalesInfo.getTemporaryQuota()));
+        }
         Set<Long> staffIds = new HashSet<>();
         Set<Long> deptIds = new HashSet<>();
 
@@ -540,7 +543,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
             // 1. 提前校验名称是否存在 (核心修改点)
             String customerName = bo.getCustomerName();
             if (customerName == null || customerName.trim().isEmpty()) {
-                throw new IllegalArgumentException("客户名称不能为空");
+                throw new ServiceException("客户名称不能为空");
             }
 
             // 构造查询条件
@@ -556,7 +559,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
                 // --- 新增场景 ---
                 if (existingCustomer != null) {
                     // 数据库中已存在同名用户
-                    throw new IllegalArgumentException("该客户已存在,请勿重复添加");
+                    throw new ServiceException("该客户已存在,请勿重复添加");
                 }
                 // 不存在,继续执行插入
                 entity = MapstructUtils.convert(bo, CustomerInfo.class);
@@ -564,14 +567,15 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
                 int insertResult = baseMapper.insert(entity);
                 if (insertResult > 0) {
                     bo.setId(entity.getId()); // 回填ID
-                    return true;
                 } else {
-                    return false;
+                    throw new ServiceException("新增客户信息失败");
                 }
 
             }
             Long customerId = entity.getId();
 
+            String customerNo = entity.getCustomerNo();
+
             /*新增客户时给每个客户创建自己的组织架构*/
             RemoteDeptVo remoteDeptVo = new RemoteDeptVo();
             remoteDeptVo.setParentId(100L);
@@ -615,6 +619,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
 
             // 销售信息
             if (salesBo != null) {
+                salesBo.setRemainingQuota(salesBo.getCreditAmount());
                 CustomerSalesInfo salesEntity = MapstructUtils.convert(salesBo, CustomerSalesInfo.class);
                 salesEntity.setCustomerId(customerId);
                 customerSalesInfoMapper.insert(salesEntity);
@@ -642,10 +647,11 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
                     // 3. 转换并填充业务联系人数据
                     CustomerContact contact = MapstructUtils.convert(contactBo, CustomerContact.class);
                     contact.setCustomerId(customerId);
-
+                    String seqId = SequenceUtils.nextPaddedIdStr(CONTACT_NO_KEY, Duration.ofDays(3650), 3);
+                    String contactNo = customerNo + seqId;
                     // 建立关联
                     contact.setUserId(userId);
-
+                    contact.setContactNo(contactNo);
                     // 4. 插入联系人表
                     if (customerContactMapper.insert(contact) <= 0) {
                         throw new ServiceException("保存联系人信息失败");