diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/message/CrmContactStatusEnum.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/message/CrmContactStatusEnum.java new file mode 100644 index 000000000..6ca5f52dc --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/message/CrmContactStatusEnum.java @@ -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; + } + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/CrmMessageController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/CrmMessageController.java new file mode 100644 index 000000000..7e003e66f --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/CrmMessageController.java @@ -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> getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO) { + PageResult pageResult = crmMessageService.getTodayCustomerPage(pageReqVO, getLoginUserId()); + return success(BeanUtils.toBean(pageResult, CrmCustomerRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/vo/CrmTodayCustomerPageReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/vo/CrmTodayCustomerPageReqVO.java new file mode 100644 index 000000000..3a14104c6 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/message/vo/CrmTodayCustomerPageReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java index 8acd92b3e..bf68e64ee 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java +++ b/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; 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 { return selectJoinList(CrmCustomerDO.class, query); } + /** + * 待办事项 - 今日需联系客户 + * + * @param pageReqVO 分页请求参数 + * @param userId 当前用户ID + * @return 分页结果 + */ + default PageResult selectTodayCustomerPage(CrmTodayCustomerPageReqVO pageReqVO, Long userId) { + MPJLambdaWrapperX 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); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageService.java new file mode 100644 index 000000000..803b3ef15 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageService.java @@ -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 getTodayCustomerPage(@Valid CrmTodayCustomerPageReqVO pageReqVO, Long userId); + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageServiceImpl.java new file mode 100644 index 000000000..86cc22faa --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/message/CrmMessageServiceImpl.java @@ -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 getTodayCustomerPage(CrmTodayCustomerPageReqVO pageReqVO, Long userId) { + return customerMapper.selectTodayCustomerPage(pageReqVO, userId); + } + +}