Explorar o código

增加流程移动端可启动标识

zhourui %!s(int64=5) %!d(string=hai) anos
pai
achega
232fb93b2a

+ 4 - 0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ProcessPlatform.java

@@ -40,6 +40,10 @@ public class ProcessPlatform extends ConfigObject {
 
 
 	public final static Integer DEFAULT_EXECUTORCOUNT = 32;
 	public final static Integer DEFAULT_EXECUTORCOUNT = 32;
 
 
+	public final static Boolean DEFAULT_DELETEPROCESSINUSE = false;
+
+	public final static Boolean DEFAULT_DELETEAPPLICATIONINUSE = false;
+
 	public static ProcessPlatform defaultInstance() {
 	public static ProcessPlatform defaultInstance() {
 		return new ProcessPlatform();
 		return new ProcessPlatform();
 	}
 	}

+ 37 - 14
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/factory/element/ProcessFactory.java

@@ -155,8 +155,7 @@ public class ProcessFactory extends ElementFactory {
 		CriteriaQuery<String> cq = cb.createQuery(String.class);
 		CriteriaQuery<String> cq = cb.createQuery(String.class);
 		Root<Process> root = cq.from(Process.class);
 		Root<Process> root = cq.from(Process.class);
 		Predicate p = cb.equal(root.get(Process_.application), application.getId());
 		Predicate p = cb.equal(root.get(Process_.application), application.getId());
-		p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)),
-				cb.isNull(root.get(Process_.editionEnable))));
+		p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)), cb.isNull(root.get(Process_.editionEnable))));
 		cq.select(root.get(Process_.id)).where(p).distinct(true);
 		cq.select(root.get(Process_.id)).where(p).distinct(true);
 		list = em.createQuery(cq).getResultList();
 		list = em.createQuery(cq).getResultList();
 		return list;
 		return list;
@@ -165,7 +164,6 @@ public class ProcessFactory extends ElementFactory {
 	/* 获取用户可启动的流程,如果applicationId 为空则取到所有可启动流程 */
 	/* 获取用户可启动的流程,如果applicationId 为空则取到所有可启动流程 */
 	public List<String> listStartableWithApplication(EffectivePerson effectivePerson, List<String> identities,
 	public List<String> listStartableWithApplication(EffectivePerson effectivePerson, List<String> identities,
 			List<String> units, Application application) throws Exception {
 			List<String> units, Application application) throws Exception {
-		List<String> list = new ArrayList<>();
 		EntityManager em = this.entityManagerContainer().get(Process.class);
 		EntityManager em = this.entityManagerContainer().get(Process.class);
 		CriteriaBuilder cb = em.getCriteriaBuilder();
 		CriteriaBuilder cb = em.getCriteriaBuilder();
 		CriteriaQuery<String> cq = cb.createQuery(String.class);
 		CriteriaQuery<String> cq = cb.createQuery(String.class);
@@ -184,11 +182,38 @@ public class ProcessFactory extends ElementFactory {
 			}
 			}
 		}
 		}
 		p = cb.and(p, cb.equal(root.get(Process_.application), application.getId()));
 		p = cb.and(p, cb.equal(root.get(Process_.application), application.getId()));
-		p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)),
-				cb.isNull(root.get(Process_.editionEnable))));
+		p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)), cb.isNull(root.get(Process_.editionEnable))));
 		cq.select(root.get(Process_.id)).where(p).distinct(true);
 		cq.select(root.get(Process_.id)).where(p).distinct(true);
