diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java index f1db9c522..59d6ae360 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java @@ -1,19 +1,16 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer.vo; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.module.crm.enums.common.CrmSceneEnum; +import cn.iocoder.yudao.module.crm.framework.vo.CrmBasePageReqVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import javax.validation.constraints.NotNull; - @Schema(description = "管理后台 - CRM 客户分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class CrmCustomerPageReqVO extends PageParam { +public class CrmCustomerPageReqVO extends CrmBasePageReqVO { @Schema(description = "客户名称", example = "赵六") private String name; @@ -30,16 +27,4 @@ public class CrmCustomerPageReqVO extends PageParam { @Schema(description = "客户来源", example = "1") private Integer source; - /** - * 场景类型 - * - * 关联 {@link CrmSceneEnum} - */ - @Schema(description = "场景类型", example = "1") - private Integer sceneType; - - @Schema(description = "是否为公海数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") - @NotNull(message = "是否为公海数据不能为空") - private Boolean pool; - } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java index 09f97a654..a7138f867 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java @@ -3,18 +3,17 @@ package cn.iocoder.yudao.module.crm.dal.mysql.customer; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; -import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; -import cn.iocoder.yudao.module.crm.enums.common.CrmSceneEnum; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; +import cn.iocoder.yudao.module.crm.util.CrmQueryPageUtils; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import org.apache.ibatis.annotations.Mapper; +import java.util.Collection; import java.util.List; /** @@ -31,28 +30,21 @@ public interface CrmCustomerMapper extends BaseMapperX { .set(CrmCustomerDO::getOwnerUserId, ownerUserId)); } - default PageResult selectPageWithAdmin(CrmCustomerPageReqVO pageReqVO, Long userId) { - // 情况一:管理员查看 - LambdaQueryWrapperX 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 selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) { - // 情况二:获取当前用户能看的分页数据 + /** + * 获取客户分页 + * + * @param pageReqVO 请求 + * @param userId 用户编号 + * @param subordinateIds 下属用户编号 + * @param isAdmin 是否为管理 + * @return 客户分页数据 + */ + default PageResult selectPage(CrmCustomerPageReqVO pageReqVO, Long userId, Collection subordinateIds, Boolean isAdmin) { IPage mpPage = MyBatisUtils.buildPage(pageReqVO); MPJLambdaWrapperX mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); // 构建数据权限连表条件 - mpjLambdaWrapperX - .innerJoin(CrmPermissionDO.class, CrmPermissionDO::getBizId, CrmCustomerDO::getId) - .eq(CrmPermissionDO::getBizType, CrmBizTypeEnum.CRM_CUSTOMER.getType()) - .eq(CrmPermissionDO::getUserId, userId); - appendQueryParams(mpjLambdaWrapperX, pageReqVO, userId); + CrmQueryPageUtils.builderQuery(mpjLambdaWrapperX, pageReqVO, userId, + CrmBizTypeEnum.CRM_CUSTOMER.getType(), CrmCustomerDO::getId, subordinateIds, isAdmin); mpjLambdaWrapperX .selectAll(CrmCustomerDO.class) .likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName()) @@ -69,28 +61,4 @@ public interface CrmCustomerMapper extends BaseMapperX { return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); } - static void appendQueryParams(MPJLambdaWrapperX 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 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); - } - } - } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/vo/CrmBasePageReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/vo/CrmBasePageReqVO.java new file mode 100644 index 000000000..d3e75d5c0 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/vo/CrmBasePageReqVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.crm.framework.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.crm.enums.common.CrmSceneEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Schema(description = "管理后台 - CRM 分页 Base Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class CrmBasePageReqVO extends PageParam { + + /** + * 场景类型, 为 null 时则表示全部 + * + * 关联 {@link CrmSceneEnum} + */ + @Schema(description = "场景类型", example = "1") + @InEnum(CrmSceneEnum.class) + private Integer sceneType; + + @Schema(description = "是否为公海数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") + private Boolean pool; // null 则表示为不是公海数据 + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java index 6a1fcfbff..e79995992 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java @@ -110,12 +110,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @Override public PageResult getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) { - boolean admin = false; - if (admin) { // 1.1. 情况一: TODO 如果是管理员; TODO @puhui999:要不如果是超管,就复用 selectPage; - customerMapper.selectPageWithAdmin(pageReqVO, userId); - } - // 1.2. 情况二:获取当前用户能看的分页数据 - return customerMapper.selectPage(pageReqVO, userId); + boolean admin = false; // TODO 如果是管理员 + return customerMapper.selectPage(pageReqVO, userId, adminUserApi.getSubordinateIds(userId), admin); } /** diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java index 21bd5e895..b86335cad 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; /** * Admin 用户 API 接口 @@ -22,6 +23,14 @@ public interface AdminUserApi { */ AdminUserRespDTO getUser(Long id); + /** + * 通过用户 ID 查询用户下属 + * + * @param id 用户编号 + * @return 用户下属用户编号列表 + */ + Set getSubordinateIds(Long id); + /** * 通过用户 ID 查询用户们 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java index adbc694da..6c1fe957f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java @@ -1,14 +1,21 @@ package cn.iocoder.yudao.module.system.api.user; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import cn.iocoder.yudao.module.system.convert.user.UserConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.service.dept.DeptService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.Set; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; /** * Admin 用户 API 实现类 @@ -20,6 +27,8 @@ public class AdminUserApiImpl implements AdminUserApi { @Resource private AdminUserService userService; + @Resource + private DeptService deptService; @Override public AdminUserRespDTO getUser(Long id) { @@ -27,6 +36,22 @@ public class AdminUserApiImpl implements AdminUserApi { return UserConvert.INSTANCE.convert4(user); } + @Override + public Set getSubordinateIds(Long id) { + AdminUserDO user = userService.getUser(id); + if (user == null) { + return null; + } + + Set subordinateIds = null; // 下属用户编号 + DeptDO dept = deptService.getDept(user.getDeptId()); + if (ObjUtil.equal(dept.getLeaderUserId(), id)) { // 校验是否是该部门的负责人 + List users = userService.getUserListByDeptIds(Collections.singletonList(dept.getId())); + subordinateIds = convertSet(users, AdminUserDO::getId); + } + return subordinateIds; + } + @Override public List getUserList(Collection ids) { List users = userService.getUserList(ids);