Commit 5c395fc1c4ee7e685c1cc407c405e318c55d1ddb
1 parent
db62d70f
CRM: 完善 code review 数据权限提到的问题,重新封装 CrmQueryWrapperUtils
Showing
21 changed files
with
223 additions
and
194 deletions
pom.xml
| ... | ... | @@ -21,7 +21,7 @@ |
| 21 | 21 | <!-- <module>yudao-module-mp</module>--> |
| 22 | 22 | <!-- <module>yudao-module-pay</module>--> |
| 23 | 23 | <!-- <module>yudao-module-mall</module>--> |
| 24 | -<!-- <module>yudao-module-crm</module>--> | |
| 24 | + <module>yudao-module-crm</module> | |
| 25 | 25 | <!-- 示例项目 --> |
| 26 | 26 | <!-- <module>yudao-example</module>--> |
| 27 | 27 | </modules> | ... | ... |
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; |
| 13 | 13 | import com.baomidou.mybatisplus.extension.toolkit.Db; |
| 14 | 14 | import com.github.yulichang.base.MPJBaseMapper; |
| 15 | 15 | import com.github.yulichang.interfaces.MPJBaseJoin; |
| 16 | +import com.github.yulichang.wrapper.MPJLambdaWrapper; | |
| 16 | 17 | import org.apache.ibatis.annotations.Param; |
| 17 | 18 | |
| 18 | 19 | import java.util.Collection; |
| ... | ... | @@ -40,6 +41,18 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> { |
| 40 | 41 | return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); |
| 41 | 42 | } |
| 42 | 43 | |
| 44 | + default <D> PageResult<D> selectJoinPage(PageParam pageParam, Class<D> clazz, MPJLambdaWrapper<T> lambdaWrapper) { | |
| 45 | + // 特殊:不分页,直接查询全部 | |
| 46 | + if (PageParam.PAGE_SIZE_NONE.equals(pageParam.getPageNo())) { | |
| 47 | + List<D> list = selectJoinList(clazz, lambdaWrapper); | |
| 48 | + return new PageResult<>(list, (long) list.size()); | |
| 49 | + } | |
| 50 | + | |
| 51 | + IPage<D> mpPage = MyBatisUtils.buildPage(pageParam); | |
| 52 | + mpPage = selectJoinPage(mpPage, clazz, lambdaWrapper); | |
| 53 | + return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); | |
| 54 | + } | |
| 55 | + | |
| 43 | 56 | default <DTO> PageResult<DTO> selectJoinPage(PageParam pageParam, Class<DTO> resultTypeClass, MPJBaseJoin<T> joinQueryWrapper) { |
| 44 | 57 | IPage<DTO> mpPage = MyBatisUtils.buildPage(pageParam); |
| 45 | 58 | selectJoinPage(mpPage, resultTypeClass, joinQueryWrapper); | ... | ... |
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmSceneEnum.java renamed to 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; |
| 7 | 7 | |
| 8 | 8 | import java.util.Arrays; |
| 9 | 9 | |
| 10 | -// TODO @puhui999:这个枚举,要不改成 CrmSceneTypeEnum | |
| 11 | 10 | /** |
| 12 | 11 | * CRM 列表检索场景 |
| 13 | 12 | * |
| ... | ... | @@ -15,14 +14,14 @@ import java.util.Arrays; |
| 15 | 14 | */ |
| 16 | 15 | @Getter |
| 17 | 16 | @AllArgsConstructor |
| 18 | -public enum CrmSceneEnum implements IntArrayValuable { | |
| 17 | +public enum CrmSceneTypeEnum implements IntArrayValuable { | |
| 19 | 18 | |
| 20 | 19 | OWNER(1, "我负责的"), |
| 21 | 20 | FOLLOW(2, "我关注的"), |
| 22 | - // TODO @puhui999:还有一个我参与的 | |
| 23 | - SUBORDINATE(3, "下属负责的"); | |
| 21 | + INVOLVED(3, "我参与的"), | |
| 22 | + SUBORDINATE(4, "下属负责的"); | |
| 24 | 23 | |
| 25 | - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmSceneEnum::getType).toArray(); | |
| 24 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmSceneTypeEnum::getType).toArray(); | |
| 26 | 25 | |
| 27 | 26 | /** |
| 28 | 27 | * 场景类型 |
| ... | ... | @@ -41,6 +40,10 @@ public enum CrmSceneEnum implements IntArrayValuable { |
| 41 | 40 | return ObjUtil.equal(FOLLOW.getType(), type); |
| 42 | 41 | } |
| 43 | 42 | |
| 43 | + public static boolean isInvolved(Integer type) { | |
| 44 | + return ObjUtil.equal(INVOLVED.getType(), type); | |
| 45 | + } | |
| 46 | + | |
| 44 | 47 | public static boolean isSubordinate(Integer type) { |
| 45 | 48 | return ObjUtil.equal(SUBORDINATE.getType(), type); |
| 46 | 49 | } | ... | ... |
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; |
| 22 | 22 | import io.swagger.v3.oas.annotations.Operation; |
| 23 | 23 | import io.swagger.v3.oas.annotations.Parameter; |
| 24 | 24 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 25 | +import jakarta.annotation.Resource; | |
| 26 | +import jakarta.servlet.http.HttpServletResponse; | |
| 27 | +import jakarta.validation.Valid; | |
| 25 | 28 | import org.springframework.security.access.prepost.PreAuthorize; |
| 26 | 29 | import org.springframework.validation.annotation.Validated; |
| 27 | 30 | import org.springframework.web.bind.annotation.*; |
| 28 | 31 | |
| 29 | -import jakarta.annotation.Resource; | |
| 30 | -import jakarta.servlet.http.HttpServletResponse; | |
| 31 | -import jakarta.validation.Valid; | |
| 32 | 32 | import java.io.IOException; |
| 33 | 33 | import java.util.List; |
| 34 | 34 | import java.util.Objects; |
| ... | ... | @@ -102,7 +102,7 @@ public class CrmBusinessController { |
| 102 | 102 | // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈; |
| 103 | 103 | Set<Long> customerIds = pageResult.getList().stream() |
| 104 | 104 | .map(CrmBusinessDO::getCustomerId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| 105 | - List<CrmCustomerDO> customerList = customerService.getCustomerList(customerIds); | |
| 105 | + List<CrmCustomerDO> customerList = customerService.getCustomerList(customerIds, getLoginUserId()); | |
| 106 | 106 | // 处理商机状态类型名称回显 |
| 107 | 107 | Set<Long> statusTypeIds = pageResult.getList().stream() |
| 108 | 108 | .map(CrmBusinessDO::getStatusTypeId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| ... | ... | @@ -127,7 +127,7 @@ public class CrmBusinessController { |
| 127 | 127 | // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈; |
| 128 | 128 | Set<Long> customerIds = pageResult.getList().stream() |
| 129 | 129 | .map(CrmBusinessDO::getCustomerId).filter(Objects::nonNull).collect(Collectors.toSet()); |
| 130 | - List<CrmCustomerDO> customerList = customerService.getCustomerList(customerIds); | |
| 130 | + List<CrmCustomerDO> customerList = customerService.getCustomerList(customerIds, getLoginUserId()); | |
| 131 | 131 | // 处理商机状态类型名称回显 |
| 132 | 132 | Set<Long> statusTypeIds = pageResult.getList().stream() |
| 133 | 133 | .map(CrmBusinessDO::getStatusTypeId).filter(Objects::nonNull).collect(Collectors.toSet()); | ... | ... |
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; |
| 22 | 22 | import io.swagger.v3.oas.annotations.Operation; |
| 23 | 23 | import io.swagger.v3.oas.annotations.Parameter; |
| 24 | 24 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 25 | +import jakarta.annotation.Resource; | |
| 26 | +import jakarta.servlet.http.HttpServletResponse; | |
| 27 | +import jakarta.validation.Valid; | |
| 25 | 28 | import lombok.extern.slf4j.Slf4j; |
| 26 | 29 | import org.springframework.security.access.prepost.PreAuthorize; |
| 27 | 30 | import org.springframework.validation.annotation.Validated; |
| 28 | 31 | import org.springframework.web.bind.annotation.*; |
| 29 | 32 | |
| 30 | -import jakarta.annotation.Resource; | |
| 31 | -import jakarta.servlet.http.HttpServletResponse; | |
| 32 | -import jakarta.validation.Valid; | |
| 33 | 33 | import java.io.IOException; |
| 34 | 34 | import java.util.Collections; |
| 35 | 35 | import java.util.List; |
| ... | ... | @@ -95,7 +95,8 @@ public class CrmContactController { |
| 95 | 95 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList( |
| 96 | 96 | NumberUtil.parseLong(contact.getCreator()), contact.getOwnerUserId()))); |
| 97 | 97 | // 2. 获取客户信息 |
| 98 | - List<CrmCustomerDO> customerList = customerService.getCustomerList(Collections.singletonList(contact.getCustomerId())); | |
| 98 | + List<CrmCustomerDO> customerList = customerService.getCustomerList( | |
| 99 | + Collections.singletonList(contact.getCustomerId()), getLoginUserId()); | |
| 99 | 100 | // 3. 直属上级 |
| 100 | 101 | List<CrmContactDO> parentContactList = contactService.getContactList(Collections.singletonList(contact.getParentId())); |
| 101 | 102 | return success(ContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList)); |
| ... | ... | @@ -150,7 +151,7 @@ public class CrmContactController { |
| 150 | 151 | } |
| 151 | 152 | // 1. 获取客户列表 |
| 152 | 153 | List<CrmCustomerDO> crmCustomerDOList = customerService.getCustomerList( |
| 153 | - convertSet(contactList, CrmContactDO::getCustomerId)); | |
| 154 | + convertSet(contactList, CrmContactDO::getCustomerId), getLoginUserId()); | |
| 154 | 155 | // 2. 获取创建人、负责人列表 |
| 155 | 156 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, |
| 156 | 157 | contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); | ... | ... |
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; |
| 18 | 18 | import io.swagger.v3.oas.annotations.Operation; |
| 19 | 19 | import io.swagger.v3.oas.annotations.Parameter; |
| 20 | 20 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 21 | +import jakarta.annotation.Resource; | |
| 22 | +import jakarta.servlet.http.HttpServletResponse; | |
| 23 | +import jakarta.validation.Valid; | |
| 21 | 24 | import org.springframework.security.access.prepost.PreAuthorize; |
| 22 | 25 | import org.springframework.validation.annotation.Validated; |
| 23 | 26 | import org.springframework.web.bind.annotation.*; |
| 24 | 27 | |
| 25 | -import jakarta.annotation.Resource; | |
| 26 | -import jakarta.servlet.http.HttpServletResponse; | |
| 27 | -import jakarta.validation.Valid; | |
| 28 | 28 | import java.io.IOException; |
| 29 | 29 | import java.util.List; |
| 30 | 30 | import java.util.Map; |
| ... | ... | @@ -124,7 +124,7 @@ public class CrmContractController { |
| 124 | 124 | } |
| 125 | 125 | // 1. 获取客户列表 |
| 126 | 126 | List<CrmCustomerDO> customerList = customerService.getCustomerList( |
| 127 | - convertSet(contactList, CrmContractDO::getCustomerId)); | |
| 127 | + convertSet(contactList, CrmContractDO::getCustomerId), getLoginUserId()); | |
| 128 | 128 | // 2. 获取创建人、负责人列表 |
| 129 | 129 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, |
| 130 | 130 | contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerPageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.controller.admin.customer.vo; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.crm.framework.vo.CrmBasePageReqVO; | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum; | |
| 4 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 7 | import lombok.Data; |
| 6 | 8 | import lombok.EqualsAndHashCode; |
| ... | ... | @@ -10,7 +12,7 @@ import lombok.ToString; |
| 10 | 12 | @Data |
| 11 | 13 | @EqualsAndHashCode(callSuper = true) |
| 12 | 14 | @ToString(callSuper = true) |
| 13 | -public class CrmCustomerPageReqVO extends CrmBasePageReqVO { | |
| 15 | +public class CrmCustomerPageReqVO extends PageParam { | |
| 14 | 16 | |
| 15 | 17 | @Schema(description = "客户名称", example = "赵六") |
| 16 | 18 | private String name; |
| ... | ... | @@ -27,4 +29,14 @@ public class CrmCustomerPageReqVO extends CrmBasePageReqVO { |
| 27 | 29 | @Schema(description = "客户来源", example = "1") |
| 28 | 30 | private Integer source; |
| 29 | 31 | |
| 32 | + /** | |
| 33 | + * 场景类型,为 null 时则表示全部 | |
| 34 | + */ | |
| 35 | + @Schema(description = "场景类型", example = "1") | |
| 36 | + @InEnum(CrmSceneTypeEnum.class) | |
| 37 | + private Integer sceneType; | |
| 38 | + | |
| 39 | + @Schema(description = "是否为公海数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") | |
| 40 | + private Boolean pool; // null 则表示为不是公海数据 | |
| 41 | + | |
| 30 | 42 | } | ... | ... |
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; |
| 23 | 23 | import io.swagger.v3.oas.annotations.Operation; |
| 24 | 24 | import io.swagger.v3.oas.annotations.Parameter; |
| 25 | 25 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 26 | +import jakarta.annotation.Resource; | |
| 27 | +import jakarta.servlet.http.HttpServletResponse; | |
| 28 | +import jakarta.validation.Valid; | |
| 26 | 29 | import org.springframework.security.access.prepost.PreAuthorize; |
| 27 | 30 | import org.springframework.validation.annotation.Validated; |
| 28 | 31 | import org.springframework.web.bind.annotation.*; |
| 29 | 32 | |
| 30 | -import jakarta.annotation.Resource; | |
| 31 | -import jakarta.servlet.http.HttpServletResponse; | |
| 32 | -import jakarta.validation.Valid; | |
| 33 | 33 | import java.io.IOException; |
| 34 | 34 | import java.util.List; |
| 35 | 35 | import java.util.Map; |
| ... | ... | @@ -39,6 +39,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 39 | 39 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap; |
| 40 | 40 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 41 | 41 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 42 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 42 | 43 | |
| 43 | 44 | @Tag(name = "管理后台 - CRM 回款") |
| 44 | 45 | @RestController |
| ... | ... | @@ -111,7 +112,7 @@ public class CrmReceivableController { |
| 111 | 112 | @PreAuthorize("@ss.hasPermission('crm:receivable:export')") |
| 112 | 113 | @OperateLog(type = EXPORT) |
| 113 | 114 | public void exportReceivableExcel(@Valid CrmReceivablePageReqVO exportReqVO, |
| 114 | - HttpServletResponse response) throws IOException { | |
| 115 | + HttpServletResponse response) throws IOException { | |
| 115 | 116 | PageResult<CrmReceivableDO> pageResult = receivableService.getReceivablePage(exportReqVO); |
| 116 | 117 | // 导出 Excel |
| 117 | 118 | ExcelUtils.write(response, "回款.xls", "数据", CrmReceivableRespVO.class, |
| ... | ... | @@ -131,7 +132,7 @@ public class CrmReceivableController { |
| 131 | 132 | } |
| 132 | 133 | // 1. 获取客户列表 |
| 133 | 134 | List<CrmCustomerDO> customerList = customerService.getCustomerList( |
| 134 | - convertSet(receivableList, CrmReceivableDO::getCustomerId)); | |
| 135 | + convertSet(receivableList, CrmReceivableDO::getCustomerId), getLoginUserId()); | |
| 135 | 136 | // 2. 获取创建人、负责人列表 |
| 136 | 137 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(receivableList, |
| 137 | 138 | contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); | ... | ... |
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; |
| 25 | 25 | import io.swagger.v3.oas.annotations.Operation; |
| 26 | 26 | import io.swagger.v3.oas.annotations.Parameter; |
| 27 | 27 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 28 | +import jakarta.annotation.Resource; | |
| 29 | +import jakarta.servlet.http.HttpServletResponse; | |
| 30 | +import jakarta.validation.Valid; | |
| 28 | 31 | import org.springframework.security.access.prepost.PreAuthorize; |
| 29 | 32 | import org.springframework.validation.annotation.Validated; |
| 30 | 33 | import org.springframework.web.bind.annotation.*; |
| 31 | 34 | |
| 32 | -import jakarta.annotation.Resource; | |
| 33 | -import jakarta.servlet.http.HttpServletResponse; | |
| 34 | -import jakarta.validation.Valid; | |
| 35 | 35 | import java.io.IOException; |
| 36 | 36 | import java.util.List; |
| 37 | 37 | import java.util.Map; |
| ... | ... | @@ -41,6 +41,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 41 | 41 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap; |
| 42 | 42 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 43 | 43 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 44 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 44 | 45 | |
| 45 | 46 | @Tag(name = "管理后台 - CRM 回款计划") |
| 46 | 47 | @RestController |
| ... | ... | @@ -115,7 +116,7 @@ public class CrmReceivablePlanController { |
| 115 | 116 | @PreAuthorize("@ss.hasPermission('crm:receivable-plan:export')") |
| 116 | 117 | @OperateLog(type = EXPORT) |
| 117 | 118 | public void exportReceivablePlanExcel(@Valid CrmReceivablePlanPageReqVO exportReqVO, |
| 118 | - HttpServletResponse response) throws IOException { | |
| 119 | + HttpServletResponse response) throws IOException { | |
| 119 | 120 | PageResult<CrmReceivablePlanDO> pageResult = receivablePlanService.getReceivablePlanPage(exportReqVO); |
| 120 | 121 | // 导出 Excel |
| 121 | 122 | ExcelUtils.write(response, "回款计划.xls", "数据", CrmReceivablePlanRespVO.class, |
| ... | ... | @@ -135,7 +136,7 @@ public class CrmReceivablePlanController { |
| 135 | 136 | } |
| 136 | 137 | // 1. 获取客户列表 |
| 137 | 138 | List<CrmCustomerDO> customerList = customerService.getCustomerList( |
| 138 | - convertSet(receivablePlanList, CrmReceivablePlanDO::getCustomerId)); | |
| 139 | + convertSet(receivablePlanList, CrmReceivablePlanDO::getCustomerId), getLoginUserId()); | |
| 139 | 140 | // 2. 获取创建人、负责人列表 |
| 140 | 141 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(receivablePlanList, |
| 141 | 142 | contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/package-info.java deleted
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 { |
| 55 | 55 | List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list); |
| 56 | 56 | |
| 57 | 57 | @Mappings({ |
| 58 | - @Mapping(target = "bizId", source = "reqVO.id"), | |
| 59 | - @Mapping(target = "newOwnerUserId", source = "reqVO.id") | |
| 58 | + @Mapping(target = "bizId", source = "reqVO.id") | |
| 60 | 59 | }) |
| 61 | 60 | CrmPermissionTransferReqBO convert(CrmCustomerTransferReqVO reqVO, Long userId); |
| 62 | 61 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/customer/CrmCustomerMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.dal.mysql.customer; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; |
| 7 | -import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; | |
| 8 | 6 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; |
| 9 | 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 10 | 8 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; |
| 11 | -import cn.iocoder.yudao.module.crm.util.CrmQueryPageUtils; | |
| 9 | +import cn.iocoder.yudao.module.crm.util.CrmQueryWrapperUtils; | |
| 12 | 10 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 13 | -import com.baomidou.mybatisplus.core.metadata.IPage; | |
| 14 | 11 | import org.apache.ibatis.annotations.Mapper; |
| 15 | 12 | |
| 16 | 13 | import java.util.Collection; |
| ... | ... | @@ -30,35 +27,25 @@ public interface CrmCustomerMapper extends BaseMapperX<CrmCustomerDO> { |
| 30 | 27 | .set(CrmCustomerDO::getOwnerUserId, ownerUserId)); |
| 31 | 28 | } |
| 32 | 29 | |
| 33 | - /** | |
| 34 | - * 获取客户分页 | |
| 35 | - * | |
| 36 | - * @param pageReqVO 请求 | |
| 37 | - * @param userId 用户编号 | |
| 38 | - * @param subordinateIds 下属用户编号 | |
| 39 | - * @param isAdmin 是否为管理 | |
| 40 | - * @return 客户分页数据 | |
| 41 | - */ | |
| 42 | - default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId, Collection<Long> subordinateIds, Boolean isAdmin) { | |
| 43 | - IPage<CrmCustomerDO> mpPage = MyBatisUtils.buildPage(pageReqVO); | |
| 30 | + default PageResult<CrmCustomerDO> selectPage(CrmCustomerPageReqVO pageReqVO, Long userId) { | |
| 44 | 31 | MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); |
| 45 | 32 | // 构建数据权限连表条件 |
| 46 | - CrmQueryPageUtils.builderQuery(mpjLambdaWrapperX, pageReqVO, userId, | |
| 47 | - CrmBizTypeEnum.CRM_CUSTOMER.getType(), CrmCustomerDO::getId, subordinateIds, isAdmin); | |
| 33 | + CrmQueryWrapperUtils.builderPageQuery(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CUSTOMER.getType(), CrmCustomerDO::getId, | |
| 34 | + userId, pageReqVO.getSceneType(), pageReqVO.getPool()); | |
| 48 | 35 | mpjLambdaWrapperX.selectAll(CrmCustomerDO.class) |
| 49 | 36 | .likeIfPresent(CrmCustomerDO::getName, pageReqVO.getName()) |
| 50 | 37 | .eqIfPresent(CrmCustomerDO::getMobile, pageReqVO.getMobile()) |
| 51 | 38 | .eqIfPresent(CrmCustomerDO::getIndustryId, pageReqVO.getIndustryId()) |
| 52 | 39 | .eqIfPresent(CrmCustomerDO::getLevel, pageReqVO.getLevel()) |
| 53 | 40 | .eqIfPresent(CrmCustomerDO::getSource, pageReqVO.getSource()); |
| 54 | - // 特殊:不分页,直接查询全部 | |
| 55 | - // TODO @puhui999:下面这个,封装一个方法;从 56 到 61 这里哈; | |
| 56 | - if (PageParam.PAGE_SIZE_NONE.equals(pageReqVO.getPageNo())) { | |
| 57 | - List<CrmCustomerDO> list = selectJoinList(CrmCustomerDO.class, mpjLambdaWrapperX); | |
| 58 | - return new PageResult<>(list, (long) list.size()); | |
| 59 | - } | |
| 60 | - mpPage = selectJoinPage(mpPage, CrmCustomerDO.class, mpjLambdaWrapperX); | |
| 61 | - return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); | |
| 41 | + return selectJoinPage(pageReqVO, CrmCustomerDO.class, mpjLambdaWrapperX); | |
| 42 | + } | |
| 43 | + | |
| 44 | + default List<CrmCustomerDO> selectBatchIds(Collection<Long> ids, Long userId) { | |
| 45 | + MPJLambdaWrapperX<CrmCustomerDO> mpjLambdaWrapperX = new MPJLambdaWrapperX<>(); | |
| 46 | + // 构建数据权限连表条件 | |
| 47 | + CrmQueryWrapperUtils.builderListQueryBatch(mpjLambdaWrapperX, CrmBizTypeEnum.CRM_CUSTOMER.getType(), ids, userId); | |
| 48 | + return selectJoinList(CrmCustomerDO.class, mpjLambdaWrapperX); | |
| 62 | 49 | } |
| 63 | 50 | |
| 64 | 51 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/vo/CrmBasePageReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.framework.vo; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | -import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | -import cn.iocoder.yudao.module.crm.enums.common.CrmSceneEnum; | |
| 6 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 7 | -import lombok.Data; | |
| 8 | -import lombok.EqualsAndHashCode; | |
| 9 | - | |
| 10 | -@Schema(description = "管理后台 - CRM 分页 Base Request VO") | |
| 11 | -@Data | |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -public class CrmBasePageReqVO extends PageParam { | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * 场景类型,为 null 时则表示全部 | |
| 17 | - */ | |
| 18 | - @Schema(description = "场景类型", example = "1") | |
| 19 | - @InEnum(CrmSceneEnum.class) | |
| 20 | - private Integer sceneType; | |
| 21 | - | |
| 22 | - @Schema(description = "是否为公海数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") | |
| 23 | - private Boolean pool; // null 则表示为不是公海数据 | |
| 24 | - | |
| 25 | -} |
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 |
| 6 | 6 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 9 | - | |
| 10 | 9 | import jakarta.validation.Valid; |
| 10 | + | |
| 11 | 11 | import java.util.Collection; |
| 12 | 12 | import java.util.List; |
| 13 | 13 | |
| ... | ... | @@ -56,7 +56,7 @@ public interface CrmCustomerService { |
| 56 | 56 | * @return 客户列表 |
| 57 | 57 | * @author ljlleo |
| 58 | 58 | */ |
| 59 | - List<CrmCustomerDO> getCustomerList(Collection<Long> ids); | |
| 59 | + List<CrmCustomerDO> getCustomerList(Collection<Long> ids, Long userId); | |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * 获得客户分页 | ... | ... |
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; |
| 15 | 15 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 16 | 16 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; |
| 17 | 17 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 18 | +import jakarta.annotation.Resource; | |
| 18 | 19 | import org.springframework.stereotype.Service; |
| 19 | 20 | import org.springframework.transaction.annotation.Transactional; |
| 20 | 21 | import org.springframework.validation.annotation.Validated; |
| 21 | 22 | |
| 22 | -import jakarta.annotation.Resource; | |
| 23 | 23 | import java.util.*; |
| 24 | 24 | |
| 25 | 25 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -93,17 +93,16 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | @Override |
| 96 | - public List<CrmCustomerDO> getCustomerList(Collection<Long> ids) { | |
| 96 | + public List<CrmCustomerDO> getCustomerList(Collection<Long> ids, Long userId) { | |
| 97 | 97 | if (CollUtil.isEmpty(ids)) { |
| 98 | 98 | return Collections.emptyList(); |
| 99 | 99 | } |
| 100 | - return customerMapper.selectBatchIds(ids); | |
| 100 | + return customerMapper.selectBatchIds(ids, userId); | |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | @Override |
| 104 | 104 | public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) { |
| 105 | - boolean admin = false; // TODO 如果是管理员 | |
| 106 | - return customerMapper.selectPage(pageReqVO, userId, adminUserApi.getSubordinateIds(userId), admin); | |
| 105 | + return customerMapper.selectPage(pageReqVO, userId); | |
| 107 | 106 | } |
| 108 | 107 | |
| 109 | 108 | /** |
| ... | ... | @@ -128,9 +127,11 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { |
| 128 | 127 | // 1. 校验客户是否存在 |
| 129 | 128 | validateCustomer(reqVO.getId()); |
| 130 | 129 | |
| 131 | - // 2. 数据权限转移 | |
| 130 | + // 2.1 数据权限转移 | |
| 132 | 131 | crmPermissionService.transferPermission( |
| 133 | 132 | CrmCustomerConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())); |
| 133 | + // 2.2 转移后重新设置负责人 | |
| 134 | + customerMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId()); | |
| 134 | 135 | |
| 135 | 136 | // 3. TODO 记录转移日志 |
| 136 | 137 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryPageUtils.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.util; | |
| 2 | - | |
| 3 | -import cn.hutool.core.collection.CollUtil; | |
| 4 | -import cn.hutool.core.util.ObjUtil; | |
| 5 | -import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | |
| 6 | -import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | |
| 7 | -import cn.iocoder.yudao.module.crm.enums.common.CrmSceneEnum; | |
| 8 | -import cn.iocoder.yudao.module.crm.framework.vo.CrmBasePageReqVO; | |
| 9 | -import com.baomidou.mybatisplus.core.toolkit.support.SFunction; | |
| 10 | -import com.github.yulichang.wrapper.MPJLambdaWrapper; | |
| 11 | - | |
| 12 | -import jakarta.annotation.Nullable; | |
| 13 | -import java.util.Collection; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * CRM 分页查询工具类 | |
| 17 | - * | |
| 18 | - * @author HUIHUI | |
| 19 | - */ | |
| 20 | -public class CrmQueryPageUtils { | |
| 21 | - | |
| 22 | - // TODO @puhui999:是不是弱化 CrmBasePageReqVO,把 sceneType 作为参数传入。默认其实 pool 不一定要传递的 | |
| 23 | - /** | |
| 24 | - * 构造 CRM 数据类型数据分页查询条件 | |
| 25 | - * | |
| 26 | - * @param queryMapper 连表查询对象 | |
| 27 | - * @param reqVO 查询条件 | |
| 28 | - * @param userId 用户编号 | |
| 29 | - * @param bizType 数据类型 {@link CrmBizTypeEnum} | |
| 30 | - * @param bizId 数据编号 | |
| 31 | - * @param subordinateIds 下属用户编号,可为空 | |
| 32 | - */ | |
| 33 | - public static <T extends MPJLambdaWrapper<?>, V extends CrmBasePageReqVO, S> void builderQuery( | |
| 34 | - T queryMapper, V reqVO, Long userId, | |
| 35 | - Integer bizType, SFunction<S, ?> bizId, | |
| 36 | - @Nullable Collection<Long> subordinateIds, // TODO @puhui999:subordinateIds 可以优化成 subordinateUserIds | |
| 37 | - Boolean isAdmin) { | |
| 38 | - // TODO @puhui999:是不是特殊处理,让这个 util 有状态,这样 isAdmin 直接从这里读取;subordinateIds 也是;这样,可以简化参数; | |
| 39 | - // 1. 构建数据权限连表条件 | |
| 40 | - if (ObjUtil.notEqual(isAdmin, Boolean.TRUE)) { // 管理员不需要数据权限 | |
| 41 | - queryMapper.innerJoin(CrmPermissionDO.class, on -> | |
| 42 | - on.eq(CrmPermissionDO::getBizType, bizType).eq(CrmPermissionDO::getBizId, bizId) | |
| 43 | - .eq(CrmPermissionDO::getUserId, userId)); | |
| 44 | - } | |
| 45 | - // 2. 拼接公海的查询条件 | |
| 46 | - if (ObjUtil.equal(reqVO.getPool(), Boolean.TRUE)) { // 情况一:公海 | |
| 47 | - queryMapper.isNull("owner_user_id"); | |
| 48 | - } else { // 情况二:不是公海 | |
| 49 | - queryMapper.isNotNull("owner_user_id"); | |
| 50 | - } | |
| 51 | - // 3. 拼接场景的查询条件 | |
| 52 | - // TODO @puhui999::1 处的数据权限,应该和 3 处的场景是结合的? | |
| 53 | - // null 时:一种处理 | |
| 54 | - // 1:一种条件; | |
| 55 | - // 2:一种条件; | |
| 56 | - // 3:一种条件; | |
| 57 | - if (CrmSceneEnum.isOwner(reqVO.getSceneType())) { // 场景一:我负责的数据 | |
| 58 | - queryMapper.eq("owner_user_id", userId); | |
| 59 | - } | |
| 60 | - // TODO puhui999: 这里有一个疑问:如果下属负责的数据权限中没有自己的话还能看吗?回复:不能 | |
| 61 | - if (CrmSceneEnum.isSubordinate(reqVO.getSceneType()) && CollUtil.isNotEmpty(subordinateIds)) { // 场景三:下属负责的数据 | |
| 62 | - queryMapper.in("owner_user_id", subordinateIds); | |
| 63 | - } | |
| 64 | - } | |
| 65 | - | |
| 66 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.util; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.ObjUtil; | |
| 5 | +import cn.hutool.extra.spring.SpringUtil; | |
| 6 | +import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; | |
| 7 | +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | |
| 8 | +import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum; | |
| 9 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 10 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | |
| 11 | +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; | |
| 12 | +import com.github.yulichang.wrapper.MPJLambdaWrapper; | |
| 13 | + | |
| 14 | +import java.util.Collection; | |
| 15 | +import java.util.List; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * CRM 分页查询工具类 | |
| 21 | + * | |
| 22 | + * @author HUIHUI | |
| 23 | + */ | |
| 24 | +public class CrmQueryWrapperUtils { | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 构造 CRM 数据类型数据分页查询条件 | |
| 28 | + * | |
| 29 | + * @param queryMapper 连表查询对象 | |
| 30 | + * @param bizType 数据类型 {@link CrmBizTypeEnum} | |
| 31 | + * @param bizId 数据编号 | |
| 32 | + * @param userId 用户编号 | |
| 33 | + * @param sceneType 场景类型 | |
| 34 | + * @param pool 公海 | |
| 35 | + */ | |
| 36 | + public static <T extends MPJLambdaWrapper<?>, S> void builderPageQuery( | |
| 37 | + T queryMapper, Integer bizType, SFunction<S, ?> bizId, Long userId, Integer sceneType, Boolean pool) { | |
| 38 | + // 1. 构建数据权限连表条件 | |
| 39 | + if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 | |
| 40 | + queryMapper.innerJoin(CrmPermissionDO.class, on -> | |
| 41 | + on.eq(CrmPermissionDO::getBizType, bizType).eq(CrmPermissionDO::getBizId, bizId) | |
| 42 | + .eq(CrmPermissionDO::getUserId, userId)); | |
| 43 | + } | |
| 44 | + // 1.2 场景一:我负责的数据 | |
| 45 | + if (CrmSceneTypeEnum.isOwner(sceneType)) { | |
| 46 | + queryMapper.eq("owner_user_id", userId); | |
| 47 | + } | |
| 48 | + // 1.3 场景一:我参与的数据 | |
| 49 | + if (CrmSceneTypeEnum.isInvolved(sceneType)) { | |
| 50 | + queryMapper.ne("owner_user_id", userId); | |
| 51 | + } | |
| 52 | + // 1.4 场景二:下属负责的数据 | |
| 53 | + if (CrmSceneTypeEnum.isSubordinate(sceneType)) { | |
| 54 | + List<AdminUserRespDTO> subordinateUsers = getAdminUserApi().getUserListBySubordinate(userId); | |
| 55 | + if (CollUtil.isNotEmpty(subordinateUsers)) { | |
| 56 | + queryMapper.in("owner_user_id", convertSet(subordinateUsers, AdminUserRespDTO::getId)); | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 60 | + // 2. 拼接公海的查询条件 | |
| 61 | + if (ObjUtil.equal(pool, Boolean.TRUE)) { // 情况一:公海 | |
| 62 | + queryMapper.isNull("owner_user_id"); | |
| 63 | + } else { // 情况二:不是公海 | |
| 64 | + queryMapper.isNotNull("owner_user_id"); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 构造 CRM 数据类型批量数据查询条件 | |
| 70 | + * | |
| 71 | + * @param queryMapper 连表查询对象 | |
| 72 | + * @param bizType 数据类型 {@link CrmBizTypeEnum} | |
| 73 | + * @param bizIds 数据编号 | |
| 74 | + * @param userId 用户编号 | |
| 75 | + */ | |
| 76 | + public static <T extends MPJLambdaWrapper<?>, S> void builderListQueryBatch( | |
| 77 | + T queryMapper, Integer bizType, Collection<Long> bizIds, Long userId) { | |
| 78 | + // 1. 构建数据权限连表条件 | |
| 79 | + if (ObjUtil.notEqual(validateAdminUser(userId), Boolean.TRUE)) { // 管理员不需要数据权限 | |
| 80 | + queryMapper.innerJoin(CrmPermissionDO.class, on -> | |
| 81 | + on.eq(CrmPermissionDO::getBizType, bizType).in(CrmPermissionDO::getBizId, bizIds) | |
| 82 | + .eq(CrmPermissionDO::getUserId, userId)); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + private static AdminUserApi getAdminUserApi() { | |
| 87 | + return SpringUtil.getBean(AdminUserApi.class); | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * 校验用户是否是管理员 | |
| 92 | + * | |
| 93 | + * @param userId 用户编号 | |
| 94 | + * @return 是/否 | |
| 95 | + */ | |
| 96 | + private static boolean validateAdminUser(Long userId) { | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + | |
| 100 | +} | ... | ... |
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) { |
| 77 | 77 | // ==================== 子表($subTable.classComment) ==================== |
| 78 | 78 | ## 情况一:MASTER_ERP 时,需要分查询页子表 |
| 79 | 79 | #if ( $table.templateType == 11 ) |
| 80 | - | |
| 81 | 80 | // 获得${subTable.classComment}分页 |
| 82 | 81 | export function get${subSimpleClassName}Page(params) { |
| 83 | 82 | return request({ |
| ... | ... | @@ -89,20 +88,18 @@ export function export${simpleClassName}Excel(params) { |
| 89 | 88 | ## 情况二:非 MASTER_ERP 时,需要列表查询子表 |
| 90 | 89 | #else |
| 91 | 90 | #if ( $subTable.subJoinMany ) |
| 92 | - | |
| 93 | 91 | // 获得${subTable.classComment}列表 |
| 94 | 92 | export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}) { |
| 95 | 93 | return request({ |
| 96 | - url: `${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField}, | |
| 94 | + url: '${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=' + ${subJoinColumn.javaField}, | |
| 97 | 95 | method: 'get' |
| 98 | 96 | }) |
| 99 | 97 | } |
| 100 | 98 | #else |
| 101 | - | |
| 102 | 99 | // 获得${subTable.classComment} |
| 103 | 100 | export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}) { |
| 104 | 101 | return request({ |
| 105 | - url: `${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField}, | |
| 102 | + url: '${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=' + ${subJoinColumn.javaField}, | |
| 106 | 103 | method: 'get' |
| 107 | 104 | }) |
| 108 | 105 | } |
| ... | ... | @@ -113,7 +110,7 @@ export function export${simpleClassName}Excel(params) { |
| 113 | 110 | // 新增${subTable.classComment} |
| 114 | 111 | export function create${subSimpleClassName}(data) { |
| 115 | 112 | return request({ |
| 116 | - url: `${baseURL}/${subSimpleClassName_strikeCase}/create`, | |
| 113 | + url: '${baseURL}/${subSimpleClassName_strikeCase}/create', | |
| 117 | 114 | method: 'post', |
| 118 | 115 | data |
| 119 | 116 | }) |
| ... | ... | @@ -122,7 +119,7 @@ export function export${simpleClassName}Excel(params) { |
| 122 | 119 | // 修改${subTable.classComment} |
| 123 | 120 | export function update${subSimpleClassName}(data) { |
| 124 | 121 | return request({ |
| 125 | - url: `${baseURL}/${subSimpleClassName_strikeCase}/update`, | |
| 122 | + url: '${baseURL}/${subSimpleClassName_strikeCase}/update', | |
| 126 | 123 | method: 'post', |
| 127 | 124 | data |
| 128 | 125 | }) |
| ... | ... | @@ -131,7 +128,7 @@ export function export${simpleClassName}Excel(params) { |
| 131 | 128 | // 删除${subTable.classComment} |
| 132 | 129 | export function delete${subSimpleClassName}(id) { |
| 133 | 130 | return request({ |
| 134 | - url: `${baseURL}/${subSimpleClassName_strikeCase}/delete?id=` + id, | |
| 131 | + url: '${baseURL}/${subSimpleClassName_strikeCase}/delete?id=' + id, | |
| 135 | 132 | method: 'delete' |
| 136 | 133 | }) |
| 137 | 134 | } |
| ... | ... | @@ -139,7 +136,7 @@ export function export${simpleClassName}Excel(params) { |
| 139 | 136 | // 获得${subTable.classComment} |
| 140 | 137 | export function get${subSimpleClassName}(id) { |
| 141 | 138 | return request({ |
| 142 | - url: `${baseURL}/${subSimpleClassName_strikeCase}/get?id=` + id, | |
| 139 | + url: '${baseURL}/${subSimpleClassName_strikeCase}/get?id=' + id, | |
| 143 | 140 | method: 'get' |
| 144 | 141 | }) |
| 145 | 142 | } | ... | ... |
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; |
| 6 | 6 | import java.util.Collection; |
| 7 | 7 | import java.util.List; |
| 8 | 8 | import java.util.Map; |
| 9 | -import java.util.Set; | |
| 10 | 9 | |
| 11 | 10 | /** |
| 12 | 11 | * Admin 用户 API 接口 |
| ... | ... | @@ -27,10 +26,10 @@ public interface AdminUserApi { |
| 27 | 26 | /** |
| 28 | 27 | * 通过用户 ID 查询用户下属 |
| 29 | 28 | * |
| 30 | - * @param id 用户编号 | |
| 31 | - * @return 用户下属用户编号列表 | |
| 29 | + * @param userId 用户编号 | |
| 30 | + * @return 用户下属用户列表 | |
| 32 | 31 | */ |
| 33 | - Set<Long> getSubordinateIds(Long id); | |
| 32 | + List<AdminUserRespDTO> getUserListBySubordinate(Long userId); | |
| 34 | 33 | |
| 35 | 34 | /** |
| 36 | 35 | * 通过用户 ID 查询用户们 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.api.user; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | 6 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| ... | ... | @@ -7,13 +8,13 @@ import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 7 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 8 | 9 | import cn.iocoder.yudao.module.system.service.dept.DeptService; |
| 9 | 10 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 11 | +import jakarta.annotation.Resource; | |
| 10 | 12 | import org.springframework.stereotype.Service; |
| 11 | 13 | |
| 12 | -import jakarta.annotation.Resource; | |
| 14 | +import java.util.ArrayList; | |
| 13 | 15 | import java.util.Collection; |
| 14 | 16 | import java.util.Collections; |
| 15 | 17 | import java.util.List; |
| 16 | -import java.util.Set; | |
| 17 | 18 | |
| 18 | 19 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 19 | 20 | |
| ... | ... | @@ -37,21 +38,32 @@ public class AdminUserApiImpl implements AdminUserApi { |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | 40 | @Override |
| 40 | - public Set<Long> getSubordinateIds(Long id) { | |
| 41 | - AdminUserDO user = userService.getUser(id); | |
| 41 | + public List<AdminUserRespDTO> getUserListBySubordinate(Long userId) { | |
| 42 | + // 1. 获取用户信息 | |
| 43 | + AdminUserDO user = userService.getUser(userId); | |
| 42 | 44 | if (user == null) { |
| 43 | - return null; | |
| 45 | + return Collections.emptyList(); | |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | - Set<Long> subordinateIds = null; // 下属用户编号 | |
| 48 | + // 2.1 获取用户负责的部门 | |
| 49 | + ArrayList<Long> deptIds = new ArrayList<>(); | |
| 47 | 50 | DeptDO dept = deptService.getDept(user.getDeptId()); |
| 48 | - // TODO @puhui999:需要递归查询到子部门;并且要排除到自己噢。 | |
| 49 | - // TODO @puhui999:保持 if return 原则,这里其实要判断不等于,则返回 null;最好返回 空集合,上面也是 | |
| 50 | - if (ObjUtil.equal(dept.getLeaderUserId(), id)) { // 校验是否是该部门的负责人 | |
| 51 | - List<AdminUserDO> users = userService.getUserListByDeptIds(Collections.singletonList(dept.getId())); | |
| 52 | - subordinateIds = convertSet(users, AdminUserDO::getId); | |
| 51 | + if (dept == null) { | |
| 52 | + return Collections.emptyList(); | |
| 53 | + } | |
| 54 | + if (ObjUtil.notEqual(dept.getLeaderUserId(), userId)) { // 校验为负责人 | |
| 55 | + return Collections.emptyList(); | |
| 53 | 56 | } |
| 54 | - return subordinateIds; | |
| 57 | + deptIds.add(dept.getId()); // 加入此部门 | |
| 58 | + // 2.2 获取所有子部门 | |
| 59 | + List<DeptDO> childDeptList = deptService.getChildDeptList(dept.getId()); | |
| 60 | + if (CollUtil.isNotEmpty(childDeptList)) { | |
| 61 | + deptIds.addAll(convertSet(childDeptList, DeptDO::getId)); | |
| 62 | + } | |
| 63 | + // 2.3 获取用户信息 | |
| 64 | + List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds); | |
| 65 | + users.removeIf(item -> ObjUtil.equal(item.getId(), userId)); // 排除自己 | |
| 66 | + return BeanUtils.toBean(users, AdminUserRespDTO.class); | |
| 55 | 67 | } |
| 56 | 68 | |
| 57 | 69 | @Override | ... | ... |
yudao-server/pom.xml
| ... | ... | @@ -92,11 +92,11 @@ |
| 92 | 92 | <!-- </dependency>--> |
| 93 | 93 | |
| 94 | 94 | <!-- CRM 相关模块。默认注释,保证编译速度 --> |
| 95 | -<!-- <dependency>--> | |
| 96 | -<!-- <groupId>cn.iocoder.boot</groupId>--> | |
| 97 | -<!-- <artifactId>yudao-module-crm-biz</artifactId>--> | |
| 98 | -<!-- <version>${revision}</version>--> | |
| 99 | -<!-- </dependency>--> | |
| 95 | + <dependency> | |
| 96 | + <groupId>cn.iocoder.boot</groupId> | |
| 97 | + <artifactId>yudao-module-crm-biz</artifactId> | |
| 98 | + <version>${revision}</version> | |
| 99 | + </dependency> | |
| 100 | 100 | |
| 101 | 101 | <!-- spring boot 配置所需依赖 --> |
| 102 | 102 | <dependency> | ... | ... |