查询项目的行政区域信息接口,项目相关管理接口逻辑完善,行政区划管理相关接口逻辑完善

This commit is contained in:
mi9688 2024-10-25 18:08:22 +08:00
parent 9912eb5671
commit c19a08f78c
14 changed files with 425 additions and 59 deletions

View File

@ -102,11 +102,11 @@ public class GLegendController extends BaseController
/**
* 删除图例
*/
@DeleteMapping("/{ids}")
@DeleteMapping("/{id}")
@ApiOperation("删除图例")
public AjaxResult remove(@PathVariable Long[] ids)
public AjaxResult remove(@PathVariable Long id)
{
return toAjax(gLegendService.deleteGLegendByIds(ids));
return toAjax(gLegendService.deleteGLegendById(id));
}
/**

View File

@ -139,4 +139,13 @@ public class ProjectController extends BaseController
public AjaxResult getUnbindProjectDeptList(){
return success(projectService.getUnbindDeptList());
}
/**
* 查询项目的行政区划树状列表
*/
@GetMapping("/areaTree/{projectId}/{reachLevel}")
@ApiOperation("查询项目的行政区划树状列表")
public AjaxResult getProjectAreaTree(@PathVariable("projectId") Long projectId, @PathVariable("reachLevel") Integer reachLevel){
return success(projectService.getProjectAreaTree(projectId, reachLevel));
}
}

View File

@ -68,4 +68,7 @@ public class GSites extends BaseEntity {
@Excel(name = "关联的视频设备")
@ApiModelProperty("关联的视频设备")
private String videoDevices;
/** 类型id(即图例id) */
private Long typeId;
}

View File

@ -33,9 +33,9 @@ public interface IGLegendService
int updateGLegend(GLegend gLegend);
/**
* 批量删除图例
* 删除图例
*/
int deleteGLegendByIds(Long[] ids);
int deleteGLegendById(Long id);
/**

View File

@ -132,8 +132,8 @@ public class GGroupsServiceImpl implements IGGroupsService
List<GGroups> roots = new ArrayList<>();
//所有站点列表
List<GGroupSiteVo> gGroupSiteAllList = selectGGroupsAllListSites(new GGroups());
System.err.println("当前项目下所有站点:");
gGroupSiteAllList.forEach(System.err::println);
// System.err.println("当前项目下所有站点:");
// gGroupSiteAllList.forEach(System.err::println);
for (GGroups group : groupsList) {
//查询组的直接子站点列表

View File

@ -3,18 +3,23 @@ package com.fastbee.ggroup.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.ggroup.domain.GSites;
import com.fastbee.ggroup.enums.SiteTypeCategoryEnum;
import com.fastbee.ggroup.mapper.GSitesMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.fastbee.ggroup.mapper.GLegendMapper;
import com.fastbee.ggroup.domain.GLegend;
import com.fastbee.ggroup.service.IGLegendService;
import org.springframework.transaction.annotation.Transactional;
/**
* 图例Service业务层处理
@ -29,8 +34,11 @@ public class GLegendServiceImpl implements IGLegendService
private final GLegendMapper gLegendMapper;
public GLegendServiceImpl(GLegendMapper gLegendMapper) {
private final GSitesMapper gSitesMapper;
public GLegendServiceImpl(GLegendMapper gLegendMapper, GSitesMapper gSitesMapper) {
this.gLegendMapper = gLegendMapper;
this.gSitesMapper = gSitesMapper;
}
@ -95,6 +103,7 @@ public class GLegendServiceImpl implements IGLegendService
* @return 结果
*/
@Override
@Transactional(rollbackFor=Exception. class)
public int updateGLegend(GLegend gLegend)
{
//图例名称不能重复
@ -105,21 +114,35 @@ public class GLegendServiceImpl implements IGLegendService
if(!duplicateNameList.isEmpty()){
throw new ServiceException("图例名称已存在!");
}
gLegend.setUpdateTime(DateUtils.getNowDate());
return gLegendMapper.updateGLegend(gLegend);
}
/**
* 批量删除图例
* 删除图例
*
* @param ids 需要删除的图例主键
* @param id 需要删除的图例主键
* @return 结果
*/
@Override
public int deleteGLegendByIds(Long[] ids)
public int deleteGLegendById(Long id)
{
return gLegendMapper.deleteGLegendByIds(ids);
List<GLegend> list = new LambdaQueryChainWrapper<>(gLegendMapper)
.select(GLegend::getId, GLegend::getName)
.eq(GLegend::getId, id).list();
if (list.isEmpty()){
throw new ServiceException("图例不存在!");
}
List<GSites> gSitesList = new LambdaQueryChainWrapper<>(gSitesMapper)
.select(GSites::getId, GSites::getType)
.eq(GSites::getType, list.get(0).getName())
.list();
if(!gSitesList.isEmpty()){
throw new ServiceException("图例已被站点使用,无法删除!");
}
return gLegendMapper.deleteById(id);
}
/**

View File

@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fastbee.common.annotation.Excel;
import com.fastbee.common.core.domain.BaseEntity;
@ -11,7 +13,7 @@ import com.fastbee.common.core.domain.BaseEntity;
* 项目对象 project
*
* @author kerwincui
* @date 2024-10-18
* @date 2024-10-25
*/
@ApiModel(value = "Project",description = "项目 project")
@Data
@ -121,9 +123,34 @@ public class Project extends BaseEntity
@ApiModelProperty("项目所属机构名称")
private String deptName;
/** 项目级别:市,县 */
@Excel(name = "项目级别:市,县")
@ApiModelProperty("项目级别:市,县")
/** 项目级别:1市级2县级 */
@Excel(name = "项目级别:1市级2县级")
@ApiModelProperty("项目级别:1市级2县级")
private String level;
/** 行政区域省代码 */
@Excel(name = "行政区域省代码")
@ApiModelProperty("行政区域省代码")
private String provinceCode;
/** 行政区域市代码 */
@Excel(name = "行政区域市代码")
@ApiModelProperty("行政区域市代码")
private String cityCode;
/** 行政区域县代码 */
@Excel(name = "行政区域县代码")
@ApiModelProperty("行政区域县代码")
private String countyCode;
/** 行政区域镇代码 */
@Excel(name = "行政区域镇代码")
@ApiModelProperty("行政区域镇代码")
private String townCode;
/** 行政区域村代码 */
@Excel(name = "行政区域村代码")
@ApiModelProperty("行政区域村代码")
private String villageCode;
}

