From 0043d02d0a10027ba0151a6e7ff4aef51c55e64c Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 9 Mar 2024 14:31:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix=EF=BC=9A=E5=95=86=E6=9C=BA=20api=20?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E7=94=9F=E6=88=90=E4=B8=8D=E5=AF=B9=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/vo/business/CrmBusinessSaveReqVO.java | 4 ++-- .../crm/service/business/CrmBusinessServiceImpl.java | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java index a9ebaae05..fa86692e7 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java @@ -66,13 +66,13 @@ public class CrmBusinessSaveReqVO { private Long contactId; // 使用场景,在【联系人详情】添加商机时,如果需要关联两者,需要传递 contactId 字段 @Schema(description = "产品列表") - private List products; + private List businessProducts; @Schema(description = "产品列表") @Data @NoArgsConstructor @AllArgsConstructor - public static class Product { + public static class BusinessProduct { @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529") @NotNull(message = "产品编号不能为空") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java index 9f2e4ceb6..5ec0a4b41 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.crm.service.business; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; -import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; @@ -24,7 +23,6 @@ import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService; import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; -import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerServiceImpl; import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; @@ -90,7 +88,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { success = CRM_BUSINESS_CREATE_SUCCESS) public Long createBusiness(CrmBusinessSaveReqVO createReqVO, Long userId) { // 1.1 校验产品项的有效性 - List businessProducts = validateBusinessProducts(createReqVO.getProducts()); + List businessProducts = validateBusinessProducts(createReqVO.getBusinessProducts()); // 1.2 校验关联字段 validateRelationDataExists(createReqVO); @@ -131,7 +129,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { // 1.1 校验存在 CrmBusinessDO oldBusiness = validateBusinessExists(updateReqVO.getId()); // 1.2 校验产品项的有效性 - List businessProducts = validateBusinessProducts(updateReqVO.getProducts()); + List businessProducts = validateBusinessProducts(updateReqVO.getBusinessProducts()); // 1.3 校验关联字段 validateRelationDataExists(updateReqVO); @@ -204,9 +202,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { } } - private List validateBusinessProducts(List list) { + private List validateBusinessProducts(List list) { // 1. 校验产品存在 - productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.Product::getProductId)); + productService.validProductList(convertSet(list, CrmBusinessSaveReqVO.BusinessProduct::getProductId)); // 2. 转化为 CrmBusinessProductDO 列表 return convertList(list, o -> BeanUtils.toBean(o, CrmBusinessProductDO.class, item -> item.setTotalPrice(MoneyUtils.priceMultiply(item.getBusinessPrice(), item.getCount())))); From 47a698868c19f6457b19790d1aeaf5d7db2b26f4 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 9 Mar 2024 17:00:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?CRM:=20=E6=A0=B9=E6=8D=AE=20review=20?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/crm/enums/ErrorCodeConstants.java | 1 + .../permission/CrmPermissionLevelEnum.java | 7 + .../permission/CrmPermissionController.java | 48 +----- .../mysql/permission/CrmPermissionMapper.java | 8 +- .../permission/CrmPermissionService.java | 17 ++- .../permission/CrmPermissionServiceImpl.java | 138 +++++++++++++++++- 6 files changed, 159 insertions(+), 60 deletions(-) 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 5d942d875..4a0976bb1 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 @@ -74,6 +74,7 @@ public interface ErrorCodeConstants { ErrorCode CRM_PERMISSION_DELETE_DENIED = new ErrorCode(1_020_007_006, "删除数据权限失败,原因:没有权限"); ErrorCode CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_007, "删除数据权限失败,原因:不能删除负责人"); ErrorCode CRM_PERMISSION_CREATE_FAIL = new ErrorCode(1_020_007_008, "创建数据权限失败,原因:所加用户已有权限"); + ErrorCode CRM_PERMISSION_CREATE_FAIL_EXISTS = new ErrorCode(1_020_007_009, "同时添加数据权限失败,原因:用户【{}】已有模块【{}】数据【{}】的【{}】权限"); // ========== 产品 1_020_008_000 ========== ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_020_008_000, "产品不存在"); diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java index 7b44fe962..f36e8cfff 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.crm.enums.permission; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; @@ -50,4 +51,10 @@ public enum CrmPermissionLevelEnum implements IntArrayValuable { return ObjUtil.equal(WRITE.level, level); } + public static String getNameByLevel(Integer level) { + CrmPermissionLevelEnum typeEnum = CollUtil.findOne(CollUtil.newArrayList(CrmPermissionLevelEnum.values()), + item -> ObjUtil.equal(item.level, level)); + return typeEnum == null ? null : typeEnum.getName(); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java index 11289b0ed..a39c4a6d8 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.crm.controller.admin.permission; import cn.hutool.core.collection.CollUtil; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; @@ -56,63 +57,20 @@ public class CrmPermissionController { @Resource private CrmPermissionService permissionService; @Resource - private CrmContactService contactService; - @Resource - private CrmBusinessService businessService; - @Resource - private CrmContractService contractService; - @Resource private AdminUserApi adminUserApi; @Resource private DeptApi deptApi; @Resource private PostApi postApi; - // TODO @puhui999:是不是还是叫 create 好点哈。 @PostMapping("/create") @Operation(summary = "创建数据权限") - @Transactional(rollbackFor = Exception.class) @PreAuthorize("@ss.hasPermission('crm:permission:create')") - @CrmPermission(bizTypeValue = "#reqVO.bizType", bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) - public CommonResult savePermission(@Valid @RequestBody CrmPermissionSaveReqVO reqVO) { - permissionService.createPermission(BeanUtils.toBean(reqVO, CrmPermissionCreateReqBO.class)); - // 处理【同时添加至】的权限 - if (CollUtil.isNotEmpty(reqVO.getToBizTypes())) { - createBizTypePermissions(reqVO); - } + public CommonResult create(@Valid @RequestBody CrmPermissionSaveReqVO reqVO) { + permissionService.createPermission(reqVO, getLoginUserId()); return success(true); } - private void createBizTypePermissions(CrmPermissionSaveReqVO reqVO) { - List createPermissions = new ArrayList<>(); - // TODO @puhui999:需要考虑,被添加人,是不是应该有对应的权限了; - if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTACT.getType())) { - List contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getBizId(), getLoginUserId()); - contactList.forEach(item -> { - createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CONTACT.getType()) - .setBizId(item.getId()).setUserId(reqVO.getUserId()).setLevel(reqVO.getLevel())); - }); - } - if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_BUSINESS.getType())) { - List businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getBizId(), getLoginUserId()); - businessList.forEach(item -> { - createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()) - .setBizId(item.getId()).setUserId(reqVO.getUserId()).setLevel(reqVO.getLevel())); - }); - } - if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTRACT.getType())) { - List contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getBizId(), getLoginUserId()); - contractList.forEach(item -> { - createPermissions.add(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CONTRACT.getType()) - .setBizId(item.getId()).setUserId(reqVO.getUserId()).setLevel(reqVO.getLevel())); - }); - } - if (CollUtil.isEmpty(createPermissions)) { - return; - } - permissionService.createPermissionBatch(createPermissions); - } - @PutMapping("/update") @Operation(summary = "编辑数据权限") @PreAuthorize("@ss.hasPermission('crm:permission:update')") 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 26f212e5e..07b7b6b1f 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 @@ -53,9 +53,11 @@ public interface CrmPermissionMapper extends BaseMapperX { CrmPermissionDO::getUserId, userId); } - default CrmPermissionDO selectByBizIdAndUserId(Long bizId, Long userId) { - return selectOne(CrmPermissionDO::getBizId, bizId, - CrmPermissionDO::getUserId, userId); + default CrmPermissionDO selectByBizAndUserId(Integer bizType, Long bizId, Long userId) { + return selectOne(new LambdaQueryWrapperX() + .eq(CrmPermissionDO::getBizType, bizType) + .eq(CrmPermissionDO::getBizId, bizId) + .eq(CrmPermissionDO::getUserId, userId)); } default int deletePermission(Integer bizType, Long bizId) { 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 39b101323..2ff8113e5 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 @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.crm.service.permission; +import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionSaveReqVO; 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.enums.common.CrmBizTypeEnum; @@ -19,6 +20,14 @@ import java.util.List; */ public interface CrmPermissionService { + /** + * 创建数据权限 + * + * @param reqVO 创建信息 + * @param userId 用户编号 + */ + void createPermission(CrmPermissionSaveReqVO reqVO, Long userId); + /** * 创建数据权限 * @@ -111,10 +120,10 @@ public interface CrmPermissionService { /** * 校验是否有指定数据的操作权限 * - * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} - * @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() - * @param userId 用户编号 - * @param level 权限级别 + * @param bizType 数据类型,关联 {@link CrmBizTypeEnum} + * @param bizId 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId() + * @param userId 用户编号 + * @param level 权限级别 * @return 是否有权限 */ boolean hasPermission(Integer bizType, Long bizId, Long userId, CrmPermissionLevelEnum level); 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 6fa90746b..c8b918586 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 @@ -4,28 +4,34 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionSaveReqVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO; +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; import cn.iocoder.yudao.module.crm.dal.mysql.permission.CrmPermissionMapper; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; +import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; +import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; +import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; +import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; 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.util.CrmPermissionUtils; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import jakarta.annotation.Resource; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import java.util.*; 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.*; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum.isOwner; @@ -40,13 +46,124 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { @Resource private CrmPermissionMapper permissionMapper; - + @Resource + @Lazy // 解决依赖循环 + private CrmContactService contactService; + @Resource + @Lazy // 解决依赖循环 + private CrmBusinessService businessService; + @Resource + @Lazy // 解决依赖循环 + private CrmContractService contractService; @Resource private AdminUserApi adminUserApi; + + @Override + @Transactional(rollbackFor = Exception.class) + @CrmPermission(bizTypeValue = "#reqVO.bizType", bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) + public void createPermission(CrmPermissionSaveReqVO reqVO, Long userId) { + // 创建数据权限 + createPermission0(BeanUtils.toBean(reqVO, CrmPermissionCreateReqBO.class)); + + // 处理【同时添加至】的权限 + if (CollUtil.isEmpty(reqVO.getToBizTypes())) { + return; + } + List createPermissions = new ArrayList<>(); + createContactPermissions(reqVO, userId, createPermissions); + createBusinessPermissions(reqVO, userId, createPermissions); + createContractPermissions(reqVO, userId, createPermissions); + if (CollUtil.isEmpty(createPermissions)) { + return; + } + createPermissionBatch(createPermissions); + } + + /** + * 处理同时添加至联系人 + * + * @param reqVO 请求 + * @param userId 操作人 + * @param createPermissions 待添加权限列表 + */ + private void createContactPermissions(CrmPermissionSaveReqVO reqVO, Long userId, List createPermissions) { + // 1. 校验是否被同时添加 + Integer type = CrmBizTypeEnum.CRM_CONTACT.getType(); + if (!reqVO.getToBizTypes().contains(type)) { + return; + } + + // 2.1 添加数据权限 + List contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + contactList.forEach(item -> { + createBizTypePermissions(reqVO, type, item.getId(), item.getName(), createPermissions); + }); + } + + /** + * 处理同时添加至商机 + * + * @param reqVO 请求 + * @param userId 操作人 + * @param createPermissions 待添加权限列表 + */ + private void createBusinessPermissions(CrmPermissionSaveReqVO reqVO, Long userId, List createPermissions) { + // 1. 校验是否被同时添加 + Integer type = CrmBizTypeEnum.CRM_BUSINESS.getType(); + if (!reqVO.getToBizTypes().contains(type)) { + return; + } + + // 2.1 添加数据权限 + List businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + businessList.forEach(item -> { + createBizTypePermissions(reqVO, type, item.getId(), item.getName(), createPermissions); + }); + } + + /** + * 处理同时添加至合同 + * + * @param reqVO 请求 + * @param userId 操作人 + * @param createPermissions 待添加权限列表 + */ + private void createContractPermissions(CrmPermissionSaveReqVO reqVO, Long userId, List createPermissions) { + // 1. 校验是否被同时添加 + Integer type = CrmBizTypeEnum.CRM_CONTRACT.getType(); + if (!reqVO.getToBizTypes().contains(type)) { + return; + } + + // 2.1 添加数据权限 + List contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + contractList.forEach(item -> { + createBizTypePermissions(reqVO, type, item.getId(), item.getName(), createPermissions); + }); + } + + private void createBizTypePermissions(CrmPermissionSaveReqVO reqVO, Integer type, Long bizId, String name, + List createPermissions) { + AdminUserRespDTO user = adminUserApi.getUser(reqVO.getUserId()); + // 1. 需要考虑,被添加人,是不是应该有对应的权限了; + CrmPermissionDO permission = hasAnyPermission(type, bizId, reqVO.getUserId()); + if (ObjUtil.isNotNull(permission)) { + throw exception(CRM_PERMISSION_CREATE_FAIL_EXISTS, user.getNickname(), CrmBizTypeEnum.getNameByType(type), + name, CrmPermissionLevelEnum.getNameByLevel(permission.getLevel())); + } + // 2. 添加数据权限 + createPermissions.add(new CrmPermissionCreateReqBO().setBizType(type) + .setBizId(bizId).setUserId(reqVO.getUserId()).setLevel(reqVO.getLevel())); + } + @Override @Transactional(rollbackFor = Exception.class) public Long createPermission(CrmPermissionCreateReqBO createReqBO) { + return createPermission0(createReqBO); + } + + private Long createPermission0(CrmPermissionCreateReqBO createReqBO) { validatePermissionNotExists(Collections.singletonList(createReqBO)); // 1. 校验用户是否存在 adminUserApi.validateUserList(Collections.singletonList(createReqBO.getUserId())); @@ -170,7 +287,7 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { throw exception(CRM_PERMISSION_DELETE_FAIL); } // 校验操作人是否为负责人 - CrmPermissionDO permission = permissionMapper.selectByBizIdAndUserId(permissions.get(0).getBizId(), userId); + CrmPermissionDO permission = permissionMapper.selectByBizAndUserId(permissions.get(0).getBizType(), permissions.get(0).getBizId(), userId); if (permission == null) { throw exception(CRM_PERMISSION_DELETE_DENIED); } @@ -220,4 +337,9 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { ObjUtil.equal(permission.getUserId(), userId) && ObjUtil.equal(permission.getLevel(), level.getLevel())); } + public CrmPermissionDO hasAnyPermission(Integer bizType, Long bizId, Long userId) { + List permissionList = permissionMapper.selectByBizTypeAndBizId(bizType, bizId); + return findFirst(permissionList, permission -> ObjUtil.equal(permission.getUserId(), userId)); + } + } From af5fbb6ff426c07f5ed02ef60f537c26a7d211f1 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 9 Mar 2024 17:54:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?CRM:=20TransferReqVO=20bizId=20->=20id?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E5=A4=8D=E5=95=86=E6=9C=BA=E8=BD=AC=E7=A7=BB?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/handler/SelectSheetWriteHandler.java | 40 ++++--------------- .../vo/business/CrmBusinessTransferReqVO.java | 3 +- .../admin/clue/vo/CrmClueTransferReqVO.java | 2 +- .../contact/vo/CrmContactTransferReqVO.java | 2 +- .../vo/contract/CrmContractTransferReqVO.java | 2 +- .../vo/customer/CrmCustomerTransferReqVO.java | 2 +- .../dal/mysql/contact/CrmContactMapper.java | 5 +-- .../core/AreaExcelColumnSelectFunction.java | 4 +- .../business/CrmBusinessServiceImpl.java | 10 ++--- .../crm/service/clue/CrmClueServiceImpl.java | 10 ++--- .../contact/CrmContactServiceImpl.java | 12 +++--- .../contract/CrmContractServiceImpl.java | 10 ++--- .../customer/CrmCustomerServiceImpl.java | 16 ++++---- 13 files changed, 42 insertions(+), 76 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java index fd66c4018..d3669f9e2 100644 --- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java @@ -60,32 +60,17 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { } // 解析下拉数据 - Map excelPropertyFields = getFieldsWithAnnotation(head, ExcelProperty.class); - Map excelColumnSelectFields = getFieldsWithAnnotation(head, ExcelColumnSelect.class); int colIndex = 0; - for (String fieldName : excelPropertyFields.keySet()) { - Field field = excelColumnSelectFields.get(fieldName); - if (field != null) { - // ExcelProperty 有一个自定义列索引的属性 index 兼容这个字段 - int index = field.getAnnotation(ExcelProperty.class).index(); - if (index != -1) { - colIndex = index; + for (Field field : head.getDeclaredFields()) { + if (field.isAnnotationPresent(ExcelColumnSelect.class)) { + ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); + if (excelProperty != null && excelProperty.index() != -1) { + colIndex = excelProperty.index(); } - buildSelectDataList(colIndex, field); + getSelectDataList(colIndex, field); } colIndex++; } - // TODO @puhui999:感觉可以 head 循环 field,如果有 ExcelColumnSelect 则进行处理;而 ExcelProperty 可能是非必须的。回答:主要是用于定位到列索引;补充:可以看看下面这样写? -// for (Field field : head.getDeclaredFields()) { -// if (field.isAnnotationPresent(ExcelColumnSelect.class)) { -// ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); -// if (excelProperty != null) { -// colIndex = excelProperty.index(); -// } -// getSelectDataList(colIndex, field); -// } -// colIndex++; -// } } /** @@ -94,7 +79,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { * @param colIndex 列索引 * @param field 字段 */ - private void buildSelectDataList(int colIndex, Field field) { + private void getSelectDataList(int colIndex, Field field) { ExcelColumnSelect columnSelect = field.getAnnotation(ExcelColumnSelect.class); String dictType = columnSelect.dictType(); String functionName = columnSelect.functionName(); @@ -174,15 +159,4 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { writeSheetHolder.getSheet().addValidationData(validation); } - public static Map getFieldsWithAnnotation(Class clazz, Class annotationClass) { - Map annotatedFields = new LinkedHashMap<>(); - Field[] fields = clazz.getDeclaredFields(); - for (Field field : fields) { - if (field.isAnnotationPresent(annotationClass)) { - annotatedFields.put(field.getName(), field); - } - } - return annotatedFields; - } - } \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java index 9fe7e2316..e26ddfa63 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java @@ -13,10 +13,9 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class CrmBusinessTransferReqVO { - // TODO @puhui999:这里最好还是用 id 哈,主要还是在 Business 业务里 @Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @NotNull(message = "商机编号不能为空") - private Long bizId; + private Long id; /** * 新负责人的用户编号 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransferReqVO.java index 7e6b8f0dd..63bdc1838 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransferReqVO.java @@ -12,7 +12,7 @@ public class CrmClueTransferReqVO { @Schema(description = "线索编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @NotNull(message = "线索编号不能为空") - private Long bizId; + private Long id; @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @NotNull(message = "新负责人的用户编号不能为空") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java index 8b5a6a6f4..0cd128cf9 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java @@ -16,7 +16,7 @@ public class CrmContactTransferReqVO { @Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @NotNull(message = "联系人编号不能为空") - private Long bizId; + private Long id; /** * 新负责人的用户编号 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java index b59e21e16..3860844f4 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java @@ -17,7 +17,7 @@ public class CrmContractTransferReqVO { @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @NotNull(message = "联系人编号不能为空") - private Long bizId; + private Long id; @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @NotNull(message = "新负责人的用户编号不能为空") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java index 38f6f1756..547ca6366 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java @@ -13,7 +13,7 @@ public class CrmCustomerTransferReqVO { @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @NotNull(message = "客户编号不能为空") - private Long bizId; + private Long id; /** * 新负责人的用户编号 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java index f94b50f49..2ab73fcaf 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java @@ -74,10 +74,7 @@ public interface CrmContactMapper extends BaseMapperX { } default List selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) { - // TODO @puhui999:父类有 selectList,查询 2 个字段的简化方法哈,可以用下 - return selectList(new LambdaQueryWrapperX() - .eq(CrmContactDO::getCustomerId, customerId) - .eq(CrmContactDO::getOwnerUserId, ownerUserId)); + return selectList(CrmContactDO::getCustomerId, customerId, CrmContactDO::getOwnerUserId, ownerUserId); } } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunction.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunction.java index b407ed470..8f0a88905 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunction.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/excel/core/AreaExcelColumnSelectFunction.java @@ -8,9 +8,7 @@ import org.springframework.stereotype.Service; import java.util.List; /** - * Excel 所属地区列下拉数据源获取接口实现类 - * - * // TODO @puhui999:类名叫:地区下拉框数据源的 {@link ExcelColumnSelectFunction} 实现类,这样看起来会更简洁一点哈 + * 地区下拉框数据源的 {@link ExcelColumnSelectFunction} 实现类 * * @author HUIHUI */ diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java index 5ec0a4b41..26f02b2f0 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java @@ -292,18 +292,18 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { @Override @Transactional(rollbackFor = Exception.class) - @LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}", + @LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_BUSINESS_TRANSFER_SUCCESS) - @CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER) public void transferBusiness(CrmBusinessTransferReqVO reqVO, Long userId) { // 1 校验商机是否存在 - CrmBusinessDO business = validateBusinessExists(reqVO.getBizId()); + CrmBusinessDO business = validateBusinessExists(reqVO.getId()); // 2.1 数据权限转移 permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_BUSINESS.getType(), - reqVO.getBizId(), reqVO.getNewOwnerUserId(), CrmPermissionLevelEnum.OWNER.getLevel())); + reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); // 2.2 设置新的负责人 - businessMapper.updateOwnerUserIdById(reqVO.getBizId(), reqVO.getNewOwnerUserId()); + businessMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId()); // 记录操作日志上下文 LogRecordContext.putVariable("business", business); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java index 3b4f0bc34..70ebeb44d 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java @@ -159,18 +159,18 @@ public class CrmClueServiceImpl implements CrmClueService { @Override @Transactional(rollbackFor = Exception.class) - @LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}", + @LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_CLUE_TRANSFER_SUCCESS) - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER) public void transferClue(CrmClueTransferReqVO reqVO, Long userId) { // 1 校验线索是否存在 - CrmClueDO clue = validateClueExists(reqVO.getBizId()); + CrmClueDO clue = validateClueExists(reqVO.getId()); // 2.1 数据权限转移 crmPermissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CLUE.getType(), - reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); + reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); // 2.2 设置新的负责人 - clueMapper.updateById(new CrmClueDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId())); + clueMapper.updateById(new CrmClueDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId())); // 3. 记录转移日志 LogRecordContext.putVariable("clue", clue); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java index ea46edf11..174db9b3a 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.crm.service.contact; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; -import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO; @@ -18,7 +17,6 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPerm import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; -import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerServiceImpl; import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; @@ -179,18 +177,18 @@ public class CrmContactServiceImpl implements CrmContactService { @Override @Transactional(rollbackFor = Exception.class) - @LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}", + @LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_CONTACT_TRANSFER_SUCCESS) - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER) public void transferContact(CrmContactTransferReqVO reqVO, Long userId) { // 1 校验联系人是否存在 - CrmContactDO contact = validateContactExists(reqVO.getBizId()); + CrmContactDO contact = validateContactExists(reqVO.getId()); // 2.1 数据权限转移 permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CONTACT.getType(), - reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); + reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); // 2.2 设置新的负责人 - contactMapper.updateById(new CrmContactDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId())); + contactMapper.updateById(new CrmContactDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId())); // 3. 记录转移日志 LogRecordContext.putVariable("contact", contact); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java index beb3ef1a8..52b6643d7 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java @@ -252,18 +252,18 @@ public class CrmContractServiceImpl implements CrmContractService { @Override @Transactional(rollbackFor = Exception.class) - @LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}", + @LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_CONTRACT_TRANSFER_SUCCESS) - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER) public void transferContract(CrmContractTransferReqVO reqVO, Long userId) { // 1. 校验合同是否存在 - CrmContractDO contract = validateContractExists(reqVO.getBizId()); + CrmContractDO contract = validateContractExists(reqVO.getId()); // 2.1 数据权限转移 crmPermissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CONTRACT.getType(), - reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); + reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); // 2.2 设置负责人 - contractMapper.updateById(new CrmContractDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId())); + contractMapper.updateById(new CrmContractDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId())); // 3. 记录转移日志 LogRecordContext.putVariable("contract", contract); 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 d314b823c..cdb7a32d9 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 @@ -199,19 +199,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @Override @Transactional(rollbackFor = Exception.class) - @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}", + @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_CUSTOMER_TRANSFER_SUCCESS) - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER) public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) { // 1.1 校验客户是否存在 - CrmCustomerDO customer = validateCustomerExists(reqVO.getBizId()); + CrmCustomerDO customer = validateCustomerExists(reqVO.getId()); // 1.2 校验拥有客户是否到达上限 validateCustomerExceedOwnerLimit(reqVO.getNewOwnerUserId(), 1); // 2.1 数据权限转移 permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CUSTOMER.getType(), - reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); + reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel())); // 2.2 转移后重新设置负责人 - customerMapper.updateById(new CrmCustomerDO().setId(reqVO.getBizId()) + customerMapper.updateById(new CrmCustomerDO().setId(reqVO.getId()) .setOwnerUserId(reqVO.getNewOwnerUserId()).setOwnerTime(LocalDateTime.now())); // 2.3 同时转移 @@ -231,21 +231,21 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { */ private void transfer(CrmCustomerTransferReqVO reqVO, Long userId) { if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTACT.getType())) { - List contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + List contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getId(), userId); contactList.forEach(item -> { contactService.transferContact(new CrmContactTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()), userId); }); } if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_BUSINESS.getType())) { - List businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + List businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getId(), userId); businessList.forEach(item -> { businessService.transferBusiness(new CrmBusinessTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()), userId); }); } if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTRACT.getType())) { - List contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getBizId(), userId); + List contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getId(), userId); contractList.forEach(item -> { contractService.transferContract(new CrmContractTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()), userId);