Просмотр исходного кода

解决报表设计器及缓存相关问题

master
jacky6024 7 лет назад
Родитель
Сommit
da38afeb7d
  1. 126
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/Aggregate.java
  2. 9
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/AvgAggregate.java
  3. 9
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/CountAggregate.java
  4. 3
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/CustomGroupAggregate.java
  5. 3
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/GroupAggregate.java
  6. 9
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/MaxAggregate.java
  7. 9
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/MinAggregate.java
  8. 3
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/SelectAggregate.java
  9. 9
      ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/SumAggregate.java
  10. 77
      ureport2-core/src/main/java/com/bstek/ureport/chart/Chart.java
  11. 24
      ureport2-core/src/main/java/com/bstek/ureport/chart/FontStyle.java
  12. 9
      ureport2-core/src/main/java/com/bstek/ureport/chart/axes/Axes.java
  13. 22
      ureport2-core/src/main/java/com/bstek/ureport/chart/axes/BaseAxes.java
  14. 58
      ureport2-core/src/main/java/com/bstek/ureport/chart/axes/ScaleLabel.java
  15. 9
      ureport2-core/src/main/java/com/bstek/ureport/chart/axes/XPosition.java
  16. 9
      ureport2-core/src/main/java/com/bstek/ureport/chart/axes/YPosition.java
  17. 32
      ureport2-core/src/main/java/com/bstek/ureport/chart/axes/impl/XAxes.java
  18. 32
      ureport2-core/src/main/java/com/bstek/ureport/chart/axes/impl/YAxes.java
  19. 27
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/BaseDataset.java
  20. 15
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/BubbleData.java
  21. 9
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/CollectType.java
  22. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/Dataset.java
  23. 15
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/DatasetType.java
  24. 15
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/PointStyle.java
  25. 15
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/ScatterData.java
  26. 15
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/Source.java
  27. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/BubbleDataset.java
  28. 15
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/DoughnutDataset.java
  29. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/MixDataset.java
  30. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/PieDataset.java
  31. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/PolarDataset.java
  32. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/RadarDataset.java
  33. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/ScatterDataset.java
  34. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/AreaDataset.java
  35. 55
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/BarDataset.java
  36. 24
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/CategoryData.java
  37. 234
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/CategoryDataset.java
  38. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/HorizontalBarDataset.java
  39. 76
      ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/LineDataset.java
  40. 15
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/Easing.java
  41. 9
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/FontStyle.java
  42. 34
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/Labels.java
  43. 17
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/Option.java
  44. 25
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/Padding.java
  45. 15
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/Position.java
  46. 24
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/AnimationsOption.java
  47. 23
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/LayoutOption.java
  48. 26
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/LegendOption.java
  49. 39
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/TitleOption.java
  50. 49
      ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/TooltipOption.java
  51. 60
      ureport2-core/src/main/java/com/bstek/ureport/export/ExportManagerImpl.java
  52. 2
      ureport2-core/src/main/java/com/bstek/ureport/model/Report.java
  53. 154
      ureport2-core/src/main/java/com/bstek/ureport/utils/DataUtils.java
  54. 9
      ureport2-js/src/dialog/PDFPrintDialog.js
  55. 3
      ureport2-js/src/jquery.draggable.js
  56. 20
      ureport2-js/src/preview.js

126
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/Aggregate.java

