Prechádzať zdrojové kódy

refactor: optimize SysCustomerPersonService logic, implement entity comparison for audit logging, and fix mapping field in SysCustomerDataService.

张旭锋 1 mesiac pred
rodič
commit
5de0be781a

+ 19 - 19
src/main/java/com/jtzx/crm/module/sys/entity/SysCustomerDataEntity.java

@@ -109,7 +109,7 @@ public class SysCustomerDataEntity extends HelioBaseEntity<Long> {
     @TableField("del_flag")
     private Integer delFlag;
 
-        /**
+    /**
      * 比较实体变化
      * @param dto 更新的数据
      * @return 变化的字符串,分为两个部分,前部分为原来的信息,后部分为修改后的信息,用","隔开
@@ -117,41 +117,41 @@ public class SysCustomerDataEntity extends HelioBaseEntity<Long> {
      */
     public String compareTo(AdminSysCustomerDataInsertOrUpdateDTO dto) {
         // 1. 先收集所有的变更,存放在集合中,如果为空,则说明没有变更,直接返回空字符串
-        List<String> changesOld = Lists.newArrayList();
-        List<String> changesNew = Lists.newArrayList();
+        StringBuilder original = new StringBuilder();
+        StringBuilder update = new StringBuilder();
 
         // 2. 挨个比较字段,把不一致的变更加到集合里
         if (this.name != null && !this.name.equals(dto.getName())) {
-            changesOld.add("学校名称【" + this.name + "】");
-            changesNew.add("学校名称【" + dto.getName() + "】");
+            original.append("学校名称【").append(this.name).append("】");
+            update.append("学校名称【").append(dto.getName()).append("】");
         }
 
         if (this.stageName != null && !this.stageName.equals(dto.getStageName())) {
-            changesOld.add("学段名称【" + this.stageName + "】");
-            changesNew.add("学段名称【" + dto.getStageName() + "】");
+            original.append("学段名称【").append(this.stageName).append("】");
+            update.append("学段名称【").append(dto.getStageName()).append("】");
         }
 
         if (this.provinceName != null && !this.provinceName.equals(dto.getProvinceName())) {
-            changesOld.add("省份名称【" + this.provinceName + "】");
-            changesNew.add("省份名称【" + dto.getProvinceName() + "】");
+            original.append("省份名称【").append(this.provinceName).append("】");
+            update.append("省份名称【").append(dto.getProvinceName()).append("】");
         }
 
         if (this.cityName != null && !this.cityName.equals(dto.getCityName())) {
-            changesOld.add("城市名称【" + this.cityName + "】");
-            changesNew.add("城市名称【" + dto.getCityName() + "】");
+            original.append("城市名称【").append(this.cityName).append("】");
+            update.append("城市名称【").append(dto.getCityName()).append("】");
         }
 
         if (this.address != null && !this.address.equals(dto.getAddress())) {
-            changesOld.add("地址【" + this.address + "】");
-            changesNew.add("地址【" + dto.getAddress() + "】");
+            original.append("地址【").append(this.address).append("】");
+            update.append("地址【").append(dto.getAddress()).append("】");
         }
-
         // 3. 用逗号连接所有变更,生成最终字符串
-        if (changesOld.isEmpty() && changesNew.isEmpty()) {
-            return null;
-        } else {
-            return String.join("", changesOld) + "," + String.join("", changesNew);
-        }
+        return original + "," + update;
     }
 
+    public String getStr() {
+        //把参数名和值转为字符串
+        return "学校名称【" + this.name + "】学段名称【" + this.stageName + "】省份名称【" + this.provinceName
+                + "】城市名称【" + this.cityName + "】地址【" + this.address + "】";
+    }
 }

+ 20 - 1
src/main/java/com/jtzx/crm/module/sys/entity/SysCustomerFollowEntity.java

@@ -1,8 +1,12 @@
 package com.jtzx.crm.module.sys.entity;
 
+import cc.uncarbon.framework.core.exception.BusinessException;
 import cc.uncarbon.framework.crud.entity.HelioBaseEntity;
 import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableName;
