完善 review 提到的问题

This commit is contained in:
puhui999 2023-11-01 10:21:56 +08:00
parent a385a37c4a
commit 91dd61edc0
28 changed files with 164 additions and 106 deletions

View File

@ -91,9 +91,10 @@ public class CrmBusinessController {
@PutMapping("/transfer") @PutMapping("/transfer")
@Operation(summary = "商机转移") @Operation(summary = "商机转移")
@PreAuthorize("@ss.hasPermission('crm:business:update')") @PreAuthorize("@ss.hasPermission('crm:business:update')")
public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferBusinessReqVO reqVO) { public CommonResult<Boolean> transfer(@Valid @RequestBody CrmBusinessTransferReqVO reqVO) {
businessService.transferBusiness(reqVO, getLoginUserId()); businessService.transferBusiness(reqVO, getLoginUserId());
return success(true); return success(true);
} }
} }

View File

@ -8,7 +8,7 @@ import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 商机转移 Request VO") @Schema(description = "管理后台 - 商机转移 Request VO")
@Data @Data
public class CrmTransferBusinessReqVO { public class CrmBusinessTransferReqVO {
@Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "联系人编号不能为空") @NotNull(message = "联系人编号不能为空")
@ -18,7 +18,7 @@ public class CrmTransferBusinessReqVO {
* 新负责人的用户编号 * 新负责人的用户编号
*/ */
@NotNull(message = "新负责人的用户编号不能为空") @NotNull(message = "新负责人的用户编号不能为空")
@Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430") @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
private Long newOwnerUserId; private Long newOwnerUserId;
/** /**

View File

@ -100,7 +100,7 @@ public class ContactController {
@PutMapping("/transfer") @PutMapping("/transfer")
@Operation(summary = "联系人转移") @Operation(summary = "联系人转移")
@PreAuthorize("@ss.hasPermission('crm:contact:update')") @PreAuthorize("@ss.hasPermission('crm:contact:update')")
public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferContactReqVO reqVO) { public CommonResult<Boolean> transfer(@Valid @RequestBody CrmContactTransferReqVO reqVO) {
contactService.transferContact(reqVO, getLoginUserId()); contactService.transferContact(reqVO, getLoginUserId());
return success(true); return success(true);
} }

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - CRM 联系人转移 Request VO")
@Data
public class CrmContactTransferReqVO {
@Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "联系人编号不能为空")
private Long id;
/**
* 新负责人的用户编号
*/
@NotNull(message = "新负责人的用户编号不能为空")
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
private Long newOwnerUserId;
/**
* 老负责人是否加入团队/
*/
@Schema(description = "老负责人是否加入团队", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
@NotNull(message = "老负责人是否加入团队不能为空")
private Boolean joinTeam;
/**
* 老负责人加入团队后的权限级别如果 {@link #joinTeam} false, permissionLevel null
* 关联 {@link CrmPermissionLevelEnum}
*/
@Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer permissionLevel;
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - CRM 联系人转移 Request VO")
@Data
public class CrmTransferContactReqVO {
@Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "联系人编号不能为空")
private Long id;
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")
private Long ownerUserId;
@Schema(description = "原负责人移除方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "原负责人移除方式不能为空")
private Integer transferType;
@Schema(description = "权限类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "权限类型不能为空")
private Integer permissionType;
}

View File

@ -90,7 +90,7 @@ public class ContractController {
@PutMapping("/transfer") @PutMapping("/transfer")
@Operation(summary = "合同转移") @Operation(summary = "合同转移")
@PreAuthorize("@ss.hasPermission('crm:contract:update')") @PreAuthorize("@ss.hasPermission('crm:contract:update')")
public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferContractReqVO reqVO) { public CommonResult<Boolean> transfer(@Valid @RequestBody CrmContractTransferReqVO reqVO) {
contractService.transferContract(reqVO, getLoginUserId()); contractService.transferContract(reqVO, getLoginUserId());
return success(true); return success(true);
} }

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.crm.controller.admin.contract.vo;
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - CRM 合同转移 Request VO")
@Data
public class CrmContractTransferReqVO {
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "联系人编号不能为空")
private Long id;
/**
* 新负责人的用户编号
*/
@NotNull(message = "新负责人的用户编号不能为空")
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
private Long newOwnerUserId;
/**
* 老负责人是否加入团队/
*/
@Schema(description = "老负责人是否加入团队", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
@NotNull(message = "老负责人是否加入团队不能为空")
private Boolean joinTeam;
/**
* 老负责人加入团队后的权限级别如果 {@link #joinTeam} false, permissionLevel null
* 关联 {@link CrmPermissionLevelEnum}
*/
@Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer permissionLevel;
}

View File

@ -1,29 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.contract.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
// TODO @puhui999CrmContractTransferReqVO模块名字要放前面看看还有没其它类似的
@Schema(description = "管理后台 - CRM 合同转移 Request VO")
@Data
public class CrmTransferContractReqVO {
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "合同编号不能为空")
private Long id;
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")
private Long ownerUserId;
@Schema(description = "原负责人移除方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "原负责人移除方式不能为空")
private Integer transferType;
@Schema(description = "权限类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "权限类型不能为空")
private Integer permissionType;
}

View File

@ -90,7 +90,7 @@ public class CrmCustomerController {
@PutMapping("/transfer") @PutMapping("/transfer")
@Operation(summary = "客户转移") @Operation(summary = "客户转移")
@PreAuthorize("@ss.hasPermission('crm:customer:update')") @PreAuthorize("@ss.hasPermission('crm:customer:update')")
public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferCustomerReqVO reqVO) { public CommonResult<Boolean> transfer(@Valid @RequestBody CrmCustomerTransferReqVO reqVO) {
customerService.transferCustomer(reqVO, getLoginUserId()); customerService.transferCustomer(reqVO, getLoginUserId());
return success(true); return success(true);
} }

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - CRM 客户转移 Request VO")
@Data
public class CrmCustomerTransferReqVO {
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "联系人编号不能为空")
private Long id;
/**
* 新负责人的用户编号
*/
@NotNull(message = "新负责人的用户编号不能为空")
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
private Long newOwnerUserId;
/**
* 老负责人是否加入团队/
*/
@Schema(description = "老负责人是否加入团队", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
@NotNull(message = "老负责人是否加入团队不能为空")
private Boolean joinTeam;
/**
* 老负责人加入团队后的权限级别如果 {@link #joinTeam} false, permissionLevel null
* 关联 {@link CrmPermissionLevelEnum}
*/
@Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer permissionLevel;
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - CRM 客户转移 Request VO")
@Data
public class CrmTransferCustomerReqVO {
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "客户编号不能为空")
private Long id;
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")
private Long ownerUserId;
@Schema(description = "原负责人移除方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "原负责人移除方式不能为空")
private Integer transferType;
@Schema(description = "权限类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "权限类型不能为空")
private Integer permissionType;
}

View File

@ -35,6 +35,6 @@ public interface CrmBusinessConvert {
@Mapping(target = "bizId", source = "reqVO.id"), @Mapping(target = "bizId", source = "reqVO.id"),
@Mapping(target = "newOwnerUserId", source = "reqVO.id") @Mapping(target = "newOwnerUserId", source = "reqVO.id")
}) })
CrmTransferPermissionReqBO convert(CrmTransferBusinessReqVO reqVO, Long userId); CrmTransferPermissionReqBO convert(CrmBusinessTransferReqVO reqVO, Long userId);
} }

View File

@ -37,6 +37,6 @@ public interface ContactConvert {
@Mapping(target = "bizId", source = "reqVO.id"), @Mapping(target = "bizId", source = "reqVO.id"),
@Mapping(target = "newOwnerUserId", source = "reqVO.id") @Mapping(target = "newOwnerUserId", source = "reqVO.id")
}) })
CrmTransferPermissionReqBO convert(CrmTransferContactReqVO reqVO, Long userId); CrmTransferPermissionReqBO convert(CrmContactTransferReqVO reqVO, Long userId);
} }

