CRM: TransferReqVO bizId -> id、修复商机转移错误

This commit is contained in:
puhui999 2024-03-09 17:54:14 +08:00
parent 47a698868c
commit af5fbb6ff4
13 changed files with 42 additions and 76 deletions

View File

@ -60,32 +60,17 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
}
// 解析下拉数据
Map<String, Field> excelPropertyFields = getFieldsWithAnnotation(head, ExcelProperty.class);
Map<String, Field> excelColumnSelectFields = getFieldsWithAnnotation(head, ExcelColumnSelect.class);
int colIndex = 0;
for (String fieldName : excelPropertyFields.keySet()) {
Field field = excelColumnSelectFields.get(fieldName);
if (field != null) {
// ExcelProperty 有一个自定义列索引的属性 index 兼容这个字段
int index = field.getAnnotation(ExcelProperty.class).index();
if (index != -1) {
colIndex = index;
for (Field field : head.getDeclaredFields()) {
if (field.isAnnotationPresent(ExcelColumnSelect.class)) {
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
if (excelProperty != null && excelProperty.index() != -1) {
colIndex = excelProperty.index();
}
buildSelectDataList(colIndex, field);
getSelectDataList(colIndex, field);
}
colIndex++;
}
// TODO @puhui999感觉可以 head 循环 field如果有 ExcelColumnSelect 则进行处理 ExcelProperty 可能是非必须的回答主要是用于定位到列索引补充可以看看下面这样写
// for (Field field : head.getDeclaredFields()) {
// if (field.isAnnotationPresent(ExcelColumnSelect.class)) {
// ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
// if (excelProperty != null) {
// colIndex = excelProperty.index();
// }
// getSelectDataList(colIndex, field);
// }
// colIndex++;
// }
}
/**
@ -94,7 +79,7 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
* @param colIndex 列索引
* @param field 字段
*/
private void buildSelectDataList(int colIndex, Field field) {
private void getSelectDataList(int colIndex, Field field) {
ExcelColumnSelect columnSelect = field.getAnnotation(ExcelColumnSelect.class);
String dictType = columnSelect.dictType();
String functionName = columnSelect.functionName();
@ -174,15 +159,4 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
writeSheetHolder.getSheet().addValidationData(validation);
}
public static Map<String, Field> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) {
Map<String, Field> annotatedFields = new LinkedHashMap<>();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(annotationClass)) {
annotatedFields.put(field.getName(), field);
}
}
return annotatedFields;
}
}

View File

@ -13,10 +13,9 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class CrmBusinessTransferReqVO {
// TODO @puhui999这里最好还是用 id 主要还是在 Business 业务里
@Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "商机编号不能为空")
private Long bizId;
private Long id;
/**
* 新负责人的用户编号

View File

@ -12,7 +12,7 @@ public class CrmClueTransferReqVO {
@Schema(description = "线索编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "线索编号不能为空")
private Long bizId;
private Long id;
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")

View File

@ -16,7 +16,7 @@ public class CrmContactTransferReqVO {
@Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "联系人编号不能为空")
private Long bizId;
private Long id;
/**
* 新负责人的用户编号

View File

@ -17,7 +17,7 @@ public class CrmContractTransferReqVO {
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "联系人编号不能为空")
private Long bizId;
private Long id;
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")

View File

@ -13,7 +13,7 @@ public class CrmCustomerTransferReqVO {
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "客户编号不能为空")
private Long bizId;
private Long id;
/**
* 新负责人的用户编号

View File

@ -74,10 +74,7 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> {
}
default List<CrmContactDO> selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) {
// TODO @puhui999父类有 selectList查询 2 个字段的简化方法哈可以用下
return selectList(new LambdaQueryWrapperX<CrmContactDO>()
.eq(CrmContactDO::getCustomerId, customerId)
.eq(CrmContactDO::getOwnerUserId, ownerUserId));
return selectList(CrmContactDO::getCustomerId, customerId, CrmContactDO::getOwnerUserId, ownerUserId);
}
}

View File

@ -8,9 +8,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
/**
* Excel 所属地区列下拉数据源获取接口实现类
*
* // TODO @puhui999类名叫地区下拉框数据源的 {@link ExcelColumnSelectFunction} 实现类这样看起来会更简洁一点哈
* 地区下拉框数据源的 {@link ExcelColumnSelectFunction} 实现类
*
* @author HUIHUI
*/

View File

@ -292,18 +292,18 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
@LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
success = CRM_BUSINESS_TRANSFER_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferBusiness(CrmBusinessTransferReqVO reqVO, Long userId) {
// 1 校验商机是否存在
CrmBusinessDO business = validateBusinessExists(reqVO.getBizId());
CrmBusinessDO business = validateBusinessExists(reqVO.getId());
// 2.1 数据权限转移
permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_BUSINESS.getType(),
reqVO.getBizId(), reqVO.getNewOwnerUserId(), CrmPermissionLevelEnum.OWNER.getLevel()));
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
// 2.2 设置新的负责人
businessMapper.updateOwnerUserIdById(reqVO.getBizId(), reqVO.getNewOwnerUserId());
businessMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
// 记录操作日志上下文
LogRecordContext.putVariable("business", business);

