查询站点和组树状列表接口按行政区过滤逻辑,行政区接口逻辑完善等

This commit is contained in:
mi9688 2024-10-28 18:01:46 +08:00
parent 3b51726b58
commit 5b2ea1f01b
14 changed files with 152 additions and 43 deletions

View File

@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -44,8 +45,18 @@ public class SysDistrictController extends BaseController
// @PreAuthorize("@ss.hasPermi('system:district:list')")
@GetMapping("/tree")
@ApiOperation("查询行政区划树状列表")
public AjaxResult tree(){
return success(sysDistrictService.selectSysDistrictTree());
public AjaxResult tree( Integer level){
return success(sysDistrictService.selectSysDistrictTree(level));
}
/**
* 查询指定地区行政区划列表
*/
@GetMapping("/tree-by-code")
@ApiOperation("查询指定地区行政区划列表")
public AjaxResult listByLevel(Long areaCode){
return success(sysDistrictService.selectSysDistrictTreeByCode(areaCode));
}
/**

View File

@ -45,9 +45,9 @@ public class ProjectDataIsolationInterceptor implements HandlerInterceptor {
if ("DELETE".equalsIgnoreCase(request.getMethod())) {
return true;
}
if ("POST".equalsIgnoreCase(request.getMethod())) {
return true;
}
// if ("POST".equalsIgnoreCase(request.getMethod())) {
// return true;
// }
if ("PUT".equalsIgnoreCase(request.getMethod())) {
return true;
}

View File

@ -46,9 +46,9 @@ public class GGroupsController extends BaseController
/**
* 查询组带叶子节点树状列表
*/
@GetMapping("/list-with-leaf")
@PostMapping("/list-with-leaf")
@ApiOperation("查询组带叶子节点树状列表")
public AjaxResult listWithLeaf(GGroups gGroups){
public AjaxResult listWithLeaf(@RequestBody GGroups gGroups){
return success(gGroupsService.selectGGroupsAndSitesList(gGroups));
}

View File

@ -11,6 +11,7 @@ import com.fastbee.project.domain.Project;
import com.fastbee.project.service.IProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -143,9 +144,9 @@ public class ProjectController extends BaseController
/**
* 查询项目的行政区划树状列表
*/
@GetMapping("/areaTree/{projectId}/{startLevel}")
@GetMapping("/areaTree")
@ApiOperation("查询项目的行政区划树状列表")
public AjaxResult getProjectAreaTree(@PathVariable("projectId") Long projectId, @PathVariable("startLevel") Integer startLevel){
public AjaxResult getProjectAreaTree(@Param("projectId") Long projectId,@Param("startLevel") Integer startLevel){
return success(projectService.getProjectAreaTree(projectId, startLevel));
}
}

View File

@ -63,6 +63,8 @@ private static final long serialVersionUID = 1L;
private String spaceValue;
//------------------------------------------------拓展业务字段--------------------------------------------
/** 父菜单名称 */
private String parentName;
@ -84,5 +86,8 @@ private static final long serialVersionUID = 1L;
/**站点类型 */
private String siteType;
/**站点名称行政区划代码 */
private List<String> areaCodeList;
}

View File

@ -15,7 +15,7 @@ import java.util.Map;
* 站点对象 g_sites
*
* @author kerwincui
* @date 2024-09-29
* &#064;date 2024-09-29
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "GSites", description = "站点 g_sites")
@ -71,4 +71,14 @@ public class GSites extends BaseEntity {
/** 类型id(即图例id) */
private Long typeId;
/** 行政区划代码 */
@Excel(name = "行政区划代码")
@ApiModelProperty("行政区划代码")
private String areaCode;
/** 完整行政区划代码一般为[县code,镇code,村code] */
@Excel(name = "完整行政区划代码一般为[县code,镇code,村code]")
@ApiModelProperty("完整行政区划代码一般为[县code,镇code,村code]")
private String fullAreaCode;
}

