Explorar el Código

修复云文件更改上级目录异常问题

o2sword hace 5 años
padre
commit
d945198152

+ 13 - 0
o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/attachment2/ActionDownload.java

@@ -8,6 +8,8 @@ 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.StandardJaxrsAction;
 import com.x.base.core.project.jaxrs.StandardJaxrsAction;
 import com.x.base.core.project.jaxrs.WoFile;
 import com.x.base.core.project.jaxrs.WoFile;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
 import com.x.file.assemble.control.ThisApplication;
 import com.x.file.assemble.control.ThisApplication;
 import com.x.file.core.entity.open.OriginFile;
 import com.x.file.core.entity.open.OriginFile;
 import com.x.file.core.entity.personal.Attachment2;
 import com.x.file.core.entity.personal.Attachment2;
@@ -15,10 +17,13 @@ import net.sf.ehcache.Ehcache;
 import net.sf.ehcache.Element;
 import net.sf.ehcache.Element;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 
 
+import javax.persistence.EntityManager;
 import java.io.ByteArrayOutputStream;
 import java.io.ByteArrayOutputStream;
 
 
 class ActionDownload extends StandardJaxrsAction {
 class ActionDownload extends StandardJaxrsAction {
 
 
+	private static Logger logger = LoggerFactory.getLogger( ActionDownload.class );
+
 	private Ehcache cache = ApplicationCache.instance().getCache(Attachment2.class);
 	private Ehcache cache = ApplicationCache.instance().getCache(Attachment2.class);
 
 
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
@@ -58,6 +63,14 @@ class ActionDownload extends StandardJaxrsAction {
 					if (bs.length < (1024 * 1024 * 10)) {
 					if (bs.length < (1024 * 1024 * 10)) {
 						cache.put(new Element(cacheKey, wo));
 						cache.put(new Element(cacheKey, wo));
 					}
 					}
+				}catch (Exception e){
+					if(e.getMessage().indexOf("existed") > -1){
+						logger.warn("原始附件{}-{}不存在,删除记录!", originFile.getId(), originFile.getName());
+						emc.beginTransaction(OriginFile.class);
+						emc.delete(OriginFile.class, originFile.getId());
+						emc.commit();
+					}
+					throw e;
 				}
 				}
 			}
 			}
 			result.setData(wo);
 			result.setData(wo);

+ 12 - 0
o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/attachment2/ActionDownloadImageWidthHeight.java

@@ -8,6 +8,8 @@ import com.x.base.core.project.exception.ExceptionWhen;
 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;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
 import com.x.file.assemble.control.ThisApplication;
 import com.x.file.assemble.control.ThisApplication;
 import com.x.file.core.entity.open.OriginFile;
 import com.x.file.core.entity.open.OriginFile;
 import com.x.file.core.entity.personal.Attachment2;
 import com.x.file.core.entity.personal.Attachment2;
@@ -24,6 +26,8 @@ import java.io.ByteArrayInputStream;
 
 
 class ActionDownloadImageWidthHeight extends BaseAction {
 class ActionDownloadImageWidthHeight extends BaseAction {
 
 
+	private static Logger logger = LoggerFactory.getLogger( ActionDownloadImageWidthHeight.class );
+
 	private Ehcache cache = ApplicationCache.instance().getCache(ActionDownloadImageWidthHeight.class);
 	private Ehcache cache = ApplicationCache.instance().getCache(ActionDownloadImageWidthHeight.class);
 
 
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, Integer width, Integer height)
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, Integer width, Integer height)
@@ -81,6 +85,14 @@ class ActionDownloadImageWidthHeight extends BaseAction {
 							result.setData(wo);
 							result.setData(wo);
 						}
 						}
 					}
 					}
+				}catch (Exception e){
+					if(e.getMessage().indexOf("existed") > -1){
+						logger.warn("原始附件{}-{}不存在,删除记录!", originFile.getId(), originFile.getName());
+						emc.beginTransaction(OriginFile.class);
+						emc.delete(OriginFile.class, originFile.getId());
+						emc.commit();
+					}
+					throw e;
 				}
 				}
 			}
 			}
 
 

+ 12 - 0
o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/attachment2/ActionDownloadStream.java

