提交 08a4301f 编写于 作者: O o2sword

视图excel导出支持集群,导出可以设置指定名称

上级 5bb897c8
......@@ -20,9 +20,10 @@ import com.x.base.core.project.annotation.ModuleType;
"com.x.processplatform.core.entity.content.Attachment", "com.x.cms.core.entity.Document",
"com.x.cms.core.entity.Review", "com.x.cms.core.entity.AppInfo", "com.x.cms.core.entity.CategoryInfo",
"com.x.organization.core.entity.Person", "com.x.organization.core.entity.Unit", "com.x.organization.core.entity.Group",
"com.x.query.dynamic.entity.*" }, storageTypes = { StorageType.processPlatform, StorageType.cms }, storeJars = {
"x_query_core_entity", "x_organization_core_entity", "x_organization_core_express",
"x_processplatform_core_entity", "x_cms_core_entity",
"x_query_core_express" }, dynamicJars = { "x_query_dynamic_entity" })
"com.x.query.dynamic.entity.*", "com.x.general.core.entity.GeneralFile"},
storageTypes = { StorageType.processPlatform, StorageType.cms, StorageType.general}, storeJars = {
"x_query_core_entity", "x_organization_core_entity", "x_organization_core_express",
"x_processplatform_core_entity", "x_cms_core_entity",
"x_query_core_express", "x_general_core_entity" }, dynamicJars = { "x_query_dynamic_entity" })
public class x_query_assemble_surface extends Deployable {
}
......@@ -32,6 +32,7 @@ class ActionExcel extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
View view;
Runtime runtime;
Business business;
......@@ -51,13 +52,12 @@ class ActionExcel extends BaseAction {
if (!business.readable(effectivePerson, view)) {
throw new ExceptionAccessDenied(effectivePerson, view);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
runtime = this.runtime(effectivePerson, business, view, wi.getFilterList(), wi.getParameter(),
wi.getCount(), false);
runtime.bundleList = wi.getBundleList();
}
Plan plan = this.accessPlan(business, view, runtime);
String excelFlag = this.girdWriteToExcel(effectivePerson, business, plan, view);
String excelFlag = this.girdWriteToExcel(effectivePerson, business, plan, view, wi.getExcelName());
Wo wo = new Wo();
wo.setId(excelFlag);
result.setData(wo);
......@@ -79,6 +79,9 @@ class ActionExcel extends BaseAction {
@FieldDescribe("数量")
private Integer count = 0;
@FieldDescribe("excel导出名称,默认为视图名称")
private String excelName;
@FieldDescribe("限定结果集")
public List<String> bundleList = new TreeList<>();
......@@ -113,6 +116,14 @@ class ActionExcel extends BaseAction {
public void setBundleList(List<String> bundleList) {
this.bundleList = bundleList;
}
public String getExcelName() {
return excelName;
}
public void setExcelName(String excelName) {
this.excelName = excelName;
}
}
}
package com.x.query.assemble.surface.jaxrs.view;
import com.x.base.core.project.config.StorageMapping;
import com.x.general.core.entity.GeneralFile;
import com.x.query.assemble.surface.ThisApplication;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
......@@ -23,16 +26,12 @@ class ActionExcelResult extends BaseAction {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
logger.info("{}", flag);
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(flag);
Optional<?> optional = CacheManager.get(business.cache(), cacheKey);
if (optional.isPresent()) {
ExcelResultObject obj = (ExcelResultObject) optional.get();
if (!StringUtils.equals(effectivePerson.getDistinguishedName(), obj.getPerson())) {
throw new ExceptionAccessDenied(effectivePerson);
}
Wo wo = new Wo(obj.getBytes(), this.contentType(true, obj.getName()),
this.contentDisposition(true, obj.getName()));
GeneralFile generalFile = emc.find(flag, GeneralFile.class);
if(generalFile!=null){
StorageMapping gfMapping = ThisApplication.context().storageMappings().get(GeneralFile.class,
generalFile.getStorage());
Wo wo = new Wo(generalFile.readContent(gfMapping), this.contentType(true, generalFile.getName()),
this.contentDisposition(true, generalFile.getName()));
result.setData(wo);
} else {
throw new ExceptionExcelResultObject(flag);
......@@ -49,4 +48,4 @@ class ActionExcelResult extends BaseAction {
}
}
\ No newline at end of file
}
......@@ -29,6 +29,7 @@ class ActionExcelWithQuery extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String queryFlag, JsonElement jsonElement)
throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
View view;
Runtime runtime;
Business business;
......@@ -49,13 +50,12 @@ class ActionExcelWithQuery extends BaseAction {
if (!business.readable(effectivePerson, view)) {
throw new ExceptionAccessDenied(effectivePerson, view);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
runtime = this.runtime(effectivePerson, business, view, wi.getFilterList(), wi.getParameter(),
wi.getCount(), false);
runtime.bundleList = wi.getBundleList();
}
Plan plan = this.accessPlan(business, view, runtime);
String excelFlag = this.girdWriteToExcel(effectivePerson, business, plan, view);
String excelFlag = this.girdWriteToExcel(effectivePerson, business, plan, view, wi.getExcelName());
Wo wo = new Wo();
wo.setId(excelFlag);
result.setData(wo);
......@@ -79,6 +79,9 @@ class ActionExcelWithQuery extends BaseAction {
@FieldDescribe("数量")
private Integer count = 0;
@FieldDescribe("excel导出名称,默认为视图名称")
private String excelName;
@FieldDescribe("限定结果集")
public List<String> bundleList = new TreeList<>();
......@@ -114,6 +117,13 @@ class ActionExcelWithQuery extends BaseAction {
this.bundleList = bundleList;
}
public String getExcelName() {
return excelName;
}
public void setExcelName(String excelName) {
this.excelName = excelName;
}
}
}
......@@ -11,7 +11,11 @@ import java.util.Objects;
import com.google.gson.reflect.TypeToken;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.config.StorageMapping;
import com.x.general.core.entity.GeneralFile;
import com.x.processplatform.core.entity.element.Process;
import com.x.query.assemble.surface.ThisApplication;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
......@@ -166,7 +170,7 @@ abstract class BaseAction extends StandardJaxrsAction {
}
protected String girdWriteToExcel(EffectivePerson effectivePerson, Business business, Plan plan, View view)
protected String girdWriteToExcel(EffectivePerson effectivePerson, Business business, Plan plan, View view, String excelName)
throws Exception {
try (XSSFWorkbook workbook = new XSSFWorkbook(); ByteArrayOutputStream os = new ByteArrayOutputStream()) {
XSSFSheet sheet = workbook.createSheet("grid");
......@@ -197,16 +201,23 @@ abstract class BaseAction extends StandardJaxrsAction {
}
}
}
String name = view.getName() + ".xlsx";
if(StringUtils.isEmpty(excelName)) {
excelName = view.getName() + ".xlsx";
}
if(!excelName.toLowerCase().endsWith(".xlsx")){
excelName = excelName + ".xlsx";
}
workbook.write(os);
ExcelResultObject obj = new ExcelResultObject();
obj.setBytes(os.toByteArray());
obj.setName(name);
obj.setPerson(effectivePerson.getDistinguishedName());
String flag = StringTools.uniqueToken();
CacheKey cacheKey = new CacheKey(flag);
CacheManager.put(business.cache(), cacheKey, obj);
return flag;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
StorageMapping gfMapping = ThisApplication.context().storageMappings().random(GeneralFile.class);
GeneralFile generalFile = new GeneralFile(gfMapping.getName(), excelName, effectivePerson.getDistinguishedName());
generalFile.saveContent(gfMapping, os.toByteArray(), excelName);
emc.beginTransaction(GeneralFile.class);
emc.persist(generalFile, CheckPersistType.all);
emc.commit();
String key = generalFile.getId();
return key;
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册