16 changed files with 548 additions and 2 deletions
@ -0,0 +1,71 @@ |
|||||
|
package org.dromara.business.controller; |
||||
|
|
||||
|
|
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.dromara.business.domain.BusinessDepartBoundary; |
||||
|
import org.dromara.business.service.IBusinessDepartBoundaryService; |
||||
|
import org.dromara.common.core.domain.R; |
||||
|
import org.dromara.common.mybatis.core.page.PageQuery; |
||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
/** |
||||
|
* 部门区域 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("/depart/boundary") |
||||
|
@Slf4j |
||||
|
@RequiredArgsConstructor |
||||
|
public class BusinessDepartBoundaryController { |
||||
|
|
||||
|
private final IBusinessDepartBoundaryService departBoundaryService; |
||||
|
|
||||
|
/** |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping(value = "/page", method = RequestMethod.GET) |
||||
|
public TableDataInfo<BusinessDepartBoundary> queryPageList(BusinessDepartBoundary departBoundary, PageQuery pageQuery) { |
||||
|
return departBoundaryService.listSysDepartBoundary(pageQuery, departBoundary); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 解析shp文件 |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping(value = "/upload", method = RequestMethod.POST) |
||||
|
public void uploadShpFile(@RequestParam("file") MultipartFile file) { |
||||
|
try { |
||||
|
departBoundaryService.uploadShpFile(file); |
||||
|
R.ok("操作成功!"); |
||||
|
} catch (Exception e) { |
||||
|
log.error(e.getMessage(), e); |
||||
|
R.fail("操作失败"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
* |
||||
|
* @param |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping(value = "/update", method = RequestMethod.POST) |
||||
|
public R<BusinessDepartBoundary> updateDepartBoundary(@RequestBody BusinessDepartBoundary departBoundary) { |
||||
|
return departBoundaryService.updateDepartBoundary(departBoundary)?R.ok("编辑成功!"):R.fail("编辑失败!"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 通过id删除 |
||||
|
* |
||||
|
* @param id |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping(value = "/delete", method = RequestMethod.DELETE) |
||||
|
public R<BusinessDepartBoundary> delete(@RequestParam(name = "id") String id) { |
||||
|
return departBoundaryService.deleteDepartBoundary(id)?R.ok("删除成功!"):R.fail("删除失败!"); |
||||
|
} |
||||
|
} |
@ -0,0 +1,66 @@ |
|||||
|
package org.dromara.business.domain; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
import org.dromara.common.mybatis.core.domain.BaseEntity; |
||||
|
import org.jeecgframework.poi.excel.annotation.Excel; |
||||
|
|
||||
|
/** |
||||
|
* 部门区域边界表 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
@TableName("business_depart_boundary") |
||||
|
public class BusinessDepartBoundary extends BaseEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/**ID*/ |
||||
|
@TableId(type = IdType.AUTO) |
||||
|
private String id; |
||||
|
/**机构ID*/ |
||||
|
private String deptId; |
||||
|
/**机构/部门名称*/ |
||||
|
@Excel(name="机构/部门名称",width=15) |
||||
|
private String deptName; |
||||
|
|
||||
|
/**是否显示0显示,1不显示*/ |
||||
|
private Integer type; |
||||
|
/**边界*/ |
||||
|
|
||||
|
private String communityName; |
||||
|
/**边界*/ |
||||
|
private String boundary; |
||||
|
|
||||
|
/** |
||||
|
* 周长 |
||||
|
*/ |
||||
|
private Double perimeter; |
||||
|
|
||||
|
/** |
||||
|
* 面积平方公里 |
||||
|
*/ |
||||
|
private Double area; |
||||
|
|
||||
|
/** |
||||
|
* 面积亩 |
||||
|
*/ |
||||
|
private Double areaMu; |
||||
|
|
||||
|
/** |
||||
|
* 编号 |
||||
|
*/ |
||||
|
private String shpNo; |
||||
|
|
||||
|
/** |
||||
|
* 0不为村级别,1为村级别 |
||||
|
*/ |
||||
|
private Integer villageType; |
||||
|
|
||||
|
/**删除状态(0,正常,1已删除)*/ |
||||
|
private String delFlag; |
||||
|
|
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package org.dromara.business.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
import org.dromara.business.domain.BusinessDepartBoundary; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 部门 Mapper 接口 |
||||
|
*/ |
||||
|
public interface BusinessDepartBoundaryMapper extends BaseMapper<BusinessDepartBoundary> { |
||||
|
Page<BusinessDepartBoundary> listSysDepartBoundary(Page<BusinessDepartBoundary> page,@Param("condition") BusinessDepartBoundary sysDepartBoundary); |
||||
|
|
||||
|
List<BusinessDepartBoundary> listSysDepartBoundaryGeomFromText(@Param("condition") BusinessDepartBoundary sysDepartBoundary); |
||||
|
/** |
||||
|
* 通过部门编码获取部门边界数据 |
||||
|
* @param deptId 部门编码 |
||||
|
* @return String |
||||
|
*/ |
||||
|
List<BusinessDepartBoundary> queryByDeptId(@Param("deptId") String deptId); |
||||
|
|
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
package org.dromara.business.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import org.dromara.business.domain.BusinessDepartBoundary; |
||||
|
import org.dromara.common.mybatis.core.page.PageQuery; |
||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* <p> |
||||
|
* 部门表 服务实现类 |
||||
|
* <p> |
||||
|
* |
||||
|
* @Author:Steve |
||||
|
* @Since: 2019-01-22 |
||||
|
*/ |
||||
|
public interface IBusinessDepartBoundaryService extends IService<BusinessDepartBoundary>{ |
||||
|
TableDataInfo<BusinessDepartBoundary> listSysDepartBoundary(PageQuery page, BusinessDepartBoundary departBoundary); |
||||
|
|
||||
|
List<BusinessDepartBoundary> listSysDepartBoundaryGeomFromText(BusinessDepartBoundary departBoundary); |
||||
|
|
||||
|
List<BusinessDepartBoundary> queryByDeptId(String deptId); |
||||
|
|
||||
|
void uploadShpFile(MultipartFile file); |
||||
|
|
||||
|
boolean deleteDepartBoundary(String id); |
||||
|
|
||||
|
boolean updateDepartBoundary(BusinessDepartBoundary departBoundary); |
||||
|
} |
@ -0,0 +1,198 @@ |
|||||
|
package org.dromara.business.service.impl; |
||||
|
|
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.apache.dubbo.config.annotation.DubboReference; |
||||
|
import org.dromara.business.domain.BusinessDepartBoundary; |
||||
|
import org.dromara.business.domain.BusinessGeospatialVectors; |
||||
|
import org.dromara.business.domain.BusinessPatrolAreas; |
||||
|
import org.dromara.business.domain.BusinessVectorDict; |
||||
|
import org.dromara.business.mapper.BusinessDepartBoundaryMapper; |
||||
|
import org.dromara.business.service.IBusinessDepartBoundaryService; |
||||
|
import org.dromara.business.service.IBusinessVectorDictService; |
||||
|
import org.dromara.business.utils.ShpAnalysisUtil; |
||||
|
import org.dromara.common.core.exception.ServiceException; |
||||
|
import org.dromara.common.mybatis.core.page.PageQuery; |
||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
||||
|
import org.dromara.system.api.RemoteDeptService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.jdbc.datasource.DataSourceUtils; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
import java.io.InputStream; |
||||
|
import java.lang.reflect.Method; |
||||
|
import java.sql.Connection; |
||||
|
import java.sql.PreparedStatement; |
||||
|
import java.sql.ResultSet; |
||||
|
import java.sql.SQLException; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 部门区域 |
||||
|
*/ |
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class BusinessDepartBoundaryServiceImpl extends ServiceImpl<BusinessDepartBoundaryMapper, BusinessDepartBoundary> implements IBusinessDepartBoundaryService { |
||||
|
|
||||
|
|
||||
|
private final IBusinessVectorDictService vectorDictService; |
||||
|
|
||||
|
@DubboReference |
||||
|
RemoteDeptService remoteDeptService; |
||||
|
|
||||
|
@Override |
||||
|
public TableDataInfo<BusinessDepartBoundary> listSysDepartBoundary(PageQuery pageQuery, BusinessDepartBoundary departBoundary) { |
||||
|
Page<BusinessDepartBoundary> page = baseMapper.listSysDepartBoundary(pageQuery.build(),departBoundary); |
||||
|
|
||||
|
return TableDataInfo.build(page); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<BusinessDepartBoundary> listSysDepartBoundaryGeomFromText(BusinessDepartBoundary sysDepartBoundary) { |
||||
|
return baseMapper.listSysDepartBoundaryGeomFromText(sysDepartBoundary); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<BusinessDepartBoundary> queryByDeptId(String deptId) { |
||||
|
return baseMapper.queryByDeptId(deptId); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void uploadShpFile(MultipartFile file) { |
||||
|
List<BusinessGeospatialVectors> geospatialVectorsList = new ArrayList<>(); |
||||
|
try { |
||||
|
//1、首先调用解析工具拿到解析的字段集合
|
||||
|
InputStream inputStream = file.getInputStream(); |
||||
|
List<Map<String, String>> mapList = ShpAnalysisUtil.analysisShpFile(inputStream); |
||||
|
|
||||
|
// 3. 构建字典map
|
||||
|
List<BusinessVectorDict> fieldsInfoList = vectorDictService.listVectorField(); |
||||
|
|
||||
|
Map<String, List<String>> dictMap = fieldsInfoList |
||||
|
.stream() |
||||
|
.collect(Collectors.toMap( |
||||
|
BusinessVectorDict::getDictCode, |
||||
|
v -> v.getFieldMappingsList().stream() |
||||
|
.map(mapping -> mapping.getItemValue().toLowerCase()) // 转小写
|
||||
|
.collect(Collectors.toList()) |
||||
|
)); |
||||
|
|
||||
|
// 4. 遍历 mapList,替换映射关系并只保留有效条目
|
||||
|
List<Map<String, String>> resultList = mapList.stream() |
||||
|
.map(originalMap -> originalMap.entrySet().stream() |
||||
|
.filter(entry -> { |
||||
|
String keyLower = entry.getKey().toLowerCase(); // 将 mapList 中的 key 转换为小写
|
||||
|
// 遍历 dictMap 的所有 List<String>,检查其中是否包含该 key
|
||||
|
return dictMap.values().stream() |
||||
|
.anyMatch(list -> list.contains(keyLower)); // 判断 dictMap 中的 List<String> 是否包含该 key
|
||||
|
}) |
||||
|
.collect(Collectors.toMap( |
||||
|
entry -> { |
||||
|
// 根据匹配的 key 查找 dictMap 中对应的 key
|
||||
|
return dictMap.entrySet().stream() |
||||
|
.filter(mapEntry -> mapEntry.getValue().contains(entry.getKey().toLowerCase())) |
||||
|
.map(Map.Entry::getKey) |
||||
|
.findFirst() |
||||
|
.orElse(""); // 如果没有匹配到,则返回空字符串
|
||||
|
}, |
||||
|
Map.Entry::getValue |
||||
|
)) |
||||
|
) |
||||
|
.filter(transformedMap -> !transformedMap.isEmpty()) // 过滤空的 Map
|
||||
|
.collect(Collectors.toList()); |
||||
|
|
||||
|
|
||||
|
// 5. 通过反射设置 GeospatialVectors 对象的属性
|
||||
|
for (Map<String, String> transformedMap : resultList) { |
||||
|
BusinessGeospatialVectors geoVector = new BusinessGeospatialVectors(); |
||||
|
|
||||
|
transformedMap.forEach((key, value) -> { |
||||
|
try { |
||||
|
// 尝试通过反射找到相应的Setter方法,并调用
|
||||
|
Method setterMethod = BusinessGeospatialVectors.class.getMethod("set" + capitalizeFirstLetter(key), String.class); |
||||
|
|
||||
|
setterMethod.invoke(geoVector, value); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
geoVector.setCreateTime(new Date()); |
||||
|
geospatialVectorsList.add(geoVector); |
||||
|
} |
||||
|
|
||||
|
//6、生成新的对象集合存储数据表中
|
||||
|
List<BusinessDepartBoundary> boundaryList = buildBusinessDepartBoundary(geospatialVectorsList); |
||||
|
|
||||
|
//批量新增部门区域数据
|
||||
|
this.saveBatch(boundaryList); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean updateDepartBoundary(BusinessDepartBoundary departBoundary) { |
||||
|
if (ObjectUtil.isEmpty(departBoundary.getId())) { |
||||
|
throw new ServiceException("【id】参数为空"); |
||||
|
} |
||||
|
|
||||
|
return this.updateById(departBoundary); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean deleteDepartBoundary(String id) { |
||||
|
BusinessDepartBoundary departBoundary = this.baseMapper.selectById(id); |
||||
|
|
||||
|
if (ObjectUtil.isEmpty(departBoundary)) { |
||||
|
throw new ServiceException("实体不存在!"); |
||||
|
} |
||||
|
|
||||
|
return this.baseMapper.deleteById(departBoundary.getId())>0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 根据解析的shp文件数据,构建部门区域 |
||||
|
* @param geospatialVectorsList |
||||
|
* @return |
||||
|
*/ |
||||
|
private List<BusinessDepartBoundary> buildBusinessDepartBoundary(List<BusinessGeospatialVectors> geospatialVectorsList) { |
||||
|
List<BusinessDepartBoundary> resultList = new ArrayList<>(); |
||||
|
|
||||
|
List<Map<String,String>> namePathList = remoteDeptService.getNamePathList(); |
||||
|
Map<String, List<Map<String, String>>> namePathMap = namePathList.stream().collect(Collectors.groupingBy(item -> item.get("shpNo"))); |
||||
|
|
||||
|
geospatialVectorsList.forEach(param->{ |
||||
|
BusinessDepartBoundary businessDepartBoundary = new BusinessDepartBoundary(); |
||||
|
businessDepartBoundary.setBoundary(param.getLandCategories()); |
||||
|
businessDepartBoundary.setDeptName(param.getLandUnitName()); |
||||
|
if (ObjectUtil.isNotEmpty(namePathMap.get(param.getLandUnitCode()))){ |
||||
|
businessDepartBoundary.setDeptId(namePathMap.get(param.getLandUnitCode()).get(0).get("deptId")); |
||||
|
businessDepartBoundary.setCommunityName(namePathMap.get(param.getLandUnitCode()).get(0).get("namePath")); |
||||
|
|
||||
|
resultList.add(businessDepartBoundary); |
||||
|
} |
||||
|
}); |
||||
|
return resultList; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private static String capitalizeFirstLetter(String str) { |
||||
|
if (str == null || str.isEmpty()) { |
||||
|
return str; |
||||
|
} |
||||
|
return str.substring(0, 1).toUpperCase() + str.substring(1); |
||||
|
} |
||||
|
} |
@ -0,0 +1,78 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="org.dromara.business.mapper.BusinessDepartBoundaryMapper"> |
||||
|
<select id="listSysDepartBoundary" resultType="org.dromara.business.domain.BusinessDepartBoundary"> |
||||
|
SELECT |
||||
|
db.id, |
||||
|
db.dept_id, |
||||
|
db.dept_name, |
||||
|
db.type, |
||||
|
db.community_name, |
||||
|
CONCAT( |
||||
|
REPLACE ( REPLACE ( REPLACE ( REPLACE ( ST_AsText ( db.boundary ), 'GEOMETRYCOLLECTION(POLYGON((', '[[' ), ')))', ']]' ), ',', '],[' ), ' ', ',' ) |
||||
|
) AS boundary, |
||||
|
db.create_by, |
||||
|
db.create_time |
||||
|
FROM |
||||
|
business_depart_boundary db |
||||
|
LEft JOIN dk_cloud.sys_dept d on db.dept_id = d.dept_id |
||||
|
<where> |
||||
|
<if test="condition.deptId != null and condition.deptId != ''"> |
||||
|
and (db.dept_id = #{condition.deptId} or d.parent_id = #{condition.deptId}) |
||||
|
</if> |
||||
|
<if test="condition.communityName != null and condition.communityName != ''"> |
||||
|
and db.community_name like concat(concat('%',#{condition.communityName}),'%') |
||||
|
</if> |
||||
|
|
||||
|
</where> |
||||
|
</select> |
||||
|
|
||||
|
|
||||
|
<select id="listSysDepartBoundaryGeomFromText" resultType="org.dromara.business.domain.BusinessDepartBoundary"> |
||||
|
SELECT |
||||
|
db.id, |
||||
|
db.dept_id, |
||||
|
db.dept_name, |
||||
|
db.type, |
||||
|
db.community_name, |
||||
|
CONCAT( |
||||
|
REPLACE ( REPLACE ( REPLACE ( REPLACE ( ST_AsText ( db.boundary ), 'GEOMETRYCOLLECTION(POLYGON((', '[[' ), ')))', ']]' ), ',', '],[' ), ' ', ',' ) |
||||
|
) AS boundary, |
||||
|
db.create_by, |
||||
|
db.create_time |
||||
|
FROM |
||||
|
business_depart_boundary db |
||||
|
LEft JOIN dk_cloud.sys_dept d on db.dept_id = d.dept_id |
||||
|
<where> |
||||
|
<if test="condition.deptId != null and condition.deptId != ''"> |
||||
|
and (db.dept_id = #{condition.deptId} or d.parent_id = #{condition.deptId}) |
||||
|
</if> |
||||
|
<if test="condition.communityName != null and condition.communityName != ''"> |
||||
|
and db.community_name like concat(concat('%',#{condition.communityName}),'%') |
||||
|
</if> |
||||
|
<if test="condition.shpNo != null and condition.shpNo != ''"> |
||||
|
and db.shp_so like #{condition.shpNo} |
||||
|
</if> |
||||
|
</where> |
||||
|
</select> |
||||
|
|
||||
|
|
||||
|
<select id="queryByDeptId" resultType="org.dromara.business.domain.BusinessDepartBoundary"> |
||||
|
SELECT |
||||
|
db.id, |
||||
|
db.dept_id, |
||||
|
db.dept_name, |
||||
|
db.type, |
||||
|
db.community_name, |
||||
|
CONCAT( |
||||
|
REPLACE ( REPLACE ( REPLACE ( REPLACE ( ST_AsText ( db.boundary ), 'GEOMETRYCOLLECTION(POLYGON((', '[[' ), ')))', ']]' ), ',', '],[' ), ' ', ',' ) |
||||
|
) AS boundary, |
||||
|
db.create_by, |
||||
|
db.create_time |
||||
|
FROM |
||||
|
business_depart_boundary db |
||||
|
LEft JOIN dk_cloud.sys_dept d on db.dept_id = d.dept_id |
||||
|
WHERE d.id = #{deptId} |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
Loading…
Reference in new issue