Kaynağa Gözat

Merge branch 'feature/增加批量修改附件的接口' into 'wrdp'

[流程平台]增加批量更新附件的接口,同时合并到重庆移动

See merge request o2oa/o2oa!2829
o2null 5 yıl önce
ebeveyn
işleme
f38bc6e964

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

@@ -0,0 +1,79 @@
+package com.x.processplatform.assemble.surface.jaxrs.attachment;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.project.config.Config;
+import com.x.base.core.project.config.StorageMapping;
+import com.x.base.core.project.exception.ExceptionAccessDenied;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.jaxrs.WrapBoolean;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.tools.ExtractTextTools;
+import com.x.base.core.project.tools.ListTools;
+import com.x.processplatform.assemble.surface.Business;
+import com.x.processplatform.assemble.surface.ThisApplication;
+import com.x.processplatform.core.entity.content.Attachment;
+import org.apache.commons.lang3.StringUtils;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+
+import java.util.List;
+
+class ActionManageBatchUpdate extends BaseAction {
+
+	private static Logger logger = LoggerFactory.getLogger(ActionManageBatchUpdate.class);
+
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String ids, String fileName, byte[] bytes,
+			FormDataContentDisposition disposition, String extraParam) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			logger.print("manageBatchUpdate receive id:{}, fileName:{}, effectivePerson:{}.", ids, fileName, effectivePerson.getDistinguishedName());
+			ActionResult<Wo> result = new ActionResult<>();
+			Business business = new Business(emc);
+			if(!business.canManageApplication(effectivePerson, null)){
+				throw new ExceptionAccessDenied(effectivePerson);
+			}
+			/* 天谷印章扩展 */
+			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);
+			}
+			if(StringUtils.isNotEmpty(ids) && bytes!=null && bytes.length>0){
+				String[] idArray = ids.split(",");
+				for (String id : idArray){
+					Attachment attachment = emc.find(id.trim(), Attachment.class);
+					if(attachment!=null){
+						StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
+								attachment.getStorage());
+						emc.beginTransaction(Attachment.class);
+						attachment.updateContent(mapping, bytes, fileName);
+						if (Config.query().getExtractImage() && ExtractTextTools.supportImage(attachment.getName())
+								&& ExtractTextTools.available(bytes)) {
+							attachment.setText(ExtractTextTools.image(bytes));
+							logger.debug("filename:{}, file type:{}, text:{}.", attachment.getName(), attachment.getType(),
+									attachment.getText());
+						}
+						emc.commit();
+
+					}
+				}
+			}
+
+			Wo wo = new Wo();
+			wo.setValue(true);
+			result.setData(wo);
+			return result;
+		}
+	}
+
+	public static class Wo extends WrapBoolean {
+
+	}
+
+}

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

@@ -1154,4 +1154,27 @@ public class AttachmentAction extends StandardJaxrsAction {
 		}
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
-}
+
+	@JaxrsMethodDescribe(value = "管理员批量替换附件.", action = ActionManageBatchUpdate.class)
+	@POST
+	@Path("batch/update/manage")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.MULTIPART_FORM_DATA)
+	public void manageBatchUpdate(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+							 @JaxrsParameterDescribe("附件Id列表,多值逗号隔开") @FormDataParam("ids") String ids,
+							 @JaxrsParameterDescribe("附件名称") @FormDataParam(FILENAME_FIELD) String fileName,
+							 @JaxrsParameterDescribe("天印扩展字段") @FormDataParam("extraParam") String extraParam,
+							 @FormDataParam(FILE_FIELD) final byte[] bytes,
+							 @FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
+		ActionResult<ActionManageBatchUpdate.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionManageBatchUpdate().execute(effectivePerson, ids, fileName, bytes, disposition,
+					extraParam);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+}