diff --git a/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/mapper/SysGroupMapper.java b/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/mapper/SysGroupMapper.java index 9c1a26cd5..808b47e5a 100644 --- a/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/mapper/SysGroupMapper.java +++ b/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/mapper/SysGroupMapper.java @@ -1,11 +1,7 @@ package cn.stylefeng.roses.kernel.group.modular.mapper; -import cn.stylefeng.roses.kernel.group.api.pojo.SysGroupDTO; import cn.stylefeng.roses.kernel.group.modular.entity.SysGroup; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; - -import java.util.List; /** * 业务分组 Mapper 接口 @@ -15,12 +11,5 @@ import java.util.List; */ public interface SysGroupMapper extends BaseMapper { - /** - * 获取用户分组列表 - * - * @author fengshuonan - * @since 2022/5/11 16:49 - */ - List getUserGroupList(@Param("groupBizCode") String groupBizCode, @Param("userId") Long userId, @Param("getTotal") boolean getTotal); } diff --git a/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/mapper/mapping/SysGroupMapper.xml b/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/mapper/mapping/SysGroupMapper.xml index dcba457db..de4e7a387 100644 --- a/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/mapper/mapping/SysGroupMapper.xml +++ b/kernel-s-group/group-business/src/main/java/cn/stylefeng/roses/kernel/group/modular/mapper/mapping/SysGroupMapper.xml @@ -2,14 +2,4 @@ - - 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 e1a336fc5..324fb9227 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.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.stylefeng.roses.kernel.auth.api.context.LoginContext; @@ -31,26 +32,44 @@ public class SysGroupServiceImpl extends ServiceImpl i @Override public List findGroupList(SysGroupRequest sysGroupRequest, boolean getTotal) { + + // 定义返回结果 + List sysGroupDTOS = new ArrayList<>(); + String groupBizCode = sysGroupRequest.getGroupBizCode(); Long userId = LoginContext.me().getLoginUser().getUserId(); - List userGroupList = this.baseMapper.getUserGroupList(groupBizCode, userId, getTotal); + + LambdaQueryWrapper wrapper = this.createWrapper(groupBizCode, userId, getTotal); + List list = this.list(wrapper); + if (ObjectUtil.isNotEmpty(list)) { + sysGroupDTOS = BeanUtil.copyToList(list, SysGroupDTO.class); + } // 增加两个固定的选中和取消选项 - addAllGroup(groupBizCode, userGroupList); + addAllGroup(groupBizCode, sysGroupDTOS); - return userGroupList; + return sysGroupDTOS; } @Override public List addSelect(SysGroupRequest sysGroupRequest) { + + // 定义返回结果 + List sysGroupDTOS = new ArrayList<>(); + String groupBizCode = sysGroupRequest.getGroupBizCode(); Long userId = LoginContext.me().getLoginUser().getUserId(); - List userGroupList = this.baseMapper.getUserGroupList(groupBizCode, userId, false); + + LambdaQueryWrapper wrapper = this.createWrapper(groupBizCode, userId, false); + List list = this.list(wrapper); + if (ObjectUtil.isNotEmpty(list)) { + sysGroupDTOS = BeanUtil.copyToList(list, SysGroupDTO.class); + } // 增加两个固定的选中和取消选项 - addCommonGroup(groupBizCode, userGroupList); + addCommonGroup(groupBizCode, sysGroupDTOS); - return userGroupList; + return sysGroupDTOS; } @Override @@ -102,7 +121,8 @@ public class SysGroupServiceImpl extends ServiceImpl i LambdaQueryWrapper sysGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(); sysGroupLambdaQueryWrapper.eq(SysGroup::getUserId, userId); sysGroupLambdaQueryWrapper.eq(SysGroup::getGroupBizCode, sysGroupRequest.getGroupBizCode()); - sysGroupLambdaQueryWrapper.eq(StrUtil.isNotBlank(sysGroupRequest.getGroupName()), SysGroup::getGroupName, sysGroupRequest.getGroupName()); + sysGroupLambdaQueryWrapper.eq(StrUtil.isNotBlank(sysGroupRequest.getGroupName()), SysGroup::getGroupName, + sysGroupRequest.getGroupName()); List list = this.list(sysGroupLambdaQueryWrapper); if (list == null || list.size() == 0) { @@ -221,4 +241,26 @@ public class SysGroupServiceImpl extends ServiceImpl i result.add(0, addGroup); } + /** + * 创建通用wrapper + * + * @author fengshuonan + * @since 2023/7/11 16:23 + */ + private LambdaQueryWrapper createWrapper(String groupBizCode, Long userId, Boolean getTotal) { + + LambdaQueryWrapper sysGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(); + sysGroupLambdaQueryWrapper.eq(SysGroup::getGroupBizCode, groupBizCode); + sysGroupLambdaQueryWrapper.eq(SysGroup::getUserId, userId); + + if (getTotal != null && !getTotal) { + sysGroupLambdaQueryWrapper.groupBy(SysGroup::getGroupName); + } + + sysGroupLambdaQueryWrapper.select(SysGroup::getGroupName, SysGroup::getGroupId, SysGroup::getGroupBizCode, SysGroup::getBusinessId, + SysGroup::getUserId); + + return sysGroupLambdaQueryWrapper; + } + }