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

Merge branch 'feature/process-dzqz-upload' into 'develop'

Merge of feature/[流程管理]增加机管局天印附件(电子签章后的附件)上传接口适配

See merge request o2oa/o2oa!140
o2null 5 лет назад
Родитель
Сommit
a196d5e102

+ 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;
 
 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 javax.persistence.EntityManager;
@@ -14,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.Selection;
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.beanutils.PropertyUtils;
 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();
 	}
 
+	/**
+	 * 将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) {
 				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)) {
 				fileName = this.fileName(disposition);
 			}
@@ -53,13 +62,6 @@ class ActionUpdate extends BaseAction {
 			if (BooleanUtils.isNotTrue(control.getAllowSave())) {
 				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,
 					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.glassfish.jersey.media.multipart.FormDataContentDisposition;
 
+import javax.servlet.http.HttpServletRequest;
+
 class ActionUpload extends BaseAction {
 
 	private static Logger logger = LoggerFactory.getLogger(ActionUpload.class);
@@ -42,11 +44,6 @@ class ActionUpload extends BaseAction {
 			if (BooleanUtils.isNotTrue(control.getAllowSave())) {
 				throw new ExceptionAccessDenied(effectivePerson, work);
 			}
-			if (StringUtils.isEmpty(fileName)) {
-				fileName = this.fileName(disposition);
-			}
-			/* 调整可能的附件名称 */
-			fileName = this.adjustFileName(business, work.getJob(), fileName);
 
 			/* 天谷印章扩展 */
 			if (StringUtils.isNotEmpty(extraParam)) {
@@ -58,6 +55,13 @@ class ActionUpload extends BaseAction {
 					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);
 			Attachment attachment = this.concreteAttachment(work, effectivePerson, site);
 			attachment.saveContent(mapping, bytes, fileName);

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

@@ -1,8 +1,8 @@
 package com.x.processplatform.assemble.surface.jaxrs.attachment;
 
 import java.util.List;
+import java.util.Map;
 
-import javax.jws.WebParam;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.*;
 import javax.ws.rs.container.AsyncResponse;
@@ -10,7 +10,10 @@ import javax.ws.rs.container.Suspended;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.commons.lang3.StringUtils;
+import org.glassfish.jersey.media.multipart.FormDataBodyPart;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
 import org.glassfish.jersey.media.multipart.FormDataParam;
 
 import com.google.gson.JsonElement;
@@ -337,16 +340,29 @@ public class AttachmentAction extends StandardJaxrsAction {
 	@Path("upload/work/{workId}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.MULTIPART_FORM_DATA)
-	public void upload(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
-			@JaxrsParameterDescribe("工作标识") @PathParam("workId") String workId,
-			@JaxrsParameterDescribe("位置") @FormDataParam("site") String site,
-			@JaxrsParameterDescribe("附件名称") @FormDataParam(FILENAME_FIELD) String fileName,
-			@JaxrsParameterDescribe("天印扩展字段") @FormDataParam("extraParam") String extraParam,
-			@FormDataParam(FILE_FIELD) final byte[] bytes,
-			@FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
+	public void upload(FormDataMultiPart form, @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+					   @JaxrsParameterDescribe("工作标识") @PathParam("workId") String workId,
+					   @JaxrsParameterDescribe("位置") @FormDataParam("site") String site,
+					   @JaxrsParameterDescribe("附件名称") @FormDataParam(FILENAME_FIELD) String fileName,
+					   @JaxrsParameterDescribe("天印扩展字段") @FormDataParam("extraParam") String extraParam,
+					   @FormDataParam(FILE_FIELD) byte[] bytes,
+					   @FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
 		ActionResult<ActionUpload.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
+			if(StringUtils.isEmpty(extraParam)){
+				extraParam = this.request2Json(request);
+			}
+			if(bytes==null){
+				Map<String, List<FormDataBodyPart>> map = form.getFields();
+				for(String key: map.keySet()){
+					FormDataBodyPart part = map.get(key).get(0);
+					if("application".equals(part.getMediaType().getType())){
+						bytes = part.getValueAs(byte[].class);
+						break;
+					}
+				}
+			}
 			result = new ActionUpload().execute(effectivePerson, workId, site, fileName, bytes, disposition,
 					extraParam);
 		} catch (Exception e) {
@@ -361,17 +377,30 @@ public class AttachmentAction extends StandardJaxrsAction {
 	@Path("upload/workcompleted/{workCompletedId}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.MULTIPART_FORM_DATA)
-	public void uploadWithWorkCompleted(@Suspended final AsyncResponse asyncResponse,
+	public void uploadWithWorkCompleted(FormDataMultiPart form, @Suspended final AsyncResponse asyncResponse,
 			@Context HttpServletRequest request,
 			@JaxrsParameterDescribe("已完成工作标识") @PathParam("workCompletedId") String workCompletedId,
 			@JaxrsParameterDescribe("位置") @FormDataParam("site") String site,
 			@JaxrsParameterDescribe("附件名称") @FormDataParam(FILENAME_FIELD) String fileName,
 			@JaxrsParameterDescribe("天印扩展字段") @FormDataParam("extraParam") String extraParam,
-			@FormDataParam(FILE_FIELD) final byte[] bytes,
+			@FormDataParam(FILE_FIELD) byte[] bytes,
 			@FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
 		ActionResult<ActionUploadWithWorkCompleted.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
+			if(StringUtils.isEmpty(extraParam)){
+				extraParam = this.request2Json(request);
+			}
+			if(bytes==null){
+				Map<String, List<FormDataBodyPart>> map = form.getFields();
+				for(String key: map.keySet()){
+					FormDataBodyPart part = map.get(key).get(0);
+					if("application".equals(part.getMediaType().getType())){
+						bytes = part.getValueAs(byte[].class);
+						break;
+					}
+				}
+			}
 			result = new ActionUploadWithWorkCompleted().execute(effectivePerson, workCompletedId, site, fileName,
 					bytes, disposition, extraParam);
 		} catch (Exception e) {
@@ -411,16 +440,29 @@ public class AttachmentAction extends StandardJaxrsAction {
 	@Path("update/{id}/work/{workId}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.MULTIPART_FORM_DATA)
-	public void update(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+	public void update(FormDataMultiPart form, @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
 			@JaxrsParameterDescribe("附件标识") @PathParam("id") String id,
 			@JaxrsParameterDescribe("工作标识") @PathParam("workId") String workId,
 			@JaxrsParameterDescribe("附件名称") @FormDataParam(FILENAME_FIELD) String fileName,
 			@JaxrsParameterDescribe("天印扩展字段") @FormDataParam("extraParam") String extraParam,
-			@FormDataParam(FILE_FIELD) final byte[] bytes,
+			@FormDataParam(FILE_FIELD) byte[] bytes,
 			@JaxrsParameterDescribe("附件") @FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
 		ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
+			if(StringUtils.isEmpty(extraParam)){
+				extraParam = this.request2Json(request);
+			}
+			if(bytes==null){
+				Map<String, List<FormDataBodyPart>> map = form.getFields();
+				for(String key: map.keySet()){
+					FormDataBodyPart part = map.get(key).get(0);
+					if("application".equals(part.getMediaType().getType())){
+						bytes = part.getValueAs(byte[].class);
+						break;
+					}
+				}
+			}
 			result = new ActionUpdate().execute(effectivePerson, id, workId, fileName, bytes, disposition, extraParam);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
@@ -478,16 +520,29 @@ public class AttachmentAction extends StandardJaxrsAction {
 	@Path("update/{id}/work/{workId}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.MULTIPART_FORM_DATA)
-	public void updatePost(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+	public void updatePost(FormDataMultiPart form, @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
 			@JaxrsParameterDescribe("附件标识") @PathParam("id") String id,
 			@JaxrsParameterDescribe("工作标识") @PathParam("workId") String workId,
 			@JaxrsParameterDescribe("附件名称") @FormDataParam(FILENAME_FIELD) String fileName,
 			@JaxrsParameterDescribe("天印扩展字段") @FormDataParam("extraParam") String extraParam,
-			@FormDataParam(FILE_FIELD) final byte[] bytes,
+			@FormDataParam(FILE_FIELD) byte[] bytes,
 			@JaxrsParameterDescribe("附件") @FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
 		ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
+			if(StringUtils.isEmpty(extraParam)){
+				extraParam = this.request2Json(request);
+			}
+			if(bytes==null){
+				Map<String, List<FormDataBodyPart>> map = form.getFields();
+				for(String key: map.keySet()){
+					FormDataBodyPart part = map.get(key).get(0);
+					if("application".equals(part.getMediaType().getType())){
+						bytes = part.getValueAs(byte[].class);
+						break;
+					}
+				}
+			}
 			result = new ActionUpdate().execute(effectivePerson, id, workId, fileName, bytes, disposition, extraParam);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);