This commit is contained in:
lu7213 committed 2025-12-02 23:07:47 +08:00
1 parent 81eca8933a
commit 345f906c35
540 files changed
+494222 -90

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ruoyi</artifactId>
<groupId>com.ruoyi</groupId>
<version>3.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>luqj-gis</artifactId>
<dependencies>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,108 @@
package com.luqj.gis.controller;
import java.util.Arrays;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.luqj.gis.domain.GisRegion;
import com.luqj.gis.service.IGisRegionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 区域Controller
*
* @author luqj
* @date 2021-07-24
*/
@RestController
@RequestMapping("/gis/region")
public class GisRegionController extends BaseController
{
@Autowired
private IGisRegionService gisRegionService;
/**
* 查询区域列表
*/
@PreAuthorize("@ss.hasPermi('gis:region:list')")
@GetMapping("/list")
public TableDataInfo list(GisRegion gisRegion)
{
startPage();
List<GisRegion> list = gisRegionService.selectGisRegionList(gisRegion);
return getDataTable(list);
}
/**
* 导出区域列表
*/
@PreAuthorize("@ss.hasPermi('gis:region:export')")
@Log(title = "区域", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(GisRegion gisRegion)
{
List<GisRegion> list = gisRegionService.selectGisRegionList(gisRegion);
ExcelUtil<GisRegion> util = new ExcelUtil<GisRegion>(GisRegion.class);
return util.exportExcel(list, "region");
}
/**
* 获取区域详细信息
*/
@PreAuthorize("@ss.hasPermi('gis:region:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(gisRegionService.selectGisRegionById(id));
}
@GetMapping("/treeselect")
public AjaxResult treeselect(GisRegion gisRegion)
{
List<GisRegion> depts = gisRegionService.selectGisRegionList(gisRegion);
return AjaxResult.success(gisRegionService.buildGisTreeSelect(depts));
}
@GetMapping("/select-by-types")
public AjaxResult selectByTypes(@RequestParam() List<Integer> types)
{
List<GisRegion> gisRegions = gisRegionService.selectUserByTypes(types);
return AjaxResult.success(gisRegionService.buildGisTreeSelectNoRoot(gisRegions));
}
/**
* 新增区域
*/
@PreAuthorize("@ss.hasPermi('gis:region:add')")
@Log(title = "区域", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody GisRegion gisRegion)
{
return toAjax(gisRegionService.insertGisRegion(gisRegion));
}
/**
* 修改区域
*/
@PreAuthorize("@ss.hasPermi('gis:region:edit')")
@Log(title = "区域", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody GisRegion gisRegion)
{
return toAjax(gisRegionService.updateGisRegion(gisRegion));
}
/**
* 删除区域
*/
@PreAuthorize("@ss.hasPermi('gis:region:remove')")
@Log(title = "区域", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(gisRegionService.deleteGisRegionByIds(ids));
}
}
@@ -0,0 +1,247 @@
package com.luqj.gis.domain;
import java.math.BigDecimal;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 区域对象 gis_region
*
* @author luqj
* @date 2021-07-24
*/
public class GisRegion extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** ID */
private Long id;
/** 区域名称 */
@Excel(name = "区域名称")
private String name;
/** 父节点Id */
@Excel(name = "父节点Id")
private Long parentId;
/** 短名称 */
@Excel(name = "短名称")
private String shortName;
/** 区域类型:0国家,1省份,2市,3县区 */
@Excel(name = "区域类型:0国家,1省份,2市,3县区")
private Integer type;
/** 区号 */
@Excel(name = "区号")
private String cityCode;
/** 邮编 */
@Excel(name = "邮编")
private String zipCode;
/** 合并名称 */
@Excel(name = "合并名称")
private String mergerName;
/** 经度 */
@Excel(name = "经度")
private BigDecimal longitude;
/** 纬度 */
@Excel(name = "纬度")
private BigDecimal latitude;
/** 区域编码 */
@Excel(name = "区域编码")
private String code;
/** 0 开通 1未开通 */
@Excel(name = "0 开通 1未开通")
private Integer isOpen;
/** 大区:如华南 */
@Excel(name = "大区:如华南")
private String bigArea;
/** 是否默认区:1-是,0否 */
@Excel(name = "是否默认区:1-是,0否")
private Integer isDefault;
/** 城市编码 */
@Excel(name = "城市编码")
private Long adCode;
private List<GisRegion> children = new ArrayList<GisRegion>();;
public List<GisRegion> getChildren() {
return children;
}
public void setChildren(List<GisRegion> children) {
this.children = children;
}
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public Long getParentId()
{
return parentId;
}
public void setShortName(String shortName)
{
this.shortName = shortName;
}
public String getShortName()
{
return shortName;
}
public void setType(Integer type)
{
this.type = type;
}
public Integer getType()
{
return type;
}
public void setCityCode(String cityCode)
{
this.cityCode = cityCode;
}
public String getCityCode()
{
return cityCode;
}
public void setZipCode(String zipCode)
{
this.zipCode = zipCode;
}
public String getZipCode()
{
return zipCode;
}
public void setMergerName(String mergerName)
{
this.mergerName = mergerName;
}
public String getMergerName()
{
return mergerName;
}
public void setLongitude(BigDecimal longitude)
{
this.longitude = longitude;
}
public BigDecimal getLongitude()
{
return longitude;
}
public void setLatitude(BigDecimal latitude)
{
this.latitude = latitude;
}
public BigDecimal getLatitude()
{
return latitude;
}
public void setCode(String code)
{
this.code = code;
}
public String getCode()
{
return code;
}
public void setIsOpen(Integer isOpen)
{
this.isOpen = isOpen;
}
public Integer getIsOpen()
{
return isOpen;
}
public void setBigArea(String bigArea)
{
this.bigArea = bigArea;
}
public String getBigArea()
{
return bigArea;
}
public void setIsDefault(Integer isDefault)
{
this.isDefault = isDefault;
}
public Integer getIsDefault()
{
return isDefault;
}
public void setAdCode(Long adCode)
{
this.adCode = adCode;
}
public Long getAdCode()
{
return adCode;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("name", getName())
.append("parentId", getParentId())
.append("shortName", getShortName())
.append("type", getType())
.append("cityCode", getCityCode())
.append("zipCode", getZipCode())
.append("mergerName", getMergerName())
.append("longitude", getLongitude())
.append("latitude", getLatitude())
.append("code", getCode())
.append("isOpen", getIsOpen())
.append("bigArea", getBigArea())
.append("isDefault", getIsDefault())
.append("adCode", getAdCode())
.toString();
}
}
@@ -0,0 +1,223 @@
package com.luqj.gis.domain;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableName;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.io.Serializable;
import java.util.Date;
/**
* 区域对象 gis_region
*
* @author luqj
* @date 2021-07-24
*/
@TableName(value = "gis_region")
public class GisRegionPlus implements Serializable
{
private static final long serialVersionUID = 1L;
/** ID */
private Long id;
/** 区域名称 */
@Excel(name = "区域名称")
private String name;
/** 父节点Id */
@Excel(name = "父节点Id")
private Long parentId;
/** 短名称 */
@Excel(name = "短名称")
private String shortName;
/** 区域类型:0国家,1省份,2市,3县区 */
@Excel(name = "区域类型:0国家,1省份,2市,3县区")
private Integer type;
/** 区号 */
@Excel(name = "区号")
private String cityCode;
/** 邮编 */
@Excel(name = "邮编")
private String zipCode;
/** 合并名称 */
@Excel(name = "合并名称")
private String mergerName;
/** 经度 */
@Excel(name = "经度")
private BigDecimal longitude;
/** 纬度 */
@Excel(name = "纬度")
private BigDecimal latitude;
/** 区域编码 */
@Excel(name = "区域编码")
private String code;
/** 0 开通 1未开通 */
@Excel(name = "0 开通 1未开通")
private Integer isOpen;
/** 大区:如华南 */
@Excel(name = "大区:如华南")
private String bigArea;
/** 是否默认区:1-是,0否 */
@Excel(name = "是否默认区:1-是,0否")
private Integer isDefault;
/** 城市编码 */
@Excel(name = "城市编码")
private Long adCode;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public Long getParentId()
{
return parentId;
}
public void setShortName(String shortName)
{
this.shortName = shortName;
}
public String getShortName()
{
return shortName;
}
public void setType(Integer type)
{
this.type = type;
}
public Integer getType()
{
return type;
}
public void setCityCode(String cityCode)
{
this.cityCode = cityCode;
}
public String getCityCode()
{
return cityCode;
}
public void setZipCode(String zipCode)
{
this.zipCode = zipCode;
}
public String getZipCode()
{
return zipCode;
}
public void setMergerName(String mergerName)
{
this.mergerName = mergerName;
}
public String getMergerName()
{
return mergerName;
}
public void setLongitude(BigDecimal longitude)
{
this.longitude = longitude;
}
public BigDecimal getLongitude()
{
return longitude;
}
public void setLatitude(BigDecimal latitude)
{
this.latitude = latitude;
}
public BigDecimal getLatitude()
{
return latitude;
}
public void setCode(String code)
{
this.code = code;
}
public String getCode()
{
return code;
}
public void setIsOpen(Integer isOpen)
{
this.isOpen = isOpen;
}
public Integer getIsOpen()
{
return isOpen;
}
public void setBigArea(String bigArea)
{
this.bigArea = bigArea;
}
public String getBigArea()
{
return bigArea;
}
public void setIsDefault(Integer isDefault)
{
this.isDefault = isDefault;
}
public Integer getIsDefault()
{
return isDefault;
}
public void setAdCode(Long adCode)
{
this.adCode = adCode;
}
public Long getAdCode()
{
return adCode;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("name", getName())
.append("parentId", getParentId())
.append("shortName", getShortName())
.append("type", getType())
.append("cityCode", getCityCode())
.append("zipCode", getZipCode())
.append("mergerName", getMergerName())
.append("longitude", getLongitude())
.append("latitude", getLatitude())
.append("code", getCode())
.append("isOpen", getIsOpen())
.append("bigArea", getBigArea())
.append("isDefault", getIsDefault())
.append("adCode", getAdCode())
.toString();
}
}
@@ -0,0 +1,24 @@
package com.luqj.gis.domain;
import com.ruoyi.common.core.domain.TreeSelect;
import java.util.stream.Collectors;
public class GisTreeSelect extends TreeSelect {
private Long value;
public GisTreeSelect(GisRegion gisRegion)
{
this.id = gisRegion.getId();
this.value = gisRegion.getId();
this.label = gisRegion.getName();
this.children = gisRegion.getChildren().stream().map(GisTreeSelect::new).collect(Collectors.toList());
}
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
}
@@ -0,0 +1,66 @@
package com.luqj.gis.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.luqj.gis.domain.GisRegion;
import com.luqj.gis.domain.GisRegionPlus;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 区域Mapper接口
*
* @author luqj
* @date 2021-07-24
*/
public interface GisRegionMapper extends BaseMapper<GisRegionPlus> {
/**
* 查询区域
*
* @param id 区域ID
* @return 区域
*/
public GisRegion selectGisRegionById(Long id);
/**
* 查询区域列表
*
* @param gisRegion 区域
* @return 区域集合
*/
public List<GisRegion> selectGisRegionList(GisRegion gisRegion);
/**
* 新增区域
*
* @param gisRegion 区域
* @return 结果
*/
public int insertGisRegion(GisRegion gisRegion);
/**
* 修改区域
*
* @param gisRegion 区域
* @return 结果
*/
public int updateGisRegion(GisRegion gisRegion);
/**
* 删除区域
*
* @param id 区域ID
* @return 结果
*/
public int deleteGisRegionById(Long id);
/**
* 批量删除区域
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteGisRegionByIds(Long[] ids);
List<GisRegion> selectUserByTypes(@Param("types") List<Integer> types);
}
@@ -0,0 +1,93 @@
package com.luqj.gis.service;
import java.util.Map;
import java.util.List;
import com.luqj.gis.domain.GisRegion;
import com.luqj.gis.domain.GisRegionPlus;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.luqj.gis.domain.GisTreeSelect;
/**
* 区域Service接口
*
* @author luqj
* @date 2021-07-24
*/
public interface IGisRegionService extends IService<GisRegionPlus>
{
/**
* 查询区域
*
* @param id 区域ID
* @return 区域
*/
public GisRegion selectGisRegionById(Long id);
/**
* 查询区域列表
*
* @param gisRegion 区域
* @return 区域集合
*/
public List<GisRegion> selectGisRegionList(GisRegion gisRegion);
List<GisTreeSelect> buildGisTreeSelect(List<GisRegion> gisRegions);
List<GisTreeSelect> buildGisTreeSelectNoRoot(List<GisRegion> gisRegions);
List<GisRegion> selectUserByTypes(List<Integer> types);
/**
* 新增区域
*
* @param gisRegion 区域
* @return 结果
*/
public int insertGisRegion(GisRegion gisRegion);
/**
* 修改区域
*
* @param gisRegion 区域
* @return 结果
*/
public int updateGisRegion(GisRegion gisRegion);
/**
* 批量删除区域
*
* @param ids 需要删除的区域ID
* @return 结果
*/
public int deleteGisRegionByIds(Long[] ids);
/**
* 删除区域信息
*
* @param id 区域ID
* @return 结果
*/
public int deleteGisRegionById(Long id);
List<GisRegionPlus> getByIds(List<Long> ids, SFunction<GisRegionPlus, ?>... columns);
GisRegionPlus getById(Long id, SFunction<GisRegionPlus, ?>... columns);
Map<Long, GisRegionPlus> getMapByIds(List<Long> ids, SFunction<GisRegionPlus, ?>... columns);
List<GisRegionPlus> getByIds(List<Long> ids);
Map<Long, GisRegionPlus> getMapByIds(List<Long> ids);
/**
* @param field sum 字段
* @param where 条件
* @param tClass 返回类型
* @param <T>
* @return
*/
<T> T sum(String field, String where, Class<T> tClass);
Long count(String where);
<T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass);
}
@@ -0,0 +1,284 @@
package com.luqj.gis.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import java.util.*;
import com.luqj.gis.domain.GisTreeSelect;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.utils.StringUtils;
import com.alibaba.fastjson.JSONArray;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.luqj.gis.mapper.GisRegionMapper;
import com.luqj.gis.domain.GisRegion;
import com.luqj.gis.domain.GisRegionPlus;
import com.luqj.gis.service.IGisRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
/**
* 区域Service业务层处理
*
* @author luqj
* @date 2021-07-24
*/
@Service
public class GisRegionServiceImpl extends ServiceImpl<GisRegionMapper, GisRegionPlus> implements IGisRegionService
{
@Autowired
private GisRegionMapper gisRegionMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public List<GisRegionPlus> getByIds(List<Long> ids, SFunction<GisRegionPlus, ?>... columns) {
LambdaQueryWrapper<GisRegionPlus> lambdaQueryWrapper = new LambdaQueryWrapper<GisRegionPlus>()
.select(columns).in(GisRegionPlus::getId, ids);
return this.list(lambdaQueryWrapper);
}
@Override
public GisRegionPlus getById(Long id, SFunction<GisRegionPlus, ?>... columns) {
LambdaQueryWrapper<GisRegionPlus> lambdaQueryWrapper = new LambdaQueryWrapper<GisRegionPlus>()
.select(columns).eq(GisRegionPlus::getId, id);
return baseMapper.selectOne(lambdaQueryWrapper);
}
@Override
public Map<Long, GisRegionPlus> getMapByIds(List<Long> ids, SFunction<GisRegionPlus, ?>... columns) {
List<GisRegionPlus> list = this.getByIds(ids, columns);
Map<Long, GisRegionPlus> map = new HashMap<>();
for (GisRegionPlus item : list) {
map.put(item.getId(), item);
}
return map;
}
@Override
public Map<Long, GisRegionPlus> getMapByIds(List<Long> ids) {
List<GisRegionPlus> list = this.getByIds(ids);
Map<Long, GisRegionPlus> map = new HashMap<>();
for (GisRegionPlus item : list) {
map.put(item.getId(), item);
}
return map;
}
@Override
public List<GisRegionPlus> getByIds(List<Long> ids) {
LambdaQueryWrapper<GisRegionPlus> lambdaQueryWrapper = new LambdaQueryWrapper<GisRegionPlus>().in(GisRegionPlus::getId, ids);
return this.list(lambdaQueryWrapper);
}
public <T> T sum(String field, String where, Class<T> tClass) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select ");
stringBuffer.append(" sum(" + field + ") as total ");
stringBuffer.append(" from gis_region ");
if (StringUtils.isNotBlank(where)) {
stringBuffer.append(" where ");
stringBuffer.append(where);
}
T result = jdbcTemplate.queryForObject(stringBuffer.toString(), tClass);
return result;
}
public Long count(String where) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select ");
stringBuffer.append(" count(1)");
stringBuffer.append(" from ");
stringBuffer.append(" gis_region ");
if (StringUtils.isNotBlank(where)) {
stringBuffer.append(" where ");
stringBuffer.append(where);
}
Long result = jdbcTemplate.queryForObject(stringBuffer.toString(), Long.class);
return result;
}
public <T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select ");
stringBuffer.append(select);
stringBuffer.append(" from ");
stringBuffer.append(" gis_region ");
if (StringUtils.isNotBlank(where)) {
stringBuffer.append(" where ");
stringBuffer.append(where);
}
stringBuffer.append(" group by ");
stringBuffer.append(groupby);
List result = jdbcTemplate.queryForList(stringBuffer.toString());
List<T> tList = JSONArray.parseArray(JSONArray.toJSONString(result), tClass);
return tList;
}
/**
* 查询区域
*
* @param id 区域ID
* @return 区域
*/
@Override
public GisRegion selectGisRegionById(Long id)
{
return gisRegionMapper.selectGisRegionById(id);
}
/**
* 查询区域列表
*
* @param gisRegion 区域
* @return 区域
*/
@Override
public List<GisRegion> selectGisRegionList(GisRegion gisRegion)
{
return gisRegionMapper.selectGisRegionList(gisRegion);
}
public List<GisRegion> selectUserByTypes(List<Integer> types)
{
return gisRegionMapper.selectUserByTypes(types);
}
public List<GisTreeSelect> buildGisTreeSelect(List<GisRegion> gisRegions)
{
List<GisRegion> deptTrees = buildGisTree(gisRegions);
GisRegion com =new GisRegion();
com.setId(0L);
com.setName("根目录");
com.setChildren(deptTrees);
List<GisRegion> pc = new ArrayList<>();
for(GisRegion c:deptTrees){
if(c.getParentId() == 0L){
pc.add(c);
}
}
com.setChildren(pc);
return Arrays.asList(com).stream().map(GisTreeSelect::new).collect(Collectors.toList());
}
public List<GisTreeSelect> buildGisTreeSelectNoRoot(List<GisRegion> gisRegions)
{
List<GisRegion> deptTrees = buildGisTree(gisRegions);
return deptTrees.stream().map(GisTreeSelect::new).collect(Collectors.toList());
}
/**
* 递归列表
*/
private void recursionFn(List<GisRegion> list, GisRegion t)
{
// 得到子节点列表
List<GisRegion> childList = getChildList(list, t);
t.setChildren(childList);
for (GisRegion tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
}
}
/**
* 得到子节点列表
*/
private List<GisRegion> getChildList(List<GisRegion> list, GisRegion t)
{
List<GisRegion> tlist = new ArrayList<GisRegion>();
Iterator<GisRegion> it = list.iterator();
while (it.hasNext())
{
GisRegion n = (GisRegion) it.next();
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue())
{
tlist.add(n);
}
}
return tlist;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<GisRegion> list, GisRegion t)
{
return getChildList(list, t).size() > 0 ? true : false;
}
public List<GisRegion> buildGisTree(List<GisRegion> depts)
{
List<GisRegion> returnList = new ArrayList<GisRegion>();
List<Long> tempList = new ArrayList<Long>();
for (GisRegion dept : depts)
{
tempList.add(dept.getId());
}
for (Iterator<GisRegion> iterator = depts.iterator(); iterator.hasNext();)
{
GisRegion dept = (GisRegion) iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(dept.getParentId()))
{
recursionFn(depts, dept);
returnList.add(dept);
}
}
if (returnList.isEmpty())
{
returnList = depts;
}
return returnList;
}
/**
* 新增区域
*
* @param gisRegion 区域
* @return 结果
*/
@Override
public int insertGisRegion(GisRegion gisRegion)
{
return gisRegionMapper.insertGisRegion(gisRegion);
}
/**
* 修改区域
*
* @param gisRegion 区域
* @return 结果
*/
@Override
public int updateGisRegion(GisRegion gisRegion)
{
return gisRegionMapper.updateGisRegion(gisRegion);
}
/**
* 批量删除区域
*
* @param ids 需要删除的区域ID
* @return 结果
*/
@Override
public int deleteGisRegionByIds(Long[] ids)
{
return gisRegionMapper.deleteGisRegionByIds(ids);
}
/**
* 删除区域信息
*
* @param id 区域ID
* @return 结果
*/
@Override
public int deleteGisRegionById(Long id)
{
return gisRegionMapper.deleteGisRegionById(id);
}
}
@@ -0,0 +1,126 @@
<?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="com.luqj.gis.mapper.GisRegionMapper">
<resultMap type="GisRegion" id="GisRegionResult">
<result property="id" column="ID" />
<result property="name" column="NAME" />
<result property="parentId" column="PARENT_ID" />
<result property="shortName" column="SHORT_NAME" />
<result property="type" column="TYPE" />
<result property="cityCode" column="CITY_CODE" />
<result property="zipCode" column="ZIP_CODE" />
<result property="mergerName" column="MERGER_NAME" />
<result property="longitude" column="LONGITUDE" />
<result property="latitude" column="LATITUDE" />
<result property="code" column="CODE" />
<result property="isOpen" column="IS_OPEN" />
<result property="bigArea" column="BIG_AREA" />
<result property="isDefault" column="IS_DEFAULT" />
<result property="adCode" column="ad_code" />
</resultMap>
<sql id="selectGisRegionVo">
select ID, NAME, PARENT_ID, SHORT_NAME, TYPE, CITY_CODE, ZIP_CODE, MERGER_NAME, LONGITUDE, LATITUDE, CODE, IS_OPEN, BIG_AREA, IS_DEFAULT, ad_code from gis_region
</sql>
<select id="selectGisRegionList" parameterType="GisRegion" resultMap="GisRegionResult">
<include refid="selectGisRegionVo"/>
<where>
<if test="name != null and name != ''"> and NAME like concat('%', #{name}, '%')</if>
<if test="parentId != null "> and PARENT_ID = #{parentId}</if>
<if test="shortName != null and shortName != ''"> and SHORT_NAME like concat('%', #{shortName}, '%')</if>
<if test="type != null "> and TYPE = #{type}</if>
<if test="cityCode != null and cityCode != ''"> and CITY_CODE = #{cityCode}</if>
<if test="zipCode != null and zipCode != ''"> and ZIP_CODE = #{zipCode}</if>
<if test="mergerName != null and mergerName != ''"> and MERGER_NAME like concat('%', #{mergerName}, '%')</if>
<if test="longitude != null "> and LONGITUDE = #{longitude}</if>
<if test="latitude != null "> and LATITUDE = #{latitude}</if>
<if test="code != null and code != ''"> and CODE = #{code}</if>
<if test="isOpen != null "> and IS_OPEN = #{isOpen}</if>
<if test="bigArea != null and bigArea != ''"> and BIG_AREA = #{bigArea}</if>
<if test="isDefault != null "> and IS_DEFAULT = #{isDefault}</if>
<if test="adCode != null "> and ad_code = #{adCode}</if>
</where>
</select>
<select id="selectGisRegionById" parameterType="Long" resultMap="GisRegionResult">
<include refid="selectGisRegionVo"/>
where ID = #{id}
</select>
<select id="selectUserByTypes" resultMap="GisRegionResult">
<include refid="selectGisRegionVo"/>
where `type` in
<foreach collection="types" item="type" index="index" open="(" close=")" separator=",">
#{type}
</foreach>
</select>
<insert id="insertGisRegion" parameterType="GisRegion" useGeneratedKeys="true" keyProperty="id">
insert into gis_region
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">NAME,</if>
<if test="parentId != null">PARENT_ID,</if>
<if test="shortName != null">SHORT_NAME,</if>
<if test="type != null">TYPE,</if>
<if test="cityCode != null">CITY_CODE,</if>
<if test="zipCode != null">ZIP_CODE,</if>
<if test="mergerName != null">MERGER_NAME,</if>
<if test="longitude != null">LONGITUDE,</if>
<if test="latitude != null">LATITUDE,</if>
<if test="code != null">CODE,</if>
<if test="isOpen != null">IS_OPEN,</if>
<if test="bigArea != null">BIG_AREA,</if>
<if test="isDefault != null">IS_DEFAULT,</if>
<if test="adCode != null">ad_code,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
<if test="parentId != null">#{parentId},</if>
<if test="shortName != null">#{shortName},</if>
<if test="type != null">#{type},</if>
<if test="cityCode != null">#{cityCode},</if>
<if test="zipCode != null">#{zipCode},</if>
<if test="mergerName != null">#{mergerName},</if>
<if test="longitude != null">#{longitude},</if>
<if test="latitude != null">#{latitude},</if>
<if test="code != null">#{code},</if>
<if test="isOpen != null">#{isOpen},</if>
<if test="bigArea != null">#{bigArea},</if>
<if test="isDefault != null">#{isDefault},</if>
<if test="adCode != null">#{adCode},</if>
</trim>
</insert>
<update id="updateGisRegion" parameterType="GisRegion">
update gis_region
<trim prefix="SET" suffixOverrides=",">
<if test="name != null">NAME = #{name},</if>
<if test="parentId != null">PARENT_ID = #{parentId},</if>
<if test="shortName != null">SHORT_NAME = #{shortName},</if>
<if test="type != null">TYPE = #{type},</if>
<if test="cityCode != null">CITY_CODE = #{cityCode},</if>
<if test="zipCode != null">ZIP_CODE = #{zipCode},</if>
<if test="mergerName != null">MERGER_NAME = #{mergerName},</if>
<if test="longitude != null">LONGITUDE = #{longitude},</if>
<if test="latitude != null">LATITUDE = #{latitude},</if>
<if test="code != null">CODE = #{code},</if>
<if test="isOpen != null">IS_OPEN = #{isOpen},</if>
<if test="bigArea != null">BIG_AREA = #{bigArea},</if>
<if test="isDefault != null">IS_DEFAULT = #{isDefault},</if>
<if test="adCode != null">ad_code = #{adCode},</if>
</trim>
where ID = #{id}
</update>
<delete id="deleteGisRegionById" parameterType="Long">
delete from gis_region where ID = #{id}
</delete>
<delete id="deleteGisRegionByIds" parameterType="String">
delete from gis_region where ID in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>