Commit 3e575a2102b2e5f4ad8e8f22fd890fc75adfc2cc
Committed by
GitHub
Merge pull request #1313 from dadiyang/fix/crm-product-delete-logrecord
[BUG] CRM 删除产品/产品分类:操作日志必然记录失败(日志模板变量未放入上下文)
Showing
2 changed files
with
12 additions
and
4 deletions
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductCategoryServiceImpl.java
| ... | ... | @@ -71,10 +71,12 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService |
| 71 | 71 | productCategoryMapper.updateById(updateObj); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - private void validateProductCategoryExists(Long id) { | |
| 75 | - if (productCategoryMapper.selectById(id) == null) { | |
| 74 | + private CrmProductCategoryDO validateProductCategoryExists(Long id) { | |
| 75 | + CrmProductCategoryDO productCategory = productCategoryMapper.selectById(id); | |
| 76 | + if (productCategory == null) { | |
| 76 | 77 | throw exception(PRODUCT_CATEGORY_NOT_EXISTS); |
| 77 | 78 | } |
| 79 | + return productCategory; | |
| 78 | 80 | } |
| 79 | 81 | |
| 80 | 82 | private void validateParentProductCategory(Long id) { |
| ... | ... | @@ -107,7 +109,7 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService |
| 107 | 109 | success = CRM_PRODUCT_CATEGORY_DELETE_SUCCESS) |
| 108 | 110 | public void deleteProductCategory(Long id) { |
| 109 | 111 | // 1.1 校验存在 |
| 110 | - validateProductCategoryExists(id); | |
| 112 | + CrmProductCategoryDO productCategory = validateProductCategoryExists(id); | |
| 111 | 113 | // 1.2 校验是否还有子分类 |
| 112 | 114 | if (productCategoryMapper.selectCountByParentId(id) > 0) { |
| 113 | 115 | throw exception(PRODUCT_CATEGORY_EXISTS_CHILDREN); |
| ... | ... | @@ -118,6 +120,9 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService |
| 118 | 120 | } |
| 119 | 121 | // 2. 删除 |
| 120 | 122 | productCategoryMapper.deleteById(id); |
| 123 | + | |
| 124 | + // 3. 记录操作日志上下文 | |
| 125 | + LogRecordContext.putVariable("productCategory", productCategory); | |
| 121 | 126 | } |
| 122 | 127 | |
| 123 | 128 | @Override | ... | ... |
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductServiceImpl.java
| ... | ... | @@ -136,7 +136,7 @@ public class CrmProductServiceImpl implements CrmProductService { |
| 136 | 136 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_PRODUCT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) |
| 137 | 137 | public void deleteProduct(Long id) { |
| 138 | 138 | // 校验存在 |
| 139 | - validateProductExists(id); | |
| 139 | + CrmProductDO product = validateProductExists(id); | |
| 140 | 140 | // 校验未被合同/商机引用,避免删除后产生悬空引用 |
| 141 | 141 | if (contractService.getContractProductCountByProductId(id) > 0) { |
| 142 | 142 | throw exception(PRODUCT_DELETE_FAIL_CONTRACT_EXISTS); |
| ... | ... | @@ -147,6 +147,9 @@ public class CrmProductServiceImpl implements CrmProductService { |
| 147 | 147 | |
| 148 | 148 | // 删除 |
| 149 | 149 | productMapper.deleteById(id); |
| 150 | + | |
| 151 | + // 记录操作日志上下文 | |
| 152 | + LogRecordContext.putVariable("product", product); | |
| 150 | 153 | } |
| 151 | 154 | |
| 152 | 155 | @Override | ... | ... |