Commit cc6cb835070669aecd9891bbac71244f5ac539fb
Committed by
Gitee
!833 修改:CRM 产品,产品列表查询接入数据权限
Merge pull request !833 from 安浩浩/develop
Showing
4 changed files
with
20 additions
and
12 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
| ... | ... | @@ -42,6 +42,7 @@ import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE; |
| 42 | 42 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 43 | 43 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; |
| 44 | 44 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 45 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 45 | 46 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_PRODUCT_TYPE; |
| 46 | 47 | |
| 47 | 48 | @Tag(name = "管理后台 - CRM 产品") |
| ... | ... | @@ -102,7 +103,7 @@ public class CrmProductController { |
| 102 | 103 | @Operation(summary = "获得产品分页") |
| 103 | 104 | @PreAuthorize("@ss.hasPermission('crm:product:query')") |
| 104 | 105 | public CommonResult<PageResult<CrmProductRespVO>> getProductPage(@Valid CrmProductPageReqVO pageVO) { |
| 105 | - PageResult<CrmProductDO> pageResult = productService.getProductPage(pageVO); | |
| 106 | + PageResult<CrmProductDO> pageResult = productService.getProductPage(pageVO, getLoginUserId()); | |
| 106 | 107 | return success(new PageResult<>(getProductDetailList(pageResult.getList()), pageResult.getTotal())); |
| 107 | 108 | } |
| 108 | 109 | |
| ... | ... | @@ -113,7 +114,7 @@ public class CrmProductController { |
| 113 | 114 | public void exportProductExcel(@Valid CrmProductPageReqVO exportReqVO, |
| 114 | 115 | HttpServletResponse response) throws IOException { |
| 115 | 116 | exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 116 | - List<CrmProductDO> list = productService.getProductPage(exportReqVO).getList(); | |
| 117 | + List<CrmProductDO> list = productService.getProductPage(exportReqVO, getLoginUserId()).getList(); | |
| 117 | 118 | // 导出 Excel |
| 118 | 119 | ExcelUtils.write(response, "产品.xls", "数据", CrmProductRespVO.class, |
| 119 | 120 | getProductDetailList(list)); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/product/CrmProductMapper.java
| ... | ... | @@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.crm.dal.mysql.product; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; | |
| 6 | 6 | import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; |
| 8 | +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | |
| 9 | +import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils; | |
| 8 | 10 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 11 | |
| 10 | 12 | /** |
| ... | ... | @@ -15,11 +17,17 @@ import org.apache.ibatis.annotations.Mapper; |
| 15 | 17 | @Mapper |
| 16 | 18 | public interface CrmProductMapper extends BaseMapperX<CrmProductDO> { |
| 17 | 19 | |
| 18 | - default PageResult<CrmProductDO> selectPage(CrmProductPageReqVO reqVO) { | |
| 19 | - return selectPage(reqVO, new LambdaQueryWrapperX<CrmProductDO>() | |
| 20 | + default PageResult<CrmProductDO> selectPage(CrmProductPageReqVO reqVO, Long userId) { | |
| 21 | + MPJLambdaWrapperX<CrmProductDO> query = new MPJLambdaWrapperX<>(); | |
| 22 | + // 拼接数据权限的查询条件 | |
| 23 | + CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_PRODUCT.getType(), | |
| 24 | + CrmProductDO::getId, userId, null, Boolean.FALSE); | |
| 25 | + // 拼接自身的查询条件 | |
| 26 | + query.selectAll(CrmProductDO.class) | |
| 20 | 27 | .likeIfPresent(CrmProductDO::getName, reqVO.getName()) |
| 21 | 28 | .eqIfPresent(CrmProductDO::getStatus, reqVO.getStatus()) |
| 22 | - .orderByDesc(CrmProductDO::getId)); | |
| 29 | + .orderByDesc(CrmProductDO::getId); | |
| 30 | + return selectJoinPage(reqVO, CrmProductDO.class, query); | |
| 23 | 31 | } |
| 24 | 32 | |
| 25 | 33 | default CrmProductDO selectByNo(String no) { | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductService.java
| ... | ... | @@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; |
| 7 | - | |
| 8 | 7 | import jakarta.validation.Valid; |
| 8 | + | |
| 9 | 9 | import java.util.Collection; |
| 10 | 10 | import java.util.List; |
| 11 | 11 | |
| ... | ... | @@ -60,7 +60,7 @@ public interface CrmProductService { |
| 60 | 60 | * @param pageReqVO 分页查询 |
| 61 | 61 | * @return 产品分页 |
| 62 | 62 | */ |
| 63 | - PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO); | |
| 63 | + PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO, Long userId); | |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * 获得产品 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductServiceImpl.java
| ... | ... | @@ -93,7 +93,7 @@ public class CrmProductServiceImpl implements CrmProductService { |
| 93 | 93 | productMapper.updateById(updateObj); |
| 94 | 94 | |
| 95 | 95 | // 3. 记录操作日志上下文 |
| 96 | - LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(crmProductDO,CrmProductSaveReqVO.class)); | |
| 96 | + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(crmProductDO, CrmProductSaveReqVO.class)); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | private CrmProductDO validateProductExists(Long id) { |
| ... | ... | @@ -145,10 +145,9 @@ public class CrmProductServiceImpl implements CrmProductService { |
| 145 | 145 | return productMapper.selectBatchIds(ids); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - // TODO @anhaohao:可以接入数据权限,参考 CrmCustomerService 的 getCustomerPage | |
| 149 | 148 | @Override |
| 150 | - public PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO) { | |
| 151 | - return productMapper.selectPage(pageReqVO); | |
| 149 | + public PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO, Long userId) { | |
| 150 | + return productMapper.selectPage(pageReqVO, userId); | |
| 152 | 151 | } |
| 153 | 152 | |
| 154 | 153 | @Override | ... | ... |