From 76ed9e3b5a67d1509cf9bf0c0b9a7813ff403614 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Tue, 30 May 2023 17:03:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.6.0=E3=80=91=E3=80=90group=E3=80=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9D=A1=E4=BB=B6=E6=9F=A5=E8=AF=A2=E7=9A=84?= =?UTF-8?q?Api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernel/group/api/GroupConditionApi.java | 62 +++++++++++++++++++ .../modular/service/SysGroupService.java | 3 +- .../service/impl/SysGroupServiceImpl.java | 34 +++++++++- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 kernel-s-group/group-api/src/main/java/cn/stylefeng/roses/kernel/group/api/GroupConditionApi.java diff --git a/kernel-s-group/group-api/src/main/java/cn/stylefeng/roses/kernel/group/api/GroupConditionApi.java b/kernel-s-group/group-api/src/main/java/cn/stylefeng/roses/kernel/group/api/GroupConditionApi.java new file mode 100644 index 000000000..e972b4349 --- /dev/null +++ b/kernel-s-group/group-api/src/main/java/cn/stylefeng/roses/kernel/group/api/GroupConditionApi.java @@ -0,0 +1,62 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.group.api; + +import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest; + +import java.util.List; + +/** + * 用在查询条件拼接语句时候的分组Api + * + * @author fengshuonan + * @since 2023/5/30 16:47 + */ +public interface GroupConditionApi { + + /** + * 获取请求是不是请求的未分组 + *

+ * 判断baseRequest中请求的conditionGroupName参数是否是“未分组” + *

+ * 如果是未分组,则查询条件中,应当拼接类似如下语句: + *

+ * queryWrapper.nested(ObjectUtil.isNotEmpty(userBizIds), i -> i.notIn(DevopsApp::getAppId, userBizIds)); + * + * @author fengshuonan + * @since 2023/5/30 16:49 + */ + Boolean getRequestUnGroupedFlag(BaseRequest baseRequest); + + /** + * 获取用户对应的业务分组下的业务id集合 + * + * @param groupBizCode 业务分组编码,应该是个常量,每个分组都应该具有的 + * @author fengshuonan + * @since 2023/5/30 16:49 + */ + List getUserGroupBizIds(String groupBizCode, BaseRequest baseRequest); + +} diff --git a/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/service/SysGroupService.java b/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/service/SysGroupService.java index 301d4ecea..aeef0a99d 100644 --- a/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/service/SysGroupService.java +++ b/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/service/SysGroupService.java @@ -1,6 +1,7 @@ package cn.stylefeng.roses.kernel.group.modular.service; import cn.stylefeng.roses.kernel.group.api.GroupApi; +import cn.stylefeng.roses.kernel.group.api.GroupConditionApi; import cn.stylefeng.roses.kernel.group.api.pojo.SysGroupDTO; import cn.stylefeng.roses.kernel.group.api.pojo.SysGroupRequest; import cn.stylefeng.roses.kernel.group.modular.entity.SysGroup; @@ -14,7 +15,7 @@ import java.util.List; * @author fengshuonan * @since 2022/05/11 12:54 */ -public interface SysGroupService extends IService, GroupApi { +public interface SysGroupService extends IService, GroupApi, GroupConditionApi { /** * 添加时候的选择分组列表 diff --git a/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/service/impl/SysGroupServiceImpl.java b/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/service/impl/SysGroupServiceImpl.java index e261349e2..553afd5ee 100644 --- a/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/service/impl/SysGroupServiceImpl.java +++ b/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/service/impl/SysGroupServiceImpl.java @@ -1,5 +1,6 @@ package cn.stylefeng.roses.kernel.group.modular.service.impl; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.stylefeng.roses.kernel.auth.api.context.LoginContext; import cn.stylefeng.roses.kernel.group.api.constants.GroupConstants; @@ -8,6 +9,7 @@ import cn.stylefeng.roses.kernel.group.api.pojo.SysGroupRequest; import cn.stylefeng.roses.kernel.group.modular.entity.SysGroup; import cn.stylefeng.roses.kernel.group.modular.mapper.SysGroupMapper; import cn.stylefeng.roses.kernel.group.modular.service.SysGroupService; +import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -121,6 +123,37 @@ public class SysGroupServiceImpl extends ServiceImpl i this.remove(wrapper); } + @Override + public Boolean getRequestUnGroupedFlag(BaseRequest baseRequest) { + // 获取前端请求的分组名称 + String conditionGroupName = baseRequest.getConditionGroupName(); + return GroupConstants.GROUP_DELETE_NAME.equals(conditionGroupName); + } + + @Override + public List getUserGroupBizIds(String groupBizCode, BaseRequest baseRequest) { + // 拼接分组相关的查询条件 + String conditionGroupName = baseRequest.getConditionGroupName(); + List userBizIds = new ArrayList<>(); + + // 如果查询的是所有分组,就是查询所有的数据,不需要拼接条件 + if (ObjectUtil.isNotEmpty(conditionGroupName) && !conditionGroupName.equals(GroupConstants.ALL_GROUP_NAME)) { + + SysGroupRequest sysGroupRequest = new SysGroupRequest(); + sysGroupRequest.setGroupBizCode(groupBizCode); + + // 查詢的不是未分组,则需要拼接一个groupName + if (!getRequestUnGroupedFlag(baseRequest)) { + sysGroupRequest.setGroupName(conditionGroupName); + } + + // 获取到筛选条件的结果 + userBizIds = this.findUserGroupDataList(sysGroupRequest); + } + + return userBizIds; + } + /** * 返回结果增加通用的两个分组名称 * @@ -165,5 +198,4 @@ public class SysGroupServiceImpl extends ServiceImpl i result.add(0, addGroup); } - }