Procházet zdrojové kódy

添加查询所有计算字段接口

fengyanjie@sagacloud.cn před 4 roky
rodič
revize
271121347f

+ 7 - 5
dmp-report/src/main/java/com/persagy/dmp/report/controller/ReportConfigController.java

@@ -8,6 +8,8 @@ import com.persagy.dmp.report.service.ReportConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 @RestController
 @RequestMapping("/report/config")
 public class ReportConfigController {
@@ -35,13 +37,13 @@ public class ReportConfigController {
         return service.delete(param);
     }
 
-    @GetMapping("/groupbyColumns")
-    public MapResponse groupbyColumns(@RequestParam String tableName) {
-        return service.groupbyColumns(tableName);
+    @PostMapping("/groupbyColumns")
+    public MapResponse groupbyColumns(@RequestBody List<String> tableNameList) {
+        return service.groupbyColumns(tableNameList);
     }
 
     @GetMapping("/calculated")
-    public MapResponse calculated(@RequestParam String tableName) {
-        return service.calculated(tableName);
+    public MapResponse calculated() {
+        return service.calculated();
     }
 }

+ 4 - 4
dmp-report/src/main/java/com/persagy/dmp/report/repository/ReportConfigRepository.java

@@ -10,11 +10,11 @@ import java.util.List;
 public interface ReportConfigRepository extends JpaRepository<ReportConfig, String>, QuerydslPredicateExecutor<ReportConfig> {
 
     @Query(nativeQuery = true,
-            value = "SELECT GROUP_CONCAT(DISTINCT group_column, ',') FROM report_config where table_name = ?")
-    String groupbyColumns(String tableName);
+            value = "SELECT group_column FROM report_config where calculated in (?1)")
+    List<String> groupbyColumns(List<String> tableNameList);
 
     @Query(nativeQuery = true,
-            value = "SELECT calculated FROM dmp_report.report_config where table_name = ?")
-    List<String> calculated(String tableName);
+            value = "SELECT calculated FROM dmp_report.report_config")
+    List<String> calculated();
 }
 

+ 20 - 9
dmp-report/src/main/java/com/persagy/dmp/report/service/ReportConfigService.java

@@ -14,10 +14,8 @@ import com.querydsl.core.types.dsl.BooleanExpression;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author fengyanjie
@@ -113,16 +111,29 @@ public class ReportConfigService implements BaseService {
         return response;
     }
 
-    public MapResponse groupbyColumns(String tableName) {
+    public MapResponse groupbyColumns(List<String> tableNameList) {
         MapResponse response = new MapResponse();
-        String groupbyColumns = reportConfigRepository.groupbyColumns(tableName);
-        response.add("data", groupbyColumns.split(","));
+        List<String> list = reportConfigRepository.groupbyColumns(tableNameList);
+        List<String> intersection = new ArrayList<>();
+        for (String groupbyColumns : list) {
+            List<String> group = Arrays.asList(groupbyColumns.split(","));
+            if (group.size() == 0) {
+                intersection.clear();
+                break;
+            }
+            if (intersection.size() == 0) {
+                intersection.addAll(group);
+                continue;
+            }
+            intersection = intersection.stream().filter(item -> group.contains(item)).collect(Collectors.toList());
+        }
+        response.add("data", intersection);
         return response;
     }
 
-    public MapResponse calculated(String tableName) {
+    public MapResponse calculated() {
         MapResponse response = new MapResponse();
-        List<String> calculated = reportConfigRepository.calculated(tableName);
+        List<String> calculated = reportConfigRepository.calculated();
         response.add("data", calculated);
         return response;
     }