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

Merge branch 'feature/增加根据job获取工作附件列表的接口' into 'project/chinamobile-重庆移动'

[流程平台]增加根据job获取工作附件列表的接口

See merge request o2oa/o2oa!2942

(cherry picked from commit d5389eb503a0475c4324cb9cb14ff403a1b7a91c)

a112df47 增加根据job获取工作附件列表的接口
o2null 5 лет назад
Родитель
Сommit
cc236c550a

+ 17 - 0
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/factory/content/JobFactory.java

@@ -2,6 +2,7 @@ package com.x.processplatform.assemble.surface.factory.content;
 
 import java.util.List;
 
+import com.x.base.core.entity.JpaObject;
 import com.x.base.core.project.tools.ListTools;
 import com.x.processplatform.assemble.surface.AbstractFactory;
 import com.x.processplatform.assemble.surface.Business;
@@ -63,4 +64,20 @@ public class JobFactory extends AbstractFactory {
 			return false;
 		}
 	}
+
+	public String findAWorkOrWorkCompleted(String job) throws Exception {
+		String id = "";
+		List<Work> ws = this.entityManagerContainer().fetchEqualAscPaging(Work.class,
+				ListTools.toList(Work.id_FIELDNAME), Work.job_FIELDNAME, job, 1, 1, JpaObject.sequence_FIELDNAME);
+		if (ListTools.isNotEmpty(ws)) {
+			id = ws.get(0).getId();
+		}else {
+			List<WorkCompleted> wcs = this.entityManagerContainer().fetchEqualAscPaging(WorkCompleted.class,
+					ListTools.toList(WorkCompleted.id_FIELDNAME), WorkCompleted.job_FIELDNAME, job, 1, 1, JpaObject.sequence_FIELDNAME);
+			if (ListTools.isNotEmpty(wcs)) {
+				id = wcs.get(0).getId();
+			}
+		}
+		return id;
+	}
 }

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

