Commit f73b857551e48c2b52dc3f212200234f86fde999

Authored by 芋道源码
Committed by Gitee
2 parents fe50356a 722e9c8a

!702 CRM【商机】【联系人】【合同】新增 transfer 接口

Merge pull request !702 from puhui999/feature/crm
Showing 26 changed files with 393 additions and 86 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
... ... @@ -11,12 +11,16 @@ public interface ErrorCodeConstants {
11 11  
12 12 // ========== 合同管理 1-020-000-000 ==========
13 13 ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在");
  14 + ErrorCode CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_000_001, "合同转移失败,原因:没有转移权限");
  15 + ErrorCode CONTRACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_000_002, "合同转移失败,原因:负责人不存在");
14 16  
15 17 // ========== 线索管理 1-020-001-000 ==========
16 18 ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
17 19  
18 20 // ========== 商机管理 1-020-002-000 ==========
19 21 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, "商机转移失败,原因:负责人不存在");
20 24  
21 25 // TODO @lilleo:商机状态、商机类型,都单独错误码段
22 26  
... ... @@ -25,6 +29,8 @@ public interface ErrorCodeConstants {
25 29  
26 30 // ========== 联系人管理 1-020-003-000 ==========
27 31 ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在");
  32 + ErrorCode CONTACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_003_001, "联系人转移失败,原因:没有转移权限");
  33 + ErrorCode CONTACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_003_002, "联系人转移失败,原因:负责人不存在");
