Kaynağa Gözat

refactor: remove unused admin list methods and simplify service insert/update logic

张旭锋 1 ay önce
ebeveyn
işleme
51e38be09e

+ 1 - 38
src/main/java/com/jtzx/crm/module/sys/model/request/AdminSysCustomerDataInsertOrUpdateDTO.java

@@ -22,7 +22,7 @@ import java.time.LocalDateTime;
 @Data
 public class AdminSysCustomerDataInsertOrUpdateDTO implements Serializable {
 
-    @Schema(description = "主键ID", hidden = true, title = "仅更新时使用")
+    @Schema(description = "主键ID", title = "仅更新时使用")
     private Long id;
 
     @Schema(description = "名称")
@@ -53,41 +53,4 @@ public class AdminSysCustomerDataInsertOrUpdateDTO implements Serializable {
     @Schema(description = "地址")
     @Size(max = 255, message = "【地址】最长255位")
     private String address;
-
-    @Schema(description = "放入公海时间")
-    private LocalDateTime resetDatetime;
-
-    @Schema(description = "认领人id")
-    private Long claimUserId;
-
-    @Schema(description = "认领人名称")
-    @Size(max = 255, message = "【认领人名称】最长255位")
-    private String claimUserName;
-
-    @Schema(description = "认领状态,0-否,1-是")
-    private Integer claimStatus;
-
-    @Schema(description = "认领时间")
-    private LocalDateTime claimDatetime;
-
-    @Schema(description = "认领人员所在的项目组id")
-    private Long claimUserGroupId;
-
-    @Schema(description = "跟进状态id,赢单状态id固定-37,方案演示id固定-33")
-    private Long followId;
-
-    @Schema(description = "跟进状态的名称")
-    @Size(max = 255, message = "【跟进状态的名称】最长255位")
-    private String followName;
-
-    @Schema(description = "赢单人id(不为null时为赢单人id)")
-    private Long successUserId;
-
-    @Schema(description = "赢单人名称(不为null时为赢单人名称)")
-    @Size(max = 255, message = "【赢单人名称(不为null时为赢单人名称)】最长255位")
-    private String successUserName;
-
-    @Schema(description = "是否赢单,0-否,1-是")
-    private Integer successStatus;
-
 }

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

@@ -1,24 +1,18 @@
 package com.jtzx.crm.module.sys.service;
 
 import cc.uncarbon.framework.core.exception.BusinessException;
-import cc.uncarbon.framework.core.page.PageParam;
-import cc.uncarbon.framework.core.page.PageResult;
 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.SysCustomerDataEntity;
 import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
 import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataInsertOrUpdateDTO;
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerDataListDTO;
 import com.jtzx.crm.module.sys.model.response.SysCustomerDataBO;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.*;
+import java.time.LocalDateTime;
+import java.util.Collection;
 
 
 /**
@@ -32,84 +26,17 @@ public class SysCustomerDataService {
     private final SysCustomerDataMapper sysCustomerDataMapper;
 
 
-    /**
-     * 后台管理-分页列表
-     */
-    public PageResult<SysCustomerDataBO> adminList(PageParam pageParam, AdminSysCustomerDataListDTO dto) {
-        Page<SysCustomerDataEntity> entityPage = sysCustomerDataMapper.selectPage(
-                new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
-                new QueryWrapper<SysCustomerDataEntity>()
-                        .lambda()
-                        // 名称
-                        .like(CharSequenceUtil.isNotBlank(dto.getName()), SysCustomerDataEntity::getName, CharSequenceUtil.cleanBlank(dto.getName()))
-                        // 学段id(param_base_data表主id)
-                        .eq(Objects.nonNull(dto.getStageId()), SysCustomerDataEntity::getStageId, dto.getStageId())
-                        // 学段名称
-                        .like(CharSequenceUtil.isNotBlank(dto.getStageName()), SysCustomerDataEntity::getStageName, CharSequenceUtil.cleanBlank(dto.getStageName()))
-                        // 省份id(省份表主id)
-                        .eq(Objects.nonNull(dto.getProvinceId()), SysCustomerDataEntity::getProvinceId, dto.getProvinceId())
-                        // 省份名称
-                        .like(CharSequenceUtil.isNotBlank(dto.getProvinceName()), SysCustomerDataEntity::getProvinceName, CharSequenceUtil.cleanBlank(dto.getProvinceName()))
-                        // 城市id(城市表主id)
-                        .eq(Objects.nonNull(dto.getCityId()), SysCustomerDataEntity::getCityId, dto.getCityId())
-                        // 城市名称
-                        .like(CharSequenceUtil.isNotBlank(dto.getCityName()), SysCustomerDataEntity::getCityName, CharSequenceUtil.cleanBlank(dto.getCityName()))
-                        // 地址
-                        .like(CharSequenceUtil.isNotBlank(dto.getAddress()), SysCustomerDataEntity::getAddress, CharSequenceUtil.cleanBlank(dto.getAddress()))
-                        // 放入公海时间
-                        .eq(Objects.nonNull(dto.getResetDatetime()), SysCustomerDataEntity::getResetDatetime, dto.getResetDatetime())
-                        // 认领人id
-                        .eq(Objects.nonNull(dto.getClaimUserId()), SysCustomerDataEntity::getClaimUserId, dto.getClaimUserId())
-                        // 认领人名称
-                        .like(CharSequenceUtil.isNotBlank(dto.getClaimUserName()), SysCustomerDataEntity::getClaimUserName, CharSequenceUtil.cleanBlank(dto.getClaimUserName()))
-                        // 认领状态,0-否,1-是
-                        .eq(Objects.nonNull(dto.getClaimStatus()), SysCustomerDataEntity::getClaimStatus, dto.getClaimStatus())
-                        // 认领时间
-                        .eq(Objects.nonNull(dto.getClaimDatetime()), SysCustomerDataEntity::getClaimDatetime, dto.getClaimDatetime())
-                        // 认领人员所在的项目组id
-                        .eq(Objects.nonNull(dto.getClaimUserGroupId()), SysCustomerDataEntity::getClaimUserGroupId, dto.getClaimUserGroupId())
-                        // 跟进状态id,赢单状态id固定-37,方案演示id固定-33
-                        .eq(Objects.nonNull(dto.getFollowId()), SysCustomerDataEntity::getFollowId, dto.getFollowId())
-                        // 跟进状态的名称
-                        .like(CharSequenceUtil.isNotBlank(dto.getFollowName()), SysCustomerDataEntity::getFollowName, CharSequenceUtil.cleanBlank(dto.getFollowName()))
-                        // 赢单人id(不为null时为赢单人id)
-                        .eq(Objects.nonNull(dto.getSuccessUserId()), SysCustomerDataEntity::getSuccessUserId, dto.getSuccessUserId())
-                        // 赢单人名称(不为null时为赢单人名称)
-                        .like(CharSequenceUtil.isNotBlank(dto.getSuccessUserName()), SysCustomerDataEntity::getSuccessUserName, CharSequenceUtil.cleanBlank(dto.getSuccessUserName()))
-                        // 是否赢单,0-否,1-是
-                        .eq(Objects.nonNull(dto.getSuccessStatus()), SysCustomerDataEntity::getSuccessStatus, dto.getSuccessStatus())
-                        // 时间区间
-                        .between(Objects.nonNull(dto.getBeginAt()) && Objects.nonNull(dto.getEndAt()), SysCustomerDataEntity::getCreatedAt, dto.getBeginAt(), dto.getEndAt())
-                        // 排序
-                        .orderByDesc(SysCustomerDataEntity::getCreatedAt)
-        );
-
-        return this.entityPage2BOPage(entityPage);
-    }
-
     /**
      * 根据 ID 取详情
      *
      * @param id 主键ID
      * @return null or BO
      */
-    public SysCustomerDataBO getOneById(Long id) {
-        return this.getOneById(id, false);
-    }
-
-    /**
-     * 根据 ID 取详情
-     *
-     * @param id 主键ID
-     * @param throwIfInvalidId 是否在 ID 无效时抛出异常
-     * @return null or BO
-     */
-    public SysCustomerDataBO getOneById(Long id, boolean throwIfInvalidId) throws BusinessException {
+    public SysCustomerDataBO getOneById(Long id) throws BusinessException {
         SysCustomerDataEntity entity = sysCustomerDataMapper.selectById(id);
-        if (throwIfInvalidId && entity == null) {
+        if (entity == null) {
             throw new BusinessException(400, "无效客户(学校)数据ID");
         }
-
         return this.entity2BO(entity);
     }
 
@@ -119,14 +46,14 @@ public class SysCustomerDataService {
     @Transactional(rollbackFor = Exception.class)
     public Long adminInsert(AdminSysCustomerDataInsertOrUpdateDTO dto) {
         log.info("[后台管理-客户(学校)数据-新增] >> DTO={}", dto);
-        this.checkExistence(dto);
-
         dto.setId(null);
         SysCustomerDataEntity entity = new SysCustomerDataEntity();
         BeanUtil.copyProperties(dto, entity);
-
+        entity.setResetDatetime(LocalDateTime.now());
+        entity.setClaimStatus(0);
+        entity.setSuccessStatus(0);
         sysCustomerDataMapper.insert(entity);
-
+        //TODO 添加操作日志
         return entity.getId();
     }
 
@@ -136,12 +63,10 @@ public class SysCustomerDataService {
     @Transactional(rollbackFor = Exception.class)
     public void adminUpdate(AdminSysCustomerDataInsertOrUpdateDTO dto) {
         log.info("[后台管理-客户(学校)数据-编辑] >> DTO={}", dto);
-        this.checkExistence(dto);
-
         SysCustomerDataEntity entity = new SysCustomerDataEntity();
         BeanUtil.copyProperties(dto, entity);
-
         sysCustomerDataMapper.updateById(entity);
+        //TODO 添加操作日志
     }
 
     /**
@@ -179,61 +104,4 @@ public class SysCustomerDataService {
         return bo;
     }
 
-    /**
-     * 实体 List 转 BO List
-     *
-     * @param entityList 实体 List
-     * @return BO List
-     */
-    private List<SysCustomerDataBO> entityList2BOs(List<SysCustomerDataEntity> entityList) {
-        if (CollUtil.isEmpty(entityList)) {
-            return Collections.emptyList();
-        }
-
-        // 深拷贝
-        List<SysCustomerDataBO> ret = new ArrayList<>(entityList.size());
-        entityList.forEach(
-            entity -> ret.add(this.entity2BO(entity))
-        );
-
-        return ret;
-    }
-
-    /**
-     * 实体分页转 BO 分页
-     *
-     * @param entityPage 实体分页
-     * @return BO 分页
-     */
-    private PageResult<SysCustomerDataBO> entityPage2BOPage(Page<SysCustomerDataEntity> entityPage) {
-        return new PageResult<SysCustomerDataBO>()
-            .setCurrent(entityPage.getCurrent())
-            .setSize(entityPage.getSize())
-            .setTotal(entityPage.getTotal())
-            .setRecords(this.entityList2BOs(entityPage.getRecords()));
-    }
-
-    /**
-     * 检查是否已存在同名数据
-     *
-     * @param dto DTO
-     */
-    private void checkExistence(AdminSysCustomerDataInsertOrUpdateDTO dto) {
-        /*
-        可以根据自己业务需要,解禁这段代码,修改判断条件和文案
-
-        SysCustomerDataEntity existingEntity = sysCustomerDataMapper.selectOne(
-                new QueryWrapper<SysCustomerDataEntity>()
-                        .lambda()
-                        .select(SysCustomerDataEntity::getId)
-                        .eq(SysCustomerDataEntity::getTitle, dto.getTitle())
-                        .last(HelioConstant.CRUD.SQL_LIMIT_1)
-        );
-
-        if (existingEntity != null && !existingEntity.getId().equals(dto.getId())) {
-            throw new BusinessException(400, "已存在相同客户(学校)数据,请重新输入");
-        }
-        */
-    }
-
 }