-		list = em.createQuery(cq).getResultList();
-		return list;
+		return em.createQuery(cq).getResultList();
+	}
+
+	/* 获取用户可启动的流程,如果applicationId 为空则取到所有可启动流程 */
+	public List<String> listStartableWithApplicationTerminalMobile(EffectivePerson effectivePerson,
+			List<String> identities, List<String> units, Application application) throws Exception {
+		EntityManager em = this.entityManagerContainer().get(Process.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<String> cq = cb.createQuery(String.class);
+		Root<Process> root = cq.from(Process.class);
+		Predicate p = cb.conjunction();
+		if (effectivePerson.isNotManager() && (!this.business().organization().person().hasRole(effectivePerson,
+				OrganizationDefinition.Manager, OrganizationDefinition.ProcessPlatformManager))) {
+			p = cb.and(cb.isEmpty(root.get(Process_.startableIdentityList)),
+					cb.isEmpty(root.get(Process_.startableUnitList)));
+			p = cb.or(p, cb.equal(root.get(Process_.creatorPerson), effectivePerson.getDistinguishedName()));
+			if (ListTools.isNotEmpty(identities)) {
+				p = cb.or(p, root.get(Process_.startableIdentityList).in(identities));
+			}
+			if (ListTools.isNotEmpty(units)) {
+				p = cb.or(p, root.get(Process_.startableUnitList).in(units));
+			}
+		}
+		p = cb.and(p, cb.equal(root.get(Process_.application), application.getId()));
+		p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)), cb.isNull(root.get(Process_.editionEnable))));
+		// 不指名仅在client端可启动那么可启动
+		p = cb.and(p, cb.or(cb.isNull(root.get(Process_.startableTerminal)),
+				cb.notEqual(root.get(Process_.startableTerminal), Process.DEFAULTSTARTABLETERMINAL_CLIENT)));
+		cq.select(root.get(Process_.id)).where(p).distinct(true);
+		return em.createQuery(cq).getResultList();
 	}
 	}
 
 
 	/* 获取用户可启动的流程,如果applicationId 为空则取到所有可启动流程 */
 	/* 获取用户可启动的流程,如果applicationId 为空则取到所有可启动流程 */
@@ -238,11 +263,10 @@ public class ProcessFactory extends ElementFactory {
 		Root<Process> root = cq.from(Process.class);
 		Root<Process> root = cq.from(Process.class);
 		Predicate p = cb.equal(root.get(Process_.application), application);
 		Predicate p = cb.equal(root.get(Process_.application), application);
 		p = cb.and(p, cb.equal(root.get(Process_.edition), edition));
 		p = cb.and(p, cb.equal(root.get(Process_.edition), edition));
-		p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)),
-				cb.isNull(root.get(Process_.editionEnable))));
+		p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)), cb.isNull(root.get(Process_.editionEnable))));
 		cq.select(root).where(p).orderBy(cb.desc(root.get(Process_.editionNumber)));
 		cq.select(root).where(p).orderBy(cb.desc(root.get(Process_.editionNumber)));
 		List<Process> list = em.createQuery(cq).getResultList();
 		List<Process> list = em.createQuery(cq).getResultList();
-		if(list!=null && !list.isEmpty()){
+		if (list != null && !list.isEmpty()) {
 			return list.get(0);
 			return list.get(0);
 		}
 		}
 		return null;
 		return null;
