瀏覽代碼

解决表达式空字符串连接产生错误的BUG,重写隐藏行列算法

master
jacky6024 7 年前
父節點
當前提交
b5fc3cb4df
  1. 12
      ureport2-core/src/main/java/com/bstek/ureport/build/Context.java
  2. 219
      ureport2-core/src/main/java/com/bstek/ureport/build/HideRowColumnBuilder.java
  3. 129
      ureport2-core/src/main/java/com/bstek/ureport/build/ReportBuilder.java
  4. 40
      ureport2-core/src/main/java/com/bstek/ureport/build/paging/FitPagePagination.java
  5. 7
      ureport2-core/src/main/java/com/bstek/ureport/build/paging/FixRowsPagination.java
  6. 54
      ureport2-core/src/main/java/com/bstek/ureport/export/word/low/WordProducer.java
  7. 18
      ureport2-core/src/main/java/com/bstek/ureport/expression/model/expr/JoinExpression.java
  8. 6
      ureport2-core/src/main/java/com/bstek/ureport/model/Cell.java
  9. 2
      ureport2-core/src/main/java/com/bstek/ureport/utils/ElUtils.java
  10. 6
      ureport2-core/src/main/resources/ureport-core-context.xml

12
ureport2-core/src/main/java/com/bstek/ureport/build/Context.java

