CRM-客户: 完善 TODO

This commit is contained in:
puhui999 2024-01-27 13:34:59 +08:00
parent d492daced4
commit d8b2da8eed
9 changed files with 40 additions and 54 deletions

View File

@ -37,6 +37,10 @@
<groupId>cn.iocoder.boot</groupId> <groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-ip</artifactId> <artifactId>yudao-spring-boot-starter-biz-ip</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-tenant</artifactId>
</dependency>
<!-- Web 相关 --> <!-- Web 相关 -->
<dependency> <dependency>
@ -70,11 +74,5 @@
<groupId>cn.iocoder.boot</groupId> <groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-test</artifactId> <artifactId>yudao-spring-boot-starter-test</artifactId>
</dependency> </dependency>
<!-- TODO @puhui999放的位置要整齐哈。 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-tenant</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -100,11 +100,11 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
return selectJoinPage(pageReqVO, CrmCustomerDO.class, query); return selectJoinPage(pageReqVO, CrmCustomerDO.class, query);
} }
default List<CrmCustomerDO> selectListByLockStatusAndOwnerUserIdNotNull(Boolean lockStatus) { default List<CrmCustomerDO> selectListByLockAndDealStatusAndNotPool(Boolean lockStatus, Boolean dealStatus) {
return selectList(new LambdaQueryWrapper<CrmCustomerDO>() return selectList(new LambdaQueryWrapper<CrmCustomerDO>()
.eq(CrmCustomerDO::getLockStatus, lockStatus) .eq(CrmCustomerDO::getLockStatus, lockStatus)
// TODO @puhui999not null 可以转化成大于 0 .eq(CrmCustomerDO::getDealStatus, dealStatus)
.isNotNull(CrmCustomerDO::getOwnerUserId)); .gt(CrmCustomerDO::getOwnerUserId, 0));
} }
} }

View File

@ -1,17 +1,9 @@
package cn.iocoder.yudao.module.crm.framework.permission.core.util; package cn.iocoder.yudao.module.crm.framework.permission.core.util;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionRoleCodeEnum; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionRoleCodeEnum;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi; import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
/** /**
@ -30,22 +22,6 @@ public class CrmPermissionUtils {
return SingletonManager.getPermissionApi().hasAnyRoles(getLoginUserId(), CrmPermissionRoleCodeEnum.CRM_ADMIN.getCode()); return SingletonManager.getPermissionApi().hasAnyRoles(getLoginUserId(), CrmPermissionRoleCodeEnum.CRM_ADMIN.getCode());
} }
// TODO @puhui999这个貌似直接放到 CrmPermissionService 会更好
/**
* 校验权限
*
* @param bizType 数据类型关联 {@link CrmBizTypeEnum}
* @param bizId 数据编号关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
* @param userId 用户编号
* @param levelEnum 权限级别
* @return boolean
*/
public static boolean hasPermission(Integer bizType, Long bizId, Long userId, CrmPermissionLevelEnum levelEnum) {
List<CrmPermissionDO> permissionList = SingletonManager.getCrmPermissionService().getPermissionListByBiz(bizType, bizId);
return anyMatch(permissionList, permission ->
ObjUtil.equal(permission.getUserId(), userId) && ObjUtil.equal(permission.getLevel(), levelEnum.getLevel()));
}
/** /**
* 静态内部类实现单例获取 * 静态内部类实现单例获取
* *
@ -54,16 +30,11 @@ public class CrmPermissionUtils {
private static class SingletonManager { private static class SingletonManager {
private static final PermissionApi PERMISSION_API = SpringUtil.getBean(PermissionApi.class); private static final PermissionApi PERMISSION_API = SpringUtil.getBean(PermissionApi.class);
private static final CrmPermissionService CRM_PERMISSION_SERVICE = SpringUtil.getBean(CrmPermissionService.class);
public static PermissionApi getPermissionApi() { public static PermissionApi getPermissionApi() {
return PERMISSION_API; return PERMISSION_API;
} }
public static CrmPermissionService getCrmPermissionService() {
return CRM_PERMISSION_SERVICE;
}
} }
} }

View File

@ -20,7 +20,7 @@ public class CrmCustomerAutoPutPoolJob implements JobHandler {
@Override @Override
@TenantJob @TenantJob
public String execute(String param) { public String execute(String param) {
int count = customerService.customerAutoPutPoolBySystem(); int count = customerService.autoPutCustomerPool();
return String.format("掉入公海客户 %s 个", count); return String.format("掉入公海客户 %s 个", count);
} }

View File

@ -126,12 +126,11 @@ public interface CrmCustomerService {
*/ */
void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive); void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive);
// TODO @puhui999autoPutCustomerPool注释说明是系统就好哈
/** /**
* 系统客户自动掉入公海 * 系统客户自动掉入公海
* *
* @return 掉入公海数量 * @return 掉入公海数量
*/ */
int customerAutoPutPoolBySystem(); int autoPutCustomerPool();
} }

