|
@@ -537,27 +537,39 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
String platform = PlatformContext.getPlatform();
|
|
String platform = PlatformContext.getPlatform();
|
|
|
|
|
+ // 1. 提前校验名称是否存在 (核心修改点)
|
|
|
|
|
+ String customerName = bo.getCustomerName();
|
|
|
|
|
+ if (customerName == null || customerName.trim().isEmpty()) {
|
|
|
|
|
+ throw new IllegalArgumentException("客户名称不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- boolean isNew = bo.getId() == null || bo.getId() <= 0;
|
|
|
|
|
|
|
+ // 构造查询条件
|
|
|
|
|
+ LambdaQueryWrapper<CustomerInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(CustomerInfo::getCustomerName, customerName.trim());
|
|
|
|
|
|
|
|
- // 1. 处理主表 CustomerInfo
|
|
|
|
|
- CustomerInfo entity = MapstructUtils.convert(bo, CustomerInfo.class);
|
|
|
|
|
- validEntityBeforeSave(entity);
|
|
|
|
|
|
|
+ // 执行查询
|
|
|
|
|
+ CustomerInfo existingCustomer = baseMapper.selectOne(queryWrapper);
|
|
|
|
|
|
|
|
- boolean success;
|
|
|
|
|
|
|
+ boolean isNew = bo.getId() == null || bo.getId() <= 0;
|
|
|
|
|
+ CustomerInfo entity = null;
|
|
|
if (isNew) {
|
|
if (isNew) {
|
|
|
- success = baseMapper.insert(entity) > 0;
|
|
|
|
|
- if (success) {
|
|
|
|
|
|
|
+ // --- 新增场景 ---
|
|
|
|
|
+ if (existingCustomer != null) {
|
|
|
|
|
+ // 数据库中已存在同名用户
|
|
|
|
|
+ throw new IllegalArgumentException("客户名称不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 不存在,继续执行插入
|
|
|
|
|
+ entity = MapstructUtils.convert(bo, CustomerInfo.class);
|
|
|
|
|
+
|
|
|
|
|
+ int insertResult = baseMapper.insert(entity);
|
|
|
|
|
+ if (insertResult > 0) {
|
|
|
bo.setId(entity.getId()); // 回填ID
|
|
bo.setId(entity.getId()); // 回填ID
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- success = baseMapper.updateById(entity) > 0;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if (!success) {
|
|
|
|
|
- return false;
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
Long customerId = entity.getId();
|
|
Long customerId = entity.getId();
|
|
|
|
|
|
|
|
/*新增客户时给每个客户创建自己的组织架构*/
|
|
/*新增客户时给每个客户创建自己的组织架构*/
|