Commit e6eaa3a24af92e5a96d2b3169c7896d3b2cdda3c
1 parent
19c9b6ae
完善 CRM-数据权限校验方式
Showing
40 changed files
with
399 additions
and
392 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
| @@ -11,17 +11,12 @@ public interface ErrorCodeConstants { | @@ -11,17 +11,12 @@ public interface ErrorCodeConstants { | ||
| 11 | 11 | ||
| 12 | // ========== 合同管理 1-020-000-000 ========== | 12 | // ========== 合同管理 1-020-000-000 ========== |
| 13 | ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在"); | 13 | ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在"); |
| 14 | - ErrorCode CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_000_001, "合同转移失败,原因:没有转移权限"); // TODO @puhui999:这个搞成 “合同操作失败,原因:没有权限” | ||
| 15 | - ErrorCode CONTRACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_000_002, "合同转移失败,原因:负责人不存在"); | ||
| 16 | 14 | ||
| 17 | // ========== 线索管理 1-020-001-000 ========== | 15 | // ========== 线索管理 1-020-001-000 ========== |
| 18 | ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); | 16 | ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); |
| 19 | 17 | ||
| 20 | // ========== 商机管理 1-020-002-000 ========== | 18 | // ========== 商机管理 1-020-002-000 ========== |
| 21 | ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); | 19 | ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); |
| 22 | - ErrorCode BUSINESS_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_002_001, "商机操作失败,原因:没有权限"); | ||
| 23 | - ErrorCode BUSINESS_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_002_002, "商机操作失败,原因:负责人不存在"); | ||
| 24 | - ErrorCode BUSINESS_TRANSFER_FAIL_OWNER_USER_EXISTS = new ErrorCode(1_020_002_003, "商机操作失败,原因:转移对象已经是该负责人"); | ||
| 25 | 20 | ||
| 26 | // TODO @lilleo:商机状态、商机类型,都单独错误码段 | 21 | // TODO @lilleo:商机状态、商机类型,都单独错误码段 |
| 27 | 22 | ||
| @@ -30,8 +25,6 @@ public interface ErrorCodeConstants { | @@ -30,8 +25,6 @@ public interface ErrorCodeConstants { | ||
| 30 | 25 | ||
| 31 | // ========== 联系人管理 1-020-003-000 ========== | 26 | // ========== 联系人管理 1-020-003-000 ========== |
| 32 | ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在"); | 27 | ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在"); |
| 33 | - ErrorCode CONTACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_003_001, "联系人转移失败,原因:没有转移权限"); // TODO @puhui999:这个搞成 “联系人操作失败,原因:没有权限” | ||
| 34 | - ErrorCode CONTACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_003_002, "联系人转移失败,原因:负责人不存在"); | ||
| 35 | 28 | ||
| 36 | // TODO @liuhongfeng:错误码分段; | 29 | // TODO @liuhongfeng:错误码分段; |
| 37 | ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_030_000_001, "回款管理不存在"); | 30 | ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_030_000_001, "回款管理不存在"); |
| @@ -43,5 +36,9 @@ public interface ErrorCodeConstants { | @@ -43,5 +36,9 @@ public interface ErrorCodeConstants { | ||
| 43 | 36 | ||
| 44 | // ========== 客户管理 1_020_007_000 ========== | 37 | // ========== 客户管理 1_020_007_000 ========== |
| 45 | ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在"); | 38 | ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在"); |
| 39 | + ErrorCode CRM_PERMISSION_DENIED = new ErrorCode(1_020_007_001, "{}操作失败,原因:没有权限"); | ||
| 40 | + ErrorCode CRM_PERMISSION_MODEL_NOT_EXISTS = new ErrorCode(1_020_007_002, "{}不存在"); | ||
| 41 | + ErrorCode CRM_PERMISSION_MODEL_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_007_003, "{}操作失败,原因:负责人不存在"); | ||
| 42 | + ErrorCode CRM_PERMISSION_MODEL_TRANSFER_FAIL_OWNER_USER_EXISTS = new ErrorCode(1_020_007_004, "{}操作失败,原因:转移对象已经是该负责人"); | ||
| 46 | 43 | ||
| 47 | } | 44 | } |
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/PermissionTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.enums.common; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Getter; | ||
| 6 | + | ||
| 7 | +import java.util.Arrays; | ||
| 8 | + | ||
| 9 | +@Getter | ||
| 10 | +@AllArgsConstructor | ||
| 11 | +public enum PermissionTypeEnum implements IntArrayValuable { | ||
| 12 | + | ||
| 13 | + READONLY(1, "只读"), | ||
| 14 | + READ_AND_WRITE(2, "读写"); | ||
| 15 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PermissionTypeEnum::getType).toArray(); | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 类型 | ||
| 19 | + */ | ||
| 20 | + private final Integer type; | ||
| 21 | + /** | ||
| 22 | + * 类型名 | ||
| 23 | + */ | ||
| 24 | + private final String name; | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public int[] array() { | ||
| 28 | + return ARRAYS; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | +} |
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/TransferTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.enums.common; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Getter; | ||
| 6 | + | ||
| 7 | +import java.util.Arrays; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Crm 负责人转移后原负责人的处理方式 | ||
| 11 | + * | ||
| 12 | + * @author HUIHUI | ||
| 13 | + */ | ||
| 14 | +@Getter | ||
| 15 | +@AllArgsConstructor | ||
| 16 | +public enum TransferTypeEnum implements IntArrayValuable { | ||
| 17 | + | ||
| 18 | + REMOVE(1, "移除"), | ||
| 19 | + TEAM(2, "转为团队成员"); | ||
| 20 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TransferTypeEnum::getType).toArray(); | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 类型 | ||
| 24 | + */ | ||
| 25 | + private final Integer type; | ||
| 26 | + /** | ||
| 27 | + * 类型名 | ||
| 28 | + */ | ||
| 29 | + private final String name; | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public int[] array() { | ||
| 33 | + return ARRAYS; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
| 1 | package cn.iocoder.yudao.module.crm.controller.admin.business; | 1 | package cn.iocoder.yudao.module.crm.controller.admin.business; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| @@ -8,7 +7,6 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | @@ -8,7 +7,6 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 8 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*; | 7 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*; |
| 9 | import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; | 8 | import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; |
| 10 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | 9 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; |
| 11 | -import cn.iocoder.yudao.module.crm.framework.utils.CrmPermissionUtils; | ||
| 12 | import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; | 10 | import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; |
| 13 | import io.swagger.v3.oas.annotations.Operation; | 11 | import io.swagger.v3.oas.annotations.Operation; |
| 14 | import io.swagger.v3.oas.annotations.Parameter; | 12 | import io.swagger.v3.oas.annotations.Parameter; |
| @@ -40,7 +38,7 @@ public class CrmBusinessController { | @@ -40,7 +38,7 @@ public class CrmBusinessController { | ||
| 40 | @Operation(summary = "创建商机") | 38 | @Operation(summary = "创建商机") |
| 41 | @PreAuthorize("@ss.hasPermission('crm:business:create')") | 39 | @PreAuthorize("@ss.hasPermission('crm:business:create')") |
| 42 | public CommonResult<Long> createBusiness(@Valid @RequestBody CrmBusinessCreateReqVO createReqVO) { | 40 | public CommonResult<Long> createBusiness(@Valid @RequestBody CrmBusinessCreateReqVO createReqVO) { |
| 43 | - return success(businessService.createBusiness(createReqVO)); | 41 | + return success(businessService.createBusiness(createReqVO, getLoginUserId())); |
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | @PutMapping("/update") | 44 | @PutMapping("/update") |
| @@ -65,7 +63,6 @@ public class CrmBusinessController { | @@ -65,7 +63,6 @@ public class CrmBusinessController { | ||
| 65 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 63 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 66 | @PreAuthorize("@ss.hasPermission('crm:business:query')") | 64 | @PreAuthorize("@ss.hasPermission('crm:business:query')") |
| 67 | public CommonResult<CrmBusinessRespVO> getBusiness(@RequestParam("id") Long id) { | 65 | public CommonResult<CrmBusinessRespVO> getBusiness(@RequestParam("id") Long id) { |
| 68 | - CrmPermissionUtils.setCrmTransferInfo(getLoginUserId(), UserTypeEnum.ADMIN.getValue()); | ||
| 69 | CrmBusinessDO business = businessService.getBusiness(id); | 66 | CrmBusinessDO business = businessService.getBusiness(id); |
| 70 | return success(CrmBusinessConvert.INSTANCE.convert(business)); | 67 | return success(CrmBusinessConvert.INSTANCE.convert(business)); |
| 71 | } | 68 | } |
| @@ -95,7 +92,6 @@ public class CrmBusinessController { | @@ -95,7 +92,6 @@ public class CrmBusinessController { | ||
| 95 | @Operation(summary = "商机转移") | 92 | @Operation(summary = "商机转移") |
| 96 | @PreAuthorize("@ss.hasPermission('crm:business:update')") | 93 | @PreAuthorize("@ss.hasPermission('crm:business:update')") |
| 97 | public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferBusinessReqVO reqVO) { | 94 | public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferBusinessReqVO reqVO) { |
| 98 | - CrmPermissionUtils.setCrmTransferInfo(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO); | ||
| 99 | businessService.businessTransfer(reqVO, getLoginUserId()); | 95 | businessService.businessTransfer(reqVO, getLoginUserId()); |
| 100 | return success(true); | 96 | return success(true); |
| 101 | } | 97 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/CrmTransferBusinessReqVO.java
| 1 | package cn.iocoder.yudao.module.crm.controller.admin.business.vo; | 1 | package cn.iocoder.yudao.module.crm.controller.admin.business.vo; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.crm.framework.vo.CrmTransferBaseVO; | 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | +import cn.iocoder.yudao.module.crm.enums.common.PermissionTypeEnum; | ||
| 5 | +import cn.iocoder.yudao.module.crm.enums.common.TransferTypeEnum; | ||
| 4 | import io.swagger.v3.oas.annotations.media.Schema; | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | 8 | ||
| 9 | +import javax.validation.constraints.NotNull; | ||
| 10 | + | ||
| 7 | @Schema(description = "管理后台 - 商机转移 Request VO") | 11 | @Schema(description = "管理后台 - 商机转移 Request VO") |
| 8 | @Data | 12 | @Data |
| 9 | -public class CrmTransferBusinessReqVO extends CrmTransferBaseVO { | 13 | +public class CrmTransferBusinessReqVO { |
| 14 | + | ||
| 15 | + @Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 16 | + @NotNull(message = "联系人编号不能为空") | ||
| 17 | + private Long id; | ||
| 18 | + | ||
| 19 | + @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 20 | + @NotNull(message = "新负责人的用户编号不能为空") | ||
| 21 | + private Long ownerUserId; | ||
| 22 | + | ||
| 23 | + @Schema(description = "原负责人移除方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 24 | + @InEnum(TransferTypeEnum.class) | ||
| 25 | + @NotNull(message = "原负责人移除方式不能为空") | ||
| 26 | + private Integer transferType; | ||
| 27 | + | ||
| 28 | + @Schema(description = "权限类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 29 | + @InEnum(PermissionTypeEnum.class) | ||
| 30 | + @NotNull(message = "权限类型不能为空") | ||
| 31 | + private Integer permissionType; | ||
| 32 | + | ||
| 10 | 33 | ||
| 11 | } | 34 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueBaseVO.java
| @@ -42,10 +42,6 @@ public class CrmClueBaseVO { | @@ -42,10 +42,6 @@ public class CrmClueBaseVO { | ||
| 42 | @Schema(description = "地址", example = "北京市海淀区") | 42 | @Schema(description = "地址", example = "北京市海淀区") |
| 43 | private String address; | 43 | private String address; |
| 44 | 44 | ||
| 45 | - @Schema(description = "负责人的用户编号", example = "27199") | ||
| 46 | - @NotNull(message = "负责人不能为空") | ||
| 47 | - private Long ownerUserId; | ||
| 48 | - | ||
| 49 | @Schema(description = "最后跟进时间") | 45 | @Schema(description = "最后跟进时间") |
| 50 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | 46 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 51 | private LocalDateTime contactLastTime; | 47 | private LocalDateTime contactLastTime; |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java
| @@ -39,7 +39,7 @@ public class ContactController { | @@ -39,7 +39,7 @@ public class ContactController { | ||
| 39 | @Operation(summary = "创建crm联系人") | 39 | @Operation(summary = "创建crm联系人") |
| 40 | @PreAuthorize("@ss.hasPermission('crm:contact:create')") | 40 | @PreAuthorize("@ss.hasPermission('crm:contact:create')") |
| 41 | public CommonResult<Long> createContact(@Valid @RequestBody ContactCreateReqVO createReqVO) { | 41 | public CommonResult<Long> createContact(@Valid @RequestBody ContactCreateReqVO createReqVO) { |
| 42 | - return success(contactService.createContact(createReqVO)); | 42 | + return success(contactService.createContact(createReqVO, getLoginUserId())); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | @PutMapping("/update") | 45 | @PutMapping("/update") |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactCreateReqVO.java
| @@ -5,18 +5,10 @@ import lombok.Data; | @@ -5,18 +5,10 @@ import lombok.Data; | ||
| 5 | import lombok.EqualsAndHashCode; | 5 | import lombok.EqualsAndHashCode; |
| 6 | import lombok.ToString; | 6 | import lombok.ToString; |
| 7 | 7 | ||
| 8 | -import java.util.Set; | ||
| 9 | - | ||
| 10 | @Schema(description = "管理后台 - crm联系人创建 Request VO") | 8 | @Schema(description = "管理后台 - crm联系人创建 Request VO") |
| 11 | @Data | 9 | @Data |
| 12 | @EqualsAndHashCode(callSuper = true) | 10 | @EqualsAndHashCode(callSuper = true) |
| 13 | @ToString(callSuper = true) | 11 | @ToString(callSuper = true) |
| 14 | public class ContactCreateReqVO extends ContactBaseVO { | 12 | public class ContactCreateReqVO extends ContactBaseVO { |
| 15 | 13 | ||
| 16 | - @Schema(description = "只读权限的用户编号数组") | ||
| 17 | - private Set<Long> roUserIds; | ||
| 18 | - | ||
| 19 | - @Schema(description = "读写权限的用户编号数组") | ||
| 20 | - private Set<Long> rwUserIds; | ||
| 21 | - | ||
| 22 | } | 14 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java
| @@ -17,4 +17,12 @@ public class CrmContactTransferReqVO { | @@ -17,4 +17,12 @@ public class CrmContactTransferReqVO { | ||
| 17 | @NotNull(message = "新负责人的用户编号不能为空") | 17 | @NotNull(message = "新负责人的用户编号不能为空") |
| 18 | private Long ownerUserId; | 18 | private Long ownerUserId; |
| 19 | 19 | ||
| 20 | + @Schema(description = "原负责人移除方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 21 | + @NotNull(message = "原负责人移除方式不能为空") | ||
| 22 | + private Integer transferType; | ||
| 23 | + | ||
| 24 | + @Schema(description = "权限类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 25 | + @NotNull(message = "权限类型不能为空") | ||
| 26 | + private Integer permissionType; | ||
| 27 | + | ||
| 20 | } | 28 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/ContractController.java
| @@ -38,7 +38,7 @@ public class ContractController { | @@ -38,7 +38,7 @@ public class ContractController { | ||
| 38 | @Operation(summary = "创建合同") | 38 | @Operation(summary = "创建合同") |
| 39 | @PreAuthorize("@ss.hasPermission('crm:contract:create')") | 39 | @PreAuthorize("@ss.hasPermission('crm:contract:create')") |
| 40 | public CommonResult<Long> createContract(@Valid @RequestBody ContractCreateReqVO createReqVO) { | 40 | public CommonResult<Long> createContract(@Valid @RequestBody ContractCreateReqVO createReqVO) { |
| 41 | - return success(contractService.createContract(createReqVO)); | 41 | + return success(contractService.createContract(createReqVO, getLoginUserId())); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | @PutMapping("/update") | 44 | @PutMapping("/update") |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/business/CrmBusinessConvert.java
| @@ -3,11 +3,13 @@ package cn.iocoder.yudao.module.crm.convert.business; | @@ -3,11 +3,13 @@ package cn.iocoder.yudao.module.crm.convert.business; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*; | 4 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*; |
| 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; |
| 6 | +import cn.iocoder.yudao.module.crm.service.permission.bo.TransferCrmPermissionBO; | ||
| 6 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 8 | +import org.mapstruct.Mapping; | ||
| 9 | +import org.mapstruct.Mappings; | ||
| 7 | import org.mapstruct.factory.Mappers; | 10 | import org.mapstruct.factory.Mappers; |
| 8 | 11 | ||
| 9 | import java.util.List; | 12 | import java.util.List; |
| 10 | -import java.util.Set; | ||
| 11 | 13 | ||
| 12 | /** | 14 | /** |
| 13 | * 商机 Convert | 15 | * 商机 Convert |
| @@ -29,13 +31,10 @@ public interface CrmBusinessConvert { | @@ -29,13 +31,10 @@ public interface CrmBusinessConvert { | ||
| 29 | 31 | ||
| 30 | List<CrmBusinessExcelVO> convertList02(List<CrmBusinessDO> list); | 32 | List<CrmBusinessExcelVO> convertList02(List<CrmBusinessDO> list); |
| 31 | 33 | ||
| 32 | - default CrmBusinessDO convert(CrmBusinessDO business, CrmTransferBusinessReqVO reqVO, Long userId) { | ||
| 33 | - Set<Long> rwUserIds = business.getRwUserIds(); | ||
| 34 | - rwUserIds.remove(userId); | ||
| 35 | - rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负责人 | ||
| 36 | - // TODO @puhui999:对原负责人,加个类似的处理:移除、转化为团队成员(只读、读写) | ||
| 37 | - return new CrmBusinessDO().setId(business.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人 | ||
| 38 | - .setRwUserIds(rwUserIds); | ||
| 39 | - } | 34 | + @Mappings({ |
| 35 | + @Mapping(target = "userId", source = "userId"), | ||
| 36 | + @Mapping(target = "crmDataId", source = "reqVO.id") | ||
| 37 | + }) | ||
| 38 | + TransferCrmPermissionBO convert(CrmTransferBusinessReqVO reqVO, Long userId); | ||
| 40 | 39 | ||
| 41 | } | 40 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java
| 1 | package cn.iocoder.yudao.module.crm.convert.contact; | 1 | package cn.iocoder.yudao.module.crm.convert.contact; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ObjUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; | 4 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; |
| 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; |
| 6 | +import cn.iocoder.yudao.module.crm.service.permission.bo.TransferCrmPermissionBO; | ||
| 7 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 8 | +import org.mapstruct.Mapping; | ||
| 9 | +import org.mapstruct.Mappings; | ||
| 8 | import org.mapstruct.factory.Mappers; | 10 | import org.mapstruct.factory.Mappers; |
| 9 | 11 | ||
| 10 | import java.util.List; | 12 | import java.util.List; |
| 11 | -import java.util.Set; | ||
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| 14 | * crm联系人 Convert | 15 | * crm联系人 Convert |
| @@ -32,13 +33,10 @@ public interface ContactConvert { | @@ -32,13 +33,10 @@ public interface ContactConvert { | ||
| 32 | 33 | ||
| 33 | List<ContactExcelVO> convertList02(List<ContactDO> list); | 34 | List<ContactExcelVO> convertList02(List<ContactDO> list); |
| 34 | 35 | ||
| 35 | - // TODO @puhui999:参考 CrmBusinessConvert 的修改建议 | ||
| 36 | - default ContactDO convert(ContactDO contact, CrmContactTransferReqVO reqVO, Long userId) { | ||
| 37 | - Set<Long> rwUserIds = contact.getRwUserIds(); | ||
| 38 | - rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人 | ||
| 39 | - rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人 | ||
| 40 | - return new ContactDO().setId(contact.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人 | ||
| 41 | - .setRwUserIds(rwUserIds); | ||
| 42 | - } | 36 | + @Mappings({ |
| 37 | + @Mapping(target = "userId", source = "userId"), | ||
| 38 | + @Mapping(target = "crmDataId", source = "reqVO.id") | ||
| 39 | + }) | ||
| 40 | + TransferCrmPermissionBO convert(CrmContactTransferReqVO reqVO, Long userId); | ||
| 43 | 41 | ||
| 44 | } | 42 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contract/ContractConvert.java
| 1 | package cn.iocoder.yudao.module.crm.convert.contract; | 1 | package cn.iocoder.yudao.module.crm.convert.contract; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ObjUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*; | 4 | import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*; |
| 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO; |
| 6 | +import cn.iocoder.yudao.module.crm.service.permission.bo.TransferCrmPermissionBO; | ||
| 7 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 8 | +import org.mapstruct.Mapping; | ||
| 9 | +import org.mapstruct.Mappings; | ||
| 8 | import org.mapstruct.factory.Mappers; | 10 | import org.mapstruct.factory.Mappers; |
| 9 | 11 | ||
| 10 | import java.util.List; | 12 | import java.util.List; |
| 11 | -import java.util.Set; | ||
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| 14 | * 合同 Convert | 15 | * 合同 Convert |
| @@ -32,13 +33,10 @@ public interface ContractConvert { | @@ -32,13 +33,10 @@ public interface ContractConvert { | ||
| 32 | 33 | ||
| 33 | List<ContractExcelVO> convertList02(List<ContractDO> list); | 34 | List<ContractExcelVO> convertList02(List<ContractDO> list); |
| 34 | 35 | ||
| 35 | - // TODO @puhui999:参考 CrmBusinessConvert 的修改建议 | ||
| 36 | - default ContractDO convert(ContractDO contract, CrmContractTransferReqVO reqVO, Long userId) { | ||
| 37 | - Set<Long> rwUserIds = contract.getRwUserIds(); | ||
| 38 | - rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人 | ||
| 39 | - rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人 | ||
| 40 | - return (ContractDO) new ContractDO().setId(contract.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人 | ||
| 41 | - .setRwUserIds(rwUserIds); | ||
| 42 | - } | 36 | + @Mappings({ |
| 37 | + @Mapping(target = "userId", source = "userId"), | ||
| 38 | + @Mapping(target = "crmDataId", source = "reqVO.id") | ||
| 39 | + }) | ||
| 40 | + TransferCrmPermissionBO convert(CrmContractTransferReqVO reqVO, Long userId); | ||
| 43 | 41 | ||
| 44 | } | 42 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/business/CrmBusinessDO.java
| 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.business; | 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.business; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 3 | import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatus.CrmBusinessStatusDO; | 4 | import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatus.CrmBusinessStatusDO; |
| 4 | import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatustype.CrmBusinessStatusTypeDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatustype.CrmBusinessStatusTypeDO; |
| 5 | -import cn.iocoder.yudao.module.crm.framework.dataobject.CrmPermissionBaseDO; | ||
| 6 | import com.baomidou.mybatisplus.annotation.KeySequence; | 6 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 7 | import com.baomidou.mybatisplus.annotation.TableId; | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| 8 | import com.baomidou.mybatisplus.annotation.TableName; | 8 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -23,7 +23,7 @@ import java.time.LocalDateTime; | @@ -23,7 +23,7 @@ import java.time.LocalDateTime; | ||
| 23 | @Builder | 23 | @Builder |
| 24 | @NoArgsConstructor | 24 | @NoArgsConstructor |
| 25 | @AllArgsConstructor | 25 | @AllArgsConstructor |
| 26 | -public class CrmBusinessDO extends CrmPermissionBaseDO { | 26 | +public class CrmBusinessDO extends BaseDO { |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | * 主键 | 29 | * 主键 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/clue/CrmClueDO.java
| @@ -65,12 +65,6 @@ public class CrmClueDO extends BaseDO { | @@ -65,12 +65,6 @@ public class CrmClueDO extends BaseDO { | ||
| 65 | */ | 65 | */ |
| 66 | private String address; | 66 | private String address; |
| 67 | /** | 67 | /** |
| 68 | - * 负责人的用户编号 | ||
| 69 | - * | ||
| 70 | - * 关联 AdminUserDO 的 id 字段 | ||
| 71 | - */ | ||
| 72 | - private Long ownerUserId; | ||
| 73 | - /** | ||
| 74 | * 最后跟进时间 TODO 添加跟进记录时更新该值 | 68 | * 最后跟进时间 TODO 添加跟进记录时更新该值 |
| 75 | */ | 69 | */ |
| 76 | private LocalDateTime contactLastTime; | 70 | private LocalDateTime contactLastTime; |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/ContactDO.java
| 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.contact; | 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.contact; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.crm.framework.dataobject.CrmPermissionBaseDO; | 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.KeySequence; | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -21,7 +21,7 @@ import java.time.LocalDateTime; | @@ -21,7 +21,7 @@ import java.time.LocalDateTime; | ||
| 21 | @Builder | 21 | @Builder |
| 22 | @NoArgsConstructor | 22 | @NoArgsConstructor |
| 23 | @AllArgsConstructor | 23 | @AllArgsConstructor |
| 24 | -public class ContactDO extends CrmPermissionBaseDO { | 24 | +public class ContactDO extends BaseDO { |
| 25 | 25 | ||
| 26 | /** | 26 | /** |
| 27 | * 主键 | 27 | * 主键 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contract/ContractDO.java
| 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.contract; | 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.contract; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.crm.framework.dataobject.CrmPermissionBaseDO; | 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.KeySequence; | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -21,7 +21,7 @@ import java.time.LocalDateTime; | @@ -21,7 +21,7 @@ import java.time.LocalDateTime; | ||
| 21 | @Builder | 21 | @Builder |
| 22 | @NoArgsConstructor | 22 | @NoArgsConstructor |
| 23 | @AllArgsConstructor | 23 | @AllArgsConstructor |
| 24 | -public class ContractDO extends CrmPermissionBaseDO { | 24 | +public class ContractDO extends BaseDO { |
| 25 | 25 | ||
| 26 | /** | 26 | /** |
| 27 | * 合同编号 | 27 | * 合同编号 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/customer/CrmCustomerDO.java
| 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.customer; | 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.customer; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.crm.framework.dataobject.CrmPermissionBaseDO; | 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.KeySequence; | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -23,7 +23,7 @@ import java.time.LocalDateTime; | @@ -23,7 +23,7 @@ import java.time.LocalDateTime; | ||
| 23 | @Builder | 23 | @Builder |
| 24 | @NoArgsConstructor | 24 | @NoArgsConstructor |
| 25 | @AllArgsConstructor | 25 | @AllArgsConstructor |
| 26 | -public class CrmCustomerDO extends CrmPermissionBaseDO { | 26 | +public class CrmCustomerDO extends BaseDO { |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | * 编号 | 29 | * 编号 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/permission/CrmPermissionDO.java
| @@ -36,9 +36,9 @@ public class CrmPermissionDO extends BaseDO { | @@ -36,9 +36,9 @@ public class CrmPermissionDO extends BaseDO { | ||
| 36 | */ | 36 | */ |
| 37 | private Integer crmType; | 37 | private Integer crmType; |
| 38 | /** | 38 | /** |
| 39 | - * 数据编号 关联 {@link CrmEnum} 对应模块 DO#id | 39 | + * 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() |
| 40 | */ | 40 | */ |
| 41 | - private Integer crmDataId; | 41 | + private Long crmDataId; |
| 42 | /** | 42 | /** |
| 43 | * 负责人的用户编号 关联 AdminUser#id | 43 | * 负责人的用户编号 关联 AdminUser#id |
| 44 | */ | 44 | */ |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java
| @@ -36,10 +36,7 @@ public interface CrmBusinessMapper extends BaseMapperX<CrmBusinessDO> { | @@ -36,10 +36,7 @@ public interface CrmBusinessMapper extends BaseMapperX<CrmBusinessDO> { | ||
| 36 | .eqIfPresent(CrmBusinessDO::getDiscountPercent, reqVO.getDiscountPercent()) | 36 | .eqIfPresent(CrmBusinessDO::getDiscountPercent, reqVO.getDiscountPercent()) |
| 37 | .eqIfPresent(CrmBusinessDO::getProductPrice, reqVO.getProductPrice()) | 37 | .eqIfPresent(CrmBusinessDO::getProductPrice, reqVO.getProductPrice()) |
| 38 | .eqIfPresent(CrmBusinessDO::getRemark, reqVO.getRemark()) | 38 | .eqIfPresent(CrmBusinessDO::getRemark, reqVO.getRemark()) |
| 39 | - .eqIfPresent(CrmBusinessDO::getOwnerUserId, reqVO.getOwnerUserId()) | ||
| 40 | .betweenIfPresent(CrmBusinessDO::getCreateTime, reqVO.getCreateTime()) | 39 | .betweenIfPresent(CrmBusinessDO::getCreateTime, reqVO.getCreateTime()) |
| 41 | - .eqIfPresent(CrmBusinessDO::getRoUserIds, reqVO.getRoUserIds()) | ||
| 42 | - .eqIfPresent(CrmBusinessDO::getRwUserIds, reqVO.getRwUserIds()) | ||
| 43 | .eqIfPresent(CrmBusinessDO::getEndStatus, reqVO.getEndStatus()) | 40 | .eqIfPresent(CrmBusinessDO::getEndStatus, reqVO.getEndStatus()) |
| 44 | .eqIfPresent(CrmBusinessDO::getEndRemark, reqVO.getEndRemark()) | 41 | .eqIfPresent(CrmBusinessDO::getEndRemark, reqVO.getEndRemark()) |
| 45 | .betweenIfPresent(CrmBusinessDO::getContactLastTime, reqVO.getContactLastTime()) | 42 | .betweenIfPresent(CrmBusinessDO::getContactLastTime, reqVO.getContactLastTime()) |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java
| 1 | package cn.iocoder.yudao.module.crm.dal.mysql.permission; | 1 | package cn.iocoder.yudao.module.crm.dal.mysql.permission; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 4 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; |
| 5 | import org.apache.ibatis.annotations.Mapper; | 6 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 7 | ||
| @@ -11,4 +12,10 @@ import org.apache.ibatis.annotations.Mapper; | @@ -11,4 +12,10 @@ import org.apache.ibatis.annotations.Mapper; | ||
| 11 | */ | 12 | */ |
| 12 | @Mapper | 13 | @Mapper |
| 13 | public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> { | 14 | public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> { |
| 15 | + | ||
| 16 | + default CrmPermissionDO selectByCrmTypeAndCrmDataId(Integer crmType, Long crmDataId) { | ||
| 17 | + return selectOne(new LambdaQueryWrapperX<CrmPermissionDO>() | ||
| 18 | + .eq(CrmPermissionDO::getCrmType, crmType).eq(CrmPermissionDO::getCrmDataId, crmDataId)); | ||
| 19 | + } | ||
| 20 | + | ||
| 14 | } | 21 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/core/aop/CrmPermissionAspect.java
| @@ -2,19 +2,11 @@ package cn.iocoder.yudao.module.crm.framework.core.aop; | @@ -2,19 +2,11 @@ package cn.iocoder.yudao.module.crm.framework.core.aop; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 5 | -import cn.iocoder.yudao.framework.common.core.KeyValue; | ||
| 6 | -import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | ||
| 7 | -import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; | ||
| 8 | -import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO; | ||
| 9 | -import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 5 | +import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; |
| 6 | +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | ||
| 10 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; | 7 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 11 | -import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | ||
| 12 | import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum; | 8 | import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum; |
| 13 | -import cn.iocoder.yudao.module.crm.framework.vo.CrmTransferBaseVO; | ||
| 14 | -import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; | ||
| 15 | -import cn.iocoder.yudao.module.crm.service.contact.ContactService; | ||
| 16 | -import cn.iocoder.yudao.module.crm.service.contract.ContractService; | ||
| 17 | -import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | 9 | +import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 18 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; |
| 19 | import org.aspectj.lang.JoinPoint; | 11 | import org.aspectj.lang.JoinPoint; |
| 20 | import org.aspectj.lang.annotation.Aspect; | 12 | import org.aspectj.lang.annotation.Aspect; |
| @@ -22,11 +14,11 @@ import org.aspectj.lang.annotation.Before; | @@ -22,11 +14,11 @@ import org.aspectj.lang.annotation.Before; | ||
| 22 | import org.springframework.stereotype.Component; | 14 | import org.springframework.stereotype.Component; |
| 23 | 15 | ||
| 24 | import javax.annotation.Resource; | 16 | import javax.annotation.Resource; |
| 25 | -import java.util.Collection; | ||
| 26 | 17 | ||
| 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 18 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 28 | import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; | 19 | import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; |
| 29 | -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | 20 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_DENIED; |
| 21 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_MODEL_NOT_EXISTS; | ||
| 30 | 22 | ||
| 31 | /** | 23 | /** |
| 32 | * Crm 数据权限校验 AOP 切面 | 24 | * Crm 数据权限校验 AOP 切面 |
| @@ -38,48 +30,16 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | @@ -38,48 +30,16 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | ||
| 38 | @Slf4j | 30 | @Slf4j |
| 39 | public class CrmPermissionAspect { | 31 | public class CrmPermissionAspect { |
| 40 | 32 | ||
| 41 | - /** | ||
| 42 | - * 用户编号 | ||
| 43 | - */ | ||
| 44 | - private static final ThreadLocal<Long> USER_ID = new ThreadLocal<>(); | ||
| 45 | - /** | ||
| 46 | - * 用户类型 | ||
| 47 | - */ | ||
| 48 | - private static final ThreadLocal<Integer> USER_TYPE = new ThreadLocal<>(); | ||
| 49 | - /** | ||
| 50 | - * 操作数据编号 | ||
| 51 | - */ | ||
| 52 | - private static final ThreadLocal<Long> DATA_ID = new ThreadLocal<>(); | ||
| 53 | - /** | ||
| 54 | - * Crm 转换数据 VO 数据 | ||
| 55 | - */ | ||
| 56 | - private static final ThreadLocal<CrmTransferBaseVO> CRM_TRANSFER_VO = new ThreadLocal<>(); | ||
| 57 | - | ||
| 58 | @Resource | 33 | @Resource |
| 59 | - private CrmBusinessService crmBusinessService; | ||
| 60 | - @Resource | ||
| 61 | - private ContactService contactService; | ||
| 62 | - @Resource | ||
| 63 | - private ContractService contractService; | ||
| 64 | - @Resource | ||
| 65 | - private CrmCustomerService crmCustomerService; | ||
| 66 | - | ||
| 67 | - public static void setCrmTransferInfo(Long userId, Integer userType, Object crmTransferBaseVO) { | ||
| 68 | - USER_ID.set(userId); | ||
| 69 | - USER_TYPE.set(userType); | ||
| 70 | - CRM_TRANSFER_VO.set((CrmTransferBaseVO) crmTransferBaseVO); | ||
| 71 | - } | 34 | + private CrmPermissionService crmPermissionService; |
| 72 | 35 | ||
| 73 | - public static void setCrmTransferInfo(Long userId, Integer userType) { | ||
| 74 | - USER_ID.set(userId); | ||
| 75 | - USER_TYPE.set(userType); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - private static void clear() { | ||
| 79 | - USER_ID.remove(); | ||
| 80 | - USER_TYPE.remove(); | ||
| 81 | - DATA_ID.remove(); | ||
| 82 | - CRM_TRANSFER_VO.remove(); | 36 | + /** |
| 37 | + * 获得用户编号 | ||
| 38 | + * | ||
| 39 | + * @return 用户编号 | ||
| 40 | + */ | ||
| 41 | + private static Long getUserId() { | ||
| 42 | + return WebFrameworkUtils.getLoginUserId(); | ||
| 83 | } | 43 | } |
| 84 | 44 | ||
| 85 | @Before("@annotation(crmPermission)") | 45 | @Before("@annotation(crmPermission)") |
| @@ -87,78 +47,46 @@ public class CrmPermissionAspect { | @@ -87,78 +47,46 @@ public class CrmPermissionAspect { | ||
| 87 | try { | 47 | try { |
| 88 | Integer crmType = crmPermission.crmType().getType(); | 48 | Integer crmType = crmPermission.crmType().getType(); |
| 89 | Integer operationType = crmPermission.operationType().getType(); | 49 | Integer operationType = crmPermission.operationType().getType(); |
| 90 | - Long id = DATA_ID.get();// 获取操作数据的编号 | ||
| 91 | - KeyValue<Collection<Long>, Collection<Long>> keyValue = new KeyValue<>(); // 数据权限 key 只读,value 读写 | ||
| 92 | - // 客户 | ||
| 93 | - if (ObjUtil.equal(crmType, CrmEnum.CRM_CUSTOMER.getType())) { | ||
| 94 | - CrmCustomerDO customer = crmCustomerService.getCustomer(id); | ||
| 95 | - if (customer == null) { | ||
| 96 | - throw exception(CUSTOMER_NOT_EXISTS); | ||
| 97 | - } | ||
| 98 | - // 如果是自己则直接过 | ||
| 99 | - if (ObjUtil.equal(customer.getOwnerUserId(), USER_ID.get())) { | ||
| 100 | - return; | ||
| 101 | - } | ||
| 102 | - new KeyValue<>(customer.getRoUserIds(), customer.getRwUserIds()); | 50 | + Long id = (Long) joinPoint.getArgs()[0];// 获取操作数据的编号 |
| 51 | + | ||
| 52 | + // 1. 获取数据权限 | ||
| 53 | + CrmPermissionDO permission = crmPermissionService.getCrmPermissionByCrmTypeAndCrmDataId(crmType, id); | ||
| 54 | + if (permission == null) { | ||
| 55 | + // 不存在说明数据也不存在 | ||
| 56 | + throw exception(CRM_PERMISSION_MODEL_NOT_EXISTS, crmPermission.crmType().getName()); | ||
| 103 | } | 57 | } |
| 104 | - // 联系人 | ||
| 105 | - if (ObjUtil.equal(crmType, CrmEnum.CRM_CONTACTS.getType())) { | ||
| 106 | - ContactDO contact = contactService.getContact(id); | ||
| 107 | - if (contact == null) { | ||
| 108 | - throw exception(CONTACT_NOT_EXISTS); | ||
| 109 | - } | ||
| 110 | - // 如果是自己则直接过 | ||
| 111 | - if (ObjUtil.equal(contact.getOwnerUserId(), USER_ID.get())) { | ||
| 112 | - return; | ||
| 113 | - } | ||
| 114 | - new KeyValue<>(contact.getRoUserIds(), contact.getRwUserIds()); | 58 | + // 1.2. 校验是否为公海数据 |
| 59 | + if (permission.getOwnerUserId() == null) { | ||
| 60 | + return; | ||
| 115 | } | 61 | } |
| 116 | - // 商机 | ||
| 117 | - if (ObjUtil.equal(crmType, CrmEnum.CRM_BUSINESS.getType())) { | ||
| 118 | - CrmBusinessDO business = crmBusinessService.getBusiness(id); | ||
| 119 | - if (business == null) { | ||
| 120 | - throw exception(BUSINESS_NOT_EXISTS); | ||
| 121 | - } | ||
| 122 | - // 如果是自己则直接过 | ||
| 123 | - if (ObjUtil.equal(business.getOwnerUserId(), USER_ID.get())) { | ||
| 124 | - return; | ||
| 125 | - } | ||
| 126 | - new KeyValue<>(business.getRoUserIds(), business.getRwUserIds()); | ||
| 127 | - } | ||
| 128 | - // 合同 | ||
| 129 | - if (ObjUtil.equal(crmType, CrmEnum.CRM_CONTRACT.getType())) { | ||
| 130 | - ContractDO contract = contractService.getContract(id); | ||
| 131 | - if (contract == null) { | ||
| 132 | - throw exception(CONTRACT_NOT_EXISTS); | ||
| 133 | - } | ||
| 134 | - // 如果是自己则直接过 | ||
| 135 | - if (ObjUtil.equal(contract.getOwnerUserId(), USER_ID.get())) { | ||
| 136 | - return; | ||
| 137 | - } | ||
| 138 | - new KeyValue<>(contract.getRoUserIds(), contract.getRwUserIds()); | 62 | + // 1.3. 校验当前负责人是不是自己 |
| 63 | + if (ObjUtil.equal(permission.getOwnerUserId(), getUserId())) { | ||
| 64 | + return; | ||
| 139 | } | 65 | } |
| 140 | - // 1. 校验是否有读权限 | 66 | + // 1.4 TODO 校验是否为超级管理员 |
| 67 | + | ||
| 68 | + // 2. 校验是否有读权限 | ||
| 141 | if (OperationTypeEnum.isRead(operationType)) { | 69 | if (OperationTypeEnum.isRead(operationType)) { |
| 142 | // 校验该数据当前用户是否可读 | 70 | // 校验该数据当前用户是否可读 |
| 143 | - boolean isRead = CollUtil.contains(keyValue.getKey(), item -> ObjUtil.equal(id, USER_ID.get())) | ||
| 144 | - || CollUtil.contains(keyValue.getValue(), item -> ObjUtil.equal(id, USER_ID.get())); | 71 | + boolean isRead = CollUtil.contains(permission.getRoUserIds(), item -> ObjUtil.equal(item, getUserId())) |
| 72 | + || CollUtil.contains(permission.getRwUserIds(), item -> ObjUtil.equal(item, getUserId())); | ||
| 145 | if (isRead) { | 73 | if (isRead) { |
| 146 | return; | 74 | return; |
| 147 | } | 75 | } |
| 148 | - throw exception(CONTRACT_NOT_EXISTS); | ||
| 149 | } | 76 | } |
| 150 | - // 2. 校验是否有编辑权限 | 77 | + |
| 78 | + // 3. 校验是否有编辑权限 | ||
| 151 | if (OperationTypeEnum.isEdit(operationType)) { | 79 | if (OperationTypeEnum.isEdit(operationType)) { |
| 152 | // 校验该数据当前用户是否可读写 | 80 | // 校验该数据当前用户是否可读写 |
| 153 | - if (CollUtil.contains(keyValue.getValue(), item -> ObjUtil.equal(id, USER_ID.get()))) { | 81 | + if (CollUtil.contains(permission.getRwUserIds(), item -> ObjUtil.equal(item, getUserId()))) { |
| 154 | return; | 82 | return; |
| 155 | } | 83 | } |
| 156 | - throw exception(CONTRACT_NOT_EXISTS); | ||
| 157 | } | 84 | } |
| 85 | + | ||
| 86 | + // 4. 没通过结束,报错 {}操作失败,原因:没有权限 | ||
| 87 | + throw exception(CRM_PERMISSION_DENIED, crmPermission.crmType().getName()); | ||
| 158 | } catch (Exception ex) { | 88 | } catch (Exception ex) { |
| 159 | log.error("[doBefore][crmPermission({}) 数据校验错误]", toJsonString(crmPermission), ex); | 89 | log.error("[doBefore][crmPermission({}) 数据校验错误]", toJsonString(crmPermission), ex); |
| 160 | - } finally { | ||
| 161 | - clear(); | ||
| 162 | } | 90 | } |
| 163 | } | 91 | } |
| 164 | 92 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/dataobject/CrmPermissionBaseDO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.framework.dataobject; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler; | ||
| 5 | -import com.baomidou.mybatisplus.annotation.TableField; | ||
| 6 | -import lombok.Data; | ||
| 7 | -import lombok.EqualsAndHashCode; | ||
| 8 | -import lombok.ToString; | ||
| 9 | - | ||
| 10 | -import java.util.Set; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * crm 数据权限基础实体对象 | ||
| 14 | - * | ||
| 15 | - * @author HUIHUI | ||
| 16 | - */ | ||
| 17 | -@Data | ||
| 18 | -@EqualsAndHashCode(callSuper = true) | ||
| 19 | -@ToString(callSuper = true) | ||
| 20 | -public class CrmPermissionBaseDO extends BaseDO { | ||
| 21 | - | ||
| 22 | - /** | ||
| 23 | - * 负责人的用户编号 关联 AdminUser#id | ||
| 24 | - */ | ||
| 25 | - private Long ownerUserId; | ||
| 26 | - /** | ||
| 27 | - * 只读权限的用户编号数组 | ||
| 28 | - */ | ||
| 29 | - @TableField(typeHandler = JsonLongSetTypeHandler.class) | ||
| 30 | - private Set<Long> roUserIds; | ||
| 31 | - /** | ||
| 32 | - * 读写权限的用户编号数组 | ||
| 33 | - */ | ||
| 34 | - @TableField(typeHandler = JsonLongSetTypeHandler.class) | ||
| 35 | - private Set<Long> rwUserIds; | ||
| 36 | - | ||
| 37 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/enums/CrmEnum.java
| 1 | package cn.iocoder.yudao.module.crm.framework.enums; | 1 | package cn.iocoder.yudao.module.crm.framework.enums; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ObjUtil; | ||
| 3 | import lombok.Getter; | 4 | import lombok.Getter; |
| 4 | import lombok.RequiredArgsConstructor; | 5 | import lombok.RequiredArgsConstructor; |
| 5 | 6 | ||
| @@ -15,12 +16,8 @@ public enum CrmEnum { | @@ -15,12 +16,8 @@ public enum CrmEnum { | ||
| 15 | CRM_LEADS(1, "线索"), | 16 | CRM_LEADS(1, "线索"), |
| 16 | CRM_CUSTOMER(2, "客户"), | 17 | CRM_CUSTOMER(2, "客户"), |
| 17 | CRM_CONTACTS(3, "联系人"), | 18 | CRM_CONTACTS(3, "联系人"), |
| 18 | - CRM_PRODUCT(4, "产品"), | ||
| 19 | CRM_BUSINESS(5, "商机"), | 19 | CRM_BUSINESS(5, "商机"), |
| 20 | - CRM_CONTRACT(6, "合同"), | ||
| 21 | - CRM_RECEIVABLES(7, "回款"), | ||
| 22 | - CRM_RECEIVABLES_PLAN(8, "回款计划"), | ||
| 23 | - CRM_CUSTOMER_POOL(9, "客户公海"); | 20 | + CRM_CONTRACT(6, "合同"); |
| 24 | 21 | ||
| 25 | /** | 22 | /** |
| 26 | * 类型 | 23 | * 类型 |
| @@ -31,4 +28,13 @@ public enum CrmEnum { | @@ -31,4 +28,13 @@ public enum CrmEnum { | ||
| 31 | */ | 28 | */ |
| 32 | private final String name; | 29 | private final String name; |
| 33 | 30 | ||
| 31 | + public static String getNameByType(Integer type) { | ||
| 32 | + for (CrmEnum crmEnum : CrmEnum.values()) { | ||
| 33 | + if (ObjUtil.equal(crmEnum.type, type)) { | ||
| 34 | + return crmEnum.name; | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return ""; | ||
| 38 | + } | ||
| 39 | + | ||
| 34 | } | 40 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/enums/OperationTypeEnum.java
| @@ -15,8 +15,7 @@ public enum OperationTypeEnum { | @@ -15,8 +15,7 @@ public enum OperationTypeEnum { | ||
| 15 | 15 | ||
| 16 | DELETE(1, "删除"), | 16 | DELETE(1, "删除"), |
| 17 | UPDATE(2, "修改"), | 17 | UPDATE(2, "修改"), |
| 18 | - READ(3, "查询"), | ||
| 19 | - TRANSFER(4, "转移"); | 18 | + READ(3, "查询"); |
| 20 | 19 | ||
| 21 | /** | 20 | /** |
| 22 | * 类型 | 21 | * 类型 |
| @@ -33,7 +32,7 @@ public enum OperationTypeEnum { | @@ -33,7 +32,7 @@ public enum OperationTypeEnum { | ||
| 33 | } | 32 | } |
| 34 | 33 | ||
| 35 | public static boolean isEdit(Integer type) { | 34 | public static boolean isEdit(Integer type) { |
| 36 | - return ObjUtil.equal(type, UPDATE.getType()) || ObjUtil.equal(type, DELETE.getType()) || ObjUtil.equal(type, TRANSFER.getType()); | 35 | + return ObjUtil.equal(type, UPDATE.getType()) || ObjUtil.equal(type, DELETE.getType()); |
| 37 | } | 36 | } |
| 38 | 37 | ||
| 39 | } | 38 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/utils/CrmPermissionUtils.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.framework.utils; | ||
| 2 | - | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | -import cn.hutool.core.util.ObjUtil; | ||
| 5 | -import cn.iocoder.yudao.module.crm.framework.core.aop.CrmPermissionAspect; | ||
| 6 | - | ||
| 7 | -import java.util.Collection; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * 数据读写权限校验工具类 | ||
| 11 | - * | ||
| 12 | - * @author HUIHUI | ||
| 13 | - */ | ||
| 14 | -public class CrmPermissionUtils { | ||
| 15 | - | ||
| 16 | - // TODO @puhui999:负责人是单独的字段哈; | ||
| 17 | - // TODO @puhui999:额外校验,如果是管理员,可以查看所有;看着要做成有状态的了,可能要搞个 CrmPermissionService 咧; | ||
| 18 | - | ||
| 19 | - /** | ||
| 20 | - * 判断当前数据对用户来说是否是只读的 | ||
| 21 | - * | ||
| 22 | - * @param roUserIds 当前操作数据的只读权限的用户编号数组 | ||
| 23 | - * @param userId 当前操作数据的用户编号 | ||
| 24 | - * @return boolean 是/否 | ||
| 25 | - */ | ||
| 26 | - public static boolean isReadOnly(Collection<Long> roUserIds, Long userId) { | ||
| 27 | - return CollUtil.contains(roUserIds, id -> ObjUtil.equal(id, userId)); | ||
| 28 | - } | ||
| 29 | - | ||
| 30 | - /** | ||
| 31 | - * 判断当前数据对用户来说是否是可读写的 | ||
| 32 | - * | ||
| 33 | - * @param rwUserIds 当前操作数据的读写权限的用户编号数组 | ||
| 34 | - * @param userId 当前操作数据的用户编号 | ||
| 35 | - * @return boolean 是/否 | ||
| 36 | - */ | ||
| 37 | - public static boolean isReadAndWrite(Collection<Long> rwUserIds, Long userId) { | ||
| 38 | - return CollUtil.contains(rwUserIds, id -> ObjUtil.equal(id, userId)); | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - public static void setCrmTransferInfo(Long userId, Integer userType, Object crmTransferBaseVO) { | ||
| 42 | - CrmPermissionAspect.setCrmTransferInfo(userId, userType, crmTransferBaseVO); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - public static void setCrmTransferInfo(Long userId, Integer userType) { | ||
| 46 | - CrmPermissionAspect.setCrmTransferInfo(userId, userType); | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/vo/CrmTransferBaseVO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.framework.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | -import javax.validation.constraints.NotNull; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * Crm 数据转移 Base VO,提供给转移的子 VO 使用 | ||
| 10 | - * | ||
| 11 | - * @author HUIHUI | ||
| 12 | - */ | ||
| 13 | -@Data | ||
| 14 | -public class CrmTransferBaseVO { | ||
| 15 | - | ||
| 16 | - @Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 17 | - @NotNull(message = "联系人编号不能为空") | ||
| 18 | - private Long id; | ||
| 19 | - | ||
| 20 | - @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 21 | - @NotNull(message = "新负责人的用户编号不能为空") | ||
| 22 | - private Long ownerUserId; | ||
| 23 | - | ||
| 24 | - @Schema(description = "原负责人移除方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 25 | - @NotNull(message = "原负责人移除方式不能为空") | ||
| 26 | - private Integer transferType; | ||
| 27 | - | ||
| 28 | - @Schema(description = "权限类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") | ||
| 29 | - @NotNull(message = "权限类型不能为空") | ||
| 30 | - private Integer permissionType; | ||
| 31 | - | ||
| 32 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java
| @@ -19,9 +19,10 @@ public interface CrmBusinessService { | @@ -19,9 +19,10 @@ public interface CrmBusinessService { | ||
| 19 | * 创建商机 | 19 | * 创建商机 |
| 20 | * | 20 | * |
| 21 | * @param createReqVO 创建信息 | 21 | * @param createReqVO 创建信息 |
| 22 | + * @param userId 用户编号 | ||
| 22 | * @return 编号 | 23 | * @return 编号 |
| 23 | */ | 24 | */ |
| 24 | - Long createBusiness(@Valid CrmBusinessCreateReqVO createReqVO); | 25 | + Long createBusiness(@Valid CrmBusinessCreateReqVO createReqVO, Long userId); |
| 25 | 26 | ||
| 26 | /** | 27 | /** |
| 27 | * 更新商机 | 28 | * 更新商机 |
| @@ -76,5 +77,5 @@ public interface CrmBusinessService { | @@ -76,5 +77,5 @@ public interface CrmBusinessService { | ||
| 76 | * @param userId 用户编号 | 77 | * @param userId 用户编号 |
| 77 | */ | 78 | */ |
| 78 | void businessTransfer(CrmTransferBusinessReqVO reqVO, Long userId); | 79 | void businessTransfer(CrmTransferBusinessReqVO reqVO, Long userId); |
| 79 | - | 80 | + |
| 80 | } | 81 | } |
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; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.crm.service.business; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.collection.ListUtil; | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | -import cn.hutool.core.util.ObjUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*; | 6 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*; |
| 8 | import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; | 7 | import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; |
| @@ -11,9 +10,11 @@ import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper; | @@ -11,9 +10,11 @@ import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper; | ||
| 11 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; | 10 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 12 | import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | 11 | import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; |
| 13 | import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum; | 12 | import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum; |
| 13 | +import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; | ||
| 14 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; | ||
| 14 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | 15 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 15 | -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 16 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 17 | +import org.springframework.transaction.annotation.Transactional; | ||
| 17 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 18 | 19 | ||
| 19 | import javax.annotation.Resource; | 20 | import javax.annotation.Resource; |
| @@ -21,7 +22,7 @@ import java.util.Collection; | @@ -21,7 +22,7 @@ import java.util.Collection; | ||
| 21 | import java.util.List; | 22 | import java.util.List; |
| 22 | 23 | ||
| 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 24 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 24 | -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | 25 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS; |
| 25 | 26 | ||
| 26 | /** | 27 | /** |
| 27 | * 商机 Service 实现类 | 28 | * 商机 Service 实现类 |
| @@ -37,17 +38,27 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -37,17 +38,27 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 37 | 38 | ||
| 38 | @Resource | 39 | @Resource |
| 39 | private AdminUserApi adminUserApi; | 40 | private AdminUserApi adminUserApi; |
| 41 | + @Resource | ||
| 42 | + private CrmPermissionService crmPermissionService; | ||
| 40 | 43 | ||
| 41 | @Override | 44 | @Override |
| 42 | - public Long createBusiness(CrmBusinessCreateReqVO createReqVO) { | 45 | + @Transactional(rollbackFor = Exception.class) |
| 46 | + public Long createBusiness(CrmBusinessCreateReqVO createReqVO, Long userId) { | ||
| 43 | // 插入 | 47 | // 插入 |
| 44 | CrmBusinessDO business = CrmBusinessConvert.INSTANCE.convert(createReqVO); | 48 | CrmBusinessDO business = CrmBusinessConvert.INSTANCE.convert(createReqVO); |
| 45 | businessMapper.insert(business); | 49 | businessMapper.insert(business); |
| 50 | + | ||
| 51 | + // 创建数据权限 | ||
| 52 | + crmPermissionService.createCrmPermission(new CrmPermissionCreateBO().setCrmType(CrmEnum.CRM_BUSINESS.getType()) | ||
| 53 | + .setCrmDataId(business.getId()).setOwnerUserId(userId)); // 设置当前操作的人为负责人 | ||
| 54 | + | ||
| 46 | // 返回 | 55 | // 返回 |
| 47 | return business.getId(); | 56 | return business.getId(); |
| 48 | } | 57 | } |
| 49 | 58 | ||
| 50 | @Override | 59 | @Override |
| 60 | + @Transactional(rollbackFor = Exception.class) | ||
| 61 | + @CrmPermission(crmType = CrmEnum.CRM_BUSINESS, operationType = OperationTypeEnum.UPDATE) | ||
| 51 | public void updateBusiness(CrmBusinessUpdateReqVO updateReqVO) { | 62 | public void updateBusiness(CrmBusinessUpdateReqVO updateReqVO) { |
| 52 | // 校验存在 | 63 | // 校验存在 |
| 53 | validateBusinessExists(updateReqVO.getId()); | 64 | validateBusinessExists(updateReqVO.getId()); |
| @@ -57,6 +68,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -57,6 +68,8 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 57 | } | 68 | } |
| 58 | 69 | ||
| 59 | @Override | 70 | @Override |
| 71 | + @Transactional(rollbackFor = Exception.class) | ||
| 72 | + @CrmPermission(crmType = CrmEnum.CRM_BUSINESS, operationType = OperationTypeEnum.DELETE) | ||
| 60 | public void deleteBusiness(Long id) { | 73 | public void deleteBusiness(Long id) { |
| 61 | // 校验存在 | 74 | // 校验存在 |
| 62 | validateBusinessExists(id); | 75 | validateBusinessExists(id); |
| @@ -97,25 +110,15 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -97,25 +110,15 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 97 | } | 110 | } |
| 98 | 111 | ||
| 99 | @Override | 112 | @Override |
| 100 | - @CrmPermission(crmType = CrmEnum.CRM_BUSINESS, operationType = OperationTypeEnum.TRANSFER) | 113 | + @Transactional(rollbackFor = Exception.class) |
| 101 | public void businessTransfer(CrmTransferBusinessReqVO reqVO, Long userId) { | 114 | public void businessTransfer(CrmTransferBusinessReqVO reqVO, Long userId) { |
| 102 | - // 1.1 校验商机是否存在 | ||
| 103 | - CrmBusinessDO business = getBusiness(reqVO.getId()); | ||
| 104 | - // 1.3 校验转移对象是否已经是该负责人 | ||
| 105 | - if (ObjUtil.equal(business.getOwnerUserId(), reqVO.getOwnerUserId())) { | ||
| 106 | - throw exception(BUSINESS_TRANSFER_FAIL_OWNER_USER_EXISTS); | ||
| 107 | - } | ||
| 108 | - // 1.4 校验新负责人是否存在 | ||
| 109 | - AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId()); | ||
| 110 | - if (user == null) { | ||
| 111 | - throw exception(BUSINESS_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS); | ||
| 112 | - } | 115 | + // 1 校验商机是否存在 |
| 116 | + validateBusinessExists(reqVO.getId()); | ||
| 113 | 117 | ||
| 114 | - // 2. 更新新的负责人 | ||
| 115 | - CrmBusinessDO updateBusiness = CrmBusinessConvert.INSTANCE.convert(business, reqVO, userId); | ||
| 116 | - businessMapper.updateById(updateBusiness); | 118 | + // 2. 数据权限转移 |
| 119 | + crmPermissionService.transferCrmPermission( | ||
| 120 | + CrmBusinessConvert.INSTANCE.convert(reqVO, userId).setCrmType(CrmEnum.CRM_BUSINESS.getType())); | ||
| 117 | 121 | ||
| 118 | - // 3. TODO 记录商机转移日志 | ||
| 119 | } | 122 | } |
| 120 | 123 | ||
| 121 | } | 124 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java
| @@ -19,9 +19,10 @@ public interface ContactService { | @@ -19,9 +19,10 @@ public interface ContactService { | ||
| 19 | * 创建crm联系人 | 19 | * 创建crm联系人 |
| 20 | * | 20 | * |
| 21 | * @param createReqVO 创建信息 | 21 | * @param createReqVO 创建信息 |
| 22 | + * @param userId 用户编号 | ||
| 22 | * @return 编号 | 23 | * @return 编号 |
| 23 | */ | 24 | */ |
| 24 | - Long createContact(@Valid ContactCreateReqVO createReqVO); | 25 | + Long createContact(@Valid ContactCreateReqVO createReqVO, Long userId); |
| 25 | 26 | ||
| 26 | /** | 27 | /** |
| 27 | * 更新crm联系人 | 28 | * 更新crm联系人 |
| @@ -76,5 +77,5 @@ public interface ContactService { | @@ -76,5 +77,5 @@ public interface ContactService { | ||
| 76 | * @param userId 用户编号 | 77 | * @param userId 用户编号 |
| 77 | */ | 78 | */ |
| 78 | void contactTransfer(CrmContactTransferReqVO reqVO, Long userId); | 79 | void contactTransfer(CrmContactTransferReqVO reqVO, Long userId); |
| 79 | - | 80 | + |
| 80 | } | 81 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java
| @@ -7,9 +7,13 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; | @@ -7,9 +7,13 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; | ||
| 7 | import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; | 7 | import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; |
| 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; | 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; |
| 9 | import cn.iocoder.yudao.module.crm.dal.mysql.contact.ContactMapper; | 9 | import cn.iocoder.yudao.module.crm.dal.mysql.contact.ContactMapper; |
| 10 | -import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 11 | -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 10 | +import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 11 | +import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | ||
| 12 | +import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum; | ||
| 13 | +import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; | ||
| 14 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; | ||
| 12 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 16 | +import org.springframework.transaction.annotation.Transactional; | ||
| 13 | import org.springframework.validation.annotation.Validated; | 17 | import org.springframework.validation.annotation.Validated; |
| 14 | 18 | ||
| 15 | import javax.annotation.Resource; | 19 | import javax.annotation.Resource; |
| @@ -17,8 +21,7 @@ import java.util.Collection; | @@ -17,8 +21,7 @@ import java.util.Collection; | ||
| 17 | import java.util.List; | 21 | import java.util.List; |
| 18 | 22 | ||
| 19 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 20 | -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | ||
| 21 | -import static cn.iocoder.yudao.module.crm.framework.utils.CrmPermissionUtils.isReadAndWrite; | 24 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS; |
| 22 | 25 | ||
| 23 | /** | 26 | /** |
| 24 | * crm联系人 Service 实现类 | 27 | * crm联系人 Service 实现类 |
| @@ -33,19 +36,26 @@ public class ContactServiceImpl implements ContactService { | @@ -33,19 +36,26 @@ public class ContactServiceImpl implements ContactService { | ||
| 33 | private ContactMapper contactMapper; | 36 | private ContactMapper contactMapper; |
| 34 | 37 | ||
| 35 | @Resource | 38 | @Resource |
| 36 | - private AdminUserApi adminUserApi; | 39 | + private CrmPermissionService crmPermissionService; |
| 37 | 40 | ||
| 38 | @Override | 41 | @Override |
| 39 | - public Long createContact(ContactCreateReqVO createReqVO) { | 42 | + public Long createContact(ContactCreateReqVO createReqVO, Long userId) { |
| 40 | // TODO @customerId:需要校验存在 | 43 | // TODO @customerId:需要校验存在 |
| 41 | // 插入 | 44 | // 插入 |
| 42 | ContactDO contact = ContactConvert.INSTANCE.convert(createReqVO); | 45 | ContactDO contact = ContactConvert.INSTANCE.convert(createReqVO); |
| 43 | contactMapper.insert(contact); | 46 | contactMapper.insert(contact); |
| 47 | + | ||
| 48 | + // 创建数据权限 | ||
| 49 | + crmPermissionService.createCrmPermission(new CrmPermissionCreateBO().setCrmType(CrmEnum.CRM_BUSINESS.getType()) | ||
| 50 | + .setCrmDataId(contact.getId()).setOwnerUserId(userId)); // 设置当前操作的人为负责人 | ||
| 51 | + | ||
| 44 | // 返回 | 52 | // 返回 |
| 45 | return contact.getId(); | 53 | return contact.getId(); |
| 46 | } | 54 | } |
| 47 | 55 | ||
| 48 | @Override | 56 | @Override |
| 57 | + @Transactional(rollbackFor = Exception.class) | ||
| 58 | + @CrmPermission(crmType = CrmEnum.CRM_CONTACTS, operationType = OperationTypeEnum.UPDATE) | ||
| 49 | public void updateContact(ContactUpdateReqVO updateReqVO) { | 59 | public void updateContact(ContactUpdateReqVO updateReqVO) { |
| 50 | // 校验存在 | 60 | // 校验存在 |
| 51 | validateContactExists(updateReqVO.getId()); | 61 | validateContactExists(updateReqVO.getId()); |
| @@ -57,6 +67,8 @@ public class ContactServiceImpl implements ContactService { | @@ -57,6 +67,8 @@ public class ContactServiceImpl implements ContactService { | ||
| 57 | } | 67 | } |
| 58 | 68 | ||
| 59 | @Override | 69 | @Override |
| 70 | + @Transactional(rollbackFor = Exception.class) | ||
| 71 | + @CrmPermission(crmType = CrmEnum.CRM_CONTACTS, operationType = OperationTypeEnum.DELETE) | ||
| 60 | public void deleteContact(Long id) { | 72 | public void deleteContact(Long id) { |
| 61 | // 校验存在 | 73 | // 校验存在 |
| 62 | validateContactExists(id); | 74 | validateContactExists(id); |
| @@ -73,6 +85,7 @@ public class ContactServiceImpl implements ContactService { | @@ -73,6 +85,7 @@ public class ContactServiceImpl implements ContactService { | ||
| 73 | } | 85 | } |
| 74 | 86 | ||
| 75 | @Override | 87 | @Override |
| 88 | + @CrmPermission(crmType = CrmEnum.CRM_CONTACTS, operationType = OperationTypeEnum.READ) | ||
| 76 | public ContactDO getContact(Long id) { | 89 | public ContactDO getContact(Long id) { |
| 77 | return contactMapper.selectById(id); | 90 | return contactMapper.selectById(id); |
| 78 | } | 91 | } |
| @@ -95,26 +108,14 @@ public class ContactServiceImpl implements ContactService { | @@ -95,26 +108,14 @@ public class ContactServiceImpl implements ContactService { | ||
| 95 | return contactMapper.selectList(exportReqVO); | 108 | return contactMapper.selectList(exportReqVO); |
| 96 | } | 109 | } |
| 97 | 110 | ||
| 98 | - // TODO @puhui999:参考 CrmBusinessServiceImpl 修改建议 | ||
| 99 | @Override | 111 | @Override |
| 100 | public void contactTransfer(CrmContactTransferReqVO reqVO, Long userId) { | 112 | public void contactTransfer(CrmContactTransferReqVO reqVO, Long userId) { |
| 101 | - // 1. 校验联系人是否存在 | ||
| 102 | - ContactDO contact = validateContactExists(reqVO.getId()); | ||
| 103 | - // 1.2. 校验用户是否拥有读写权限 | ||
| 104 | - if (!isReadAndWrite(contact.getRwUserIds(), userId)) { | ||
| 105 | - throw exception(CONTACT_TRANSFER_FAIL_PERMISSION_DENIED); | ||
| 106 | - } | ||
| 107 | - // 2. 校验新负责人是否存在 | ||
| 108 | - AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId()); | ||
| 109 | - if (user == null) { | ||
| 110 | - throw exception(CONTACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS); | ||
| 111 | - } | ||
| 112 | - | ||
| 113 | - // 3. 更新新的负责人 | ||
| 114 | - ContactDO updateContact = ContactConvert.INSTANCE.convert(contact, reqVO, userId); | ||
| 115 | - contactMapper.updateById(updateContact); | 113 | + // 1 校验联系人是否存在 |
| 114 | + validateContactExists(reqVO.getId()); | ||
| 116 | 115 | ||
| 117 | - // 4. TODO 记录联系人转移日志 | 116 | + // 2. 数据权限转移 |
| 117 | + crmPermissionService.transferCrmPermission( | ||
| 118 | + ContactConvert.INSTANCE.convert(reqVO, userId).setCrmType(CrmEnum.CRM_CONTACTS.getType())); | ||
| 118 | 119 | ||
| 119 | } | 120 | } |
| 120 | 121 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractService.java
| @@ -19,9 +19,10 @@ public interface ContractService { | @@ -19,9 +19,10 @@ public interface ContractService { | ||
| 19 | * 创建合同 | 19 | * 创建合同 |
| 20 | * | 20 | * |
| 21 | * @param createReqVO 创建信息 | 21 | * @param createReqVO 创建信息 |
| 22 | + * @param userId 用户编号 | ||
| 22 | * @return 编号 | 23 | * @return 编号 |
| 23 | */ | 24 | */ |
| 24 | - Long createContract(@Valid ContractCreateReqVO createReqVO); | 25 | + Long createContract(@Valid ContractCreateReqVO createReqVO, Long userId); |
| 25 | 26 | ||
| 26 | /** | 27 | /** |
| 27 | * 更新合同 | 28 | * 更新合同 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImpl.java
| @@ -10,9 +10,10 @@ import cn.iocoder.yudao.module.crm.dal.mysql.contract.ContractMapper; | @@ -10,9 +10,10 @@ import cn.iocoder.yudao.module.crm.dal.mysql.contract.ContractMapper; | ||
| 10 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; | 10 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 11 | import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | 11 | import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; |
| 12 | import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum; | 12 | import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum; |
| 13 | -import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 14 | -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 13 | +import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 14 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; | ||
| 15 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 16 | +import org.springframework.transaction.annotation.Transactional; | ||
| 16 | import org.springframework.validation.annotation.Validated; | 17 | import org.springframework.validation.annotation.Validated; |
| 17 | 18 | ||
| 18 | import javax.annotation.Resource; | 19 | import javax.annotation.Resource; |
| @@ -20,8 +21,7 @@ import java.util.Collection; | @@ -20,8 +21,7 @@ import java.util.Collection; | ||
| 20 | import java.util.List; | 21 | import java.util.List; |
| 21 | 22 | ||
| 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 23 | -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | ||
| 24 | -import static cn.iocoder.yudao.module.crm.framework.utils.CrmPermissionUtils.isReadAndWrite; | 24 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTRACT_NOT_EXISTS; |
| 25 | 25 | ||
| 26 | /** | 26 | /** |
| 27 | * 合同 Service 实现类 | 27 | * 合同 Service 实现类 |
| @@ -36,18 +36,25 @@ public class ContractServiceImpl implements ContractService { | @@ -36,18 +36,25 @@ public class ContractServiceImpl implements ContractService { | ||
| 36 | private ContractMapper contractMapper; | 36 | private ContractMapper contractMapper; |
| 37 | 37 | ||
| 38 | @Resource | 38 | @Resource |
| 39 | - private AdminUserApi adminUserApi; | 39 | + private CrmPermissionService crmPermissionService; |
| 40 | 40 | ||
| 41 | @Override | 41 | @Override |
| 42 | - public Long createContract(ContractCreateReqVO createReqVO) { | 42 | + public Long createContract(ContractCreateReqVO createReqVO, Long userId) { |
| 43 | // 插入 | 43 | // 插入 |
| 44 | ContractDO contract = ContractConvert.INSTANCE.convert(createReqVO); | 44 | ContractDO contract = ContractConvert.INSTANCE.convert(createReqVO); |
| 45 | contractMapper.insert(contract); | 45 | contractMapper.insert(contract); |
| 46 | + | ||
| 47 | + // 创建数据权限 | ||
| 48 | + crmPermissionService.createCrmPermission(new CrmPermissionCreateBO().setCrmType(CrmEnum.CRM_CONTRACT.getType()) | ||
| 49 | + .setCrmDataId(contract.getId()).setOwnerUserId(userId)); // 设置当前操作的人为负责人 | ||
| 50 | + | ||
| 46 | // 返回 | 51 | // 返回 |
| 47 | return contract.getId(); | 52 | return contract.getId(); |
| 48 | } | 53 | } |
| 49 | 54 | ||
| 50 | @Override | 55 | @Override |
| 56 | + @Transactional(rollbackFor = Exception.class) | ||
| 57 | + @CrmPermission(crmType = CrmEnum.CRM_CONTRACT, operationType = OperationTypeEnum.DELETE) | ||
| 51 | public void updateContract(ContractUpdateReqVO updateReqVO) { | 58 | public void updateContract(ContractUpdateReqVO updateReqVO) { |
| 52 | // 校验存在 | 59 | // 校验存在 |
| 53 | validateContractExists(updateReqVO.getId()); | 60 | validateContractExists(updateReqVO.getId()); |
| @@ -57,6 +64,8 @@ public class ContractServiceImpl implements ContractService { | @@ -57,6 +64,8 @@ public class ContractServiceImpl implements ContractService { | ||
| 57 | } | 64 | } |
| 58 | 65 | ||
| 59 | @Override | 66 | @Override |
| 67 | + @Transactional(rollbackFor = Exception.class) | ||
| 68 | + @CrmPermission(crmType = CrmEnum.CRM_CONTRACT, operationType = OperationTypeEnum.DELETE) | ||
| 60 | public void deleteContract(Long id) { | 69 | public void deleteContract(Long id) { |
| 61 | // 校验存在 | 70 | // 校验存在 |
| 62 | validateContractExists(id); | 71 | validateContractExists(id); |
| @@ -73,6 +82,7 @@ public class ContractServiceImpl implements ContractService { | @@ -73,6 +82,7 @@ public class ContractServiceImpl implements ContractService { | ||
| 73 | } | 82 | } |
| 74 | 83 | ||
| 75 | @Override | 84 | @Override |
| 85 | + @CrmPermission(crmType = CrmEnum.CRM_CONTRACT, operationType = OperationTypeEnum.READ) | ||
| 76 | public ContractDO getContract(Long id) { | 86 | public ContractDO getContract(Long id) { |
| 77 | return contractMapper.selectById(id); | 87 | return contractMapper.selectById(id); |
| 78 | } | 88 | } |
| @@ -95,27 +105,15 @@ public class ContractServiceImpl implements ContractService { | @@ -95,27 +105,15 @@ public class ContractServiceImpl implements ContractService { | ||
| 95 | return contractMapper.selectList(exportReqVO); | 105 | return contractMapper.selectList(exportReqVO); |
| 96 | } | 106 | } |
| 97 | 107 | ||
| 98 | - // TODO @puhui999:参考 CrmBusinessServiceImpl 修改建议 | ||
| 99 | @Override | 108 | @Override |
| 100 | - @CrmPermission(crmType = CrmEnum.CRM_CONTRACT, operationType = OperationTypeEnum.TRANSFER) | 109 | + @Transactional(rollbackFor = Exception.class) |
| 101 | public void contractTransfer(CrmContractTransferReqVO reqVO, Long userId) { | 110 | public void contractTransfer(CrmContractTransferReqVO reqVO, Long userId) { |
| 102 | - // 1. 校验合同是否存在 | ||
| 103 | - ContractDO contract = validateContractExists(reqVO.getId()); | ||
| 104 | - // 1.2. 校验用户是否拥有读写权限 | ||
| 105 | - if (!isReadAndWrite(contract.getRwUserIds(), userId)) { | ||
| 106 | - throw exception(CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED); | ||
| 107 | - } | ||
| 108 | - // 2. 校验新负责人是否存在 | ||
| 109 | - AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId()); | ||
| 110 | - if (user == null) { | ||
| 111 | - throw exception(CONTRACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS); | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - // 3. 更新新的负责人 | ||
| 115 | - ContractDO updateContract = ContractConvert.INSTANCE.convert(contract, reqVO, userId); | ||
| 116 | - contractMapper.updateById(updateContract); | 111 | + // 1 校验合同是否存在 |
| 112 | + validateContractExists(reqVO.getId()); | ||
| 117 | 113 | ||
| 118 | - // 4. TODO 记录合同转移日志 | 114 | + // 2. 数据权限转移 |
| 115 | + crmPermissionService.transferCrmPermission( | ||
| 116 | + ContractConvert.INSTANCE.convert(reqVO, userId).setCrmType(CrmEnum.CRM_CONTRACT.getType())); | ||
| 119 | 117 | ||
| 120 | } | 118 | } |
| 121 | 119 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java
| @@ -2,8 +2,10 @@ package cn.iocoder.yudao.module.crm.service.permission; | @@ -2,8 +2,10 @@ package cn.iocoder.yudao.module.crm.service.permission; | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | 4 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; |
| 5 | +import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | ||
| 5 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; | 6 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; |
| 6 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO; | 7 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO; |
| 8 | +import cn.iocoder.yudao.module.crm.service.permission.bo.TransferCrmPermissionBO; | ||
| 7 | 9 | ||
| 8 | import javax.validation.Valid; | 10 | import javax.validation.Valid; |
| 9 | 11 | ||
| @@ -39,9 +41,17 @@ public interface CrmPermissionService { | @@ -39,9 +41,17 @@ public interface CrmPermissionService { | ||
| 39 | /** | 41 | /** |
| 40 | * 获得数据权限 | 42 | * 获得数据权限 |
| 41 | * | 43 | * |
| 42 | - * @param id 编号 | 44 | + * @param crmType 数据类型 关联 {@link CrmEnum} |
| 45 | + * @param crmDataId 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() | ||
| 43 | * @return 数据权限 | 46 | * @return 数据权限 |
| 44 | */ | 47 | */ |
| 45 | - CrmPermissionDO getCrmPermission(Long id); | 48 | + CrmPermissionDO getCrmPermissionByCrmTypeAndCrmDataId(Integer crmType, Long crmDataId); |
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 数据权限转移 | ||
| 52 | + * | ||
| 53 | + * @param transferCrmPermissionBO 数据权限转移请求 | ||
| 54 | + */ | ||
| 55 | + void transferCrmPermission(@Valid TransferCrmPermissionBO transferCrmPermissionBO); | ||
| 46 | 56 | ||
| 47 | } | 57 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java
| 1 | package cn.iocoder.yudao.module.crm.service.permission; | 1 | package cn.iocoder.yudao.module.crm.service.permission; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.hutool.core.util.ObjUtil; | ||
| 3 | import cn.iocoder.yudao.module.crm.convert.permission.CrmPermissionConvert; | 5 | import cn.iocoder.yudao.module.crm.convert.permission.CrmPermissionConvert; |
| 4 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; |
| 5 | import cn.iocoder.yudao.module.crm.dal.mysql.permission.CrmPermissionMapper; | 7 | import cn.iocoder.yudao.module.crm.dal.mysql.permission.CrmPermissionMapper; |
| 8 | +import cn.iocoder.yudao.module.crm.enums.common.PermissionTypeEnum; | ||
| 9 | +import cn.iocoder.yudao.module.crm.enums.common.TransferTypeEnum; | ||
| 10 | +import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | ||
| 6 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; | 11 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO; |
| 7 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO; | 12 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionUpdateBO; |
| 13 | +import cn.iocoder.yudao.module.crm.service.permission.bo.TransferCrmPermissionBO; | ||
| 14 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 15 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 8 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 9 | import org.springframework.transaction.annotation.Transactional; | 17 | import org.springframework.transaction.annotation.Transactional; |
| 10 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 11 | 19 | ||
| 12 | import javax.annotation.Resource; | 20 | import javax.annotation.Resource; |
| 21 | +import java.util.Set; | ||
| 13 | 22 | ||
| 14 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 15 | -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_NOT_EXISTS; | 24 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| 16 | 25 | ||
| 17 | /** | 26 | /** |
| 18 | * crm 数据权限 Service 接口实现类 | 27 | * crm 数据权限 Service 接口实现类 |
| @@ -26,6 +35,8 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | @@ -26,6 +35,8 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | ||
| 26 | @Resource | 35 | @Resource |
| 27 | private CrmPermissionMapper crmPermissionMapper; | 36 | private CrmPermissionMapper crmPermissionMapper; |
| 28 | 37 | ||
| 38 | + @Resource | ||
| 39 | + private AdminUserApi adminUserApi; | ||
| 29 | 40 | ||
| 30 | @Override | 41 | @Override |
| 31 | @Transactional(rollbackFor = Exception.class) | 42 | @Transactional(rollbackFor = Exception.class) |
| @@ -59,8 +70,52 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | @@ -59,8 +70,52 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { | ||
| 59 | } | 70 | } |
| 60 | 71 | ||
| 61 | @Override | 72 | @Override |
| 62 | - public CrmPermissionDO getCrmPermission(Long id) { | ||
| 63 | - return crmPermissionMapper.selectById(id); | 73 | + public CrmPermissionDO getCrmPermissionByCrmTypeAndCrmDataId(Integer crmType, Long crmDataId) { |
| 74 | + return crmPermissionMapper.selectByCrmTypeAndCrmDataId(crmType, crmDataId); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public void transferCrmPermission(TransferCrmPermissionBO transferCrmPermissionBO) { | ||
| 79 | + // 1 校验商机是否存在 | ||
| 80 | + CrmPermissionDO permission = getCrmPermissionByCrmTypeAndCrmDataId(transferCrmPermissionBO.getCrmType(), | ||
| 81 | + transferCrmPermissionBO.getCrmDataId()); | ||
| 82 | + String crmName = CrmEnum.getNameByType(transferCrmPermissionBO.getCrmType()); | ||
| 83 | + if (permission == null) { | ||
| 84 | + throw exception(CRM_PERMISSION_MODEL_NOT_EXISTS, crmName); | ||
| 85 | + } | ||
| 86 | + // 1.2 校验转移对象是否已经是该负责人 | ||
| 87 | + if (ObjUtil.equal(permission.getOwnerUserId(), permission.getOwnerUserId())) { | ||
| 88 | + throw exception(CRM_PERMISSION_MODEL_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS, crmName); | ||
| 89 | + } | ||
| 90 | + // 1.3 校验新负责人是否存在 | ||
| 91 | + AdminUserRespDTO user = adminUserApi.getUser(permission.getOwnerUserId()); | ||
| 92 | + if (user == null) { | ||
| 93 | + throw exception(CRM_PERMISSION_MODEL_TRANSFER_FAIL_OWNER_USER_EXISTS, crmName); | ||
| 94 | + } | ||
| 95 | + // TODO 校验是否为超级管理员 || 1.4 | ||
| 96 | + // 1.4 校验是否有写权限 | ||
| 97 | + if (!CollUtil.contains(permission.getRwUserIds(), id -> ObjUtil.equal(id, transferCrmPermissionBO.getUserId()))) { | ||
| 98 | + throw exception(CRM_PERMISSION_DENIED, crmName); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + // 2 权限转移 | ||
| 102 | + CrmPermissionDO updateCrmPermission = new CrmPermissionDO().setId(permission.getId()) | ||
| 103 | + .setOwnerUserId(transferCrmPermissionBO.getOwnerUserId()); | ||
| 104 | + if (ObjUtil.equal(TransferTypeEnum.TEAM.getType(), transferCrmPermissionBO.getTransferType())) { | ||
| 105 | + if (ObjUtil.equal(PermissionTypeEnum.READONLY.getType(), transferCrmPermissionBO.getPermissionType())) { | ||
| 106 | + Set<Long> roUserIds = permission.getRoUserIds(); | ||
| 107 | + roUserIds.add(permission.getOwnerUserId()); // 老负责人加入团队有只读权限 | ||
| 108 | + updateCrmPermission.setRoUserIds(roUserIds); | ||
| 109 | + } | ||
| 110 | + if (ObjUtil.equal(PermissionTypeEnum.READ_AND_WRITE.getType(), transferCrmPermissionBO.getPermissionType())) { | ||
| 111 | + Set<Long> rwUserIds = permission.getRwUserIds(); | ||
| 112 | + rwUserIds.add(permission.getOwnerUserId()); // 老负责人加入团队有读写权限 | ||
| 113 | + updateCrmPermission.setRoUserIds(rwUserIds); | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | + crmPermissionMapper.updateById(updateCrmPermission); | ||
| 117 | + | ||
| 118 | + // 3. TODO 记录机转移日志 | ||
| 64 | } | 119 | } |
| 65 | 120 | ||
| 66 | } | 121 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionCreateBO.java
| @@ -23,7 +23,7 @@ public class CrmPermissionCreateBO { | @@ -23,7 +23,7 @@ public class CrmPermissionCreateBO { | ||
| 23 | * 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() | 23 | * 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() |
| 24 | */ | 24 | */ |
| 25 | @NotNull(message = "Crm 数据编号不能为空") | 25 | @NotNull(message = "Crm 数据编号不能为空") |
| 26 | - private Integer crmDataId; | 26 | + private Long crmDataId; |
| 27 | /** | 27 | /** |
| 28 | * 负责人的用户编号 关联 AdminUser#id, null 则为公海数据 | 28 | * 负责人的用户编号 关联 AdminUser#id, null 则为公海数据 |
| 29 | */ | 29 | */ |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/CrmPermissionUpdateBO.java
| @@ -30,7 +30,7 @@ public class CrmPermissionUpdateBO { | @@ -30,7 +30,7 @@ public class CrmPermissionUpdateBO { | ||
| 30 | * 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() | 30 | * 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() |
| 31 | */ | 31 | */ |
| 32 | @NotNull(message = "Crm 数据编号不能为空") | 32 | @NotNull(message = "Crm 数据编号不能为空") |
| 33 | - private Integer crmDataId; | 33 | + private Long crmDataId; |
| 34 | /** | 34 | /** |
| 35 | * 负责人的用户编号 关联 AdminUser#id, null 则为公海数据 | 35 | * 负责人的用户编号 关联 AdminUser#id, null 则为公海数据 |
| 36 | */ | 36 | */ |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/bo/TransferCrmPermissionBO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.service.permission.bo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.crm.enums.common.PermissionTypeEnum; | ||
| 4 | +import cn.iocoder.yudao.module.crm.enums.common.TransferTypeEnum; | ||
| 5 | +import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +import javax.validation.constraints.NotNull; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 数据权限转移 BO | ||
| 12 | + * | ||
| 13 | + * @author HUIHUI | ||
| 14 | + */ | ||
| 15 | +@Data | ||
| 16 | +public class TransferCrmPermissionBO { | ||
| 17 | + | ||
| 18 | + @NotNull(message = "用户编号不能为空") | ||
| 19 | + private Long userId; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * Crm 类型 关联 {@link CrmEnum} | ||
| 23 | + */ | ||
| 24 | + @NotNull(message = "Crm 类型不能为空") | ||
| 25 | + private Integer crmType; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 数据编号 关联 {@link CrmEnum} 对应模块 DO#getId() | ||
| 29 | + */ | ||
| 30 | + @NotNull(message = "Crm 数据编号不能为空") | ||
| 31 | + private Long crmDataId; | ||
| 32 | + | ||
| 33 | + @NotNull(message = "新负责人的用户编号不能为空") | ||
| 34 | + private Long ownerUserId; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 原负责人移除方式, 关联 {@link TransferTypeEnum} | ||
| 38 | + */ | ||
| 39 | + @NotNull(message = "原负责人移除方式不能为空") | ||
| 40 | + private Integer transferType; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 权限类型, 关联 {@link PermissionTypeEnum} | ||
| 44 | + */ | ||
| 45 | + @NotNull(message = "权限类型不能为空") | ||
| 46 | + private Integer permissionType; | ||
| 47 | + | ||
| 48 | +} |
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImplTest.java
| @@ -15,6 +15,7 @@ import java.util.List; | @@ -15,6 +15,7 @@ import java.util.List; | ||
| 15 | 15 | ||
| 16 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | 16 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
| 17 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | 17 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 18 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||
| 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 19 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 19 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 20 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 20 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | 21 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; |
| @@ -42,7 +43,7 @@ public class CrmBusinessServiceImplTest extends BaseDbUnitTest { | @@ -42,7 +43,7 @@ public class CrmBusinessServiceImplTest extends BaseDbUnitTest { | ||
| 42 | CrmBusinessCreateReqVO reqVO = randomPojo(CrmBusinessCreateReqVO.class); | 43 | CrmBusinessCreateReqVO reqVO = randomPojo(CrmBusinessCreateReqVO.class); |
| 43 | 44 | ||
| 44 | // 调用 | 45 | // 调用 |
| 45 | - Long businessId = businessService.createBusiness(reqVO); | 46 | + Long businessId = businessService.createBusiness(reqVO, getLoginUserId()); |
| 46 | // 断言 | 47 | // 断言 |
| 47 | assertNotNull(businessId); | 48 | assertNotNull(businessId); |
| 48 | // 校验记录的属性是否正确 | 49 | // 校验记录的属性是否正确 |
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImplTest.java
| @@ -17,6 +17,7 @@ import java.util.List; | @@ -17,6 +17,7 @@ import java.util.List; | ||
| 17 | 17 | ||
| 18 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | 18 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
| 19 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | 19 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 20 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||
| 20 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 21 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 21 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 22 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 22 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | 23 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; |
| @@ -44,7 +45,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest { | @@ -44,7 +45,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest { | ||
| 44 | ContractCreateReqVO reqVO = randomPojo(ContractCreateReqVO.class); | 45 | ContractCreateReqVO reqVO = randomPojo(ContractCreateReqVO.class); |
| 45 | 46 | ||
| 46 | // 调用 | 47 | // 调用 |
| 47 | - Long contractId = contractService.createContract(reqVO); | 48 | + Long contractId = contractService.createContract(reqVO, getLoginUserId()); |
| 48 | // 断言 | 49 | // 断言 |
| 49 | assertNotNull(contractId); | 50 | assertNotNull(contractId); |
| 50 | // 校验记录的属性是否正确 | 51 | // 校验记录的属性是否正确 |