|
|
@@ -13,6 +13,10 @@ import com.usoftchina.bi.server.model.vo.dataVo.PopAndIndDataInfo;
|
|
|
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.sql.SQLException;
|
|
|
import java.util.*;
|
|
|
@@ -31,23 +35,19 @@ public class ShowPopulationService {
|
|
|
ChartsUtilService chartsUtilService;
|
|
|
|
|
|
public RepEntity showPopulation(PopulationInfo populationInfo, String token, int dashId) throws SQLException {
|
|
|
- if (populationInfo == null || "".equals(populationInfo)){
|
|
|
- return new RepEntity(RepCode.Null);
|
|
|
- }
|
|
|
+ Assert.notNull(populationInfo, "参数不能为空");
|
|
|
PopAndIndDataInfo popAndIndDataInfo = new PopAndIndDataInfo();
|
|
|
//取表名
|
|
|
int id = populationInfo.getId();
|
|
|
//获取列配置
|
|
|
ChartsColumnConfig chartsColumn = chartsConfigMapper.getChartsColumn(id);
|
|
|
- if (chartsColumn == null || "".equals(chartsColumn)){
|
|
|
- return new RepEntity(RepCode.Null);
|
|
|
+ if (ObjectUtils.isEmpty(chartsColumn)){
|
|
|
+ return new RepEntity(RepCode.erro.getCode(), "图表列配置为空", null);
|
|
|
}
|
|
|
- String style = chartsColumn.getChartStyle();
|
|
|
- String config = chartsColumn.getChartConfig();
|
|
|
popAndIndDataInfo.setChartsColumnConfig(chartsColumn);
|
|
|
|
|
|
String tableName = chartsUtilService.getSqlStr(token, id, dashId);
|
|
|
- if ("".equals(tableName)){
|
|
|
+ if (StringUtils.isEmpty(tableName)){
|
|
|
return new RepEntity(RepCode.NoAuthority);
|
|
|
}
|
|
|
|
|
|
@@ -61,18 +61,17 @@ public class ShowPopulationService {
|
|
|
}
|
|
|
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 ("".equals(screens) || screens == null || screens.size() == 0){
|
|
|
+ if (CollectionUtils.isEmpty(screens)){
|
|
|
screen = "";
|
|
|
screenStr = "";
|
|
|
}else {
|
|
|
@@ -82,78 +81,70 @@ public class ShowPopulationService {
|
|
|
screenStr = String.valueOf(sb .replace(1, 5, "where "));
|
|
|
}
|
|
|
|
|
|
- //无分组
|
|
|
- if (groupByList.size() == 0) {
|
|
|
- Iterator<String> operatorsList = operators.iterator();
|
|
|
- while (operatorsList.hasNext()) {
|
|
|
- String operator = operatorsList.next();
|
|
|
- if ("75TH".equalsIgnoreCase(operator)) {
|
|
|
- String calculation = "MEDIAN";
|
|
|
- Double median = showChartsMapper.getColumnDev(tableName, columnName, calculation, screenStr);
|
|
|
- calculation = "MAX";
|
|
|
- Double max = showChartsMapper.getColumnDev(tableName, columnName, calculation, screenStr);
|
|
|
- value = showChartsMapper.getValue(tableName, columnName, calculation, median, max);
|
|
|
- } else if ("25TH".equalsIgnoreCase(operator)) {
|
|
|
- String calculation = "MEDIAN";
|
|
|
- Double median = showChartsMapper.getColumnDev(tableName, columnName, calculation, screen);
|
|
|
- calculation = "MIN";
|
|
|
- Double min = showChartsMapper.getColumnDev(tableName, columnName, calculation, screenStr);
|
|
|
- value = showChartsMapper.getValue(tableName, columnName, calculation, min, median);
|
|
|
- } else if ("PERCENT".equalsIgnoreCase(operator)) {
|
|
|
- value = 1.00;
|
|
|
- } else if("dictinctCount".equalsIgnoreCase(operator)){
|
|
|
- value = showChartsMapper.getDistinctCountColumnData(tableName, columnName, operator, screenStr);
|
|
|
- } else {
|
|
|
- value = showChartsMapper.getColumnData(tableName, columnName, operator, screenStr);
|
|
|
+ //无分组
|
|
|
+ if (groupByList.size() == 0) {
|
|
|
+ Iterator<String> operatorsList = operators.iterator();
|
|
|
+ while (operatorsList.hasNext()) {
|
|
|
+ String operator = operatorsList.next();
|
|
|
+ if ("75TH".equalsIgnoreCase(operator)) {
|
|
|
+ String calculation = "MEDIAN";
|
|
|
+ Double median = showChartsMapper.getColumnDev(tableName, columnName, calculation, screenStr);
|
|
|
+ calculation = "MAX";
|
|
|
+ Double max = showChartsMapper.getColumnDev(tableName, columnName, calculation, screenStr);
|
|
|
+ value = showChartsMapper.getValue(tableName, columnName, calculation, median, max);
|
|
|
+ } else if ("25TH".equalsIgnoreCase(operator)) {
|
|
|
+ String calculation = "MEDIAN";
|
|
|
+ Double median = showChartsMapper.getColumnDev(tableName, columnName, calculation, screen);
|
|
|
+ calculation = "MIN";
|
|
|
+ Double min = showChartsMapper.getColumnDev(tableName, columnName, calculation, screenStr);
|
|
|
+ value = showChartsMapper.getValue(tableName, columnName, calculation, min, median);
|
|
|
+ } else if ("PERCENT".equalsIgnoreCase(operator)) {
|
|
|
+ value = 1.00;
|
|
|
+ } else if("dictinctCount".equalsIgnoreCase(operator)){
|
|
|
+ value = showChartsMapper.getDistinctCountColumnData(tableName, columnName, operator, screenStr);
|
|
|
+ } else {
|
|
|
+ value = showChartsMapper.getColumnData(tableName, columnName, operator, screenStr);
|
|
|
+ }
|
|
|
+ targetData.put(operator, value);
|
|
|
}
|
|
|
- targetData.put(operator, value);
|
|
|
- }
|
|
|
- popAndIndDataInfo.setValueList(targetData);
|
|
|
- return new RepEntity(RepCode.success, popAndIndDataInfo);
|
|
|
- //有分组
|
|
|
- }else {
|
|
|
- String listOne = groupByList.get(0);
|
|
|
-
|
|
|
- Iterator operatorsList = operators.iterator();
|
|
|
- //获取常规运算列
|
|
|
- List<String> operatorColumn = new ArrayList<>();
|
|
|
- //获取25th,75th算符
|
|
|
- List<String> operatorOther = new ArrayList<>();
|
|
|
-
|
|
|
- String next = null;
|
|
|
- while (operatorsList.hasNext()){
|
|
|
- next = String.valueOf(operatorsList.next()).toLowerCase();
|
|
|
-
|
|
|
- //计算25th,75th,和百分比
|
|
|
- if (next.toUpperCase() == "PERCENT" || "PERCENT".equals(next.toUpperCase())){
|
|
|
- String op = "count(" + columnName + ")/(select count(1) from " + tableName + ") "+ next;
|
|
|
- operatorColumn.add(op);
|
|
|
- }else if ("25th".equals(next) || "75th".equals(next)){
|
|
|
- operatorOther.add(next);
|
|
|
- }else {
|
|
|
- String op = next + "(" + columnName + ") as " + next.toLowerCase();
|
|
|
- operatorColumn.add(op);
|
|
|
+ popAndIndDataInfo.setValueList(targetData);
|
|
|
+ return new RepEntity(RepCode.success, popAndIndDataInfo);
|
|
|
+ //有分组
|
|
|
+ }else {
|
|
|
+ String listOne = groupByList.get(0);
|
|
|
+ Iterator<String> operatorsList = operators.iterator();
|
|
|
+ //获取常规运算列
|
|
|
+ List<String> operatorColumn = new ArrayList<>();
|
|
|
+ //获取25th,75th算符
|
|
|
+ List<String> operatorOther = new ArrayList<>();
|
|
|
+ String next = null;
|
|
|
+ while (operatorsList.hasNext()){
|
|
|
+ next = operatorsList.next().toLowerCase();
|
|
|
+ //计算25th,75th,和百分比
|
|
|
+ if (next.toUpperCase() == "PERCENT" || "PERCENT".equals(next.toUpperCase())){
|
|
|
+ String op = "count(" + columnName + ")/(select count(1) from " + tableName + ") "+ next;
|
|
|
+ operatorColumn.add(op);
|
|
|
+ }else if ("25th".equals(next) || "75th".equals(next)){
|
|
|
+ operatorOther.add(next);
|
|
|
+ }else {
|
|
|
+ String op = next + "(" + columnName + ") as " + next.toLowerCase();
|
|
|
+ operatorColumn.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);
|
|
|
- popAndIndDataInfo.setValueList(valueList);
|
|
|
- return new RepEntity(RepCode.success, popAndIndDataInfo);
|
|
|
- }
|
|
|
+ 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);
|
|
|
+ popAndIndDataInfo.setValueList(valueList);
|
|
|
+ return new RepEntity(RepCode.success, popAndIndDataInfo);
|
|
|
+ }
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
if (e.getCause().getMessage().contains("ORA-00904:")) {
|