Browse Source

机管局天印接口附件上传修改

o2sword 5 years ago
parent
commit
5e2be929f0

+ 25 - 3
o2server/x_base_core_project/src/main/java/com/x/base/core/project/jaxrs/StandardJaxrsAction.java

@@ -1,9 +1,7 @@
 package com.x.base.core.project.jaxrs;
 package com.x.base.core.project.jaxrs;
 
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import java.util.*;
 import java.util.Map.Entry;
 import java.util.Map.Entry;
 
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManager;
@@ -14,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.Selection;
 import javax.persistence.criteria.Selection;
+import javax.servlet.http.HttpServletRequest;
 
 
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.collections4.map.ListOrderedMap;
 import org.apache.commons.collections4.map.ListOrderedMap;
@@ -1244,4 +1243,27 @@ public abstract class StandardJaxrsAction extends AbstractJaxrsAction {
 		return em.createQuery(cq.select(cb.count(root)).where(predicate)).getSingleResult();
 		return em.createQuery(cq.select(cb.count(root)).where(predicate)).getSingleResult();
 	}
 	}
 
 
+	/**
+	 * 将request参数值转为json
+	 */
+	public String request2Json(HttpServletRequest request) {
+		Map<String,String> map = new HashMap<>();
+		Enumeration paramNames = request.getParameterNames();
+		while (paramNames.hasMoreElements()) {
+			String paramName = (String) paramNames.nextElement();
+			String[] pv = request.getParameterValues(paramName);
+			StringBuilder sb = new StringBuilder();
+			for (int i = 0; i < pv.length; i++) {
+				if (pv[i].length() > 0) {
+					if (i > 0) {
+						sb.append(",");
+					}
+					sb.append(pv[i]);
+				}
+			}
+			map.put(paramName, sb.toString());
+		}
+		return gson.toJson(map);
+	}
+
 }
 }

+ 9 - 7
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionUpdate.java

@@ -42,6 +42,15 @@ class ActionUpdate extends BaseAction {
 			if (null == attachment) {
 			if (null == attachment) {
 				throw new ExceptionEntityNotExist(id, Attachment.class);
 				throw new ExceptionEntityNotExist(id, Attachment.class);
 			}
 			}
+
+			/* 天谷印章扩展 */
+			if (StringUtils.isNotEmpty(extraParam)) {
+				WiExtraParam wiExtraParam = gson.fromJson(extraParam, WiExtraParam.class);
+				if (StringUtils.isNotEmpty(wiExtraParam.getFileName())) {
+					fileName = wiExtraParam.getFileName();
+				}
+			}
+
 			if (StringUtils.isEmpty(fileName)) {
 			if (StringUtils.isEmpty(fileName)) {
 				fileName = this.fileName(disposition);
 				fileName = this.fileName(disposition);
 			}
 			}
@@ -53,13 +62,6 @@ class ActionUpdate extends BaseAction {
 			if (BooleanUtils.isNotTrue(control.getAllowSave())) {
 			if (BooleanUtils.isNotTrue(control.getAllowSave())) {
 				throw new ExceptionAccessDenied(effectivePerson, work);
 				throw new ExceptionAccessDenied(effectivePerson, work);
 			}
 			}
-			/* 天谷印章扩展 */
-			if (StringUtils.isNotEmpty(extraParam)) {
-				WiExtraParam wiExtraParam = gson.fromJson(extraParam, WiExtraParam.class);
-				if (StringUtils.isNotEmpty(wiExtraParam.getFileName())) {
-					fileName = wiExtraParam.getFileName();
-				}
-			}
 
 
 			StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
 			StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
 					attachment.getStorage());
 					attachment.getStorage());

+ 9 - 5
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionUpload.java

@@ -23,6 +23,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.tika.Tika;
 import org.apache.tika.Tika;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 
 
