mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
crm-客户管理:新增客户放入公海和领取公海客户
This commit is contained in:
parent
77d7bcc73f
commit
b41d469d46
@ -37,6 +37,9 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户已存在所属负责人");
|
||||
ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户状态已锁定");
|
||||
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 个单独配置段噢
|
||||
ErrorCode CUSTOMER_POOL_CONFIG_ERROR = new ErrorCode(1_020_006_001, "客户公海规则设置不正确");
|
||||
ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_006_002, "客户限制配置不存在");
|
||||
|
@ -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.convert.customer.CrmCustomerConvert;
|
||||
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.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
@ -103,23 +101,21 @@ public class CrmCustomerController {
|
||||
return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap));
|
||||
}
|
||||
|
||||
// TODO @puhui999:领取公海客户,是不是放到客户那更合适哈?
|
||||
@PutMapping("/receive")
|
||||
@Operation(summary = "领取公海数据")
|
||||
@PreAuthorize("@ss.hasPermission('crm:permission:update')")
|
||||
public CommonResult<Boolean> receive(@RequestParam("bizType") Integer bizType, @RequestParam("bizId") Long bizId) {
|
||||
permissionService.receiveBiz(bizType, bizId, getLoginUserId());
|
||||
@Operation(summary = "领取客户公海数据")
|
||||
@Parameter(name = "id", description = "客户编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
|
||||
public CommonResult<Boolean> receive(@RequestParam("id") Long id) {
|
||||
customerService.receive(id, getLoginUserId());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
// TODO @puhui999:是不是放到客户那更合适哈?
|
||||
@PutMapping("/put-pool")
|
||||
@Operation(summary = "数据放入公海")
|
||||
@PreAuthorize("@ss.hasPermission('crm:permission:update')")
|
||||
@CrmPermission(bizTypeValue = "#bizType", bizId = "#bizId"
|
||||
, level = CrmPermissionLevelEnum.OWNER)
|
||||
public CommonResult<Boolean> putPool(@RequestParam(value = "bizType") Integer bizType, @RequestParam("bizId") Long bizId) {
|
||||
permissionService.putPool(bizType, bizId, getLoginUserId());
|
||||
@Parameter(name = "id", description = "客户编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('crm:customer:update')")
|
||||
public CommonResult<Boolean> putPool(@RequestParam("id") Long id) {
|
||||
customerService.putPool(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -35,10 +34,10 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> {
|
||||
.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>()
|
||||
.eq(CrmPermissionDO::getBizType, bizType)
|
||||
.in(CrmPermissionDO::getBizId, bizIds)
|
||||
.eq(CrmPermissionDO::getBizId, bizId)
|
||||
.eq(CrmPermissionDO::getLevel, level));
|
||||
}
|
||||
|
||||
|
@ -86,14 +86,16 @@ public interface CrmCustomerService {
|
||||
void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
|
||||
|
||||
// TODO @xiaqing:根据 controller 的建议,改下
|
||||
|
||||
/**
|
||||
* 领取公海客户
|
||||
*
|
||||
* @param ids 要领取的客户 id
|
||||
*/
|
||||
void receive(List<Long>ids);
|
||||
void receive(List<Long> ids);
|
||||
|
||||
// TODO @xiaqing:根据 controller 的建议,改下
|
||||
|
||||
/**
|
||||
* 分配公海客户
|
||||
*
|
||||
@ -101,6 +103,21 @@ public interface CrmCustomerService {
|
||||
* @param ownerId 分配的负责人id
|
||||
* @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);
|
||||
|
||||
}
|
||||
|
@ -135,8 +135,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
|
||||
// 1. 校验合同是否存在
|
||||
// 1. 校验客户是否存在
|
||||
validateCustomer(reqVO.getId());
|
||||
|
||||
// 2. 数据权限转移
|
||||
@ -169,6 +170,50 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
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){
|
||||
// 先一次性校验完成客户是否可用
|
||||
// TODO @xiaqing:批量一次性加载客户列表,然后去逐个校验;
|
||||
|
@ -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.dal.dataobject.permission.CrmPermissionDO;
|
||||
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.CrmPermissionTransferReqBO;
|
||||
|
||||
@ -33,6 +34,13 @@ public interface CrmPermissionService {
|
||||
*/
|
||||
void updatePermission(CrmPermissionUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 数据权限转移
|
||||
*
|
||||
* @param crmPermissionTransferReqBO 数据权限转移请求
|
||||
*/
|
||||
void transferPermission(@Valid CrmPermissionTransferReqBO crmPermissionTransferReqBO);
|
||||
|
||||
/**
|
||||
* 删除数据权限
|
||||
*
|
||||
@ -41,14 +49,13 @@ public interface CrmPermissionService {
|
||||
void deletePermission(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获取用户数据权限通过 数据类型 x 某个数据 x 用户编号
|
||||
* 删除数据权限
|
||||
*
|
||||
* @param bizType 数据类型,关联 {@link CrmBizTypeEnum}
|
||||
* @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
|
||||
* @param userId 用户编号,AdminUser#id
|
||||
* @return Crm 数据权限
|
||||
* @param level 数据权限级别,关联 {@link CrmPermissionLevelEnum}
|
||||
*/
|
||||
CrmPermissionDO getPermissionByBizTypeAndBizIdAndUserId(Integer bizType, Long bizId, Long userId);
|
||||
void deletePermission(Integer bizType, Long bizId, Integer level);
|
||||
|
||||
/**
|
||||
* 获取用户数据权限通过 权限编号 x 用户编号
|
||||
@ -69,22 +76,12 @@ public interface CrmPermissionService {
|
||||
List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId);
|
||||
|
||||
/**
|
||||
* 获取数据权限列表,通过 数据类型 x 某个数据
|
||||
* 获得数据权限列表
|
||||
*
|
||||
* @param bizType 数据类型,关联 {@link CrmBizTypeEnum}
|
||||
* @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
|
||||
* @param level 权限级别
|
||||
* @return Crm 数据权限列表
|
||||
* @param ids 数据权限编号列表
|
||||
* @return 数据权限列表
|
||||
*/
|
||||
List<CrmPermissionDO> getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection<Long> bizIds, Integer level);
|
||||
|
||||
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);
|
||||
|
||||
/**
|
||||
* 领取公海数据
|
||||
*
|
||||
* @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);
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.framework.enums.CrmPermissionLevelEnum.isOwner;
|
||||
|
||||
@ -61,52 +62,6 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
|
||||
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
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void transferPermission(CrmPermissionTransferReqBO transferReqBO) {
|
||||
@ -148,31 +103,58 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
|
||||
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
|
||||
public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long 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
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user