View File

@ -47,6 +47,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT; import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
@ -313,23 +314,22 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
} }
@Override @Override
public int customerAutoPutPoolBySystem() { public int autoPutCustomerPool() {
CrmCustomerPoolConfigDO poolConfig = customerPoolConfigService.getCustomerPoolConfig(); CrmCustomerPoolConfigDO poolConfig = customerPoolConfigService.getCustomerPoolConfig();
if (poolConfig == null || !poolConfig.getEnabled()) { if (poolConfig == null || !poolConfig.getEnabled()) {
return 0; return 0;
} }
// 1. 获取没有锁定的不在公海的客户 // 1.1 获取没有锁定的不在公海的客户且没有成交的
List<CrmCustomerDO> customerList = customerMapper.selectListByLockStatusAndOwnerUserIdNotNull(Boolean.FALSE); List<CrmCustomerDO> notDealCustomerList = customerMapper.selectListByLockAndDealStatusAndNotPool(Boolean.FALSE, Boolean.FALSE);
List<CrmCustomerDO> poolCustomerList = CollectionUtils.filterList(customerList, customer -> { // 1.2 获取没有锁定的不在公海的客户且成交的
// TODO @puhui999建议这里作为一个查询条件哈不放内存里过滤 List<CrmCustomerDO> dealCustomerList = customerMapper.selectListByLockAndDealStatusAndNotPool(Boolean.FALSE, Boolean.TRUE);
// 1.1 未成交放入公海 List<CrmCustomerDO> poolCustomerList = new ArrayList<>();
if (!customer.getDealStatus()) { poolCustomerList.addAll(filterList(notDealCustomerList, customer ->
return (poolConfig.getDealExpireDays() - LocalDateTimeUtils.between(customer.getCreateTime())) <= 0; (poolConfig.getDealExpireDays() - LocalDateTimeUtils.between(customer.getCreateTime())) <= 0));
} poolCustomerList.addAll(filterList(dealCustomerList, customer -> {
// 1.2 未跟进放入公海
LocalDateTime lastTime = ObjUtil.defaultIfNull(customer.getContactLastTime(), customer.getCreateTime()); LocalDateTime lastTime = ObjUtil.defaultIfNull(customer.getContactLastTime(), customer.getCreateTime());
return (poolConfig.getContactExpireDays() - LocalDateTimeUtils.between(lastTime)) <= 0; return (poolConfig.getContactExpireDays() - LocalDateTimeUtils.between(lastTime)) <= 0;
}); }));
// 2. 逐个放入公海 // 2. 逐个放入公海
int count = 0; int count = 0;

View File

@ -33,7 +33,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_DELETE_DENIED; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_DELETE_DENIED;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_NOT_EXISTS; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_NOT_EXISTS;
import static cn.iocoder.yudao.module.crm.framework.permission.core.util.CrmPermissionUtils.hasPermission;
/** /**
* 跟进记录 Service 实现类 * 跟进记录 Service 实现类
@ -119,7 +118,7 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
// 校验存在 // 校验存在
CrmFollowUpRecordDO followUpRecord = validateFollowUpRecordExists(id); CrmFollowUpRecordDO followUpRecord = validateFollowUpRecordExists(id);
// 校验权限 // 校验权限
if (!hasPermission(followUpRecord.getBizType(), followUpRecord.getBizId(), userId, CrmPermissionLevelEnum.OWNER)) { if (!permissionService.hasPermission(followUpRecord.getBizType(), followUpRecord.getBizId(), userId, CrmPermissionLevelEnum.OWNER)) {
throw exception(FOLLOW_UP_RECORD_DELETE_DENIED); throw exception(FOLLOW_UP_RECORD_DELETE_DENIED);
} }

View File

@ -108,4 +108,15 @@ public interface CrmPermissionService {
*/ */
List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId); List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId);
/**
* 校验权限
*
* @param bizType 数据类型关联 {@link CrmBizTypeEnum}
* @param bizId 数据编号关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
* @param userId 用户编号
* @param levelEnum 权限级别
* @return boolean
*/
boolean hasPermission(Integer bizType, Long bizId, Long userId, CrmPermissionLevelEnum levelEnum);
} }

View File

@ -24,6 +24,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum.isOwner; import static cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum.isOwner;
@ -211,4 +212,11 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
return permissionMapper.selectListByBizTypeAndUserId(bizType, userId); return permissionMapper.selectListByBizTypeAndUserId(bizType, userId);
} }
@Override
public boolean hasPermission(Integer bizType, Long bizId, Long userId, CrmPermissionLevelEnum levelEnum) {
List<CrmPermissionDO> permissionList = permissionMapper.selectByBizTypeAndBizId(bizType, bizId);
return anyMatch(permissionList, permission ->
ObjUtil.equal(permission.getUserId(), userId) && ObjUtil.equal(permission.getLevel(), levelEnum.getLevel()));
}
} }