Commit 4bd97c4baf020b2c311b4bcc39222b7f4de37981

Authored by dhb52
1 parent 410c551e

wip: 根据code review优化代码

yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
@@ -84,4 +84,7 @@ public interface ErrorCodeConstants { @@ -84,4 +84,7 @@ public interface ErrorCodeConstants {
84 // ========== 跟进记录 1_020_013_000 ========== 84 // ========== 跟进记录 1_020_013_000 ==========
85 ErrorCode FOLLOW_UP_RECORD_NOT_EXISTS = new ErrorCode(1_020_013_000, "跟进记录不存在"); 85 ErrorCode FOLLOW_UP_RECORD_NOT_EXISTS = new ErrorCode(1_020_013_000, "跟进记录不存在");
86 86
  87 + // ========== 待办消息 1_020_014_000 ==========
  88 + ErrorCode BACKLOG_CONTACT_STATUS_ERROR = new ErrorCode(1_020_014_000, "客户联系状态有误");
  89 +
87 } 90 }
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/message/CrmContactStatusEnum.java deleted
1 -package cn.iocoder.yudao.module.crm.enums.message;  
2 -  
3 -import cn.iocoder.yudao.framework.common.core.IntArrayValuable;  
4 -import lombok.Getter;  
5 -import lombok.RequiredArgsConstructor;  
6 -  
7 -import java.util.Arrays;  
8 -  
9 -/**  
10 - * CRM 联系状态  
11 - *  
12 - * @author dhb52  
13 - */  
14 -@RequiredArgsConstructor  
15 -@Getter  
16 -public enum CrmContactStatusEnum implements IntArrayValuable {  
17 -  
18 - NEEDED_TODAY(1, "今日需联系"),  
19 - EXPIRED(2, "已逾期"),  
20 - ALREADY_CONTACT(3, "已联系"),  
21 - ;  
22 -  
23 - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmContactStatusEnum::getType).toArray();  
24 -  
25 - /**  
26 - * 状态  
27 - */  
28 - private final Integer type;  
29 - /**  
30 - * 状态名  
31 - */  
32 - private final String name;  
33 -  
34 - @Override  
35 - public int[] array() {  
36 - return ARRAYS;  
37 - }  
38 -  
39 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/CrmMessageController.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/backlog/CrmBacklogController.java
1 -package cn.iocoder.yudao.module.crm.controller.admin.message; 1 +package cn.iocoder.yudao.module.crm.controller.admin.backlog;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO; 6 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO;
7 -import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO; 7 +import cn.iocoder.yudao.module.crm.controller.admin.backlog.vo.CrmTodayCustomerPageReqVO;
8 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 8 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
9 -import cn.iocoder.yudao.module.crm.service.message.CrmMessageService; 9 +import cn.iocoder.yudao.module.crm.service.message.CrmBacklogService;
10 import io.swagger.v3.oas.annotations.Operation; 10 import io.swagger.v3.oas.annotations.Operation;
11 import io.swagger.v3.oas.annotations.tags.Tag; 11 import io.swagger.v3.oas.annotations.tags.Tag;
12 import jakarta.annotation.Resource; 12 import jakarta.annotation.Resource;
@@ -20,19 +20,19 @@ import org.springframework.web.bind.annotation.RestController; @@ -20,19 +20,19 @@ import org.springframework.web.bind.annotation.RestController;
20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
21 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; 21 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
22 22
23 -@Tag(name = "管理后台 - CRM消息") 23 +@Tag(name = "管理后台 - CRM待办消息")
24 @RestController 24 @RestController
25 -@RequestMapping("/crm/message") 25 +@RequestMapping("/crm/backlog")
26 @Validated 26 @Validated
27 -public class CrmMessageController { 27 +public class CrmBacklogController {
28 28
29 @Resource 29 @Resource
30 - private CrmMessageService crmMessageService; 30 + private CrmBacklogService crmMessageService;
31 31
32 // TODO 芋艿:未来可能合并到 CrmCustomerController 32 // TODO 芋艿:未来可能合并到 CrmCustomerController
33 - @GetMapping("/todayCustomer") // TODO @dbh52:【优先级低】url 使用中划线,项目规范。然后叫 today-customer-page,通过 page 体现出它是个分页接口 33 + @GetMapping("/today-customer-page")
34 @Operation(summary = "今日需联系客户") 34 @Operation(summary = "今日需联系客户")
35 - @PreAuthorize("@ss.hasPermission('crm:message:todayCustomer')") 35 + @PreAuthorize("@ss.hasPermission('crm:customer:query')")
36 public CommonResult<PageResult<CrmCustomerRespVO>> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO) { 36 public CommonResult<PageResult<CrmCustomerRespVO>> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO) {
37 PageResult<CrmCustomerDO> pageResult = crmMessageService.getTodayCustomerPage(pageReqVO, getLoginUserId()); 37 PageResult<CrmCustomerDO> pageResult = crmMessageService.getTodayCustomerPage(pageReqVO, getLoginUserId());
38 return success(BeanUtils.toBean(pageResult, CrmCustomerRespVO.class)); 38 return success(BeanUtils.toBean(pageResult, CrmCustomerRespVO.class));
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/vo/CrmTodayCustomerPageReqVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/backlog/vo/CrmTodayCustomerPageReqVO.java
1 -package cn.iocoder.yudao.module.crm.controller.admin.message.vo; 1 +package cn.iocoder.yudao.module.crm.controller.admin.backlog.vo;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageParam; 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 import cn.iocoder.yudao.framework.common.validation.InEnum; 4 import cn.iocoder.yudao.framework.common.validation.InEnum;
5 import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum; 5 import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum;
6 -import cn.iocoder.yudao.module.crm.enums.message.CrmContactStatusEnum;  
7 import io.swagger.v3.oas.annotations.media.Schema; 6 import io.swagger.v3.oas.annotations.media.Schema;
8 import lombok.Data; 7 import lombok.Data;
9 import lombok.EqualsAndHashCode; 8 import lombok.EqualsAndHashCode;
@@ -15,10 +14,12 @@ import lombok.ToString; @@ -15,10 +14,12 @@ import lombok.ToString;
15 @ToString(callSuper = true) 14 @ToString(callSuper = true)
16 public class CrmTodayCustomerPageReqVO extends PageParam { 15 public class CrmTodayCustomerPageReqVO extends PageParam {
17 16
18 - // TODO @dbh52:CrmContactStatusEnum 可以直接枚举三个 Integer;一般来说,枚举类尽量给数据模型用,这样枚举类少,更聚焦;这里的枚举,更多是专门给这个接口用的哈 17 + public static final int CONTACT_TODAY = 1;
  18 + public static final int CONTACT_EXPIRED = 2;
  19 + public static final int CONTACT_ALREADY = 3;
  20 +
19 21
20 @Schema(description = "联系状态", example = "1") 22 @Schema(description = "联系状态", example = "1")
21 - @InEnum(CrmContactStatusEnum.class)  
22 private Integer contactStatus; 23 private Integer contactStatus;
23 24
24 @Schema(description = "场景类型", example = "1") 25 @Schema(description = "场景类型", example = "1")
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java
@@ -4,20 +4,26 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -4,20 +4,26 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; 6 import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.backlog.vo.CrmTodayCustomerPageReqVO;
7 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; 8 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
8 -import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO;  
9 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 9 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
10 import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO; 10 import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
11 import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; 11 import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
12 -import cn.iocoder.yudao.module.crm.enums.message.CrmContactStatusEnum;  
13 import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils; 12 import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils;
14 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 13 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
15 import org.apache.ibatis.annotations.Mapper; 14 import org.apache.ibatis.annotations.Mapper;
16 import org.springframework.lang.Nullable; 15 import org.springframework.lang.Nullable;
17 16
18 import java.time.LocalDate; 17 import java.time.LocalDate;
  18 +import java.time.LocalDateTime;
  19 +import java.time.LocalTime;
  20 +import java.time.temporal.TemporalUnit;
19 import java.util.Collection; 21 import java.util.Collection;
20 import java.util.List; 22 import java.util.List;
  23 +import java.util.concurrent.TimeUnit;
  24 +
  25 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  26 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BACKLOG_CONTACT_STATUS_ERROR;
21 27
22 /** 28 /**
23 * 客户 Mapper 29 * 客户 Mapper
@@ -80,41 +86,22 @@ public interface CrmCustomerMapper extends BaseMapperX&lt;CrmCustomerDO&gt; { @@ -80,41 +86,22 @@ public interface CrmCustomerMapper extends BaseMapperX&lt;CrmCustomerDO&gt; {
80 CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(), 86 CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
81 CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), null); 87 CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), null);
82 88
83 - query.selectAll(CrmCustomerDO.class)  
84 - .leftJoin(CrmFollowUpRecordDO.class, CrmFollowUpRecordDO::getBizId, CrmCustomerDO::getId)  
85 - .eq(CrmFollowUpRecordDO::getType, CrmBizTypeEnum.CRM_CUSTOMER.getType()); 89 + query.selectAll(CrmCustomerDO.class);
86 90
87 // 拼接自身的查询条件 91 // 拼接自身的查询条件
88 - // TODO @dbh52:这里不仅仅要获得 today、tomorrow。而是 today 要获取今天的 00:00:00 这种;  
89 - LocalDate today = LocalDate.now();  
90 - LocalDate tomorrow = today.plusDays(1);  
91 - LocalDate yesterday = today.minusDays(1);  
92 - if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.NEEDED_TODAY.getType())) {  
93 - // 今天需联系:  
94 - // 1.【客户】的【下一次联系时间】 是【今天】  
95 - // 2. 无法找到【今天】创建的【跟进】记录  
96 - query.between(CrmCustomerDO::getContactNextTime, today, tomorrow)  
97 - // TODO @dbh52:是不是查询 CrmCustomerDO::contactLastTime < today?因为今天联系过,应该会更新该字段,减少链表查询;  
98 - .between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)  
99 - .isNull(CrmFollowUpRecordDO::getId);  
100 - } else if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.EXPIRED.getType())) {  
101 - // 已逾期:  
102 - // 1. 【客户】的【下一次联系时间】 <= 【昨天】  
103 - // 2. 无法找到【今天】创建的【跟进】记录  
104 - // TODO @dbh52:是不是 contactNextTime 在当前时间之前,且 contactLastTime < contactNextTime?说白了,就是下次联系时间超过当前时间,且最后联系时间没去联系;  
105 - query.le(CrmCustomerDO::getContactNextTime, yesterday)  
106 - .between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)  
107 - .isNull(CrmFollowUpRecordDO::getId);  
108 - } else if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.ALREADY_CONTACT.getType())) {  
109 - // 已联系:  
110 - // 1.【客户】的【下一次联系时间】 是【今天】  
111 - // 2. 找到【今天】创建的【跟进】记录  
112 - query.between(CrmCustomerDO::getContactNextTime, today, tomorrow)  
113 - // TODO @dbh52:contactLastTime 是今天  
114 - .between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)  
115 - .isNotNull(CrmFollowUpRecordDO::getId); 92 + LocalDateTime beginOfToday = LocalDateTime.now().toLocalDate().atTime(LocalTime.MIN);
  93 + LocalDateTime endOfToday = LocalDateTime.now().toLocalDate().atTime(LocalTime.MAX);
  94 + if (pageReqVO.getContactStatus().equals(CrmTodayCustomerPageReqVO.CONTACT_TODAY)) {
  95 + // 今天需联系
  96 + query.between(CrmCustomerDO::getContactNextTime, beginOfToday, endOfToday);
  97 + } else if (pageReqVO.getContactStatus().equals(CrmTodayCustomerPageReqVO.CONTACT_EXPIRED)) {
  98 + // 已逾期
  99 + query.lt(CrmCustomerDO::getContactNextTime, beginOfToday);
  100 + } else if (pageReqVO.getContactStatus().equals(CrmTodayCustomerPageReqVO.CONTACT_ALREADY)) {
  101 + // 已联系
  102 + query.between(CrmCustomerDO::getContactLastTime, beginOfToday, endOfToday);
116 } else { 103 } else {
117 - // TODO: 参数错误,是不是要兜一下底;直接抛出异常就好啦; 104 + throw exception(BACKLOG_CONTACT_STATUS_ERROR);
118 } 105 }
119 106
120 return selectJoinPage(pageReqVO, CrmCustomerDO.class, query); 107 return selectJoinPage(pageReqVO, CrmCustomerDO.class, query);
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageService.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmBacklogService.java
1 package cn.iocoder.yudao.module.crm.service.message; 1 package cn.iocoder.yudao.module.crm.service.message;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO; 4 +import cn.iocoder.yudao.module.crm.controller.admin.backlog.vo.CrmTodayCustomerPageReqVO;
5 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 5 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
6 import jakarta.validation.Valid; 6 import jakarta.validation.Valid;
7 7
8 /** 8 /**
9 - * CRM 代办消息 Service 接口 9 + * CRM 待办消息 Service 接口
10 * 10 *
11 * @author dhb52 11 * @author dhb52
12 */ 12 */
13 -public interface CrmMessageService { 13 +public interface CrmBacklogService {
14 14
15 /** 15 /**
16 - * TODO @dbh52:注释要写下 16 + * 根据【联系状态】、【场景类型】筛选客户分页
17 * 17 *
18 - * @param pageReqVO  
19 - * @return 18 + * @param pageReqVO 分页查询
  19 + * @return 分页数据
20 */ 20 */
21 PageResult<CrmCustomerDO> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO, Long userId); 21 PageResult<CrmCustomerDO> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO, Long userId);
22 22
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageServiceImpl.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmBacklogServiceImpl.java
1 package cn.iocoder.yudao.module.crm.service.message; 1 package cn.iocoder.yudao.module.crm.service.message;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO; 4 +import cn.iocoder.yudao.module.crm.controller.admin.backlog.vo.CrmTodayCustomerPageReqVO;
5 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; 5 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
6 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper; 6 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
7 import jakarta.annotation.Resource; 7 import jakarta.annotation.Resource;
8 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
9 import org.springframework.validation.annotation.Validated; 9 import org.springframework.validation.annotation.Validated;
10 10
11 -// TODO @dbh52:注释要写下 11 +/**
  12 + * 待办消息 Service 实现类
  13 + */
  14 +
12 @Component 15 @Component
13 @Validated 16 @Validated
14 -public class CrmMessageServiceImpl implements CrmMessageService { 17 +public class CrmBacklogServiceImpl implements CrmBacklogService {
15 18
16 @Resource 19 @Resource
17 private CrmCustomerMapper customerMapper; 20 private CrmCustomerMapper customerMapper;