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

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

o2sword 6 лет назад
Родитель
Сommit
41f1679520

+ 45 - 12
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;
@@ -11,7 +11,9 @@ 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;
@@ -338,19 +340,30 @@ 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);
 			}
+			logger.print("上传附件fileName={},extraParam={}", fileName, extraParam);
+			if(bytes==null){
+				Map<String, List<FormDataBodyPart>> map = form.getFields();
+				for(String key: map.keySet()){
+					FormDataBodyPart part = map.get(key).get(0);
+					if(StringUtils.isEmpty(key) && "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) {
@@ -365,13 +378,13 @@ 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);
@@ -379,6 +392,16 @@ public class AttachmentAction extends StandardJaxrsAction {
 			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(StringUtils.isEmpty(key) && "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) {
@@ -418,12 +441,12 @@ 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);
@@ -431,6 +454,16 @@ public class AttachmentAction extends StandardJaxrsAction {
 			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(StringUtils.isEmpty(key) && "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);