|
@@ -0,0 +1,246 @@
|
|
|
+package com.onemap.apply.service.impl.table;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.onemap.apply.domain.table.TableDTO;
|
|
|
+import com.onemap.apply.domain.table.TableDataVo;
|
|
|
+import com.onemap.apply.domain.table.TableFiledDTO;
|
|
|
+import com.onemap.apply.domain.table.TableResRuleDTO;
|
|
|
+import com.onemap.apply.mapper.table.*;
|
|
|
+import com.onemap.apply.service.table.TableDataSelectService;
|
|
|
+import com.onemap.common.core.utils.StringUtils;
|
|
|
+import com.onemap.common.core.web.domain.RequestResult;
|
|
|
+import com.onemap.system.api.AnalyseService;
|
|
|
+import oracle.jdbc.internal.ObjectData;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class TableDataSelectServiceImpl implements TableDataSelectService {
|
|
|
+ @Resource
|
|
|
+ private TableResRuleMapper tableResRuleMapper;
|
|
|
+ @Resource
|
|
|
+ private TableMapper tableMapper;
|
|
|
+ @Resource
|
|
|
+ private TableDataSelectMapper tableDataSelectMapper;
|
|
|
+ @Resource
|
|
|
+ private AnalyseService analyseService;
|
|
|
+ @Resource
|
|
|
+ private TableFiledRelationMapper tableFiledRelationMapper;
|
|
|
+ @Resource
|
|
|
+ private TableFiledMapper tableFiledMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map dataSelectByPoint(String pointEWkt, String bsm) {
|
|
|
+ Map retList = new LinkedHashMap<>();
|
|
|
+ if (StringUtils.isNotEmpty(bsm)) {
|
|
|
+ QueryWrapper<TableResRuleDTO> queryResOneWrapper = new QueryWrapper<>();
|
|
|
+ queryResOneWrapper.eq("id", bsm);
|
|
|
+ TableResRuleDTO v_table_res_id = tableResRuleMapper.selectOne(queryResOneWrapper);
|
|
|
+
|
|
|
+ List<List<TableDataVo>> data = dataSelectById(pointEWkt, bsm);
|
|
|
+ if (data == null || data.size() <= 0) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+ retList.put("data", data);
|
|
|
+ retList.put("dataname", getTableName(v_table_res_id.getFromTableId()));
|
|
|
+
|
|
|
+ QueryWrapper<TableResRuleDTO> queryResWrapper = new QueryWrapper<>();
|
|
|
+ queryResWrapper.eq("pid", bsm);
|
|
|
+ List<TableResRuleDTO> v_table_Res = tableResRuleMapper.selectList(queryResWrapper);
|
|
|
+ List<Map> childLit = new ArrayList<>();
|
|
|
+ for (TableResRuleDTO tableResRuleDTO : v_table_Res) {
|
|
|
+ Map childMap = new HashMap();
|
|
|
+ List<Map> v_data = new ArrayList<>();
|
|
|
+ List<Map> v_child = new ArrayList<>();
|
|
|
+ for (List<TableDataVo> dataMap : data) {
|
|
|
+ String geomEWKT = null;
|
|
|
+ for (TableDataVo tableDataVo : dataMap) {
|
|
|
+ if ("geom".equals(tableDataVo.getFiled())) {
|
|
|
+ geomEWKT = (String) tableDataVo.getData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(geomEWKT)) {
|
|
|
+ Map v_childMap = dataSelectByPoint(geomEWKT, tableResRuleDTO.getId());
|
|
|
+ if (v_childMap != null) {
|
|
|
+ v_data.addAll((List<Map>) v_childMap.get("data"));
|
|
|
+ v_child.addAll((List<Map>) v_childMap.get("child"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ childMap.put("dataname", getTableName(tableResRuleDTO.getAnalyseTableId()));
|
|
|
+ childMap.put("data", v_data);
|
|
|
+ childMap.put("child", v_child);
|
|
|
+ childLit.add(childMap);
|
|
|
+ }
|
|
|
+ retList.put("child", childLit);
|
|
|
+ }
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTableName(String bsm) {
|
|
|
+ // 获取from_table_id
|
|
|
+ QueryWrapper<TableDTO> queryFromTableWrapper = new QueryWrapper<>();
|
|
|
+ if (StringUtils.isNotEmpty(bsm)) {
|
|
|
+ queryFromTableWrapper.eq("id", bsm);
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 获取from_table_id
|
|
|
+ queryFromTableWrapper.eq("id", bsm);
|
|
|
+ TableDTO v_from_table = tableMapper.selectOne(queryFromTableWrapper);
|
|
|
+ if (StringUtils.isNull(v_from_table)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return v_from_table.getTableDescribe();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<List<TableDataVo>> dataSelectById(String pointEWkt, String bsm) {
|
|
|
+ List<List<TableDataVo>> retList = new ArrayList<>();
|
|
|
+ QueryWrapper<TableResRuleDTO> queryResWrapper = new QueryWrapper<>();
|
|
|
+ if (StringUtils.isNotEmpty(bsm)) {
|
|
|
+ queryResWrapper.eq("id", bsm);
|
|
|
+ } else {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ TableResRuleDTO v_table_Res = tableResRuleMapper.selectOne(queryResWrapper);
|
|
|
+ if (StringUtils.isNull(v_table_Res)) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取from_table_id
|
|
|
+ QueryWrapper<TableDTO> queryFromTableWrapper = new QueryWrapper<>();
|
|
|
+ queryFromTableWrapper.eq("id", v_table_Res.getFromTableId());
|
|
|
+ TableDTO v_from_table = tableMapper.selectOne(queryFromTableWrapper);
|
|
|
+ if (StringUtils.isNull(v_from_table)) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取analyse_table_id
|
|
|
+ TableDTO v_analyse_table = null;
|
|
|
+ if (StringUtils.isNotEmpty(v_table_Res.getAnalyseTableId())) {
|
|
|
+ QueryWrapper<TableDTO> queryAnalyseTableWrapper = new QueryWrapper<>();
|
|
|
+ queryAnalyseTableWrapper.eq("id", v_table_Res.getAnalyseTableId());
|
|
|
+ v_analyse_table = tableMapper.selectOne(queryAnalyseTableWrapper);
|
|
|
+ }
|
|
|
+ String v_analyse_type = v_table_Res.getAnalyseType();
|
|
|
+ if (v_analyse_table == null) {
|
|
|
+ //intersects 相交
|
|
|
+ //intersection 交集
|
|
|
+// v_table_Res.getAnalyseType();
|
|
|
+ if ("intersection".equals(v_analyse_type)) {
|
|
|
+ return tabelIntersectionHandle(pointEWkt, v_from_table.getTableName(), v_from_table.getId());
|
|
|
+ }
|
|
|
+ return tabelIntersectsHandle(pointEWkt, v_from_table.getTableName(), v_from_table.getId());
|
|
|
+ } else {
|
|
|
+ if ("intersection".equals(v_analyse_type)) {
|
|
|
+ return tabelIntersectionHandle(pointEWkt, v_analyse_table.getTableName(), v_analyse_table.getId());
|
|
|
+ }
|
|
|
+ return tabelIntersectsHandle(pointEWkt, v_analyse_table.getTableName(), v_analyse_table.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //取相交的函数
|
|
|
+ private List<List<TableDataVo>> tabelIntersectsHandle(String eWkt, String tableName, String tableId) {
|
|
|
+ List<List<TableDataVo>> retList = new ArrayList<>();
|
|
|
+ List<String> from_kj_ids = intersectsTableWkt(tableName, null, null, eWkt, null);
|
|
|
+ if (from_kj_ids == null || from_kj_ids.size() == 0) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TableFiledDTO> filedlist = getFieldListByTableId(tableId, null);
|
|
|
+ List<String> outputColumn = new ArrayList<>();
|
|
|
+ for (TableFiledDTO v_data : filedlist) {
|
|
|
+ outputColumn.add(v_data.getFiledName());
|
|
|
+ }
|
|
|
+ List<Map> retDataList = new ArrayList<>();
|
|
|
+ for (String v_id : from_kj_ids) {
|
|
|
+ Map map = tableDataSelectMapper.getTableDataById(tableName, v_id, outputColumn);
|
|
|
+ retDataList.add(map);
|
|
|
+ }
|
|
|
+ return dataMapTransFormZh(retDataList, filedlist);
|
|
|
+ }
|
|
|
+
|
|
|
+ //取并集的函数
|
|
|
+ private List<List<TableDataVo>> tabelIntersectionHandle(String eWkt, String tableName, String tableId) {
|
|
|
+ List<List<TableDataVo>> retList = new ArrayList<>();
|
|
|
+ List<String> from_kj_ids = intersectsTableWkt(tableName, null, null, eWkt, null);
|
|
|
+ if (from_kj_ids == null || from_kj_ids.size() == 0) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TableFiledDTO> list = getFieldListByTableId(tableId, null);
|
|
|
+ List<String> outputColumn = new ArrayList<>();
|
|
|
+ for (TableFiledDTO v_data : list) {
|
|
|
+ outputColumn.add(v_data.getFiledName());
|
|
|
+ }
|
|
|
+ List<Map> from_jg = intersectionTableWkt(tableName, 4326, from_kj_ids, eWkt, 4525, outputColumn);
|
|
|
+ if (from_jg == null || from_jg.size() == 0) {
|
|
|
+ return dataMapTransFormZh(from_jg, list);
|
|
|
+ }
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<List<TableDataVo>> dataMapTransFormZh(List<Map> from_jg, List<TableFiledDTO> filedList) {
|
|
|
+ List<List<TableDataVo>> retList = new ArrayList<>();
|
|
|
+ if (from_jg == null || from_jg.size() == 0) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+ if (filedList == null || filedList.size() == 0) {
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+ //循环结果
|
|
|
+ for (Map v_data : from_jg) {
|
|
|
+ //循环字段
|
|
|
+ List<TableDataVo> v_dataList = new ArrayList<>();
|
|
|
+ for (TableFiledDTO v_filed_data : filedList) {
|
|
|
+ String v_filedName = v_filed_data.getFiledName();
|
|
|
+ String v_filedZh = v_filed_data.getFiledZh();
|
|
|
+ Object v_filedData = v_data.get(v_filedName);
|
|
|
+ TableDataVo tableDataVo = new TableDataVo();
|
|
|
+ tableDataVo.setData(v_filedData);
|
|
|
+ tableDataVo.setFiledZH(v_filedZh);
|
|
|
+ tableDataVo.setFiled(v_filedName);
|
|
|
+ v_dataList.add(tableDataVo);
|
|
|
+ }
|
|
|
+ retList.add(v_dataList);
|
|
|
+ }
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> intersectsTableWkt(String inputTable, Integer inputSRID, List<String> inputIds, String intersectsWkt, Integer intersectsWktSRID) {
|
|
|
+ RequestResult result = analyseService.intersectsTableWkt(inputTable, inputSRID, inputIds, intersectsWkt, intersectsWktSRID);
|
|
|
+ Integer statuscode = (Integer) result.get("statuscode");
|
|
|
+ if (statuscode == 200) {
|
|
|
+ Object resultDataObject = result.get("data");
|
|
|
+ if (StringUtils.isNotNull(resultDataObject)) {
|
|
|
+ List<String> idsList = (List<String>) resultDataObject;
|
|
|
+ return idsList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Map> intersectionTableWkt(String inputTable, Integer inputSRID, List<String> inputIds, String intersectsWkt, Integer intersectsWktSRID, List<String> outputColumn) {
|
|
|
+ RequestResult result = analyseService.intersectionTableWkt(inputTable, inputSRID, inputIds, intersectsWkt, intersectsWktSRID, outputColumn);
|
|
|
+ Integer statuscode = (Integer) result.get("statuscode");
|
|
|
+ if (statuscode == 200) {
|
|
|
+ Object resultDataObject = result.get("data");
|
|
|
+ if (StringUtils.isNotNull(resultDataObject)) {
|
|
|
+ List<Map> idsList = (List<Map>) resultDataObject;
|
|
|
+ return idsList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<TableFiledDTO> getFieldListByTableId(String tableId, Integer isDisplay) {
|
|
|
+ List<TableFiledDTO> list = tableFiledMapper.getFiledDTOByTableId(tableId, isDisplay);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|