|
|
@ -1,30 +1,29 @@ |
|
|
|
package com.kms.yg.znjg.controller; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.kms.common.utils.UserUtils; |
|
|
|
import com.kms.yg.znjg.domain.SyDir; |
|
|
|
import com.kms.yg.znjg.domain.SyScene; |
|
|
|
import com.kms.yg.znjg.domain.SySceneConfigRelation; |
|
|
|
import com.kms.yg.znjg.domain.SySceneDirRelation; |
|
|
|
import com.kms.yg.znjg.mapper.SyDirMapper; |
|
|
|
import com.kms.yg.znjg.mapper.SySceneConfigRelationMapper; |
|
|
|
import com.kms.yg.znjg.mapper.SySceneDirRelationMapper; |
|
|
|
import com.kms.yg.znjg.mapper.SySceneMapper; |
|
|
|
import com.kms.yg.znjg.domain.*; |
|
|
|
import com.kms.yg.znjg.mapper.*; |
|
|
|
import com.kms.yg.znjg.service.SySceneService; |
|
|
|
import com.kms.yg.znjg.vo.SyDirVo; |
|
|
|
import com.kms.yg.znjg.vo.SySceneVo; |
|
|
|
import com.kms.yxgh.base.Response; |
|
|
|
import com.shuili.common.core.domain.SearchParam; |
|
|
|
import com.shuili.common.core.domain.entity.SysUser; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -49,6 +48,12 @@ public class SySceneController { |
|
|
|
@Autowired |
|
|
|
private SySceneConfigRelationMapper sySceneConfigRelationMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SyDirLayerMapper syDirLayerMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SyLayerMapper syLayerMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 分页查询所有的地图场景信息 |
|
|
|
* |
|
|
@ -199,4 +204,157 @@ public class SySceneController { |
|
|
|
} |
|
|
|
return responseInfo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据场景id获取关联的图层信息 |
|
|
|
* |
|
|
|
* @param sceneId 场景id |
|
|
|
* @return |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@GetMapping(value = "/getLayerTree/{sceneId}") |
|
|
|
@ApiOperation("根据场景id获取关联的图层信息") |
|
|
|
public Response getLayerTree(@PathVariable(value = "sceneId") String sceneId) throws Exception { |
|
|
|
try { |
|
|
|
// 查询场景关联的图层目录信息
|
|
|
|
List<SySceneDirRelation> sceneDirRelations = sySceneDirRelationMapper.selectByMap(new HashMap<String, Object>() {{ |
|
|
|
put("scene_id", sceneId); |
|
|
|
put("is_valid", "1"); |
|
|
|
}}); |
|
|
|
if (sceneDirRelations != null && sceneDirRelations.size() > 0) { |
|
|
|
// 根据图层目录查询关联的图层目录id
|
|
|
|
List<String> dirIds = sceneDirRelations.stream().map(SySceneDirRelation::getDirId).collect(Collectors.toList()); |
|
|
|
//获取专题目录一级目录
|
|
|
|
List<SyDir> allDirs = syDirMapper.findSecondInDirList(dirIds); |
|
|
|
if (allDirs == null || allDirs.size() == 0) { |
|
|
|
throw new Exception("未找到关联的图层信息"); |
|
|
|
} |
|
|
|
List tree = new ArrayList(); |
|
|
|
Iterator<SyDir> it = allDirs.iterator(); |
|
|
|
while (it.hasNext()) { |
|
|
|
List<Map> list = getProjectLayerData(it.next()); |
|
|
|
if (list != null && list.size() > 0) { |
|
|
|
tree.add(list.get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
String dirId = ObjectUtil.isNotEmpty(sceneId) ? "" : "root"; |
|
|
|
List<SyLayer> rootLabels = syLayerMapper.getAllByDirId(dirId); |
|
|
|
Map rootItem = new HashMap(); |
|
|
|
rootItem.put("id", "root"); |
|
|
|
rootItem.put("text", "全部"); |
|
|
|
rootItem.put("iconCls", "icon-folder"); |
|
|
|
rootItem.put("pid", ""); |
|
|
|
rootItem.put("dirOrder", 1); |
|
|
|
rootItem.put("info", ""); |
|
|
|
if (allDirs == null || allDirs.size() == 0) { |
|
|
|
rootItem.put("children", new ArrayList<>()); |
|
|
|
} else { |
|
|
|
rootItem.put("children", tree); |
|
|
|
} |
|
|
|
if (rootLabels.size() > 0) { |
|
|
|
//去掉不包含"root"的
|
|
|
|
List<SyLayer> newRootLabels = rootLabels.stream() |
|
|
|
.filter(syLabel -> syLabel.getDirId().contains("root")) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
rootItem.put("layers", newRootLabels); |
|
|
|
} |
|
|
|
return new Response() {{ |
|
|
|
setCode("200"); |
|
|
|
setData(rootItem); |
|
|
|
}}; |
|
|
|
} else { |
|
|
|
throw new Exception("未找到关联的图层信息"); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
return new Response() {{ |
|
|
|
setCode("500"); |
|
|
|
setMsg(e.getMessage()); |
|
|
|
}}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Map> getProjectLayerData(SyDir topSyLabelDir) { |
|
|
|
Set<String> dirSeqSet = syDirMapper.selectDirSeq(); |
|
|
|
Set<String> dirIdSet = new HashSet<>(); |
|
|
|
dirIdSet.add(topSyLabelDir.getId()); |
|
|
|
for (String dirSeq : dirSeqSet) { |
|
|
|
String[] dirSeqs = dirSeq.split(","); |
|
|
|
if (dirSeqs.length > 1 && dirSeqs[dirSeqs.length - 2].equals(topSyLabelDir.getId())) { |
|
|
|
Arrays.stream(dirSeqs).forEach(key -> { |
|
|
|
if (!"root".equals(key)) { |
|
|
|
dirIdSet.add(key); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
List<SyDir> dirList = new ArrayList<>(); |
|
|
|
if (dirIdSet.size() > 0) { |
|
|
|
dirList = syDirMapper.findByIds(dirIdSet.toArray(new String[dirIdSet.size()])); |
|
|
|
} |
|
|
|
if (dirList == null || dirList.size() == 0) { |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
List<SyLayer> syLabelList = syLayerMapper.findListByDirSeq(topSyLabelDir.getId()); |
|
|
|
Map<String, SyLayer> syLabelMap = syLabelList.stream().collect(Collectors.toMap(x -> x.getId(), x -> x)); |
|
|
|
|
|
|
|
List<SyDirLayer> syLabelDirRelationList = syDirLayerMapper.findByDirSeq(topSyLabelDir.getId()); |
|
|
|
Map<String, List<SyDirLayer>> syViewPointDirDataMap = syLabelDirRelationList.stream().collect(Collectors.groupingBy(SyDirLayer::getDirId)); |
|
|
|
List<Map> list = dirList.stream().map(x -> { |
|
|
|
Map item = getDirTreeMap(null, x, null); |
|
|
|
List<SyDirLayer> dirLayerList = syViewPointDirDataMap.get(x.getId()); |
|
|
|
if (dirLayerList != null && dirLayerList.size() > 0) { |
|
|
|
List layers = new ArrayList<>(); |
|
|
|
dirLayerList.stream().forEach(xd -> { |
|
|
|
SyLayer layerc = syLabelMap.get(xd.getLayerId()); |
|
|
|
if (layerc != null) { |
|
|
|
layers.add(layerc); |
|
|
|
} |
|
|
|
}); |
|
|
|
item.put("layers", layers); |
|
|
|
} |
|
|
|
return item; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
Map<String, Map> idMap = list.stream().collect(Collectors.toMap(x -> MapUtils.getString(x, "id"), Function.identity())); |
|
|
|
Iterator<Map> it = list.iterator(); |
|
|
|
while (it.hasNext()) { |
|
|
|
Map item = it.next(); |
|
|
|
String pid = MapUtils.getString(item, "pid"); |
|
|
|
if (!"root".equals(pid)) { |
|
|
|
Map parent = idMap.get(pid); |
|
|
|
if (parent != null) { |
|
|
|
List childrens = null; |
|
|
|
if (!parent.containsKey("children")) { |
|
|
|
childrens = new ArrayList<>(); |
|
|
|
parent.put("children", new ArrayList<>()); |
|
|
|
} else { |
|
|
|
childrens = (List) parent.get("children"); |
|
|
|
} |
|
|
|
childrens.add(item); |
|
|
|
parent.put("children", childrens); |
|
|
|
} |
|
|
|
it.remove(); |
|
|
|
} |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map getDirTreeMap(Map item, SyDir syLabelDir, String iconCls) { |
|
|
|
if (item == null) { |
|
|
|
item = new HashMap(); |
|
|
|
} |
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(iconCls)) { |
|
|
|
iconCls = "icon-folder"; |
|
|
|
} |
|
|
|
item.put("id", syLabelDir.getId()); |
|
|
|
item.put("text", syLabelDir.getName()); |
|
|
|
item.put("iconCls", iconCls); |
|
|
|
item.put("pid", syLabelDir.getParentId()); |
|
|
|
item.put("dirOrder", syLabelDir.getOrderNm()); |
|
|
|
item.put("info", ""); |
|
|
|
return item; |
|
|
|
} |
|
|
|
} |
|
|
|