View File

@ -23,7 +23,7 @@ public interface ProjectMapper extends MPJBaseMapper<Project>
* @param projectId 项目主键
* @return 项目
*/
Project selectProjectByProjectId(Long projectId);
Project selectProjectById(Long projectId);
/**
* 查询项目列表

View File

@ -2,6 +2,7 @@ package com.fastbee.project.service;
import com.fastbee.common.core.domain.entity.SysDept;
import com.fastbee.project.domain.Project;
import com.fastbee.system.domain.SysDistrict;
import java.util.List;
import java.util.Map;
@ -73,4 +74,9 @@ public interface IProjectService
*/
List<Project> selectAdminProjectList();
/**
* 获取项目行政区域列表
* @return 行政区域列表
*/
List<SysDistrict> getProjectAreaTree(Long projectId,Integer reachLevel);
}

View File

@ -1,6 +1,9 @@
package com.fastbee.project.service.impl;
import cn.hutool.core.codec.Base64;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONException;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.fastbee.common.constant.ProjectLevelConstant;
import com.fastbee.common.core.domain.entity.SysDept;
@ -12,12 +15,15 @@ import com.fastbee.project.domain.Project;
import com.fastbee.project.mapper.ProjectMapper;
import com.fastbee.project.service.IProjectService;
import com.fastbee.system.domain.SysDistrict;
import com.fastbee.system.mapper.SysDeptMapper;
import com.fastbee.system.mapper.SysDistrictMapper;
import com.fastbee.system.mapper.SysUserMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* 项目Service业务层处理
@ -33,10 +39,13 @@ public class ProjectServiceImpl implements IProjectService
private final SysDeptMapper sysDeptMapper;
private final SysUserMapper sysUserMapper;
public ProjectServiceImpl(ProjectMapper projectMapper, SysDeptMapper sysDeptMapper, SysUserMapper sysUserMapper) {
private final SysDistrictMapper sysDistrictMapper;
public ProjectServiceImpl(ProjectMapper projectMapper, SysDeptMapper sysDeptMapper, SysUserMapper sysUserMapper, SysDistrictMapper sysDistrictMapper) {
this.projectMapper = projectMapper;
this.sysDeptMapper = sysDeptMapper;
this.sysUserMapper = sysUserMapper;
this.sysDistrictMapper = sysDistrictMapper;
}
/**
@ -48,7 +57,7 @@ public class ProjectServiceImpl implements IProjectService
@Override
public Project selectProjectByProjectId(Long projectId)
{
return projectMapper.selectProjectByProjectId(projectId);
return projectMapper.selectProjectById(projectId);
}
/**
@ -59,9 +68,10 @@ public class ProjectServiceImpl implements IProjectService
{
return new LambdaQueryChainWrapper<>(projectMapper)
.select(Project::getId, Project::getProjectName, Project::getScope,
Project::getAdministrativeArea, Project::getDeptId,Project::getAdministrativeAreaCode,
Project::getDeptId,
Project::getLogo, Project::getImage, Project::getLevel, Project::getDeptName,
Project::getCreateTime)
Project::getCreateTime,
Project::getAdministrativeAreaCode,Project::getAdministrativeArea, Project::getProvinceCode,Project::getCityCode,Project::getCountyCode)
.like(StringUtils.isNotBlank(project.getSearchValue()),Project::getProjectName, project.getSearchValue())
.list();
}
@ -72,16 +82,76 @@ public class ProjectServiceImpl implements IProjectService
@Override
public int insertProject(Project project)
{ //判断选择的机构下是否已经绑定项目
List<Project> projectList = new LambdaQueryChainWrapper<>(projectMapper)
.select(Project::getId, Project::getProjectName)
.eq(Project::getDeptId, project.getDeptId()).list();
if(!projectList.isEmpty()){
throw new ServiceException("该机构下已经存在项目");
// List<Project> projectList = new LambdaQueryChainWrapper<>(projectMapper)
// .select(Project::getId, Project::getProjectName)
// .eq(Project::getDeptId, project.getDeptId()).list();
// if(!projectList.isEmpty()){
// throw new ServiceException("该机构下已经存在项目");
// }
//项目行政区域处理
//拆解项目行政区域代码信息
if(StringUtils.isBlank(project.getAdministrativeAreaCode())){
throw new ServiceException("项目行政区域代码不能为空!");
}
//判断行政区域代码json格式
if(isNotValidJsonArray(project.getAdministrativeAreaCode())){
throw new ServiceException("项目行政区域代码多选列表非json数组");
}
//项目省代码列表
List<String> provincialCodeList =new ArrayList<>();
//项目市代码列表
List<String> cityCodeList =new ArrayList<>();
//项目县代码列表
List<String> countyCodeList =new ArrayList<>();
//项目镇代码列表
List<String> townCodeList =new ArrayList<>();
//项目村代码列表
List<String> villageCodeList =new ArrayList<>();
JSONArray administrativeAreaList = JSONUtil.parseArray(project.getAdministrativeAreaCode());
administrativeAreaList.forEach(item->{
if(isNotValidJsonArray(item.toString())){
throw new ServiceException("项目行政区域代码多选列表的元素非json数组");
}
//单个行政区划代码列表
JSONArray administrativeArea = JSONUtil.parseArray(item);
//拆解出每个行政区划代码里面的镇或村
if(administrativeArea.size()!=5){
throw new ServiceException("项目行政区域代码多选列表的元素长度必须为5到达村级别");
}
//保存项目省代码列表
provincialCodeList.add(administrativeArea.get(0).toString());
//保存项目市代码列表
cityCodeList.add(administrativeArea.get(1).toString());
//保存项目县代码列表
countyCodeList.add(administrativeArea.get(2).toString());
//保存项目镇代码列表
townCodeList.add(administrativeArea.get(3).toString());
//保存项目村代码列表
villageCodeList.add(administrativeArea.get(4).toString());
});
//设置项目省村行政区划代码列表
project.setProvinceCode(JSONUtil.toJsonStr(provincialCodeList));
project.setCityCode(JSONUtil.toJsonStr(cityCodeList));
project.setCountyCode(JSONUtil.toJsonStr(countyCodeList));
project.setTownCode(JSONUtil.toJsonStr(townCodeList));
project.setVillageCode(JSONUtil.toJsonStr(villageCodeList));
project.setCreateTime(DateUtils.getNowDate());
return projectMapper.insertProject(project);
}
/**
* 验证json对象是否是数组
*/
public boolean isNotValidJsonArray(String jsonStr) {
try {
JSONUtil.parseArray(jsonStr);
} catch (JSONException e) {
return true;
}
return false;
}
/**
* 修改项目
*/
@ -186,11 +256,154 @@ public class ProjectServiceImpl implements IProjectService
//查询所有子一级项目列表
projectList = new LambdaQueryChainWrapper<>(projectMapper)
.select(Project::getId, Project::getProjectName)
.in(!ProjectHolder.getProjectInfo().getProjectIdList().isEmpty(),Project::getParentId, ProjectHolder.getProjectInfo().getProjectIdList())
.in(!ProjectHolder.getProjectInfo().getProjectIdList().isEmpty(),Project::getParentId,
ProjectHolder.getProjectInfo().getProjectIdList())
.list();
}
return projectList;
}
/**
* 查询项目的行政区划树状列表
*/
@Override
public List<SysDistrict> getProjectAreaTree(Long projectId,Integer startLevel) {
//参数校验
if(startLevel>5||startLevel<1){
throw new ServiceException("超出行政级别查询范围(1~5级)!");
}
//查询项目的行政区划信息
Project project = new LambdaQueryChainWrapper<>(projectMapper)
.select(Project::getProvinceCode, Project::getCityCode, Project::getCountyCode,
Project::getTownCode, Project::getVillageCode)
.eq(Project::getId, projectId)
.one();
if (Objects.isNull(project)) {
throw new ServiceException("项目不存在");
}
//判断项目的省村行政区划列表数据不为null
isProvinceCodeBlank(project);
//查询项目的省村行政区划列表数据
//目前项目下面的镇或者村都可以多选划分成一个项目
//找到项目行政区划开始多选的级别
//判断省是否多选
JSONArray provinceCodeList = JSONUtil.parseArray(project.getProvinceCode());
//判断集合中的元素值都相等则说明省未多选
if (!provinceCodeList.stream().allMatch(provinceCode -> provinceCode.equals(provinceCodeList.get(0)))) {
throw new ServiceException("项目省级行政区划只能包含一个省!");
}
//判断市是否多选
JSONArray cityCodeList = JSONUtil.parseArray(project.getCityCode());
//判断集合中的元素值都相等则说明市未多选
if (!cityCodeList.stream().allMatch(cityCode -> cityCode.equals(cityCodeList.get(0)))) {
throw new ServiceException("项目市级行政区划只能包含一个市!");
}
//判断县是否多选
JSONArray countyCodeList = JSONUtil.parseArray(project.getCountyCode());
//判断集合中的元素值都相等则说明县未多选
if (!countyCodeList.stream().allMatch(countyCode -> countyCode.equals(countyCodeList.get(0)))) {
throw new ServiceException("项目县级行政区划只能包含一个县!");
}
//判断镇是否多选
JSONArray townCodeList = JSONUtil.parseArray(project.getTownCode());
//判断集合中的元素值都相等则说明镇未多选
List<Object> distinctTownCodeList = new ArrayList<>();
// if (!townCodeList.stream().allMatch(townCode -> townCode.equals(townCodeList.get(0)))) {
//找出选择了哪些镇,给元素去重
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);
//合并镇村行政区划代码集合
List<Object> townAndvillageCodeList = new ArrayList<>();
townAndvillageCodeList.addAll(distinctTownCodeList);
townAndvillageCodeList.addAll(villageCodeList);
System.err.println("合并后镇、村行政区划代码");
System.err.println(townAndvillageCodeList);
//查询项目所属县下面的所有镇村行政区划列表
List<SysDistrict> projectDistrictList =new ArrayList<>();
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<Integer> administrativeDivisionLevelList=new ArrayList<>();
// //倒叙循环reachLevel次
// for (int i = startLevel;i<6; i++) {
// administrativeDivisionLevelList.add(i);
// }
//限制行政区划级别
projectDistrictList = sysDistrictLambdaQueryChainWrapper
// .in(SysDistrict::getLevel, administrativeDivisionLevelList)
// .eq(SysDistrict::getParentId, countyCodeList.get(0))
// .in(SysDistrict::getAdcode,townAndvillageCodeList)
.list();
//过滤掉非项目行政区划的省份数据
projectDistrictList = projectDistrictList.stream().
filter(sysDistrict -> (
sysDistrict.getAdcode().toString().equals(provinceCodeList.get(0).toString())
&& sysDistrict.getParentId()==null
// ||!sysDistrict.getAdcode().equals(cityCodeList.get(0))
// ||!sysDistrict.getAdcode().equals(countyCodeList.get(0))
)
)
.collect(Collectors.toList());
System.err.println("项目所属县下面的所有镇、村行政区划列表");
System.err.println(projectDistrictList);
//构建树状结构
return buildTree(projectDistrictList);
}
private static void isProvinceCodeBlank(Project project) {
if (StringUtils.isBlank(project.getProvinceCode())){
throw new ServiceException("项目省级行政区划信息缺失!");
}
if (StringUtils.isBlank(project.getCityCode())){
throw new ServiceException("项目市级行政区划信息缺失!");
}
if (StringUtils.isBlank(project.getCountyCode())){
throw new ServiceException("项目县级行政区划信息缺失!");
}
if (StringUtils.isBlank(project.getTownCode())){
throw new ServiceException("项目镇级行政区划信息缺失!");
}
if (StringUtils.isBlank(project.getVillageCode())){
throw new ServiceException("项目村级行政区划信息缺失!");
}
}
private List<SysDistrict> buildTree(List<SysDistrict> SysDistricts) {
Map<Long, SysDistrict> map = new HashMap<>();
List<SysDistrict> roots = new ArrayList<>();
for (SysDistrict sysDistrict : SysDistricts) {
map.put(sysDistrict.getAdcode(), sysDistrict);
}
return getDistricts(SysDistricts, map, roots);
}
private List<SysDistrict> getDistricts(List<SysDistrict> SysDistricts, Map<Long, SysDistrict> map, List<SysDistrict> roots) {
for (SysDistrict sysDistrict : SysDistricts) {
Long parentId = sysDistrict.getParentId();
if (parentId == null || !map.containsKey(parentId)) {
roots.add(sysDistrict);
} else {
SysDistrict parent = map.get(parentId);
if (parent.getChildren() == null) {
parent.setChildren(new ArrayList<>());
}
parent.getChildren().add(sysDistrict);
}
}
return roots;
}
public List<Long> getAllProjects(Long projectId) {
List<Long> allProjects = new ArrayList<>();

View File

@ -31,10 +31,15 @@
<result property="administrativeAreaCode" column="administrative_area_code" />
<result property="deptName" column="dept_name" />
<result property="level" column="level" />
<result property="provinceCode" column="province_code" />
<result property="cityCode" column="city_code" />
<result property="countyCode" column="county_code" />
<result property="townCode" column="town_code" />
<result property="villageCode" column="village_code" />
</resultMap>
<sql id="selectProjectVo">
select id, project_name, sys_show_name, central_coordinates, scope, administrative_area, owner, logo, image, video_introduction, remark, p_params, introduce, del_flag, create_time, create_by, update_time, remarks, tenant_id, tenant_name, owner_id, parent_id, dept_id, administrative_area_code, dept_name, level from project
select id, project_name, sys_show_name, central_coordinates, scope, administrative_area, owner, logo, image, video_introduction, remark, p_params, introduce, del_flag, create_time, create_by, update_time, remarks, tenant_id, tenant_name, owner_id, parent_id, dept_id, administrative_area_code, dept_name, level, province_code, city_code, county_code, town_code, village_code from project
</sql>
<select id="selectProjectList" parameterType="Project" resultMap="ProjectResult">
@ -60,18 +65,22 @@
<if test="administrativeAreaCode != null and administrativeAreaCode != ''"> and administrative_area_code = #{administrativeAreaCode}</if>
<if test="deptName != null and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
<if test="level != null and level != ''"> and level = #{level}</if>
<if test="provinceCode != null and provinceCode != ''"> and province_code = #{provinceCode}</if>
<if test="cityCode != null and cityCode != ''"> and city_code = #{cityCode}</if>
<if test="countyCode != null and countyCode != ''"> and county_code = #{countyCode}</if>
<if test="townCode != null and townCode != ''"> and town_code = #{townCode}</if>
<if test="villageCode != null and villageCode != ''"> and village_code = #{villageCode}</if>
</where>
</select>
<select id="selectProjectByProjectId" parameterType="Long" resultMap="ProjectResult">
<select id="selectProjectById" parameterType="Long" resultMap="ProjectResult">
<include refid="selectProjectVo"/>
where id = #{id}
</select>
<insert id="insertProject" parameterType="Project">
<insert id="insertProject" parameterType="Project" useGeneratedKeys="true" keyProperty="id">
insert into project
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="projectName != null and projectName != ''">project_name,</if>
<if test="sysShowName != null and sysShowName != ''">sys_show_name,</if>
<if test="centralCoordinates != null and centralCoordinates != ''">central_coordinates,</if>
@ -97,9 +106,13 @@
<if test="administrativeAreaCode != null">administrative_area_code,</if>
<if test="deptName != null">dept_name,</if>
<if test="level != null">level,</if>
<if test="provinceCode != null">province_code,</if>
<if test="cityCode != null">city_code,</if>
<if test="countyCode != null">county_code,</if>
<if test="townCode != null">town_code,</if>
<if test="villageCode != null">village_code,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="projectName != null and projectName != ''">#{projectName},</if>
<if test="sysShowName != null and sysShowName != ''">#{sysShowName},</if>
<if test="centralCoordinates != null and centralCoordinates != ''">#{centralCoordinates},</if>
@ -125,6 +138,11 @@
<if test="administrativeAreaCode != null">#{administrativeAreaCode},</if>
<if test="deptName != null">#{deptName},</if>
<if test="level != null">#{level},</if>
<if test="provinceCode != null">#{provinceCode},</if>
<if test="cityCode != null">#{cityCode},</if>
<if test="countyCode != null">#{countyCode},</if>
<if test="townCode != null">#{townCode},</if>
<if test="villageCode != null">#{villageCode},</if>
</trim>
</insert>
@ -156,17 +174,22 @@
<if test="administrativeAreaCode != null">administrative_area_code = #{administrativeAreaCode},</if>
<if test="deptName != null">dept_name = #{deptName},</if>
<if test="level != null">level = #{level},</if>
<if test="provinceCode != null">province_code = #{provinceCode},</if>
<if test="cityCode != null">city_code = #{cityCode},</if>
<if test="countyCode != null">county_code = #{countyCode},</if>
<if test="townCode != null">town_code = #{townCode},</if>
<if test="villageCode != null">village_code = #{villageCode},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteProjectByProjectId" parameterType="Long">
<delete id="deleteProjectById" parameterType="Long">
delete from project where id = #{id}
</delete>
<delete id="deleteProjectByProjectIds" parameterType="String">
<delete id="deleteProjectByIds" parameterType="String">
delete from project where id in
<foreach item="projectId" collection="array" open="(" separator="," close=")">
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>

View File

@ -16,7 +16,7 @@ import com.fastbee.common.core.domain.BaseEntity;
* 行政区划对象 sys_district
*
* @author kerwincui
* @date 2024-10-18
* @date 2024-10-25
*/
@ApiModel(value = "SysDistrict",description = "行政区划 sys_district")
@Data
@ -38,9 +38,9 @@ private static final long serialVersionUID = 1L;
@ApiModelProperty("省市级别")
private Long level;
/** 父级id */
@Excel(name = "父级id")
@ApiModelProperty("父级id")
/** 父级id(指向adcode字段) */
@Excel(name = "父级id(指向adcode字段)")
@ApiModelProperty("父级id(指向adcode字段)")
private Long parentId;
/** 简称 */
@ -66,5 +66,16 @@ private static final long serialVersionUID = 1L;
/** 删除标志0代表存在 2代表删除 */
private String delFlag;
/** 行政区域地图轮廓json数据 */
@Excel(name = "行政区域地图轮廓json数据")
@ApiModelProperty("行政区域地图轮廓json数据")
private String mapOutline;
/** 行政区域地图轮廓json数据url */
@Excel(name = "行政区域地图轮廓json数据url")
@ApiModelProperty("行政区域地图轮廓json数据url")
private String mapOutlineUrl;
private List<SysDistrict> children;
}

