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

@@ -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);
}
}