@ -50,14 +50,16 @@ public class Context {
private Map<Row,Map<Column,Cell>> blankCellsMap=new HashMap<Row,Map<Column,Cell>>();
private Map<Row,Integer> fillBlankRowsMap=new HashMap<Row,Integer>();
private Map<String,ChartData> chartDataMap=new HashMap<String,ChartData>();
private HideRowColumnBuilder hideRowColumnBuilder;
public Context(ReportBuilder reportBuilder,Report report,Map<String,Dataset> datasetMap,ApplicationContext applicationContext,Map<String,Object> parameters) {
public Context(ReportBuilder reportBuilder,Report report,Map<String,Dataset> datasetMap,ApplicationContext applicationContext,Map<String,Object> parameters,HideRowColumnBuilder hideRowColumnBuilder) {
this.reportBuilder=reportBuilder;
this.report = report;
report.setContext(this);
this.datasetMap=datasetMap;
this.applicationContext=applicationContext;
this.parameters=parameters;
this.hideRowColumnBuilder=hideRowColumnBuilder;
Map<String,List<Cell>> cellsMap=report.getCellsMap();
for(String key:cellsMap.keySet()){
if(key.equals(report.getRootCell().getName())){
@ -71,6 +73,14 @@ public class Context {
this.rootCell.setName("ROOT");
}
public void doHideProcessColumn(Column col) {
hideRowColumnBuilder.doHideProcessColumn(report, col);
}
public void doHideProcessRow(Row row) {
hideRowColumnBuilder.doHideProcessRow(report, row);
}
public void addFillBlankRow(Row row,int value){
fillBlankRowsMap.put(row, value);
}

219
ureport2-core/src/main/java/com/bstek/ureport/build/HideRowColumnBuilder.java

@ -0,0 +1,219 @@
package com.bstek.ureport.build;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.model.Column;
import com.bstek.ureport.model.Report;
import com.bstek.ureport.model.Row;
/**
* @author Jacky.gao
* @since 2017年7月4日
*/
public class HideRowColumnBuilder {
public void doHideProcessColumn(Report report, Column col) {
int colWidth=col.getWidth();
if(colWidth>0){
return;
}
List<Column> columns=report.getColumns();
int colNumber=col.getColumnNumber();
Map<Row, Map<Column, Cell>> cellMap=report.getRowColCellMap();
List<Row> rows=report.getRows();
for(Row row:rows){
Map<Column,Cell> rowMap=cellMap.get(row);
if(rowMap==null){
return;
}
Cell cell=rowMap.get(col);
if(cell!=null){
int colSpan=cell.getColSpan();
if(colSpan>0){
colSpan--;
if(colSpan==1){
colSpan=0;
}
cell.setColSpan(colSpan);
Column nextCol=columns.get(colNumber);
cell.setColumn(nextCol);
rowMap.put(nextCol, cell);
}
}else{
cell=fetchPrevColumnCell(report, colNumber-2, row);
int colSpan=cell.getColSpan();
if(colSpan>0){
colSpan--;
if(colSpan==1){
colSpan=0;
}
cell.setColSpan(colSpan);
}
}
rowMap.remove(col);
}
}
public void doHideProcessRow(Report report, Row row) {
int rowHeight=row.getRealHeight();
if(rowHeight>0){
return;
}
Map<Row, Map<Column, Cell>> cellMap=report.getRowColCellMap();
Map<Column,Cell> map=cellMap.get(row);
if(map==null){
return;
}
List<Row> rows=report.getRows();
List<Column> columns=report.getColumns();
int rowNumber=row.getRowNumber();
for(Column col:columns){
Cell cell=map.get(col);
if(cell!=null){
int rowSpan=cell.getRowSpan();
if(rowSpan>0){
rowSpan--;
if(rowSpan==1){
rowSpan=0;
}
cell.setRowSpan(rowSpan);
Row nextRow=rows.get(rowNumber);
cell.setRow(nextRow);
Map<Column,Cell> nextRowMap=cellMap.get(nextRow);
if(nextRowMap==null){
nextRowMap=new HashMap<Column,Cell>();
cellMap.put(nextRow, nextRowMap);
}
nextRowMap.put(col, cell);
}
}else{
Cell prevCell=fetchPrevRowCell(report, rowNumber-2, col);
int rowSpan=prevCell.getRowSpan();
if(rowSpan>0){
rowSpan--;
if(rowSpan==1){
rowSpan=0;
}
prevCell.setRowSpan(rowSpan);
}
}
}
cellMap.remove(row);
}
private Cell fetchPrevColumnCell(Report report, int startColNumber, Row row) {
Map<Row, Map<Column, Cell>> cellMap=report.getRowColCellMap();
List<Column> columns=report.getColumns();
Cell targetCell=null;
Map<Column,Cell> colMap=cellMap.get(row);
for(int i=startColNumber;i>-1;i--){
Column prevCol=columns.get(i);
if(colMap==null){
continue;
}
targetCell=colMap.get(prevCol);
if(targetCell!=null){
break;
}
}
return targetCell;
}
private Cell fetchPrevRowCell(Report report, int startRowNumber, Column col) {
Map<Row, Map<Column, Cell>> cellMap=report.getRowColCellMap();
List<Row> rows=report.getRows();
Cell targetCell=null;
for(int i=startRowNumber;i>-1;i--){
Row prevRow=rows.get(i);
Map<Column,Cell> colMap=cellMap.get(prevRow);
if(colMap==null){
continue;
}
targetCell=colMap.get(col);
if(targetCell!=null){
break;
}
}
return targetCell;
}
/*
public void processRowColumn(Report report, int i, Row row) {
Map<Row, Map<Column, Cell>> cellMap=report.getRowColCellMap();
Map<Column,Cell> map=cellMap.get(row);
if(map==null){
return;
}
List<Row> rows=report.getRows();
List<Column> columns=report.getColumns();
int colSize=columns.size();
for(int j=0;j<colSize;j++){
Column col=columns.get(j);
if(col==null){
continue;
}
Cell cell=map.get(col);
if(cell==null){
continue;
}
int colWidth=col.getWidth();
int colSpan=cell.getColSpan();
if(colWidth<1){
if(colSpan>1){
colSpan--;
if(colSpan<2)colSpan=0;
cell.setColSpan(colSpan);
Column nextCol=columns.get(j+1);
map.put(nextCol, cell);
}
map.remove(col);
}else{
if(colSpan>1){
int start=j+1,end=j+colSpan;
for(int num=start;num<end;num++){
Column nextCol=columns.get(num);
if(nextCol.getWidth()<1){
colSpan--;
}
}
if(colSpan<2){
colSpan=0;
}
cell.setColSpan(colSpan);
}
}
int rowHeight=row.getRealHeight();
int rowSpan=cell.getRowSpan();
if(rowHeight<1){
if(rowSpan>1){
rowSpan--;
if(rowSpan<2)rowSpan=0;
cell.setRowSpan(rowSpan);
Row nextRow=rows.get(i+1);
Map<Column,Cell> cmap=cellMap.get(nextRow);
cmap.put(col, cell);
}
}else{
if(rowSpan>1){
int start=i+1,end=i+rowSpan;
for(int num=start;num<end;num++){
Row nextRow=rows.get(num);
if(nextRow.getRealHeight()<1){
rowSpan--;
}
}
if(rowSpan<2){
rowSpan=0;
}
cell.setRowSpan(rowSpan);
}
}
}
if(row.getRealHeight()<1){
cellMap.remove(row);
}
}
*/
}

129
ureport2-core/src/main/java/com/bstek/ureport/build/ReportBuilder.java

@ -64,6 +64,7 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
private Map<String,DatasourceProvider> datasourceProviderMap=new HashMap<String,DatasourceProvider>();
private Map<Expand,CellBuilder> cellBuildersMap=new HashMap<Expand,CellBuilder>();
private NoneExpandBuilder noneExpandBuilder=new NoneExpandBuilder();
private HideRowColumnBuilder hideRowColumnBuilder;
public ReportBuilder() {
cellBuildersMap.put(Expand.Right,new RightExpandBuilder());
cellBuildersMap.put(Expand.Down,new DownExpandBuilder());
@ -72,7 +73,7 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
public Report buildReport(ReportDefinition reportDefinition,Map<String,Object> parameters) {
Report report = reportDefinition.newReport();
Map<String,Dataset> datasetMap=buildDatasets(reportDefinition, parameters, applicationContext);
Context context = new Context(this,report,datasetMap,applicationContext,parameters);
Context context = new Context(this,report,datasetMap,applicationContext,parameters,hideRowColumnBuilder);
long start=System.currentTimeMillis();
List<Cell> cells=new ArrayList<Cell>();
cells.add(report.getRootCell());
@ -265,8 +266,11 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
for(int i=0;i<rowSize;i++){
Row row=rows.get(i);
int rowRealHeight=row.getRealHeight();
if(rowRealHeight==0){
continue;
}
Band band=row.getBand();
if(band!=null && rowRealHeight>0){
if(band!=null){
String rowKey=row.getRowKey();
int index=-1;
if(band.equals(Band.headerrepeat)){
@ -290,29 +294,27 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
pageRepeatFooters.remove(index);
pageRepeatFooters.add(index,row);
}
continue;
}
if(rowRealHeight>1 && band==null){
rowHeight+=rowRealHeight;
pageRows.add(row);
boolean overflow=false;
if((i+1)<rows.size()){
Row nextRow=rows.get(i+1);
if((rowHeight+nextRow.getRealHeight()) > height){
overflow=true;
}
}
if(!overflow && row.isPageBreak()){
rowHeight+=rowRealHeight;
pageRows.add(row);
boolean overflow=false;
if((i+1)<rows.size()){
Row nextRow=rows.get(i+1);
if((rowHeight+nextRow.getRealHeight()) > height){
overflow=true;
}
if(overflow){
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
pageIndex++;
pages.add(newPage);
rowHeight=repeatHeaderRowHeight+repeatFooterRowHeight;
pageRows=new ArrayList<Row>();
}
}
processRowColumn(report, i, row);
if(!overflow && row.isPageBreak()){
overflow=true;
}
if(overflow){
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
pageIndex++;
pages.add(newPage);
rowHeight=repeatHeaderRowHeight+repeatFooterRowHeight;
pageRows=new ArrayList<Row>();
}
}
if(pageRows.size()>0){
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
@ -326,10 +328,12 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
}
for(int i=0;i<rowSize;i++){
Row row=rows.get(i);
processRowColumn(report, i, row);
int height=row.getRealHeight();
if(height==0){
continue;
}
Band band=row.getBand();
if(band!=null && height>0){
if(band!=null){
String rowKey=row.getRowKey();
int index=-1;
if(band.equals(Band.headerrepeat)){
@ -357,7 +361,7 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
throw new ReportComputeException("Invalid row["+band+"] with key "+rowKey+".");
}
}
if(height<1 || band!=null){
if(band!=null){
continue;
}
pageRows.add(row);
@ -379,80 +383,9 @@ public class ReportBuilder extends BasePagination implements ApplicationContextA
buildSummaryRows(summaryRows, pages);
report.setPages(pages);
}
private void processRowColumn(Report report, int i, Row row) {
Map<Row, Map<Column, Cell>> cellMap=report.getRowColCellMap();
Map<Column,Cell> map=cellMap.get(row);
if(map==null){
return;
}
List<Row> rows=report.getRows();
List<Column> columns=report.getColumns();
int colSize=columns.size();
for(int j=0;j<colSize;j++){
Column col=columns.get(j);
if(col==null){
continue;
}
Cell cell=map.get(col);
if(cell==null){
continue;
}
int colWidth=col.getWidth();
int colSpan=cell.getColSpan();
if(colWidth<1){
if(colSpan>1){
colSpan--;
if(colSpan<2)colSpan=0;
cell.setColSpan(colSpan);
Column nextCol=columns.get(j+1);
map.put(nextCol, cell);
}
map.remove(col);
}else{
if(colSpan>1){
int start=j+1,end=j+colSpan;
for(int num=start;num<end;num++){
Column nextCol=columns.get(num);
if(nextCol.getWidth()<1){
colSpan--;
}
}
if(colSpan<2){
colSpan=0;
}
cell.setColSpan(colSpan);
}
}
int rowHeight=row.getRealHeight();
int rowSpan=cell.getRowSpan();
if(rowHeight<1){
if(rowSpan>1){
rowSpan--;
if(rowSpan<2)rowSpan=0;
cell.setRowSpan(rowSpan);
Row nextRow=rows.get(i+1);
Map<Column,Cell> cmap=cellMap.get(nextRow);
cmap.put(col, cell);
}
}else{
if(rowSpan>1){
int start=i+1,end=i+rowSpan;
for(int num=start;num<end;num++){
Row nextRow=rows.get(num);
if(nextRow.getRealHeight()<1){
rowSpan--;
}
}
if(rowSpan<2){
rowSpan=0;
}
cell.setRowSpan(rowSpan);
}
}
}
if(row.getRealHeight()<1){
cellMap.remove(row);
}
public void setHideRowColumnBuilder(HideRowColumnBuilder hideRowColumnBuilder) {
this.hideRowColumnBuilder = hideRowColumnBuilder;
}
@Override

40
ureport2-core/src/main/java/com/bstek/ureport/build/paging/FitPagePagination.java

@ -56,8 +56,11 @@ public class FitPagePagination extends BasePagination implements Pagination {
int pageIndex=1;
while(row!=null){
int rowRealHeight=row.getRealHeight();
if(rowRealHeight==0){
continue;
}
Band band=row.getBand();
if(band!=null && rowRealHeight>0){
if(band!=null){
String rowKey=row.getRowKey();
int index=-1;
if(band.equals(Band.headerrepeat)){
@ -81,27 +84,26 @@ public class FitPagePagination extends BasePagination implements Pagination {
pageRepeatFooters.remove(index);
pageRepeatFooters.add(index,row);
}
continue;
}
if(rowRealHeight>1 && band==null){
rowHeight+=rowRealHeight;
pageRows.add(row);
boolean overflow=false;
if((i+1)<rows.size()){
Row nextRow=rows.get(i+1);
if((rowHeight+nextRow.getRealHeight()) > height){
overflow=true;
}
}
if(!overflow && row.isPageBreak()){
rowHeight+=rowRealHeight;
pageRows.add(row);
boolean overflow=false;
if((i+1)<rows.size()){
Row nextRow=rows.get(i+1);
if((rowHeight+nextRow.getRealHeight()) > height){
overflow=true;
}
if(overflow){
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
pageIndex++;
pages.add(newPage);
rowHeight=repeatHeaderRowHeight+repeatFooterRowHeight;
pageRows=new ArrayList<Row>();
}
}
if(!overflow && row.isPageBreak()){
overflow=true;
}
if(overflow){
Page newPage=buildPage(pageRows,pageRepeatHeaders,pageRepeatFooters,titleRows,pageIndex,report);
pageIndex++;
pages.add(newPage);
rowHeight=repeatHeaderRowHeight+repeatFooterRowHeight;
pageRows=new ArrayList<Row>();
}
i++;
if(i<rowSize){

7
ureport2-core/src/main/java/com/bstek/ureport/build/paging/FixRowsPagination.java

@ -50,8 +50,11 @@ public class FixRowsPagination extends BasePagination implements Pagination {
int pageIndex=1;
for(Row row:rows){
int height=row.getRealHeight();
if(height==0){
continue;
}
Band band=row.getBand();
if(band!=null && height>0){
if(band!=null){
String rowKey=row.getRowKey();
int index=-1;
if(band.equals(Band.headerrepeat)){
@ -78,8 +81,6 @@ public class FixRowsPagination extends BasePagination implements Pagination {
if(index==-1){
throw new ReportComputeException("Invalid row["+band+"] with key "+rowKey+".");
}
}
if(height<1 && row.getBand()!=null){
continue;
}
pageRows.add(row);

54
ureport2-core/src/main/java/com/bstek/ureport/export/word/low/WordProducer.java

@ -15,6 +15,60 @@
******************************************************************************/
package com.bstek.ureport.export.word.low;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.imageio.ImageIO;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.BreakType;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColumns;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageSz;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcBorders;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STPageOrientation;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;
import com.bstek.ureport.build.paging.Page;
import com.bstek.ureport.chart.ChartData;
import com.bstek.ureport.definition.Alignment;
import com.bstek.ureport.definition.Border;
import com.bstek.ureport.definition.BorderStyle;
import com.bstek.ureport.definition.CellStyle;
import com.bstek.ureport.definition.Orientation;
import com.bstek.ureport.definition.Paper;
import com.bstek.ureport.exception.ReportComputeException;
import com.bstek.ureport.export.Producer;
import com.bstek.ureport.export.word.DxaUtils;
import com.bstek.ureport.model.Cell;
import com.bstek.ureport.model.Column;
import com.bstek.ureport.model.Image;
import com.bstek.ureport.model.Report;
import com.bstek.ureport.model.Row;
import com.bstek.ureport.utils.ImageUtils;
import com.microsoft.schemas.office.word.CTBorder;
/**
* @author Jacky.gao

18
ureport2-core/src/main/java/com/bstek/ureport/expression/model/expr/JoinExpression.java

@ -18,8 +18,10 @@ package com.bstek.ureport.expression.model.expr;
import java.util.ArrayList;
import java.util.List;
import com.bstek.ureport.build.BindData;
import com.bstek.ureport.build.Context;
import com.bstek.ureport.expression.model.Operator;
import com.bstek.ureport.expression.model.data.BindDataListExpressionData;
import com.bstek.ureport.expression.model.data.ExpressionData;
import com.bstek.ureport.expression.model.data.ObjectExpressionData;
import com.bstek.ureport.expression.model.data.ObjectListExpressionData;
@ -54,6 +56,22 @@ public class JoinExpression extends BaseExpression {
}else if(data instanceof ObjectListExpressionData){
ObjectListExpressionData d=(ObjectListExpressionData)data;
obj=d.getData();
}else if(data instanceof BindDataListExpressionData){
BindDataListExpressionData dataList=(BindDataListExpressionData)data;
List<BindData> bindList=dataList.getData();
if(bindList.size()==1){
BindData bindData=bindList.get(0);
obj=bindData.getValue();
}else{
StringBuilder sb=new StringBuilder();
for(BindData bd:bindList){
if(sb.length()>0){
sb.append(",");
}
sb.append(bd.getValue());
}
obj=sb.toString();
}
}
if(obj==null){
obj="";

6
ureport2-core/src/main/java/com/bstek/ureport/model/Cell.java

@ -320,10 +320,16 @@ public class Cell implements ReportCell {
int rowHeight=item.getRowHeight();
if(rowHeight>-1){
row.setRealHeight(rowHeight);
if(rowHeight==0){
context.doHideProcessRow(row);
}
}
int colWidth=item.getColWidth();
if(colWidth>-1){
column.setWidth(colWidth);
if(colWidth==0){
context.doHideProcessColumn(column);
}
}
if(StringUtils.isNotBlank(item.getNewValue())){
this.data=item.getNewValue();

2
ureport2-core/src/main/java/com/bstek/ureport/utils/ElUtils.java

@ -81,7 +81,7 @@ public class ElUtils {
Collections.reverse(postfixStack);// 将后缀式栈反转
while (!postfixStack.isEmpty()) {
String currentValue = postfixStack.pop();
if (!isOperator(currentValue.charAt(0))) {// 如果不是运算符则存入操作数栈中
if (currentValue.equals("") || !isOperator(currentValue.charAt(0))) {// 如果不是运算符则存入操作数栈中
currentValue = currentValue.replace("~", "-");
resultStack.push(currentValue);
} else {// 如果是运算符则从操作数栈中取两个值和该数值一起参与运算

6
ureport2-core/src/main/resources/ureport-core-context.xml

@ -30,7 +30,11 @@
<property name="disabled" value="${ureport.disableFileProvider}"></property>
</bean>
<bean id="ureport.reportBuilder" class="com.bstek.ureport.build.ReportBuilder"></bean>
<bean id="ureport.reportBuilder" class="com.bstek.ureport.build.ReportBuilder">
<property name="hideRowColumnBuilder" ref="ureport.hideRowColumnBuilder"></property>
</bean>
<bean id="ureport.hideRowColumnBuilder" class="com.bstek.ureport.build.HideRowColumnBuilder"></bean>
<bean id="ureport.reportParser" class="com.bstek.ureport.parser.ReportParser"></bean>

載入中…
取消
儲存