View File

@ -13,5 +13,7 @@ public class GGroupSiteDto {
private String space; // 站点空间
private Integer orderNum;// 排序
private Long projectId;//项目id
private String areaCode;//区域编码
private String fullAreaCode;//完整区域编码
}

View File

@ -13,6 +13,7 @@ public class GGroupSiteVo {
private String type; // 对应 gs.type
private String space; // 对应 gs.space
private String spaceValue; // 对应 gs.space
private String areaCode;// 对应 gs.area_code
// Getter Setter

View File

@ -125,15 +125,24 @@ public class GGroupsServiceImpl implements IGGroupsService
/**
* 构建组和站点树状列表
*/
private List<GGroups> buildTreeSite(List<GGroups> groupsList) {
private List<GGroups> buildTreeSite(List<GGroups> groupsList,List<String> areaCodeList) {
// 构建一个Map用于存储每个组对象:id->组对象
Map<Long, GGroups> map = new HashMap<>();
//根组列表
List<GGroups> roots = new ArrayList<>();
//所有站点列表
List<GGroupSiteVo> gGroupSiteAllList = selectGGroupsAllListSites(new GGroups());
// System.err.println("当前项目下所有站点:");
// gGroupSiteAllList.forEach(System.err::println);
//根据区域代码过滤站点
if(Objects.nonNull(areaCodeList) && !areaCodeList.isEmpty()){
System.err.println("开始过滤站点");
System.err.println(areaCodeList);
System.err.println("过滤前站点");
System.err.println(gGroupSiteAllList);
gGroupSiteAllList = gGroupSiteAllList.stream()
.filter(site -> areaCodeList.contains(site.getAreaCode())).collect(Collectors.toList());
System.err.println("过滤后的站点");
System.err.println(gGroupSiteAllList);
}
for (GGroups group : groupsList) {
//查询组的直接子站点列表
@ -166,7 +175,7 @@ public class GGroupsServiceImpl implements IGGroupsService
public List<GGroupSiteVo> selectGGroupsAllListSites(GGroups gGroups) {
MPJLambdaWrapper<GSiteGroups> gSiteGroupsMPJLambdaWrapper = new MPJLambdaWrapper<GSiteGroups>()
.select(GSiteGroups::getId, GSiteGroups::getParentId, GSiteGroups::getSiteId)
.select(GSites::getName, GSites::getIcon, GSites::getType, GSites::getSpace, GSites::getSpaceValue)
.select(GSites::getName, GSites::getIcon, GSites::getType, GSites::getSpace, GSites::getSpaceValue,GSites::getAreaCode)
.leftJoin(GGroups.class, GGroups::getId, GSiteGroups::getParentId)
.leftJoin(GSites.class, GSites::getId, GSiteGroups::getSiteId)
.in(!ProjectHolder.getProjectInfo().getProjectIdList().isEmpty(),GGroups::getProjectId,ProjectHolder.getProjectInfo().getProjectIdList());
@ -198,7 +207,6 @@ public class GGroupsServiceImpl implements IGGroupsService
/**
* 修改组
*
* @param gGroups
* @return 结果
*/
@ -223,7 +231,6 @@ public class GGroupsServiceImpl implements IGGroupsService
/**
* 删除组信息
*
* @param id 组主键
* @return 结果
*/
@ -241,14 +248,18 @@ public class GGroupsServiceImpl implements IGGroupsService
*/
@Override
public List<?> selectGGroupsAndSitesList(GGroups gGroups) {
//查询项目下的全部站点
List<GGroups> groupSiteTreeList = 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(!ProjectHolder.getProjectInfo().getProjectIdList().isEmpty(),GGroups::getProjectId,
ProjectHolder.getProjectInfo().getProjectIdList())
.list();
List<GGroups> gGroupsList = buildTreeSite(groupSiteTreeList);
//构建组和站点树状列表
List<GGroups> gGroupsList = buildTreeSite(groupSiteTreeList,gGroups.getAreaCodeList());
//组的树状结构外层数组元素套一层数组方便前端数据渲染
return gGroupsList.stream().map(gGroups1 -> {
List<GGroups> list1 = new ArrayList<>();

View File

@ -83,12 +83,23 @@ public class GSitesServiceImpl extends ServiceImpl<GSiteGroupsMapper,GSiteGroups
if (Objects.nonNull(sameNameSite)) {
throw new ServiceException("站点名称重复!");
}
//是否选择行政区域
if (StringUtils.isBlank(gGroupSiteDto.getAreaCode())) {
throw new ServiceException("请选择行政区域!");
}
if(StringUtils.isBlank(gGroupSiteDto.getFullAreaCode())){
throw new ServiceException("请提交行政区域完整编码!");
}
//未上传站点地图json数据
if(StringUtils.isBlank(gGroupSiteDto.getIcon())){
throw new ServiceException("请选择站点图标!");
}
//设置坐标值等信息
getReadJsonFileContent(gSites);
//设置行政区域编码
gSites.setAreaCode(gGroupSiteDto.getAreaCode());
//设置行政区域完整编码
gSites.setFullAreaCode(gGroupSiteDto.getFullAreaCode());
//插入站点表
int inserted = gSitesMapper.insert(gSites);
gGroupSiteDto.setSiteId(gSites.getId());
@ -163,6 +174,7 @@ public class GSitesServiceImpl extends ServiceImpl<GSiteGroupsMapper,GSiteGroups
if (Objects.nonNull(sameNameSite)) {
throw new ServiceException("站点名称重复!");
}
GSites sites = new GSites();
BeanUtils.copyProperties(gSitesEditDto, sites);
//读取文件内容

View File

@ -18,10 +18,13 @@
<result property="spaceValue" column="space_value" />
<result property="dataDevices" column="data_devices" />
<result property="videoDevices" column="video_devices" />
<result property="typeId" column="type_id" />
<result property="areaCode" column="area_code" />
<result property="fullAreaCode" column="full_area_code" />
</resultMap>
<sql id="selectGSitesVo">
select id, name, icon, type, create_by, create_time, update_time, update_by, space, project_id, space_value, data_devices, video_devices from g_sites
select id, name, icon, type, create_by, create_time, update_time, update_by, space, project_id, space_value, data_devices, video_devices, type_id, area_code, full_area_code from g_sites
</sql>
<select id="selectGSitesList" parameterType="GSites" resultMap="GSitesResult">
@ -35,6 +38,9 @@
<if test="spaceValue != null and spaceValue != ''"> and space_value = #{spaceValue}</if>
<if test="dataDevices != null and dataDevices != ''"> and data_devices = #{dataDevices}</if>
<if test="videoDevices != null and videoDevices != ''"> and video_devices = #{videoDevices}</if>
<if test="typeId != null "> and type_id = #{typeId}</if>
<if test="areaCode != null and areaCode != ''"> and area_code = #{areaCode}</if>
<if test="fullAreaCode != null and fullAreaCode != ''"> and full_area_code = #{fullAreaCode}</if>
</where>
</select>
@ -58,6 +64,9 @@
<if test="spaceValue != null">space_value,</if>
<if test="dataDevices != null">data_devices,</if>
<if test="videoDevices != null">video_devices,</if>
<if test="typeId != null">type_id,</if>
<if test="areaCode != null">area_code,</if>
<if test="fullAreaCode != null">full_area_code,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if>
@ -72,6 +81,9 @@
<if test="spaceValue != null">#{spaceValue},</if>
<if test="dataDevices != null">#{dataDevices},</if>
<if test="videoDevices != null">#{videoDevices},</if>
<if test="typeId != null">#{typeId},</if>
<if test="areaCode != null">#{areaCode},</if>
<if test="fullAreaCode != null">#{fullAreaCode},</if>
</trim>
</insert>
@ -90,6 +102,9 @@
<if test="spaceValue != null">space_value = #{spaceValue},</if>
<if test="dataDevices != null">data_devices = #{dataDevices},</if>
<if test="videoDevices != null">video_devices = #{videoDevices},</if>
<if test="typeId != null">type_id = #{typeId},</if>
<if test="areaCode != null">area_code = #{areaCode},</if>
<if test="fullAreaCode != null">full_area_code = #{fullAreaCode},</if>
</trim>
where id = #{id}
</update>

View File

@ -198,7 +198,8 @@ public class ProjectServiceImpl implements IProjectService
//查询该管理员所管理的项目id以及子项目id列表
Project project = new LambdaQueryChainWrapper<>(projectMapper)
.select(Project::getId, Project::getProjectName,Project::getLevel,Project::getDeptId)
.select(Project::getId, Project::getProjectName,Project::getLevel,Project::getDeptId
,Project::getCityCode,Project::getCountyCode)
.eq(Project::getDeptId, sysUser.getDeptId())
.one();
if(Objects.isNull(project)){
@ -211,7 +212,16 @@ public class ProjectServiceImpl implements IProjectService
map.put("projectIds",projectsBase64);
map.put("projectId",project.getId());
map.put("projectName", project.getProjectName());
map.put("projectLevel",project.getLevel().equals("市级")? ProjectLevelConstant.LEVEL_CITY :ProjectLevelConstant.LEVEL_COUNTY);
if(project.getLevel().equals("市级")){
map.put("projectLevel", ProjectLevelConstant.LEVEL_CITY);
map.put("projectAreaCode", JSONUtil.parseArray(project.getCityCode()).get(0));
}
if(project.getLevel().equals("县级")){
map.put("projectLevel", ProjectLevelConstant.LEVEL_COUNTY);
map.put("projectAreaCode",JSONUtil.parseArray(project.getCountyCode()).get(0));
}
return map;
}
@ -298,8 +308,8 @@ public class ProjectServiceImpl implements IProjectService
.in(SysDistrict::getAdcode,administrativeCodeList)
.list();
System.err.println("项目所属县下面的所有镇、村行政区划列表");
System.err.println(projectDistrictList);
// System.err.println("项目所属县下面的所有镇、村行政区划列表");
// System.err.println(projectDistrictList);
//构建树状结构
return buildTree(projectDistrictList);
}
@ -343,10 +353,10 @@ public class ProjectServiceImpl implements IProjectService
distinctTownCodeList = townCodeList.stream().distinct().collect(Collectors.toList());
JSONArray villageCodeList = JSONUtil.parseArray(project.getVillageCode());
System.err.println("镇行政区划代码");
System.err.println(distinctTownCodeList);
System.err.println("村行政区划代码");
System.err.println(villageCodeList);
// System.err.println("镇行政区划代码");
// System.err.println(distinctTownCodeList);
// System.err.println("村行政区划代码");
// System.err.println(villageCodeList);
//合并省村行政区划代码集合
List<Object> administrativeCodeList = new ArrayList<>();
int[] startLevels = {1, 2, 3, 4, 5};
@ -360,8 +370,8 @@ public class ProjectServiceImpl implements IProjectService
break;
}
}
System.err.println("合并后镇、村行政区划代码");
System.err.println(administrativeCodeList);
// System.err.println("合并后镇、村行政区划代码");
// System.err.println(administrativeCodeList);
return administrativeCodeList;
}

View File

@ -59,5 +59,11 @@ public interface ISysDistrictService
*/
public int deleteSysDistrictById(Long id);
List<SysDistrict> selectSysDistrictTree();
List<SysDistrict> selectSysDistrictTree(Integer level);
/**
* 查询指定地区行政区划树状列表
*/
List<SysDistrict> selectSysDistrictTreeByCode(Long areaCode);
}

View File

@ -9,6 +9,7 @@ import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONException;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.fastbee.common.exception.ServiceException;
import org.apache.commons.lang3.StringUtils;
@ -69,9 +70,6 @@ public class SysDistrictServiceImpl implements ISysDistrictService
/**
* 修改行政区划
*
* @param sysDistrict 行政区划
* @return 结果
*/
@Override
public int updateSysDistrict(SysDistrict sysDistrict)
@ -118,9 +116,6 @@ public class SysDistrictServiceImpl implements ISysDistrictService
/**
* 批量删除行政区划
*
* @param ids 需要删除的行政区划主键
* @return 结果
*/
@Override
public int deleteSysDistrictByIds(Long[] ids)
@ -130,9 +125,6 @@ public class SysDistrictServiceImpl implements ISysDistrictService
/**
* 删除行政区划信息
*
* @param id 行政区划主键
* @return 结果
*/
@Override
public int deleteSysDistrictById(Long id)
@ -142,19 +134,52 @@ public class SysDistrictServiceImpl implements ISysDistrictService
/**
* 查询行政区划树状列表
* @return 树状列表
*/
@Override
public List<SysDistrict> selectSysDistrictTree() {
public List<SysDistrict> selectSysDistrictTree(Integer level) {
System.err.println("等级:level:"+level);
//计算查询用时
long startTime = System.currentTimeMillis();
List<SysDistrict> sysDistrictList = new LambdaQueryChainWrapper<>(sysDistrictMapper)
.select(SysDistrict::getId,SysDistrict::getAdcode, SysDistrict::getParentId, SysDistrict::getName,
SysDistrict::getFullName )
.ge(Objects.nonNull(level),SysDistrict::getLevel, level)
.list();
System.err.println("查询用时:"+(System.currentTimeMillis()-startTime));
return buildTree(sysDistrictList);
}
/**
* 查询指定地区行政区划树状列表
*/
@Override
public List<SysDistrict> selectSysDistrictTreeByCode(Long areaCode) {
LambdaQueryChainWrapper<SysDistrict> sysDistrictLambdaQueryChainWrapper = new LambdaQueryChainWrapper<>(sysDistrictMapper)
.select(SysDistrict::getId, SysDistrict::getParentId, SysDistrict::getName, SysDistrict::getAdcode,
SysDistrict::getLevel, SysDistrict::getFullName, SysDistrict::getName
, SysDistrict::getLng, SysDistrict::getLat);
//获取子级别
List<SysDistrict> sysDistrictList = sysDistrictLambdaQueryChainWrapper.eq(SysDistrict::getAdcode, areaCode)
.list();
if (Objects.isNull(sysDistrictList) || sysDistrictList.isEmpty()) {
throw new ServiceException("未查询到指定地区行政区划树状列表!");
}
//查询全部
List<SysDistrict> sysDistrictListAll = new LambdaQueryChainWrapper<>(sysDistrictMapper)
.select(SysDistrict::getId, SysDistrict::getParentId, SysDistrict::getName, SysDistrict::getAdcode,
SysDistrict::getLevel, SysDistrict::getFullName, SysDistrict::getName
, SysDistrict::getLng, SysDistrict::getLat)
.ge(SysDistrict::getAdcode, areaCode)
.lt(SysDistrict::getAdcode, (Long.parseLong(areaCode.toString().substring(0,2))+1)*10000000000L)
.list();
return buildTree(sysDistrictList);
System.err.println("查询到全部列表上限条件");
System.err.println(((Long.parseLong(areaCode.toString().substring(0,2))+1)*10000000000L));
List<SysDistrict> sysDistricts = buildTree(sysDistrictListAll);
return Collections.singletonList(sysDistricts.get(0));
}
private List<SysDistrict> buildTree(List<SysDistrict> SysDistricts) {
Map<Long, SysDistrict> map = new HashMap<>();
List<SysDistrict> roots = new ArrayList<>();