Browse Source

Merge remote-tracking branch 'origin/feature-cache' into feature-refactor

chenw 6 years ago
parent
commit
671e2a67f8

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ChartsConfigMapper.java

@@ -15,7 +15,7 @@ import java.util.Map;
 
 @Mapper
 @Repository
-@CacheNamespace
+@CacheNamespace(flushInterval = 300000L)
 public interface ChartsConfigMapper {
 
     @Insert("insert into bi_charts(id,CHART_NAME,CHART_TYPE,BD_DATA_ID,CHART_CONFIG,GROUP_BY,ACCESS_AUTHORITY,UPDATE_AUTHORITY,BC_CHARTS_GROUP,CHART_DESCRIBES,BC_CHART_STYLE," +

+ 4 - 3
bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ShowChartsMapper.java

@@ -11,10 +11,11 @@ import org.springframework.stereotype.Repository;
 
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 @Mapper
 @Repository
-@CacheNamespace
+@CacheNamespace(flushInterval = 300000L)
 public interface ShowChartsMapper {
     /*
     查询X轴列数
@@ -238,8 +239,8 @@ public interface ShowChartsMapper {
     总体分组的值
      */
     @Select("select ${groupBy},${operation} from ${tableName} ${screen} group by ${groupBy} order by ${groupByOne}")
-    List<LinkedHashMap<String, Object>> getGroupByValue(@Param("groupBy") String groupBy, @Param("operation") String operation, @Param("tableName") String tableName,
-                                                        @Param("groupByOne") String groupByOne, @Param("screen") String screen);
+    List<Map<String, Object>> getGroupByValue(@Param("groupBy") String groupBy, @Param("operation") String operation, @Param("tableName") String tableName,
+                                              @Param("groupByOne") String groupByOne, @Param("screen") String screen);
 
     /*
     总体TH值

+ 33 - 52
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowIndividualService.java

@@ -14,6 +14,10 @@ import com.usoftchina.bi.core.jdbc.DynamicDataSourceContextHolder;
 import com.usoftchina.bi.server.utils.ScreenUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
 
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
@@ -36,78 +40,55 @@ public class ShowIndividualService {
     ChartsUtilService chartsUtilService;
 
     public RepEntity showIndividual(IndividualConfigInfo individualConfigInfo, String token, int dashId){
-        if (individualConfigInfo == null || "".equals(individualConfigInfo)){
-            return new RepEntity(RepCode.Null);
-        }
+        Assert.notNull(individualConfigInfo, "请求参数不能为空");
+        /* 变量定义 */
         PopAndIndDataInfo popAndIndDataInfo = new PopAndIndDataInfo();
-
         List<LinkedHashMap<String, Object>> targetValue = new ArrayList<>();
-        //取表名
         int id = individualConfigInfo.getId();
-        //获取列配置
         ChartsColumnConfig chartsColumn = chartsConfigMapper.getChartsColumn(id);
-        if (chartsColumn == null || "".equals(chartsColumn)){
+        String tableName = chartsUtilService.getSqlStr(token, id, dashId);
+        int baseId = getChartsDataUtilService.getBaseId(id);
+        List<Screen> screens = individualConfigInfo.getFilters();
+        ScreenStr scr = new ScreenStr();
+        String screen = "";
+        String screenStr = "";
+        String columnName = individualConfigInfo.getSortColumn();
+        String columnListName = individualConfigInfo.getColumnListName().toString();
+        String sort = individualConfigInfo.getSort();
+        String tableListName = columnListName.replace("[", "").replace("]", "");
+        /* 参数校验 */
+        if (ObjectUtils.isEmpty(chartsColumn)) {
             return new RepEntity(RepCode.Null);
         }
-        popAndIndDataInfo.setChartsColumnConfig(chartsColumn);
-
-        String tableName = chartsUtilService.getSqlStr(token, id, dashId);
-        if ("".equals(tableName)){
+        if (StringUtils.isEmpty(tableName)){
             return new RepEntity(RepCode.NoAuthority);
-    }
-
-        int baseId = getChartsDataUtilService.getBaseId(id);
-
+        }
         try{
             if (!DynamicDataSourceContextHolder.isContainsDataSource(baseId)) {
                 return new RepEntity(RepCode.DataSourceNull);
             } else {
                 DynamicDataSourceContextHolder.setDataSourceType(baseId);
             }
-
-            //取筛选列表
-            List<Screen> screens = individualConfigInfo.getFilters();
-            ScreenStr scr = new ScreenStr();
-            String screen = "";
-            String screenStr = "";
-            if ("".equals(screens) || screens == null || screens.size() == 0){
-                screen = "";
-                screenStr = "";
-            }else {
+            if (!CollectionUtils.isEmpty(screens)){
                 scr = screenUtil.screensUtil(screens, "", "");
                 screen = scr.getRet();
                 StringBuilder sb = new StringBuilder(screen);
                 screenStr = String.valueOf(sb .replace(1, 5, "where "));
             }
-
-        String columnName = individualConfigInfo.getSortColumn();
-        //查询其他列
-        String columnListName = individualConfigInfo.getColumnListName().toString();
-        String sort = individualConfigInfo.getSort();
-
-        String tableListName = this.getString(columnListName);
-
-        targetValue = showChartsMapper.getOtherData(tableListName, tableName, columnName, sort, screenStr, individualConfigInfo.getTestPage().enablePaging());
-        PageInfo<LinkedHashMap<String, Object>> pageInfo = new PageInfo<>(targetValue);
-        popAndIndDataInfo.setValueList(pageInfo);
-    }catch (Exception e){
-        e.printStackTrace();
-        if (e.getCause().getMessage().contains("ORA-00904:")) {
-            return new RepEntity(RepCode.erro.getCode(), "数据源" + e.getCause().getMessage().replace("ORA-00904:", "").replaceAll("标识符", "列"), null);
+            targetValue = showChartsMapper.getOtherData(tableListName, tableName, columnName, sort, screenStr, individualConfigInfo.getTestPage().enablePaging());
+            PageInfo<LinkedHashMap<String, Object>> pageInfo = new PageInfo<>(targetValue);
+            popAndIndDataInfo.setChartsColumnConfig(chartsColumn);
+            popAndIndDataInfo.setValueList(pageInfo);
+        }catch (Exception e){
+            e.printStackTrace();
+            if (e.getCause().getMessage().contains("ORA-00904:")) {
+                return new RepEntity(RepCode.erro.getCode(), "数据源" + e.getCause().getMessage().replace("ORA-00904:", "").replaceAll("标识符", "列"), null);
+            }
+            return new RepEntity(RepCode.erro.getCode(), e.getCause().getMessage(), null);
+        }finally {
+            DynamicDataSourceContextHolder.clearDataSourceType();
         }
-        return new RepEntity(RepCode.erro.getCode(), e.getCause().getMessage(), null);
-    }finally {
-        DynamicDataSourceContextHolder.clearDataSourceType();
-    }
         return new RepEntity(RepCode.success, popAndIndDataInfo);
     }
 
-
-    private String getString(String str){
-        String st1 = "[";
-        String st2 = "]";
-        String strA = str.replace(st1, "");
-        String strB = strA.replace(st2, "");
-        return strB;
-    }
 }

+ 29 - 56
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowPopulationService.java

@@ -35,54 +35,44 @@ public class ShowPopulationService {
     ChartsUtilService chartsUtilService;
 
     public RepEntity showPopulation(PopulationInfo populationInfo, String token, int dashId) throws SQLException {
-        Assert.notNull(populationInfo, "参数不能为空");
+        Assert.notNull(populationInfo, "请求参数不能为空");
+        /* 变量定义 */
         PopAndIndDataInfo popAndIndDataInfo = new PopAndIndDataInfo();
-        //取表名
         int id = populationInfo.getId();
-        //获取列配置
+        int baseId = getChartsDataUtilService.getBaseId(id);
         ChartsColumnConfig chartsColumn = chartsConfigMapper.getChartsColumn(id);
+        String tableName = chartsUtilService.getSqlStr(token, id, dashId);
+        List<String> groupByList = populationInfo.getGroupByList();     //分组
+        String columnName = populationInfo.getColumnName();
+        List<String> operators = populationInfo.getOperatorList();
+        Map<String, Double> targetData = new HashMap<>();               //存放结果集
+        Double value = null;                                            //MAP的值
+        List<Screen> screens = populationInfo.getFilters();
+        String screen = "";
+        String screenStr = "";
+        ScreenStr str = new ScreenStr();
+        /* 参数校验 */
         if (ObjectUtils.isEmpty(chartsColumn)){
-            return new RepEntity(RepCode.erro.getCode(), "图表列配置为空", null);
+            return new RepEntity(RepCode.erro.getCode(), "图表列配置错误", null);
         }
-        popAndIndDataInfo.setChartsColumnConfig(chartsColumn);
-
-        String tableName = chartsUtilService.getSqlStr(token, id, dashId);
         if (StringUtils.isEmpty(tableName)){
             return new RepEntity(RepCode.NoAuthority);
         }
-
-        int baseId = getChartsDataUtilService.getBaseId(id);
-
+        /* 取数逻辑 */
         try{
             if (!DynamicDataSourceContextHolder.isContainsDataSource(baseId)) {
                 return new RepEntity(RepCode.DataSourceNull);
             } else {
                 DynamicDataSourceContextHolder.setDataSourceType(baseId);
             }
-            List<String> groupByList = populationInfo.getGroupByList();  //分组
-
-            //取目标列和分析运算符
-            String columnName = populationInfo.getColumnName();
-            List<String> operators = populationInfo.getOperatorList();
-            Map<String, Double> targetData = new HashMap<>();  //存放结果集
-            Double value = null;                 //MAP的值
-            //取筛选列表
-            List<Screen> screens = populationInfo.getFilters();
-            String screen = "";
-            String screenStr = "";
-            ScreenStr str = new ScreenStr();
-            if (CollectionUtils.isEmpty(screens)){
-                screen = "";
-                screenStr = "";
-            }else {
+            //条件语句处理
+            if (!CollectionUtils.isEmpty(screens)){
                 str = screenUtil.screensUtil(screens, "", "");
                 screen = str.getRet();
                 StringBuilder sb = new StringBuilder(screen);
                 screenStr = String.valueOf(sb .replace(1, 5, "where "));
             }
-
-            //无分组
-            if (groupByList.size() == 0) {
+            if (CollectionUtils.isEmpty(groupByList)) {
                 Iterator<String> operatorsList = operators.iterator();
                 while (operatorsList.hasNext()) {
                     String operator = operatorsList.next();
@@ -107,41 +97,31 @@ public class ShowPopulationService {
                     }
                     targetData.put(operator, value);
                 }
+                popAndIndDataInfo.setChartsColumnConfig(chartsColumn);
                 popAndIndDataInfo.setValueList(targetData);
                 return new RepEntity(RepCode.success, popAndIndDataInfo);
-                //有分组
             }else {
-                String listOne = groupByList.get(0);
+                String sortFiled = groupByList.get(0);
                 Iterator<String> operatorsList = operators.iterator();
-                //获取常规运算列
-                List<String> operatorColumn = new ArrayList<>();
-                //获取25th,75th算符
-                List<String> operatorOther = new ArrayList<>();
+                List<String> normalOperatorColumn = new ArrayList<>();
+                List<String> specialOperatorOther = new ArrayList<>();
                 String next = null;
                 while (operatorsList.hasNext()){
                     next = operatorsList.next();
                     //计算25th,75th,和百分比
                     if ("PERCENT".equalsIgnoreCase(next)){
                         String op = "count(" + columnName + ")/(select count(1) from " + tableName + ") \""+ next + "\"";
-                        operatorColumn.add(op);
+                        normalOperatorColumn.add(op);
                     }else if ("25th".equalsIgnoreCase(next) || "75th".equalsIgnoreCase(next)){
-                        operatorOther.add(next);
+                        specialOperatorOther.add(next);
                     }else {
                         String op = next + "(" + columnName + ") as \"" + next + "\"";
-                        operatorColumn.add(op);
+                        normalOperatorColumn.add(op);
                     }
                 }
-
-                String groups = groupByList.toString();
-                String groupBy = getString(groups);
-                String oprs = operatorColumn.toString();
-                String opr = getString(oprs);
-                //存放正常值
-                List<LinkedHashMap<String, Object>> valueList = new ArrayList<>();
-                //存放25th,75th
-                List<LinkedHashMap<String, Object>> valueListTh = new ArrayList<>();
-                Iterator thList = operatorOther.iterator();
-                valueList = showChartsMapper.getGroupByValue(groupBy, opr, tableName, listOne, screenStr);
+                String groupBy = String.join(",", groupByList),
+                       fileds = String.join(",", normalOperatorColumn);
+                List<Map<String, Object>> valueList = showChartsMapper.getGroupByValue(groupBy, fileds, tableName, sortFiled, screenStr);
                 popAndIndDataInfo.setValueList(valueList);
                 return new RepEntity(RepCode.success, popAndIndDataInfo);
             }
@@ -156,11 +136,4 @@ public class ShowPopulationService {
         }
     }
 
-    public String getString(String str){
-        String st1 = "[";
-        String st2 = "]";
-        String strA = str.replace(st1, "");
-        String strB = strA.replace(st2, "");
-        return strB;
-    }
 }