diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java index 6b5eea184..4dc209d7d 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java @@ -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, "客户限制配置不存在"); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java index 3a1c4746e..f0da5eb65 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java @@ -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 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 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 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 putPool(@RequestParam("id") Long id) { + customerService.putPool(id); return success(true); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java index ad54a7604..349318502 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java @@ -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 { .eq(CrmPermissionDO::getUserId, userId)); } - default List selectListByBizTypeAndBizIdsAndLevel(Integer bizType, Collection bizIds, Integer level) { + default List selectListByBizTypeAndBizIdAndLevel(Integer bizType, Long bizId, Integer level) { return selectList(new LambdaQueryWrapperX() .eq(CrmPermissionDO::getBizType, bizType) - .in(CrmPermissionDO::getBizId, bizIds) + .eq(CrmPermissionDO::getBizId, bizId) .eq(CrmPermissionDO::getLevel, level)); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java index 6aa21477e..497196aa5 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java @@ -86,21 +86,38 @@ public interface CrmCustomerService { void lockCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO); // TODO @xiaqing:根据 controller 的建议,改下 + /** * 领取公海客户 * * @param ids 要领取的客户 id */ - void receive(Listids); + void receive(List ids); // TODO @xiaqing:根据 controller 的建议,改下 + /** * 分配公海客户 * - * @param cIds 要分配的客户 id + * @param cIds 要分配的客户 id * @param ownerId 分配的负责人id * @author xiaqing */ - void distributeByIds(ListcIds,Long ownerId); + void distributeByIds(List cIds, Long ownerId); + + /** + * 领取公海客户 + * + * @param id 编号 + * @param userId 用户编号 + */ + void receive(Long id, Long userId); + + /** + * 客户放入公海 + * + * @param id 客户编号 + */ + void putPool(Long id); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java index b1e6404bb..131a03ce4 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java @@ -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 cIds, Long ownerId){ // 先一次性校验完成客户是否可用 // TODO @xiaqing:批量一次性加载客户列表,然后去逐个校验; diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java index e1f471669..638388031 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java @@ -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 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 getPermissionByBizTypeAndBizId(Integer bizType, Long bizId); /** - * 获取数据权限列表,通过 数据类型 x 某个数据 + * 获得数据权限列表 * - * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} - * @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() - * @param level 权限级别 - * @return Crm 数据权限列表 + * @param ids 数据权限编号列表 + * @return 数据权限列表 */ - List getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection bizIds, Integer level); - List getPermissionListByIds(Collection ids); - /** - * 数据权限转移 - * - * @param crmPermissionTransferReqBO 数据权限转移请求 - */ - void transferPermission(@Valid CrmPermissionTransferReqBO crmPermissionTransferReqBO); /** * 获取用户参与的模块数据列表 @@ -95,22 +92,4 @@ public interface CrmPermissionService { */ List 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); - } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java index 330678bd5..5d85ebf80 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java @@ -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 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 getPermissionByBizTypeAndBizId(Integer bizType, Long bizId) { - return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId); - } - - @Override - public List getPermissionByBizTypeAndBizIdsAndLevel(Integer bizType, Collection bizIds, Integer level) { - return crmPermissionMapper.selectListByBizTypeAndBizIdsAndLevel(bizType, bizIds, level); - } - - @Override - public List getPermissionListByIds(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return Collections.emptyList(); - } - return crmPermissionMapper.selectBatchIds(ids); - } - - private void validateCrmPermissionExists(Collection ids) { - List 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 ids) { + // 校验存在 + validateCrmPermissionExists(ids); + + // 删除 + crmPermissionMapper.deleteBatchIds(ids); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deletePermission(Integer bizType, Long bizId, Integer level) { + List 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 getPermissionByBizTypeAndBizId(Integer bizType, Long bizId) { + return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId); + } + + @Override + public List getPermissionListByIds(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } + return crmPermissionMapper.selectBatchIds(ids); + } + + private void validateCrmPermissionExists(Collection ids) { + List permissionList = crmPermissionMapper.selectBatchIds(ids); + // 校验存在 + if (ObjUtil.notEqual(permissionList.size(), ids.size())) { + throw exception(CRM_PERMISSION_NOT_EXISTS); + } + } + @Override public List 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 - } - }