crm-客户管理:新增客户放入公海和领取公海客户

This commit is contained in:
puhui999 2023-11-22 18:44:49 +08:00
parent 77d7bcc73f
commit b41d469d46
7 changed files with 144 additions and 123 deletions

View File

@ -37,6 +37,9 @@ public interface ErrorCodeConstants {
ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户已存在所属负责人"); ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户已存在所属负责人");
ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户状态已锁定"); ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户状态已锁定");
ErrorCode CUSTOMER_ALREADY_DEAL = new ErrorCode(1_020_006_003, "客户已交易"); ErrorCode CUSTOMER_ALREADY_DEAL = new ErrorCode(1_020_006_003, "客户已交易");
ErrorCode CUSTOMER_NOT_IN_POOL = new ErrorCode(1_020_006_004, "客户领取失败,原因:不是公海客户");
ErrorCode CUSTOMER_IN_POOL = new ErrorCode(1_020_006_005, "客户放入公海失败,原因:已经是公海客户");
ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_006, "客户放入公海失败,原因:客户已锁定");
// TODO @wanwan 2 个单独配置段噢 // TODO @wanwan 2 个单独配置段噢
ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确"); ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确");
ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在"); ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在");

View File

@ -8,8 +8,6 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
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.framework.core.annotations.CrmPermission;
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.DeptApi;
@ -103,23 +101,21 @@ public class CrmCustomerController {
return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap)); return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap));
} }
// TODO @puhui999领取公海客户是不是放到客户那更合适哈
@PutMapping("/receive") @PutMapping("/receive")
@Operation(summary = "领取公海数据") @Operation(summary = "领取客户公海数据")
@PreAuthorize("@ss.hasPermission('crm:permission:update')") @Parameter(name = "id", description = "客户编号", required = true, example = "1024")
public CommonResult<Boolean> receive(@RequestParam("bizType") Integer bizType, @RequestParam("bizId") Long bizId) { @PreAuthorize("@ss.hasPermission('crm:customer:update')")
permissionService.receiveBiz(bizType, bizId, getLoginUserId()); public CommonResult<Boolean> receive(@RequestParam("id") Long id) {
customerService.receive(id, getLoginUserId());
return success(true); return success(true);
} }
// TODO @puhui999是不是放到客户那更合适哈
@PutMapping("/put-pool") @PutMapping("/put-pool")
@Operation(summary = "数据放入公海") @Operation(summary = "数据放入公海")
@PreAuthorize("@ss.hasPermission('crm:permission:update')") @Parameter(name = "id", description = "客户编号", required = true, example = "1024")
@CrmPermission(bizTypeValue = "#bizType", bizId = "#bizId" @PreAuthorize("@ss.hasPermission('crm:customer:update')")
, level = CrmPermissionLevelEnum.OWNER) public CommonResult<Boolean> putPool(@RequestParam("id") Long id) {
public CommonResult<Boolean> putPool(@RequestParam(value = "bizType") Integer bizType, @RequestParam("bizId") Long bizId) { customerService.putPool(id);
permissionService.putPool(bizType, bizId, getLoginUserId());
return success(true); return success(true);
} }

View File

@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -35,10 +34,10 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> {
.eq(CrmPermissionDO::getUserId, userId)); .eq(CrmPermissionDO::getUserId, userId));
} }
default List<CrmPermissionDO> selectListByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level) { default List<CrmPermissionDO> selectListByBizTypeAndBizIdAndLevel(Integer bizType, Long bizId, Integer level) {
return selectList(new LambdaQueryWrapperX<CrmPermissionDO>() return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
.eq(CrmPermissionDO::getBizType, bizType) .eq(CrmPermissionDO::getBizType, bizType)
.in(CrmPermissionDO::getBizId, bizIds) .eq(CrmPermissionDO::getBizId, bizId)
.eq(CrmPermissionDO::getLevel, level)); .eq(CrmPermissionDO::getLevel, level));
} }

View File

@ -86,14 +86,16 @@ public interface CrmCustomerService {
void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
// TODO @xiaqing根据 controller 的建议改下 // TODO @xiaqing根据 controller 的建议改下
/** /**
* 领取公海客户 * 领取公海客户
* *
* @param ids 要领取的客户 id * @param ids 要领取的客户 id
*/ */
void receive(List<Long>ids); void receive(List<Long> ids);
// TODO @xiaqing根据 controller 的建议改下 // TODO @xiaqing根据 controller 的建议改下
/** /**
* 分配公海客户 * 分配公海客户
* *
@ -101,6 +103,21 @@ public interface CrmCustomerService {
* @param ownerId 分配的负责人id * @param ownerId 分配的负责人id
* @author xiaqing * @author xiaqing
*/ */
void distributeByIds(List<Long>cIds,Long ownerId); void distributeByIds(List<Long> cIds, Long ownerId);
/**
* 领取公海客户
*
* @param id 编号
* @param userId 用户编号
*/
void receive(Long id, Long userId);
/**
* 客户放入公海
*
* @param id 客户编号
*/
void putPool(Long id);
} }

