Commit 180a62699af05199b5daf8bd8990e947ba0b1962
Committed by
Gitee
!845 CRM:线索相关内容
Merge pull request !845 from Minh-X/develop
Showing
2 changed files
with
66 additions
and
22 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java
| ... | ... | @@ -11,6 +11,12 @@ public interface LogRecordConstants { |
| 11 | 11 | // ======================= CRM_LEADS 线索 ======================= |
| 12 | 12 | |
| 13 | 13 | String CRM_LEADS_TYPE = "CRM 线索"; |
| 14 | + String CRM_LEADS_CREATE_SUB_TYPE = "创建线索"; | |
| 15 | + String CRM_LEADS_CREATE_SUCCESS = "创建了线索{{#clue.name}}"; | |
| 16 | + String CRM_LEADS_UPDATE_SUB_TYPE = "更新线索"; | |
| 17 | + String CRM_LEADS_UPDATE_SUCCESS = "更新了线索【{{#clueName}}】: {_DIFF{#updateReqVO}}"; | |
| 18 | + String CRM_LEADS_DELETE_SUB_TYPE = "删除线索"; | |
| 19 | + String CRM_LEADS_DELETE_SUCCESS = "删除了线索【{{#clueName}}】"; | |
| 14 | 20 | |
| 15 | 21 | // ======================= CRM_CUSTOMER 客户 ======================= |
| 16 | 22 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java
| ... | ... | @@ -2,8 +2,11 @@ package cn.iocoder.yudao.module.crm.service.clue; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | +import cn.hutool.core.lang.Assert; | |
| 5 | 6 | import cn.hutool.core.util.ObjectUtil; |
| 7 | +import cn.hutool.core.util.StrUtil; | |
| 6 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 7 | 10 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | 11 | import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO; |
| 9 | 12 | import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueSaveReqVO; |
| ... | ... | @@ -19,7 +22,11 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPerm |
| 19 | 22 | import cn.iocoder.yudao.module.crm.service.clue.bo.CrmClueUpdateFollowUpReqBO; |
| 20 | 23 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| 21 | 24 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 25 | +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; | |
| 22 | 26 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 27 | +import com.mzt.logapi.context.LogRecordContext; | |
| 28 | +import com.mzt.logapi.service.impl.DiffParseFunction; | |
| 29 | +import com.mzt.logapi.starter.annotation.LogRecord; | |
| 23 | 30 | import jakarta.annotation.Resource; |
| 24 | 31 | import org.springframework.stereotype.Service; |
| 25 | 32 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -29,11 +36,12 @@ import java.util.Collection; |
| 29 | 36 | import java.util.List; |
| 30 | 37 | import java.util.Objects; |
| 31 | 38 | import java.util.Set; |
| 32 | -import java.util.stream.Collectors; | |
| 33 | 39 | |
| 34 | 40 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 35 | 41 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 42 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 36 | 43 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| 44 | +import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; | |
| 37 | 45 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; |
| 38 | 46 | |
| 39 | 47 | /** |
| ... | ... | @@ -58,29 +66,52 @@ public class CrmClueServiceImpl implements CrmClueService { |
| 58 | 66 | private AdminUserApi adminUserApi; |
| 59 | 67 | |
| 60 | 68 | @Override |
| 69 | + @Transactional(rollbackFor = Exception.class) | |
| 70 | + @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_CREATE_SUB_TYPE, bizNo = "{{#clue.id}}", | |
| 71 | + success = CRM_LEADS_CREATE_SUCCESS) | |
| 61 | 72 | // TODO @min:补充相关几个方法的操作日志; |
| 62 | 73 | public Long createClue(CrmClueSaveReqVO createReqVO) { |
| 63 | - // 校验关联数据 | |
| 74 | + // 1. 校验关联数据 | |
| 64 | 75 | validateRelationDataExists(createReqVO); |
| 65 | 76 | |
| 66 | - // 插入 | |
| 77 | + // 2. 插入 | |
| 67 | 78 | CrmClueDO clue = BeanUtils.toBean(createReqVO, CrmClueDO.class); |
| 68 | 79 | clueMapper.insert(clue); |
| 69 | - // 返回 | |
| 80 | + | |
| 81 | + // 3. 创建数据权限 | |
| 82 | + CrmPermissionCreateReqBO createReqBO = new CrmPermissionCreateReqBO() | |
| 83 | + .setBizType(CrmBizTypeEnum.CRM_LEADS.getType()) | |
| 84 | + .setBizId(clue.getId()) | |
| 85 | + // 设置当前操作的人为负责人 | |
| 86 | + .setUserId(getLoginUserId()) | |
| 87 | + .setLevel(CrmPermissionLevelEnum.OWNER.getLevel()); | |
| 88 | + crmPermissionService.createPermission(createReqBO); | |
| 89 | + | |
| 90 | + // 4. 记录操作日志上下文 | |
| 91 | + LogRecordContext.putVariable("clue", clue); | |
| 70 | 92 | return clue.getId(); |
| 71 | 93 | } |
| 72 | 94 | |
| 73 | 95 | @Override |
| 96 | + @Transactional(rollbackFor = Exception.class) | |
| 97 | + @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", | |
| 98 | + success = CRM_LEADS_UPDATE_SUCCESS) | |
| 74 | 99 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) |
| 75 | 100 | public void updateClue(CrmClueSaveReqVO updateReqVO) { |
| 76 | - // 校验线索是否存在 | |
| 77 | - validateClueExists(updateReqVO.getId()); | |
| 78 | - // 校验关联数据 | |
| 101 | + Assert.notNull(updateReqVO.getId(), "线索编号不能为空"); | |
| 102 | + // 1. 校验线索是否存在 | |
| 103 | + CrmClueDO oldClue = validateClueExists(updateReqVO.getId()); | |
| 104 | + // 2. 校验关联数据 | |
| 79 | 105 | validateRelationDataExists(updateReqVO); |
| 80 | 106 | |
| 81 | - // 更新 | |
| 107 | + // 3. 更新 | |
| 82 | 108 | CrmClueDO updateObj = BeanUtils.toBean(updateReqVO, CrmClueDO.class); |
| 83 | 109 | clueMapper.updateById(updateObj); |
| 110 | + | |
| 111 | + // 3. 记录操作日志上下文 | |
| 112 | + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldClue, CrmCustomerSaveReqVO.class)); | |
| 113 | + LogRecordContext.putVariable("clueName", oldClue.getName()); | |
| 114 | + | |
| 84 | 115 | } |
| 85 | 116 | |
| 86 | 117 | @Override |
| ... | ... | @@ -89,20 +120,30 @@ public class CrmClueServiceImpl implements CrmClueService { |
| 89 | 120 | } |
| 90 | 121 | |
| 91 | 122 | @Override |
| 123 | + @Transactional(rollbackFor = Exception.class) | |
| 124 | + @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_DELETE_SUB_TYPE, bizNo = "{{#id}}", | |
| 125 | + success = CRM_LEADS_DELETE_SUCCESS) | |
| 92 | 126 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) |
| 93 | 127 | public void deleteClue(Long id) { |
| 94 | - // 校验存在 | |
| 95 | - validateClueExists(id); | |
| 96 | - // 删除 | |
| 128 | + // 1. 校验存在 | |
| 129 | + CrmClueDO clue = validateClueExists(id); | |
| 130 | + | |
| 131 | + // 2. 删除 | |
| 97 | 132 | clueMapper.deleteById(id); |
| 98 | - // 删除数据权限 | |
| 133 | + | |
| 134 | + // 3. 删除数据权限 | |
| 99 | 135 | crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_LEADS.getType(), id); |
| 136 | + | |
| 137 | + // 4. 记录操作日志上下文 | |
| 138 | + LogRecordContext.putVariable("clueName", clue.getName()); | |
| 100 | 139 | } |
| 101 | 140 | |
| 102 | - private void validateClueExists(Long id) { | |
| 103 | - if (clueMapper.selectById(id) == null) { | |
| 141 | + private CrmClueDO validateClueExists(Long id) { | |
| 142 | + CrmClueDO crmClueDO = clueMapper.selectById(id); | |
| 143 | + if (crmClueDO == null) { | |
| 104 | 144 | throw exception(CLUE_NOT_EXISTS); |
| 105 | 145 | } |
| 146 | + return crmClueDO; | |
| 106 | 147 | } |
| 107 | 148 | |
| 108 | 149 | @Override |
| ... | ... | @@ -145,19 +186,16 @@ public class CrmClueServiceImpl implements CrmClueService { |
| 145 | 186 | List<CrmClueDO> clues = getClueList(clueIds, userId); |
| 146 | 187 | if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) { |
| 147 | 188 | clueIds.removeAll(convertSet(clues, CrmClueDO::getId)); |
| 148 | - // TODO @min:可以使用 StrUtil.join(",", clueIds) 简化这种常见操作 | |
| 149 | - throw exception(CLUE_ANY_CLUE_NOT_EXISTS, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); | |
| 189 | + throw exception(CLUE_ANY_CLUE_NOT_EXISTS, StrUtil.join(",", clueIds)); | |
| 150 | 190 | } |
| 151 | 191 | |
| 152 | 192 | // 过滤出未转化的客户 |
| 153 | - // TODO @min:1)存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了;2)常见的过滤逻辑,可以使用 CollectionUtils.filterList() | |
| 154 | - List<CrmClueDO> unTransformClues = clues.stream() | |
| 155 | - .filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())).toList(); | |
| 156 | - // 传入的线索中包含已经转化的情况,抛出业务异常 | |
| 193 | + List<CrmClueDO> unTransformClues = CollectionUtils.filterList(clues, | |
| 194 | + clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())); | |
| 195 | + // 存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了 | |
| 157 | 196 | if (ObjectUtil.notEqual(clues.size(), unTransformClues.size())) { |
| 158 | - // TODO @min:可以使用 StrUtil.join(",", clueIds) 简化这种常见操作 | |
| 159 | 197 | clueIds.removeAll(convertSet(unTransformClues, CrmClueDO::getId)); |
| 160 | - throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); | |
| 198 | + throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, StrUtil.join(",", clueIds)); | |
| 161 | 199 | } |
| 162 | 200 | |
| 163 | 201 | // 遍历线索(未转化的线索),创建对应的客户 | ... | ... |