@@ -254,12 +278,11 @@ public class ProcessFactory extends ElementFactory {
 		CriteriaQuery<Process> cq = cb.createQuery(Process.class);
 		CriteriaQuery<Process> cq = cb.createQuery(Process.class);
 		Root<Process> root = cq.from(Process.class);
 		Root<Process> root = cq.from(Process.class);
 		Predicate p = cb.equal(root.get(Process_.application), application);
 		Predicate p = cb.equal(root.get(Process_.application), application);
-		p = cb.and(p, cb.or(cb.equal(root.get(Process_.id), flag),
-				cb.equal(root.get(Process_.name), flag),
+		p = cb.and(p, cb.or(cb.equal(root.get(Process_.id), flag), cb.equal(root.get(Process_.name), flag),
 				cb.equal(root.get(Process_.alias), flag)));
 				cb.equal(root.get(Process_.alias), flag)));
 		cq.select(root).where(p).orderBy(cb.desc(root.get(Process_.editionNumber)));
 		cq.select(root).where(p).orderBy(cb.desc(root.get(Process_.editionNumber)));
 		List<Process> list = em.createQuery(cq).getResultList();
 		List<Process> list = em.createQuery(cq).getResultList();
-		if(list!=null && !list.isEmpty()){
+		if (list != null && !list.isEmpty()) {
 			return list.get(0);
 			return list.get(0);
 		}
 		}
 		return null;
 		return null;
@@ -305,7 +328,7 @@ public class ProcessFactory extends ElementFactory {
 		Root<Process> root = cq.from(Process.class);
 		Root<Process> root = cq.from(Process.class);
 		Predicate p = cb.conjunction();
 		Predicate p = cb.conjunction();
 		p = cb.and(p, root.get(Process_.id).in(processList));
 		p = cb.and(p, root.get(Process_.id).in(processList));
-		if(includeEdition){
+		if (includeEdition) {
 			p = cb.and(p, cb.isNull(root.get(Process_.editionEnable)));
 			p = cb.and(p, cb.isNull(root.get(Process_.editionEnable)));
 			Subquery<Process> subquery = cq.subquery(Process.class);
 			Subquery<Process> subquery = cq.subquery(Process.class);
 			Root<Process> subRoot = subquery.from(Process.class);
 			Root<Process> subRoot = subquery.from(Process.class);

+ 56 - 0
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/process/ActionListWithPersonWithApplicationTerminalMobile.java

@@ -0,0 +1,56 @@
+package com.x.processplatform.assemble.surface.jaxrs.process;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.bean.WrapCopier;
+import com.x.base.core.project.bean.WrapCopierFactory;
+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.tools.SortTools;
+import com.x.processplatform.assemble.surface.Business;
+import com.x.processplatform.core.entity.element.Application;
+import com.x.processplatform.core.entity.element.Process;
+
+class ActionListWithPersonWithApplicationTerminalMobile extends BaseAction {
+
+	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String applicationFlag) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<List<Wo>> result = new ActionResult<>();
+			Business business = new Business(emc);
+			List<Wo> wos = new ArrayList<>();
+			Application application = business.application().pick(applicationFlag);
+			if (null == application) {
+				throw new ExceptionEntityNotExist(applicationFlag, Application.class);
+			}
+			List<String> roles = business.organization().role().listWithPerson(effectivePerson);
+			List<String> identities = business.organization().identity().listWithPerson(effectivePerson);
+			List<String> units = business.organization().unit().listWithPersonSupNested(effectivePerson);
+			if (!business.application().allowRead(effectivePerson, roles, identities, units, application)) {
+				throw new ExceptionAccessDenied(effectivePerson);
+			}
+
+			List<String> ids = business.process().listStartableWithApplicationTerminalMobile(effectivePerson,
+					identities, units, application);
+			for (String id : ids) {
+				wos.add(Wo.copier.copy(business.process().pick(id)));
+			}
+			SortTools.asc(wos, false, "name");
+			result.setData(wos);
+			return result;
+		}
+	}
+
+	public static class Wo extends Process {
+
+		private static final long serialVersionUID = 1521228691441978462L;
+
+		static WrapCopier<Process, Wo> copier = WrapCopierFactory.wo(Process.class, Wo.class, null,
+				JpaObject.FieldsInvisible);
+	}
+}

+ 21 - 5
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/process/ProcessAction.java

@@ -27,7 +27,6 @@ public class ProcessAction extends StandardJaxrsAction {
 
 
 	private static Logger logger = LoggerFactory.getLogger(ProcessAction.class);
 	private static Logger logger = LoggerFactory.getLogger(ProcessAction.class);
 
 
-
 	@JaxrsMethodDescribe(value = "获取流程.", action = ActionGet.class)
 	@JaxrsMethodDescribe(value = "获取流程.", action = ActionGet.class)
 	@GET
 	@GET
 	@Path("{flag}")
 	@Path("{flag}")
@@ -46,8 +45,6 @@ public class ProcessAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 	}
 
 
-
-
 	@JaxrsMethodDescribe(value = "获取流程内容,附带所有的Activity信息", action = ActionGetComplex.class)
 	@JaxrsMethodDescribe(value = "获取流程内容,附带所有的Activity信息", action = ActionGetComplex.class)
 	@GET
 	@GET
 	@Path("{flag}/complex")
 	@Path("{flag}/complex")
@@ -84,7 +81,7 @@ public class ProcessAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 	}
 
 
-	@JaxrsMethodDescribe(value = "根据指定Application获取所有流程.", action = ActionListWithPersonWithApplication.class)
+	@JaxrsMethodDescribe(value = "根据指定Application获取可启动的流程.", action = ActionListWithPersonWithApplication.class)
 	@GET
 	@GET
 	@Path("list/application/{applicationFlag}")
 	@Path("list/application/{applicationFlag}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@@ -103,6 +100,25 @@ public class ProcessAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 	}
 
 
+	@JaxrsMethodDescribe(value = "根据指定Application获取mobile端可启动的流程.", action = ActionListWithPersonWithApplicationTerminalMobile.class)
+	@GET
+	@Path("list/application/{applicationFlag}/terminal/mobile")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void listWithPersonWithApplicationTerminalMobile(@Suspended final AsyncResponse asyncResponse,
+			@Context HttpServletRequest request,
+			@JaxrsParameterDescribe("应用标识") @PathParam("applicationFlag") String applicationFlag) {
+		ActionResult<List<ActionListWithPersonWithApplicationTerminalMobile.Wo>> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionListWithPersonWithApplicationTerminalMobile().execute(effectivePerson, applicationFlag);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
 	@JaxrsMethodDescribe(value = "获取当前用户在指定流程中可启动流程的身份.", action = ActionListAvailableIdentityWithProcess.class)
 	@JaxrsMethodDescribe(value = "获取当前用户在指定流程中可启动流程的身份.", action = ActionListAvailableIdentityWithProcess.class)
 	@GET
 	@GET
 	@Path("list/available/identity/process/{flag}")
 	@Path("list/available/identity/process/{flag}")
@@ -146,7 +162,7 @@ public class ProcessAction extends StandardJaxrsAction {
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
 	@Consumes(MediaType.APPLICATION_JSON)
 	public void ListWithIds(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
 	public void ListWithIds(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
-						JsonElement jsonElement) {
+			JsonElement jsonElement) {
 		ActionResult<List<ActionListWithProcess.Wo>> result = new ActionResult<>();
 		ActionResult<List<ActionListWithProcess.Wo>> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
 		try {

+ 18 - 0
o2server/x_processplatform_core_entity/src/main/java/com/x/processplatform/core/entity/element/Process.java

@@ -49,6 +49,10 @@ public class Process extends SliceJpaObject {
 	public static final String DEFAULTSTARTMODE_DRAFT = "draft";
 	public static final String DEFAULTSTARTMODE_DRAFT = "draft";
 	public static final String DEFAULTSTARTMODE_INSTANCE = "instance";
 	public static final String DEFAULTSTARTMODE_INSTANCE = "instance";
 
 
+	public static final String DEFAULTSTARTABLETERMINAL_CLIENT = "client";
+	public static final String DEFAULTSTARTABLETERMINAL_MOBILE = "mobile";
+	public static final String DEFAULTSTARTABLETERMINAL_BOTH = "both";
+
 	public String getId() {
 	public String getId() {
 		return id;
 		return id;
 	}
 	}
@@ -361,6 +365,12 @@ public class Process extends SliceJpaObject {
 	@CheckPersist(allowEmpty = true)
 	@CheckPersist(allowEmpty = true)
 	private Boolean checkDraft;
 	private Boolean checkDraft;
 
 
+	public static final String startableTerminal_FIELDNAME = "startableTerminal";
+	@FieldDescribe("可启动流程终端类型,可选值 client,mobile,both")
+	@Column(length = JpaObject.length_32B, name = ColumnNamePrefix + startableTerminal_FIELDNAME)
+	@CheckPersist(allowEmpty = true)
+	private String startableTerminal;
+
 	public static final String projection_FIELDNAME = "projection";
 	public static final String projection_FIELDNAME = "projection";
 	@FieldDescribe("字段映射配置.")
 	@FieldDescribe("字段映射配置.")
 	@Lob
 	@Lob
@@ -848,4 +858,12 @@ public class Process extends SliceJpaObject {
 		this.defaultStartMode = defaultStartMode;
 		this.defaultStartMode = defaultStartMode;
 	}
 	}
 
 
+	public String getStartableTerminal() {
+		return startableTerminal;
+	}
+
+	public void setStartableTerminal(String startableTerminal) {
+		this.startableTerminal = startableTerminal;
+	}
+
 }
 }

+ 159 - 0
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/jaxrs/work/V2Reroute copy.java

@@ -0,0 +1,159 @@
+package com.x.processplatform.service.processing.jaxrs.work;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import com.google.gson.JsonElement;
+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.entity.annotation.CheckPersistType;
+import com.x.base.core.entity.annotation.CheckRemoveType;
+import com.x.base.core.project.exception.ExceptionEntityNotExist;
+import com.x.base.core.project.executor.ProcessPlatformExecutorFactory;
+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.ListTools;
+import com.x.processplatform.core.entity.content.Task;
+import com.x.processplatform.core.entity.content.Work;
+import com.x.processplatform.core.entity.content.WorkLog;
+import com.x.processplatform.core.entity.element.Activity;
+import com.x.processplatform.core.entity.element.Form;
+import com.x.processplatform.core.express.service.processing.jaxrs.work.V2RerouteWi;
+import com.x.processplatform.service.processing.Business;
+import com.x.processplatform.service.processing.MessageFactory;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+
+class V2Reroute extends BaseAction {
+
+	private static Logger logger = LoggerFactory.getLogger(V2Reroute.class);
+
+	/**
+	 * @param effectivePerson current person
+	 */
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
+
+		final String job;
+		final Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			Work work = emc.fetch(id, Work.class, ListTools.toList(Work.job_FIELDNAME));
+			if (null == work) {
+				throw new ExceptionEntityNotExist(id, Work.class);
+			}
+			job = work.getJob();
+		}
+		Callable<ActionResult<Wo>> callable = new Callable<ActionResult<Wo>>() {
+			public ActionResult<Wo> call() throws Exception {
+				ActionResult<Wo> result = new ActionResult<>();
+				Work work;
+				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+					Business business = new Business(emc);
+					work = emc.find(id, Work.class);
+					if (null == work) {
+						throw new ExceptionEntityNotExist(id, Work.class);
+					}
+					Activity activity = business.element().getActivity(wi.getActivity());
+					if (!StringUtils.equals(work.getProcess(), activity.getProcess())) {
+						throw new ExceptionProcessNotMatch();
+					}
+					emc.beginTransaction(Work.class);
+					emc.beginTransaction(Task.class);
+					emc.beginTransaction(WorkLog.class);
+					/** 重新设置表单 */
+					setForm(business, work, activity);
+					work.setDestinationActivity(activity.getId());
+					work.setDestinationActivityType(activity.getActivityType());
+					work.setDestinationRoute("");
+					work.setDestinationRouteName("");
+					work.getProperties().setManualForceTaskIdentityList(new ArrayList<String>());
+					if (ListTools.isNotEmpty(wi.getManualForceTaskIdentityList())) {
+						work.getProperties().setManualForceTaskIdentityList(wi.getManualForceTaskIdentityList());
+					}
+					removeTask(business, work);
+					if (BooleanUtils.isTrue(wi.getMergeWork())) {
+						/* 合并工作 */
+						work.setSplitting(false);
+						work.setSplitToken("");
+						work.getSplitTokenList().clear();
+						work.setSplitValue("");
+						removeOtherWork(business, work);
+						removeOtherWorkLog(business, work);
+					}
+					emc.check(work, CheckPersistType.all);
+					emc.commit();
+				}
+
+				Wo wo = new Wo();
+				wo.setValue(true);
+				result.setData(wo);
+				return result;
+			}
+		};
+		return ProcessPlatformExecutorFactory.get(job).submit(callable).get();
+
+	}
+
+	private void setForm(Business business, Work work, Activity activity) throws Exception {
+		if (StringUtils.isNotEmpty(activity.getForm())) {
+			//表单需要重新判断,如果是从模板或者复制过来的流程可能发生表单不存在的情况.
+			Form form = business.entityManagerContainer().find(activity.getForm(), Form.class);
+			if (null!= form){
+				work.setForm(form.getId());
+			}
+		}
+	}
+
+	public static class Wi extends V2RerouteWi {
+
+	}
+
+	public static class Wo extends WrapBoolean {
+	}
+
+	private void removeTask(Business business, Work work) throws Exception {
+		/* 删除可能的待办 */
+		List<Task> os = business.entityManagerContainer().listEqual(Task.class, Task.activityToken_FIELDNAME,
+				work.getActivityToken());
+		os.stream().forEach(o -> {
+			try {
+				business.entityManagerContainer().remove(o, CheckRemoveType.all);
+				MessageFactory.task_delete(o);
+			} catch (Exception e) {
+				logger.error(e);
+			}
+		});
+	}
+
+	private void removeOtherWork(Business business, Work work) throws Exception {
+		List<Work> os = business.entityManagerContainer().listEqualAndNotEqual(Work.class, Work.job_FIELDNAME,
+				work.getJob(), JpaObject.id_FIELDNAME, work.getId());
+		os.stream().forEach(o -> {
+			try {
+				business.entityManagerContainer().remove(o, CheckRemoveType.all);
+				MessageFactory.work_delete(o);
+			} catch (Exception e) {
+				logger.error(e);
+			}
+		});
+	}
+
+	private void removeOtherWorkLog(Business business, Work work) throws Exception {
+		List<WorkLog> os = business.entityManagerContainer().listEqualAndEqualAndNotEqual(WorkLog.class,
+				WorkLog.job_FIELDNAME, work.getJob(), WorkLog.connected_FIELDNAME, false,
+				WorkLog.fromActivity_FIELDNAME, work.getActivity());
+		os.stream().forEach(o -> {
+			try {
+				business.entityManagerContainer().remove(o, CheckRemoveType.all);
+			} catch (Exception e) {
+				logger.error(e);
+			}
+		});
+	}
+
+}

+ 92 - 46
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/jaxrs/work/V2Reroute.java

@@ -48,62 +48,108 @@ class V2Reroute extends BaseAction {
 			}
 			}
 			job = work.getJob();
 			job = work.getJob();
 		}
 		}
