Browse Source

添加查询报表可分组列表接口

fengyanjie@sagacloud.cn 4 năm trước cách đây
mục cha
commit
3214cde315

+ 6 - 4
dmp-report/src/main/java/com/persagy/dmp/report/controller/ReportConfigController.java

@@ -6,10 +6,7 @@ import com.persagy.dmp.report.common.criteria.JacksonCriteria;
 import com.persagy.dmp.report.entity.ReportConfig;
 import com.persagy.dmp.report.service.ReportConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 @RestController
 @RequestMapping("/report/config")
@@ -37,4 +34,9 @@ public class ReportConfigController {
     public MapResponse delete(@RequestBody ReportConfig param) {
         return service.delete(param);
     }
+
+    @GetMapping("/groupbyColumns")
+    public MapResponse groupbyColumns(@RequestParam String tableName) {
+        return service.groupbyColumns(tableName);
+    }
 }

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

@@ -2,8 +2,13 @@ package com.persagy.dmp.report.repository;
 
 import com.persagy.dmp.report.entity.ReportConfig;
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.querydsl.QuerydslPredicateExecutor;
 
 public interface ReportConfigRepository extends JpaRepository<ReportConfig, String>, QuerydslPredicateExecutor<ReportConfig> {
+
+    @Query(nativeQuery = true,
+            value = "SELECT GROUP_CONCAT(DISTINCT group_column, ',') FROM dmp_report.report_config where table_name = ?")
+    String groupbyColumns(String tableName);
 }
 

+ 8 - 1
dmp-report/src/main/java/com/persagy/dmp/report/service/ReportConfigService.java

@@ -91,7 +91,7 @@ public class ReportConfigService implements BaseService {
         }
 
         Optional<ReportConfig> one = reportConfigRepository.findOne(QReportConfig.reportConfig.calculated.eq(calculated));
-        if(!one.isPresent()){
+        if (!one.isPresent()) {
             response.setFail("calculated is not exists");
             return response;
         }
@@ -112,4 +112,11 @@ public class ReportConfigService implements BaseService {
         reportConfigRepository.deleteById(calculated);
         return response;
     }
+
+    public MapResponse groupbyColumns(String tableName) {
+        MapResponse response = new MapResponse();
+        String groupbyColumns = reportConfigRepository.groupbyColumns(tableName);
+        response.add("data", groupbyColumns.split(","));
+        return response;
+    }
 }