@@ -0,0 +1,132 @@
+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.entity.JpaObject;
+import com.x.base.core.project.annotation.FieldDescribe;
+import com.x.base.core.project.bean.WrapCopier;
+import com.x.base.core.project.bean.WrapCopierFactory;
+import com.x.base.core.project.exception.ExceptionAccessDenied;
+import com.x.base.core.project.gson.GsonPropertyObject;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.processplatform.assemble.surface.Business;
+import com.x.processplatform.core.entity.content.Attachment;
+import org.apache.commons.lang3.BooleanUtils;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+class ActionListWithJob extends BaseAction {
+
+	private static Logger logger = LoggerFactory.getLogger(ActionListWithJob.class);
+
+	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String job) throws Exception {
+
+		ActionResult<List<Wo>> result = new ActionResult<>();
+		CompletableFuture<List<Wo>> listFuture = listFuture(effectivePerson, job);
+		CompletableFuture<Boolean> checkControlFuture = checkJobControlFuture(effectivePerson, job);
+		result.setData(listFuture.get(10, TimeUnit.SECONDS));
+		if (BooleanUtils.isFalse(checkControlFuture.get(10, TimeUnit.SECONDS))) {
+			throw new ExceptionAccessDenied(effectivePerson, job);
+		}
+		return result;
+
+	}
+
+	private CompletableFuture<List<Wo>> listFuture(EffectivePerson effectivePerson, String flag) {
+		return CompletableFuture.supplyAsync(() -> {
+			List<Wo> wos = new ArrayList<>();
+			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+				Business business = new Business(emc);
+				List<String> identities = business.organization().identity().listWithPerson(effectivePerson);
+				List<String> units = business.organization().unit().listWithPerson(effectivePerson);
+				final String job = flag;
+				for (Attachment attachment : business.entityManagerContainer().listEqual(Attachment.class,
+						Attachment.job_FIELDNAME, job)) {
+					Wo wo = Wo.copier.copy(attachment);
+					boolean canControl = this.control(attachment, effectivePerson, identities, units, business);
+					boolean canEdit = this.edit(attachment, effectivePerson, identities, units, business);
+					boolean canRead = this.read(attachment, effectivePerson, identities, units, business);
+					if (canRead) {
+						wo.getControl().setAllowRead(true);
+						wo.getControl().setAllowEdit(canEdit);
+						wo.getControl().setAllowControl(canControl);
+						wos.add(wo);
+					}
+				}
+				wos = wos.stream()
+						.sorted(Comparator.comparing(Wo::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
+								.thenComparing(
+										Comparator.comparing(Wo::getCreateTime, Comparator.nullsLast(Date::compareTo))))
+						.collect(Collectors.toList());
+			} catch (Exception e) {
+				logger.error(e);
+			}
+			return wos;
+		});
+
+	}
+
+	public static class Wo extends Attachment {
+
+		private static final long serialVersionUID = -7666329770246726197L;
+
+		static WrapCopier<Attachment, Wo> copier = WrapCopierFactory.wo(Attachment.class, Wo.class, null,
+				JpaObject.FieldsInvisible);
+
+		private WoControl control = new WoControl();
+
+		public WoControl getControl() {
+			return control;
+		}
+
+		public void setControl(WoControl control) {
+			this.control = control;
+		}
+
+	}
+
+	public static class WoControl extends GsonPropertyObject {
+		private static final long serialVersionUID = -7283783148043076205L;
+		@FieldDescribe("可读")
+		private Boolean allowRead = false;
+		@FieldDescribe("可写")
+		private Boolean allowEdit = false;
+		@FieldDescribe("可控制")
+		private Boolean allowControl = false;
+
+		public Boolean getAllowRead() {
+			return allowRead;
+		}
+
+		public void setAllowRead(Boolean allowRead) {
+			this.allowRead = allowRead;
+		}
+
+		public Boolean getAllowEdit() {
+			return allowEdit;
+		}
+
+		public void setAllowEdit(Boolean allowEdit) {
+			this.allowEdit = allowEdit;
+		}
+
+		public Boolean getAllowControl() {
+			return allowControl;
+		}
+
+		public void setAllowControl(Boolean allowControl) {
+			this.allowControl = allowControl;
+		}
+
+	}
+
+}

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

@@ -173,6 +173,25 @@ public class AttachmentAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 
+	@JaxrsMethodDescribe(value = "根据工作的job获取Attachment列表.", action = ActionListWithJob.class)
+	@GET
+	@Path("list/job/{job}")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void listWithJob(@Suspended final AsyncResponse asyncResponse,
+											@Context HttpServletRequest request,
+											@JaxrsParameterDescribe("工作的job") @PathParam("job") String job) {
+		ActionResult<List<ActionListWithJob.Wo>> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionListWithJob().execute(effectivePerson, job);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
 	@JaxrsMethodDescribe(value = "删除指定work下的附件.", action = ActionDeleteWithWork.class)
 	@DELETE
 	@Path("{id}/work/{workId}")

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

@@ -235,6 +235,23 @@ abstract class BaseAction extends StandardJaxrsAction {
 		return value;
 	}
 
+	protected CompletableFuture<Boolean> checkJobControlFuture(EffectivePerson effectivePerson, String job) {
+		return CompletableFuture.supplyAsync(() -> {
+			Boolean value = false;
+			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+				Business business = new Business(emc);
+				String flag = business.job().findAWorkOrWorkCompleted(job);
+				if(StringUtils.isNotEmpty(flag)){
+					value = business.readableWithWorkOrWorkCompleted(effectivePerson, flag,
+							new ExceptionEntityNotExist(job));
+				}
+			} catch (Exception e) {
+				logger.error(e);
+			}
+			return value;
+		});
+	}
+
 	protected CompletableFuture<Boolean> checkControlFuture(EffectivePerson effectivePerson, String flag) {
 		return CompletableFuture.supplyAsync(() -> {
 			Boolean value = false;