From 5c395fc1c4ee7e685c1cc407c405e318c55d1ddb Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 8 Dec 2023 15:27:58 +0800 Subject: [PATCH] =?UTF-8?q?CRM:=20=E5=AE=8C=E5=96=84=20code=20review=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E6=8F=90=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E9=87=8D=E6=96=B0=E5=B0=81=E8=A3=85?= =?UTF-8?q?=20CrmQueryWrapperUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../mybatis/core/mapper/BaseMapperX.java | 13 +++ ...rmSceneEnum.java => CrmSceneTypeEnum.java} | 13 ++- .../admin/business/CrmBusinessController.java | 10 +- .../admin/contact/CrmContactController.java | 11 +- .../admin/contract/CrmContractController.java | 8 +- .../customer/vo/CrmCustomerPageReqVO.java | 16 ++- .../receivable/CrmReceivableController.java | 11 +- .../CrmReceivablePlanController.java | 11 +- .../module/crm/controller/package-info.java | 6 -- .../convert/customer/CrmCustomerConvert.java | 3 +- .../dal/mysql/customer/CrmCustomerMapper.java | 37 +++---- .../crm/framework/vo/CrmBasePageReqVO.java | 25 ----- .../service/customer/CrmCustomerService.java | 4 +- .../customer/CrmCustomerServiceImpl.java | 13 +-- .../module/crm/util/CrmQueryPageUtils.java | 66 ------------ .../module/crm/util/CrmQueryWrapperUtils.java | 100 ++++++++++++++++++ .../main/resources/codegen/vue/api/api.js.vm | 15 ++- .../module/system/api/user/AdminUserApi.java | 7 +- .../system/api/user/AdminUserApiImpl.java | 36 ++++--- yudao-server/pom.xml | 10 +- 21 files changed, 223 insertions(+), 194 deletions(-) rename yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/{CrmSceneEnum.java => CrmSceneTypeEnum.java} (77%) delete mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/package-info.java delete mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/vo/CrmBasePageReqVO.java delete mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryPageUtils.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java diff --git a/pom.xml b/pom.xml index df8fc2c6f..26dec77cf 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ - + yudao-module-crm diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index 023611bbc..b0c0f784e 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.extension.toolkit.Db; import com.github.yulichang.base.MPJBaseMapper; import com.github.yulichang.interfaces.MPJBaseJoin; +import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.ibatis.annotations.Param; import java.util.Collection; @@ -40,6 +41,18 @@ public interface BaseMapperX extends MPJBaseMapper { return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); } + default PageResult selectJoinPage(PageParam pageParam, Class clazz, MPJLambdaWrapper lambdaWrapper) { + // 特殊:不分页,直接查询全部 + if (PageParam.PAGE_SIZE_NONE.equals(pageParam.getPageNo())) { + List list = selectJoinList(clazz, lambdaWrapper); + return new PageResult<>(list, (long) list.size()); + } + + IPage mpPage = MyBatisUtils.buildPage(pageParam); + mpPage = selectJoinPage(mpPage, clazz, lambdaWrapper); + return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); + } + default PageResult selectJoinPage(PageParam pageParam, Class resultTypeClass, MPJBaseJoin joinQueryWrapper) { IPage mpPage = MyBatisUtils.buildPage(pageParam); selectJoinPage(mpPage, resultTypeClass, joinQueryWrapper); diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmSceneEnum.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmSceneTypeEnum.java similarity index 77% rename from yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmSceneEnum.java rename to yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmSceneTypeEnum.java index a8d892a90..dc714250d 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmSceneEnum.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmSceneTypeEnum.java @@ -7,7 +7,6 @@ import lombok.Getter; import java.util.Arrays; -// TODO @puhui999:这个枚举,要不改成 CrmSceneTypeEnum /** * CRM 列表检索场景 * @@ -15,14 +14,14 @@ import java.util.Arrays; */ @Getter @AllArgsConstructor -public enum CrmSceneEnum implements IntArrayValuable { +public enum CrmSceneTypeEnum implements IntArrayValuable { OWNER(1, "我负责的"), FOLLOW(2, "我关注的"), - // TODO @puhui999:还有一个我参与的 - SUBORDINATE(3, "下属负责的"); + INVOLVED(3, "我参与的"), + SUBORDINATE(4, "下属负责的"); - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmSceneEnum::getType).toArray(); + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmSceneTypeEnum::getType).toArray(); /** * 场景类型 @@ -41,6 +40,10 @@ public enum CrmSceneEnum implements IntArrayValuable { return ObjUtil.equal(FOLLOW.getType(), type); } + public static boolean isInvolved(Integer type) { + return ObjUtil.equal(INVOLVED.getType(), type); + } + public static boolean isSubordinate(Integer type) { return ObjUtil.equal(SUBORDINATE.getType(), type); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java index 119440378..0c6756bc7 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java @@ -22,13 +22,13 @@ import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; import java.io.IOException; import java.util.List; import java.util.Objects; @@ -102,7 +102,7 @@ public class CrmBusinessController { // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈; Set customerIds = pageResult.getList().stream() .map(CrmBusinessDO::getCustomerId).filter(Objects::nonNull).collect(Collectors.toSet()); - List customerList = customerService.getCustomerList(customerIds); + List customerList = customerService.getCustomerList(customerIds, getLoginUserId()); // 处理商机状态类型名称回显 Set statusTypeIds = pageResult.getList().stream() .map(CrmBusinessDO::getStatusTypeId).filter(Objects::nonNull).collect(Collectors.toSet()); @@ -127,7 +127,7 @@ public class CrmBusinessController { // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈; Set customerIds = pageResult.getList().stream() .map(CrmBusinessDO::getCustomerId).filter(Objects::nonNull).collect(Collectors.toSet()); - List customerList = customerService.getCustomerList(customerIds); + List customerList = customerService.getCustomerList(customerIds, getLoginUserId()); // 处理商机状态类型名称回显 Set statusTypeIds = pageResult.getList().stream() .map(CrmBusinessDO::getStatusTypeId).filter(Objects::nonNull).collect(Collectors.toSet()); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java index df55ef413..811b4758e 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java @@ -22,14 +22,14 @@ import com.google.common.collect.Lists; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; import java.io.IOException; import java.util.Collections; import java.util.List; @@ -95,7 +95,8 @@ public class CrmContactController { Map userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList( NumberUtil.parseLong(contact.getCreator()), contact.getOwnerUserId()))); // 2. 获取客户信息 - List customerList = customerService.getCustomerList(Collections.singletonList(contact.getCustomerId())); + List customerList = customerService.getCustomerList( + Collections.singletonList(contact.getCustomerId()), getLoginUserId()); // 3. 直属上级 List parentContactList = contactService.getContactList(Collections.singletonList(contact.getParentId())); return success(ContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList)); @@ -150,7 +151,7 @@ public class CrmContactController { } // 1. 获取客户列表 List crmCustomerDOList = customerService.getCustomerList( - convertSet(contactList, CrmContactDO::getCustomerId)); + convertSet(contactList, CrmContactDO::getCustomerId), getLoginUserId()); // 2. 获取创建人、负责人列表 Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java index b1581bc62..24426cd5a 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java @@ -18,13 +18,13 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; import java.io.IOException; import java.util.List; import java.util.Map; @@ -124,7 +124,7 @@ public class CrmContractController { } // 1. 获取客户列表 List customerList = customerService.getCustomerList( - convertSet(contactList, CrmContractDO::getCustomerId)); + convertSet(contactList, CrmContractDO::getCustomerId), getLoginUserId()); // 2. 获取创建人、负责人列表 Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); 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 59d6ae360..830b7da6d 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,6 +1,8 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer.vo; -import cn.iocoder.yudao.module.crm.framework.vo.CrmBasePageReqVO; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -10,7 +12,7 @@ import lombok.ToString; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class CrmCustomerPageReqVO extends CrmBasePageReqVO { +public class CrmCustomerPageReqVO extends PageParam { @Schema(description = "客户名称", example = "赵六") private String name; @@ -27,4 +29,14 @@ public class CrmCustomerPageReqVO extends CrmBasePageReqVO { @Schema(description = "客户来源", example = "1") private Integer source; + /** + * 场景类型,为 null 时则表示全部 + */ + @Schema(description = "场景类型", example = "1") + @InEnum(CrmSceneTypeEnum.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/controller/admin/receivable/CrmReceivableController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivableController.java index 45ea6f020..4c4be4a25 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivableController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivableController.java @@ -23,13 +23,13 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; import java.io.IOException; import java.util.List; import java.util.Map; @@ -39,6 +39,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - CRM 回款") @RestController @@ -111,7 +112,7 @@ public class CrmReceivableController { @PreAuthorize("@ss.hasPermission('crm:receivable:export')") @OperateLog(type = EXPORT) public void exportReceivableExcel(@Valid CrmReceivablePageReqVO exportReqVO, - HttpServletResponse response) throws IOException { + HttpServletResponse response) throws IOException { PageResult pageResult = receivableService.getReceivablePage(exportReqVO); // 导出 Excel ExcelUtils.write(response, "回款.xls", "数据", CrmReceivableRespVO.class, @@ -131,7 +132,7 @@ public class CrmReceivableController { } // 1. 获取客户列表 List customerList = customerService.getCustomerList( - convertSet(receivableList, CrmReceivableDO::getCustomerId)); + convertSet(receivableList, CrmReceivableDO::getCustomerId), getLoginUserId()); // 2. 获取创建人、负责人列表 Map userMap = adminUserApi.getUserMap(convertListByFlatMap(receivableList, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivablePlanController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivablePlanController.java index fe569a087..f8e2e6ecd 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivablePlanController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivablePlanController.java @@ -25,13 +25,13 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; import java.io.IOException; import java.util.List; import java.util.Map; @@ -41,6 +41,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - CRM 回款计划") @RestController @@ -115,7 +116,7 @@ public class CrmReceivablePlanController { @PreAuthorize("@ss.hasPermission('crm:receivable-plan:export')") @OperateLog(type = EXPORT) public void exportReceivablePlanExcel(@Valid CrmReceivablePlanPageReqVO exportReqVO, - HttpServletResponse response) throws IOException { + HttpServletResponse response) throws IOException { PageResult pageResult = receivablePlanService.getReceivablePlanPage(exportReqVO); // 导出 Excel ExcelUtils.write(response, "回款计划.xls", "数据", CrmReceivablePlanRespVO.class, @@ -135,7 +136,7 @@ public class CrmReceivablePlanController { } // 1. 获取客户列表 List customerList = customerService.getCustomerList( - convertSet(receivablePlanList, CrmReceivablePlanDO::getCustomerId)); + convertSet(receivablePlanList, CrmReceivablePlanDO::getCustomerId), getLoginUserId()); // 2. 获取创建人、负责人列表 Map userMap = adminUserApi.getUserMap(convertListByFlatMap(receivablePlanList, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/package-info.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/package-info.java deleted file mode 100644 index 8354b3176..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 提供 RESTful API 给前端: - * 1. admin 包:提供给管理后台 yudao-ui-admin 前端项目 - * 2. app 包:提供给用户 APP yudao-ui-app 前端项目,它的 Controller 和 VO 都要添加 App 前缀,用于和管理后台进行区分 - */ -package cn.iocoder.yudao.module.crm.controller; diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java index fcf643f66..0e21b26b8 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java @@ -55,8 +55,7 @@ public interface CrmCustomerConvert { List convertList02(List list); @Mappings({ - @Mapping(target = "bizId", source = "reqVO.id"), - @Mapping(target = "newOwnerUserId", source = "reqVO.id") + @Mapping(target = "bizId", source = "reqVO.id") }) CrmPermissionTransferReqBO convert(CrmCustomerTransferReqVO reqVO, Long userId); 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 0ce9d9f03..9c29c668f 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 @@ -1,16 +1,13 @@ 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.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.enums.common.CrmBizTypeEnum; -import cn.iocoder.yudao.module.crm.util.CrmQueryPageUtils; +import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils; 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; @@ -30,35 +27,25 @@ public interface CrmCustomerMapper extends BaseMapperX { .set(CrmCustomerDO::getOwnerUserId, ownerUserId)); } - /** - * 获取客户分页 - * - * @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); + default PageResult selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) { MPJLambdaWrapperX mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); // 构建数据权限连表条件 - CrmQueryPageUtils.builderQuery(mpjLambdaWrapperX, pageReqVO, userId, - CrmBizTypeEnum.CRM_CUSTOMER.getType(), CrmCustomerDO::getId, subordinateIds, isAdmin); + CrmQueryWrapperUtils.builderPageQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CUSTOMER.getType(), CrmCustomerDO::getId, + userId, pageReqVO.getSceneType(), pageReqVO.getPool()); mpjLambdaWrapperX.selectAll(CrmCustomerDO.class) .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()); - // 特殊:不分页,直接查询全部 - // TODO @puhui999:下面这个,封装一个方法;从 56 到 61 这里哈; - if (PageParam.PAGE_SIZE_NONE.equals(pageReqVO.getPageNo())) { - List list = selectJoinList(CrmCustomerDO.class, mpjLambdaWrapperX); - return new PageResult<>(list, (long) list.size()); - } - mpPage = selectJoinPage(mpPage, CrmCustomerDO.class, mpjLambdaWrapperX); - return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); + return selectJoinPage(pageReqVO, CrmCustomerDO.class, mpjLambdaWrapperX); + } + + default List selectBatchIds(Collection ids, Long userId) { + MPJLambdaWrapperX mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); + // 构建数据权限连表条件 + CrmQueryWrapperUtils.builderListQueryBatch(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CUSTOMER.getType(), ids, userId); + return selectJoinList(CrmCustomerDO.class, mpjLambdaWrapperX); } } 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 deleted file mode 100644 index 14070fa19..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/vo/CrmBasePageReqVO.java +++ /dev/null @@ -1,25 +0,0 @@ -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 时则表示全部 - */ - @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/CrmCustomerService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java index bf22413d4..1bd1fee47 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java @@ -6,8 +6,8 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageR import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; - import jakarta.validation.Valid; + import java.util.Collection; import java.util.List; @@ -56,7 +56,7 @@ public interface CrmCustomerService { * @return 客户列表 * @author ljlleo */ - List getCustomerList(Collection ids); + List getCustomerList(Collection ids, Long userId); /** * 获得客户分页 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 e3723c281..2460a33fb 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 @@ -15,11 +15,11 @@ import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import jakarta.annotation.Resource; import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -93,17 +93,16 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { } @Override - public List getCustomerList(Collection ids) { + public List getCustomerList(Collection ids, Long userId) { if (CollUtil.isEmpty(ids)) { return Collections.emptyList(); } - return customerMapper.selectBatchIds(ids); + return customerMapper.selectBatchIds(ids, userId); } @Override public PageResult getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) { - boolean admin = false; // TODO 如果是管理员 - return customerMapper.selectPage(pageReqVO, userId, adminUserApi.getSubordinateIds(userId), admin); + return customerMapper.selectPage(pageReqVO, userId); } /** @@ -128,9 +127,11 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { // 1. 校验客户是否存在 validateCustomer(reqVO.getId()); - // 2. 数据权限转移 + // 2.1 数据权限转移 crmPermissionService.transferPermission( CrmCustomerConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())); + // 2.2 转移后重新设置负责人 + customerMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId()); // 3. TODO 记录转移日志 } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryPageUtils.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryPageUtils.java deleted file mode 100644 index 5830a24a3..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryPageUtils.java +++ /dev/null @@ -1,66 +0,0 @@ -package cn.iocoder.yudao.module.crm.util; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjUtil; -import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; -import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; -import cn.iocoder.yudao.module.crm.enums.common.CrmSceneEnum; -import cn.iocoder.yudao.module.crm.framework.vo.CrmBasePageReqVO; -import com.baomidou.mybatisplus.core.toolkit.support.SFunction; -import com.github.yulichang.wrapper.MPJLambdaWrapper; - -import jakarta.annotation.Nullable; -import java.util.Collection; - -/** - * CRM 分页查询工具类 - * - * @author HUIHUI - */ -public class CrmQueryPageUtils { - - // TODO @puhui999:是不是弱化 CrmBasePageReqVO,把 sceneType 作为参数传入。默认其实 pool 不一定要传递的 - /** - * 构造 CRM 数据类型数据分页查询条件 - * - * @param queryMapper 连表查询对象 - * @param reqVO 查询条件 - * @param userId 用户编号 - * @param bizType 数据类型 {@link CrmBizTypeEnum} - * @param bizId 数据编号 - * @param subordinateIds 下属用户编号,可为空 - */ - public static , V extends CrmBasePageReqVO, S> void builderQuery( - T queryMapper, V reqVO, Long userId, - Integer bizType, SFunction bizId, - @Nullable Collection subordinateIds, // TODO @puhui999:subordinateIds 可以优化成 subordinateUserIds - Boolean isAdmin) { - // TODO @puhui999:是不是特殊处理,让这个 util 有状态,这样 isAdmin 直接从这里读取;subordinateIds 也是;这样,可以简化参数; - // 1. 构建数据权限连表条件 - if (ObjUtil.notEqual(isAdmin, Boolean.TRUE)) { // 管理员不需要数据权限 - queryMapper.innerJoin(CrmPermissionDO.class, on -> - on.eq(CrmPermissionDO::getBizType, bizType).eq(CrmPermissionDO::getBizId, bizId) - .eq(CrmPermissionDO::getUserId, userId)); - } - // 2. 拼接公海的查询条件 - if (ObjUtil.equal(reqVO.getPool(), Boolean.TRUE)) { // 情况一:公海 - queryMapper.isNull("owner_user_id"); - } else { // 情况二:不是公海 - queryMapper.isNotNull("owner_user_id"); - } - // 3. 拼接场景的查询条件 - // TODO @puhui999::1 处的数据权限,应该和 3 处的场景是结合的? - // null 时:一种处理 - // 1:一种条件; - // 2:一种条件; - // 3:一种条件; - if (CrmSceneEnum.isOwner(reqVO.getSceneType())) { // 场景一:我负责的数据 - queryMapper.eq("owner_user_id", userId); - } - // TODO puhui999: 这里有一个疑问:如果下属负责的数据权限中没有自己的话还能看吗?回复:不能 - if (CrmSceneEnum.isSubordinate(reqVO.getSceneType()) && CollUtil.isNotEmpty(subordinateIds)) { // 场景三:下属负责的数据 - queryMapper.in("owner_user_id", subordinateIds); - } - } - -} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java new file mode 100644 index 000000000..23e422332 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java @@ -0,0 +1,100 @@ +package cn.iocoder.yudao.module.crm.util; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; +import cn.hutool.extra.spring.SpringUtil; +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; +import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.github.yulichang.wrapper.MPJLambdaWrapper; + +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; + +/** + * CRM 分页查询工具类 + * + * @author HUIHUI + */ +public class CrmQueryWrapperUtils { + + /** + * 构造 CRM 数据类型数据分页查询条件 + * + * @param queryMapper 连表查询对象 + * @param bizType 数据类型 {@link CrmBizTypeEnum} + * @param bizId 数据编号 + * @param userId 用户编号 + * @param sceneType 场景类型 + * @param pool 公海 + */ + public static , S> void builderPageQuery( + T queryMapper, Integer bizType, SFunction bizId, Long userId, Integer sceneType, Boolean pool) { + // 1. 构建数据权限连表条件 + if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 + queryMapper.innerJoin(CrmPermissionDO.class, on -> + on.eq(CrmPermissionDO::getBizType, bizType).eq(CrmPermissionDO::getBizId, bizId) + .eq(CrmPermissionDO::getUserId, userId)); + } + // 1.2 场景一:我负责的数据 + if (CrmSceneTypeEnum.isOwner(sceneType)) { + queryMapper.eq("owner_user_id", userId); + } + // 1.3 场景一:我参与的数据 + if (CrmSceneTypeEnum.isInvolved(sceneType)) { + queryMapper.ne("owner_user_id", userId); + } + // 1.4 场景二:下属负责的数据 + if (CrmSceneTypeEnum.isSubordinate(sceneType)) { + List subordinateUsers = getAdminUserApi().getUserListBySubordinate(userId); + if (CollUtil.isNotEmpty(subordinateUsers)) { + queryMapper.in("owner_user_id", convertSet(subordinateUsers, AdminUserRespDTO::getId)); + } + } + + // 2. 拼接公海的查询条件 + if (ObjUtil.equal(pool, Boolean.TRUE)) { // 情况一:公海 + queryMapper.isNull("owner_user_id"); + } else { // 情况二:不是公海 + queryMapper.isNotNull("owner_user_id"); + } + } + + /** + * 构造 CRM 数据类型批量数据查询条件 + * + * @param queryMapper 连表查询对象 + * @param bizType 数据类型 {@link CrmBizTypeEnum} + * @param bizIds 数据编号 + * @param userId 用户编号 + */ + public static , S> void builderListQueryBatch( + T queryMapper, Integer bizType, Collection bizIds, Long userId) { + // 1. 构建数据权限连表条件 + if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 + queryMapper.innerJoin(CrmPermissionDO.class, on -> + on.eq(CrmPermissionDO::getBizType, bizType).in(CrmPermissionDO::getBizId, bizIds) + .eq(CrmPermissionDO::getUserId, userId)); + } + } + + private static AdminUserApi getAdminUserApi() { + return SpringUtil.getBean(AdminUserApi.class); + } + + /** + * 校验用户是否是管理员 + * + * @param userId 用户编号 + * @return 是/否 + */ + private static boolean validateAdminUser(Long userId) { + return false; + } + +} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm index bfe2dc007..fcc2e9197 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm @@ -77,7 +77,6 @@ export function export${simpleClassName}Excel(params) { // ==================== 子表($subTable.classComment) ==================== ## 情况一:MASTER_ERP 时,需要分查询页子表 #if ( $table.templateType == 11 ) - // 获得${subTable.classComment}分页 export function get${subSimpleClassName}Page(params) { return request({ @@ -89,20 +88,18 @@ export function export${simpleClassName}Excel(params) { ## 情况二:非 MASTER_ERP 时,需要列表查询子表 #else #if ( $subTable.subJoinMany ) - // 获得${subTable.classComment}列表 export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}) { return request({ - url: `${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField}, + url: '${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=' + ${subJoinColumn.javaField}, method: 'get' }) } #else - // 获得${subTable.classComment} export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}) { return request({ - url: `${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField}, + url: '${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=' + ${subJoinColumn.javaField}, method: 'get' }) } @@ -113,7 +110,7 @@ export function export${simpleClassName}Excel(params) { // 新增${subTable.classComment} export function create${subSimpleClassName}(data) { return request({ - url: `${baseURL}/${subSimpleClassName_strikeCase}/create`, + url: '${baseURL}/${subSimpleClassName_strikeCase}/create', method: 'post', data }) @@ -122,7 +119,7 @@ export function export${simpleClassName}Excel(params) { // 修改${subTable.classComment} export function update${subSimpleClassName}(data) { return request({ - url: `${baseURL}/${subSimpleClassName_strikeCase}/update`, + url: '${baseURL}/${subSimpleClassName_strikeCase}/update', method: 'post', data }) @@ -131,7 +128,7 @@ export function export${simpleClassName}Excel(params) { // 删除${subTable.classComment} export function delete${subSimpleClassName}(id) { return request({ - url: `${baseURL}/${subSimpleClassName_strikeCase}/delete?id=` + id, + url: '${baseURL}/${subSimpleClassName_strikeCase}/delete?id=' + id, method: 'delete' }) } @@ -139,7 +136,7 @@ export function export${simpleClassName}Excel(params) { // 获得${subTable.classComment} export function get${subSimpleClassName}(id) { return request({ - url: `${baseURL}/${subSimpleClassName_strikeCase}/get?id=` + id, + url: '${baseURL}/${subSimpleClassName_strikeCase}/get?id=' + id, method: 'get' }) } 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 39f65d3e7..c4510ba08 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,7 +6,6 @@ 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 接口 @@ -27,10 +26,10 @@ public interface AdminUserApi { /** * 通过用户 ID 查询用户下属 * - * @param id 用户编号 - * @return 用户下属用户编号列表 + * @param userId 用户编号 + * @return 用户下属用户列表 */ - Set getSubordinateIds(Long id); + List getUserListBySubordinate(Long userId); /** * 通过用户 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 25bba01b0..c7055114e 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,5 +1,6 @@ package cn.iocoder.yudao.module.system.api.user; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; @@ -7,13 +8,13 @@ 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 jakarta.annotation.Resource; import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; +import java.util.ArrayList; 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; @@ -37,21 +38,32 @@ public class AdminUserApiImpl implements AdminUserApi { } @Override - public Set getSubordinateIds(Long id) { - AdminUserDO user = userService.getUser(id); + public List getUserListBySubordinate(Long userId) { + // 1. 获取用户信息 + AdminUserDO user = userService.getUser(userId); if (user == null) { - return null; + return Collections.emptyList(); } - Set subordinateIds = null; // 下属用户编号 + // 2.1 获取用户负责的部门 + ArrayList deptIds = new ArrayList<>(); DeptDO dept = deptService.getDept(user.getDeptId()); - // TODO @puhui999:需要递归查询到子部门;并且要排除到自己噢。 - // TODO @puhui999:保持 if return 原则,这里其实要判断不等于,则返回 null;最好返回 空集合,上面也是 - if (ObjUtil.equal(dept.getLeaderUserId(), id)) { // 校验是否是该部门的负责人 - List users = userService.getUserListByDeptIds(Collections.singletonList(dept.getId())); - subordinateIds = convertSet(users, AdminUserDO::getId); + if (dept == null) { + return Collections.emptyList(); } - return subordinateIds; + if (ObjUtil.notEqual(dept.getLeaderUserId(), userId)) { // 校验为负责人 + return Collections.emptyList(); + } + deptIds.add(dept.getId()); // 加入此部门 + // 2.2 获取所有子部门 + List childDeptList = deptService.getChildDeptList(dept.getId()); + if (CollUtil.isNotEmpty(childDeptList)) { + deptIds.addAll(convertSet(childDeptList, DeptDO::getId)); + } + // 2.3 获取用户信息 + List users = userService.getUserListByDeptIds(deptIds); + users.removeIf(item -> ObjUtil.equal(item.getId(), userId)); // 排除自己 + return BeanUtils.toBean(users, AdminUserRespDTO.class); } @Override diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index 20b67725b..40086477b 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -92,11 +92,11 @@ - - - - - + + cn.iocoder.boot + yudao-module-crm-biz + ${revision} +