-		Callable<ActionResult<Wo>> callable = new Callable<ActionResult<Wo>>() {
-			public ActionResult<Wo> call() throws Exception {
-				ActionResult<Wo> result = new ActionResult<>();
-				Work work;
-				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-					Business business = new Business(emc);
-					work = emc.find(id, Work.class);
-					if (null == work) {
-						throw new ExceptionEntityNotExist(id, Work.class);
-					}
-					Activity activity = business.element().getActivity(wi.getActivity());
-					if (!StringUtils.equals(work.getProcess(), activity.getProcess())) {
-						throw new ExceptionProcessNotMatch();
-					}
-					emc.beginTransaction(Work.class);
-					emc.beginTransaction(Task.class);
-					emc.beginTransaction(WorkLog.class);
-					/** 重新设置表单 */
-					setForm(business, work, activity);
-					work.setDestinationActivity(activity.getId());
-					work.setDestinationActivityType(activity.getActivityType());
-					work.setDestinationRoute("");
-					work.setDestinationRouteName("");
-					work.getProperties().setManualForceTaskIdentityList(new ArrayList<String>());
-					if (ListTools.isNotEmpty(wi.getManualForceTaskIdentityList())) {
-						work.getProperties().setManualForceTaskIdentityList(wi.getManualForceTaskIdentityList());
-					}
-					removeTask(business, work);
-					if (BooleanUtils.isTrue(wi.getMergeWork())) {
-						/* 合并工作 */
-						work.setSplitting(false);
-						work.setSplitToken("");
-						work.getSplitTokenList().clear();
-						work.setSplitValue("");
-						removeOtherWork(business, work);
-						removeOtherWorkLog(business, work);
-					}
-					emc.check(work, CheckPersistType.all);
-					emc.commit();
-				}
 
 
-				Wo wo = new Wo();
-				wo.setValue(true);
-				result.setData(wo);
-				return result;
+		Callable<ActionResult<Wo>> callable = () -> {
+			ActionResult<Wo> result = new ActionResult<>();
+			Work work;
+			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+				Business business = new Business(emc);
+				work = emc.find(id, Work.class);
+				if (null == work) {
+					throw new ExceptionEntityNotExist(id, Work.class);
+				}
+				Activity activity = business.element().getActivity(wi.getActivity());
+				if (!StringUtils.equals(work.getProcess(), activity.getProcess())) {
+					throw new ExceptionProcessNotMatch();
+				}
+				emc.beginTransaction(Work.class);
+				emc.beginTransaction(Task.class);
+				emc.beginTransaction(WorkLog.class);
+				/** 重新设置表单 */
+				setForm(business, work, activity);
+				work.setDestinationActivity(activity.getId());
+				work.setDestinationActivityType(activity.getActivityType());
+				work.setDestinationRoute("");
+				work.setDestinationRouteName("");
+				work.getProperties().setManualForceTaskIdentityList(new ArrayList<String>());
+				if (ListTools.isNotEmpty(wi.getManualForceTaskIdentityList())) {
+					work.getProperties().setManualForceTaskIdentityList(wi.getManualForceTaskIdentityList());
+				}
+				removeTask(business, work);
+				if (BooleanUtils.isTrue(wi.getMergeWork())) {
+					/* 合并工作 */
+					work.setSplitting(false);
+					work.setSplitToken("");
+					work.getSplitTokenList().clear();
+					work.setSplitValue("");
+					removeOtherWork(business, work);
+					removeOtherWorkLog(business, work);
+				}
+				emc.check(work, CheckPersistType.all);
+				emc.commit();
 			}
 			}