View File

@ -37,6 +37,6 @@ public interface ContractConvert {
@Mapping(target = "bizId", source = "reqVO.id"), @Mapping(target = "bizId", source = "reqVO.id"),
@Mapping(target = "newOwnerUserId", source = "reqVO.id") @Mapping(target = "newOwnerUserId", source = "reqVO.id")
}) })
CrmTransferPermissionReqBO convert(CrmTransferContractReqVO reqVO, Long userId); CrmTransferPermissionReqBO convert(CrmContractTransferReqVO reqVO, Long userId);
} }

View File

@ -35,6 +35,6 @@ public interface CrmCustomerConvert {
@Mapping(target = "bizId", source = "reqVO.id"), @Mapping(target = "bizId", source = "reqVO.id"),
@Mapping(target = "newOwnerUserId", source = "reqVO.id") @Mapping(target = "newOwnerUserId", source = "reqVO.id")
}) })
CrmTransferPermissionReqBO convert(CrmTransferCustomerReqVO reqVO, Long userId); CrmTransferPermissionReqBO convert(CrmCustomerTransferReqVO reqVO, Long userId);
} }

View File

@ -42,6 +42,8 @@ public class CrmPermissionDO extends BaseDO {
private Long userId; private Long userId;
/** /**
* 权限级别关联 {@link CrmPermissionLevelEnum} * 权限级别关联 {@link CrmPermissionLevelEnum}
* 如果为公海数据的话会干掉此数据的负责人领取人则上位负责人
* 客户放入公海后会干掉团队成员中的负责人而其他团队成员则不受影响
*/ */
private Integer permissionLevel; private Integer permissionLevel;

View File

@ -44,4 +44,17 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> {
.eq(CrmPermissionDO::getBizId, bizId)); .eq(CrmPermissionDO::getBizId, bizId));
} }
/**
* 获取数据权限列表通过 数据类型 x 用户编号如果
*
* @param bizType 数据类型关联 {@link CrmBizTypeEnum}
* @param userId
* @return Crm 数据权限列表
*/
default List<CrmPermissionDO> selectByBizTypeAndUserId(Integer bizType, Long userId) {
return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
.eq(CrmPermissionDO::getBizType, bizType)
.eq(CrmPermissionDO::getUserId, userId));
}
} }

