Commit e16f1caae0d70e9943fd2dfbe8191eddcd87e3a0

Authored by 芋道源码
Committed by Gitee
2 parents 50f7be99 4558ecd8

!831 WIP: CRM-待办事项

Merge pull request !831 from dhb52/crm-msg
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/message/CrmContactStatusEnum.java 0 → 100644
  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 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.message;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO;
  8 +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
  9 +import cn.iocoder.yudao.module.crm.service.message.CrmMessageService;
  10 +import io.swagger.v3.oas.annotations.Operation;
  11 +import io.swagger.v3.oas.annotations.tags.Tag;
  12 +import jakarta.annotation.Resource;
  13 +import jakarta.validation.Valid;
  14 +import org.springframework.security.access.prepost.PreAuthorize;
  15 +import org.springframework.validation.annotation.Validated;
  16 +import org.springframework.web.bind.annotation.GetMapping;
  17 +import org.springframework.web.bind.annotation.RequestMapping;
  18 +import org.springframework.web.bind.annotation.RestController;
  19 +
  20 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  21 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
  22 +
  23 +
  24 +@Tag(name = "管理后台 - CRM消息")
  25 +@RestController
  26 +@RequestMapping("/crm/message")
  27 +@Validated
  28 +public class CrmMessageController {
  29 +
  30 + @Resource
  31 + private CrmMessageService crmMessageService;
  32 +
  33 + @GetMapping("/todayCustomer")
  34 + @Operation(summary = "今日需联系客户")
  35 + @PreAuthorize("@ss.hasPermission('crm:message:todayCustomer')")
  36 + public CommonResult<PageResult<CrmCustomerRespVO>> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO) {
  37 + PageResult<CrmCustomerDO> pageResult = crmMessageService.getTodayCustomerPage(pageReqVO, getLoginUserId());
  38 + return success(BeanUtils.toBean(pageResult, CrmCustomerRespVO.class));
  39 + }
  40 +
  41 +}
0 \ No newline at end of file 42 \ No newline at end of file
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/vo/CrmTodayCustomerPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.message.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  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;
  8 +import lombok.Data;
  9 +import lombok.EqualsAndHashCode;
  10 +import lombok.ToString;
  11 +
  12 +@Schema(description = "管理后台 - 今日需联系客户 Request VO")
  13 +@Data
  14 +@EqualsAndHashCode(callSuper = true)
  15 +@ToString(callSuper = true)
  16 +public class CrmTodayCustomerPageReqVO extends PageParam {
  17 +
  18 + @Schema(description = "联系状态", example = "1")
  19 + @InEnum(CrmContactStatusEnum.class)
  20 + private Integer contactStatus;
  21 +
  22 + @Schema(description = "场景类型", example = "1")
  23 + @InEnum(CrmSceneTypeEnum.class)
  24 + private Integer sceneType;
  25 +
  26 +}
0 \ No newline at end of file 27 \ No newline at end of file
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java
@@ -5,13 +5,17 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; @@ -5,13 +5,17 @@ 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.customer.vo.CrmCustomerPageReqVO; 7 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
  8 +import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO;
8 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;
9 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;
10 import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils; 13 import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils;
11 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 14 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
12 import org.apache.ibatis.annotations.Mapper; 15 import org.apache.ibatis.annotations.Mapper;
13 import org.springframework.lang.Nullable; 16 import org.springframework.lang.Nullable;
14 17
  18 +import java.time.LocalDate;