@@ -8,6 +8,8 @@ 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.StandardJaxrsAction;
 import com.x.base.core.project.jaxrs.StandardJaxrsAction;
 import com.x.base.core.project.jaxrs.WoFile;
 import com.x.base.core.project.jaxrs.WoFile;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
 import com.x.file.assemble.control.ThisApplication;
 import com.x.file.assemble.control.ThisApplication;
 import com.x.file.core.entity.open.OriginFile;
 import com.x.file.core.entity.open.OriginFile;
 import com.x.file.core.entity.personal.Attachment2;
 import com.x.file.core.entity.personal.Attachment2;
@@ -19,6 +21,8 @@ import java.io.ByteArrayOutputStream;
 
 
 class ActionDownloadStream extends StandardJaxrsAction {
 class ActionDownloadStream extends StandardJaxrsAction {
 
 
+	private static Logger logger = LoggerFactory.getLogger( ActionDownloadStream.class );
+
 	private Ehcache cache = ApplicationCache.instance().getCache(Attachment2.class);
 	private Ehcache cache = ApplicationCache.instance().getCache(Attachment2.class);
 
 
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
@@ -58,6 +62,14 @@ class ActionDownloadStream extends StandardJaxrsAction {
 					if (bs.length < (1024 * 1024 * 10)) {
 					if (bs.length < (1024 * 1024 * 10)) {
 						cache.put(new Element(cacheKey, wo));
 						cache.put(new Element(cacheKey, wo));
 					}
 					}
+				}catch (Exception e){
+					if(e.getMessage().indexOf("existed") > -1){
+						logger.warn("原始附件{}-{}不存在,删除记录!", originFile.getId(), originFile.getName());
+						emc.beginTransaction(OriginFile.class);
+						emc.delete(OriginFile.class, originFile.getId());
+						emc.commit();
+					}
+					throw e;
 				}
 				}
 			}
 			}
 			result.setData(wo);
 			result.setData(wo);

+ 3 - 0
o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/attachment2/ActionUpdate.java

@@ -33,6 +33,9 @@ class ActionUpdate extends BaseAction {
 			}
 			}
 			emc.beginTransaction(Attachment2.class);
 			emc.beginTransaction(Attachment2.class);
 			Wi.copier.copy(wi, attachment);
 			Wi.copier.copy(wi, attachment);
+			if (StringUtils.isEmpty(attachment.getFolder())) {
+				attachment.setFolder(Business.TOP_FOLD);
+			}
 			emc.check(attachment, CheckPersistType.all);
 			emc.check(attachment, CheckPersistType.all);
 			emc.commit();
 			emc.commit();
 			Wo wo = new Wo();
 			Wo wo = new Wo();

+ 5 - 3
o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/folder2/ActionUpdate.java

@@ -47,14 +47,16 @@ class ActionUpdate extends BaseAction {
 				List<String> ids = new ArrayList<>();
 				List<String> ids = new ArrayList<>();
 				ids.add(folder.getId());
 				ids.add(folder.getId());
 				ids.addAll(business.folder2().listSubNested(folder.getId(), FileStatus.VALID.getName()));
 				ids.addAll(business.folder2().listSubNested(folder.getId(), FileStatus.VALID.getName()));
-				if(ids.contains(folder.getSuperior())){
-					throw new Exception("superior can not be sub folder.");
+				if(ids.contains(wi.getSuperior())){
+					throw new Exception("无效父目录:"+wi.getSuperior()+",父目录不能为本目录及子目录.");
 				}
 				}
 			}else{
 			}else{
 				wi.setSuperior(Business.TOP_FOLD);
 				wi.setSuperior(Business.TOP_FOLD);
 			}
 			}
 
 
-			this.exist(business, effectivePerson, wi.getName(), wi.getSuperior(), folder.getId());
+			if(this.exist(business, effectivePerson, wi.getName(), wi.getSuperior(), folder.getId())){
+				throw new ExceptionFolderNameExist(effectivePerson.getName(), wi.getName(), wi.getSuperior());
+			}
 			emc.beginTransaction(Folder2.class);
 			emc.beginTransaction(Folder2.class);
 			folder.setName(wi.getName());
 			folder.setName(wi.getName());
 			folder.setSuperior(wi.getSuperior());
 			folder.setSuperior(wi.getSuperior());