提交 a9e9b0ad 编写于 作者: L luojing

人员组织导入及获取导入结果附件-缓存去除,改为存取到通用附件

上级 7ac308b9
package com.x.base.core.project; package com.x.base.core.project;
import com.x.base.core.entity.StorageType;
import com.x.base.core.project.annotation.Module; import com.x.base.core.project.annotation.Module;
import com.x.base.core.project.annotation.ModuleCategory; import com.x.base.core.project.annotation.ModuleCategory;
import com.x.base.core.project.annotation.ModuleType; import com.x.base.core.project.annotation.ModuleType;
...@@ -10,6 +11,6 @@ import com.x.base.core.project.annotation.ModuleType; ...@@ -10,6 +11,6 @@ import com.x.base.core.project.annotation.ModuleType;
"com.x.organization.core.entity.Identity", "com.x.organization.core.entity.PersonAttribute", "com.x.organization.core.entity.Identity", "com.x.organization.core.entity.PersonAttribute",
"com.x.organization.core.entity.Unit", "com.x.organization.core.entity.UnitAttribute", "com.x.organization.core.entity.Unit", "com.x.organization.core.entity.UnitAttribute",
"com.x.organization.core.entity.PersonCard","com.x.organization.core.entity.PermissionSetting", "com.x.organization.core.entity.PersonCard","com.x.organization.core.entity.PermissionSetting",
"com.x.organization.core.entity.UnitDuty" }, storeJars = { "x_organization_core_entity" }) "com.x.organization.core.entity.UnitDuty", "com.x.general.core.entity.file.GeneralFile" },storageTypes = { StorageType.general}, storeJars = { "x_organization_core_entity" ,"x_general_core_entity"})
public class x_organization_assemble_control extends Deployable { public class x_organization_assemble_control extends Deployable {
} }
package com.x.organization.assemble.control.jaxrs.inputperson; package com.x.organization.assemble.control.jaxrs.inputperson;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile; import com.x.base.core.project.jaxrs.WoFile;
...@@ -7,6 +11,9 @@ import com.x.base.core.project.logger.Logger; ...@@ -7,6 +11,9 @@ import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory; import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.cache.Cache.CacheKey; import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager; import com.x.base.core.project.cache.CacheManager;
import com.x.general.core.entity.file.GeneralFile;
import com.x.organization.assemble.control.ThisApplication;
import org.apache.commons.lang3.StringUtils;
import java.util.Optional; import java.util.Optional;
...@@ -17,13 +24,28 @@ public class ActionGetResult extends BaseAction { ...@@ -17,13 +24,28 @@ public class ActionGetResult extends BaseAction {
protected ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception { protected ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
logger.debug(effectivePerson, "flag:{}.", flag); logger.debug(effectivePerson, "flag:{}.", flag);
ActionResult<Wo> result = new ActionResult<>(); ActionResult<Wo> result = new ActionResult<>();
CacheKey cacheKey = new CacheKey(flag); Wo wo = null;
Optional<?> optional = CacheManager.get(this.cache, cacheKey); try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
if (!optional.isPresent()) { GeneralFile generalFile = emc.find(flag, GeneralFile.class);
throw new ExceptionResultNotFound(flag); if(generalFile!=null){
if (!StringUtils.equals(effectivePerson.getDistinguishedName(), generalFile.getPerson())) {
throw new ExceptionAccessDenied(effectivePerson);
}
StorageMapping gfMapping = ThisApplication.context().storageMappings().get(GeneralFile.class,
generalFile.getStorage());
wo = new Wo(generalFile.readContent(gfMapping), this.contentType(true, generalFile.getName()),
this.contentDisposition(true, generalFile.getName()));
result.setData(wo);
generalFile.deleteContent(gfMapping);
emc.beginTransaction(GeneralFile.class);
emc.delete(GeneralFile.class, generalFile.getId());
emc.commit();
} else {
throw new ExceptionInputResultObject(flag);
}
} }
CacheInputResult o = (CacheInputResult) optional.get();
Wo wo = new Wo(o.getBytes(), this.contentType(true, o.getName()), this.contentDisposition(true, o.getName()));
result.setData(wo); result.setData(wo);
return result; return result;
} }
......
...@@ -22,7 +22,10 @@ import javax.script.Bindings; ...@@ -22,7 +22,10 @@ import javax.script.Bindings;
import javax.script.ScriptContext; import javax.script.ScriptContext;
import javax.script.SimpleScriptContext; import javax.script.SimpleScriptContext;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.cache.CacheManager; import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.StorageMapping;
import com.x.general.core.entity.file.GeneralFile;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils; import org.apache.commons.text.StringEscapeUtils;
...@@ -97,12 +100,7 @@ class ActionInputAll extends BaseAction { ...@@ -97,12 +100,7 @@ class ActionInputAll extends BaseAction {
this.scanUnit(business, workbook); this.scanUnit(business, workbook);
String name = "person_input_" + DateTools.formatDate(new Date()) + ".xlsx"; String name = "person_input_" + DateTools.formatDate(new Date()) + ".xlsx";
workbook.write(os); workbook.write(os);
CacheInputResult cacheInputResult = new CacheInputResult(); String flag = saveAttachment(os.toByteArray(),name,effectivePerson);
cacheInputResult.setName(name);
cacheInputResult.setBytes(os.toByteArray());
String flag = StringTools.uniqueToken();
CacheKey cacheKey = new CacheKey(flag);
CacheManager.put(this.cache, cacheKey, cacheInputResult);
CacheManager.notify(Person.class); CacheManager.notify(Person.class);
CacheManager.notify(Group.class); CacheManager.notify(Group.class);
CacheManager.notify(Role.class); CacheManager.notify(Role.class);
...@@ -1228,6 +1226,18 @@ class ActionInputAll extends BaseAction { ...@@ -1228,6 +1226,18 @@ class ActionInputAll extends BaseAction {
o.setPassword(Crypto.encrypt(o.getPassword(), Config.token().getKey())); o.setPassword(Crypto.encrypt(o.getPassword(), Config.token().getKey()));
} }
} }
private String saveAttachment(byte[] bytes,String attachmentName,EffectivePerson effectivePerson) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
StorageMapping gfMapping = ThisApplication.context().storageMappings().random(GeneralFile.class);
GeneralFile generalFile = new GeneralFile(gfMapping.getName(), attachmentName, effectivePerson.getDistinguishedName());
generalFile.saveContent(gfMapping, bytes, attachmentName);
emc.beginTransaction(GeneralFile.class);
emc.persist(generalFile, CheckPersistType.all);
emc.commit();
return generalFile.getId();
}
}
public static class Wo extends GsonPropertyObject { public static class Wo extends GsonPropertyObject {
......
package com.x.organization.assemble.control.jaxrs.inputperson;
import com.x.base.core.project.exception.PromptException;
public class ExceptionInputResultObject extends PromptException {
private static final long serialVersionUID = 9085364457175859374L;
ExceptionInputResultObject(String flag) {
super("对象不存在:{}.", flag);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册