15 import java.util.Collection; 19 import java.util.Collection;
16 import java.util.List; 20 import java.util.List;
17 21
@@ -63,4 +67,53 @@ public interface CrmCustomerMapper extends BaseMapperX&lt;CrmCustomerDO&gt; { @@ -63,4 +67,53 @@ public interface CrmCustomerMapper extends BaseMapperX&lt;CrmCustomerDO&gt; {
63 return selectJoinList(CrmCustomerDO.class, query); 67 return selectJoinList(CrmCustomerDO.class, query);
64 } 68 }
65 69
  70 + /**
  71 + * 待办事项 - 今日需联系客户
  72 + *
  73 + * @param pageReqVO 分页请求参数
  74 + * @param userId 当前用户ID
  75 + * @return 分页结果
  76 + */
  77 + default PageResult<CrmCustomerDO> selectTodayCustomerPage(CrmTodayCustomerPageReqVO pageReqVO, Long userId) {
  78 + MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>();
  79 + // 拼接数据权限的查询条件
  80 + CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
  81 + CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), null);
  82 +
  83 + query.selectAll(CrmCustomerDO.class)
  84 + .leftJoin(CrmFollowUpRecordDO.class, CrmFollowUpRecordDO::getBizId, CrmCustomerDO::getId)
  85 + .eq(CrmFollowUpRecordDO::getType, CrmBizTypeEnum.CRM_CUSTOMER.getType());
  86 +
  87 + // 拼接自身的查询条件
  88 + LocalDate today = LocalDate.now();
  89 + LocalDate tomorrow = today.plusDays(1);
  90 + LocalDate yesterday = today.minusDays(1);
  91 + if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.NEEDED_TODAY.getType())) {
  92 + // 今天需联系:
  93 + // 1.【客户】的【下一次联系时间】 是【今天】
  94 + // 2. 无法找到【今天】创建的【跟进】记录
  95 + query.between(CrmCustomerDO::getContactNextTime, today, tomorrow)
  96 + .between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)
  97 + .isNull(CrmFollowUpRecordDO::getId);
  98 + } else if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.EXPIRED.getType())) {
  99 + // 已逾期:
  100 + // 1. 【客户】的【下一次联系时间】 <= 【昨天】
  101 + // 2. 无法找到【今天】创建的【跟进】记录
  102 + query.le(CrmCustomerDO::getContactNextTime, yesterday)
  103 + .between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)
  104 + .isNull(CrmFollowUpRecordDO::getId);
  105 + } else if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.ALREADY_CONTACT.getType())) {
  106 + // 已联系:
  107 + // 1.【客户】的【下一次联系时间】 是【今天】
  108 + // 2. 找到【今天】创建的【跟进】记录
  109 + query.between(CrmCustomerDO::getContactNextTime, today, tomorrow)
  110 + .between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)
  111 + .isNotNull(CrmFollowUpRecordDO::getId);
  112 + } else {
  113 + // TODO: 参数错误,是不是要兜一下底
  114 + }
  115 +
  116 + return selectJoinPage(pageReqVO, CrmCustomerDO.class, query);
  117 + }
  118 +
66 } 119 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.service.message;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO;
  5 +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
  6 +import jakarta.validation.Valid;
  7 +
  8 +/**
  9 + * CRM 代办消息 Service 接口
  10 + *
  11 + * @author dhb52
  12 + */
  13 +public interface CrmMessageService {
  14 +
  15 + /**
  16 + *
  17 + * @param pageReqVO
  18 + * @return
  19 + */
  20 + PageResult<CrmCustomerDO> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO, Long userId);
  21 +
  22 +}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.service.message;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO;
  5 +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
  6 +import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
  7 +import jakarta.annotation.Resource;
  8 +import org.springframework.stereotype.Component;
  9 +import org.springframework.validation.annotation.Validated;
  10 +
  11 +
  12 +@Component
  13 +@Validated
  14 +public class CrmMessageServiceImpl implements CrmMessageService {
  15 +
  16 + @Resource
  17 + private CrmCustomerMapper customerMapper;
  18 +
  19 + @Override
  20 + public PageResult<CrmCustomerDO> getTodayCustomerPage(CrmTodayCustomerPageReqVO pageReqVO, Long userId) {
  21 + return customerMapper.selectTodayCustomerPage(pageReqVO, userId);
  22 + }
  23 +
  24 +}