!847 fix: 根据Code Review修改代办消息backlog

Merge pull request !847 from dhb52/crm-msg
This commit is contained in:
芋道源码 2024-01-22 04:14:18 +00:00 committed by Gitee
commit 422b19caf7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 48 additions and 96 deletions

View File

@ -86,4 +86,7 @@ public interface ErrorCodeConstants {
ErrorCode FOLLOW_UP_RECORD_NOT_EXISTS = new ErrorCode(1_020_013_000, "跟进记录不存在"); ErrorCode FOLLOW_UP_RECORD_NOT_EXISTS = new ErrorCode(1_020_013_000, "跟进记录不存在");
ErrorCode FOLLOW_UP_RECORD_DELETE_DENIED = new ErrorCode(1_020_013_001, "删除跟进记录失败,原因:没有权限"); ErrorCode FOLLOW_UP_RECORD_DELETE_DENIED = new ErrorCode(1_020_013_001, "删除跟进记录失败,原因:没有权限");
// ========== 待办消息 1_020_014_000 ==========
ErrorCode BACKLOG_CONTACT_STATUS_INVALID = new ErrorCode(1_020_014_000, "客户联系状态有误");
} }

View File

@ -1,39 +0,0 @@
package cn.iocoder.yudao.module.crm.enums.message;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
/**
* CRM 联系状态
*
* @author dhb52
*/
@RequiredArgsConstructor
@Getter
public enum CrmContactStatusEnum implements IntArrayValuable {
NEEDED_TODAY(1, "今日需联系"),
EXPIRED(2, "已逾期"),
ALREADY_CONTACT(3, "已联系"),
;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmContactStatusEnum::getType).toArray();
/**
* 状态
*/
private final Integer type;
/**
* 状态名
*/
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -1,12 +1,12 @@
package cn.iocoder.yudao.module.crm.controller.admin.message; package cn.iocoder.yudao.module.crm.controller.admin.backlog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.backlog.vo.CrmTodayCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.service.message.CrmMessageService; import cn.iocoder.yudao.module.crm.service.message.CrmBacklogService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -20,19 +20,19 @@ import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - CRM消息") @Tag(name = "管理后台 - CRM待办消息")
@RestController @RestController
@RequestMapping("/crm/message") @RequestMapping("/crm/backlog")
@Validated @Validated
public class CrmMessageController { public class CrmBacklogController {
@Resource @Resource
private CrmMessageService crmMessageService; private CrmBacklogService crmMessageService;
// TODO 芋艿未来可能合并到 CrmCustomerController // TODO 芋艿未来可能合并到 CrmCustomerController
@GetMapping("/todayCustomer") // TODO @dbh52优先级低url 使用中划线项目规范然后叫 today-customer-page通过 page 体现出它是个分页接口 @GetMapping("/today-customer-page")
@Operation(summary = "今日需联系客户") @Operation(summary = "今日需联系客户")
@PreAuthorize("@ss.hasPermission('crm:message:todayCustomer')") @PreAuthorize("@ss.hasPermission('crm:customer:query')")
public CommonResult<PageResult<CrmCustomerRespVO>> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO) { public CommonResult<PageResult<CrmCustomerRespVO>> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO) {
PageResult<CrmCustomerDO> pageResult = crmMessageService.getTodayCustomerPage(pageReqVO, getLoginUserId()); PageResult<CrmCustomerDO> pageResult = crmMessageService.getTodayCustomerPage(pageReqVO, getLoginUserId());
return success(BeanUtils.toBean(pageResult, CrmCustomerRespVO.class)); return success(BeanUtils.toBean(pageResult, CrmCustomerRespVO.class));

View File

@ -1,9 +1,8 @@
package cn.iocoder.yudao.module.crm.controller.admin.message.vo; package cn.iocoder.yudao.module.crm.controller.admin.backlog.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum; import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum;
import cn.iocoder.yudao.module.crm.enums.message.CrmContactStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -15,10 +14,12 @@ import lombok.ToString;
@ToString(callSuper = true) @ToString(callSuper = true)
public class CrmTodayCustomerPageReqVO extends PageParam { public class CrmTodayCustomerPageReqVO extends PageParam {
// TODO @dbh52CrmContactStatusEnum 可以直接枚举三个 Integer一般来说枚举类尽量给数据模型用这样枚举类少更聚焦这里的枚举更多是专门给这个接口用的哈 public static final int CONTACT_TODAY = 1;
public static final int CONTACT_EXPIRED = 2;
public static final int CONTACT_ALREADY = 3;
@Schema(description = "联系状态", example = "1") @Schema(description = "联系状态", example = "1")
@InEnum(CrmContactStatusEnum.class)
private Integer contactStatus; private Integer contactStatus;
@Schema(description = "场景类型", example = "1") @Schema(description = "场景类型", example = "1")

View File

@ -4,21 +4,24 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.backlog.vo.CrmTodayCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.enums.message.CrmContactStatusEnum;
import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils; import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BACKLOG_CONTACT_STATUS_INVALID;
/** /**
* 客户 Mapper * 客户 Mapper
* *
@ -82,41 +85,22 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(), CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), null); CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), null);
query.selectAll(CrmCustomerDO.class) query.selectAll(CrmCustomerDO.class);
.leftJoin(CrmFollowUpRecordDO.class, CrmFollowUpRecordDO::getBizId, CrmCustomerDO::getId)
.eq(CrmFollowUpRecordDO::getType, CrmBizTypeEnum.CRM_CUSTOMER.getType());
// 拼接自身的查询条件 // 拼接自身的查询条件
// TODO @dbh52这里不仅仅要获得 todaytomorrow而是 today 要获取今天的 00:00:00 这种 LocalDateTime beginOfToday = LocalDate.now().atTime(LocalTime.MIN);
LocalDate today = LocalDate.now(); LocalDateTime endOfToday = LocalDate.now().atTime(LocalTime.MAX);
LocalDate tomorrow = today.plusDays(1); if (pageReqVO.getContactStatus().equals(CrmTodayCustomerPageReqVO.CONTACT_TODAY)) {
LocalDate yesterday = today.minusDays(1); // 今天需联系
if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.NEEDED_TODAY.getType())) { query.between(CrmCustomerDO::getContactNextTime, beginOfToday, endOfToday);
// 今天需联系 } else if (pageReqVO.getContactStatus().equals(CrmTodayCustomerPageReqVO.CONTACT_EXPIRED)) {
// 1.客户下一次联系时间 今天 // 已逾期
// 2. 无法找到今天创建的跟进记录 query.lt(CrmCustomerDO::getContactNextTime, beginOfToday);
query.between(CrmCustomerDO::getContactNextTime, today, tomorrow) } else if (pageReqVO.getContactStatus().equals(CrmTodayCustomerPageReqVO.CONTACT_ALREADY)) {
// TODO @dbh52是不是查询 CrmCustomerDO::contactLastTime < today因为今天联系过应该会更新该字段减少链表查询 // 已联系
.between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow) query.between(CrmCustomerDO::getContactLastTime, beginOfToday, endOfToday);
.isNull(CrmFollowUpRecordDO::getId);
} else if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.EXPIRED.getType())) {
// 已逾期
// 1. 客户下一次联系时间 <= 昨天
// 2. 无法找到今天创建的跟进记录
// TODO @dbh52是不是 contactNextTime 在当前时间之前 contactLastTime < contactNextTime说白了就是下次联系时间超过当前时间且最后联系时间没去联系
query.le(CrmCustomerDO::getContactNextTime, yesterday)
.between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)
.isNull(CrmFollowUpRecordDO::getId);
} else if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.ALREADY_CONTACT.getType())) {
// 已联系
// 1.客户下一次联系时间 今天
// 2. 找到今天创建的跟进记录
query.between(CrmCustomerDO::getContactNextTime, today, tomorrow)
// TODO @dbh52contactLastTime 是今天
.between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)
.isNotNull(CrmFollowUpRecordDO::getId);
} else { } else {
// TODO: 参数错误是不是要兜一下底直接抛出异常就好啦 throw exception(BACKLOG_CONTACT_STATUS_INVALID);
} }
return selectJoinPage(pageReqVO, CrmCustomerDO.class, query); return selectJoinPage(pageReqVO, CrmCustomerDO.class, query);

View File

@ -1,22 +1,22 @@
package cn.iocoder.yudao.module.crm.service.message; package cn.iocoder.yudao.module.crm.service.message;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.backlog.vo.CrmTodayCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
/** /**
* CRM 办消息 Service 接口 * CRM 办消息 Service 接口
* *
* @author dhb52 * @author dhb52
*/ */
public interface CrmMessageService { public interface CrmBacklogService {
/** /**
* TODO @dbh52注释要写下 * 根据联系状态场景类型筛选客户分页
* *
* @param pageReqVO * @param pageReqVO 分页查询
* @return * @return 分页数据
*/ */
PageResult<CrmCustomerDO> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO, Long userId); PageResult<CrmCustomerDO> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO, Long userId);

View File

@ -1,17 +1,20 @@
package cn.iocoder.yudao.module.crm.service.message; package cn.iocoder.yudao.module.crm.service.message;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.message.vo.CrmTodayCustomerPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.backlog.vo.CrmTodayCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper; import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
// TODO @dbh52注释要写下 /**
* 待办消息 Service 实现类
*/
@Component @Component
@Validated @Validated
public class CrmMessageServiceImpl implements CrmMessageService { public class CrmBacklogServiceImpl implements CrmBacklogService {
@Resource @Resource
private CrmCustomerMapper customerMapper; private CrmCustomerMapper customerMapper;