@ -16,7 +16,6 @@
package com.bstek.ureport.build.aggregate;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
@ -27,15 +26,8 @@ import com.bstek.ureport.Utils;
import com.bstek.ureport.build.BindData;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.definition.Order;
import com.bstek.ureport.definition.value.DatasetValue;
import com.bstek.ureport.definition.value.ExpressionValue;
import com.bstek.ureport.definition.value.Value;
import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.expression.model.Condition;
import com.bstek.ureport.expression.model.Expression;
import com.bstek.ureport.expression.model.expr.BaseExpression;
import com.bstek.ureport.expression.model.expr.JoinExpression;
import com.bstek.ureport.expression.model.expr.ParenExpression;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
@ -67,124 +59,6 @@ public abstract class Aggregate {
return label;
}
protected Cell fetchLeftCell(Cell cell, Context context,String datasetName){
Cell targetCell=null;
Cell leftCell=cell.getLeftParentCell();
if(leftCell!=null){
Value leftCellValue=leftCell.getValue();
DatasetExpression leftDSValue=fetchDatasetExpression(leftCellValue);
if(leftDSValue!=null){
String leftDatasetName=leftDSValue.getDatasetName();
if(leftDatasetName.equals(datasetName)){
if(leftCell.getBindData()!=null){
targetCell=leftCell;
}
}
}
}
return targetCell;
}
protected Cell fetchTopCell(Cell cell, Context context,String datasetName){
Cell targetCell=null;
Cell topCell=cell.getTopParentCell();
if(topCell!=null){
Value topCellValue=topCell.getValue();
DatasetExpression leftDSValue=fetchDatasetExpression(topCellValue);
if(leftDSValue!=null){
String leftDatasetName=leftDSValue.getDatasetName();
if(leftDatasetName.equals(datasetName)){
if(topCell.getBindData()!=null){
targetCell=topCell;
}
}
}
}
return targetCell;
}
protected DatasetExpression fetchDatasetExpression(Value value){
if(value instanceof ExpressionValue){
ExpressionValue exprValue=(ExpressionValue)value;
Expression expr=exprValue.getExpression();
if(expr instanceof DatasetExpression){
return (DatasetExpression)expr;
}else if(expr instanceof ParenExpression){
ParenExpression parenExpr=(ParenExpression)expr;
DatasetExpression targetExpr=buildDatasetExpression(parenExpr);
return targetExpr;
}else{
return null;
}
}else if(value instanceof DatasetValue){
return (DatasetValue)value;
}
return null;
}
private DatasetExpression buildDatasetExpression(JoinExpression joinExpr){
List<BaseExpression> expressions=joinExpr.getExpressions();
for(BaseExpression baseExpr:expressions){
if(baseExpr instanceof DatasetExpression){
return (DatasetExpression)baseExpr;
}else if(baseExpr instanceof JoinExpression){
JoinExpression childExpr=(JoinExpression)baseExpr;
return buildDatasetExpression(childExpr);
}
}
return null;
}
protected List<?> fetchData(Cell cell, Context context,String datasetName) {
Cell leftCell=fetchLeftCell(cell, context, datasetName);
Cell topCell=fetchTopCell(cell, context, datasetName);
List<Object> leftList=null,topList=null;
if(leftCell!=null){
leftList=leftCell.getBindData();
}
if(topCell!=null){
topList=topCell.getBindData();
}
if(leftList==null && topList==null){
List<?> data=context.getDatasetData(datasetName);
return data;
}else if(leftList==null){
return topList;
}else if(topList==null){
return leftList;
}else{
List<Object> list=null;
Object data=null;
String prop=null;
if(leftList.size()>topList.size()){
list=topList;
data=leftCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
prop=de.getProperty();
}else{
list=leftList;
data=topCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
prop=de.getProperty();
}
List<Object> result=new ArrayList<Object>();
for(Object obj:list){
Object o=Utils.getProperty(obj, prop);
if(o==data){
result.add(obj);
}
}
return result;
}
}
protected boolean doCondition(Condition condition,Cell cell,Object obj,Context context){
if(condition==null){
return true;

9
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/AvgAggregate.java

@ -27,6 +27,7 @@ import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.expression.model.Condition;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
* @author Jacky.gao
@ -37,8 +38,8 @@ public class AvgAggregate extends Aggregate {
public List<BindData> aggregate(DatasetExpression expr, Cell cell,Context context) {
String datasetName=expr.getDatasetName();
String property=expr.getProperty();
Cell leftCell=fetchLeftCell(cell, context, datasetName);
Cell topCell=fetchTopCell(cell, context, datasetName);
Cell leftCell=DataUtils.fetchLeftCell(cell, context, datasetName);
Cell topCell=DataUtils.fetchTopCell(cell, context, datasetName);
List<Object> leftList=null,topList=null;
if(leftCell!=null){
leftList=leftCell.getBindData();
@ -62,7 +63,7 @@ public class AvgAggregate extends Aggregate {
list=topList;
data=leftCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
@ -71,7 +72,7 @@ public class AvgAggregate extends Aggregate {
list=leftList;
data=topCell.getData();
Value value=topCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}

9
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/CountAggregate.java

@ -26,6 +26,7 @@ import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.expression.model.Condition;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
* @author Jacky.gao
@ -35,8 +36,8 @@ public class CountAggregate extends Aggregate {
@Override
public List<BindData> aggregate(DatasetExpression expr, Cell cell,Context context) {
String datasetName=expr.getDatasetName();
Cell leftCell=fetchLeftCell(cell, context, datasetName);
Cell topCell=fetchTopCell(cell, context, datasetName);
Cell leftCell=DataUtils.fetchLeftCell(cell, context, datasetName);
Cell topCell=DataUtils.fetchTopCell(cell, context, datasetName);
List<Object> leftList=null,topList=null;
if(leftCell!=null){
leftList=leftCell.getBindData();
@ -60,7 +61,7 @@ public class CountAggregate extends Aggregate {
list=topList;
data=leftCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
@ -69,7 +70,7 @@ public class CountAggregate extends Aggregate {
list=leftList;
data=topCell.getData();
Value value=topCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}

3
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/CustomGroupAggregate.java

@ -27,6 +27,7 @@ import com.bstek.ureport.definition.value.GroupItem;
import com.bstek.ureport.expression.model.Condition;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
* @author Jacky.gao
@ -36,7 +37,7 @@ public class CustomGroupAggregate extends Aggregate {
@Override
public List<BindData> aggregate(DatasetExpression expr, Cell cell,Context context) {
List<?> objList=fetchData(cell, context, expr.getDatasetName());
List<?> objList=DataUtils.fetchData(cell, context, expr.getDatasetName());
List<BindData> list = doAggregate(expr, cell, context, objList);
return list;
}

3
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/GroupAggregate.java

@ -26,6 +26,7 @@ import com.bstek.ureport.build.Context;
import com.bstek.ureport.definition.Order;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
* @author Jacky.gao
@ -34,7 +35,7 @@ import com.bstek.ureport.model.Cell;
public class GroupAggregate extends Aggregate {
@Override
public List<BindData> aggregate(DatasetExpression expr,Cell cell,Context context) {
List<?> objList=fetchData(cell, context, expr.getDatasetName());
List<?> objList=DataUtils.fetchData(cell, context, expr.getDatasetName());
List<BindData> list = doAggregate(expr, cell, context, objList);
return list;
}

9
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/MaxAggregate.java

@ -27,6 +27,7 @@ import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.expression.model.Condition;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
* @author Jacky.gao
@ -37,8 +38,8 @@ public class MaxAggregate extends Aggregate {
public List<BindData> aggregate(DatasetExpression expr, Cell cell,Context context) {
String datasetName=expr.getDatasetName();
String property=expr.getProperty();
Cell leftCell=fetchLeftCell(cell, context, datasetName);
Cell topCell=fetchTopCell(cell, context, datasetName);
Cell leftCell=DataUtils.fetchLeftCell(cell, context, datasetName);
Cell topCell=DataUtils.fetchTopCell(cell, context, datasetName);
List<Object> leftList=null,topList=null;
if(leftCell!=null){
leftList=leftCell.getBindData();
@ -62,7 +63,7 @@ public class MaxAggregate extends Aggregate {
list=topList;
data=leftCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
@ -71,7 +72,7 @@ public class MaxAggregate extends Aggregate {
list=leftList;
data=topCell.getData();
Value value=topCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}

9
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/MinAggregate.java

@ -27,6 +27,7 @@ import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.expression.model.Condition;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
* @author Jacky.gao
@ -37,8 +38,8 @@ public class MinAggregate extends Aggregate {
public List<BindData> aggregate(DatasetExpression expr, Cell cell,Context context) {
String datasetName=expr.getDatasetName();
String property=expr.getProperty();
Cell leftCell=fetchLeftCell(cell, context, datasetName);
Cell topCell=fetchTopCell(cell, context, datasetName);
Cell leftCell=DataUtils.fetchLeftCell(cell, context, datasetName);
Cell topCell=DataUtils.fetchTopCell(cell, context, datasetName);
List<Object> leftList=null,topList=null;
if(leftCell!=null){
leftList=leftCell.getBindData();
@ -62,7 +63,7 @@ public class MinAggregate extends Aggregate {
list=topList;
data=leftCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
@ -71,7 +72,7 @@ public class MinAggregate extends Aggregate {
list=leftList;
data=topCell.getData();
Value value=topCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}

3
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/SelectAggregate.java

@ -26,6 +26,7 @@ import com.bstek.ureport.build.Context;
import com.bstek.ureport.definition.Order;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
* @author Jacky.gao
@ -34,7 +35,7 @@ import com.bstek.ureport.model.Cell;
public class SelectAggregate extends Aggregate {
@Override
public List<BindData> aggregate(DatasetExpression expr,Cell cell, Context context) {
List<?> objList=fetchData(cell, context, expr.getDatasetName());
List<?> objList=DataUtils.fetchData(cell, context, expr.getDatasetName());
return doAggregate(expr, cell, context, objList);
}

9
ureport2-core/src/main/java/com/bstek/ureport/build/aggregate/SumAggregate.java

@ -27,6 +27,7 @@ import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.expression.model.Condition;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
* @author Jacky.gao
@ -37,8 +38,8 @@ public class SumAggregate extends Aggregate {
public List<BindData> aggregate(DatasetExpression expr, Cell cell,Context context) {
String datasetName=expr.getDatasetName();
String property=expr.getProperty();
Cell leftCell=fetchLeftCell(cell, context, datasetName);
Cell topCell=fetchTopCell(cell, context, datasetName);
Cell leftCell=DataUtils.fetchLeftCell(cell, context, datasetName);
Cell topCell=DataUtils.fetchTopCell(cell, context, datasetName);
List<Object> leftList=null,topList=null;
if(leftCell!=null){
leftList=leftCell.getBindData();
@ -62,7 +63,7 @@ public class SumAggregate extends Aggregate {
list=topList;
data=leftCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
@ -71,7 +72,7 @@ public class SumAggregate extends Aggregate {
list=leftList;
data=topCell.getData();
Value value=topCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
DatasetExpression de=DataUtils.fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}

77
ureport2-core/src/main/java/com/bstek/ureport/chart/Chart.java

@ -1,6 +1,25 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart;
import java.util.List;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.chart.axes.impl.XAxes;
import com.bstek.ureport.chart.axes.impl.YAxes;
import com.bstek.ureport.chart.dataset.Dataset;
import com.bstek.ureport.chart.option.Option;
import com.bstek.ureport.model.Cell;
@ -10,23 +29,69 @@ import com.bstek.ureport.model.Cell;
* @since 2017年6月8日
*/
public class Chart {
private Option option;
private List<Option> options;
private Dataset dataset;
private XAxes xaxes;
private YAxes yaxes;
public String doCompute(Cell cell, Context context){
StringBuilder sb=new StringBuilder();
sb.append("{");
sb.append("type:\""+dataset.type()+"\",");
sb.append("data:"+dataset.buildDataJson(context, cell)+",");
sb.append("options:{");
if(options!=null && options.size()>0){
for(Option option:options){
sb.append(option.buildOptionJson());
sb.append(",");
}
}
if(xaxes!=null || yaxes!=null){
sb.append("scales:{");
if(xaxes!=null){
sb.append("xAxes:[");
sb.append(xaxes.toJson());
sb.append("]");
}
if(yaxes!=null){
sb.append("yAxes:[");
sb.append(yaxes.toJson());
sb.append("]");
}
sb.append("}");
}
sb.append("}");
sb.append("}");
return sb.toString();
}
public Option getOption() {
return option;
public List<Option> getOptions() {
return options;
}
public void setOption(Option option) {
this.option = option;
public void setOptions(List<Option> options) {
this.options = options;
}
public Dataset getDataset() {
return dataset;
}
public void setDataset(Dataset dataset) {
this.dataset = dataset;
}
public XAxes getXaxes() {
return xaxes;
}
public void setXaxes(XAxes xaxes) {
this.xaxes = xaxes;
}
public YAxes getYaxes() {
return yaxes;
}
public void setYaxes(YAxes yaxes) {
this.yaxes = yaxes;
}
}

24
ureport2-core/src/main/java/com/bstek/ureport/chart/FontStyle.java

@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart;
/**
* @author Jacky.gao
* @since 2017年6月8日
*/
public enum FontStyle {
normal,italic,bold;
}

9
ureport2-core/src/main/java/com/bstek/ureport/chart/axes/Axes.java

@ -0,0 +1,9 @@
package com.bstek.ureport.chart.axes;
/**
* @author Jacky.gao
* @since 2017年6月14日
*/
public interface Axes {
String toJson();
}

22
ureport2-core/src/main/java/com/bstek/ureport/chart/axes/BaseAxes.java

@ -0,0 +1,22 @@
package com.bstek.ureport.chart.axes;
/**
* @author Jacky.gao
* @since 2017年6月14日
*/
public abstract class BaseAxes implements Axes {
private int rotation;
private ScaleLabel scaleLabel;
public int getRotation() {
return rotation;
}
public void setRotation(int rotation) {
this.rotation = rotation;
}
public ScaleLabel getScaleLabel() {
return scaleLabel;
}
public void setScaleLabel(ScaleLabel scaleLabel) {
this.scaleLabel = scaleLabel;
}
}

58
ureport2-core/src/main/java/com/bstek/ureport/chart/axes/ScaleLabel.java

@ -0,0 +1,58 @@
package com.bstek.ureport.chart.axes;
import com.bstek.ureport.chart.FontStyle;
/**
* @author Jacky.gao
* @since 2017年6月14日
*/
public class ScaleLabel {
private boolean display=false;
private String labelString="";
private String fontColor="#666";
private int fontSize=12;
private FontStyle fontStyle=FontStyle.normal;
public String toJson(){
StringBuilder sb=new StringBuilder();
sb.append("{");
sb.append("display:"+display+",");
sb.append("labelString:\""+labelString+"\",");
sb.append("fontColor:\""+fontColor+"\",");
sb.append("fontSize:"+fontSize+",");
sb.append("fontStyle:\""+fontStyle+"\"");
sb.append("}");
return sb.toString();
}
public boolean isDisplay() {
return display;
}
public void setDisplay(boolean display) {
this.display = display;
}
public String getLabelString() {
return labelString;
}
public void setLabelString(String labelString) {
this.labelString = labelString;
}
public String getFontColor() {
return fontColor;
}
public void setFontColor(String fontColor) {
this.fontColor = fontColor;
}
public int getFontSize() {
return fontSize;
}
public void setFontSize(int fontSize) {
this.fontSize = fontSize;
}
public FontStyle getFontStyle() {
return fontStyle;
}
public void setFontStyle(FontStyle fontStyle) {
this.fontStyle = fontStyle;
}
}

9
ureport2-core/src/main/java/com/bstek/ureport/chart/axes/XPosition.java

@ -0,0 +1,9 @@
package com.bstek.ureport.chart.axes;
/**
* @author Jacky.gao
* @since 2017年6月14日
*/
public enum XPosition {
top,bottom;
}

9
ureport2-core/src/main/java/com/bstek/ureport/chart/axes/YPosition.java

@ -0,0 +1,9 @@
package com.bstek.ureport.chart.axes;
/**
* @author Jacky.gao
* @since 2017年6月14日
*/
public enum YPosition {
left,right;
}

32
ureport2-core/src/main/java/com/bstek/ureport/chart/axes/impl/XAxes.java

@ -0,0 +1,32 @@
package com.bstek.ureport.chart.axes.impl;
import com.bstek.ureport.chart.axes.BaseAxes;
import com.bstek.ureport.chart.axes.ScaleLabel;
import com.bstek.ureport.chart.axes.XPosition;
/**
* @author Jacky.gao
* @since 2017年6月14日
*/
public class XAxes extends BaseAxes {
private XPosition xposition=XPosition.bottom;
@Override
public String toJson() {
StringBuilder sb=new StringBuilder();
sb.append("{");
sb.append("position:\""+xposition+"\",");
sb.append("minRotation:"+getRotation()+",");
ScaleLabel scaleLabel=getScaleLabel();
if(scaleLabel!=null){
sb.append("scaleLabel:"+scaleLabel.toJson());
}
sb.append("}");
return sb.toString();
}
public XPosition getXposition() {
return xposition;
}
public void setXposition(XPosition xposition) {
this.xposition = xposition;
}
}

32
ureport2-core/src/main/java/com/bstek/ureport/chart/axes/impl/YAxes.java

@ -0,0 +1,32 @@
package com.bstek.ureport.chart.axes.impl;
import com.bstek.ureport.chart.axes.BaseAxes;
import com.bstek.ureport.chart.axes.ScaleLabel;
import com.bstek.ureport.chart.axes.YPosition;
/**
* @author Jacky.gao
* @since 2017年6月14日
*/
public class YAxes extends BaseAxes {
private YPosition yposition;
@Override
public String toJson() {
StringBuilder sb=new StringBuilder();
sb.append("{");
sb.append("position:\""+yposition+"\",");
sb.append("minRotation:"+getRotation()+",");
ScaleLabel scaleLabel=getScaleLabel();
if(scaleLabel!=null){
sb.append("scaleLabel:"+scaleLabel.toJson());
}
sb.append("}");
return sb.toString();
}
public YPosition getYposition() {
return yposition;
}
public void setYposition(YPosition yposition) {
this.yposition = yposition;
}
}

27
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/BaseDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset;
@ -6,5 +21,15 @@ package com.bstek.ureport.chart.dataset;
* @since 2017年6月9日
*/
public abstract class BaseDataset implements Dataset {
private String[] COLORS={"255,99,132","255,159,64","255,205,86","75,192,192",
"54,162,235","153,102,255","153,102,255","201,203,207","205,92,92",
"255,127,80","173,255,47","127,255,0","138,43,226","147,112,219",
"198,226,255","rbg(154,50,205","193,205,205","238,238,224",
"24,116,205","137,104,205","180,82,205","205,50,120","205,0,0","148,0,211"};
protected String getRgbColor(int index){
if(index>=COLORS.length){
index=index % COLORS.length;
}
return COLORS[index];
}
}

15
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/BubbleData.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset;
/**

9
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/CollectType.java

@ -0,0 +1,9 @@
package com.bstek.ureport.chart.dataset;
/**
* @author Jacky.gao
* @since 2017年6月13日
*/
public enum CollectType {
select,count,sum,avg,max,min;
}

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/Dataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset;
import com.bstek.ureport.build.Context;
@ -8,7 +23,7 @@ import com.bstek.ureport.model.Cell;
* @since 2017年6月8日
*/
public interface Dataset {
String buildConfiguration(Context context,Cell cell);
String buildDataJson(Context context,Cell cell);
DatasetType getDatasetType();
String type();
}

15
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/DatasetType.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset;
/**

15
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/PointStyle.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset;
/**

15
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/ScatterData.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset;
/**

15
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/Source.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset;
/**

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/BubbleDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl;
import com.bstek.ureport.build.Context;
@ -21,7 +36,7 @@ public class BubbleDataset implements Dataset {
private int hoverBorderWidth;
private int hoverRadius;
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}
@Override

15
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/DoughnutDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl;
/**

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/MixDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl;
import java.util.ArrayList;
@ -19,7 +34,7 @@ public class MixDataset implements Dataset {
private List<LineDataset> lineDatasets=new ArrayList<LineDataset>();
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/PieDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl;
import com.bstek.ureport.build.Context;
@ -19,7 +34,7 @@ public class PieDataset implements Dataset {
private String hoverBorderColor;
private int hoverBorderWidth;
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/PolarDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl;
import com.bstek.ureport.build.Context;
@ -19,7 +34,7 @@ public class PolarDataset implements Dataset {
private String hoverBorderColor;
private int hoverBorderWidth;
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/RadarDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl;
import com.bstek.ureport.build.Context;
@ -30,7 +45,7 @@ public class RadarDataset implements Dataset {
private int pointHoverRadius;
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/ScatterDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl;
import com.bstek.ureport.build.Context;
@ -30,7 +45,7 @@ public class ScatterDataset implements Dataset {
private int pointHoverBorderWidth;
private int pointHoverRadius;
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}
@Override

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/AreaDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl.category;
import com.bstek.ureport.build.Context;
@ -10,7 +25,7 @@ import com.bstek.ureport.model.Cell;
*/
public class AreaDataset extends LineDataset {
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}
@Override

55
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/BarDataset.java

@ -1,7 +1,21 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl.category;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.chart.dataset.Dataset;
import com.bstek.ureport.chart.dataset.DatasetType;
import com.bstek.ureport.model.Cell;
@ -9,18 +23,13 @@ import com.bstek.ureport.model.Cell;
* @author Jacky.gao
* @since 2017年6月8日
*/
public class BarDataset implements Dataset{
private double[] data;
private String label;
private String backgroundColor;
private String borderColor;
private int borderWidth;
public class BarDataset extends CategoryDataset{
private String hoverBackgroundColor;
private String hoverBorderColor;
private String hoverBorderWidth;
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}
@Override
@ -31,36 +40,6 @@ public class BarDataset implements Dataset{
public String type() {
return "bar";
}
public double[] getData() {
return data;
}
public void setData(double[] data) {
this.data = data;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
}
public String getBorderColor() {
return borderColor;
}
public void setBorderColor(String borderColor) {
this.borderColor = borderColor;
}
public int getBorderWidth() {
return borderWidth;
}
public void setBorderWidth(int borderWidth) {
this.borderWidth = borderWidth;
}
public String getHoverBackgroundColor() {
return hoverBackgroundColor;
}

24
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/CategoryData.java

@ -1,24 +0,0 @@
package com.bstek.ureport.chart.dataset.impl.category;
import java.util.List;
/**
* @author Jacky.gao
* @since 2017年6月9日
*/
public class CategoryData {
private String label;
private List<Double> data;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<Double> getData() {
return data;
}
public void setData(List<Double> data) {
this.data = data;
}
}

234
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/CategoryDataset.java

@ -1,16 +1,39 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl.category;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.bstek.ureport.Utils;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.chart.dataset.BaseDataset;
import com.bstek.ureport.chart.dataset.CollectType;
import com.bstek.ureport.chart.dataset.Source;
import com.bstek.ureport.definition.value.AggregateType;
import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.utils.DataUtils;
/**
@ -19,52 +42,198 @@ import com.bstek.ureport.model.Cell;
*/
public abstract class CategoryDataset extends BaseDataset {
private Source source=Source.dataset;
private AggregateType aggregateType=AggregateType.select;
private CollectType collectType=CollectType.select;
private String datasetName;
private String categoryProperty;
private String seriesProperty;
private String valueProperty;
private String categoryExpression;
private String seriesExpression;
private String valueExpression;
protected List<CategoryData> buildCategoryDatas(Context context,Cell cell){
List<CategoryData> list=new ArrayList<CategoryData>();
List<?> data=context.getDatasetData(datasetName);
private String labels;
private String format;
protected String buildDatasetJson(Context context,Cell cell){
List<?> dataList=DataUtils.fetchData(cell, context, datasetName);
List<Object> categoryList=new ArrayList<Object>();
Map<Object,List<Object>> seriesMap=new HashMap<Object,List<Object>>();
for(Object obj:data){
Map<Object,Map<Object,List<Double>>> seriesDataMap=new HashMap<Object,Map<Object,List<Double>>>();
for(Object obj:dataList){
Object category=Utils.getProperty(obj, categoryProperty);
if(category!=null){
if(!categoryList.contains(category)){
categoryList.add(category);
}
if(category==null){
continue;
}
if(!categoryList.contains(category)){
categoryList.add(category);
}
Object series=Utils.getProperty(obj, seriesProperty);
if(series!=null){
List<Object> valueList;
if(seriesMap.containsKey(series)){
valueList=seriesMap.get(series);
if(series==null){
continue;
}
Object value=Utils.getProperty(obj, valueProperty);
double data=0;
if(value!=null && StringUtils.isNotBlank(value.toString())){
data=Utils.toBigDecimal(value).doubleValue();
}
if(seriesDataMap.containsKey(series)){
Map<Object,List<Double>> categoryMap=seriesDataMap.get(series);
List<Double> valueList=null;
if(categoryMap.containsKey(category)){
valueList=categoryMap.get(category);
}else{
valueList=new ArrayList<Object>();
seriesMap.put(series, valueList);
valueList=new ArrayList<Double>();
categoryMap.put(category, valueList);
}
valueList.add(data);
}else{
Map<Object,List<Double>> categoryMap=new HashMap<Object,List<Double>>();
for(Object cg:categoryList){
categoryMap.put(cg, new ArrayList<Double>());
}
Object value=Utils.getProperty(obj, valueProperty);
valueList.add(value);
List<Double> valueList=categoryMap.get(category);
valueList.add(data);
}
}
return list;
setLabels(toLabel(categoryList));
return buildDatasets(seriesDataMap);
}
public AggregateType getAggregateType() {
return aggregateType;
private String buildDatasets(Map<Object,Map<Object,List<Double>>> map){
StringBuilder sb=new StringBuilder();
sb.append("[");
int i=0;
for(Object series:map.keySet()){
if(i>0){
sb.append(",");
}
i++;
sb.append("{");
sb.append("label:\""+series+"\",");
String color=null;
if(this instanceof LineDataset){
color="rgb("+getRgbColor(i)+")";
}else{
color="rgba("+getRgbColor(i)+",0.5)";
}
sb.append("backgroundColor:\""+color+"\",");
sb.append("borderColor:\"rgb("+getRgbColor(i)+")\",");
sb.append("data:"+buildData(map.get(series)));
if(this instanceof LineDataset){
sb.append(",");
if(this instanceof AreaDataset){
sb.append("fill:true");
}else{
sb.append("fill:false");
}
}
sb.append("}");
}
sb.append("]");
return sb.toString();
}
private String buildData(Map<Object,List<Double>> categoryMap){
StringBuilder sb=new StringBuilder();
sb.append("[");
for(Object category:categoryMap.keySet()){
List<Double> list=categoryMap.get(category);
double data=collectData(list);
if(sb.length()>1){
sb.append(",");
}
sb.append(data);
}
sb.append("]");
return sb.toString();
}
private double collectData(List<Double> list){
double result=0;
switch(collectType){
case select:
result = list.get(0);
break;
case avg:
double total=0;
for(double data:list){
total+=data;
}
result=Utils.toBigDecimal(total).divide(Utils.toBigDecimal(list.size()),8,BigDecimal.ROUND_HALF_UP).doubleValue();
break;
case count:
result=list.size();
break;
case max:
Double max=null;
for(double data:list){
if(max==null){
max=data;
}else if(max<data){
max=data;
}
}
result=max;
break;
case min:
Double min=null;
for(double data:list){
if(min==null){
min=data;
}else if(min>data){
min=data;
}
}
result=min;
break;
case sum:
for(double data:list){
result+=data;
}
break;
}
return result;
}
private String toLabel(List<Object> categoryList){
StringBuilder sb=new StringBuilder();
for(Object obj:categoryList){
if(sb.length()>0){
sb.append(",");
}else{
sb.append("[");
}
if(StringUtils.isNotBlank(format)){
if(obj instanceof Date){
Date date=(Date)obj;
SimpleDateFormat sd=new SimpleDateFormat(format);
obj=sd.format(date);
}else{
try{
BigDecimal data=Utils.toBigDecimal(obj);
DecimalFormat df=new DecimalFormat(format);
obj=df.format(data.doubleValue());
}catch(Exception ex){
throw new ReportComputeException("Can not format data ["+obj+"] use pattern ["+format+"]");
}
}
}
sb.append("\""+obj+"\"");
}
if(sb.length()==0){
sb.append("[");
}
sb.append("]");
return sb.toString();
}
public CollectType getCollectType() {
return collectType;
}
public void setAggregateType(AggregateType aggregateType) {
this.aggregateType = aggregateType;
public void setCollectType(CollectType collectType) {
this.collectType = collectType;
}
public Source getSource() {
@ -115,4 +284,19 @@ public abstract class CategoryDataset extends BaseDataset {
public void setValueExpression(String valueExpression) {
this.valueExpression = valueExpression;
}
public void setLabels(String labels) {
this.labels = labels;
}
public String getLabels() {
return labels;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
}

17
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/HorizontalBarDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl.category;
import com.bstek.ureport.build.Context;
@ -10,7 +25,7 @@ import com.bstek.ureport.model.Cell;
*/
public class HorizontalBarDataset extends BarDataset {
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
return null;
}
@Override

76
ureport2-core/src/main/java/com/bstek/ureport/chart/dataset/impl/category/LineDataset.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.dataset.impl.category;
import com.bstek.ureport.build.Context;
@ -10,12 +25,6 @@ import com.bstek.ureport.model.Cell;
* @since 2017年6月8日
*/
public class LineDataset extends CategoryDataset{
private double[] data;
private String label;
private String backgroundColor;
private String borderColor;
private int borderWidth;
private boolean fill;
private double lineTension=0.2;
private String pointBackgroundColor;
private String pointBorderColor;
@ -28,19 +37,13 @@ public class LineDataset extends CategoryDataset{
private int pointHoverBorderWidth;
private int pointHoverRadius;
@Override
public String buildConfiguration(Context context,Cell cell) {
public String buildDataJson(Context context,Cell cell) {
String datasetJson=buildDatasetJson(context, cell);
StringBuilder sb=new StringBuilder();
sb.append("{");
if(label!=null){
sb.append("label:\""+label+"\"");
}
sb.append("");
sb.append("");
sb.append("");
sb.append("");
sb.append("");
sb.append("");
sb.append("");
String labels=getLabels();
sb.append("labels:"+labels+",");
sb.append("datasets:"+datasetJson+"");
sb.append("}");
return sb.toString();
}
@ -52,44 +55,7 @@ public class LineDataset extends CategoryDataset{
public String type() {
return "line";
}
public double[] getData() {
return data;
}
public void setData(double[] data) {
this.data = data;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
}
public String getBorderColor() {
return borderColor;
}
public void setBorderColor(String borderColor) {
this.borderColor = borderColor;
}
public int getBorderWidth() {
return borderWidth;
}
public void setBorderWidth(int borderWidth) {
this.borderWidth = borderWidth;
}
public boolean isFill() {
return fill;
}
public void setFill(boolean fill) {
this.fill = fill;
}
public double getLineTension() {
return lineTension;
}

15
ureport2-core/src/main/java/com/bstek/ureport/chart/option/Easing.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option;
/**

9
ureport2-core/src/main/java/com/bstek/ureport/chart/option/FontStyle.java

@ -1,9 +0,0 @@
package com.bstek.ureport.chart.option;
/**
* @author Jacky.gao
* @since 2017年6月8日
*/
public enum FontStyle {
normal,italic,bold;
}

34
ureport2-core/src/main/java/com/bstek/ureport/chart/option/Labels.java

@ -1,5 +1,22 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option;
import com.bstek.ureport.chart.FontStyle;
/**
* @author Jacky.gao
* @since 2017年6月8日
@ -9,8 +26,17 @@ public class Labels {
private int fontSize=12;
private FontStyle fontStyle=FontStyle.normal;
private String fontColor="#666";
private String fontFamily="'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
private int padding=10;
public String toJson(){
StringBuilder sb=new StringBuilder();
sb.append("{");
sb.append("boxWidth:"+boxWidth+",");
sb.append("fontSize:"+fontSize+",");
sb.append("fontStyle:\""+fontStyle+"\",");
sb.append("fontColor:\""+fontColor+"\"");
sb.append("}");
return sb.toString();
}
public int getBoxWidth() {
return boxWidth;
}
@ -35,12 +61,6 @@ public class Labels {
public void setFontColor(String fontColor) {
this.fontColor = fontColor;
}
public String getFontFamily() {
return fontFamily;
}
public void setFontFamily(String fontFamily) {
this.fontFamily = fontFamily;
}
public int getPadding() {
return padding;
}

17
ureport2-core/src/main/java/com/bstek/ureport/chart/option/Option.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option;
/**
@ -5,5 +20,5 @@ package com.bstek.ureport.chart.option;
* @since 2017年6月8日
*/
public interface Option {
String getConfiguration();
String buildOptionJson();
}

25
ureport2-core/src/main/java/com/bstek/ureport/chart/option/Padding.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option;
/**
@ -9,6 +24,16 @@ public class Padding {
private int right;
private int top;
private int bottom;
public String toJson(){
StringBuilder sb=new StringBuilder();
sb.append("{");
sb.append("left:"+left+",");
sb.append("right:"+right+",");
sb.append("top:"+top+",");
sb.append("bottom:"+bottom);
sb.append("}");
return sb.toString();
}
public int getLeft() {
return left;
}

15
ureport2-core/src/main/java/com/bstek/ureport/chart/option/Position.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option;
/**

24
ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/AnimationsOption.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option.impl;
import com.bstek.ureport.chart.option.Easing;
@ -11,8 +26,13 @@ public class AnimationsOption implements Option {
private int duration=1000;
private Easing easing=Easing.easeOutQuart;
@Override
public String getConfiguration() {
return null;
public String buildOptionJson() {
StringBuilder sb=new StringBuilder();
sb.append("animation:{");
sb.append("duration:"+duration+",");
sb.append("easing:\""+easing+"\"");
sb.append("}");
return sb.toString();
}
public int getDuration() {
return duration;

23
ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/LayoutOption.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option.impl;
import com.bstek.ureport.chart.option.Option;
@ -10,8 +25,12 @@ import com.bstek.ureport.chart.option.Padding;
public class LayoutOption implements Option {
private Padding padding;
@Override
public String getConfiguration() {
return null;
public String buildOptionJson() {
StringBuilder sb=new StringBuilder();
sb.append("layout:{");
sb.append("padding:"+padding.toJson());
sb.append("}");
return sb.toString();
}
public Padding getPadding() {
return padding;

26
ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/LegendOption.java

@ -1,3 +1,18 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option.impl;
import com.bstek.ureport.chart.option.Labels;
@ -13,8 +28,15 @@ public class LegendOption implements Option {
private Position position=Position.top;
private Labels labels;
@Override
public String getConfiguration() {
return null;
public String buildOptionJson() {
StringBuilder sb=new StringBuilder();
sb.append("legend:{");
sb.append("display:"+display+",");
sb.append("position:\""+position+"\"");
if(labels!=null){
sb.append("labels:"+labels.toJson());
}
return sb.toString();
}
public boolean isDisplay() {
return display;

39
ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/TitleOption.java

@ -1,6 +1,21 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option.impl;
import com.bstek.ureport.chart.option.FontStyle;
import com.bstek.ureport.chart.FontStyle;
import com.bstek.ureport.chart.option.Option;
import com.bstek.ureport.chart.option.Position;
@ -12,14 +27,24 @@ public class TitleOption implements Option {
private boolean display;
private Position position=Position.top;
private int fontSize=12;
private String fontFamily="'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
private String fontColor="#666";
private FontStyle fontStyle=FontStyle.bold;
private int padding=10;
private String text;
@Override
public String getConfiguration() {
return null;
public String buildOptionJson() {
StringBuilder sb=new StringBuilder();
sb.append("title:{");
sb.append("display:"+display+",");
sb.append("text:\""+text+"\",");
sb.append("position:\""+position+"\"");
sb.append("fontSize:"+fontSize+",");
sb.append("fontColor:\""+fontColor+"\",");
sb.append("fontStyle:\""+fontStyle+"\",");
sb.append("padding:\""+padding+"\",");
sb.append("text:\""+text+"\"");
sb.append("}");
return sb.toString();
}
public boolean isDisplay() {
return display;
@ -39,12 +64,6 @@ public class TitleOption implements Option {
public void setFontSize(int fontSize) {
this.fontSize = fontSize;
}
public String getFontFamily() {
return fontFamily;
}
public void setFontFamily(String fontFamily) {
this.fontFamily = fontFamily;
}
public String getFontColor() {
return fontColor;
}

49
ureport2-core/src/main/java/com/bstek/ureport/chart/option/impl/TooltipOption.java

@ -1,6 +1,21 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.chart.option.impl;
import com.bstek.ureport.chart.option.FontStyle;
import com.bstek.ureport.chart.FontStyle;
import com.bstek.ureport.chart.option.Option;
/**
@ -9,18 +24,26 @@ import com.bstek.ureport.chart.option.Option;
*/
public class TooltipOption implements Option {
private boolean enabled=true;
private String titleFontFamily="'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
private int titleFontSize=12;
private FontStyle titleFontStyle=FontStyle.bold;
private String titleFontColor="#fff";
private String bodyFontFamily="'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
private int bodyFontSize=12;
private FontStyle bodyFontStyle=FontStyle.normal;
private String bodyFontColor="#fff";
@Override
public String getConfiguration() {
return null;
public String buildOptionJson() {
StringBuilder sb=new StringBuilder();
sb.append("tooltips:{");
sb.append("enabled:"+enabled+",");
sb.append("titleFontSize:"+titleFontSize+",");
sb.append("titleFontStyle:\""+titleFontStyle+"\",");
sb.append("titleFontColor:\""+titleFontColor+"\",");
sb.append("bodyFontSize:"+bodyFontSize+",");
sb.append("bodyFontStyle:\""+bodyFontStyle+"\",");
sb.append("bodyFontColor:\""+bodyFontColor+"\",");
sb.append("}");
return sb.toString();
}
public boolean isEnabled() {
@ -31,14 +54,6 @@ public class TooltipOption implements Option {
this.enabled = enabled;
}
public String getTitleFontFamily() {
return titleFontFamily;
}
public void setTitleFontFamily(String titleFontFamily) {
this.titleFontFamily = titleFontFamily;
}
public int getTitleFontSize() {
return titleFontSize;
}
@ -63,14 +78,6 @@ public class TooltipOption implements Option {
this.titleFontColor = titleFontColor;
}
public String getBodyFontFamily() {
return bodyFontFamily;
}
public void setBodyFontFamily(String bodyFontFamily) {
this.bodyFontFamily = bodyFontFamily;
}
public int getBodyFontSize() {
return bodyFontSize;
}

60
ureport2-core/src/main/java/com/bstek/ureport/export/ExportManagerImpl.java

@ -42,7 +42,8 @@ public class ExportManagerImpl implements ExportManager {
public HtmlReport exportHtml(String file,String contextPath,Map<String, Object> parameters) {
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
Report report=reportRender.render(reportDefinition, parameters);
CacheUtils.storeReport(file, report);
String fullName=file+parameters.toString();
CacheUtils.storeReport(fullName, report);
HtmlReport htmlReport=new HtmlReport();
String content=htmlProducer.produce(report);
htmlReport.setContent(content);
@ -53,7 +54,12 @@ public class ExportManagerImpl implements ExportManager {
@Override
public HtmlReport exportHtml(String file,String contextPath,Map<String, Object> parameters, int pageIndex) {
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
Report report=reportRender.render(reportDefinition, parameters);
String fullName=file+parameters.toString();
Report report=CacheUtils.getReport(fullName);
if (report == null) {
report = reportRender.render(reportDefinition, parameters);
CacheUtils.storeReport(fullName, report);
}
SinglePageData pageData=PageBuilder.buildSinglePageData(pageIndex, report);
List<Page> pages=pageData.getPages();
String content=null;
@ -72,38 +78,68 @@ public class ExportManagerImpl implements ExportManager {
@Override
public void exportPdf(ExportConfigure config) {
String file=config.getFile();
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
Report report=reportRender.render(reportDefinition, config.getParameters());
Map<String, Object> parameters=config.getParameters();
String fullName=file+parameters.toString();
Report report=CacheUtils.getReport(fullName);
if (report == null) {
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
report = reportRender.render(reportDefinition, parameters);
CacheUtils.storeReport(fullName, report);
}
pdfProducer.produce(report, config.getOutputStream());
}
@Override
public void exportWord(ExportConfigure config) {
String file=config.getFile();
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
Report report=reportRender.render(reportDefinition, config.getParameters());
Map<String, Object> parameters=config.getParameters();
String fullName=file+parameters.toString();
Report report=CacheUtils.getReport(fullName);
if (report == null) {
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
report = reportRender.render(reportDefinition, parameters);
CacheUtils.storeReport(fullName, report);
}
wordProducer.produce(report, config.getOutputStream());
}
@Override
public void exportExcel(ExportConfigure config) {
String file=config.getFile();
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
Report report=reportRender.render(reportDefinition, config.getParameters());
Map<String, Object> parameters=config.getParameters();
String fullName=file+parameters.toString();
Report report=CacheUtils.getReport(fullName);
if (report == null) {
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
report = reportRender.render(reportDefinition, parameters);
CacheUtils.storeReport(fullName, report);
}
excelProducer.produce(report, config.getOutputStream());
}
@Override
public void exportExcelWithPaging(ExportConfigure config) {
String file=config.getFile();
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
Report report=reportRender.render(reportDefinition, config.getParameters());
Map<String, Object> parameters=config.getParameters();
String fullName=file+parameters.toString();
Report report=CacheUtils.getReport(fullName);
if (report == null) {
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
report = reportRender.render(reportDefinition, parameters);
CacheUtils.storeReport(fullName, report);
}
excelProducer.produceWithPaging(report, config.getOutputStream());
}
@Override
public void exportExcelWithPagingSheet(ExportConfigure config) {
String file=config.getFile();
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
Report report=reportRender.render(reportDefinition, config.getParameters());
Map<String, Object> parameters=config.getParameters();
String fullName=file+parameters.toString();
Report report=CacheUtils.getReport(fullName);
if (report == null) {
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
report = reportRender.render(reportDefinition, parameters);
CacheUtils.storeReport(fullName, report);
}
excelProducer.produceWithSheet(report, config.getOutputStream());
}

2
ureport2-core/src/main/java/com/bstek/ureport/model/Report.java

@ -145,7 +145,7 @@ public class Report {
paper.setColumnEnabled(this.paper.isColumnEnabled());
paper.setFixRows(this.paper.getFixRows());
paper.setPagingMode(this.paper.getPagingMode());
this.paper=paper;
setPaper(paper);
pages=PagingBuilder.buildPages(this);
}

154
ureport2-core/src/main/java/com/bstek/ureport/utils/DataUtils.java

@ -0,0 +1,154 @@
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.utils;
import java.util.ArrayList;
import java.util.List;
import com.bstek.ureport.Utils;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.definition.value.DatasetValue;
import com.bstek.ureport.definition.value.ExpressionValue;
import com.bstek.ureport.definition.value.Value;
import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.expression.model.Expression;
import com.bstek.ureport.expression.model.expr.BaseExpression;
import com.bstek.ureport.expression.model.expr.JoinExpression;
import com.bstek.ureport.expression.model.expr.ParenExpression;
import com.bstek.ureport.expression.model.expr.dataset.DatasetExpression;
import com.bstek.ureport.model.Cell;
/**
* @author Jacky.gao
* @since 2017年6月12日
*/
public class DataUtils {
public static List<?> fetchData(Cell cell, Context context,String datasetName) {
Cell leftCell=fetchLeftCell(cell, context, datasetName);
Cell topCell=fetchTopCell(cell, context, datasetName);
List<Object> leftList=null,topList=null;
if(leftCell!=null){
leftList=leftCell.getBindData();
}
if(topCell!=null){
topList=topCell.getBindData();
}
if(leftList==null && topList==null){
List<?> data=context.getDatasetData(datasetName);
return data;
}else if(leftList==null){
return topList;
}else if(topList==null){
return leftList;
}else{
List<Object> list=null;
Object data=null;
String prop=null;
if(leftList.size()>topList.size()){
list=topList;
data=leftCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
prop=de.getProperty();
}else{
list=leftList;
data=topCell.getData();
Value value=leftCell.getValue();
DatasetExpression de=fetchDatasetExpression(value);
if(de==null){
throw new ReportComputeException("Unsupport value : "+value);
}
prop=de.getProperty();
}
List<Object> result=new ArrayList<Object>();
for(Object obj:list){
Object o=Utils.getProperty(obj, prop);
if(o==data){
result.add(obj);
}
}
return result;
}
}
public static Cell fetchLeftCell(Cell cell, Context context,String datasetName){
Cell targetCell=null;
Cell leftCell=cell.getLeftParentCell();
if(leftCell!=null){
Value leftCellValue=leftCell.getValue();
DatasetExpression leftDSValue=fetchDatasetExpression(leftCellValue);
if(leftDSValue!=null){
String leftDatasetName=leftDSValue.getDatasetName();
if(leftDatasetName.equals(datasetName)){
if(leftCell.getBindData()!=null){
targetCell=leftCell;
}
}
}
}
return targetCell;
}
public static Cell fetchTopCell(Cell cell, Context context,String datasetName){
Cell targetCell=null;
Cell topCell=cell.getTopParentCell();
if(topCell!=null){
Value topCellValue=topCell.getValue();
DatasetExpression leftDSValue=fetchDatasetExpression(topCellValue);
if(leftDSValue!=null){
String leftDatasetName=leftDSValue.getDatasetName();
if(leftDatasetName.equals(datasetName)){
if(topCell.getBindData()!=null){
targetCell=topCell;
}
}
}
}
return targetCell;
}
public static DatasetExpression fetchDatasetExpression(Value value){
if(value instanceof ExpressionValue){
ExpressionValue exprValue=(ExpressionValue)value;
Expression expr=exprValue.getExpression();
if(expr instanceof DatasetExpression){
return (DatasetExpression)expr;
}else if(expr instanceof ParenExpression){
ParenExpression parenExpr=(ParenExpression)expr;
DatasetExpression targetExpr=buildDatasetExpression(parenExpr);
return targetExpr;
}else{
return null;
}
}else if(value instanceof DatasetValue){
return (DatasetValue)value;
}
return null;
}
private static DatasetExpression buildDatasetExpression(JoinExpression joinExpr){
List<BaseExpression> expressions=joinExpr.getExpressions();
for(BaseExpression baseExpr:expressions){
if(baseExpr instanceof DatasetExpression){
return (DatasetExpression)baseExpr;
}else if(baseExpr instanceof JoinExpression){
JoinExpression childExpr=(JoinExpression)baseExpr;
return buildDatasetExpression(childExpr);
}
}
return null;
}
}

9
ureport2-js/src/dialog/PDFPrintDialog.js

@ -176,8 +176,9 @@ export default class PDFPrintDialog{
_this.paper.bottomMargin=mmToPoint(value);
});
const file=getParameter('_u');
const urlParameters=window.location.search;
const h=$(window).height();
const url=window._server+"/pdf/show?_u="+file+"&_p=1";
const url=window._server+"/pdf/show"+urlParameters+"&_p=1";
const iFrame=$(`<iframe name="_iframe_for_pdf_print" style="width: 100%;height:${h}px;margin-top: 5px;border:solid 1px #c2c2c2" frameborder="0" src="${url}"></iframe>`);
this.body.append(iFrame);
iFrame.on('load',function(){
@ -191,10 +192,10 @@ export default class PDFPrintDialog{
const paperData=JSON.stringify(_this.paper);
$.ajax({
type:'POST',
data:{paper:paperData},
url:window._server+'/pdf/newPaging?_u='+file,
data:{_paper:paperData},
url:window._server+'/pdf/newPaging'+urlParameters,
success:function(){
const newUrl=window._server+'/pdf/show?_u='+file+'&_r='+(index++);
const newUrl=window._server+'/pdf/show'+urlParameters+'&_r='+(index++);
iFrame.prop('src',newUrl);
},
error:function(){

3
ureport2-js/src/jquery.draggable.js

@ -24,6 +24,9 @@
if(className && (className==='form-control' || className==='presentation' || iscm)){
return;
}
if(className.indexOf("ureport")>-1 || className.indexOf("ds_name")>-1 || className.indexOf("dataset_name")>-1 || target.tagName==="A"){
return;
}
if(target && $(target).attr('role')==='presentation'){
return;
}

20
ureport2-js/src/preview.js

@ -7,15 +7,15 @@ import {alert} from './MsgBox.js';
import PDFPrintDialog from './dialog/PDFPrintDialog.js';
$(document).ready(function(){
const file=getParameter('_u');
const urlParameters=window.location.search;
$('.ureport-print').click(function(){
const url=window._server+'/preview/loadPrintPages?_u='+file;
const url=window._server+'/preview/loadPrintPages'+urlParameters;
showLoading();
$.ajax({
url,
type:'POST',
success:function(result){
$.get(window._server+'/preview/loadPagePaper?_u='+file,function(paper){
$.get(window._server+'/preview/loadPagePaper'+urlParameters,function(paper){
const html=result.html;
const iFrame=window.frames['_print_frame'];
let styles=`<style type="text/css">`;
@ -38,7 +38,7 @@ $(document).ready(function(){
const pdfPrintDialog=new PDFPrintDialog();
let load=false;
$(`.ureport-pdf-print`).click(function(){
$.get(window._server+'/preview/loadPagePaper?_u='+file,function(paper){
$.get(window._server+'/preview/loadPagePaper'+urlParameters,function(paper){
pdfPrintDialog.show(paper);
if(!load){
showLoading();
@ -48,7 +48,7 @@ $(document).ready(function(){
});
$(`.ureport-pdf-direct-print`).click(function(){
showLoading();
const url=window._server+'/pdf/show?_u='+file+`&_i=${index++}`;
const url=window._server+'/pdf/show'+urlParameters+`&_i=${index++}`;
const iframe=window.frames['_print_pdf_frame'];
if(!directPrintPdf){
directPrintPdf=true;
@ -62,23 +62,23 @@ $(document).ready(function(){
iframe.location.href=url;
});
$(`.ureport-export-pdf`).click(function(){
const url=window._server+'/pdf?_u='+file;
const url=window._server+'/pdf'+urlParameters;
window.open(url,'_blank');
});
$(`.ureport-export-word`).click(function(){
const url=window._server+'/word?_u='+file;
const url=window._server+'/word'+urlParameters;
window.open(url,'_blank');
});
$(`.ureport-export-excel`).click(function(){
const url=window._server+'/excel?_u='+file;
const url=window._server+'/excel'+urlParameters;
window.open(url,'_blank');
});
$(`.ureport-export-excel-paging`).click(function(){
const url=window._server+'/excel/paging?_u='+file;
const url=window._server+'/excel/paging'+urlParameters;
window.open(url,'_blank');
});
$(`.ureport-export-excel-paging-sheet`).click(function(){
const url=window._server+'/excel/sheet?_u='+file;
const url=window._server+'/excel/sheet'+urlParameters;
window.open(url,'_blank');
});
});

Загрузка…
Отмена
Сохранить