|
|
@@ -0,0 +1,111 @@
|
|
|
+package com.server;
|
|
|
+
|
|
|
+import com.dao.ChartsConfigMapper;
|
|
|
+import com.dao.ShowChartsMapper;
|
|
|
+import com.model.pojo.RepCode;
|
|
|
+import com.model.pojo.RepEntity;
|
|
|
+import com.model.vo.configVo.PopulationInfo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ShowPopulationService {
|
|
|
+ @Autowired
|
|
|
+ ChartsConfigMapper chartsConfigMapper;
|
|
|
+ @Autowired
|
|
|
+ ShowChartsMapper showChartsMapper;
|
|
|
+
|
|
|
+ public RepEntity showPopulation(PopulationInfo populationInfo) throws SQLException {
|
|
|
+ if (populationInfo == null || "".equals(populationInfo)){
|
|
|
+ return new RepEntity(RepCode.Null);
|
|
|
+ }
|
|
|
+ //取表名
|
|
|
+ int id = populationInfo.getId();
|
|
|
+ String tableName = chartsConfigMapper.getTableName(id).toUpperCase();
|
|
|
+// String tableName = "bench_flowchart".toUpperCase();
|
|
|
+ if (tableName == null || "".equals(tableName)){
|
|
|
+ return new RepEntity(RepCode.nullTableName);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> groupByList = populationInfo.getGroupByList(); //分组
|
|
|
+
|
|
|
+ //取目标列和分析运算符
|
|
|
+ String columnName = populationInfo.getColumnName();
|
|
|
+ List<String> operators = populationInfo.getOperatorList();
|
|
|
+ Map<String, Double> targetData = new HashMap<>(); //存放结果集
|
|
|
+ Double value = null; //MAP的值
|
|
|
+
|
|
|
+ //无分组
|
|
|
+ if (groupByList.size() == 0) {
|
|
|
+ Iterator operatorsList = operators.iterator();
|
|
|
+ while (operatorsList.hasNext()) {
|
|
|
+ String operator = String.valueOf(operatorsList.next()).toUpperCase();
|
|
|
+ if ("75th".equals(operator)) {
|
|
|
+ String calculation = "MEDIAN";
|
|
|
+ Double median = showChartsMapper.getColumnDev(tableName, columnName, calculation);
|
|
|
+ calculation = "MAX";
|
|
|
+ Double max = showChartsMapper.getColumnDev(tableName, columnName, calculation);
|
|
|
+ value = showChartsMapper.getValue(tableName, columnName, calculation, median, max);
|
|
|
+ } else if ("25th".equals(operator)) {
|
|
|
+ String calculation = "MEDIAN";
|
|
|
+ Double median = showChartsMapper.getColumnDev(tableName, columnName, calculation);
|
|
|
+ calculation = "MIN";
|
|
|
+ Double min = showChartsMapper.getColumnDev(tableName, columnName, calculation);
|
|
|
+ value = showChartsMapper.getValue(tableName, columnName, calculation, min, median);
|
|
|
+ } else if ("percentage".equals(operator)) {
|
|
|
+ value = 1.00;
|
|
|
+ } else {
|
|
|
+ value = showChartsMapper.getColumnDev(tableName, columnName, operator);
|
|
|
+ }
|
|
|
+ targetData.put(operator, value);
|
|
|
+ }
|
|
|
+ return new RepEntity(RepCode.success, targetData);
|
|
|
+ //有分组
|
|
|
+ }else {
|
|
|
+ String listOne = groupByList.get(0);
|
|
|
+
|
|
|
+ Iterator operatorsList = operators.iterator();
|
|
|
+ //获取运算列
|
|
|
+ List<String> operatorColumn = new ArrayList<>();
|
|
|
+
|
|
|
+ while (operatorsList.hasNext()){
|
|
|
+ String next = String.valueOf(operatorsList.next()).toLowerCase();
|
|
|
+ String op = next + "(" + columnName + ") as " +next.toLowerCase() ;
|
|
|
+ operatorColumn.add(op);
|
|
|
+ }
|
|
|
+
|
|
|
+// groupByList.addAll(operatorColumn);
|
|
|
+ String groups = groupByList.toString();
|
|
|
+ String groupBy = getString(groups);
|
|
|
+
|
|
|
+ String oprs = operatorColumn.toString();
|
|
|
+ String opr = getString(oprs);
|
|
|
+
|
|
|
+ //列头
|
|
|
+ groupByList.add(columnName);
|
|
|
+ groupByList.addAll(operators);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<LinkedHashMap<String, Object>> valueList = new ArrayList<>();
|
|
|
+ valueList = showChartsMapper.getGroupByValue(groupBy, opr, tableName, listOne);
|
|
|
+ System.out.println("valueList:"+ valueList);
|
|
|
+// PopulationDataInfo populationDataInfo = new PopulationDataInfo();
|
|
|
+// populationDataInfo.setColumnHead(groupByList);
|
|
|
+// populationDataInfo.setValueList(valueList);
|
|
|
+ return new RepEntity(RepCode.success, valueList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getString(String str){
|
|
|
+ String st1 = "[";
|
|
|
+ String st2 = "]";
|
|
|
+ String strA = str.replace(st1, "");
|
|
|
+ String StrB = strA.replace(st2, "");
|
|
|
+ System.out.println("str:"+ StrB);
|
|
|
+ return StrB;
|
|
|
+ }
|
|
|
+}
|