View File

@ -1,13 +1,17 @@
package com.fastbee.system.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONException;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.fastbee.common.exception.ServiceException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.system.mapper.SysDistrictMapper;
@ -72,9 +76,46 @@ public class SysDistrictServiceImpl implements ISysDistrictService
@Override
public int updateSysDistrict(SysDistrict sysDistrict)
{
String mapOutlineUrl = sysDistrict.getMapOutlineUrl();
//未上传行政区划轮廓不做处理
if(StringUtils.isBlank(mapOutlineUrl)){
return sysDistrictMapper.updateSysDistrict(sysDistrict);
}
//判断行政区划轮廓json文件路url是否是完整url还是相对url
if((mapOutlineUrl.contains("http://") || mapOutlineUrl.contains("https://"))){
//如果不是是相对url则代表修改过行政区划轮廓数据
String jsonData = HttpUtil.get(mapOutlineUrl);
System.err.println("获取到行政区划轮廓json:"+jsonData);
//读取文件内容
if (Objects.isNull(jsonData)) {
throw new ServiceException("上传行政区划地图轮廓json数据为空");
}
//校验文件内容是否是json格式
if (!isValidJson(jsonData)) {
throw new ServiceException("json格式不正确");
}
int startIndex = mapOutlineUrl.indexOf("/profile/upload/");
String relativeUrl = mapOutlineUrl.substring(startIndex);
sysDistrict.setMapOutlineUrl(relativeUrl);
sysDistrict.setMapOutline(jsonData);
}
return sysDistrictMapper.updateSysDistrict(sysDistrict);
}
/**
* 验证字符串是否是json格式
*/
public boolean isValidJson(String jsonStr) {
try {
JSONUtil.parseObj(jsonStr);
} catch (JSONException e) {
return false;
}
return true;
}
/**
* 批量删除行政区划
*

View File

@ -14,10 +14,12 @@
<result property="lng" column="lng" />
<result property="lat" column="lat" />
<result property="delFlag" column="del_flag" />
<result property="mapOutline" column="map_outline" />
<result property="mapOutlineUrl" column="map_outline_url" />
</resultMap>
<sql id="selectSysDistrictVo">
select id, adcode, level, parent_id, name, full_name, lng, lat, del_flag from sys_district
select id, adcode, level, parent_id, name, full_name, lng, lat, del_flag, map_outline, map_outline_url from sys_district
</sql>
<select id="selectSysDistrictList" parameterType="SysDistrict" resultMap="SysDistrictResult">
@ -30,6 +32,8 @@
<if test="fullName != null and fullName != ''"> and full_name like concat('%', #{fullName}, '%')</if>
<if test="lng != null "> and lng = #{lng}</if>
<if test="lat != null "> and lat = #{lat}</if>
<if test="mapOutline != null and mapOutline != ''"> and map_outline = #{mapOutline}</if>
<if test="mapOutlineUrl != null and mapOutlineUrl != ''"> and map_outline_url = #{mapOutlineUrl}</if>
</where>
</select>
@ -49,6 +53,8 @@
<if test="lng != null">lng,</if>
<if test="lat != null">lat,</if>
<if test="delFlag != null">del_flag,</if>
<if test="mapOutline != null">map_outline,</if>
<if test="mapOutlineUrl != null">map_outline_url,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="adcode != null">#{adcode},</if>
@ -59,6 +65,8 @@
<if test="lng != null">#{lng},</if>
<if test="lat != null">#{lat},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="mapOutline != null">#{mapOutline},</if>
<if test="mapOutlineUrl != null">#{mapOutlineUrl},</if>
</trim>
</insert>
@ -73,6 +81,8 @@
<if test="lng != null">lng = #{lng},</if>
<if test="lat != null">lat = #{lat},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="mapOutline != null">map_outline = #{mapOutline},</if>
<if test="mapOutlineUrl != null">map_outline_url = #{mapOutlineUrl},</if>
</trim>
where id = #{id}
</update>