CRM: 完善跟进日志 TODO

This commit is contained in:
puhui999 2024-01-23 22:31:51 +08:00
parent 7bb171512a
commit 6850c7c71d
11 changed files with 178 additions and 75 deletions

View File

@ -2,14 +2,14 @@ package cn.iocoder.yudao.module.crm.controller.admin.operatelog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.operatelog.vo.CrmOperateLogPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.operatelog.vo.CrmOperateLogPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.operatelog.vo.CrmOperateLogV2RespVO;
import cn.iocoder.yudao.module.crm.enums.LogRecordConstants; import cn.iocoder.yudao.module.crm.enums.LogRecordConstants;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.system.api.logger.OperateLogApi; import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO; import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2RespDTO;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@ -51,16 +51,14 @@ public class CrmOperateLogController {
BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), CRM_RECEIVABLE_PLAN_TYPE); BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), CRM_RECEIVABLE_PLAN_TYPE);
} }
// TODO @puhui999还是搞个 VO 出来哈
@GetMapping("/page") @GetMapping("/page")
@Operation(summary = "获得操作日志") @Operation(summary = "获得操作日志")
@Parameter(name = "id", description = "客户编号", required = true) @PreAuthorize("@ss.hasPermission('crm:operate-log:query')")
@PreAuthorize("@ss.hasPermission('crm:customer:query')") public CommonResult<PageResult<CrmOperateLogV2RespVO>> getCustomerOperateLog(@Valid CrmOperateLogPageReqVO pageReqVO) {
public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(@Valid CrmOperateLogPageReqVO pageReqVO) {
OperateLogV2PageReqDTO reqDTO = new OperateLogV2PageReqDTO(); OperateLogV2PageReqDTO reqDTO = new OperateLogV2PageReqDTO();
reqDTO.setPageSize(PAGE_SIZE_NONE); // 默认不分页需要分页需注释 reqDTO.setPageSize(PAGE_SIZE_NONE); // 默认不分页需要分页需注释
reqDTO.setBizType(BIZ_TYPE_MAP.get(pageReqVO.getBizType())).setBizId(pageReqVO.getBizId()); reqDTO.setBizType(BIZ_TYPE_MAP.get(pageReqVO.getBizType())).setBizId(pageReqVO.getBizId());
return success(operateLogApi.getOperateLogPage(reqDTO)); return success(BeanUtils.toBean(operateLogApi.getOperateLogPage(reqDTO), CrmOperateLogV2RespVO.class));
} }
} }

View File

