|
@@ -14,6 +14,7 @@ import com.util.CalculationJudgeUtil;
|
|
|
import com.util.ScreenUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
@@ -39,6 +40,7 @@ public class ShowHistogramService {
|
|
|
|
|
|
柱状图数据展示
|
|
|
*/
|
|
|
+ @Transactional
|
|
|
public RepEntity showHistogram(HistogramConfigInfo histogramConfigInfo){
|
|
|
ChartsDataInfo chartsDataInfo = new ChartsDataInfo();
|
|
|
if (histogramConfigInfo == null || "".equals(histogramConfigInfo)){
|
|
@@ -55,141 +57,156 @@ public class ShowHistogramService {
|
|
|
String baseName = getChartsDataUtilService.getBaseName(id);
|
|
|
System.out.println("切换数据库"+baseName);
|
|
|
|
|
|
- if (!DynamicDataSourceContextHolder.isContainsDataSource(baseName)) {
|
|
|
-
|
|
|
- System.out.println("数据源 " + baseName + " 不存在使用默认的数据源 -> ");
|
|
|
- } else {
|
|
|
- System.out.println("使用数据源:" + baseName);
|
|
|
- DynamicDataSourceContextHolder.setDataSourceType(baseName);
|
|
|
- }
|
|
|
-
|
|
|
- String xColumn = histogramConfigInfo.getxAxis().getColumnRename();
|
|
|
- String yColumn = histogramConfigInfo.getyAxis().getColumnRename();
|
|
|
- String xColumnType = histogramConfigInfo.getxAxis().getColumnType();
|
|
|
+ try{
|
|
|
+ if (!DynamicDataSourceContextHolder.isContainsDataSource(baseName)) {
|
|
|
+
|
|
|
+ System.out.println("数据源 " + baseName + " 不存在使用默认的数据源 -> ");
|
|
|
+ } else {
|
|
|
+ System.out.println("使用数据源:" + baseName);
|
|
|
+ DynamicDataSourceContextHolder.setDataSourceType(baseName);
|
|
|
+ }
|
|
|
|
|
|
- String xAxisType = histogramConfigInfo.getxAxis().getShowDataType();
|
|
|
- List<String> groupBy = histogramConfigInfo.getGroups();
|
|
|
+ String xColumn = histogramConfigInfo.getxAxis().getColumnRename();
|
|
|
+ String yColumn = histogramConfigInfo.getyAxis().getColumnRename();
|
|
|
+ String xColumnType = histogramConfigInfo.getxAxis().getColumnType();
|
|
|
|
|
|
- if (xColumn == null || "".equals(xColumn) || yColumn == null || "".equals(yColumn)){
|
|
|
- return new RepEntity(RepCode.nullAxis);
|
|
|
- }
|
|
|
+ String xAxisType = histogramConfigInfo.getxAxis().getShowDataType();
|
|
|
+ List<String> groupBy = histogramConfigInfo.getGroups();
|
|
|
|
|
|
- String yType = histogramConfigInfo.getyAxis().getShowDataType();
|
|
|
- String yAxisType = calculationJudgeUtil.Judge(yType);
|
|
|
+ if (xColumn == null || "".equals(xColumn) || yColumn == null || "".equals(yColumn)){
|
|
|
+ return new RepEntity(RepCode.nullAxis);
|
|
|
+ }
|
|
|
|
|
|
+ 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>();
|
|
|
- List<String> xData = new ArrayList<String>();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- if ("time".equals(xColumnType)){
|
|
|
- xAxisData = timeConverterUtil.timeConverter(xColumn, tableName, xAxisType);
|
|
|
- xData = timeConverterUtil.toRespons(xAxisData,xAxisType );
|
|
|
- System.out.println("data:"+xAxisData);
|
|
|
- }else {
|
|
|
- xAxisData = showChartsMapper.getXAxis(xColumn, tableName);
|
|
|
+ Series series = new Series();
|
|
|
+ List<Double> value = new ArrayList<Double>();
|
|
|
+ List<Series> serieses = new ArrayList<Series>();
|
|
|
+ List<String> xAxisData = new ArrayList<String>();
|
|
|
+ List<String> xData = new ArrayList<String>();
|
|
|
|
|
|
- }
|
|
|
- if ("".equals(xAxisData) || xAxisData == null || xAxisData.size() == 0){
|
|
|
- return new RepEntity(RepCode.Null);
|
|
|
- }
|
|
|
- if ("week".equals(xAxisType) || "month".equals(xAxisType) || "quarter".equals(xAxisType)){
|
|
|
- chartsDataInfo.setxAxis(xData);
|
|
|
- }else {
|
|
|
- chartsDataInfo.setxAxis(xAxisData);
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ if ("time".equals(xColumnType)){
|
|
|
+ xAxisData = timeConverterUtil.timeConverter(xColumn, tableName, xAxisType);
|
|
|
+ xData = timeConverterUtil.toRespons(xAxisData,xAxisType );
|
|
|
+ System.out.println("data:"+xAxisData);
|
|
|
+ }else {
|
|
|
+ xAxisData = showChartsMapper.getXAxis(xColumn, tableName);
|
|
|
|
|
|
+ }
|
|
|
+ if ("".equals(xAxisData) || xAxisData == null || xAxisData.size() == 0){
|
|
|
+ return new RepEntity(RepCode.Null);
|
|
|
+ }
|
|
|
+ if ("week".equals(xAxisType) || "month".equals(xAxisType) || "quarter".equals(xAxisType)){
|
|
|
+ chartsDataInfo.setxAxis(xData);
|
|
|
+ }else {
|
|
|
+ chartsDataInfo.setxAxis(xAxisData);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- List<Screen> screens = histogramConfigInfo.getFilters();
|
|
|
- String screen = "";
|
|
|
- if ("".equals(screens) || screens == null){
|
|
|
- screen = "";
|
|
|
- }else {
|
|
|
- screen = screenUtil.screensUtil(screens);
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- Iterator itX = xAxisData.iterator();
|
|
|
- while (itX.hasNext()){
|
|
|
- String xdata = (String)itX.next();
|
|
|
- double valueOne = 0;
|
|
|
- String valueOnes = null;
|
|
|
- if ("time".equals(xColumnType)){
|
|
|
- valueOnes = timeConverterUtil.getTimeValueConverter(yColumn, xColumn, tableName, yAxisType, xAxisType, xdata);
|
|
|
+
|
|
|
+ List<Screen> screens = histogramConfigInfo.getFilters();
|
|
|
+ String screen = "";
|
|
|
+ if ("".equals(screens) || screens == null){
|
|
|
+ screen = "";
|
|
|
}else {
|
|
|
- valueOnes = showChartsMapper.getValues(yColumn, xColumn, tableName, yAxisType, xdata, screen);
|
|
|
+ screen = screenUtil.screensUtil(screens);
|
|
|
}
|
|
|
- if (valueOnes == null || "".equals(valueOnes)){
|
|
|
- valueOne = 0;
|
|
|
- }else {
|
|
|
- valueOne = Double.parseDouble(valueOnes);
|
|
|
+
|
|
|
+
|
|
|
+ Iterator itX = xAxisData.iterator();
|
|
|
+ while (itX.hasNext()){
|
|
|
+ String xdata = (String)itX.next();
|
|
|
+ if (xdata == null || "".equals(xdata)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ double valueOne = 0;
|
|
|
+ String valueOnes = null;
|
|
|
+ if ("time".equals(xColumnType)){
|
|
|
+ valueOnes = timeConverterUtil.getTimeValueConverter(yColumn, xColumn, tableName, yAxisType, xAxisType, xdata, screen);
|
|
|
+ }else {
|
|
|
+ valueOnes = showChartsMapper.getValues(yColumn, xColumn, tableName, yAxisType, xdata, screen);
|
|
|
+ }
|
|
|
+ if (valueOnes == null || "".equals(valueOnes)){
|
|
|
+ valueOne = 0;
|
|
|
+ }else {
|
|
|
+ valueOne = Double.parseDouble(valueOnes);
|
|
|
+ }
|
|
|
+ value.add(valueOne);
|
|
|
}
|
|
|
- value.add(valueOne);
|
|
|
- }
|
|
|
|
|
|
- System.out.println(value);
|
|
|
- series.setName(xColumn);
|
|
|
- series.setValue(value);
|
|
|
- serieses.add(series);
|
|
|
- System.out.println(serieses);
|
|
|
-
|
|
|
-
|
|
|
- if (groupBy.size() != 0){
|
|
|
- serieses.remove(0);
|
|
|
- Iterator itGroup = groupBy.iterator();
|
|
|
-
|
|
|
-
|
|
|
- while (itGroup.hasNext()){
|
|
|
- String groupByName = (String) itGroup.next();
|
|
|
- List<String> groupsData = showChartsMapper.getGroups(groupByName,tableName);
|
|
|
- System.out.println("groupdata:"+ groupsData.toString());
|
|
|
- Iterator itGroupsData = groupsData.iterator();
|
|
|
-
|
|
|
-
|
|
|
- while(itGroupsData.hasNext()){
|
|
|
- Series ne = new Series();
|
|
|
- String groupsName = (String)itGroupsData.next();
|
|
|
- ne.setName(groupsName);
|
|
|
- ne.setStack(groupByName);
|
|
|
-
|
|
|
- List<Double> groupsValue = new ArrayList<Double>();
|
|
|
- Iterator itXAxisData = xAxisData.iterator();
|
|
|
-
|
|
|
-
|
|
|
- while (itXAxisData.hasNext()){
|
|
|
- String xAxisDataOne = (String) itXAxisData.next();
|
|
|
- double groupsValueOne = 0;
|
|
|
- String groupsValueOnes = null;
|
|
|
- if ("time".equals(xColumnType)){
|
|
|
- groupsValueOnes = timeConverterUtil.getGroupTimeConverter(yAxisType, yColumn, tableName, groupByName, xAxisType,
|
|
|
- groupsName, xColumn, xAxisDataOne);
|
|
|
- }else {
|
|
|
- groupsValueOnes = showChartsMapper.getGroupsValue(yAxisType, yColumn, tableName, groupByName, groupsName, xColumn, xAxisDataOne);
|
|
|
+ System.out.println(value);
|
|
|
+ series.setName(xColumn);
|
|
|
+ series.setValue(value);
|
|
|
+ serieses.add(series);
|
|
|
+ System.out.println(serieses);
|
|
|
+
|
|
|
+
|
|
|
+ if (groupBy.size() != 0){
|
|
|
+ serieses.remove(0);
|
|
|
+ Iterator itGroup = groupBy.iterator();
|
|
|
+
|
|
|
+
|
|
|
+ while (itGroup.hasNext()){
|
|
|
+ String groupByName = (String) itGroup.next();
|
|
|
+ List<String> groupsData = showChartsMapper.getGroups(groupByName,tableName);
|
|
|
+ System.out.println("groupdata:"+ groupsData.toString());
|
|
|
+ Iterator itGroupsData = groupsData.iterator();
|
|
|
+
|
|
|
+
|
|
|
+ while(itGroupsData.hasNext()){
|
|
|
+ Series ne = new Series();
|
|
|
+ String groupsName = (String)itGroupsData.next();
|
|
|
+ if (groupsName == null || "".equals(groupsName)){
|
|
|
+ continue;
|
|
|
}
|
|
|
- if ("".equals(groupsValueOnes) || groupsValueOnes == null){
|
|
|
- groupsValueOne = 0;
|
|
|
- }else{
|
|
|
- groupsValueOne = Double.parseDouble(groupsValueOnes);
|
|
|
+ ne.setName(groupsName);
|
|
|
+ ne.setStack(groupByName);
|
|
|
+
|
|
|
+ List<Double> groupsValue = new ArrayList<Double>();
|
|
|
+ Iterator itXAxisData = xAxisData.iterator();
|
|
|
+
|
|
|
+
|
|
|
+ while (itXAxisData.hasNext()){
|
|
|
+ String xAxisDataOne = (String) itXAxisData.next();
|
|
|
+ if (xAxisDataOne == null || "".equals(xAxisDataOne)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ double groupsValueOne = 0;
|
|
|
+ String groupsValueOnes = null;
|
|
|
+ if ("time".equals(xColumnType)){
|
|
|
+ groupsValueOnes = timeConverterUtil.getGroupTimeConverter(yAxisType, yColumn, tableName, groupByName, xAxisType,
|
|
|
+ groupsName, xColumn, xAxisDataOne, screen);
|
|
|
+ }else {
|
|
|
+ groupsValueOnes = showChartsMapper.getGroupsValue(yAxisType, yColumn, tableName, groupByName, groupsName, xColumn, xAxisDataOne, screen);
|
|
|
+ }
|
|
|
+ if ("".equals(groupsValueOnes) || groupsValueOnes == null){
|
|
|
+ groupsValueOne = 0;
|
|
|
+ }else{
|
|
|
+ groupsValueOne = Double.parseDouble(groupsValueOnes);
|
|
|
+ }
|
|
|
+ groupsValue.add(groupsValueOne);
|
|
|
}
|
|
|
- groupsValue.add(groupsValueOne);
|
|
|
- }
|
|
|
|
|
|
- ne.setValue(groupsValue);
|
|
|
- System.out.println("值:"+ series);
|
|
|
- serieses.add(ne);
|
|
|
+ ne.setValue(groupsValue);
|
|
|
+ System.out.println("值:"+ series);
|
|
|
+ serieses.add(ne);
|
|
|
+ }
|
|
|
+ System.out.println(serieses);
|
|
|
}
|
|
|
- System.out.println(serieses);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- chartsDataInfo.setSerieses(serieses);
|
|
|
|
|
|
- DynamicDataSourceContextHolder.clearDataSourceType();
|
|
|
+ chartsDataInfo.setSerieses(serieses);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ System.out.println("异常");
|
|
|
+ return new RepEntity(RepCode.erro);
|
|
|
+ }finally {
|
|
|
+ DynamicDataSourceContextHolder.clearDataSourceType();
|
|
|
+ }
|
|
|
|
|
|
return new RepEntity(RepCode.success, chartsDataInfo);
|
|
|
}
|