View File

@ -159,18 +159,18 @@ public class CrmClueServiceImpl implements CrmClueService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
@LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
success = CRM_CLUE_TRANSFER_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferClue(CrmClueTransferReqVO reqVO, Long userId) {
// 1 校验线索是否存在
CrmClueDO clue = validateClueExists(reqVO.getBizId());
CrmClueDO clue = validateClueExists(reqVO.getId());
// 2.1 数据权限转移
crmPermissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CLUE.getType(),
reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
// 2.2 设置新的负责人
clueMapper.updateById(new CrmClueDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
clueMapper.updateById(new CrmClueDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
// 3. 记录转移日志
LogRecordContext.putVariable("clue", clue);

View File

@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.crm.service.contact;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusinessReqVO;
@ -18,7 +17,6 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPerm
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerServiceImpl;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
@ -179,18 +177,18 @@ public class CrmContactServiceImpl implements CrmContactService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
@LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
success = CRM_CONTACT_TRANSFER_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferContact(CrmContactTransferReqVO reqVO, Long userId) {
// 1 校验联系人是否存在
CrmContactDO contact = validateContactExists(reqVO.getBizId());
CrmContactDO contact = validateContactExists(reqVO.getId());
// 2.1 数据权限转移
permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CONTACT.getType(),
reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
// 2.2 设置新的负责人
contactMapper.updateById(new CrmContactDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
contactMapper.updateById(new CrmContactDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
// 3. 记录转移日志
LogRecordContext.putVariable("contact", contact);

View File

@ -252,18 +252,18 @@ public class CrmContractServiceImpl implements CrmContractService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
@LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
success = CRM_CONTRACT_TRANSFER_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferContract(CrmContractTransferReqVO reqVO, Long userId) {
// 1. 校验合同是否存在
CrmContractDO contract = validateContractExists(reqVO.getBizId());
CrmContractDO contract = validateContractExists(reqVO.getId());
// 2.1 数据权限转移
crmPermissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CONTRACT.getType(),
reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
// 2.2 设置负责人
contractMapper.updateById(new CrmContractDO().setId(reqVO.getBizId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
contractMapper.updateById(new CrmContractDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
// 3. 记录转移日志
LogRecordContext.putVariable("contract", contract);

View File

@ -199,19 +199,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.bizId}}",
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
success = CRM_CUSTOMER_TRANSFER_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.bizId", level = CrmPermissionLevelEnum.OWNER)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
// 1.1 校验客户是否存在
CrmCustomerDO customer = validateCustomerExists(reqVO.getBizId());
CrmCustomerDO customer = validateCustomerExists(reqVO.getId());
// 1.2 校验拥有客户是否到达上限
validateCustomerExceedOwnerLimit(reqVO.getNewOwnerUserId(), 1);
// 2.1 数据权限转移
permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CUSTOMER.getType(),
reqVO.getBizId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
// 2.2 转移后重新设置负责人
customerMapper.updateById(new CrmCustomerDO().setId(reqVO.getBizId())
customerMapper.updateById(new CrmCustomerDO().setId(reqVO.getId())
.setOwnerUserId(reqVO.getNewOwnerUserId()).setOwnerTime(LocalDateTime.now()));
// 2.3 同时转移
@ -231,21 +231,21 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
*/
private void transfer(CrmCustomerTransferReqVO reqVO, Long userId) {
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTACT.getType())) {
List<CrmContactDO> contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getBizId(), userId);
List<CrmContactDO> contactList = contactService.getContactListByCustomerIdOwnerUserId(reqVO.getId(), userId);
contactList.forEach(item -> {
contactService.transferContact(new CrmContactTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(),
reqVO.getOldOwnerPermissionLevel()), userId);
});
}
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_BUSINESS.getType())) {
List<CrmBusinessDO> businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getBizId(), userId);
List<CrmBusinessDO> businessList = businessService.getBusinessListByCustomerIdOwnerUserId(reqVO.getId(), userId);
businessList.forEach(item -> {
businessService.transferBusiness(new CrmBusinessTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(),
reqVO.getOldOwnerPermissionLevel()), userId);
});
}
if (reqVO.getToBizTypes().contains(CrmBizTypeEnum.CRM_CONTRACT.getType())) {
List<CrmContractDO> contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getBizId(), userId);
List<CrmContractDO> contractList = contractService.getContractListByCustomerIdOwnerUserId(reqVO.getId(), userId);
contractList.forEach(item -> {
contractService.transferContract(new CrmContractTransferReqVO(item.getId(), reqVO.getNewOwnerUserId(),
reqVO.getOldOwnerPermissionLevel()), userId);