|
|
|
|
@ -7,9 +7,11 @@ 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.dal.dataobject.clue.CrmClueDO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
@ -29,6 +31,40 @@ import java.util.List;
|
|
|
|
|
@Mapper
|
|
|
|
|
public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
|
|
|
|
|
|
|
|
|
private static MPJLambdaWrapperX<CrmCustomerDO> buildPutInPoolRemindCustomerWrapper(CrmCustomerPageReqVO pageReqVO, CrmCustomerPoolConfigDO poolConfigDO, Long userId) {
|
|
|
|
|
MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>();
|
|
|
|
|
// 拼接数据权限的查询条件
|
|
|
|
|
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
|
|
|
|
|
CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), null);
|
|
|
|
|
|
|
|
|
|
// 锁定状态不需要提醒
|
|
|
|
|
query.ne(CrmCustomerDO::getLockStatus, true);
|
|
|
|
|
|
|
|
|
|
// 情况一:未成交提醒日期区间
|
|
|
|
|
Integer dealExpireDays = poolConfigDO.getDealExpireDays();
|
|
|
|
|
LocalDateTime startDealRemindDate = LocalDateTimeUtil.beginOfDay(LocalDateTime.now())
|
|
|
|
|
.minusDays(dealExpireDays);
|
|
|
|
|
LocalDateTime endDealRemindDate = LocalDateTimeUtil.endOfDay(LocalDateTime.now())
|
|
|
|
|
.minusDays(Math.max(dealExpireDays - poolConfigDO.getNotifyDays(), 0));
|
|
|
|
|
// 情况二:未跟进提醒日期区间
|
|
|
|
|
Integer contactExpireDays = poolConfigDO.getContactExpireDays();
|
|
|
|
|
LocalDateTime startContactRemindDate = LocalDateTimeUtil.beginOfDay(LocalDateTime.now())
|
|
|
|
|
.minusDays(contactExpireDays);
|
|
|
|
|
LocalDateTime endContactRemindDate = LocalDateTimeUtil.endOfDay(LocalDateTime.now())
|
|
|
|
|
.minusDays(Math.max(contactExpireDays - poolConfigDO.getNotifyDays(), 0));
|
|
|
|
|
query
|
|
|
|
|
// 情况一:1. 未成交放入公海提醒
|
|
|
|
|
.eq(CrmCustomerDO::getDealStatus, false)
|
|
|
|
|
.between(CrmCustomerDO::getCreateTime, startDealRemindDate, endDealRemindDate)
|
|
|
|
|
// 情况二:未跟进放入公海提醒
|
|
|
|
|
.or() // 2.1 contactLastTime 为空 TODO 芋艿:这个要不要搞个默认值;
|
|
|
|
|
.isNull(CrmCustomerDO::getContactLastTime)
|
|
|
|
|
.between(CrmCustomerDO::getCreateTime, startContactRemindDate, endContactRemindDate)
|
|
|
|
|
.or() // 2.2 ContactLastTime 不为空
|
|
|
|
|
.between(CrmCustomerDO::getContactLastTime, startContactRemindDate, endContactRemindDate);
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default Long selectCountByLockStatusAndOwnerUserId(Boolean lockStatus, Long ownerUserId) {
|
|
|
|
|
return selectCount(new LambdaUpdateWrapper<CrmCustomerDO>()
|
|
|
|
|
.eq(CrmCustomerDO::getLockStatus, lockStatus)
|
|
|
|
|
@ -102,39 +138,42 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
|
|
|
|
|
default PageResult<CrmCustomerDO> selectPutInPoolRemindCustomerPage(CrmCustomerPageReqVO pageReqVO,
|
|
|
|
|
CrmCustomerPoolConfigDO poolConfigDO,
|
|
|
|
|
Long userId) {
|
|
|
|
|
final MPJLambdaWrapperX<CrmCustomerDO> query = buildPutInPoolRemindCustomerWrapper(pageReqVO, poolConfigDO, userId);
|
|
|
|
|
return selectJoinPage(pageReqVO, CrmCustomerDO.class, query.selectAll(CrmCustomerDO.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default Long selectPutInPoolRemindCustomerCount(CrmCustomerPageReqVO pageReqVO,
|
|
|
|
|
CrmCustomerPoolConfigDO poolConfigDO,
|
|
|
|
|
Long userId) {
|
|
|
|
|
final MPJLambdaWrapperX<CrmCustomerDO> query = buildPutInPoolRemindCustomerWrapper(pageReqVO, poolConfigDO, userId);
|
|
|
|
|
return selectCount(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default Long getTodayCustomerCount(Long userId) {
|
|
|
|
|
MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>();
|
|
|
|
|
// 拼接数据权限的查询条件
|
|
|
|
|
|
|
|
|
|
// 我负责的, 非公海
|
|
|
|
|
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
|
|
|
|
|
CrmCustomerDO::getId, userId, pageReqVO.getSceneType(), null);
|
|
|
|
|
CrmCustomerDO::getId, userId, CrmSceneTypeEnum.OWNER.getType(), Boolean.FALSE);
|
|
|
|
|
|
|
|
|
|
// 锁定状态不需要提醒
|
|
|
|
|
query.ne(CrmCustomerDO::getLockStatus, true);
|
|
|
|
|
// 今天需联系
|
|
|
|
|
LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
|
|
|
|
|
LocalDateTime endOfToday = LocalDateTimeUtil.endOfDay(LocalDateTime.now());
|
|
|
|
|
query.between(CrmCustomerDO::getContactNextTime, beginOfToday, endOfToday);
|
|
|
|
|
|
|
|
|
|
// 拼接自身的查询条件
|
|
|
|
|
query.selectAll(CrmCustomerDO.class);
|
|
|
|
|
// 情况一:未成交提醒日期区间
|
|
|
|
|
Integer dealExpireDays = poolConfigDO.getDealExpireDays();
|
|
|
|
|
LocalDateTime startDealRemindDate = LocalDateTimeUtil.beginOfDay(LocalDateTime.now())
|
|
|
|
|
.minusDays(dealExpireDays);
|
|
|
|
|
LocalDateTime endDealRemindDate = LocalDateTimeUtil.endOfDay(LocalDateTime.now())
|
|
|
|
|
.minusDays(Math.max(dealExpireDays - poolConfigDO.getNotifyDays(), 0));
|
|
|
|
|
// 情况二:未跟进提醒日期区间
|
|
|
|
|
Integer contactExpireDays = poolConfigDO.getContactExpireDays();
|
|
|
|
|
LocalDateTime startContactRemindDate = LocalDateTimeUtil.beginOfDay(LocalDateTime.now())
|
|
|
|
|
.minusDays(contactExpireDays);
|
|
|
|
|
LocalDateTime endContactRemindDate = LocalDateTimeUtil.endOfDay(LocalDateTime.now())
|
|
|
|
|
.minusDays(Math.max(contactExpireDays - poolConfigDO.getNotifyDays(), 0));
|
|
|
|
|
query
|
|
|
|
|
// 情况一:1. 未成交放入公海提醒
|
|
|
|
|
.eq(CrmCustomerDO::getDealStatus, false)
|
|
|
|
|
.between(CrmCustomerDO::getCreateTime, startDealRemindDate, endDealRemindDate)
|
|
|
|
|
// 情况二:未跟进放入公海提醒
|
|
|
|
|
.or() // 2.1 contactLastTime 为空 TODO 芋艿:这个要不要搞个默认值;
|
|
|
|
|
.isNull(CrmCustomerDO::getContactLastTime)
|
|
|
|
|
.between(CrmCustomerDO::getCreateTime, startContactRemindDate, endContactRemindDate)
|
|
|
|
|
.or() // 2.2 ContactLastTime 不为空
|
|
|
|
|
.between(CrmCustomerDO::getContactLastTime, startContactRemindDate, endContactRemindDate);
|
|
|
|
|
return selectJoinPage(pageReqVO, CrmCustomerDO.class, query);
|
|
|
|
|
return selectCount(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default Long getFollowCustomerCount(Long userId) {
|
|
|
|
|
MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>();
|
|
|
|
|
|
|
|
|
|
// 我负责的, 非公海
|
|
|
|
|
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
|
|
|
|
|
CrmCustomerDO::getId, userId, CrmSceneTypeEnum.OWNER.getType(), Boolean.FALSE);
|
|
|
|
|
|
|
|
|
|
// 未跟进
|
|
|
|
|
query.ne(CrmClueDO::getFollowUpStatus, true);
|
|
|
|
|
|
|
|
|
|
return selectCount(query);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|