You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.0 KiB
89 lines
3.0 KiB
3 years ago
|
package com.tptj.demo.hg.comment.excel.processor;
|
||
|
|
||
|
import com.fr.form.data.WidgetDataOutput;
|
||
|
import com.fr.form.data.WidgetOutletFactory;
|
||
|
import com.fr.form.ui.DictContainedCustomWriteAbleEditor;
|
||
|
import com.fr.general.ComparatorUtils;
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.report.cell.ResultCellElement;
|
||
|
import com.fr.report.worksheet.CalculatableResWorkSheet;
|
||
|
import com.fr.stable.script.CalculatorProvider;
|
||
|
import com.fr.third.springframework.web.context.request.RequestContextHolder;
|
||
|
import com.fr.third.springframework.web.context.request.ServletRequestAttributes;
|
||
|
import com.fr.third.v2.org.apache.poi.ss.util.CellRangeAddressList;
|
||
|
import com.fr.web.core.SessionPoolManager;
|
||
|
import com.fr.web.core.WidgetSessionIDInfor;
|
||
|
import com.fr.web.utils.WebUtils;
|
||
|
|
||
|
/**
|
||
|
* @author 秃破天际
|
||
|
* @version 10.0
|
||
|
* Created by 秃破天际 on 2021-04-13
|
||
|
**/
|
||
|
public class ExcelDictionary {
|
||
|
|
||
|
private CalculatableResWorkSheet sheet;
|
||
|
|
||
|
private DictContainedCustomWriteAbleEditor wgt;
|
||
|
|
||
|
private CellRangeAddressList cells;
|
||
|
|
||
|
private String[] data = new String[0];
|
||
|
|
||
|
public ExcelDictionary( CalculatableResWorkSheet sheet, DictContainedCustomWriteAbleEditor wgt ){
|
||
|
this.sheet = sheet;
|
||
|
this.wgt = wgt;
|
||
|
cells = new CellRangeAddressList();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断目标数据字典与缓存数据字典是否是同一个,是的话就会进行区域的合并
|
||
|
* @param dic
|
||
|
* @return
|
||
|
*/
|
||
|
public boolean isSameDic( ExcelDictionary dic ){
|
||
|
return ComparatorUtils.equals( dic.getWgt().getDictionary(), wgt.getDictionary() );
|
||
|
}
|
||
|
|
||
|
public DictContainedCustomWriteAbleEditor getWgt() {
|
||
|
return wgt;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 同一个数据字典可以对多个单元格生效,通过该方法进行区域的指定。
|
||
|
* @param cell
|
||
|
*/
|
||
|
public void addCells( ResultCellElement cell ){
|
||
|
int row = cell.getRow();
|
||
|
int col = cell.getColumn();
|
||
|
int rspan = cell.getRowSpan();
|
||
|
int cspan = cell.getColumnSpan();
|
||
|
cells.addCellRangeAddress( row, col, row + rspan -1, col + cspan -1 );
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 生成字典数据
|
||
|
* @throws Exception
|
||
|
*/
|
||
|
public void build()throws Exception{
|
||
|
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||
|
WidgetDataOutput widgetDataOutlet = WidgetOutletFactory.createWidgetDataOutlet(attrs.getRequest(), wgt);
|
||
|
String sessionId = WebUtils.getHTTPRequestParameter(attrs.getRequest(),"sessionID");
|
||
|
WidgetSessionIDInfor info = SessionPoolManager.getSessionIDInfor(sessionId, WidgetSessionIDInfor.class);
|
||
|
CalculatorProvider calculator = sheet.getCalculator();
|
||
|
JSONArray jsonData = widgetDataOutlet.createJSONData(info, calculator, attrs.getRequest(), wgt);
|
||
|
data = new String[jsonData.size()];
|
||
|
for( int i=0;i<data.length;i++ ){
|
||
|
data[i] = jsonData.optJSONObject(i).optString("text");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public String[] getData() {
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
public CellRangeAddressList getCells() {
|
||
|
return cells;
|
||
|
}
|
||
|
}
|