Browse Source

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

luojing 5 years ago
parent
commit
a9e9b0ad9e

+ 2 - 1
o2server/x_base_core_project/src/main/java/com/x/base/core/project/x_organization_assemble_control.java

@@ -1,5 +1,6 @@
 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.ModuleCategory;
 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.Unit", "com.x.organization.core.entity.UnitAttribute",
 		"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 {
 }

+ 28 - 6
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/ActionGetResult.java

@@ -1,5 +1,9 @@
 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.EffectivePerson;
 import com.x.base.core.project.jaxrs.WoFile;
@@ -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.cache.Cache.CacheKey;
 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;
 
@@ -17,13 +24,28 @@ public class ActionGetResult extends BaseAction {
 	protected ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
 		logger.debug(effectivePerson, "flag:{}.", flag);
 		ActionResult<Wo> result = new ActionResult<>();
-		CacheKey cacheKey = new CacheKey(flag);
-		Optional<?> optional = CacheManager.get(this.cache, cacheKey);
-		if (!optional.isPresent()) {
-			throw new ExceptionResultNotFound(flag);
+		Wo wo = null;
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			GeneralFile generalFile = emc.find(flag, GeneralFile.class);
+			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);
 		return result;
 	}

+ 16 - 6
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/ActionInputAll.java

@@ -22,7 +22,10 @@ import javax.script.Bindings;
 import javax.script.ScriptContext;
 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.config.StorageMapping;
+import com.x.general.core.entity.file.GeneralFile;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.StringEscapeUtils;
@@ -97,12 +100,7 @@ class ActionInputAll extends BaseAction {
 			this.scanUnit(business, workbook);
 			String name = "person_input_" + DateTools.formatDate(new Date()) + ".xlsx";
 			workbook.write(os);
-			CacheInputResult cacheInputResult = new CacheInputResult();
-			cacheInputResult.setName(name);
-			cacheInputResult.setBytes(os.toByteArray());
-			String flag = StringTools.uniqueToken();
-			CacheKey cacheKey = new CacheKey(flag);
-			CacheManager.put(this.cache, cacheKey, cacheInputResult);
+			String flag = saveAttachment(os.toByteArray(),name,effectivePerson);
 			CacheManager.notify(Person.class);
 			CacheManager.notify(Group.class);
 			CacheManager.notify(Role.class);
@@ -1228,6 +1226,18 @@ class ActionInputAll extends BaseAction {
 			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 {
 

+ 13 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/ExceptionInputResultObject.java

@@ -0,0 +1,13 @@
+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);
+    }
+
+}