+import com.jtzx.crm.module.sys.model.request.AdmcnSysCustomerDataInsertOrUpdateDTO;
+import iom.baomidou.mybatisplus.annotation.TableName;
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerFollowInsertOrUpdateDTO;
+
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -133,4 +137,19 @@ public class SysCustomerFollowEntity extends HelioBaseEntity<Long> {
     @Schema(description = "逻辑删除标识", title = "0=否 1=是")
     @TableField("del_flag")
     private Integer delFlag;
+
+    /**
+     * 从公海认领的记录
+     */
+    public String getCustomString() {
+        return "将【" + this.productName + "】从公海认领";
+    }
+
+
+    /**
+     * 退回公海的记录
+     */
+    public String returnCustomString() {
+        return "将【" + this.productName + "】转至公海";
+    }
 }

+ 59 - 4
src/main/java/com/jtzx/crm/module/sys/entity/SysCustomerPersonEntity.java

@@ -3,13 +3,16 @@ package com.jtzx.crm.module.sys.entity;
 import cc.uncarbon.framework.crud.entity.HelioBaseEntity;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.*;
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonInsertOrUpdateDTO;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 import lombok.experimental.SuperBuilder;
-import io.swagger.v3.oas.annotations.media.Schema;
 
-import java.time.LocalDate;
-import java.time.LocalDateTime;
+import java.util.Objects;
 
 
 /**
@@ -56,4 +59,56 @@ public class SysCustomerPersonEntity extends HelioBaseEntity<Long> {
     @TableField("del_flag")
     private Integer delFlag;
 
+    /**
+     * 编辑联系人时使用
+     * @param dto
+     * @return
+     */
+    public String compareTo(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
+        StringBuilder original = new StringBuilder();
+        StringBuilder update = new StringBuilder();
+
+        // 1. 姓名
+        if (!Objects.equals(this.name, dto.getName())) {
+            original.append("姓名【").append(this.name).append("】");
+            update.append("姓名【").append(dto.getName()).append("】");
+        }
+
+        // 2. 职务名称
+        if (!Objects.equals(this.positionName, dto.getPositionName())) {
+            original.append("职务名称【").append(this.positionName).append("】");
+            update.append("职务名称【").append(dto.getPositionName()).append("】");
+        }
+
+        // 3. 手机号
+        if (!Objects.equals(this.phoneNo, dto.getPhoneNo())) {
+            original.append("手机号【").append(this.phoneNo).append("】");
+            update.append("手机号【").append(dto.getPhoneNo()).append("】");
+        }
+
+        // 4. 办公电话
+        if (!Objects.equals(this.officePhoneNo, dto.getOfficePhoneNo())) {
+            original.append("办公电话【").append(this.officePhoneNo).append("】");
+            update.append("办公电话【").append(dto.getOfficePhoneNo()).append("】");
+        }
+
+        // 5. 备注
+        if (!Objects.equals(this.remark, dto.getRemark())) {
+            original.append("备注【").append(this.remark).append("】");
+            update.append("备注【").append(dto.getRemark()).append("】");
+        }
+
+        return original + "," + update;
+    }
+
+
+    /**
+     * 删除联系人时使用
+     * @return
+     */
+    public String getStr() {
+        //把参数名和值转为字符串
+        return "姓名【" + this.name + "】职务名称【" + this.positionName + "】手机号【" + this.phoneNo
+                + "】办公电话【" + this.officePhoneNo + "】备注【" + this.remark + "】";
+    }
 }

+ 28 - 10
src/main/java/com/jtzx/crm/module/sys/model/request/AdminSysCustomerFollowInsertOrUpdateDTO.java

@@ -1,16 +1,14 @@
 package com.jtzx.crm.module.sys.model.request;
 
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.Size;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 import lombok.experimental.SuperBuilder;
-import jakarta.validation.constraints.NotBlank;
-import jakarta.validation.constraints.NotNull;
-import jakarta.validation.constraints.Size;
+
 import java.io.Serializable;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
 
 
