code review:crm 客户转移

This commit is contained in:
YunaiV 2023-10-29 18:39:54 +08:00
parent f73b857551
commit 67ac11b56c
17 changed files with 23 additions and 53 deletions

View File

@ -11,7 +11,7 @@ public interface ErrorCodeConstants {
// ========== 合同管理 1-020-000-000 ==========
ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在");
ErrorCode CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_000_001, "合同转移失败,原因:没有转移权限");
ErrorCode CONTRACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_000_001, "合同转移失败,原因:没有转移权限"); // TODO @puhui999这个搞成 合同操作失败原因没有权限
ErrorCode CONTRACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_000_002, "合同转移失败,原因:负责人不存在");
// ========== 线索管理 1-020-001-000 ==========
@ -19,7 +19,7 @@ public interface ErrorCodeConstants {
// ========== 商机管理 1-020-002-000 ==========
ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在");
ErrorCode BUSINESS_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_002_001, "商机转移失败,原因:没有转移权限");
ErrorCode BUSINESS_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_002_001, "商机转移失败,原因:没有转移权限"); // TODO @puhui999这个搞成 商机操作失败原因没有权限
ErrorCode BUSINESS_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_002_002, "商机转移失败,原因:负责人不存在");
// TODO @lilleo商机状态商机类型都单独错误码段
@ -29,7 +29,7 @@ public interface ErrorCodeConstants {
// ========== 联系人管理 1-020-003-000 ==========
ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在");
ErrorCode CONTACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_003_001, "联系人转移失败,原因:没有转移权限");
ErrorCode CONTACT_TRANSFER_FAIL_PERMISSION_DENIED = new ErrorCode(1_020_003_001, "联系人转移失败,原因:没有转移权限"); // TODO @puhui999这个搞成 联系人操作失败原因没有权限
ErrorCode CONTACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS = new ErrorCode(1_020_003_002, "联系人转移失败,原因:负责人不存在");
// TODO @liuhongfeng错误码分段

View File

@ -5,21 +5,12 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Set;
@Schema(description = "管理后台 - 商机创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmBusinessCreateReqVO extends CrmBusinessBaseVO {
@Schema(description = "只读权限的用户编号数组")
private Set<Long> roUserIds;
@Schema(description = "读写权限的用户编号数组")
private Set<Long> rwUserIds;
// TODO @ljileo新建的时候应该可以传递添加的产品
}

View File

@ -15,6 +15,6 @@ public class CrmBusinessTransferReqVO {
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")
private Long ownerUserId; // 新的负责人
private Long ownerUserId;
}

View File

@ -6,7 +6,6 @@ import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.util.Set;
@Schema(description = "管理后台 - 商机更新 Request VO")
@Data
@ -18,13 +17,6 @@ public class CrmBusinessUpdateReqVO extends CrmBusinessBaseVO {
@NotNull(message = "主键不能为空")
private Long id;
@Schema(description = "只读权限的用户编号数组")
private Set<Long> roUserIds;
@Schema(description = "读写权限的用户编号数组")
private Set<Long> rwUserIds;
// TODO @ljileo修改的时候应该可以传递添加的产品
}

View File

@ -5,8 +5,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Set;
@Schema(description = "管理后台 - crm联系人更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ -16,10 +14,4 @@ public class ContactUpdateReqVO extends ContactBaseVO {
@Schema(description = "主键", example = "23210")
private Long id;
@Schema(description = "只读权限的用户编号数组")
private Set<Long> roUserIds;
@Schema(description = "读写权限的用户编号数组")
private Set<Long> rwUserIds;
}

View File

@ -15,6 +15,6 @@ public class CrmContactTransferReqVO {
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")
private Long ownerUserId; // 新的负责人
private Long ownerUserId;
}

View File

@ -95,5 +95,4 @@ public class ContractController {
return success(true);
}
}

View File

@ -5,18 +5,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Set;
@Schema(description = "管理后台 - 合同创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ContractCreateReqVO extends ContractBaseVO {
@Schema(description = "只读权限的用户编号数组")
private Set<Long> roUserIds;
@Schema(description = "读写权限的用户编号数组")
private Set<Long> rwUserIds;
}

View File

@ -6,7 +6,6 @@ import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.util.Set;
@Schema(description = "管理后台 - 合同更新 Request VO")
@Data
@ -18,10 +17,4 @@ public class ContractUpdateReqVO extends ContractBaseVO {
@NotNull(message = "合同编号不能为空")
private Long id;
@Schema(description = "只读权限的用户编号数组")
private Set<Long> roUserIds;
@Schema(description = "读写权限的用户编号数组")
private Set<Long> rwUserIds;
}

