Sfoglia il codice sorgente

添加分页查询

DESKTOP-2K9OVK9\siwei 4 mesi fa
parent
commit
7e3a92bef1

+ 31 - 39
onemap-common/onemap-common-core/src/main/java/com/onemap/common/core/web/controller/BaseController.java

@@ -18,25 +18,21 @@ import com.onemap.common.core.web.page.TableDataInfo;
 
 /**
  * web层通用数据处理
- * 
+ *
  * @author onemap
  */
-public class BaseController
-{
+public class BaseController {
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     /**
      * 将前台传递过来的日期格式的字符串,自动转化为Date类型
      */
     @InitBinder
-    public void initBinder(WebDataBinder binder)
-    {
+    public void initBinder(WebDataBinder binder) {
         // Date 类型转换
-        binder.registerCustomEditor(Date.class, new PropertyEditorSupport()
-        {
+        binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
             @Override
-            public void setAsText(String text)
-            {
+            public void setAsText(String text) {
                 setValue(DateUtils.parseDate(text));
             }
         });
@@ -45,33 +41,29 @@ public class BaseController
     /**
      * 设置请求分页数据
      */
-    protected void startPage()
-    {
+    protected void startPage() {
         PageUtils.startPage();
     }
 
     /**
      * 设置请求分页数据(record格式)
      */
-    protected void startRecordPage()
-    {
+    protected void startRecordPage() {
         PageUtils.startRecordPage();
     }
 
     /**
      * 清理分页的线程变量
      */
-    protected void clearPage()
-    {
+    protected void clearPage() {
         PageUtils.clearPage();
     }
 
     /**
      * 响应请求分页数据
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    protected TableDataInfo getDataTable(List<?> list)
-    {
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    protected TableDataInfo getDataTable(List<?> list) {
         TableDataInfo rspData = new TableDataInfo();
         rspData.setCode(HttpStatus.SUCCESS);
         rspData.setRows(list);
@@ -83,9 +75,8 @@ public class BaseController
     /**
      * 响应请求分页数据(record格式)
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    protected RecordTableDataInfo getRecordDataTable(List<?> list)
-    {
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    protected RecordTableDataInfo getRecordDataTable(List<?> list) {
         RecordTableDataInfo rspData = new RecordTableDataInfo();
 //        rspData.setCode(HttpStatus.SUCCESS);
         rspData.setData(list);
@@ -98,73 +89,74 @@ public class BaseController
         return rspData;
     }
 
+    protected TableDataInfo getDataTableCustom(List<?> list, long total) {
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setRows(list);
+        rspData.setMsg("查询成功");
+        rspData.setTotal(total);
+        return rspData;
+    }
+
     /**
      * 返回成功
      */
-    public AjaxResult success()
-    {
+    public AjaxResult success() {
         return AjaxResult.success();
     }
 
     /**
      * 返回成功消息
      */
-    public AjaxResult success(String message)
-    {
+    public AjaxResult success(String message) {
         return AjaxResult.success(message);
     }
 
     /**
      * 返回成功消息
      */
-    public AjaxResult success(Object data)
-    {
+    public AjaxResult success(Object data) {
         return AjaxResult.success(data);
     }
 
     /**
      * 返回失败消息
      */
-    public AjaxResult error()
-    {
+    public AjaxResult error() {
         return AjaxResult.error();
     }
 
     /**
      * 返回失败消息
      */
-    public AjaxResult error(String message)
-    {
+    public AjaxResult error(String message) {
         return AjaxResult.error(message);
     }
 
     /**
      * 返回警告消息
      */
-    public AjaxResult warn(String message)
-    {
+    public AjaxResult warn(String message) {
         return AjaxResult.warn(message);
     }
 
     /**
      * 响应返回结果
-     * 
+     *
      * @param rows 影响行数
      * @return 操作结果
      */
-    protected AjaxResult toAjax(int rows)
-    {
+    protected AjaxResult toAjax(int rows) {
         return rows > 0 ? AjaxResult.success() : AjaxResult.error();
     }
 
     /**
      * 响应返回结果
-     * 
+     *
      * @param result 结果
      * @return 操作结果
      */
-    protected AjaxResult toAjax(boolean result)
-    {
+    protected AjaxResult toAjax(boolean result) {
         return result ? success() : error();
     }
 }

+ 12 - 3
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/dimentity/DimEntityController.java

@@ -4,7 +4,9 @@ import com.onemap.apply.domain.dimentity.EntityRelationshipToNeo4jVo;
 import com.onemap.apply.mapper.dimentity.DimEntityReponsitory;
 import com.onemap.apply.service.dimentity.DimEntityService;
 import com.onemap.common.core.utils.StringUtils;
+import com.onemap.common.core.web.controller.BaseController;
 import com.onemap.common.core.web.domain.RequestResult;
+import com.onemap.common.core.web.page.TableDataInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.neo4j.core.Neo4jClient;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -12,10 +14,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.Collections;
+import java.util.List;
 
 @RestController
 @RequestMapping("dimentity")
-public class DimEntityController {
+public class DimEntityController extends BaseController {
     @Resource
     private DimEntityService dimEntityService;
 
@@ -25,8 +29,13 @@ public class DimEntityController {
     }
 
     @GetMapping("/entity/code/table/list")
-    public RequestResult queryEntityCodeTableList(String id, String entityid, String entityname) {
-        return RequestResult.success(dimEntityService.queryEntityCodeTableList(id, entityid, entityname));
+    public TableDataInfo queryEntityCodeTableList(String id, String entityid, String entityname) {
+        List<String> tablesList = dimEntityService.queryEntityCodeTableListFront(id);
+        if (null == tablesList || tablesList.isEmpty()) {
+            return getDataTableCustom(Collections.emptyList(), 0);
+        }
+        startPage();
+        return getDataTable(dimEntityService.queryEntityCodeTableList(id, entityid, entityname, tablesList));
     }
 
     @GetMapping("/entity/data")

+ 0 - 2
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/domain/dimentity/EntityCodeListVo.java

@@ -1,7 +1,5 @@
 package com.onemap.apply.domain.dimentity;
 
-import java.util.List;
-
 public class EntityCodeListVo {
     private String entityname;
     private String alias;

+ 3 - 1
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/dimentity/DimEntityService.java

@@ -11,7 +11,9 @@ import java.util.Map;
 public interface DimEntityService {
     List<EntityCodeTreeVo> queryEntityCodeTableTree(String id);
 
-    List<EntityCodeListVo> queryEntityCodeTableList(String id, String entityid, String entityname);
+    public List<String> queryEntityCodeTableListFront(String id);
+
+    List<EntityCodeListVo> queryEntityCodeTableList(String id, String entityid, String entityname, List<String> tables);
 
     Map<String, Object> queryEntityData(String entityid);
 

+ 56 - 18
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/dimentity/impl/DimEntityServiceImpl.java

@@ -48,19 +48,19 @@ public class DimEntityServiceImpl implements DimEntityService {
     }
 
     @Override
-    public List<EntityCodeListVo> queryEntityCodeTableList(String id, String entityid, String entityname) {
+    public List<String> queryEntityCodeTableListFront(String id) {
         if (StringUtils.isEmpty(id)) {
-            return new ArrayList<>();
+            return Collections.emptyList();
         }
         //创建视图
         String viewTableName = StringUtils.getTemporaryTableName();
         createView(viewTableName);
-        List<String> d0_tables = dimEntityMapper.queryTablesNameByViewCode(viewTableName, id);
-        if (d0_tables.size() > 0) {
-            return dimEntityMapper.queryEntityCodeTableTreeDataByCodeV1(id, d0_tables, entityid, entityname);
-        } else {
-            return new ArrayList<>();
-        }
+        return dimEntityMapper.queryTablesNameByViewCode(viewTableName, id);
+    }
+
+    @Override
+    public List<EntityCodeListVo> queryEntityCodeTableList(String id, String entityid, String entityname, List<String> tables) {
+        return dimEntityMapper.queryEntityCodeTableTreeDataByCodeV1(id, tables, entityid, entityname);
     }
 
     @Override
@@ -197,25 +197,63 @@ public class DimEntityServiceImpl implements DimEntityService {
     public Map<String, Object> queryEntityRelationshipToNeo4j(String entityid) {
         Map<String, Object> retMap = new HashMap<>();
 //        String sql = "match (n:Entity{ entityid:'MA1001NE103K1034230XXXXXXXXXXXXX2501010009'}) <-[r]->(b:Entity)  return b.entityid, type(r)";
-        String sql = "match (n:Entity{ entityid:'" + entityid + "'}) <-[r]->(b:Entity)  return n.entityid as source,  n.entilayer as entilayer,  b.entityid as target,  b.entilayer as comilayer,  type(r) as value";
-        System.out.println("cql:" + sql);
-        Collection<Map<String, Object>> links = neo4jClient.query(sql).fetch().all();
-        if (links.isEmpty()) {
+        //这个sql是他关联其他
+        String start_sql = "match (n:Entity{ entityid:'" + entityid + "'}) -[r]->(b:Entity)  return n.entityid as source,  n.entilayer as entilayer,  b.entityid as target,  b.entilayer as comilayer,  type(r) as value";
+        Collection<Map<String, Object>> links_start_entityid = neo4jClient.query(start_sql).fetch().all();
+
+        //这个sql是其他关联他
+        String end_sql = "match (n:Entity{ entityid:'" + entityid + "'}) <-[r]-(b:Entity)  return b.entityid as source ,  b.entilayer as entilayer, n.entityid as target,  n.entilayer as comilayer,   type(r) as value";
+        Collection<Map<String, Object>> links_end_entityid = neo4jClient.query(end_sql).fetch().all();
+
+        if (links_start_entityid.isEmpty() && links_end_entityid.isEmpty()) {
             retMap.put("links", new HashMap<>());
             retMap.put("data", new ArrayList<>());
             return retMap;
         }
-        retMap.put("links", links);
-
-        List<Map<String, Object>> dataList = new ArrayList<>();
+        //用于判断结果是查询过
         Set<String> dataSet = new HashSet<>();
-        for (Map<String, Object> doMap : links) {
-            String comentityid = (String) doMap.get("target");
+        //用于判断结果是否有值
+        Set<String> dataSetTrue = new HashSet<>();
+        //添加关系
+        List<Map<String, Object>> linksList = new ArrayList<>();
+        //添加数据
+        List<Map<String, Object>> dataList = new ArrayList<>();
+
+        for (Map<String, Object> linksMap : links_start_entityid) {
+            String comentityid = (String) linksMap.get("target");
             if (!dataSet.contains(comentityid)) {
-                dataList.add(queryEntityData(comentityid));
+                Map<String, Object> dataMap = queryEntityData(comentityid);
+                if (dataMap != null && !dataMap.isEmpty()) {
+                    dataSetTrue.add(comentityid);
+                    dataList.add(dataMap);
+                }
                 dataSet.add(comentityid);
             }
+            if (dataSetTrue.contains(comentityid)) {
+                linksList.add(linksMap);
+            }
+        }
+
+        for (Map<String, Object> linksMap : links_end_entityid) {
+            String comentityid = (String) linksMap.get("source");
+            if (dataSetTrue.contains(comentityid)) {
+                //先判断数据存在
+                linksList.add(linksMap);
+            } else {
+                if (!dataSet.contains(comentityid)) {
+                    Map<String, Object> dataMap = queryEntityData(comentityid);
+                    if (dataMap != null && !dataMap.isEmpty()) {
+                        dataSetTrue.add(comentityid);
+                        dataList.add(dataMap);
+                    }
+                    dataSet.add(comentityid);
+                }
+                if (dataSetTrue.contains(comentityid)) {
+                    linksList.add(linksMap);
+                }
+            }
         }
+        retMap.put("links", linksList);
         retMap.put("data", dataList);
         return retMap;
     }