View File

@ -80,8 +80,8 @@ public class CrmPermissionAspect {
return; return;
} }
if (isRead(permissionLevel)) { // 读权限 if (isRead(permissionLevel)) { // 读权限
// 如果没有数据权限或没有负责人则表示此记录为公海数据所有人都有只读权限 // 如果没有数据权限或没有负责人则表示此记录为公海数据所有人都有只读权限可以领取成为负责人团队成员领取的
if (!CollUtil.anyMatch(bizPermissions, item -> isOwner(item.getPermissionLevel()))) { if (CollUtil.isEmpty(bizPermissions) || !CollUtil.anyMatch(bizPermissions, item -> isOwner(item.getPermissionLevel()))) {
return; return;
} }
if (isRead(userPermission.getPermissionLevel())) { // 校验当前用户是否有读权限 if (isRead(userPermission.getPermissionLevel())) { // 校验当前用户是否有读权限

View File

@ -76,6 +76,6 @@ public interface CrmBusinessService {
* @param reqVO 请求 * @param reqVO 请求
* @param userId 用户编号 * @param userId 用户编号
*/ */
void transferBusiness(CrmTransferBusinessReqVO reqVO, Long userId); void transferBusiness(CrmBusinessTransferReqVO reqVO, Long userId);
} }

View File

@ -109,7 +109,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void transferBusiness(CrmTransferBusinessReqVO reqVO, Long userId) { public void transferBusiness(CrmBusinessTransferReqVO reqVO, Long userId) {
// 1 校验商机是否存在 // 1 校验商机是否存在
validateBusinessExists(reqVO.getId()); validateBusinessExists(reqVO.getId());

View File

@ -76,6 +76,6 @@ public interface ContactService {
* @param reqVO 请求 * @param reqVO 请求
* @param userId 用户编号 * @param userId 用户编号
*/ */
void transferContact(CrmTransferContactReqVO reqVO, Long userId); void transferContact(CrmContactTransferReqVO reqVO, Long userId);
} }

View File

@ -110,7 +110,7 @@ public class ContactServiceImpl implements ContactService {
} }
@Override @Override
public void transferContact(CrmTransferContactReqVO reqVO, Long userId) { public void transferContact(CrmContactTransferReqVO reqVO, Long userId) {
// 1 校验联系人是否存在 // 1 校验联系人是否存在
validateContactExists(reqVO.getId()); validateContactExists(reqVO.getId());

View File

@ -76,6 +76,6 @@ public interface ContractService {
* @param reqVO 请求 * @param reqVO 请求
* @param userId 用户编号 * @param userId 用户编号
*/ */
void transferContract(CrmTransferContractReqVO reqVO, Long userId); void transferContract(CrmContractTransferReqVO reqVO, Long userId);
} }

View File

@ -108,7 +108,7 @@ public class ContractServiceImpl implements ContractService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void transferContract(CrmTransferContractReqVO reqVO, Long userId) { public void transferContract(CrmContractTransferReqVO reqVO, Long userId) {
// 1 校验合同是否存在 // 1 校验合同是否存在
validateContractExists(reqVO.getId()); validateContractExists(reqVO.getId());

View File

@ -84,6 +84,6 @@ public interface CrmCustomerService {
* @param reqVO 请求 * @param reqVO 请求
* @param userId 用户编号 * @param userId 用户编号
*/ */
void transferCustomer(CrmTransferCustomerReqVO reqVO, Long userId); void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId);
} }

View File

@ -131,7 +131,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void transferCustomer(CrmTransferCustomerReqVO reqVO, Long userId) { public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
// 1. 校验合同是否存在 // 1. 校验合同是否存在
validateCustomer(reqVO.getId()); validateCustomer(reqVO.getId());

View File

@ -17,7 +17,6 @@ import java.util.List;
*/ */
public interface CrmPermissionService { public interface CrmPermissionService {
// TODO @puhui999方法名上不用 Crm
/** /**
* 创建数据权限 * 创建数据权限
* *
@ -59,6 +58,15 @@ public interface CrmPermissionService {
*/ */
List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId); List<CrmPermissionDO> getPermissionByBizTypeAndBizId(Integer bizType, Long bizId);
/**
* 获取数据权限列表通过 数据类型 x 用户编号
*
* @param bizType 数据类型关联 {@link CrmBizTypeEnum}
* @param userId 用户编号
* @return Crm 数据权限列表
*/
List<CrmPermissionDO> getPermissionByBizTypeAndUserId(Integer bizType, Long userId);
/** /**
* 数据权限转移 * 数据权限转移
* *

View File

@ -73,6 +73,11 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId); return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId);
} }
@Override
public List<CrmPermissionDO> getPermissionByBizTypeAndUserId(Integer bizType, Long userId) {
return crmPermissionMapper.selectByBizTypeAndUserId(bizType, userId);
}
private void validateCrmPermissionExists(Long id) { private void validateCrmPermissionExists(Long id) {
if (crmPermissionMapper.selectById(id) == null) { if (crmPermissionMapper.selectById(id) == null) {
throw exception(CRM_PERMISSION_NOT_EXISTS); throw exception(CRM_PERMISSION_NOT_EXISTS);