View File

@ -135,8 +135,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) { public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
// 1. 校验合同是否存在 // 1. 校验客户是否存在
validateCustomer(reqVO.getId()); validateCustomer(reqVO.getId());
// 2. 数据权限转移 // 2. 数据权限转移
@ -169,6 +170,50 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
transferCustomerOwner(cIds,ownerId); transferCustomerOwner(cIds,ownerId);
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void receive(Long id, Long userId) {
// 1. 校验存在
CrmCustomerDO customer = customerMapper.selectById(id);
if (customer == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2. 校验是否为公海数据
if (customer.getOwnerUserId() != null) {
throw exception(CUSTOMER_NOT_IN_POOL);
}
// 2. 领取公海数据-设置负责人
customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(userId));
// 3. 创建负责人数据权限
crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
.setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void putPool(Long id) {
// 1. 校验存在
CrmCustomerDO customer = customerMapper.selectById(id);
if (customer == null) {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2. 校验是否为公海数据
if (customer.getOwnerUserId() == null) {
throw exception(CUSTOMER_IN_POOL);
}
// 1.3. 校验客户是否锁定
if (customer.getLockStatus()) {
throw exception(CUSTOMER_LOCKED_PUT_POOL_FAIL);
}
// 2. 公海数据-设置负责人 NULL
customerMapper.updateById(new CrmCustomerDO().setId(customer.getId()).setOwnerUserId(null));
// 3. 删除负责人数据权限
crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
CrmPermissionLevelEnum.OWNER.getLevel());
}
private void transferCustomerOwner(List <Long> cIds, Long ownerId){ private void transferCustomerOwner(List <Long> cIds, Long ownerId){
// 先一次性校验完成客户是否可用 // 先一次性校验完成客户是否可用
// TODO @xiaqing批量一次性加载客户列表然后去逐个校验 // TODO @xiaqing批量一次性加载客户列表然后去逐个校验

View File

@ -4,6 +4,7 @@ package cn.iocoder.yudao.module.crm.service.permission;
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
@ -33,6 +34,13 @@ public interface CrmPermissionService {
*/ */
void updatePermission(CrmPermissionUpdateReqVO updateReqVO); void updatePermission(CrmPermissionUpdateReqVO updateReqVO);
/**
* 数据权限转移
*
* @param crmPermissionTransferReqBO 数据权限转移请求
*/
void transferPermission(@Valid CrmPermissionTransferReqBO crmPermissionTransferReqBO);
/** /**
* 删除数据权限 * 删除数据权限
* *
@ -41,14 +49,13 @@ public interface CrmPermissionService {
void deletePermission(Collection<Long> ids); void deletePermission(Collection<Long> ids);
/** /**
* 获取用户数据权限通过 数据类型 x 某个数据 x 用户编号 * 删除数据权限
* *
* @param bizType 数据类型关联 {@link CrmBizTypeEnum} * @param bizType 数据类型关联 {@link CrmBizTypeEnum}
* @param bizId 数据编号关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() * @param bizId 数据编号关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
* @param userId 用户编号AdminUser#id * @param level 数据权限级别关联 {@link CrmPermissionLevelEnum}
* @return Crm 数据权限
*/ */
CrmPermissionDO getPermissionByBizTypeAndBizIdAndUserId(Integer bizType, Long bizId, Long userId); void deletePermission(Integer bizType, Long bizId, Integer level);
/** /**
* 获取用户数据权限通过 权限编号 x 用户编号 * 获取用户数据权限通过 权限编号 x 用户编号
@ -69,22 +76,12 @@ public interface CrmPermissionService {
List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId); List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId);
/** /**
* 取数据权限列表通过 数据类型 x 某个数据 * 得数据权限列表
* *
* @param bizType 数据类型关联 {@link CrmBizTypeEnum} * @param ids 数据权限编号列表
* @param bizIds 数据编号关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() * @return 数据权限列表
* @param level 权限级别
* @return Crm 数据权限列表
*/ */
List<CrmPermissionDO> getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level);
List<CrmPermissionDO> getPermissionListByIds(Collection<Long> ids); List<CrmPermissionDO> getPermissionListByIds(Collection<Long> ids);
/**
* 数据权限转移
*
* @param crmPermissionTransferReqBO 数据权限转移请求
*/
void transferPermission(@Valid CrmPermissionTransferReqBO crmPermissionTransferReqBO);
/** /**
* 获取用户参与的模块数据列表 * 获取用户参与的模块数据列表
@ -95,22 +92,4 @@ 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 用户编号AdminUser#id
*/
void receiveBiz(Integer bizType, Long bizId, Long userId);
/**
* 数据放入公海
*
* @param bizType 数据类型关联 {@link CrmBizTypeEnum}
* @param bizId 数据编号关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
* @param userId 用户编号AdminUser#id
*/
void putPool(Integer bizType, Long bizId, Long userId);
} }

View File

@ -21,6 +21,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.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.framework.enums.CrmPermissionLevelEnum.isOwner; import static cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum.isOwner;
@ -61,52 +62,6 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
crmPermissionMapper.updateBatch(updateDO); crmPermissionMapper.updateBatch(updateDO);
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void deletePermission(Collection<Long> ids) {
// 校验存在
validateCrmPermissionExists(ids);
// 删除
crmPermissionMapper.deleteBatchIds(ids);
}
@Override
public CrmPermissionDO getPermissionByBizTypeAndBizIdAndUserId(Integer bizType, Long bizId, Long userId) {
return crmPermissionMapper.selectByBizTypeAndBizIdByUserId(bizType, bizId, userId);
}
@Override
public CrmPermissionDO getPermissionByIdAndUserId(Long id, Long userId) {
return crmPermissionMapper.selectByIdAndUserId(id, userId);
}
@Override
public List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId) {
return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId);
}
@Override
public List<CrmPermissionDO> getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level) {
return crmPermissionMapper.selectListByBizTypeAndBizIdsAndLevel(bizType, bizIds, level);
}
@Override
public List<CrmPermissionDO> getPermissionListByIds(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return crmPermissionMapper.selectBatchIds(ids);
}
private void validateCrmPermissionExists(Collection<Long> ids) {
List<CrmPermissionDO> permissionList = crmPermissionMapper.selectBatchIds(ids);
// 校验存在
if (ObjUtil.notEqual(permissionList.size(), ids.size())) {
throw exception(CRM_PERMISSION_NOT_EXISTS);
}
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void transferPermission(CrmPermissionTransferReqBO transferReqBO) { public void transferPermission(CrmPermissionTransferReqBO transferReqBO) {
@ -148,31 +103,58 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
crmPermissionMapper.deleteById(oldPermission.getId()); crmPermissionMapper.deleteById(oldPermission.getId());
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void deletePermission(Collection<Long> ids) {
// 校验存在
validateCrmPermissionExists(ids);
// 删除
crmPermissionMapper.deleteBatchIds(ids);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deletePermission(Integer bizType, Long bizId, Integer level) {
List<CrmPermissionDO> permissions = crmPermissionMapper.selectListByBizTypeAndBizIdAndLevel(bizType, bizId, level);
// 校验存在
if (CollUtil.isEmpty(permissions)) {
throw exception(CRM_PERMISSION_NOT_EXISTS);
}
// 删除数据权限
crmPermissionMapper.deleteBatchIds(convertSet(permissions, CrmPermissionDO::getId));
}
@Override
public CrmPermissionDO getPermissionByIdAndUserId(Long id, Long userId) {
return crmPermissionMapper.selectByIdAndUserId(id, userId);
}
@Override
public List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId) {
return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId);
}
@Override
public List<CrmPermissionDO> getPermissionListByIds(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return crmPermissionMapper.selectBatchIds(ids);
}
private void validateCrmPermissionExists(Collection<Long> ids) {
List<CrmPermissionDO> permissionList = crmPermissionMapper.selectBatchIds(ids);
// 校验存在
if (ObjUtil.notEqual(permissionList.size(), ids.size())) {
throw exception(CRM_PERMISSION_NOT_EXISTS);
}
}
@Override @Override
public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId) { public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId) {
return crmPermissionMapper.selectListByBizTypeAndUserId(bizType, userId); return crmPermissionMapper.selectListByBizTypeAndUserId(bizType, userId);
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void receiveBiz(Integer bizType, Long bizId, Long userId) {
//CrmPermissionDO permission = crmPermissionMapper.selectByBizTypeAndBizIdByUserId(bizType, bizId, CrmPermissionDO.POOL_USER_ID);
//if (permission == null) { // 不存在则模块数据也不存在
// throw exception(CRM_PERMISSION_MODEL_NOT_EXISTS, CrmBizTypeEnum.getNameByType(bizType));
//}
//
//crmPermissionMapper.updateById(new CrmPermissionDO().setId(permission.getId()).setUserId(userId));
// TODO puhui999: 领取数据后需要创建一个负责人数据权限
}
@Override
@Transactional(rollbackFor = Exception.class)
public void putPool(Integer bizType, Long bizId, Long userId) {
CrmPermissionDO permission = crmPermissionMapper.selectByBizTypeAndBizIdByUserId(bizType, bizId, userId);
if (permission == null) { // 不存在则模块数据也不存在
throw exception(CRM_PERMISSION_MODEL_NOT_EXISTS, CrmBizTypeEnum.getNameByType(bizType));
}
// TODO puhui999: 数据放入公海后删除负责人的数据权限完事数据负责人设置为 null
}
} }