|
|
@@ -1,11 +1,11 @@
|
|
|
-package com.database2.server;
|
|
|
+package com.server;
|
|
|
|
|
|
-import com.database2.dao.ShowChartsMapper;
|
|
|
+import com.dao.ShowChartsMapper;
|
|
|
import com.model.bo.Series;
|
|
|
import com.model.pojo.RepCode;
|
|
|
import com.model.pojo.RepEntity;
|
|
|
import com.model.vo.configVo.HistogramConfigInfo;
|
|
|
-import com.model.vo.dataVo.HistogramDataInfo;
|
|
|
+import com.model.vo.dataVo.ChartsDataInfo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
|
|
@@ -14,58 +14,47 @@ import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Repository
|
|
|
-public class ShowChartsService {
|
|
|
+public class ShowHistogramService {
|
|
|
@Autowired
|
|
|
ShowChartsMapper showChartsMapper;
|
|
|
@Autowired
|
|
|
TimeConverterUtil timeConverterUtil;
|
|
|
+ @Autowired
|
|
|
+ CalculationJudgeUtil calculationJudgeUtil;
|
|
|
|
|
|
/*
|
|
|
柱状图数据展示
|
|
|
*/
|
|
|
public RepEntity showHistogram(HistogramConfigInfo histogramConfigInfo){
|
|
|
- HistogramDataInfo histogramDataInfo = new HistogramDataInfo();
|
|
|
+ ChartsDataInfo chartsDataInfo = new ChartsDataInfo();
|
|
|
if (histogramConfigInfo == null || "".equals(histogramConfigInfo)){
|
|
|
return new RepEntity(RepCode.Null);
|
|
|
}
|
|
|
String tableName = histogramConfigInfo.getTableName();
|
|
|
String xColumn = histogramConfigInfo.getxAxis().getColumnRename();
|
|
|
String yColumn = histogramConfigInfo.getyAxis().getColumnRename();
|
|
|
+ String xColumnType = histogramConfigInfo.getxAxis().getColumnType();
|
|
|
|
|
|
- String xAxisType = histogramConfigInfo.getxAxis().getDataType();
|
|
|
+ String xAxisType = histogramConfigInfo.getxAxis().getShowDataType();
|
|
|
List<String> groupBy = histogramConfigInfo.getGroups();
|
|
|
|
|
|
if (xColumn == null || "".equals(xColumn) || yColumn == null || "".equals(yColumn)){
|
|
|
return new RepEntity(RepCode.nullAxis);
|
|
|
}
|
|
|
|
|
|
- String dataType = histogramConfigInfo.getyAxis().getDataType();
|
|
|
- if (dataType == null || "".equals(dataType) || "sum".equals(dataType)){
|
|
|
- dataType = "sum";
|
|
|
- }else if ("count".equals(dataType)){
|
|
|
- dataType = "count";
|
|
|
- }else if ("max".equals(dataType)){
|
|
|
- dataType = "max";
|
|
|
- }else if ("min".equals(dataType)){
|
|
|
- dataType = "min";
|
|
|
- }else if ("avg".equals(dataType)){
|
|
|
- dataType = "avg";
|
|
|
- }else if ("distinctCount".equals(dataType)){
|
|
|
- dataType = "distinct count";
|
|
|
- }else {
|
|
|
- return new RepEntity(RepCode.erro);
|
|
|
- }
|
|
|
+ String yType = histogramConfigInfo.getyAxis().getShowDataType();
|
|
|
+ String yAxisType = calculationJudgeUtil.Judge(yType);
|
|
|
+
|
|
|
|
|
|
Series series = new Series();
|
|
|
List<Double> value = new ArrayList<Double>();
|
|
|
List<Series> serieses = new ArrayList<Series>(); //生成柱状图的系列
|
|
|
List<String> xAxisData = new ArrayList<String>(); //X轴自己用
|
|
|
- List<String> xData = new ArrayList<String>(); //X轴跟前端沟通失败之后转给前端用
|
|
|
+ List<String> xData = new ArrayList<String>(); //X轴前端用
|
|
|
|
|
|
//X轴
|
|
|
//判断是否为日期类型
|
|
|
- if ("time".equals(histogramConfigInfo.getxAxis().getColumnType())){
|
|
|
-// xAxisData = showChartsMapper.getDate(xColumn.getColumnRename(), tableName);
|
|
|
+ if ("time".equals(xColumnType)){
|
|
|
xAxisData = timeConverterUtil.timeConverter(xColumn, tableName, xAxisType);
|
|
|
xData = timeConverterUtil.toRespons(xAxisData,xAxisType );
|
|
|
System.out.println("data:"+xAxisData);
|
|
|
@@ -77,24 +66,23 @@ public class ShowChartsService {
|
|
|
return new RepEntity(RepCode.Null);
|
|
|
}
|
|
|
if ("week".equals(xAxisType) || "month".equals(xAxisType) || "quarter".equals(xAxisType)){
|
|
|
- histogramDataInfo.setxAxis(xData);
|
|
|
+ chartsDataInfo.setxAxis(xData);
|
|
|
}else {
|
|
|
- histogramDataInfo.setxAxis(xAxisData);
|
|
|
+ chartsDataInfo.setxAxis(xAxisData);
|
|
|
}
|
|
|
|
|
|
- System.out.println("x轴:"+ histogramDataInfo.getxAxis());
|
|
|
-
|
|
|
//无分组时Y值
|
|
|
- System.out.println("列:"+groupBy);
|
|
|
Iterator itX = xAxisData.iterator();
|
|
|
while (itX.hasNext()){
|
|
|
String xdata = (String)itX.next();
|
|
|
double valueOne = 0;
|
|
|
String valueOnes = null;
|
|
|
- if ("time".equals(histogramConfigInfo.getxAxis().getColumnType())){
|
|
|
- valueOnes = timeConverterUtil.getTimeValueConverter(yColumn, xColumn, tableName, dataType, xAxisType, xdata);
|
|
|
+ if ("time".equals(xColumnType)){
|
|
|
+// System.out.println("Y:"+ yColumn + "........x:" + xColumn + "........yAxistype:" + yAxisType + "...xtpye:+"+yAxisType+ " xdata:"+xdata);
|
|
|
+ valueOnes = timeConverterUtil.getTimeValueConverter(yColumn, xColumn, tableName, yAxisType, xAxisType, xdata);
|
|
|
+// System.out.println("value:"+valueOnes);
|
|
|
}else {
|
|
|
- valueOnes = showChartsMapper.getValues(yColumn, xColumn, tableName, dataType, xdata);
|
|
|
+ valueOnes = showChartsMapper.getValues(yColumn, xColumn, tableName, yAxisType, xdata);
|
|
|
}
|
|
|
if (valueOnes == null || "".equals(valueOnes)){
|
|
|
valueOne = 0;
|
|
|
@@ -102,7 +90,6 @@ public class ShowChartsService {
|
|
|
valueOne = Double.parseDouble(valueOnes);
|
|
|
}
|
|
|
value.add(valueOne);
|
|
|
- System.out.println("value:"+value);
|
|
|
}
|
|
|
|
|
|
System.out.println(value);
|
|
|
@@ -111,7 +98,6 @@ public class ShowChartsService {
|
|
|
serieses.add(series);
|
|
|
System.out.println(serieses);
|
|
|
|
|
|
- System.out.println("size:"+groupBy.size());
|
|
|
//有分组
|
|
|
if (groupBy.size() != 0){
|
|
|
serieses.remove(0);
|
|
|
@@ -139,11 +125,11 @@ public class ShowChartsService {
|
|
|
String xAxisDataOne = (String) itXAxisData.next();
|
|
|
double groupsValueOne = 0;
|
|
|
String groupsValueOnes = null;
|
|
|
- if ("time".equals(histogramConfigInfo.getxAxis().getColumnType())){
|
|
|
- groupsValueOnes = timeConverterUtil.getGroupTimeConverter(dataType, yColumn, tableName, groupByName, xAxisType,
|
|
|
+ if ("time".equals(xColumnType)){
|
|
|
+ groupsValueOnes = timeConverterUtil.getGroupTimeConverter(yAxisType, yColumn, tableName, groupByName, xAxisType,
|
|
|
groupsName, xColumn, xAxisDataOne);
|
|
|
}else {
|
|
|
- groupsValueOnes = showChartsMapper.getGroupsValue(dataType, yColumn, tableName, groupByName, groupsName, xColumn, xAxisDataOne);
|
|
|
+ groupsValueOnes = showChartsMapper.getGroupsValue(yAxisType, yColumn, tableName, groupByName, groupsName, xColumn, xAxisDataOne);
|
|
|
}
|
|
|
if ("".equals(groupsValueOnes) || groupsValueOnes == null){
|
|
|
groupsValueOne = 0;
|
|
|
@@ -161,9 +147,9 @@ public class ShowChartsService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- histogramDataInfo.setSerieses(serieses);
|
|
|
+ chartsDataInfo.setSerieses(serieses);
|
|
|
|
|
|
- return new RepEntity(RepCode.success, histogramDataInfo);
|
|
|
+ return new RepEntity(RepCode.success, chartsDataInfo);
|
|
|
}
|
|
|
|
|
|
|