+			Wo wo = new Wo();
+			wo.setValue(true);
+			result.setData(wo);
+			return result;
 		};
 		};
+		// Callable<ActionResult<Wo>> callable = new Callable<ActionResult<Wo>>() {
+		// public ActionResult<Wo> call() throws Exception {
+		// ActionResult<Wo> result = new ActionResult<>();
+		// Work work;
+		// try (EntityManagerContainer emc =
+		// EntityManagerContainerFactory.instance().create()) {
+		// Business business = new Business(emc);
+		// work = emc.find(id, Work.class);
+		// if (null == work) {
+		// throw new ExceptionEntityNotExist(id, Work.class);
+		// }
+		// Activity activity = business.element().getActivity(wi.getActivity());
+		// if (!StringUtils.equals(work.getProcess(), activity.getProcess())) {
+		// throw new ExceptionProcessNotMatch();
+		// }
+		// emc.beginTransaction(Work.class);
+		// emc.beginTransaction(Task.class);
+		// emc.beginTransaction(WorkLog.class);
+		// /** 重新设置表单 */
+		// setForm(business, work, activity);
+		// work.setDestinationActivity(activity.getId());
+		// work.setDestinationActivityType(activity.getActivityType());
+		// work.setDestinationRoute("");
+		// work.setDestinationRouteName("");
+		// work.getProperties().setManualForceTaskIdentityList(new ArrayList<String>());
+		// if (ListTools.isNotEmpty(wi.getManualForceTaskIdentityList())) {
+		// work.getProperties().setManualForceTaskIdentityList(wi.getManualForceTaskIdentityList());
+		// }
+		// removeTask(business, work);
+		// if (BooleanUtils.isTrue(wi.getMergeWork())) {
+		// /* 合并工作 */
+		// work.setSplitting(false);
+		// work.setSplitToken("");
+		// work.getSplitTokenList().clear();
+		// work.setSplitValue("");
+		// removeOtherWork(business, work);
+		// removeOtherWorkLog(business, work);
+		// }
+		// emc.check(work, CheckPersistType.all);
+		// emc.commit();
+		// }
+
+		// Wo wo = new Wo();
+		// wo.setValue(true);
+		// result.setData(wo);
+		// return result;
+		// }
+		// };
 		return ProcessPlatformExecutorFactory.get(job).submit(callable).get();
 		return ProcessPlatformExecutorFactory.get(job).submit(callable).get();
 
 
 	}
 	}
 
 
 	private void setForm(Business business, Work work, Activity activity) throws Exception {
 	private void setForm(Business business, Work work, Activity activity) throws Exception {
 		if (StringUtils.isNotEmpty(activity.getForm())) {
 		if (StringUtils.isNotEmpty(activity.getForm())) {
-			//表单需要重新判断,如果是从模板或者复制过来的流程可能发生表单不存在的情况.
+			// 表单需要重新判断,如果是从模板或者复制过来的流程可能发生表单不存在的情况.
 			Form form = business.entityManagerContainer().find(activity.getForm(), Form.class);
 			Form form = business.entityManagerContainer().find(activity.getForm(), Form.class);
-			if (null!= form){
+			if (null != form) {
 				work.setForm(form.getId());
 				work.setForm(form.getId());
 			}
 			}
 		}
 		}