View File

@ -15,6 +15,6 @@ public class CrmContractTransferReqVO {
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")
private Long ownerUserId; // 新的负责人
private Long ownerUserId;
}

View File

@ -32,8 +32,10 @@ public interface CrmBusinessConvert {
default CrmBusinessDO convert(CrmBusinessDO business, CrmBusinessTransferReqVO reqVO, Long userId) {
Set<Long> rwUserIds = business.getRwUserIds();
rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人
rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人 TODO puhui999是不是直接 rwUserIds.remove(userId)
// TODO @puhui999ownerUserId 不用添加到进去它就是 ownerUserId 就够因为一共有 3 个角色负责人读写只读
rwUserIds.add(reqVO.getOwnerUserId()); // 读写权限加入新的负人
// TODO @puhui999对原负责人加个类似的处理移除转化为团队成员只读读写
return new CrmBusinessDO().setId(business.getId()).setOwnerUserId(reqVO.getOwnerUserId()) // 设置新负责人
.setRwUserIds(rwUserIds);
}

View File

@ -32,6 +32,7 @@ public interface ContactConvert {
List<ContactExcelVO> convertList02(List<ContactDO> list);
// TODO @puhui999参考 CrmBusinessConvert 的修改建议
default ContactDO convert(ContactDO contact, CrmContactTransferReqVO reqVO, Long userId) {
Set<Long> rwUserIds = contact.getRwUserIds();
rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人

View File

@ -32,6 +32,7 @@ public interface ContractConvert {
List<ContractExcelVO> convertList02(List<ContractDO> list);
// TODO @puhui999参考 CrmBusinessConvert 的修改建议
default ContractDO convert(ContractDO contract, CrmContractTransferReqVO reqVO, Long userId) {
Set<Long> rwUserIds = contract.getRwUserIds();
rwUserIds.removeIf(item -> ObjUtil.equal(item, userId)); // 移除老负责人

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.crm.framework.utils;
import java.util.Collection;
// TODO @puhui999改成 CrmPermissionUtils
/**
* 数据读写权限校验工具类
*
@ -9,6 +10,8 @@ import java.util.Collection;
*/
public class AuthUtil {
// TODO @puhui999负责人是单独的字段哈
// TODO @puhui999额外校验如果是管理员可以查看所有看着要做成有状态的了可能要搞个 CrmPermissionService
/**
* 判断当前数据对用户来说是否是只读的
*
@ -17,6 +20,7 @@ public class AuthUtil {
* @return boolean /
*/
public static boolean isReadOnly(Collection<Long> roUserIds, Long userId) {
// TODO @puhui999从代码角度来说最好使用 CollUtil.contains
return roUserIds.contains(userId);
}

View File

@ -92,26 +92,27 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
return businessMapper.selectList(exportReqVO);
}
// TODO @puhui999动名词哈transferBusiness
@Override
public void businessTransfer(CrmBusinessTransferReqVO reqVO, Long userId) {
// 1. 校验商机是否存在
// 1.1 校验商机是否存在
CrmBusinessDO business = validateBusinessExists(reqVO.getId());
// 1.2. 校验用户是否拥有读写权限
// 1.2 校验用户是否拥有读写权限
if (!isReadAndWrite(business.getRwUserIds(), userId)) {
throw exception(BUSINESS_TRANSFER_FAIL_PERMISSION_DENIED);
}
// 2. 校验新负责人是否存在
// TODO @puhui999如果已经是该负责人抛个业务异常
// 1.3 校验新负责人是否存在
AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId());
if (user == null) {
throw exception(BUSINESS_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS);
}
// 3. 更新新的负责人
// 2. 更新新的负责人
CrmBusinessDO updateBusiness = CrmBusinessConvert.INSTANCE.convert(business, reqVO, userId);
businessMapper.updateById(updateBusiness);
// 4. TODO 记录商机转移日志
}
}

View File

@ -95,6 +95,7 @@ public class ContactServiceImpl implements ContactService {
return contactMapper.selectList(exportReqVO);
}
// TODO @puhui999参考 CrmBusinessServiceImpl 修改建议
@Override
public void contactTransfer(CrmContactTransferReqVO reqVO, Long userId) {
// 1. 校验联系人是否存在

View File

@ -92,6 +92,7 @@ public class ContractServiceImpl implements ContractService {
return contractMapper.selectList(exportReqVO);
}
// TODO @puhui999参考 CrmBusinessServiceImpl 修改建议
@Override
public void contractTransfer(CrmContractTransferReqVO reqVO, Long userId) {
// 1. 校验合同是否存在