@ -0,0 +1,89 @@
package cn.iocoder.yudao.module.crm.controller.admin.operatelog.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - CRM 跟进 Response VO")
@Data
@ExcelIgnoreUnannotated
public class CrmOperateLogV2RespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private Long id;
/**
* 链路追踪编号
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private String traceId;
/**
* 用户编号
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long userId;
/**
* 用户名称
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
private String userName;
/**
* 用户类型
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer userType;
/**
* 操作模块类型
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private String type;
/**
* 操作名
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "修改客户")
private String subType;
/**
* 操作模块业务编号
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private Long bizId;
/**
* 操作内容
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "将什么从什么改为了什么")
private String action;
/**
* 拓展字段
*/
@Schema(description = "编号", example = "{orderId: 1}")
private String extra;
/**
* 请求方法名
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private String requestMethod;
/**
* 请求地址
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private String requestUrl;
/**
* 用户 IP
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private String userIp;
/**
* 浏览器 UA
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private String userAgent;
/**
* 创建时间
*/
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-01-01")
private LocalDateTime createTime;
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.crm.convert.permission;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionRespVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
@ -29,13 +30,10 @@ public interface CrmPermissionConvert {
CrmPermissionConvert INSTANCE = Mappers.getMapper(CrmPermissionConvert.class); CrmPermissionConvert INSTANCE = Mappers.getMapper(CrmPermissionConvert.class);
// TODO @puhui999这个要不也搞到 copy default List<CrmPermissionRespVO> convert(List<CrmPermissionDO> permissions, List<AdminUserRespDTO> userList,
List<CrmPermissionRespVO> convert(List<CrmPermissionDO> permission);
default List<CrmPermissionRespVO> convert(List<CrmPermissionDO> permission, List<AdminUserRespDTO> userList,
Map<Long, DeptRespDTO> deptMap, Map<Long, PostRespDTO> postMap) { Map<Long, DeptRespDTO> deptMap, Map<Long, PostRespDTO> postMap) {
Map<Long, AdminUserRespDTO> userMap = CollectionUtils.convertMap(userList, AdminUserRespDTO::getId); Map<Long, AdminUserRespDTO> userMap = CollectionUtils.convertMap(userList, AdminUserRespDTO::getId);
return CollectionUtils.convertList(convert(permission), item -> { return CollectionUtils.convertList(BeanUtils.toBean(permissions, CrmPermissionRespVO.class), item -> {
findAndThen(userMap, item.getUserId(), user -> { findAndThen(userMap, item.getUserId(), user -> {
item.setNickname(user.getNickname()); item.setNickname(user.getNickname());
findAndThen(deptMap, user.getDeptId(), deptRespDTO -> item.setDeptName(deptRespDTO.getName())); findAndThen(deptMap, user.getDeptId(), deptRespDTO -> item.setDeptName(deptRespDTO.getName()));

View File

@ -114,10 +114,15 @@ public class CrmCustomerDO extends BaseDO {
*/ */
private String detailAddress; private String detailAddress;
/**
* 最后接收时间
*/
private LocalDateTime receiveTime;
/** /**
* 最后跟进时间 * 最后跟进时间
*/ */
private LocalDateTime contactLastTime; private LocalDateTime contactLastTime;
/** /**
* 最后跟进内容 * 最后跟进内容
*/ */

View File

@ -1,9 +1,17 @@
package cn.iocoder.yudao.module.crm.framework.permission.core.util; package cn.iocoder.yudao.module.crm.framework.permission.core.util;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionRoleCodeEnum; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionRoleCodeEnum;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi; import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
/** /**
@ -22,6 +30,21 @@ public class CrmPermissionUtils {
return SingletonManager.getPermissionApi().hasAnyRoles(getLoginUserId(), CrmPermissionRoleCodeEnum.CRM_ADMIN.getCode()); return SingletonManager.getPermissionApi().hasAnyRoles(getLoginUserId(), CrmPermissionRoleCodeEnum.CRM_ADMIN.getCode());
} }
/**
* 校验权限
*
* @param bizType 数据类型关联 {@link CrmBizTypeEnum}
* @param bizId 数据编号关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
* @param userId 用户编号
* @param levelEnum 权限级别
* @return boolean
*/
public static boolean hasPermission(Integer bizType, Long bizId, Long userId, CrmPermissionLevelEnum levelEnum) {
List<CrmPermissionDO> permissionList = SingletonManager.getCrmPermissionService().getPermissionListByBiz(bizType, bizId);
return anyMatch(permissionList, permission ->
ObjUtil.equal(permission.getUserId(), userId) && ObjUtil.equal(permission.getLevel(), levelEnum.getLevel()));
}
/** /**
* 静态内部类实现单例获取 * 静态内部类实现单例获取
* *
@ -30,11 +53,16 @@ public class CrmPermissionUtils {
private static class SingletonManager { private static class SingletonManager {
private static final PermissionApi PERMISSION_API = SpringUtil.getBean(PermissionApi.class); private static final PermissionApi PERMISSION_API = SpringUtil.getBean(PermissionApi.class);
private static final CrmPermissionService CRM_PERMISSION_SERVICE = SpringUtil.getBean(CrmPermissionService.class);
public static PermissionApi getPermissionApi() { public static PermissionApi getPermissionApi() {
return PERMISSION_API; return PERMISSION_API;
} }
public static CrmPermissionService getCrmPermissionService() {
return CRM_PERMISSION_SERVICE;
}
} }
} }

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.crm.service.clue;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -15,7 +14,6 @@ import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransformReqV
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert; import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO; import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper; import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
@ -193,46 +191,39 @@ public class CrmClueServiceImpl implements CrmClueService {
} }
// 2. 遍历线索(未转化的线索)创建对应的客户 // 2. 遍历线索(未转化的线索)创建对应的客户
// TODO @puhui999这里不用过滤了 clues.forEach(clue -> {
List<CrmClueDO> translateClues = filterList(clues, clue -> ObjUtil.equal(Boolean.FALSE, clue.getTransformStatus())); Long customerId = customerService.createCustomer(BeanUtils.toBean(clue, CrmCustomerCreateReqBO.class), userId);
List<CrmCustomerDO> customers = customerService.createCustomerBatch(convertList(translateClues, clue -> clue.setCustomerId(customerId);
BeanUtils.toBean(clue, CrmCustomerCreateReqBO.class)), userId); });
// TODO @puhui999这里不用搞一个 clueCustomerIdMap 出来可以考虑逐个创建然后把 customerId 设置回 CrmClueDO避免 name 匹配极端会有问题哈
// TODO 是不是就直接 foreach 处理好了因为本身量不大for 处理性能 ok可阅读性好
Map<Long, Long> clueCustomerIdMap = new HashMap<>(translateClues.size());
// 2.1 更新线索 // 2.1 更新线索
clueMapper.updateBatch(convertList(customers, customer -> { clueMapper.updateBatch(convertList(clues, clue -> new CrmClueDO().setId(clue.getId()).setTransformStatus(Boolean.TRUE)
CrmClueDO firstClue = findFirst(translateClues, clue -> ObjUtil.equal(clue.getName(), customer.getName())); .setCustomerId(clue.getCustomerId())));
clueCustomerIdMap.put(firstClue.getId(), customer.getId());
return new CrmClueDO().setId(firstClue.getId()).setTransformStatus(Boolean.TRUE).setCustomerId(customer.getId());
}));
// 2.3 复制跟进 // 2.3 复制跟进
updateFollowUpRecords(clueCustomerIdMap); updateFollowUpRecords(clues);
// 3. 记录操作日志 // 3. 记录操作日志
for (CrmClueDO clue : translateClues) { for (CrmClueDO clue : clues) {
// TODO @puhui999这里优化下translate 操作日志 getSelf().translateCustomerLog(clue);
getSelf().receiveClueLog(clue);
} }
} }
private void updateFollowUpRecords(Map<Long, Long> clueCustomerIdMap) { private void updateFollowUpRecords(List<CrmClueDO> clues) {
List<CrmFollowUpRecordDO> followUpRecords = followUpRecordService.getFollowUpRecordByBiz( List<CrmFollowUpRecordDO> followUpRecords = followUpRecordService.getFollowUpRecordByBiz(
CrmBizTypeEnum.CRM_LEADS.getType(), clueCustomerIdMap.keySet()); CrmBizTypeEnum.CRM_LEADS.getType(), convertSet(clues, CrmClueDO::getId));
if (CollUtil.isEmpty(followUpRecords)) { if (CollUtil.isEmpty(followUpRecords)) {
return; return;
} }
Map<Long, CrmClueDO> clueMap = convertMap(clues, CrmClueDO::getId);
// 创建跟进 // 创建跟进
followUpRecordService.createFollowUpRecordBatch(convertList(followUpRecords, followUpRecord -> followUpRecordService.createFollowUpRecordBatch(convertList(followUpRecords, followUpRecord ->
BeanUtils.toBean(followUpRecord, CrmFollowUpCreateReqBO.class).setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()) BeanUtils.toBean(followUpRecord, CrmFollowUpCreateReqBO.class).setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
.setBizId(clueCustomerIdMap.get(followUpRecord.getBizId())))); .setBizId(clueMap.get(followUpRecord.getBizId()).getCustomerId())));
} }
@LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_TRANSLATE_SUB_TYPE, bizNo = "{{#clue.id}}", @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_TRANSLATE_SUB_TYPE, bizNo = "{{#clue.id}}",
success = CRM_LEADS_TRANSLATE_SUCCESS) success = CRM_LEADS_TRANSLATE_SUCCESS)
public void receiveClueLog(CrmClueDO clue) { public void translateCustomerLog(CrmClueDO clue) {
// 记录操作日志上下文 // 记录操作日志上下文
LogRecordContext.putVariable("clue", clue); LogRecordContext.putVariable("clue", clue);
} }

View File

@ -6,6 +6,9 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
import cn.iocoder.yudao.module.crm.dal.mysql.contactbusinesslink.CrmContactBusinessMapper; import cn.iocoder.yudao.module.crm.dal.mysql.contactbusinesslink.CrmContactBusinessMapper;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission;
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -19,7 +22,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS;
// TODO @puhui999数据权限的校验每个操作
/** /**
* 联系人与商机的关联 Service 实现类 * 联系人与商机的关联 Service 实现类
* *
@ -40,6 +42,7 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService
private CrmContactService contactService; private CrmContactService contactService;
@Override @Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#createReqVO.contactId", level = CrmPermissionLevelEnum.WRITE)
public void createContactBusinessList(CrmContactBusinessReqVO createReqVO) { public void createContactBusinessList(CrmContactBusinessReqVO createReqVO) {
CrmContactDO contact = contactService.getContact(createReqVO.getContactId()); CrmContactDO contact = contactService.getContact(createReqVO.getContactId());
if (contact == null) { if (contact == null) {
@ -65,6 +68,7 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService
} }
@Override @Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#deleteReqVO.contactId", level = CrmPermissionLevelEnum.WRITE)
public void deleteContactBusinessList(CrmContactBusinessReqVO deleteReqVO) { public void deleteContactBusinessList(CrmContactBusinessReqVO deleteReqVO) {
CrmContactDO contact = contactService.getContact(deleteReqVO.getContactId()); CrmContactDO contact = contactService.getContact(deleteReqVO.getContactId());
if (contact == null) { if (contact == null) {
@ -76,11 +80,13 @@ public class CrmContactBusinessServiceImpl implements CrmContactBusinessService
} }
@Override @Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#contactId", level = CrmPermissionLevelEnum.WRITE)
public void deleteContactBusinessByContactId(Long contactId) { public void deleteContactBusinessByContactId(Long contactId) {
contactBusinessMapper.delete(CrmContactBusinessDO::getContactId, contactId); contactBusinessMapper.delete(CrmContactBusinessDO::getContactId, contactId);
} }
@Override @Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#contactId", level = CrmPermissionLevelEnum.READ)
public List<CrmContactBusinessDO> getContactBusinessListByContactId(Long contactId) { public List<CrmContactBusinessDO> getContactBusinessListByContactId(Long contactId) {
return contactBusinessMapper.selectListByContactId(contactId); return contactBusinessMapper.selectListByContactId(contactId);
} }

View File

@ -100,13 +100,13 @@ public interface CrmCustomerService {
void updateCustomerFollowUp(CrmUpdateFollowUpReqBO customerUpdateFollowUpReqBO); void updateCustomerFollowUp(CrmUpdateFollowUpReqBO customerUpdateFollowUpReqBO);
/** /**
* 批量创建客户 * 创建客户
* *
* @param customerCreateReqBOs 请求 * @param customerCreateReq 请求信息
* @param userId 用户编号 * @param userId 用户编号
* @return 客户列表 * @return 客户列表
*/ */
List<CrmCustomerDO> createCustomerBatch(List<CrmCustomerCreateReqBO> customerCreateReqBOs, Long userId); Long createCustomer(CrmCustomerCreateReqBO customerCreateReq, Long userId);
// ==================== 公海相关操作 ==================== // ==================== 公海相关操作 ====================

View File

@ -43,12 +43,10 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT; import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_OWNER_LIMIT; import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_OWNER_LIMIT;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
/** /**
@ -91,9 +89,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
// 2. 插入客户 // 2. 插入客户
CrmCustomerDO customer = BeanUtils.toBean(createReqVO, CrmCustomerDO.class) CrmCustomerDO customer = BeanUtils.toBean(createReqVO, CrmCustomerDO.class)
.setLockStatus(false).setDealStatus(false) .setLockStatus(false).setDealStatus(false).setContactLastTime(LocalDateTime.now());
.setContactLastTime(LocalDateTime.now());
// TODO @puhui999可能要加个 receiveTime 字段记录最后接收时间
customerMapper.insert(customer); customerMapper.insert(customer);
// 3. 创建数据权限 // 3. 创建数据权限
@ -214,21 +210,21 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<CrmCustomerDO> createCustomerBatch(List<CrmCustomerCreateReqBO> customerCreateReqBOs, Long userId) { @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_CREATE_SUB_TYPE, bizNo = "{{#customer.id}}",
if (CollUtil.isEmpty(customerCreateReqBOs)) { success = CRM_CUSTOMER_CREATE_SUCCESS)
return emptyList(); public Long createCustomer(CrmCustomerCreateReqBO customerCreateReq, Long userId) {
} // 1. 插入客户
CrmCustomerDO customer = BeanUtils.toBean(customerCreateReq, CrmCustomerDO.class).setOwnerUserId(userId)
.setLockStatus(false).setDealStatus(false).setReceiveTime(LocalDateTime.now());
customerMapper.insert(customer);
// 创建客户 // 2. 创建数据权限
List<CrmCustomerDO> customers = convertList(customerCreateReqBOs, customerBO -> permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
BeanUtils.toBean(customerBO, CrmCustomerDO.class).setOwnerUserId(userId)); .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
customerMapper.insertBatch(customers);
// 创建负责人数据权限 // 3. 记录操作日志上下文
permissionService.createPermissionBatch(convertList(customers, customer -> new CrmPermissionCreateReqBO() LogRecordContext.putVariable("customer", customer);
.setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()).setBizId(customer.getId()).setUserId(userId) return customer.getId();
.setLevel(CrmPermissionLevelEnum.OWNER.getLevel())));
return customers;
} }
// ==================== 公海相关操作 ==================== // ==================== 公海相关操作 ====================

View File

@ -7,7 +7,6 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordSaveReqVO; import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO; import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
import cn.iocoder.yudao.module.crm.dal.mysql.followup.CrmFollowUpRecordMapper; import cn.iocoder.yudao.module.crm.dal.mysql.followup.CrmFollowUpRecordMapper;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
@ -31,10 +30,10 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_DELETE_DENIED; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_DELETE_DENIED;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_NOT_EXISTS; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_NOT_EXISTS;
import static cn.iocoder.yudao.module.crm.framework.permission.core.util.CrmPermissionUtils.hasPermission;
/** /**
* 跟进记录 Service 实现类 * 跟进记录 Service 实现类
@ -94,14 +93,15 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
customerService.updateCustomerFollowUp(updateFollowUpReqBO); customerService.updateCustomerFollowUp(updateFollowUpReqBO);
} }
// TODO @puhui999这两个不更新 contactLastTimecontactLastContent只更新 nextTime
// 3.1 更新 contactIds 对应的记录 // 3.1 更新 contactIds 对应的记录
if (CollUtil.isNotEmpty(createReqVO.getContactIds())) { if (CollUtil.isNotEmpty(createReqVO.getContactIds())) {
contactService.updateContactFollowUpBatch(convertList(createReqVO.getContactIds(), updateFollowUpReqBO::setBizId)); contactService.updateContactFollowUpBatch(convertList(createReqVO.getContactIds(),
contactId -> updateFollowUpReqBO.setBizId(contactId).setContactLastTime(null).setContactLastContent(null)));
} }
// 3.2 需要更新 businessIdscontactIds 对应的记录 // 3.2 需要更新 businessIdscontactIds 对应的记录
if (CollUtil.isNotEmpty(createReqVO.getBusinessIds())) { if (CollUtil.isNotEmpty(createReqVO.getBusinessIds())) {
businessService.updateBusinessFollowUpBatch(convertList(createReqVO.getBusinessIds(), updateFollowUpReqBO::setBizId)); businessService.updateBusinessFollowUpBatch(convertList(createReqVO.getBusinessIds(),
businessId -> updateFollowUpReqBO.setBizId(businessId).setContactLastTime(null).setContactLastContent(null)));
} }
return followUpRecord.getId(); return followUpRecord.getId();
} }
@ -112,8 +112,7 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
return; return;
} }
List<CrmFollowUpRecordDO> followUpRecords = BeanUtils.toBean(followUpCreateReqBOs, CrmFollowUpRecordDO.class); crmFollowUpRecordMapper.insertBatch(BeanUtils.toBean(followUpCreateReqBOs, CrmFollowUpRecordDO.class));
crmFollowUpRecordMapper.insertBatch(followUpRecords);
} }
@Override @Override
@ -121,12 +120,7 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
// 校验存在 // 校验存在
CrmFollowUpRecordDO followUpRecord = validateFollowUpRecordExists(id); CrmFollowUpRecordDO followUpRecord = validateFollowUpRecordExists(id);
// 校验权限 // 校验权限
// TODO @puhui999是不是封装一个 hasPermission更简介一点 if (!hasPermission(followUpRecord.getBizType(), followUpRecord.getBizId(), userId, CrmPermissionLevelEnum.OWNER)) {
List<CrmPermissionDO> permissionList = permissionService.getPermissionListByBiz(
followUpRecord.getBizType(), followUpRecord.getBizId());
boolean hasPermission = anyMatch(permissionList, permission ->
ObjUtil.equal(permission.getUserId(), userId) && ObjUtil.equal(permission.getLevel(), CrmPermissionLevelEnum.OWNER.getLevel()));
if (!hasPermission) {
throw exception(FOLLOW_UP_RECORD_DELETE_DENIED); throw exception(FOLLOW_UP_RECORD_DELETE_DENIED);
} }

View File

@ -21,7 +21,6 @@ public class CrmUpdateFollowUpReqBO {
@Schema(description = "最后跟进时间") @Schema(description = "最后跟进时间")
@DiffLogField(name = "最后跟进时间") @DiffLogField(name = "最后跟进时间")
@NotNull(message = "最后跟进时间不能为空")
private LocalDateTime contactLastTime; private LocalDateTime contactLastTime;
@Schema(description = "下次联系时间") @Schema(description = "下次联系时间")
@ -30,7 +29,6 @@ public class CrmUpdateFollowUpReqBO {
@Schema(description = "最后更进内容") @Schema(description = "最后更进内容")
@DiffLogField(name = "最后更进内容") @DiffLogField(name = "最后更进内容")
@NotNull(message = "最后更进内容不能为空")
private String contactLastContent; private String contactLastContent;
} }