📄 viewaction.java
字号:
if (resource == null) {
resource = new ResourceVO();
resource.setId(Sequence.getSequence());
resource.setSortId(Sequence.getTimeSequence());
resource.setApplicationid(getApplication());
}
ResourceVO sp = (ResourceVO) rp.doView(_superiorid);
resource.setSuperior(sp);
resource.setModule(view.getModule().getId());
resource.setApplication(view.getModule().getApplication().getId());
resource.setDisplayView(((View) getContent()).getId());
resource.setDescription(_resourcedesc);
resource.setType(ResourceType.RESOURCE_TYPE_MENU);
// resource.setIsprotected(ResourceType.ISPROTECTED_YES);
resource.setIsprotected(false);
resource.setResourceAction(ResourceType.ACTION_TYPE_VIEW);
resource.setDisplayView(view.getId());
view.setRelatedResourceid(resource.getId());
rp.doUpdate(resource);
} else {
if (resource != null) {
rp.doRemove(resource.getId());
}
}
proxy.doUpdate(view);
return SUCCESS;
}
public String get_resourcedesc() {
View view = (View) getContent();
String rid = view.getRelatedResourceid();
if (rid != null) {
try {
ResourceProcess rp = (ResourceProcess) ProcessFactory
.createProcess(ResourceProcess.class);
ResourceVO rvo = (ResourceVO) rp.doView(rid);
if (rvo != null) {
return rvo.getDescription();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public void set_resourcedesc(String _resourcedesc) {
this._resourcedesc = _resourcedesc;
}
public String get_isPagination() {
View content = (View) getContent();
if (content.isPagination()) {
return "true";
} else {
return "false";
}
}
public void set_isPagination(String _isPagination) {
View content = (View) getContent();
if (_isPagination != null) {
if (_isPagination.trim().equalsIgnoreCase("true")) {
content.setPagination(true);
return;
}
}
content.setPagination(false);
}
public String get_isShowTotalRow() {
View content = (View) getContent();
if (content.isShowTotalRow()) {
return "true";
} else {
return "false";
}
}
public void set_isShowTotalRow(String _isShowTotalRow) {
View content = (View) getContent();
if (_isShowTotalRow != null) {
if (_isShowTotalRow.trim().equalsIgnoreCase("true")) {
content.setShowTotalRow(true);
return;
}
}
content.setShowTotalRow(false);
}
public static Map get_OPENTYPE() {
return _OPENTYPE;
}
public String getTotalRowText() {
return totalRowText;
}
public void setTotalRowText(String totalRowText) {
this.totalRowText = totalRowText;
}
public String expDocToExcel() throws Exception {
DocumentProcess dp = (DocumentProcess) ProcessFactory
.createProcess(DocumentProcess.class);
String viewid = get_viewid();
View view = (View) proxy.doView(viewid);
if (view != null) {
setContent(view);
ParamsTable params = this.getParams(); // 获取并设置参数
WebUser user = this.getUser();
ArrayList errors = new ArrayList();
DataPackage datas = null;
JavaScriptRunner runner = JavaScriptRunner.getInstance();
if (view.getEditMode().equals(View.EDIT_MODE_DESIGN)) { // DESIGN
String cndt = view.getFilterCondition();
if (cndt != null && cndt.trim().length() > 0) {
String hql = new FilterExpression()
.parseToHql(cndt, params);
System.out.println(hql);
datas = dp.queryByHQL(hql, getApplication());
}
} else if (view.getEditMode().equals(View.EDIT_MODE_CODE)) { // CODE
String js = view.getFilterScript();
if (js != null && js.trim().length() > 0) {
Document currdoc = null;
if (view.getSearchForm() != null) {
currdoc = view.getSearchForm().createDocument(params,
user);
} else {
currdoc = new Document();
}
runner.initBSFManager(currdoc, params, user, errors,
getApplication());
Object result = runner.run(js);
if (result != null && result instanceof String) {
String dql = (String) result;
datas = dp.queryByDQL(dql, getParams(),
getApplication());
}
}
}
Collection excelData = new HashSet();
Collection heads = new HashSet();
if (datas != null && datas.datas != null && datas.datas.size() > 0) {
Collection columns = view.getColumns();
for (Iterator iter = columns.iterator(); iter.hasNext();) {
Column col = (Column) iter.next();
heads.add(col.getName());
}
for (Iterator iter = datas.datas.iterator(); iter.hasNext();) {
Document doc = (Document) iter.next();
runner.initBSFManager(doc, params, user, errors, user
.getApplicationid());
Object result = null;
Map line = new HashMap();
for (Iterator iterator = columns.iterator(); iterator
.hasNext();) {
Column col = (Column) iterator.next();
if (col.getType() != null
&& col.getType().equals(
Column.COLUMN_TYPE_SCRIPT))
result = runner.run(col.getValueScript());
else if (col.getType() != null
&& col.getType().equals(
Column.COLUMN_TYPE_FIELD)) {
Item item = doc.findItem(col.getFieldName());
if (item != null
&& (item.getType().equals(
Item.VALUE_TYPE_VARCHAR) || item
.getType().equals(
Item.VALUE_TYPE_TEXT)))
result = item.getVarcharvalue();
else if (item != null
&& item.getType().equals(
Item.VALUE_TYPE_NUMBER))
result = item.getNumbervalue();
else if (item != null
&& item.getType().equals(
Item.VALUE_TYPE_DATE))
result = item.getDatevalue();
else
result = "";
}
line.put(col.getName(), result);
}
excelData.add(line);
System.out.println("line..........");
}
}
if (excelData != null && excelData.size() > 0) {
String path = DefaultProperty.getProperty("REPORT_PATH");
String savePath = ServletActionContext.getRequest()
.getRealPath("").replaceAll("\\\\", "/")
+ path;
String flieName = Sequence.getSequence() + ".xls";
savePath += flieName;
creatExcelFile(heads, excelData, savePath);
String context = ServletActionContext.getRequest()
.getContextPath();
String excelWebPath = context + path + flieName;
ServletActionContext.getRequest().setAttribute("excelWebPath",
excelWebPath);
}
}
return SUCCESS;
}
public void creatExcelFile(Collection heads, Collection datas,
String outputFile) throws IOException {
// 创建新的Excel 工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
if (heads != null && datas != null && datas.size() > 0) {
HSSFSheet sheet = workbook.createSheet();
HSSFRow headrow = sheet.createRow((short) 0);
int i = 0;
for (Iterator iter = heads.iterator(); iter.hasNext();) {
String head = (String) iter.next();
HSSFCell cell = headrow.createCell((short) i);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(head);
i++;
}
int j = 1;
for (Iterator iter = datas.iterator(); iter.hasNext();) {
Map map = (Map) iter.next();
HSSFRow row = sheet.createRow((short) j);
int k = 0;
for (Iterator iterator = heads.iterator(); iterator.hasNext();) {
String columnName = (String) iterator.next();
Object result = (Object) map.get(columnName);
HSSFCell cell = row.createCell((short) k);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
if (result instanceof String) {
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue((String) result);
} else if (result instanceof Double) {
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(((Double) result).doubleValue());
} else if (result instanceof Date) {
cell.setCellStyle(cellStyle);
cell.setCellValue((Date) result);
}
k++;
}
j++;
}
}
// 新建一输出文件流
FileOutputStream fOut = new FileOutputStream(outputFile);
// 把相应的Excel 工作簿存盘
workbook.write(fOut);
fOut.flush();
// 操作结束,关闭文件
fOut.close();
System.out.println("Excel文件生成.................");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -