添加项目数据隔离逻辑

This commit is contained in:
mi9688
2024-10-17 18:17:06 +08:00
parent 0fb3e4bd8d
commit a5c5d88b46
12 changed files with 227 additions and 24 deletions

View File

@ -9,6 +9,7 @@ public enum GroupTagEnum {
MONITORING_STATIONS(3, "检测站点"),
OTHER_OBJECTS(4, "其他对象"),
WATER_AFFAIRS(5, "水利事务"),
ADMINISTRATIVE_REGION(7, "行政区域"),
ALARM_EVENTS(6, "报警事件");
private final int code;

View File

@ -4,6 +4,7 @@ package com.fastbee.ggroup.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fastbee.ggroup.domain.GGroups;
import com.fastbee.ggroup.domain.vo.GGroupSiteVo;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@ -15,7 +16,7 @@ import java.util.List;
* @date 2024-09-27
*/
public interface GGroupsMapper extends BaseMapper<GGroups>
public interface GGroupsMapper extends MPJBaseMapper<GGroups>
{
/**
* 查询组
@ -36,7 +37,8 @@ public interface GGroupsMapper extends BaseMapper<GGroups>
@Select({
"<script>",
"select gsg.id, gsg.parent_id as parent_id, gg.name as parent_name, gsg.site_id as siteId, gs.name as name, gs.icon, gs.type, gs.space,gs.space_value",
"select gsg.id, gsg.parent_id as parent_id, gg.name as parent_name, gsg.site_id as siteId," +
"gs.name as name, gs.icon, gs.type, gs.space,gs.space_value",
"from g_site_groups gsg",
"left join g_groups gg on gsg.parent_id = gg.id",
"left join g_sites gs on gsg.site_id = gs.id",

View File

@ -25,12 +25,12 @@ public interface IGGroupsService
public GGroups selectGGroupsById(Long id);
/**
* 查询组列表
* 查询组树状列表
*
* @param gGroups 组
* @return 组集合
*/
public List<GGroups> selectGGroupsList(GGroups gGroups);
public List<GGroups> selectGGroupsList(GGroups gGroups);
public List<GGroupSiteVo> selectGGroupsListSites(GGroups gGroups);
/**

View File

@ -5,6 +5,7 @@ import cn.hutool.extra.ssh.JschUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.holder.ProjectHolder;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.ggroup.domain.GGroups;
import com.fastbee.ggroup.domain.GSiteGroups;
@ -16,12 +17,14 @@ import com.fastbee.ggroup.mapper.GSitesMapper;
import com.fastbee.ggroup.service.IGGroupsService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -36,6 +39,12 @@ public class GGroupsServiceImpl implements IGGroupsService
@Autowired
private GGroupsMapper gGroupsMapper;
@Autowired
private GSitesMapper gSitesMapper;
@Autowired
private GSiteGroupsMapper gSiteGroupsMapper;
/**
* 查询组
@ -51,7 +60,7 @@ public class GGroupsServiceImpl implements IGGroupsService
/**
* 查询组列表
* 查询组树状结构列表
*
* @param gGroups 组
* @return 组
@ -59,18 +68,34 @@ public class GGroupsServiceImpl implements IGGroupsService
@Override
public List<GGroups> selectGGroupsList(GGroups gGroups)
{
return buildTree(gGroupsMapper.selectGGroupsList(gGroups));
// List<GGroups> gGroupsList = gGroupsMapper.selectGGroupsList(gGroups);
List<GGroups> list = new LambdaQueryChainWrapper<>(gGroupsMapper).select(GGroups::getId, GGroups::getName, GGroups::getIcon,
GGroups::getTag, GGroups::getParentId, GGroups::getProjectId, GGroups::getProjectName,
GGroups::getOrderNum, GGroups::getSpace)
.in(GGroups::getProjectId, ProjectHolder.getProjectInfo().getProjectIdList())
.list();
return buildTree(list);
}
/**
* 查询/搜索组列表
*
* 查询组下面的站点
* @param gGroups 组
* @return 组
*/
@Override
public List<GGroupSiteVo> selectGGroupsListSites(GGroups gGroups) {
return gGroupsMapper.selectGGroupsSiteList(gGroups);
MPJLambdaWrapper<GSiteGroups> gSiteGroupsMPJLambdaWrapper = new MPJLambdaWrapper<GSiteGroups>()
.select(GSiteGroups::getId, GSiteGroups::getParentId, GSiteGroups::getSiteId)
// .select(GGroups::getName)//起个别名
// .selectAs(GGroups::getName, "parentName")
.select(GSites::getName, GSites::getIcon, GSites::getType, GSites::getSpace, GSites::getSpaceValue)
.leftJoin(GGroups.class, GGroups::getId, GSiteGroups::getParentId)
.leftJoin(GSites.class, GSites::getId, GSiteGroups::getSiteId)
.eq(GSiteGroups::getParentId, gGroups.getParentId())
.like(StringUtils.isNotBlank(gGroups.getName()), GGroups::getName, gGroups.getName());
;
return gSiteGroupsMapper.selectJoinList(GGroupSiteVo.class,gSiteGroupsMPJLambdaWrapper);
}
private List<GGroups> buildTree(List<GGroups> groups) {
@ -155,7 +180,7 @@ public class GGroupsServiceImpl implements IGGroupsService
/**
* 修改组
*
*
* @param gGroups 组
* @return 结果
*/
@ -177,7 +202,7 @@ public class GGroupsServiceImpl implements IGGroupsService
/**
* 批量删除组
*
*
* @param ids 需要删除的组主键
* @return 结果
*/
@ -189,7 +214,7 @@ public class GGroupsServiceImpl implements IGGroupsService
/**
* 删除组信息
*
*
* @param id 组主键
* @return 结果
*/
@ -200,13 +225,29 @@ public class GGroupsServiceImpl implements IGGroupsService
}
/**
* 查询组和站点的树状结构
* 查询组和站点(叶子节点)的树状结构
* @param gGroups 组
* @return 列表
*/
@Override
public List<?> selectGGroupsAndSitesList(GGroups gGroups) {
List<GGroups> list = new LambdaQueryChainWrapper<>(gGroupsMapper)
.select(GGroups::getId, GGroups::getName, GGroups::getParentId,
GGroups::getIcon,GGroups::getTag,
GGroups::getSpace, GGroups::getSpaceValue, GGroups::getProjectId)
.eq(Objects.nonNull(gGroups.getTag()), GGroups::getTag, gGroups.getTag())
.in(GGroups::getProjectId, ProjectHolder.getProjectInfo().getProjectIdList())
.list();
System.err.println(ProjectHolder.getProjectInfo());
ProjectHolder.getProjectInfo().getProjectIdList().forEach(System.err::println);
list.forEach(System.err::println);
List<GGroups> gGroupsList = buildTreeSite(list);
List<List<GGroups>> listList = gGroupsList.stream().map(gGroups1 -> {
List<GGroups> list1 = new ArrayList<>();
list1.add(gGroups1);
return list1;
}).collect(Collectors.toList());
//组的树状结构
return buildTreeSite(gGroupsMapper.selectGGroupsList(gGroups));
return listList;
}
}