!846 fix: 修复 CRM 的一些 bug

Merge pull request !846 from puhui999/develop
This commit is contained in:
芋道源码 2024-01-22 00:45:29 +00:00 committed by Gitee
commit d7f04c94bb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 73 additions and 85 deletions

View File

@ -44,6 +44,11 @@ public class CrmFollowUpRecordRespVO {
@Schema(description = "关联的联系人名称数组")
private List<String> contactNames;
@Schema(description = "图片")
private List<String> picUrls;
@Schema(description = "附件")
private List<String> fileUrls;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -37,8 +37,12 @@ public class CrmFollowUpRecordSaveReqVO {
@Schema(description = "关联的商机编号数组")
private List<Long> businessIds;
@Schema(description = "关联的联系人编号数组")
private List<Long> contactIds;
@Schema(description = "图片")
private List<String> picUrls;
@Schema(description = "附件")
private List<String> fileUrls;
}

View File

@ -28,6 +28,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@ -103,7 +104,12 @@ public class CrmPermissionController {
// 拼接数据
List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId));
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId));
Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream);
Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, item -> {
if (item == null) {
return Stream.empty();
}
return item.stream();
});
Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds);
return success(CrmPermissionConvert.INSTANCE.convert(permission, userList, deptMap, postMap));
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.crm.convert.permission;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO;
@ -49,11 +48,11 @@ public interface CrmPermissionConvert {
findAndThen(userMap, item.getUserId(), user -> {
item.setNickname(user.getNickname());
findAndThen(deptMap, user.getDeptId(), deptRespDTO -> item.setDeptName(deptRespDTO.getName()));
List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds());
if (CollUtil.isEmpty(postRespList)) {
if (user.getPostIds() == null) {
item.setPostNames(Collections.emptySet());
return;
}
List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds());
item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName));
});
return item;

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.crm.dal.dataobject.followup;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import cn.iocoder.yudao.framework.mybatis.core.type.StringListTypeHandler;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
import cn.iocoder.yudao.module.crm.enums.DictTypeConstants;
@ -66,6 +67,18 @@ public class CrmFollowUpRecordDO extends BaseDO {
*/
private LocalDateTime nextTime;
/**
* 图片
*/
@TableField(typeHandler = StringListTypeHandler.class)
private List<String> picUrls;
/**
* 附件
*/
@TableField(typeHandler = StringListTypeHandler.class)
private List<String> fileUrls;
/**
* 关联的商机编号数组
*
@ -81,4 +94,5 @@ public class CrmFollowUpRecordDO extends BaseDO {
@TableField(typeHandler = LongListTypeHandler.class)
private List<Long> contactIds;
}

View File

@ -58,6 +58,7 @@ public interface CrmBusinessMapper extends BaseMapperX<CrmBusinessDO> {
MPJLambdaWrapperX<CrmBusinessDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_BUSINESS.getType(), ids, userId);
query.selectAll(CrmBusinessDO.class).in(CrmBusinessDO::getId, ids).orderByDesc(CrmBusinessDO::getId);
return selectJoinList(CrmBusinessDO.class, query);
}

View File

@ -45,6 +45,7 @@ public interface CrmClueMapper extends BaseMapperX<CrmClueDO> {
MPJLambdaWrapperX<CrmClueDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_LEADS.getType(), ids, userId);
query.selectAll(CrmClueDO.class).in(CrmClueDO::getId, ids).orderByDesc(CrmClueDO::getId);
return selectJoinList(CrmClueDO.class, query);
}

View File

@ -67,6 +67,7 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> {
MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, userId);
query.selectAll(CrmContactDO.class).in(CrmContactDO::getId, ids).orderByDesc(CrmContactDO::getId);
return selectJoinList(CrmContactDO.class, query);
}

View File

@ -54,10 +54,11 @@ public interface CrmContractMapper extends BaseMapperX<CrmContractDO> {
}
default List<CrmContractDO> selectBatchIds(Collection<Long> ids, Long userId) {
MPJLambdaWrapperX<CrmContractDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
MPJLambdaWrapperX<CrmContractDO> query = new MPJLambdaWrapperX<>();
// 构建数据权限连表条件
CrmQueryWrapperUtils.appendPermissionCondition(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, userId);
return selectJoinList(CrmContractDO.class, mpjLambdaWrapperX);
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, userId);
query.selectAll(CrmContractDO.class).in(CrmContractDO::getId, ids).orderByDesc(CrmContractDO::getId);
return selectJoinList(CrmContractDO.class, query);
}
default Long selectCountByContactId(Long contactId) {

View File

@ -64,6 +64,7 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
MPJLambdaWrapperX<CrmCustomerDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CUSTOMER.getType(), ids, userId);
query.selectAll(CrmCustomerDO.class).in(CrmCustomerDO::getId, ids).orderByDesc(CrmCustomerDO::getId);
return selectJoinList(CrmCustomerDO.class, query);
}

View File

@ -53,6 +53,11 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> {
.eq(CrmPermissionDO::getId, id).eq(CrmPermissionDO::getUserId, userId));
}
default CrmPermissionDO selectByBizIdAndUserId(Long id, Long userId) {
return selectOne(new LambdaQueryWrapperX<CrmPermissionDO>()
.eq(CrmPermissionDO::getBizId, id).eq(CrmPermissionDO::getUserId, userId));
}
default int deletePermission(Integer bizType, Long bizId) {
return delete(new LambdaQueryWrapperX<CrmPermissionDO>()
.eq(CrmPermissionDO::getBizType, bizType)

View File

@ -53,6 +53,7 @@ public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> {
MPJLambdaWrapperX<CrmReceivableDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE.getType(), ids, userId);
query.selectAll(CrmReceivableDO.class).in(CrmReceivableDO::getId, ids).orderByDesc(CrmReceivableDO::getId);
return selectJoinList(CrmReceivableDO.class, query);
}

View File

@ -52,6 +52,7 @@ public interface CrmReceivablePlanMapper extends BaseMapperX<CrmReceivablePlanDO
MPJLambdaWrapperX<CrmReceivablePlanDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), ids, userId);
query.selectAll(CrmReceivablePlanDO.class).in(CrmReceivablePlanDO::getId, ids).orderByDesc(CrmReceivablePlanDO::getId);
return selectJoinList(CrmReceivablePlanDO.class, query);
}

View File

@ -66,90 +66,36 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
crmFollowUpRecordMapper.insert(followUpRecord);
LocalDateTime now = LocalDateTime.now();
// TODO @puhui999感觉可以这里基于 type 102 104 这种判断然后每个类型的调用封装一个小方法之后调用这些小方法再之后74-7680-82 也是等价的处理
CrmUpdateFollowUpReqBO updateFollowUpReqBO = new CrmUpdateFollowUpReqBO().setBizId(followUpRecord.getBizId())
.setContactLastTime(now).setContactNextTime(followUpRecord.getNextTime()).setContactLastContent(followUpRecord.getContent());
// 2. 更新 bizId 对应的记录
updateBizTypeFollowUp(followUpRecord, now);
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_BUSINESS.getType(), followUpRecord.getBizType())) { // 更新商机跟进信息
businessService.updateBusinessFollowUpBatch(Collections.singletonList(updateFollowUpReqBO));
}
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_LEADS.getType(), followUpRecord.getBizType())) { // 更新线索跟进信息
clueService.updateClueFollowUp(updateFollowUpReqBO);
}
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CONTACT.getType(), followUpRecord.getBizType())) { // 更新联系人跟进信息
contactService.updateContactFollowUpBatch(Collections.singletonList(updateFollowUpReqBO));
}
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CONTRACT.getType(), followUpRecord.getBizType())) { // 更新合同跟进信息
contractService.updateContractFollowUp(updateFollowUpReqBO);
}
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CUSTOMER.getType(), followUpRecord.getBizType())) { // 更新客户跟进信息
customerService.updateCustomerFollowUp(updateFollowUpReqBO);
}
// 3.1 更新 contactIds 对应的记录
if (CollUtil.isNotEmpty(createReqVO.getContactIds())) {
contactService.updateContactFollowUpBatch(convertList(createReqVO.getContactIds(), contactId ->
new CrmUpdateFollowUpReqBO().setBizId(contactId).setContactNextTime(followUpRecord.getNextTime())
.setContactLastTime(now).setContactLastContent(followUpRecord.getContent())));
contactService.updateContactFollowUpBatch(convertList(createReqVO.getContactIds(), updateFollowUpReqBO::setBizId));
}
// 3.2 需要更新 businessIdscontactIds 对应的记录
if (CollUtil.isNotEmpty(createReqVO.getBusinessIds())) {
businessService.updateBusinessFollowUpBatch(convertList(createReqVO.getBusinessIds(), businessId ->
new CrmUpdateFollowUpReqBO().setBizId(businessId).setContactNextTime(followUpRecord.getNextTime())
.setContactLastTime(now).setContactLastContent(followUpRecord.getContent())));
businessService.updateBusinessFollowUpBatch(convertList(createReqVO.getBusinessIds(), updateFollowUpReqBO::setBizId));
}
return followUpRecord.getId();
}
/**
* 执行更新
*
* @param followUpRecord 跟进记录
* @param now 跟进时间
*/
private void updateBizTypeFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
updateBusinessFollowUp(followUpRecord, now);
updateClueFollowUp(followUpRecord, now);
updateContactFollowUp(followUpRecord, now);
updateContractFollowUp(followUpRecord, now);
updateCustomerFollowUp(followUpRecord, now);
}
private void updateBusinessFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_BUSINESS.getType(), followUpRecord.getBizType())) {
return;
}
// 更新商机跟进信息
businessService.updateBusinessFollowUpBatch(Collections.singletonList(new CrmUpdateFollowUpReqBO()
.setBizId(followUpRecord.getBizId()).setContactNextTime(followUpRecord.getNextTime()).setContactLastTime(now)
.setContactLastContent(followUpRecord.getContent())));
}
private void updateClueFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_LEADS.getType(), followUpRecord.getBizType())) {
return;
}
// 更新线索跟进信息
clueService.updateClueFollowUp(new CrmUpdateFollowUpReqBO().setBizId(followUpRecord.getBizId()).setContactLastTime(now)
.setContactNextTime(followUpRecord.getNextTime()).setContactLastContent(followUpRecord.getContent()));
}
private void updateContactFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CONTACT.getType(), followUpRecord.getBizType())) {
return;
}
// 更新联系人跟进信息
contactService.updateContactFollowUpBatch(Collections.singletonList(new CrmUpdateFollowUpReqBO()
.setBizId(followUpRecord.getBizId()).setContactNextTime(followUpRecord.getNextTime()).setContactLastTime(now)
.setContactLastContent(followUpRecord.getContent())));
}
private void updateContractFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CONTRACT.getType(), followUpRecord.getBizType())) {
return;
}
// 更新合同跟进信息
contractService.updateContractFollowUp(new CrmUpdateFollowUpReqBO().setBizId(followUpRecord.getBizId()).setContactLastTime(now)
.setContactNextTime(followUpRecord.getNextTime()).setContactLastContent(followUpRecord.getContent()));
}
private void updateCustomerFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CUSTOMER.getType(), followUpRecord.getBizType())) {
return;
}
// 更新客户跟进信息
customerService.updateCustomerFollowUp(new CrmUpdateFollowUpReqBO().setBizId(followUpRecord.getBizId()).setContactLastTime(now)
.setContactNextTime(followUpRecord.getNextTime()).setContactLastContent(followUpRecord.getContent()));
}
@Override
public void deleteFollowUpRecord(Long id, Long userId) {
// 校验存在

View File

@ -167,7 +167,10 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
throw exception(CRM_PERMISSION_DELETE_FAIL);
}
// 校验操作人是否为负责人
CrmPermissionDO permission = permissionMapper.selectByIdAndUserId(permissions.get(0).getBizId(), userId);
CrmPermissionDO permission = permissionMapper.selectByBizIdAndUserId(permissions.getFirst().getBizId(), userId);
if (permission == null) {
throw exception(CRM_PERMISSION_DELETE_DENIED);
}
if (!CrmPermissionLevelEnum.isOwner(permission.getLevel())) {
throw exception(CRM_PERMISSION_DELETE_DENIED);
}

View File

@ -84,10 +84,9 @@ public class CrmQueryWrapperUtils {
if (CrmPermissionUtils.isCrmAdmin()) {// 管理员不需要数据权限
return;
}
query.innerJoin(CrmPermissionDO.class, on ->
on.eq(CrmPermissionDO::getBizType, bizType).in(CrmPermissionDO::getBizId, bizIds)
.in(CollUtil.isNotEmpty(bizIds), CrmPermissionDO::getUserId, userId));
.eq(CollUtil.isNotEmpty(bizIds), CrmPermissionDO::getUserId, userId));
}
/**