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

Merge branch 'feature/增加批量上传同附件到多个work的接口' into 'wrdp'

[流程平台]增加批量上传附件到多个work的接口,合并到重庆移动

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

+ 56 - 33
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageUpload.java → o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageBatchUpload.java

@@ -6,10 +6,9 @@ import com.x.base.core.entity.annotation.CheckPersistType;
 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.exception.ExceptionEntityNotExist;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
-import com.x.base.core.project.jaxrs.WoId;
+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;
@@ -18,38 +17,29 @@ import com.x.processplatform.assemble.surface.ThisApplication;
 import com.x.processplatform.assemble.surface.WorkControl;
 import com.x.processplatform.core.entity.content.Attachment;
 import com.x.processplatform.core.entity.content.Work;
-import com.x.processplatform.core.entity.element.Application;
-import com.x.processplatform.core.entity.element.Process;
+import com.x.processplatform.core.entity.content.WorkCompleted;
+import com.x.processplatform.core.entity.element.ActivityType;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.tika.Tika;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 
-class ActionManageUpload extends BaseAction {
+class ActionManageBatchUpload extends BaseAction {
 
-	private static Logger logger = LoggerFactory.getLogger(ActionManageUpload.class);
+	private static Logger logger = LoggerFactory.getLogger(ActionManageBatchUpload.class);
 
-	ActionResult<Wo> execute(EffectivePerson effectivePerson, String workId, String site, String fileName, byte[] bytes,
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String workIds, String site, String fileName, byte[] bytes,
 			FormDataContentDisposition disposition, String extraParam, String person) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<Wo> result = new ActionResult<>();
 			Business business = new Business(emc);
-			/* 后面要重新保存 */
-			Work work = emc.find(workId, Work.class);
-			/* 判断work是否存在 */
-			if (null == work) {
-				throw new ExceptionEntityNotExist(workId, Work.class);
-			}
-			Process process = business.process().pick(work.getProcess());
-			Application application = business.application().pick(work.getApplication());
 			// 需要对这个应用的管理权限
-			if (!business.canManageApplicationOrProcess(effectivePerson, application, process)) {
+			if (!business.canManageApplication(effectivePerson, null)) {
 				throw new ExceptionAccessDenied(effectivePerson);
 			}
+
 			if (StringUtils.isEmpty(fileName)) {
 				fileName = this.fileName(disposition);
 			}
-			/* 调整可能的附件名称 */
-			fileName = this.adjustFileName(business, work.getJob(), fileName);
 
 			/* 天谷印章扩展 */
 			if (StringUtils.isNotEmpty(extraParam)) {
@@ -61,26 +51,41 @@ class ActionManageUpload extends BaseAction {
 					site = wiExtraParam.getSite();
 				}
 			}
+
 			person = business.organization().person().get(person);
 			if(StringUtils.isEmpty(person)){
 				person = effectivePerson.getDistinguishedName();
 			}
-			StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
-			Attachment attachment = this.concreteAttachment(work, person, site);
-			attachment.saveContent(mapping, bytes, fileName);
-			attachment.setType((new Tika()).detect(bytes, fileName));
-			logger.debug("filename:{}, file type:{}.", attachment.getName(), attachment.getType());
-			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());
+			if(StringUtils.isNotEmpty(workIds) && bytes!=null && bytes.length>0) {
+				String[] idArray = workIds.split(",");
+				for (String workId : idArray) {
+                    Attachment attachment = null;
+					Work work = emc.find(workId.trim(), Work.class);
+                    if(work!=null) {
+						attachment = this.concreteAttachment(work, person, site);
+                    }else{
+                        WorkCompleted workCompleted = emc.find(workId, WorkCompleted.class);
+                        if (null != workCompleted) {
+                            attachment = this.concreteAttachment(workCompleted, person, site);
+                        }
+                    }
+                    if(attachment!=null){
+                        StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
+                        attachment.saveContent(mapping, bytes, fileName);
+                        attachment.setType((new Tika()).detect(bytes, fileName));
+                        if (Config.query().getExtractImage() && ExtractTextTools.supportImage(attachment.getName())
+                                && ExtractTextTools.available(bytes)) {
+                            attachment.setText(ExtractTextTools.image(bytes));
+                        }
+                        emc.beginTransaction(Attachment.class);
+                        emc.persist(attachment, CheckPersistType.all);
+                        emc.commit();
+                    }
+				}
 			}
-			emc.beginTransaction(Attachment.class);
-			emc.persist(attachment, CheckPersistType.all);
-			emc.commit();
+
 			Wo wo = new Wo();
-			wo.setId(attachment.getId());
+			wo.setValue(true);
 			result.setData(wo);
 			return result;
 		}
@@ -104,7 +109,25 @@ class ActionManageUpload extends BaseAction {
 		return attachment;
 	}
 
-	public static class Wo extends WoId {
+    private Attachment concreteAttachment(WorkCompleted workCompleted, String person, String site) throws Exception {
+        Attachment attachment = new Attachment();
+        attachment.setCompleted(true);
+        attachment.setPerson(person);
+        attachment.setLastUpdatePerson(person);
+        attachment.setSite(site);
+        /** 用于判断目录的值 */
+        attachment.setWorkCreateTime(workCompleted.getStartTime());
+        attachment.setApplication(workCompleted.getApplication());
+        attachment.setProcess(workCompleted.getProcess());
+        attachment.setJob(workCompleted.getJob());
+        attachment.setActivity(workCompleted.getActivity());
+        attachment.setActivityName(workCompleted.getActivityName());
+        attachment.setActivityToken(workCompleted.getActivity());
+        attachment.setActivityType(ActivityType.end);
+        return attachment;
+    }
+
+	public static class Wo extends WrapBoolean {
 
 	}
 

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

@@ -1061,23 +1061,23 @@ public class AttachmentAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 
-	@JaxrsMethodDescribe(value = "管理员上传附件.", action = ActionManageUpload.class)
+	@JaxrsMethodDescribe(value = "管理员批量上传附件.", action = ActionManageBatchUpload.class)
 	@POST
-	@Path("upload/work/{workId}/manage")
+	@Path("batch/upload/manage")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.MULTIPART_FORM_DATA)
-	public void manageUpload(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
-			@JaxrsParameterDescribe("工作标识") @PathParam("workId") String workId,
+	public void manageBatchUpload(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+			@JaxrsParameterDescribe("工作标识列表,多值逗号隔开") @FormDataParam("workIds") String workIds,
 			@JaxrsParameterDescribe("位置") @FormDataParam("site") String site,
 			@JaxrsParameterDescribe("附件名称") @FormDataParam(FILENAME_FIELD) String fileName,
 			@JaxrsParameterDescribe("上传到指定用户") @FormDataParam("person") String person,
 			@JaxrsParameterDescribe("天印扩展字段") @FormDataParam("extraParam") String extraParam,
 			@FormDataParam(FILE_FIELD) final byte[] bytes,
 			@FormDataParam(FILE_FIELD) final FormDataContentDisposition disposition) {
-		ActionResult<ActionManageUpload.Wo> result = new ActionResult<>();
+		ActionResult<ActionManageBatchUpload.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new ActionManageUpload().execute(effectivePerson, workId, site, fileName, bytes, disposition,
+			result = new ActionManageBatchUpload().execute(effectivePerson, workIds, site, fileName, bytes, disposition,
 					extraParam, person);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);