@@ -27,23 +25,23 @@ public class AdminSysCustomerFollowInsertOrUpdateDTO implements Serializable {
     @Schema(description = "主键ID", hidden = true, title = "仅更新时使用")
     private Long id;
 
-    @Schema(description = "认领人(跟进)id")
+    @Schema(description = "认领人(跟进)id", hidden = true)
     private Long claimUserId;
 
-    @Schema(description = "认领人(跟进)名称")
+    @Schema(description = "认领人(跟进)名称", hidden = true)
     @Size(max = 255, message = "【认领人(跟进)名称】最长255位")
     private String claimUserName;
 
-    @Schema(description = "认领人员所在的项目组id")
+    @Schema(description = "认领人员所在的项目组id", hidden = true)
     private Long claimUserGroupId;
 
-    @Schema(description = "跟进时间")
+    @Schema(description = "跟进时间", hidden = true)
     private LocalDateTime claimDatetime;
 
     @Schema(description = "客户表主id")
     private Long customerId;
 
-    @Schema(description = "客户名称")
+    @Schema(description = "客户名称", hidden = true)
     private String customerName;
 
     @Schema(description = "产品id(param_base_data表主id)")
@@ -60,7 +58,7 @@ public class AdminSysCustomerFollowInsertOrUpdateDTO implements Serializable {
     @Size(max = 255, message = "【跟进状态的名称】最长255位")
     private String followName;
 
-    @Schema(description = "是否赢单,0-否,1-是")
+    @Schema(description = "是否赢单,0-否,1-是", hidden = true)
     private Integer successStatus;
 
     @Schema(description = "联系人id(customer_person表主id)")
@@ -94,4 +92,24 @@ public class AdminSysCustomerFollowInsertOrUpdateDTO implements Serializable {
     @Size(max = 5000, message = "【预约取消原因】最长5000位")
     private String cancelRemark;
 
+
+    @Schema(description = "学段id(param_base_data表主id)", hidden = true)
+    private Long stageId;
+
+    @Schema(description = "学段名称", hidden = true)
+    private String stageName;
+
+    @Schema(description = "省份id(省份表主id)", hidden = true)
+    private Long provinceId;
+
+    @Schema(description = "省份名称", hidden = true)
+    private String provinceName;
+
+    @Schema(description = "城市id(城市表主id)", hidden = true)
+    private Long cityId;
+
+    @Schema(description = "城市名称", hidden = true)
+    private String cityName;
+
+
 }

+ 11 - 5
src/main/java/com/jtzx/crm/module/sys/model/request/AdminSysCustomerPersonInsertOrUpdateDTO.java

@@ -1,17 +1,14 @@
 package com.jtzx.crm.module.sys.model.request;
 
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.Size;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 import lombok.experimental.SuperBuilder;
-import jakarta.validation.constraints.NotBlank;
-import jakarta.validation.constraints.NotNull;
-import jakarta.validation.constraints.Size;
+
 import java.io.Serializable;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
 
 
 /**
@@ -53,4 +50,13 @@ public class AdminSysCustomerPersonInsertOrUpdateDTO implements Serializable {
     @Size(max = 2000, message = "【备注】最长2000位")
     private String remark;
 
+    /**
+     *
+     * 新增联系人时使用
+     */
+    public String getStr() {
+        //把参数名和值转为字符串
+        return "姓名【" + this.name + "】职务名称【" + this.positionName + "】手机号【" + this.phoneNo
+                + "】办公电话【" + this.officePhoneNo + "】备注【" + this.remark + "】";
+    }
 }

+ 1 - 1
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataService.java

@@ -173,7 +173,7 @@ public class SysCustomerDataService {
                     .provinceName(entity.getProvinceName())
                     .cityId(entity.getCityId())
                     .cityName(entity.getCityName())
-                    .content(entity.getName())
+                    .content(entity.getStr())
                     .build();
             if (userGroupRelation != null) {
                 logEntity.setOperUserGroupId(userGroupRelation.getGroupId());

+ 12 - 51
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerPersonService.java

@@ -1,19 +1,18 @@
 package com.jtzx.crm.module.sys.service;
 
-import cc.uncarbon.framework.core.constant.HelioConstant;
 import cc.uncarbon.framework.core.exception.BusinessException;
 import cc.uncarbon.framework.core.page.PageParam;
 import cc.uncarbon.framework.core.page.PageResult;
-import com.jtzx.crm.module.sys.entity.SysCustomerPersonEntity;
-import com.jtzx.crm.module.sys.mapper.SysCustomerPersonMapper;
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonInsertOrUpdateDTO;
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonListDTO;
-import com.jtzx.crm.module.sys.model.response.SysCustomerPersonBO;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.text.CharSequenceUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jtzx.crm.module.sys.entity.SysCustomerPersonEntity;
+import com.jtzx.crm.module.sys.mapper.SysCustomerPersonMapper;
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonInsertOrUpdateDTO;
+import com.jtzx.crm.module.sys.model.request.AdminSysCustomerPersonListDTO;
+import com.jtzx.crm.module.sys.model.response.SysCustomerPersonBO;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -64,29 +63,18 @@ public class SysCustomerPersonService {
         return this.entityPage2BOPage(entityPage);
     }
 
-    /**
-     * 根据 ID 取详情
-     *
-     * @param id 主键ID
-     * @return null or BO
-     */
-    public SysCustomerPersonBO getOneById(Long id) {
-        return this.getOneById(id, false);
-    }
 
     /**
      * 根据 ID 取详情
      *
      * @param id 主键ID
-     * @param throwIfInvalidId 是否在 ID 无效时抛出异常
      * @return null or BO
      */
-    public SysCustomerPersonBO getOneById(Long id, boolean throwIfInvalidId) throws BusinessException {
+    public SysCustomerPersonBO getOneById(Long id) throws BusinessException {
         SysCustomerPersonEntity entity = sysCustomerPersonMapper.selectById(id);
-        if (throwIfInvalidId && entity == null) {
+        if (entity == null) {
             throw new BusinessException(400, "无效客户(学校)联系人数据ID");
         }
-
         return this.entity2BO(entity);
     }
 
@@ -96,8 +84,6 @@ public class SysCustomerPersonService {
     @Transactional(rollbackFor = Exception.class)
     public Long adminInsert(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
         log.info("[后台管理-客户(学校)联系人数据-新增] >> DTO={}", dto);
-        this.checkExistence(dto);
-
         dto.setId(null);
         SysCustomerPersonEntity entity = new SysCustomerPersonEntity();
         BeanUtil.copyProperties(dto, entity);
@@ -113,7 +99,6 @@ public class SysCustomerPersonService {
     @Transactional(rollbackFor = Exception.class)
     public void adminUpdate(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
         log.info("[后台管理-客户(学校)联系人数据-编辑] >> DTO={}", dto);
-        this.checkExistence(dto);
 
         SysCustomerPersonEntity entity = new SysCustomerPersonEntity();
         BeanUtil.copyProperties(dto, entity);
@@ -170,7 +155,7 @@ public class SysCustomerPersonService {
         // 深拷贝
         List<SysCustomerPersonBO> ret = new ArrayList<>(entityList.size());
         entityList.forEach(
-            entity -> ret.add(this.entity2BO(entity))
+                entity -> ret.add(this.entity2BO(entity))
         );
 
         return ret;
@@ -184,33 +169,9 @@ public class SysCustomerPersonService {
      */
     private PageResult<SysCustomerPersonBO> entityPage2BOPage(Page<SysCustomerPersonEntity> entityPage) {
         return new PageResult<SysCustomerPersonBO>()
-            .setCurrent(entityPage.getCurrent())
-            .setSize(entityPage.getSize())
-            .setTotal(entityPage.getTotal())
-            .setRecords(this.entityList2BOs(entityPage.getRecords()));
-    }
-
-    /**
-     * 检查是否已存在同名数据
-     *
-     * @param dto DTO
-     */
-    private void checkExistence(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
-        /*
-        可以根据自己业务需要,解禁这段代码,修改判断条件和文案
-
-        SysCustomerPersonEntity existingEntity = sysCustomerPersonMapper.selectOne(
-                new QueryWrapper<SysCustomerPersonEntity>()
-                        .lambda()
-                        .select(SysCustomerPersonEntity::getId)
-                        .eq(SysCustomerPersonEntity::getTitle, dto.getTitle())
-                        .last(HelioConstant.CRUD.SQL_LIMIT_1)
-        );
-
-        if (existingEntity != null && !existingEntity.getId().equals(dto.getId())) {
-            throw new BusinessException(400, "已存在相同客户(学校)联系人数据,请重新输入");
-        }
-        */
+                .setCurrent(entityPage.getCurrent())
+                .setSize(entityPage.getSize())
+                .setTotal(entityPage.getTotal())
+                .setRecords(this.entityList2BOs(entityPage.getRecords()));
     }
-
 }