Commit 6891b75e27c41608c4dc70adcecf2feb9f472ff0
1 parent
19c0227c
📖 CRM:产品模块的 review
Showing
4 changed files
with
15 additions
and
12 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
| ... | ... | @@ -136,8 +136,7 @@ public class CrmProductController { |
| 136 | 136 | public CommonResult<PageResult<OperateLogV2RespDTO>> getProductOperateLog(@RequestParam("bizId") Long bizId) { |
| 137 | 137 | OperateLogV2PageReqDTO reqVO = new OperateLogV2PageReqDTO(); |
| 138 | 138 | reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页 |
| 139 | - reqVO.setBizType(CRM_PRODUCT_TYPE); | |
| 140 | - reqVO.setBizId(bizId); | |
| 139 | + reqVO.setBizType(CRM_PRODUCT_TYPE).setBizId(bizId); | |
| 141 | 140 | return success(operateLogApi.getOperateLogPage(BeanUtils.toBean(reqVO, OperateLogV2PageReqDTO.class))); |
| 142 | 141 | } |
| 143 | 142 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.module.crm.framework.operatelog.core.CrmProductStatusParseFunction; | |
| 4 | +import cn.iocoder.yudao.module.crm.framework.operatelog.core.CrmProductUnitParseFunction; | |
| 3 | 5 | import com.mzt.logapi.starter.annotation.DiffLogField; |
| 4 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 7 | import jakarta.validation.constraints.NotNull; |
| ... | ... | @@ -23,7 +25,7 @@ public class CrmProductSaveReqVO { |
| 23 | 25 | private String no; |
| 24 | 26 | |
| 25 | 27 | @Schema(description = "单位", example = "2") |
| 26 | - @DiffLogField(name = "单位", function = "getProductUnitName") | |
| 28 | + @DiffLogField(name = "单位", function = CrmProductUnitParseFunction.NAME) | |
| 27 | 29 | private Integer unit; |
| 28 | 30 | |
| 29 | 31 | @Schema(description = "价格, 单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911") |
| ... | ... | @@ -33,7 +35,7 @@ public class CrmProductSaveReqVO { |
| 33 | 35 | |
| 34 | 36 | @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "上架") |
| 35 | 37 | @NotNull(message = "状态不能为空") |
| 36 | - @DiffLogField(name = "状态", function = "getProductStatusName") | |
| 38 | + @DiffLogField(name = "状态", function = CrmProductStatusParseFunction.NAME) | |
| 37 | 39 | private Integer status; |
| 38 | 40 | |
| 39 | 41 | @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductCategoryServiceImpl.java
| ... | ... | @@ -49,7 +49,8 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService |
| 49 | 49 | // 2. 插入分类 |
| 50 | 50 | CrmProductCategoryDO category = BeanUtils.toBean(createReqVO, CrmProductCategoryDO.class); |
| 51 | 51 | productCategoryMapper.insert(category); |
| 52 | - // 记录操作日志上下文 | |
| 52 | + | |
| 53 | + // 3. 记录操作日志上下文 | |
| 53 | 54 | LogRecordContext.putVariable("productCategoryId", category.getId()); |
| 54 | 55 | return category.getId(); |
| 55 | 56 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductServiceImpl.java
| ... | ... | @@ -58,21 +58,21 @@ public class CrmProductServiceImpl implements CrmProductService { |
| 58 | 58 | @LogRecord(type = CRM_PRODUCT_TYPE, subType = CRM_PRODUCT_CREATE_SUB_TYPE, bizNo = "{{#productId}}", |
| 59 | 59 | success = CRM_PRODUCT_CREATE_SUCCESS) |
| 60 | 60 | public Long createProduct(CrmProductSaveReqVO createReqVO) { |
| 61 | - // 校验产品 | |
| 61 | + // 1. 校验产品 | |
| 62 | 62 | adminUserApi.validateUserList(Collections.singleton(createReqVO.getOwnerUserId())); |
| 63 | 63 | validateProductNoDuplicate(null, createReqVO.getNo()); |
| 64 | 64 | validateProductCategoryExists(createReqVO.getCategoryId()); |
| 65 | 65 | |
| 66 | - // 插入产品 | |
| 66 | + // 2. 插入产品 | |
| 67 | 67 | CrmProductDO product = BeanUtils.toBean(createReqVO, CrmProductDO.class); |
| 68 | 68 | productMapper.insert(product); |
| 69 | 69 | |
| 70 | - // 插入数据权限 | |
| 70 | + // 3. 插入数据权限 | |
| 71 | 71 | permissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(product.getOwnerUserId()) |
| 72 | 72 | .setBizType(CrmBizTypeEnum.CRM_PRODUCT.getType()).setBizId(product.getId()) |
| 73 | 73 | .setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); |
| 74 | 74 | |
| 75 | - // 记录操作日志上下文 | |
| 75 | + // 4. 记录操作日志上下文 | |
| 76 | 76 | LogRecordContext.putVariable("productId", product.getId()); |
| 77 | 77 | return product.getId(); |
| 78 | 78 | } |
| ... | ... | @@ -82,17 +82,17 @@ public class CrmProductServiceImpl implements CrmProductService { |
| 82 | 82 | success = CRM_PRODUCT_UPDATE_SUCCESS) |
| 83 | 83 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_PRODUCT, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) |
| 84 | 84 | public void updateProduct(CrmProductSaveReqVO updateReqVO) { |
| 85 | - // 校验产品 | |
| 85 | + // 1. 校验产品 | |
| 86 | 86 | updateReqVO.setOwnerUserId(null); // 不修改负责人 |
| 87 | 87 | CrmProductDO crmProductDO = validateProductExists(updateReqVO.getId()); |
| 88 | 88 | validateProductNoDuplicate(updateReqVO.getId(), updateReqVO.getNo()); |
| 89 | 89 | validateProductCategoryExists(updateReqVO.getCategoryId()); |
| 90 | 90 | |
| 91 | - // 更新产品 | |
| 91 | + // 2. 更新产品 | |
| 92 | 92 | CrmProductDO updateObj = BeanUtils.toBean(updateReqVO, CrmProductDO.class); |
| 93 | 93 | productMapper.updateById(updateObj); |
| 94 | 94 | |
| 95 | - // 记录操作日志上下文 | |
| 95 | + // 3. 记录操作日志上下文 | |
| 96 | 96 | LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(crmProductDO,CrmProductSaveReqVO.class)); |
| 97 | 97 | } |
| 98 | 98 | |
| ... | ... | @@ -145,6 +145,7 @@ public class CrmProductServiceImpl implements CrmProductService { |
| 145 | 145 | return productMapper.selectBatchIds(ids); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | + // TODO @anhaohao:可以接入数据权限,参考 CrmCustomerService 的 getCustomerPage | |
| 148 | 149 | @Override |
| 149 | 150 | public PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO) { |
| 150 | 151 | return productMapper.selectPage(pageReqVO); | ... | ... |