crm-客户:分页查询 mapper 还是得拆成两个,怎么查逻辑交给 service 去做处理

This commit is contained in:
puhui999 2023-11-28 14:27:36 +08:00
parent 6c536caad4
commit 79600774ec
4 changed files with 45 additions and 41 deletions

View File

@ -23,7 +23,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAnd
/**
* Crm 数据权限 Convert
*
* @author Wanwan
* @author HUIHUI
*/
@Mapper
public interface CrmPermissionConvert {

View File

@ -25,47 +25,25 @@ import java.util.List;
@Mapper
public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
static void appendQueryParams(MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
if (pageReqVO.getPool()) { // 情况一公海
mpjLambdaWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
} else { // 情况二不是公海
mpjLambdaWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
}
// TODO 场景数据过滤
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一我负责的数据
mpjLambdaWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
}
}
static void appendQueryParams(LambdaQueryWrapperX<CrmCustomerDO> lambdaQueryWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
if (pageReqVO.getPool()) { // 情况一公海
lambdaQueryWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
} else { // 情况二不是公海
lambdaQueryWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
}
// TODO 场景数据过滤
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一我负责的数据
lambdaQueryWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
}
}
default int updateOwnerUserIdById(Long id, Long ownerUserId) {
return update(new LambdaUpdateWrapper<CrmCustomerDO>()
.eq(CrmCustomerDO::getId, id)
.set(CrmCustomerDO::getOwnerUserId, ownerUserId));
}
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId, Boolean admin) {
if (admin) { // 情况一管理员查看
LambdaQueryWrapperX<CrmCustomerDO> queryWrapperX = new LambdaQueryWrapperX<>();
appendQueryParams(queryWrapperX, pageReqVO, userId);
return selectPage(pageReqVO, queryWrapperX
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
}
default PageResult<CrmCustomerDO> selectPageWithAdmin(CrmCustomerPageReqVO pageReqVO, Long userId) {
// 情况一管理员查看
LambdaQueryWrapperX<CrmCustomerDO> queryWrapperX = new LambdaQueryWrapperX<>();
appendQueryParams(queryWrapperX, pageReqVO, userId);
return selectPage(pageReqVO, queryWrapperX
.likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName())
.eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile())
.eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId())
.eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel())
.eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()));
}
default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
// 情况二获取当前用户能看的分页数据
IPage<CrmCustomerDO> mpPage = MyBatisUtils.buildPage(pageReqVO);
MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>();
@ -91,4 +69,28 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> {
return new PageResult<>(mpPage.getRecords(), mpPage.getTotal());
}
static void appendQueryParams(MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
if (pageReqVO.getPool()) { // 情况一公海
mpjLambdaWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
} else { // 情况二不是公海
mpjLambdaWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
}
// TODO 场景数据过滤
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一我负责的数据
mpjLambdaWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
}
}
static void appendQueryParams(LambdaQueryWrapperX<CrmCustomerDO> lambdaQueryWrapperX, CrmCustomerPageReqVO pageReqVO, Long userId) {
if (pageReqVO.getPool()) { // 情况一公海
lambdaQueryWrapperX.isNull(CrmCustomerDO::getOwnerUserId);
} else { // 情况二不是公海
lambdaQueryWrapperX.isNotNull(CrmCustomerDO::getOwnerUserId);
}
// TODO 场景数据过滤
if (CrmSceneEnum.isOwner(pageReqVO.getSceneType())) { // 场景一我负责的数据
lambdaQueryWrapperX.eq(CrmCustomerDO::getOwnerUserId, userId);
}
}
}

View File

@ -100,9 +100,12 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
@Override
public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
// 1.1. TODO 如果是超级管理员
boolean admin = false;
return customerMapper.selectPage(pageReqVO, userId, admin);
if (admin) { // 1.1. 情况一 TODO 如果是管理员
customerMapper.selectPageWithAdmin(pageReqVO, userId);
}
// 1.2. 情况二获取当前用户能看的分页数据
return customerMapper.selectPage(pageReqVO, userId);
}
/**

View File

@ -19,11 +19,10 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ToString(callSuper = true)
public class BannerPageReqVO extends PageParam {
// TODO @puhui999example
@Schema(description = "标题")
@Schema(description = "标题", example = "这是一个标题")
private String title;
@Schema(description = "状态")
@Schema(description = "状态", example = "1")
@InEnum(CommonStatusEnum.class)
private Integer status;