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

Merge branch 'fix/云文件不同用户上传同一文件到根目录失败' into 'develop'

Merge of fix/[云文件]不同用户上传同一文件到根目录失败 to develop

See merge request o2oa/o2oa!625
程剑 5 лет назад
Родитель
Сommit
82f1fe59d2

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

@@ -26,7 +26,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
-class ActionUpload extends StandardJaxrsAction {
+class ActionUpload extends BaseAction {
 
 	// @HttpMethodDescribe(value = "创建Attachment对象,如果没有上级目录用(0)替代.", response =
 	// WrapOutId.class)
@@ -66,7 +66,8 @@ class ActionUpload extends StandardJaxrsAction {
 				throw new ExceptionEmptyExtension(fileName);
 			}
 			/** 同一目录下文件名唯一 */
-			if (this.exist(business, fileName, folderId)) {
+
+			if (this.exist(business, fileName, folderId, effectivePerson.getDistinguishedName())) {
 				throw new ExceptionSameNameFileExist(fileName);
 			}
 			if(StringUtils.isEmpty(fileMd5)){
@@ -107,20 +108,6 @@ class ActionUpload extends StandardJaxrsAction {
 		}
 	}
 
-	private Boolean exist(Business business, String fileName, String folderId) throws Exception {
-		EntityManager em = business.entityManagerContainer().get(Attachment2.class);
-		CriteriaBuilder cb = em.getCriteriaBuilder();
-		CriteriaQuery<Long> cq = cb.createQuery(Long.class);
-		Root<Attachment2> root = cq.from(Attachment2.class);
-		Predicate p = cb.equal(root.get(Attachment2_.name), fileName);
-		if (StringUtils.isNotEmpty(folderId)) {
-			p = cb.and(p, cb.equal(root.get(Attachment2_.folder), folderId));
-		} else {
-			p = cb.and(p, cb.or(cb.isNull(root.get(Attachment2_.folder)), cb.equal(root.get(Attachment2_.folder), "")));
-		}
-		return em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult() > 0;
-	}
-
 	public static class Wo extends WoId {
 	}
 }

+ 2 - 16
o2server/x_file_assemble_control/src/main/java/com/x/file/assemble/control/jaxrs/attachment2/ActionUploadCallback.java

@@ -27,7 +27,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
-class ActionUploadCallback extends StandardJaxrsAction {
+class ActionUploadCallback extends BaseAction {
 
 	// @HttpMethodDescribe(value = "创建Attachment对象,如果没有上级目录用(0)替代.", response =
 	// WrapOutId.class)
@@ -67,7 +67,7 @@ class ActionUploadCallback extends StandardJaxrsAction {
 				throw new ExceptionEmptyExtensionCallback(callback, fileName);
 			}
 			/** 同一目录下文件名唯一 */
-			if (this.exist(business, fileName, folderId)) {
+			if (this.exist(business, fileName, folderId, effectivePerson.getDistinguishedName())) {
 				throw new ExceptionSameNameFileExistCallback(callback, fileName);
 			}
 			if(StringUtils.isEmpty(fileMd5)){
@@ -109,20 +109,6 @@ class ActionUploadCallback extends StandardJaxrsAction {
 		}
 	}
 
-	private Boolean exist(Business business, String fileName, String folderId) throws Exception {
-		EntityManager em = business.entityManagerContainer().get(Attachment2.class);
-		CriteriaBuilder cb = em.getCriteriaBuilder();
-		CriteriaQuery<Long> cq = cb.createQuery(Long.class);
-		Root<Attachment2> root = cq.from(Attachment2.class);
-		Predicate p = cb.equal(root.get(Attachment2_.name), fileName);
-		if (StringUtils.isNotEmpty(folderId)) {
-			p = cb.and(p, cb.equal(root.get(Attachment2_.folder), folderId));
-		} else {
-			p = cb.and(p, cb.or(cb.isNull(root.get(Attachment2_.folder)), cb.equal(root.get(Attachment2_.folder), "")));
-		}
-		return em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult() > 0;
-	}
-
 	public static class Wo<T> extends WoCallback<T> {
 		public Wo(String callbackName, T t) {
 			super(callbackName, t);

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

@@ -4,7 +4,16 @@ import com.x.base.core.project.gson.XGsonBuilder;
 import com.x.base.core.project.jaxrs.StandardJaxrsAction;
 import com.x.base.core.project.message.MessageConnector;
 import com.x.base.core.project.organization.OrganizationDefinition;
+import com.x.file.assemble.control.Business;
 import com.x.file.core.entity.personal.Attachment;
+import com.x.file.core.entity.personal.Attachment2;
+import com.x.file.core.entity.personal.Attachment2_;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
 
 abstract class BaseAction extends StandardJaxrsAction {
 
@@ -42,4 +51,15 @@ abstract class BaseAction extends StandardJaxrsAction {
 		MessageConnector.send(MessageConnector.TYPE_ATTACHMENT_EDITORMODIFY, title, person,
 				XGsonBuilder.convert(attachment, Attachment.class));
 	}
+
+	protected Boolean exist(Business business, String fileName, String folderId, String person) throws Exception {
+		EntityManager em = business.entityManagerContainer().get(Attachment2.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<Long> cq = cb.createQuery(Long.class);
+		Root<Attachment2> root = cq.from(Attachment2.class);
+		Predicate p = cb.equal(root.get(Attachment2_.name), fileName);
+		p = cb.and(p, cb.equal(root.get(Attachment2_.person), person));
+		p = cb.and(p, cb.equal(root.get(Attachment2_.folder), folderId));
+		return em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult() > 0;
+	}
 }

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

@@ -25,9 +25,6 @@ public class ActionCreate extends BaseAction {
 			if (StringUtils.isEmpty(wi.getName())) {
 				throw new ExceptionFolderNameEmpty();
 			}
-			if (this.exist(business, effectivePerson, wi.getName(), wi.getSuperior(), null)) {
-				throw new ExceptionFolderNameExist(effectivePerson.getName(), wi.getName(), wi.getSuperior());
-			}
 			if(StringUtils.isEmpty(wi.getSuperior())){
 				wi.setSuperior(Business.TOP_FOLD);
 			}else{
@@ -36,6 +33,9 @@ public class ActionCreate extends BaseAction {
 					throw new ExceptionFolderNotExist(wi.getSuperior());
 				}
 			}
+			if (this.exist(business, effectivePerson, wi.getName(), wi.getSuperior(), null)) {
+				throw new ExceptionFolderNameExist(effectivePerson.getName(), wi.getName(), wi.getSuperior());
+			}
 			emc.beginTransaction(Folder2.class);
 			Folder2 folder = Wi.copier.copy(wi);
 			folder.setPerson(effectivePerson.getDistinguishedName());