Commit f366d440d8bfb09fa063b341cea3f972055b9862
Merge remote-tracking branch 'yudao/develop' into develop
Showing
10 changed files
with
79 additions
and
43 deletions
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/QueryWrapperX.java
| ... | ... | @@ -151,7 +151,7 @@ public class QueryWrapperX<T> extends QueryWrapper<T> { |
| 151 | 151 | switch (SqlConstants.DB_TYPE) { |
| 152 | 152 | case ORACLE: |
| 153 | 153 | case ORACLE_12C: |
| 154 | - super.eq("ROWNUM", n); | |
| 154 | + super.le("ROWNUM", n); | |
| 155 | 155 | break; |
| 156 | 156 | case SQL_SERVER: |
| 157 | 157 | case SQL_SERVER2005: | ... | ... |
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/convert/business/CrmBusinessConvert.java
| ... | ... | @@ -50,8 +50,8 @@ public interface CrmBusinessConvert { |
| 50 | 50 | @Mapping(target = "id", source = "reqBO.bizId") |
| 51 | 51 | CrmBusinessDO convert(CrmUpdateFollowUpReqBO reqBO); |
| 52 | 52 | |
| 53 | - default List<CrmBusinessDO> convertList(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList) { | |
| 54 | - return CollectionUtils.convertList(updateFollowUpReqBOList, INSTANCE::convert); | |
| 53 | + default List<CrmBusinessDO> convertList(List<CrmUpdateFollowUpReqBO> list) { | |
| 54 | + return CollectionUtils.convertList(list, INSTANCE::convert); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/CrmContactConvert.java
| ... | ... | @@ -70,8 +70,8 @@ public interface CrmContactConvert { |
| 70 | 70 | @Mapping(target = "id", source = "reqBO.bizId") |
| 71 | 71 | CrmContactDO convert(CrmUpdateFollowUpReqBO reqBO); |
| 72 | 72 | |
| 73 | - default List<CrmContactDO> convertList(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList) { | |
| 74 | - return CollectionUtils.convertList(updateFollowUpReqBOList, INSTANCE::convert); | |
| 73 | + default List<CrmContactDO> convertList(List<CrmUpdateFollowUpReqBO> list) { | |
| 74 | + return CollectionUtils.convertList(list, INSTANCE::convert); | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | } | ... | ... |
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.customer.CrmCustomerService; |
| 20 | 23 | import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO; |
| 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,50 @@ public class CrmClueServiceImpl implements CrmClueService { |
| 58 | 66 | private AdminUserApi adminUserApi; |
| 59 | 67 | |
| 60 | 68 | @Override |
| 61 | - // TODO @min:补充相关几个方法的操作日志; | |
| 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) | |
| 62 | 72 | public Long createClue(CrmClueSaveReqVO createReqVO) { |
| 63 | - // 校验关联数据 | |
| 73 | + // 1. 校验关联数据 | |
| 64 | 74 | validateRelationDataExists(createReqVO); |
| 65 | 75 | |
| 66 | - // 插入 | |
| 76 | + // 2. 插入 | |
| 67 | 77 | CrmClueDO clue = BeanUtils.toBean(createReqVO, CrmClueDO.class); |
| 68 | 78 | clueMapper.insert(clue); |
| 69 | - // 返回 | |
| 79 | + | |
| 80 | + // 3. 创建数据权限 | |
| 81 | + CrmPermissionCreateReqBO createReqBO = new CrmPermissionCreateReqBO() | |
| 82 | + .setBizType(CrmBizTypeEnum.CRM_LEADS.getType()) | |
| 83 | + .setBizId(clue.getId()) | |
| 84 | + // 设置当前操作的人为负责人 | |
| 85 | + .setUserId(getLoginUserId()) | |
| 86 | + .setLevel(CrmPermissionLevelEnum.OWNER.getLevel()); | |
| 87 | + crmPermissionService.createPermission(createReqBO); | |
| 88 | + | |
| 89 | + // 4. 记录操作日志上下文 | |
| 90 | + LogRecordContext.putVariable("clue", clue); | |
| 70 | 91 | return clue.getId(); |
| 71 | 92 | } |
| 72 | 93 | |
| 73 | 94 | @Override |
| 95 | + @Transactional(rollbackFor = Exception.class) | |
| 96 | + @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", | |
| 97 | + success = CRM_LEADS_UPDATE_SUCCESS) | |
| 74 | 98 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) |
| 75 | 99 | public void updateClue(CrmClueSaveReqVO updateReqVO) { |
| 76 | - // 校验线索是否存在 | |
| 77 | - validateClueExists(updateReqVO.getId()); | |
| 78 | - // 校验关联数据 | |
| 100 | + Assert.notNull(updateReqVO.getId(), "线索编号不能为空"); | |
| 101 | + // 1. 校验线索是否存在 | |
| 102 | + CrmClueDO oldClue = validateClueExists(updateReqVO.getId()); | |
| 103 | + // 2. 校验关联数据 | |
| 79 | 104 | validateRelationDataExists(updateReqVO); |
| 80 | 105 | |
| 81 | - // 更新 | |
| 106 | + // 3. 更新 | |
| 82 | 107 | CrmClueDO updateObj = BeanUtils.toBean(updateReqVO, CrmClueDO.class); |
| 83 | 108 | clueMapper.updateById(updateObj); |
| 109 | + | |
| 110 | + // 3. 记录操作日志上下文 | |
| 111 | + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldClue, CrmCustomerSaveReqVO.class)); | |
| 112 | + LogRecordContext.putVariable("clueName", oldClue.getName()); | |
| 84 | 113 | } |
| 85 | 114 | |
| 86 | 115 | @Override |
| ... | ... | @@ -89,20 +118,30 @@ public class CrmClueServiceImpl implements CrmClueService { |
| 89 | 118 | } |
| 90 | 119 | |
| 91 | 120 | @Override |
| 121 | + @Transactional(rollbackFor = Exception.class) | |
| 122 | + @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_DELETE_SUB_TYPE, bizNo = "{{#id}}", | |
| 123 | + success = CRM_LEADS_DELETE_SUCCESS) | |
| 92 | 124 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) |
| 93 | 125 | public void deleteClue(Long id) { |
| 94 | - // 校验存在 | |
| 95 | - validateClueExists(id); | |
| 96 | - // 删除 | |
| 126 | + // 1. 校验存在 | |
| 127 | + CrmClueDO clue = validateClueExists(id); | |
| 128 | + | |
| 129 | + // 2. 删除 | |
| 97 | 130 | clueMapper.deleteById(id); |
| 98 | - // 删除数据权限 | |
| 131 | + | |
| 132 | + // 3. 删除数据权限 | |
| 99 | 133 | crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_LEADS.getType(), id); |
| 134 | + | |
| 135 | + // 4. 记录操作日志上下文 | |
| 136 | + LogRecordContext.putVariable("clueName", clue.getName()); | |
| 100 | 137 | } |
| 101 | 138 | |
| 102 | - private void validateClueExists(Long id) { | |
| 103 | - if (clueMapper.selectById(id) == null) { | |
| 139 | + private CrmClueDO validateClueExists(Long id) { | |
| 140 | + CrmClueDO crmClueDO = clueMapper.selectById(id); | |
| 141 | + if (crmClueDO == null) { | |
| 104 | 142 | throw exception(CLUE_NOT_EXISTS); |
| 105 | 143 | } |
| 144 | + return crmClueDO; | |
| 106 | 145 | } |
| 107 | 146 | |
| 108 | 147 | @Override |
| ... | ... | @@ -145,29 +184,24 @@ public class CrmClueServiceImpl implements CrmClueService { |
| 145 | 184 | List<CrmClueDO> clues = getClueList(clueIds, userId); |
| 146 | 185 | if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) { |
| 147 | 186 | 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(","))); | |
| 187 | + throw exception(CLUE_ANY_CLUE_NOT_EXISTS, StrUtil.join(",", clueIds)); | |
| 150 | 188 | } |
| 151 | 189 | |
| 152 | - // 过滤出未转化的客户 | |
| 153 | - // TODO @min:1)存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了;2)常见的过滤逻辑,可以使用 CollectionUtils.filterList() | |
| 154 | - List<CrmClueDO> unTransformClues = clues.stream() | |
| 155 | - .filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())).toList(); | |
| 156 | - // 传入的线索中包含已经转化的情况,抛出业务异常 | |
| 157 | - if (ObjectUtil.notEqual(clues.size(), unTransformClues.size())) { | |
| 158 | - // TODO @min:可以使用 StrUtil.join(",", clueIds) 简化这种常见操作 | |
| 159 | - clueIds.removeAll(convertSet(unTransformClues, CrmClueDO::getId)); | |
| 160 | - throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); | |
| 190 | + // 存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了 | |
| 191 | + List<CrmClueDO> translatedClues = CollectionUtils.filterList(clues, | |
| 192 | + clue -> ObjectUtil.equal(Boolean.TRUE, clue.getTransformStatus())); | |
| 193 | + if (CollUtil.isNotEmpty(translatedClues)) { | |
| 194 | + throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, StrUtil.join(",", convertSet(translatedClues, CrmClueDO::getId))); | |
| 161 | 195 | } |
| 162 | 196 | |
| 163 | 197 | // 遍历线索(未转化的线索),创建对应的客户 |
| 164 | - unTransformClues.forEach(clue -> { | |
| 198 | + reqVO.getIds().forEach(id -> { | |
| 165 | 199 | // 1. 创建客户 |
| 166 | - CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null); | |
| 200 | + CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(id, CrmCustomerSaveReqVO.class).setId(null); | |
| 167 | 201 | Long customerId = customerService.createCustomer(customerSaveReqVO, userId); |
| 168 | 202 | // TODO @puhui999:如果有跟进记录,需要一起转过去;提问:艿艿这里是复制线索所有的跟进吗?还是直接把线索相关的跟进 bizType、bizId 全改为关联客户? |
| 169 | 203 | // 2. 更新线索 |
| 170 | - clueMapper.updateById(new CrmClueDO().setId(clue.getId()) | |
| 204 | + clueMapper.updateById(new CrmClueDO().setId(id) | |
| 171 | 205 | .setTransformStatus(Boolean.TRUE).setCustomerId(customerId)); |
| 172 | 206 | }); |
| 173 | 207 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/followup/CrmFollowUpRecordServiceImpl.java
| ... | ... | @@ -66,6 +66,7 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService { |
| 66 | 66 | crmFollowUpRecordMapper.insert(followUpRecord); |
| 67 | 67 | |
| 68 | 68 | LocalDateTime now = LocalDateTime.now(); |
| 69 | + // TODO @puhui999:感觉可以这里基于 type 做 102 到 104 这种判断;然后,每个类型的调用封装一个小方法,之后调用这些小方法;再之后,74-76、80-82 也是等价的处理; | |
| 69 | 70 | // 2. 更新 bizId 对应的记录; |
| 70 | 71 | updateBizTypeFollowUp(followUpRecord, now); |
| 71 | 72 | // 3.1 更新 contactIds 对应的记录 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/followup/bo/CrmUpdateFollowUpReqBO.java
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.product.convert.comment; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | 4 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 6 | 5 | import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; |
| 7 | 6 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; |
| 8 | -import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; | |
| 9 | 7 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; |
| 10 | 8 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 11 | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| ... | ... | @@ -61,6 +59,4 @@ public interface ProductCommentConvert { |
| 61 | 59 | return divide.intValue(); |
| 62 | 60 | } |
| 63 | 61 | |
| 64 | - PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> productCommentDOPageResult); | |
| 65 | - | |
| 66 | 62 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java
| ... | ... | @@ -3,13 +3,13 @@ package cn.iocoder.yudao.module.product.service.comment; |
| 3 | 3 | import cn.hutool.core.date.DateUtil; |
| 4 | 4 | import cn.hutool.core.util.RandomUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | 8 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; |
| 9 | 10 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; |
| 10 | 11 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; |
| 11 | 12 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 12 | -import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; | |
| 13 | 13 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; |
| 14 | 14 | import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; |
| 15 | 15 | import cn.iocoder.yudao.module.product.enums.comment.ProductCommentScoresEnum; |
| ... | ... | @@ -128,7 +128,8 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { |
| 128 | 128 | productCommentPageReqVO.setReplyStatus(Boolean.TRUE); |
| 129 | 129 | |
| 130 | 130 | PageResult<ProductCommentDO> commentPage = productCommentService.getCommentPage(productCommentPageReqVO); |
| 131 | - PageResult<ProductCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage(productCommentMapper.selectPage(productCommentPageReqVO)); | |
| 131 | + PageResult<ProductCommentRespVO> result = BeanUtils.toBean(productCommentMapper.selectPage(productCommentPageReqVO), | |
| 132 | + ProductCommentRespVO.class); | |
| 132 | 133 | assertEquals(result.getTotal(), commentPage.getTotal()); |
| 133 | 134 | |
| 134 | 135 | PageResult<ProductCommentDO> all = productCommentService.getCommentPage(new ProductCommentPageReqVO()); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeSaveReqVO.java
| ... | ... | @@ -11,8 +11,7 @@ import jakarta.validation.constraints.Size; |
| 11 | 11 | @Data |
| 12 | 12 | public class NoticeSaveReqVO { |
| 13 | 13 | |
| 14 | - @Schema(description = "岗位公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 15 | - @NotNull(message = "岗位公告编号不能为空") | |
| 14 | + @Schema(description = "岗位公告编号", example = "1024") | |
| 16 | 15 | private Long id; |
| 17 | 16 | |
| 18 | 17 | @Schema(description = "公告标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") | ... | ... |