!831 WIP: CRM-待办事项

Merge pull request !831 from dhb52/crm-msg
This commit is contained in:
芋道源码 2024-01-15 00:53:04 +00:00 committed by Gitee
commit e16f1caae0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,39 @@
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

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.crm.controller.admin.message;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.message.vo.CrmTodayCustomerPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.service.message.CrmMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - CRM消息")
@RestController
@RequestMapping("/crm/message")
@Validated
public class CrmMessageController {
@Resource
private CrmMessageService crmMessageService;
@GetMapping("/todayCustomer")
@Operation(summary = "今日需联系客户")
@PreAuthorize("@ss.hasPermission('crm:message:todayCustomer')")
public CommonResult<PageResult<CrmCustomerRespVO>> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO) {
PageResult<CrmCustomerDO> pageResult = crmMessageService.getTodayCustomerPage(pageReqVO, getLoginUserId());
return success(BeanUtils.toBean(pageResult, CrmCustomerRespVO.class));
}
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.crm.controller.admin.message.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
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 lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 今日需联系客户 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmTodayCustomerPageReqVO extends PageParam {
@Schema(description = "联系状态", example = "1")
@InEnum(CrmContactStatusEnum.class)
private Integer contactStatus;
@Schema(description = "场景类型", example = "1")
@InEnum(CrmSceneTypeEnum.class)
private Integer sceneType;
}

View File

@ -5,13 +5,17 @@ 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.MPJLambdaWrapperX;
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.followup.CrmFollowUpRecordDO;
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 com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
@ -63,4 +67,53 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
return selectJoinList(CrmCustomerDO.class, query);
}
/**
* 待办事项 - 今日需联系客户
*
* @param pageReqVO 分页请求参数
* @param userId 当前用户ID
* @return 分页结果
*/
default PageResult<CrmCustomerDO> selectTodayCustomerPage(CrmTodayCustomerPageReqVO pageReqVO, Long userId) {
MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), null);
query.selectAll(CrmCustomerDO.class)
.leftJoin(CrmFollowUpRecordDO.class, CrmFollowUpRecordDO::getBizId, CrmCustomerDO::getId)
.eq(CrmFollowUpRecordDO::getType, CrmBizTypeEnum.CRM_CUSTOMER.getType());
// 拼接自身的查询条件
LocalDate today = LocalDate.now();
LocalDate tomorrow = today.plusDays(1);
LocalDate yesterday = today.minusDays(1);
if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.NEEDED_TODAY.getType())) {
// 今天需联系
// 1.客户下一次联系时间 今天
// 2. 无法找到今天创建的跟进记录
query.between(CrmCustomerDO::getContactNextTime, today, tomorrow)
.between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)
.isNull(CrmFollowUpRecordDO::getId);
} else if (pageReqVO.getContactStatus().equals(CrmContactStatusEnum.EXPIRED.getType())) {
// 已逾期
// 1. 客户下一次联系时间 <= 昨天
// 2. 无法找到今天创建的跟进记录
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)
.between(CrmFollowUpRecordDO::getCreateTime, today, tomorrow)
.isNotNull(CrmFollowUpRecordDO::getId);
} else {
// TODO: 参数错误是不是要兜一下底
}
return selectJoinPage(pageReqVO, CrmCustomerDO.class, query);
}
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.crm.service.message;
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.dal.dataobject.customer.CrmCustomerDO;
import jakarta.validation.Valid;
/**
* CRM 代办消息 Service 接口
*
* @author dhb52
*/
public interface CrmMessageService {
/**
*
* @param pageReqVO
* @return
*/
PageResult<CrmCustomerDO> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO, Long userId);
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.crm.service.message;
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.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
@Component
@Validated
public class CrmMessageServiceImpl implements CrmMessageService {
@Resource
private CrmCustomerMapper customerMapper;
@Override
public PageResult<CrmCustomerDO> getTodayCustomerPage(CrmTodayCustomerPageReqVO pageReqVO, Long userId) {
return customerMapper.selectTodayCustomerPage(pageReqVO, userId);
}
}