|
@@ -0,0 +1,96 @@
|
|
|
+package com.onemap.apply.service.dimentity.impl;
|
|
|
+
|
|
|
+import com.onemap.apply.domain.dimentity.EntityCodeTreeVo;
|
|
|
+import com.onemap.apply.domain.dimentity.EntityRelationshipVo;
|
|
|
+import com.onemap.apply.mapper.dimentity.DimEntityMapper;
|
|
|
+import com.onemap.apply.service.dimentity.DimEntityService;
|
|
|
+import com.onemap.common.core.utils.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class DimEntityServiceImpl implements DimEntityService {
|
|
|
+ @Resource
|
|
|
+ private DimEntityMapper dimEntityMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EntityCodeTreeVo> queryEntityCodeTableTree() {
|
|
|
+ //创建视图
|
|
|
+ String viewTableName = StringUtils.getTemporaryTableName();
|
|
|
+ createView(viewTableName);
|
|
|
+ return queryEntityCodeTableTreeData(null, 1, viewTableName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> queryEntityData(String entityid) {
|
|
|
+ //获取所有的实体关系表
|
|
|
+ List<String> tablesList = dimEntityMapper.querySchemaTableByName("vector", "实体图元关联表");
|
|
|
+ if (tablesList == null || tablesList.size() == 0) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<EntityRelationshipVo> relationshipVos = dimEntityMapper.queryEntityRelationshipDataByEntityId(entityid, tablesList);
|
|
|
+ if (relationshipVos == null || relationshipVos.size() == 0) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
|
|
|
+ for (EntityRelationshipVo relationshipVo : relationshipVos) {
|
|
|
+ ret.add(dimEntityMapper.queryEntityDataByEntityId(relationshipVo.getTylayer(), relationshipVo.getElementid()));
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createView(String viewTableName) {
|
|
|
+ //判斷视图是否存在
|
|
|
+ List<String> viewsList = dimEntityMapper.querySchemaTableByName("vector", viewTableName);
|
|
|
+ //视图存在,不创建
|
|
|
+ if (viewsList != null && viewsList.size() > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取所有的实体关系表
|
|
|
+ List<String> tablesList = dimEntityMapper.querySchemaTableByName("vector", "实体关系表");
|
|
|
+
|
|
|
+ //通过实体关系表,获取实体关系表中,所有映射的实体代理点。此处创建视图,视图将一个小时后删除
|
|
|
+ StringBuilder viewSql = new StringBuilder();
|
|
|
+ for (int i = 0; i < tablesList.size(); i++) {
|
|
|
+ if (i > 0) {
|
|
|
+ viewSql.append(" union all ");
|
|
|
+ }
|
|
|
+ String tableName = tablesList.get(i).trim();
|
|
|
+ String sql = "SELECT entilayer FROM vector.\"" + tableName + "\" x group by entilayer";
|
|
|
+ viewSql.append(sql);
|
|
|
+ }
|
|
|
+ dimEntityMapper.createEntityCodeTableDataViewByTableSql(viewSql.toString(), viewTableName);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<EntityCodeTreeVo> queryEntityCodeTableTreeData(String code, Integer level, String viewTableName) {
|
|
|
+ Long count = 0L;
|
|
|
+ List<EntityCodeTreeVo> entityCodeTreeVos = dimEntityMapper.queryEntityCodeTable(code, level);
|
|
|
+ if (level < 4) {
|
|
|
+ for (EntityCodeTreeVo entityCodeTreeVo : entityCodeTreeVos) {
|
|
|
+ entityCodeTreeVo.setCount(0L);
|
|
|
+// List<String> d0_tables = dimEntityMapper.queryTablesNameByViewCode(viewTableName, entityCodeTreeVo.getId());
|
|
|
+// if (d0_tables.size() > 0) {
|
|
|
+// entityCodeTreeVo.setCount(dimEntityMapper.queryEntityCodeTableCountByCode(entityCodeTreeVo.getId(), d0_tables));
|
|
|
+// }
|
|
|
+ entityCodeTreeVo.setChildren(queryEntityCodeTableTreeData(entityCodeTreeVo.getId(), level + 1, viewTableName));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (EntityCodeTreeVo entityCodeTreeVo : entityCodeTreeVos) {
|
|
|
+ entityCodeTreeVo.setCount(0L);
|
|
|
+ List<String> d0_tables = dimEntityMapper.queryTablesNameByViewCode(viewTableName, entityCodeTreeVo.getId());
|
|
|
+ if (d0_tables.size() > 0) {
|
|
|
+// entityCodeTreeVo.setCount(dimEntityMapper.queryEntityCodeTableCountByCode(entityCodeTreeVo.getId(), d0_tables));
|
|
|
+ entityCodeTreeVo.setChildren(dimEntityMapper.queryEntityCodeTableTreeDataByCode(entityCodeTreeVo.getId(), d0_tables));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return entityCodeTreeVos;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|