+import javax.servlet.http.HttpServletRequest;
+
 class ActionUpload extends BaseAction {
 class ActionUpload extends BaseAction {
 
 
 	private static Logger logger = LoggerFactory.getLogger(ActionUpload.class);
 	private static Logger logger = LoggerFactory.getLogger(ActionUpload.class);
@@ -42,11 +44,6 @@ class ActionUpload extends BaseAction {
 			if (BooleanUtils.isNotTrue(control.getAllowSave())) {
 			if (BooleanUtils.isNotTrue(control.getAllowSave())) {
 				throw new ExceptionAccessDenied(effectivePerson, work);
 				throw new ExceptionAccessDenied(effectivePerson, work);
 			}
 			}
-			if (StringUtils.isEmpty(fileName)) {
-				fileName = this.fileName(disposition);
-			}
-			/* 调整可能的附件名称 */
-			fileName = this.adjustFileName(business, work.getJob(), fileName);
 
 
 			/* 天谷印章扩展 */
 			/* 天谷印章扩展 */
 			if (StringUtils.isNotEmpty(extraParam)) {
 			if (StringUtils.isNotEmpty(extraParam)) {
@@ -58,6 +55,13 @@ class ActionUpload extends BaseAction {
 					site = wiExtraParam.getSite();
 					site = wiExtraParam.getSite();
 				}
 				}
 			}
 			}
+
+			if (StringUtils.isEmpty(fileName)) {
+				fileName = this.fileName(disposition);
+			}
+			/* 调整可能的附件名称 */
+			fileName = this.adjustFileName(business, work.getJob(), fileName);
+
 			StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
 			StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
 			Attachment attachment = this.concreteAttachment(work, effectivePerson, site);
 			Attachment attachment = this.concreteAttachment(work, effectivePerson, site);
 			attachment.saveContent(mapping, bytes, fileName);
 			attachment.saveContent(mapping, bytes, fileName);

+ 13 - 0
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/AttachmentAction.java

@@ -10,6 +10,7 @@ import javax.ws.rs.container.Suspended;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MediaType;
 
 
+import org.apache.commons.lang3.StringUtils;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.glassfish.jersey.media.multipart.FormDataParam;
 import org.glassfish.jersey.media.multipart.FormDataParam;
 
 
@@ -347,6 +348,9 @@ public class AttachmentAction extends StandardJaxrsAction {
 		ActionResult<ActionUpload.Wo> result = new ActionResult<>();
 		ActionResult<ActionUpload.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
 		try {
+			if(StringUtils.isEmpty(extraParam)){
+				extraParam = this.request2Json(request);
+			}
 			result = new ActionUpload().execute(effectivePerson, workId, site, fileName, bytes, disposition,
 			result = new ActionUpload().execute(effectivePerson, workId, site, fileName, bytes, disposition,
 					extraParam);
 					extraParam);
 		} catch (Exception e) {
 		} catch (Exception e) {
@@ -372,6 +376,9 @@ public class AttachmentAction extends StandardJaxrsAction {
 		ActionResult<ActionUploadWithWorkCompleted.Wo> result = new ActionResult<>();
 		ActionResult<ActionUploadWithWorkCompleted.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
 		try {
+			if(StringUtils.isEmpty(extraParam)){
+				extraParam = this.request2Json(request);
+			}
 			result = new ActionUploadWithWorkCompleted().execute(effectivePerson, workCompletedId, site, fileName,
 			result = new ActionUploadWithWorkCompleted().execute(effectivePerson, workCompletedId, site, fileName,
 					bytes, disposition, extraParam);
 					bytes, disposition, extraParam);
 		} catch (Exception e) {
 		} catch (Exception e) {
@@ -421,6 +428,9 @@ public class AttachmentAction extends StandardJaxrsAction {
 		ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
 		ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
 		try {
+			if(StringUtils.isEmpty(extraParam)){
+				extraParam = this.request2Json(request);
+			}
 			result = new ActionUpdate().execute(effectivePerson, id, workId, fileName, bytes, disposition, extraParam);
 			result = new ActionUpdate().execute(effectivePerson, id, workId, fileName, bytes, disposition, extraParam);
 		} catch (Exception e) {
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			logger.error(e, effectivePerson, request, null);
@@ -488,6 +498,9 @@ public class AttachmentAction extends StandardJaxrsAction {
 		ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
 		ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
 		try {
+			if(StringUtils.isEmpty(extraParam)){
+				extraParam = this.request2Json(request);
+			}
 			result = new ActionUpdate().execute(effectivePerson, id, workId, fileName, bytes, disposition, extraParam);
 			result = new ActionUpdate().execute(effectivePerson, id, workId, fileName, bytes, disposition, extraParam);
 		} catch (Exception e) {
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			logger.error(e, effectivePerson, request, null);