修改:CRM 产品,产品列表查询接入数据权限

This commit is contained in:
anhaohao 2024-01-15 10:51:23 +08:00
parent e16f1caae0
commit 454e800067
4 changed files with 20 additions and 12 deletions

View File

@ -42,6 +42,7 @@ import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_PRODUCT_TYPE; import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_PRODUCT_TYPE;
@Tag(name = "管理后台 - CRM 产品") @Tag(name = "管理后台 - CRM 产品")
@ -102,7 +103,7 @@ public class CrmProductController {
@Operation(summary = "获得产品分页") @Operation(summary = "获得产品分页")
@PreAuthorize("@ss.hasPermission('crm:product:query')") @PreAuthorize("@ss.hasPermission('crm:product:query')")
public CommonResult<PageResult<CrmProductRespVO>> getProductPage(@Valid CrmProductPageReqVO pageVO) { public CommonResult<PageResult<CrmProductRespVO>> getProductPage(@Valid CrmProductPageReqVO pageVO) {
PageResult<CrmProductDO> pageResult = productService.getProductPage(pageVO); PageResult<CrmProductDO> pageResult = productService.getProductPage(pageVO, getLoginUserId());
return success(new PageResult<>(getProductDetailList(pageResult.getList()), pageResult.getTotal())); return success(new PageResult<>(getProductDetailList(pageResult.getList()), pageResult.getTotal()));
} }
@ -113,7 +114,7 @@ public class CrmProductController {
public void exportProductExcel(@Valid CrmProductPageReqVO exportReqVO, public void exportProductExcel(@Valid CrmProductPageReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<CrmProductDO> list = productService.getProductPage(exportReqVO).getList(); List<CrmProductDO> list = productService.getProductPage(exportReqVO, getLoginUserId()).getList();
// 导出 Excel // 导出 Excel
ExcelUtils.write(response, "产品.xls", "数据", CrmProductRespVO.class, ExcelUtils.write(response, "产品.xls", "数据", CrmProductRespVO.class,
getProductDetailList(list)); getProductDetailList(list));

View File

@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.crm.dal.mysql.product;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@ -15,11 +17,17 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface CrmProductMapper extends BaseMapperX<CrmProductDO> { public interface CrmProductMapper extends BaseMapperX<CrmProductDO> {
default PageResult<CrmProductDO> selectPage(CrmProductPageReqVO reqVO) { default PageResult<CrmProductDO> selectPage(CrmProductPageReqVO reqVO, Long userId) {
return selectPage(reqVO, new LambdaQueryWrapperX<CrmProductDO>() MPJLambdaWrapperX<CrmProductDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_PRODUCT.getType(),
CrmProductDO::getId, userId, null, Boolean.FALSE);
// 拼接自身的查询条件
query.selectAll(CrmProductDO.class)
.likeIfPresent(CrmProductDO::getName, reqVO.getName()) .likeIfPresent(CrmProductDO::getName, reqVO.getName())
.eqIfPresent(CrmProductDO::getStatus, reqVO.getStatus()) .eqIfPresent(CrmProductDO::getStatus, reqVO.getStatus())
.orderByDesc(CrmProductDO::getId)); .orderByDesc(CrmProductDO::getId);
return selectJoinPage(reqVO, CrmProductDO.class, query);
} }
default CrmProductDO selectByNo(String no) { default CrmProductDO selectByNo(String no) {

View File

@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO; import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -60,7 +60,7 @@ public interface CrmProductService {
* @param pageReqVO 分页查询 * @param pageReqVO 分页查询
* @return 产品分页 * @return 产品分页
*/ */
PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO); PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO, Long userId);
/** /**
* 获得产品 * 获得产品

View File

@ -145,10 +145,9 @@ public class CrmProductServiceImpl implements CrmProductService {
return productMapper.selectBatchIds(ids); return productMapper.selectBatchIds(ids);
} }
// TODO @anhaohao可以接入数据权限参考 CrmCustomerService getCustomerPage
@Override @Override
public PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO) { public PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO, Long userId) {
return productMapper.selectPage(pageReqVO); return productMapper.selectPage(pageReqVO, userId);
} }
@Override @Override