28 34  
29 35 // TODO @liuhongfeng:错误码分段;
30 36 ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_030_000_001, "回款管理不存在");
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
... ... @@ -23,6 +23,7 @@ import java.util.List;
23 23  
24 24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
25 25 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  26 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
26 27  
27 28 @Tag(name = "管理后台 - 商机")
28 29 @RestController
... ... @@ -80,11 +81,19 @@ public class CrmBusinessController {
80 81 @PreAuthorize("@ss.hasPermission('crm:business:export')")
81 82 @OperateLog(type = EXPORT)
82 83 public void exportBusinessExcel(@Valid CrmBusinessExportReqVO exportReqVO,
83   - HttpServletResponse response) throws IOException {
  84 + HttpServletResponse response) throws IOException {
84 85 List<CrmBusinessDO> list = businessService.getBusinessList(exportReqVO);
85 86 // 导出 Excel
86 87 List<CrmBusinessExcelVO> datas = CrmBusinessConvert.INSTANCE.convertList02(list);
87 88 ExcelUtils.write(response, "商机.xls", "数据", CrmBusinessExcelVO.class, datas);
88 89 }
89 90  
  91 + @PutMapping("/transfer")
  92 + @Operation(summary = "商机转移")
  93 + @PreAuthorize("@ss.hasPermission('crm:business:update')")
  94 + public CommonResult<Boolean> transfer(@Valid @RequestBody CrmBusinessTransferReqVO reqVO) {
  95 + businessService.businessTransfer(reqVO, getLoginUserId());
  96 + return success(true);
  97 + }
  98 +
90 99 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/CrmBusinessCreateReqVO.java
... ... @@ -5,12 +5,21 @@ import lombok.Data;
5 5 import lombok.EqualsAndHashCode;
6 6 import lombok.ToString;
7 7  
  8 +import java.util.Set;
  9 +
8 10 @Schema(description = "管理后台 - 商机创建 Request VO")
9 11 @Data
10 12 @EqualsAndHashCode(callSuper = true)
11 13 @ToString(callSuper = true)
12 14 public class CrmBusinessCreateReqVO extends CrmBusinessBaseVO {
13 15  
  16 + @Schema(description = "只读权限的用户编号数组")
  17 + private Set<Long> roUserIds;
  18 +
  19 + @Schema(description = "读写权限的用户编号数组")
  20 + private Set<Long> rwUserIds;
  21 +
  22 +
14 23 // TODO @ljileo:新建的时候,应该可以传递添加的产品;
15 24  
16 25 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/CrmBusinessTransferReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.business.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +@Schema(description = "管理后台 - 商机转移 Request VO")
  9 +@Data
  10 +public class CrmBusinessTransferReqVO {
  11 +
  12 + @Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
  13 + @NotNull(message = "联系人编号不能为空")
  14 + private Long id;
  15 +
  16 + @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
  17 + @NotNull(message = "新负责人的用户编号不能为空")
  18 + private Long ownerUserId; // 新的负责人
  19 +
  20 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/CrmBusinessUpdateReqVO.java
... ... @@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
6 6 import lombok.ToString;
7 7  
8 8 import javax.validation.constraints.NotNull;
  9 +import java.util.Set;
9 10  
10 11 @Schema(description = "管理后台 - 商机更新 Request VO")
11 12 @Data
... ... @@ -17,6 +18,13 @@ public class CrmBusinessUpdateReqVO extends CrmBusinessBaseVO {
17 18 @NotNull(message = "主键不能为空")
18 19 private Long id;
19 20  
  21 + @Schema(description = "只读权限的用户编号数组")
  22 + private Set<Long> roUserIds;
  23 +
  24 + @Schema(description = "读写权限的用户编号数组")
  25 + private Set<Long> rwUserIds;
  26 +
  27 +
20 28 // TODO @ljileo:修改的时候,应该可以传递添加的产品;
21 29  
22 30 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.contact;
2 2  
3   -import org.springframework.web.bind.annotation.*;
4   -import javax.annotation.Resource;
5   -import org.springframework.validation.annotation.Validated;
6   -import org.springframework.security.access.prepost.PreAuthorize;
7   -import io.swagger.v3.oas.annotations.tags.Tag;
8   -import io.swagger.v3.oas.annotations.Parameter;
9   -import io.swagger.v3.oas.annotations.Operation;
10   -
11   -import javax.validation.constraints.*;
12   -import javax.validation.*;
13   -import javax.servlet.http.*;
14   -import java.util.*;
15   -import java.io.IOException;
16   -
17   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
18 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
19   -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
20   -
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
21 5 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
22   -
23 6 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
24   -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
25   -
26 7 import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
27   -import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
28 8 import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert;
  9 +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
29 10 import cn.iocoder.yudao.module.crm.service.contact.ContactService;
  11 +import io.swagger.v3.oas.annotations.Operation;
  12 +import io.swagger.v3.oas.annotations.Parameter;
  13 +import io.swagger.v3.oas.annotations.tags.Tag;
  14 +import org.springframework.security.access.prepost.PreAuthorize;
  15 +import org.springframework.validation.annotation.Validated;
  16 +import org.springframework.web.bind.annotation.*;
  17 +
  18 +import javax.annotation.Resource;
  19 +import javax.servlet.http.HttpServletResponse;
  20 +import javax.validation.Valid;
  21 +import java.io.IOException;
  22 +import java.util.Collection;
  23 +import java.util.List;
  24 +
  25 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  26 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  27 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
30 28  
31 29 @Tag(name = "管理后台 - crm联系人")
32 30 @RestController
... ... @@ -99,4 +97,12 @@ public class ContactController {
99 97 ExcelUtils.write(response, "crm联系人.xls", "数据", ContactExcelVO.class, datas);
100 98 }
101 99  
  100 + @PutMapping("/transfer")
  101 + @Operation(summary = "联系人转移")
  102 + @PreAuthorize("@ss.hasPermission('crm:contact:update')")
  103 + public CommonResult<Boolean> transfer(@Valid @RequestBody CrmContactTransferReqVO reqVO) {
  104 + contactService.contactTransfer(reqVO, getLoginUserId());
  105 + return success(true);
  106 + }
  107 +
102 108 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactCreateReqVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
2 2  
3   -import lombok.*;
4   -import java.util.*;
5 3 import io.swagger.v3.oas.annotations.media.Schema;
6   -import javax.validation.constraints.*;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +import java.util.Set;
7 9  
8 10 @Schema(description = "管理后台 - crm联系人创建 Request VO")
9 11 @Data
... ... @@ -11,4 +13,10 @@ import javax.validation.constraints.*;
11 13 @ToString(callSuper = true)
12 14 public class ContactCreateReqVO extends ContactBaseVO {
13 15  
  16 + @Schema(description = "只读权限的用户编号数组")
  17 + private Set<Long> roUserIds;
  18 +
  19 + @Schema(description = "读写权限的用户编号数组")
  20 + private Set<Long> rwUserIds;
  21 +
14 22 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactUpdateReqVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.*;
5   -import java.util.*;
6   -import javax.validation.constraints.*;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +import java.util.Set;
7 9  
8 10 @Schema(description = "管理后台 - crm联系人更新 Request VO")
9 11 @Data
... ... @@ -14,4 +16,10 @@ public class ContactUpdateReqVO extends ContactBaseVO {
14 16 @Schema(description = "主键", example = "23210")
15 17 private Long id;
16 18  
  19 + @Schema(description = "只读权限的用户编号数组")
  20 + private Set<Long> roUserIds;
  21 +
  22 + @Schema(description = "读写权限的用户编号数组")
  23 + private Set<Long> rwUserIds;
  24 +
17 25 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +@Schema(description = "管理后台 - 联系人转移 Request VO")
  9 +@Data
  10 +public class CrmContactTransferReqVO {
  11 +
  12 + @Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
  13 + @NotNull(message = "联系人编号不能为空")
  14 + private Long id;
  15 +
  16 + @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
  17 + @NotNull(message = "新负责人的用户编号不能为空")
  18 + private Long ownerUserId; // 新的负责人
  19 +
  20 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/ContractController.java
... ... @@ -23,6 +23,7 @@ import java.util.List;
23 23  
24 24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
25 25 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  26 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
26 27  
27 28 @Tag(name = "管理后台 - 合同")
28 29 @RestController
... ... @@ -86,4 +87,13 @@ public class ContractController {
86 87 ExcelUtils.write(response, "合同.xls", "数据", ContractExcelVO.class, datas);
87 88 }
88 89  
  90 + @PutMapping("/transfer")
  91 + @Operation(summary = "合同转移")
  92 + @PreAuthorize("@ss.hasPermission('crm:contract:update')")
  93 + public CommonResult<Boolean> transfer(@Valid @RequestBody CrmContractTransferReqVO reqVO) {
  94 + contractService.contractTransfer(reqVO, getLoginUserId());
  95 + return success(true);
  96 + }
  97 +
  98 +
89 99 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/ContractCreateReqVO.java
... ... @@ -5,6 +5,8 @@ import lombok.Data;
5 5 import lombok.EqualsAndHashCode;
6 6 import lombok.ToString;
7 7  
  8 +import java.util.Set;
  9 +
8 10 @Schema(description = "管理后台 - 合同创建 Request VO")
9 11 @Data
10 12 @EqualsAndHashCode(callSuper = true)
... ... @@ -12,9 +14,9 @@ import lombok.ToString;
12 14 public class ContractCreateReqVO extends ContractBaseVO {
13 15  
14 16 @Schema(description = "只读权限的用户编号数组")
15   - private String roUserIds;
  17 + private Set<Long> roUserIds;
16 18  
17 19 @Schema(description = "读写权限的用户编号数组")
18   - private String rwUserIds;
  20 + private Set<Long> rwUserIds;
19 21  
20 22 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/ContractUpdateReqVO.java
... ... @@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
6 6 import lombok.ToString;
7 7  
8 8 import javax.validation.constraints.NotNull;
  9 +import java.util.Set;
9 10  
10 11 @Schema(description = "管理后台 - 合同更新 Request VO")
11 12 @Data
... ... @@ -18,9 +19,9 @@ public class ContractUpdateReqVO extends ContractBaseVO {
18 19 private Long id;
19 20  
20 21 @Schema(description = "只读权限的用户编号数组")
21   - private String roUserIds;
  22 + private Set<Long> roUserIds;
22 23  
23 24 @Schema(description = "读写权限的用户编号数组")
24   - private String rwUserIds;
  25 + private Set<Long> rwUserIds;
25 26  
26 27 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractTransferReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.contract.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +@Schema(description = "管理后台 - 合同转移 Request VO")
  9 +@Data
  10 +public class CrmContractTransferReqVO {
  11 +
  12 + @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
  13 + @NotNull(message = "合同编号不能为空")
  14 + private Long id;
  15 +
  16 + @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
  17 + @NotNull(message = "新负责人的用户编号不能为空")
  18 + private Long ownerUserId; // 新的负责人
  19 +
  20 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/business/CrmBusinessConvert.java
1 1 package cn.iocoder.yudao.module.crm.convert.business;
2 2  
3   -import java.util.*;
4   -
  3 +import cn.hutool.core.util.ObjUtil;
5 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -
7   -import org.mapstruct.Mapper;
8   -import org.mapstruct.factory.Mappers;
9 5 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*;
10 6 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
  7 +import org.mapstruct.Mapper;
  8 +import org.mapstruct.factory.Mappers;
  9 +
  10 +import java.util.List;
  11 +import java.util.Set;
11 12  
12 13 /**
13 14 * 商机 Convert
... ... @@ -29,4 +30,12 @@ public interface CrmBusinessConvert {
29 30  
30 31 List<CrmBusinessExcelVO> convertList02(List<CrmBusinessDO> list);
31 32  
  33 + default CrmBusinessDO convert(CrmBusinessDO business, CrmBusinessTransferReqVO reqVO, Long userId) {
  34 + Set<Long> rwUserIds = business.getRwUserIds();
  35 + rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人
  36 + rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人
  37 + return new CrmBusinessDO().setId(business.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人
  38 + .setRwUserIds(rwUserIds);
  39 + }
  40 +
32 41 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java
1 1 package cn.iocoder.yudao.module.crm.convert.contact;
2 2  
3   -import java.util.*;
4   -
  3 +import cn.hutool.core.util.ObjUtil;
5 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -
7   -import org.mapstruct.Mapper;
8   -import org.mapstruct.factory.Mappers;
9 5 import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
10 6 import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
  7 +import org.mapstruct.Mapper;
  8 +import org.mapstruct.factory.Mappers;
  9 +
  10 +import java.util.List;
  11 +import java.util.Set;
11 12  
12 13 /**
13 14 * crm联系人 Convert
... ... @@ -31,4 +32,12 @@ public interface ContactConvert {
31 32  
32 33 List<ContactExcelVO> convertList02(List<ContactDO> list);
33 34  
  35 + default ContactDO convert(ContactDO contact, CrmContactTransferReqVO reqVO, Long userId) {
  36 + Set<Long> rwUserIds = contact.getRwUserIds();
  37 + rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人
  38 + rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人
  39 + return new ContactDO().setId(contact.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人
  40 + .setRwUserIds(rwUserIds);
  41 + }
  42 +
34 43 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contract/ContractConvert.java
1 1 package cn.iocoder.yudao.module.crm.convert.contract;
2 2  
  3 +import cn.hutool.core.util.ObjUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractCreateReqVO;
5   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractExcelVO;
6   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractRespVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractUpdateReqVO;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*;
8 6 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
9 7 import org.mapstruct.Mapper;
10 8 import org.mapstruct.factory.Mappers;
11 9  
12 10 import java.util.List;
  11 +import java.util.Set;
13 12  
14 13 /**
15 14 * 合同 Convert
... ... @@ -33,4 +32,12 @@ public interface ContractConvert {
33 32  
34 33 List<ContractExcelVO> convertList02(List<ContractDO> list);
35 34  
  35 + default ContractDO convert(ContractDO contract, CrmContractTransferReqVO reqVO, Long userId) {
  36 + Set<Long> rwUserIds = contract.getRwUserIds();
  37 + rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人
  38 + rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人
  39 + return new ContractDO().setId(contract.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人
  40 + .setRwUserIds(rwUserIds);
  41 + }
  42 +
36 43 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/business/CrmBusinessDO.java
1 1 package cn.iocoder.yudao.module.crm.dal.dataobject.business;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
4 5 import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatus.CrmBusinessStatusDO;
5 6 import cn.iocoder.yudao.module.crm.dal.dataobject.businessstatustype.CrmBusinessStatusTypeDO;
6 7 import com.baomidou.mybatisplus.annotation.KeySequence;
  8 +import com.baomidou.mybatisplus.annotation.TableField;
7 9 import com.baomidou.mybatisplus.annotation.TableId;
8 10 import com.baomidou.mybatisplus.annotation.TableName;
9 11 import lombok.*;
10 12  
11 13 import java.time.LocalDateTime;
  14 +import java.util.Set;
12 15  
13 16 /**
14 17 * 商机 DO
... ... @@ -85,16 +88,14 @@ public class CrmBusinessDO extends BaseDO {
85 88 private Long ownerUserId;
86 89 /**
87 90 * 只读权限的用户编号数组
88   - *
89   - * TODO @lijie:应该是 List<Long>,然后使用下对应的 typehandler
90 91 */
91   - private String roUserIds;
  92 + @TableField(typeHandler = JsonLongSetTypeHandler.class)
  93 + private Set<Long> roUserIds;
92 94 /**
93 95 * 读写权限的用户编号数组
94   - *
95   - * TODO @lijie:应该是 List<Long>,然后使用下对应的 typehandler
96 96 */
97   - private String rwUserIds;
  97 + @TableField(typeHandler = JsonLongSetTypeHandler.class)
  98 + private Set<Long> rwUserIds;
98 99 /**
99 100 * 1赢单2输单3无效
100 101 *
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/ContactDO.java
1 1 package cn.iocoder.yudao.module.crm.dal.dataobject.contact;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
4 5 import com.baomidou.mybatisplus.annotation.KeySequence;
  6 +import com.baomidou.mybatisplus.annotation.TableField;
5 7 import com.baomidou.mybatisplus.annotation.TableId;
6 8 import com.baomidou.mybatisplus.annotation.TableName;
7 9 import lombok.*;
8 10  
9 11 import java.time.LocalDateTime;
  12 +import java.util.Set;
10 13  
11 14 /**
12 15 * crm 联系人 DO
... ... @@ -77,4 +80,15 @@ public class ContactDO extends BaseDO {
77 80 */
78 81 private LocalDateTime lastTime;
79 82  
  83 + /**
  84 + * 只读权限的用户编号数组
  85 + */
  86 + @TableField(typeHandler = JsonLongSetTypeHandler.class)
  87 + private Set<Long> roUserIds;
  88 + /**
  89 + * 读写权限的用户编号数组
  90 + */
  91 + @TableField(typeHandler = JsonLongSetTypeHandler.class)
  92 + private Set<Long> rwUserIds;
  93 +
80 94 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contract/ContractDO.java
1 1 package cn.iocoder.yudao.module.crm.dal.dataobject.contract;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
4 5 import com.baomidou.mybatisplus.annotation.KeySequence;
  6 +import com.baomidou.mybatisplus.annotation.TableField;
5 7 import com.baomidou.mybatisplus.annotation.TableId;
6 8 import com.baomidou.mybatisplus.annotation.TableName;
7 9 import lombok.*;
8 10  
9 11 import java.time.LocalDateTime;
  12 +import java.util.Set;
10 13  
11 14 /**
12 15 * 合同 DO
... ... @@ -79,11 +82,13 @@ public class ContractDO extends BaseDO {
79 82 /**
80 83 * 只读权限的用户编号数组
81 84 */
82   - private String roUserIds;
  85 + @TableField(typeHandler = JsonLongSetTypeHandler.class)
  86 + private Set<Long> roUserIds;
83 87 /**
84 88 * 读写权限的用户编号数组
85 89 */
86   - private String rwUserIds;
  90 + @TableField(typeHandler = JsonLongSetTypeHandler.class)
  91 + private Set<Long> rwUserIds;
87 92 /**
88 93 * 联系人编号
89 94 */
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/utils/AuthUtil.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.framework.utils;
  2 +
  3 +import java.util.Collection;
  4 +
  5 +/**
  6 + * 数据读写权限校验工具类
  7 + *
  8 + * @author HUIHUI
  9 + */
  10 +public class AuthUtil {
  11 +
  12 + /**
  13 + * 判断当前数据对用户来说是否是只读的
  14 + *
  15 + * @param roUserIds 当前操作数据的只读权限的用户编号数组
  16 + * @param userId 当前操作数据的用户编号
  17 + * @return boolean 是/否
  18 + */
  19 + public static boolean isReadOnly(Collection<Long> roUserIds, Long userId) {
  20 + return roUserIds.contains(userId);
  21 + }
  22 +
  23 + /**
  24 + * 判断当前数据对用户来说是否是可读写的
  25 + *
  26 + * @param rwUserIds 当前操作数据的读写权限的用户编号数组
  27 + * @param userId 当前操作数据的用户编号
  28 + * @return boolean 是/否
  29 + */
  30 + public static boolean isReadAndWrite(Collection<Long> rwUserIds, Long userId) {
  31 + return rwUserIds.contains(userId);
  32 + }
  33 +
  34 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java
1 1 package cn.iocoder.yudao.module.crm.service.business;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessCreateReqVO;
5   -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessExportReqVO;
6   -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessPageReqVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessUpdateReqVO;
  4 +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*;
8 5 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
9 6  
10 7 import javax.validation.Valid;
... ... @@ -72,4 +69,12 @@ public interface CrmBusinessService {
72 69 */
73 70 List<CrmBusinessDO> getBusinessList(CrmBusinessExportReqVO exportReqVO);
74 71  
  72 + /**
  73 + * 商机转移
  74 + *
  75 + * @param reqVO 请求
  76 + * @param userId 用户编号
  77 + */
  78 + void businessTransfer(CrmBusinessTransferReqVO reqVO, Long userId);
  79 +
75 80 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
... ... @@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.service.business;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.collection.ListUtil;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessCreateReqVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessExportReqVO;
8   -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessPageReqVO;
9   -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessUpdateReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*;
10 7 import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
11 8 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
12 9 import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper;
  10 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  11 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
13 12 import org.springframework.stereotype.Service;
14 13 import org.springframework.validation.annotation.Validated;
15 14  
... ... @@ -18,7 +17,8 @@ import java.util.Collection;
18 17 import java.util.List;
19 18  
20 19 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
21   -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS;
  20 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
  21 +import static cn.iocoder.yudao.module.crm.framework.utils.AuthUtil.isReadAndWrite;
22 22  
23 23 /**
24 24 * 商机 Service 实现类
... ... @@ -32,6 +32,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
32 32 @Resource
33 33 private CrmBusinessMapper businessMapper;
34 34  
  35 + @Resource
  36 + private AdminUserApi adminUserApi;
  37 +
35 38 @Override
36 39 public Long createBusiness(CrmBusinessCreateReqVO createReqVO) {
37 40 // 插入
... ... @@ -58,10 +61,12 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
58 61 businessMapper.deleteById(id);
59 62 }
60 63  
61   - private void validateBusinessExists(Long id) {
62   - if (businessMapper.selectById(id) == null) {
  64 + private CrmBusinessDO validateBusinessExists(Long id) {
  65 + CrmBusinessDO crmBusiness = businessMapper.selectById(id);
  66 + if (crmBusiness == null) {
63 67 throw exception(BUSINESS_NOT_EXISTS);
64 68 }
  69 + return crmBusiness;
65 70 }
66 71  
67 72 @Override
... ... @@ -87,4 +92,26 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
87 92 return businessMapper.selectList(exportReqVO);
88 93 }
89 94  
  95 + @Override
  96 + public void businessTransfer(CrmBusinessTransferReqVO reqVO, Long userId) {
  97 + // 1. 校验商机是否存在
  98 + CrmBusinessDO business = validateBusinessExists(reqVO.getId());
  99 + // 1.2. 校验用户是否拥有读写权限
  100 + if (!isReadAndWrite(business.getRwUserIds(), userId)) {
  101 + throw exception(BUSINESS_TRANSFER_FAIL_PERMISSION_DENIED);
  102 + }
  103 + // 2. 校验新负责人是否存在
  104 + AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId());
  105 + if (user == null) {
  106 + throw exception(BUSINESS_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS);
  107 + }
  108 +
  109 + // 3. 更新新的负责人
  110 + CrmBusinessDO updateBusiness = CrmBusinessConvert.INSTANCE.convert(business, reqVO, userId);
  111 + businessMapper.updateById(updateBusiness);
  112 +
  113 + // 4. TODO 记录商机转移日志
  114 +
  115 + }
  116 +
90 117 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java
1 1 package cn.iocoder.yudao.module.crm.service.contact;
2 2  
3   -import java.util.*;
4   -import javax.validation.*;
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 4 import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
6 5 import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
7   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +
  7 +import javax.validation.Valid;
  8 +import java.util.Collection;
  9 +import java.util.List;
8 10  
9 11 /**
10 12 * crm联系人 Service 接口
... ... @@ -67,4 +69,12 @@ public interface ContactService {
67 69 */
68 70 List<ContactDO> getContactList(ContactExportReqVO exportReqVO);
69 71  
  72 + /**
  73 + * 联系人编号
  74 + *
  75 + * @param reqVO 请求
  76 + * @param userId 用户编号
  77 + */
  78 + void contactTransfer(CrmContactTransferReqVO reqVO, Long userId);
  79 +
70 80 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java
... ... @@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.service.contact;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.collection.ListUtil;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactExportReqVO;
8   -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO;
9   -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactUpdateReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
10 7 import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert;
11 8 import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
12 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;
13 12 import org.springframework.stereotype.Service;
14 13 import org.springframework.validation.annotation.Validated;
15 14  
... ... @@ -18,7 +17,8 @@ import java.util.Collection;
18 17 import java.util.List;
19 18  
20 19 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
21   -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS;
  20 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
  21 +import static cn.iocoder.yudao.module.crm.framework.utils.AuthUtil.isReadAndWrite;
22 22  
23 23 /**
24 24 * crm联系人 Service 实现类
... ... @@ -32,6 +32,9 @@ public class ContactServiceImpl implements ContactService {
32 32 @Resource
33 33 private ContactMapper contactMapper;
34 34  
  35 + @Resource
  36 + private AdminUserApi adminUserApi;
  37 +
35 38 @Override
36 39 public Long createContact(ContactCreateReqVO createReqVO) {
37 40 // TODO @customerId:需要校验存在
... ... @@ -61,10 +64,12 @@ public class ContactServiceImpl implements ContactService {
61 64 contactMapper.deleteById(id);
62 65 }
63 66  
64   - private void validateContactExists(Long id) {
65   - if (contactMapper.selectById(id) == null) {
  67 + private ContactDO validateContactExists(Long id) {
  68 + ContactDO contact = contactMapper.selectById(id);
  69 + if (contact == null) {
66 70 throw exception(CONTACT_NOT_EXISTS);
67 71 }
  72 + return contact;
68 73 }
69 74  
70 75 @Override
... ... @@ -90,4 +95,26 @@ public class ContactServiceImpl implements ContactService {
90 95 return contactMapper.selectList(exportReqVO);
91 96 }
92 97  
  98 + @Override
  99 + public void contactTransfer(CrmContactTransferReqVO reqVO, Long userId) {
  100 + // 1. 校验联系人是否存在
  101 + ContactDO contact = validateContactExists(reqVO.getId());
  102 + // 1.2. 校验用户是否拥有读写权限
  103 + if (!isReadAndWrite(contact.getRwUserIds(), userId)) {
  104 + throw exception(CONTACT_TRANSFER_FAIL_PERMISSION_DENIED);
  105 + }
  106 + // 2. 校验新负责人是否存在
  107 + AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId());
  108 + if (user == null) {
  109 + throw exception(CONTACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS);
  110 + }
  111 +
  112 + // 3. 更新新的负责人
  113 + ContactDO updateContact = ContactConvert.INSTANCE.convert(contact, reqVO, userId);
  114 + contactMapper.updateById(updateContact);
  115 +
  116 + // 4. TODO 记录联系人转移日志
  117 +
  118 + }
  119 +
93 120 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractService.java
1 1 package cn.iocoder.yudao.module.crm.service.contract;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractCreateReqVO;
5   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractExportReqVO;
6   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractPageReqVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractUpdateReqVO;
  4 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*;
8 5 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
9 6  
10 7 import javax.validation.Valid;
... ... @@ -72,4 +69,12 @@ public interface ContractService {
72 69 */
73 70 List<ContractDO> getContractList(ContractExportReqVO exportReqVO);
74 71  
  72 + /**
  73 + * 合同转移
  74 + *
  75 + * @param reqVO 请求
  76 + * @param userId 用户编号
  77 + */
  78 + void contractTransfer(CrmContractTransferReqVO reqVO, Long userId);
  79 +
75 80 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImpl.java
... ... @@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.service.contract;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.collection.ListUtil;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractCreateReqVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractExportReqVO;
8   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractPageReqVO;
9   -import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractUpdateReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*;
10 7 import cn.iocoder.yudao.module.crm.convert.contract.ContractConvert;
11 8 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
12 9 import cn.iocoder.yudao.module.crm.dal.mysql.contract.ContractMapper;
  10 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  11 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
13 12 import org.springframework.stereotype.Service;
14 13 import org.springframework.validation.annotation.Validated;
15 14  
... ... @@ -18,7 +17,8 @@ import java.util.Collection;
18 17 import java.util.List;
19 18  
20 19 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
21   -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTRACT_NOT_EXISTS;
  20 +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
  21 +import static cn.iocoder.yudao.module.crm.framework.utils.AuthUtil.isReadAndWrite;
22 22  
23 23 /**
24 24 * 合同 Service 实现类
... ... @@ -32,6 +32,9 @@ public class ContractServiceImpl implements ContractService {
32 32 @Resource
33 33 private ContractMapper contractMapper;
34 34  
  35 + @Resource
  36 + private AdminUserApi adminUserApi;
  37 +
35 38 @Override
36 39 public Long createContract(ContractCreateReqVO createReqVO) {
37 40 // 插入
... ... @@ -58,10 +61,12 @@ public class ContractServiceImpl implements ContractService {
58 61 contractMapper.deleteById(id);
59 62 }
60 63  
61   - private void validateContractExists(Long id) {
62   - if (contractMapper.selectById(id) == null) {
  64 + private ContractDO validateContractExists(Long id) {
  65 + ContractDO contract = contractMapper.selectById(id);
  66 + if (contract == null) {
63 67 throw exception(CONTRACT_NOT_EXISTS);
64 68 }
  69 + return contract;
65 70 }
66 71  
67 72 @Override
... ... @@ -87,4 +92,26 @@ public class ContractServiceImpl implements ContractService {
87 92 return contractMapper.selectList(exportReqVO);
88 93 }
89 94  
  95 + @Override
  96 + public void contractTransfer(CrmContractTransferReqVO reqVO, Long userId) {
  97 + // 1. 校验合同是否存在
  98 + ContractDO contract = validateContractExists(reqVO.getId());
  99 + // 1.2. 校验用户是否拥有读写权限
  100 + if (!isReadAndWrite(contract.getRwUserIds(), userId)) {
  101 + throw exception(CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED);
  102 + }
  103 + // 2. 校验新负责人是否存在
  104 + AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId());
  105 + if (user == null) {
  106 + throw exception(CONTRACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS);
  107 + }
  108 +
  109 + // 3. 更新新的负责人
  110 + ContractDO updateContract = ContractConvert.INSTANCE.convert(contract, reqVO, userId);
  111 + contractMapper.updateById(updateContract);
  112 +
  113 + // 4. TODO 记录合同转移日志
  114 +
  115 + }
  116 +
90 117 }
... ...