Просмотр исходного кода

BUG修复:在前端的信息内容发布接口里新增流程附件同步功能

o2lee 5 лет назад
Родитель
Сommit
8ed2590f4f

+ 2 - 1
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishByWorkFlow.java

@@ -278,11 +278,12 @@ public class ActionPersistPublishByWorkFlow extends BaseAction {
 				throw exception;
 			}
 		}
+
 		if (check) {
 			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 				logService.log(emc, wi.getCreatorIdentity(),
 						document.getCategoryAlias() + ":" + document.getTitle(), document.getAppId(),
-						document.getCategoryId(), document.getId(), "", "DOCUMENT", "发布");
+						document.getCategoryId(), document.getId(), "", "DOCUMENT", "发布" );
 			} catch (Throwable th) {
 				th.printStackTrace();
 				result.error(th);

+ 86 - 4
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishContent.java

@@ -1,12 +1,16 @@
 package com.x.cms.assemble.control.jaxrs.document;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.*;
 
 import javax.servlet.http.HttpServletRequest;
 
+import com.x.base.core.entity.annotation.CheckPersistType;
+import com.x.base.core.project.config.StorageMapping;
+import com.x.base.core.project.exception.ExceptionWhen;
+import com.x.processplatform.core.entity.content.Attachment;
+import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import com.google.gson.JsonElement;
@@ -228,6 +232,50 @@ public class ActionPersistPublishContent extends BaseAction {
 			}
 		}
 
+		//从流程管理中复制所有的附件到CMS
+		if (check) {
+			if ( wi.getWf_attachmentIds() != null && wi.getWf_attachmentIds().length > 0 ) {
+				FileInfo fileInfo = null;
+				Attachment attachment = null;
+				StorageMapping mapping_attachment = null;
+				StorageMapping mapping_fileInfo = null;
+				InputStream input = null;
+				byte[] attachment_content = null;
+				for (String attachmentId : wi.getWf_attachmentIds()) {
+					try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+						document = emc.find(document.getId(), Document.class, ExceptionWhen.not_found);
+						attachment = emc.find(attachmentId, Attachment.class, ExceptionWhen.not_found);
+						if (attachment != null) {
+							emc.beginTransaction(FileInfo.class);
+							emc.beginTransaction(Document.class);
+
+							mapping_attachment = ThisApplication.context().storageMappings().get(Attachment.class, attachment.getStorage());
+							attachment_content = attachment.readContent(mapping_attachment);
+
+							mapping_fileInfo = ThisApplication.context().storageMappings().random(FileInfo.class);
+							fileInfo = concreteFileInfo(effectivePerson.getDistinguishedName(), document, mapping_fileInfo, attachment.getName(), attachment.getSite());
+							input = new ByteArrayInputStream(attachment_content);
+							fileInfo.saveContent(mapping_fileInfo, input, attachment.getName());
+							fileInfo.setName(attachment.getName());
+							emc.check(document, CheckPersistType.all);
+							emc.persist(fileInfo, CheckPersistType.all);
+
+							emc.commit();
+						}
+					} catch (Throwable th) {
+						th.printStackTrace();
+						result.error(th);
+					} finally {
+						if (input != null) {
+							input.close();
+						}
+					}
+				}
+				ApplicationCache.notify(FileInfo.class);
+				ApplicationCache.notify(Document.class);
+			}
+		}
+
 		if (check) {
 			try {				
 				Wo wo = new Wo();
@@ -240,6 +288,7 @@ public class ActionPersistPublishContent extends BaseAction {
 				throw exception;
 			}
 		}
+
 		if (check) {
 			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 				logService.log(emc, wi.getCreatorIdentity(),
@@ -363,6 +412,39 @@ public class ActionPersistPublishContent extends BaseAction {
 		return result;
 	}
 
+	private FileInfo concreteFileInfo(String person, Document document, StorageMapping storage, String name, String site) throws Exception {
+		String fileName = UUID.randomUUID().toString();
+		String extension = FilenameUtils.getExtension(name);
+		FileInfo attachment = new FileInfo();
+		if (StringUtils.isEmpty(extension)) {
+			throw new Exception("file extension is empty.");
+		} else {
+			fileName = fileName + "." + extension;
+		}
+		if (name.indexOf("\\") > 0) {
+			name = StringUtils.substringAfterLast(name, "\\");
+		}
+		if (name.indexOf("/") > 0) {
+			name = StringUtils.substringAfterLast(name, "/");
+		}
+		attachment.setCreateTime(new Date());
+		attachment.setLastUpdateTime(new Date());
+		attachment.setExtension(extension);
+		attachment.setName(name);
+		attachment.setFileName(fileName);
+		attachment.setStorage(storage.getName());
+		attachment.setAppId(document.getAppId());
+		attachment.setCategoryId(document.getCategoryId());
+		attachment.setDocumentId(document.getId());
+		attachment.setCreatorUid(person);
+		attachment.setSite(site);
+		attachment.setFileHost("");
+		attachment.setFilePath("");
+		attachment.setFileType("ATTACHMENT");
+
+		return attachment;
+	}
+
 	public static class Wi {
 		
 		public static WrapCopier<Wi, Document> copier = WrapCopierFactory.wi( Wi.class, Document.class, null, null);

+ 8 - 1
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/BaseAction.java

@@ -3,11 +3,13 @@ package com.x.cms.assemble.control.jaxrs.document;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.UUID;
 
 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.cache.ApplicationCache;
+import com.x.base.core.project.config.StorageMapping;
 import com.x.base.core.project.jaxrs.StandardJaxrsAction;
 import com.x.base.core.project.tools.ListTools;
 import com.x.cms.assemble.control.Business;
@@ -29,7 +31,10 @@ import com.x.cms.core.entity.AppInfo;
 import com.x.cms.core.entity.CategoryInfo;
 import com.x.cms.core.entity.Document;
 
+import com.x.cms.core.entity.FileInfo;
 import net.sf.ehcache.Ehcache;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.StringUtils;
 
 public class BaseAction extends StandardJaxrsAction {
 	protected Ehcache cache = ApplicationCache.instance().getCache( Document.class);
@@ -215,7 +220,9 @@ public class BaseAction extends StandardJaxrsAction {
 		}		
 		return false;
 	}
-	
+
+
+
 //	/**
 //	 * 将权限组,组织为一个整体集合
 //	 * @param personName