提交 d21b44a3 编写于 作者: O o2null

Merge branch 'feat/task' into 'develop'

Merge branch 'cherry-pick-90930e11' into 'develop'

See merge request o2oa/o2oa!662
......@@ -39,6 +39,7 @@ import com.x.base.core.entity.tools.JpaObjectTools;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.NumberTools;
import com.x.base.core.project.tools.StringTools;
......@@ -1144,7 +1145,7 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
List<Tuple> list = em.createQuery(cq).setMaxResults(1).getResultList();
if (!list.isEmpty()) {
Tuple tuple = list.get(0);
t = clz.newInstance();
t = clz.getDeclaredConstructor().newInstance();
for (int i = 0; i < selections.size(); i++) {
PropertyUtils.setProperty(t, attributes.get(i), tuple.get(selections.get(i)));
}
......
......@@ -3,11 +3,12 @@ package com.x.base.core.project.processplatform;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
......@@ -20,6 +21,12 @@ public class ManualTaskIdentityMatrix extends GsonPropertyObject {
private Matrix matrix = new Matrix();
public static final String ADD_POSITION_BEFORE = "before";
public static final String ADD_POSITION_AFTER = "after";
public static final String ADD_POSITION_TOP = "top";
public static final String ADD_POSITION_BOTTOM = "bottom";
public static final String ADD_POSITION_EXTEND = "extend";
public static ManualTaskIdentityMatrix concreteSingleRow(List<String> list) {
ManualTaskIdentityMatrix manualTaskIdentityMatrix = new ManualTaskIdentityMatrix();
Row row = new Row();
......@@ -46,52 +53,50 @@ public class ManualTaskIdentityMatrix extends GsonPropertyObject {
return manualTaskIdentityMatrix;
}
public ManualTaskIdentityMatrix extend(String identity, boolean replace, List<String> list) {
for (Row row : matrix) {
int idx = row.indexOf(identity);
if (idx > -1) {
row.addAll(idx + 1, list);
if (replace) {
row.remove(idx);
public ManualTaskIdentityMatrix add(String identity, String position, List<String> list) {
List<String> identities = ListTools.trim(list, true, true);
if (ListTools.isEmpty(identities)) {
return this;
}
if (StringUtils.equals(ADD_POSITION_TOP, position)) {
Row row = new Row();
row.addAll(ListTools.trim(list, true, true));
matrix.add(0, row);
} else if (StringUtils.equals(ADD_POSITION_BOTTOM, position)) {
Row row = new Row();
row.addAll(ListTools.trim(list, true, true));
matrix.add(row);
} else {
int rowpos = 0;
int colpos = -1;
for (Row row : matrix) {
colpos = row.indexOf(identity);
if (colpos > -1) {
break;
} else {
rowpos++;
}
break;
}
}
return this;
}
public ManualTaskIdentityMatrix extend(String identity, boolean replace, String... arr) {
return this.extend(identity, replace, Arrays.asList(arr));
}
public ManualTaskIdentityMatrix add(String identity, boolean after, boolean replace, List<String> list) {
int rowpos = 0;
int colpos = -1;
for (Row row : matrix) {
colpos = row.indexOf(identity);
if (colpos > -1) {
break;
} else {
rowpos++;
addBeforeAfterExtend(position, identities, rowpos, colpos);
}
}
if (replace && (colpos > -1)) {
matrix.get(rowpos).remove(colpos);
}
if (after) {
rowpos++;
}
for (String str : list) {
Row row = new Row();
row.add(str);
matrix.add(rowpos++, row);
}
compact();
return this;
}
public ManualTaskIdentityMatrix add(String identity, boolean after, boolean replace, String... arr) {
return this.add(identity, after, replace, Arrays.asList(arr));
private void addBeforeAfterExtend(String position, List<String> identities, int rowpos, int colpos) {
if (StringUtils.equals(ADD_POSITION_BEFORE, position)) {
Row row = new Row();
row.addAll(identities);
matrix.add(rowpos, row);
} else if (StringUtils.equals(ADD_POSITION_AFTER, position)) {
Row row = new Row();
row.addAll(identities);
matrix.add(rowpos + 1, row);
} else {
matrix.get(rowpos).addAll(colpos + 1, identities);
}
}
public ManualTaskIdentityMatrix reset(String identity, List<String> addBeforeIdentities,
......@@ -107,13 +112,13 @@ public class ManualTaskIdentityMatrix extends GsonPropertyObject {
}
}
if (colpos > -1) {
resetUpdate(rowpos, colpos, addBeforeIdentities, extendIdentities, addAfterIdentities);
resetUpdate(rowpos, colpos, addBeforeIdentities, extendIdentities, addAfterIdentities, remove);
}
return this;
}
private void resetUpdate(int rowpos, int colpos, List<String> addBeforeIdentities, List<String> extendIdentities,
List<String> addAfterIdentities) {
List<String> addAfterIdentities, boolean remove) {
if ((null != addBeforeIdentities) && (!addBeforeIdentities.isEmpty())) {
for (String str : addBeforeIdentities) {
Row row = new Row();
......@@ -124,6 +129,9 @@ public class ManualTaskIdentityMatrix extends GsonPropertyObject {
if ((null != extendIdentities) && (!extendIdentities.isEmpty())) {
matrix.get(rowpos).addAll(colpos + 1, extendIdentities);
}
if (remove) {
matrix.get(rowpos).remove();
}
if ((null != addAfterIdentities) && (!addAfterIdentities.isEmpty())) {
for (String str : addAfterIdentities) {
Row row = new Row();
......@@ -172,12 +180,13 @@ public class ManualTaskIdentityMatrix extends GsonPropertyObject {
*/
public List<String> completed(String identity) {
List<String> list = new ArrayList<>();
matrix.stream().forEach(row -> {
for (Row row : matrix) {
if (row.contains(identity)) {
list.addAll(row);
row.clear();
break;
}
});
}
compact();
return ListTools.trim(list, true, true);
}
......@@ -189,13 +198,24 @@ public class ManualTaskIdentityMatrix extends GsonPropertyObject {
* @return
*/
public List<String> completed(List<String> identities) {
Set<Row> rows = new HashSet<>();
for (String identity : identities) {
for (Row row : matrix) {
if (row.contains(identity)) {
rows.add(row);
break;
}
}
}
List<String> list = new ArrayList<>();
matrix.stream().forEach(row -> {
if (!ListUtils.intersection(identities, row).isEmpty()) {
Iterator<Row> rowIterator = matrix.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
if (rows.contains(row)) {
rowIterator.remove();
list.addAll(row);
row.clear();
}
});
}
compact();
return ListTools.trim(list, true, true);
}
......
......@@ -929,15 +929,15 @@ public class TaskAction extends StandardJaxrsAction {
@JaxrsMethodDescribe(value = "V2_重置待办,将之前的待办转为已办,opinion:办理意见,routeName:选择路由,identityList:新的办理人.", action = V2Reset.class)
@PUT
@Path("v2/reset")
@Path("v2/{id}/reset")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void V2Reset(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
@JaxrsParameterDescribe("标识") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<V2Reset.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Reset().execute(effectivePerson, jsonElement);
result = new V2Reset().execute(effectivePerson, id, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
......@@ -947,15 +947,15 @@ public class TaskAction extends StandardJaxrsAction {
@JaxrsMethodDescribe(value = "Mock Post To Put.", action = V2Reset.class)
@POST
@Path("v2/reset/mockputtopost")
@Path("v2/{id}/reset/mockputtopost")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void V2ResetMockPutToPost(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
public void v2ResetMockPutToPost(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<V2Reset.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Reset().execute(effectivePerson, jsonElement);
result = new V2Reset().execute(effectivePerson, id, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
......@@ -1057,35 +1057,17 @@ public class TaskAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "V2_在指定待办位置扩充处理人.", action = V2Extend.class)
@POST
@Path("v2/extend")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void v2Extend(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<V2Extend.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Extend().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "V2_在指定待办位置新增处理人.", action = V2Add.class)
@POST
@Path("v2/add")
@Path("v2/{id}/add")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void v2Add(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
@JaxrsParameterDescribe("标识") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<V2Add.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Add().execute(effectivePerson, jsonElement);
result = new V2Add().execute(effectivePerson, id, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
......
......@@ -14,8 +14,10 @@ import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.Applications;
import com.x.base.core.project.x_processplatform_service_processing;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
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.jaxrs.WoId;
......@@ -35,8 +37,9 @@ import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.content.WorkLog;
import com.x.processplatform.core.express.ProcessingAttributes;
import com.x.processplatform.core.express.assemble.surface.jaxrs.work.V2AddManualTaskIdentityMatrixWi;
import com.x.processplatform.core.express.assemble.surface.jaxrs.work.V2AddManualTaskIdentityMatrixWi.Option;
import com.x.processplatform.core.express.service.processing.jaxrs.task.ProcessingWi;
import com.x.processplatform.core.express.service.processing.jaxrs.task.V2AddWi;
import com.x.processplatform.core.express.service.processing.jaxrs.task.WrapUpdatePrevTaskIdentity;
import com.x.processplatform.core.express.service.processing.jaxrs.taskcompleted.WrapUpdateNextTaskIdentity;
......@@ -45,8 +48,6 @@ public class V2Add extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(V2Add.class);
// 当前提交的串号
private final String series = StringTools.uniqueToken();
// 新加入的身份列表
private List<String> identites = new ArrayList<>();
// 新创建的待办标识列表
private List<String> newTasks = new ArrayList<>();
// 当前待办转成已办得到的已办id
......@@ -64,13 +65,13 @@ public class V2Add extends BaseAction {
// 本环节创建的record
private Record concreteRecord = null;
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
}
this.init(effectivePerson, jsonElement);
this.add(this.task, wi.getAfter(), wi.getReplace(), identites);
if (BooleanUtils.isTrue(wi.getReplace())) {
this.init(effectivePerson, id, jsonElement);
this.add(this.task, wi.getOptionList(), wi.getRemove());
if (BooleanUtils.isTrue(wi.getRemove())) {
taskCompletedId = this.processingTask(this.task);
}
this.processingWork(this.task);
......@@ -82,14 +83,14 @@ public class V2Add extends BaseAction {
return result();
}
private void init(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
private void init(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
this.effectivePerson = effectivePerson;
this.wi = this.convertToWrapIn(jsonElement, Wi.class);
this.task = emc.find(wi.getTask(), Task.class);
this.task = emc.find(id, Task.class);
if (null == task) {
throw new ExceptionEntityNotExist(wi.getTask(), Task.class);
throw new ExceptionEntityNotExist(id, Task.class);
}
if (emc.countEqual(Work.class, JpaObject.id_FIELDNAME, task.getWork()) < 1) {
throw new ExceptionEntityNotExist(task.getWork(), Work.class);
......@@ -105,24 +106,17 @@ public class V2Add extends BaseAction {
}
this.existTaskIds = emc.idsEqualAndEqual(Task.class, Task.job_FIELDNAME, task.getJob(), Task.work_FIELDNAME,
task.getWork());
this.identites = business.organization().identity().list(wi.getIdentityList());
// 在新扩充待办人员中去除已经有待办人员
identites.remove(task.getIdentity());
if (ListTools.isEmpty(identites)) {
throw new ExceptionIdentityEmpty();
}
}
}
private void add(Task task, Boolean after, Boolean replace, List<String> identites) throws Exception {
V2AddWi req = new V2AddWi();
req.setTask(task.getId());
req.setAfter(after);
req.setReplace(replace);
req.setIdentityList(identites);
private void add(Task task, List<V2AddManualTaskIdentityMatrixWi.Option> options, Boolean remove) throws Exception {
V2AddManualTaskIdentityMatrixWi req = new V2AddManualTaskIdentityMatrixWi();
req.setIdentity(task.getIdentity());
req.setOptionList(options);
req.setRemove(remove);
WrapBoolean resp = ThisApplication.context().applications()
.postQuery(x_processplatform_service_processing.class, Applications.joinQueryUri("task", "v2", "add"),
req, task.getJob())
.postQuery(x_processplatform_service_processing.class, Applications.joinQueryUri("work", "v2",
task.getWork(), "add", "manual", "task", "identity", "matrix"), req, task.getJob())
.getData(WrapBoolean.class);
if (BooleanUtils.isNotTrue(resp.getValue())) {
throw new ExceptionAdd(task.getId());
......@@ -241,10 +235,32 @@ public class V2Add extends BaseAction {
return result;
}
public static class Wi extends V2AddWi {
public static class Wi extends GsonPropertyObject {
private static final long serialVersionUID = -6251874269093504136L;
@FieldDescribe("操作")
private List<Option> optionList;
@FieldDescribe("是否删除指定待办身份")
private Boolean remove;
public List<Option> getOptionList() {
return optionList;
}
public void setOptionList(List<Option> optionList) {
this.optionList = optionList;
}
public Boolean getRemove() {
return remove;
}
public void setRemove(Boolean remove) {
this.remove = remove;
}
}
public static class WoControl extends WorkControl {
......
package com.x.processplatform.assemble.surface.jaxrs.task;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
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.project.Applications;
import com.x.base.core.project.x_processplatform_service_processing;
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.ListTools;
import com.x.base.core.project.tools.StringTools;
import com.x.processplatform.assemble.surface.Business;
import com.x.processplatform.assemble.surface.ThisApplication;
import com.x.processplatform.assemble.surface.WorkControl;
import com.x.processplatform.core.entity.content.Record;
import com.x.processplatform.core.entity.content.RecordProperties.NextManual;
import com.x.processplatform.core.entity.content.Task;
import com.x.processplatform.core.entity.content.TaskCompleted;
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.content.WorkLog;
import com.x.processplatform.core.express.ProcessingAttributes;
import com.x.processplatform.core.express.service.processing.jaxrs.task.ProcessingWi;
import com.x.processplatform.core.express.service.processing.jaxrs.task.V2ExtendWi;
import com.x.processplatform.core.express.service.processing.jaxrs.task.WrapUpdatePrevTaskIdentity;
import com.x.processplatform.core.express.service.processing.jaxrs.taskcompleted.WrapUpdateNextTaskIdentity;
public class V2Extend extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(V2Extend.class);
// 当前提交的串号
private final String series = StringTools.uniqueToken();
// 新加入的身份列表
private List<String> identites = new ArrayList<>();
// 新创建的待办标识列表
private List<String> newTasks = new ArrayList<>();
// 当前待办转成已办得到的已办id
private String taskCompletedId;
// 已经存在的待办标识列表
private List<String> existTaskIds = new ArrayList<>();
// 输入
private Wi wi;
// 当前执行用户
private EffectivePerson effectivePerson;
// 根据输入得到的待办
private Task task = null;
// 当前待办的workLog
private WorkLog workLog = null;
// 本环节创建的record
private Record concreteRecord = null;
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
}
this.init(effectivePerson, jsonElement);
this.extend(this.task, wi.getReplace(), identites);
if (BooleanUtils.isTrue(wi.getReplace())) {
taskCompletedId = this.processingTask(this.task);
}
this.processingWork(this.task);
this.createRecord(task, workLog);
if (StringUtils.isNotEmpty(taskCompletedId)) {
this.updateTaskCompleted();
}
this.updateTask();
return result();
}
private void init(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
this.effectivePerson = effectivePerson;
this.wi = this.convertToWrapIn(jsonElement, Wi.class);
this.task = emc.find(wi.getTask(), Task.class);
if (null == task) {
throw new ExceptionEntityNotExist(wi.getTask(), Task.class);
}
if (emc.countEqual(Work.class, JpaObject.id_FIELDNAME, task.getWork()) < 1) {
throw new ExceptionEntityNotExist(task.getWork(), Work.class);
}
this.workLog = emc.firstEqualAndEqual(WorkLog.class, WorkLog.job_FIELDNAME, task.getJob(),
WorkLog.fromActivityToken_FIELDNAME, task.getActivityToken());
if (null == workLog) {
throw new ExceptionEntityNotExist(WorkLog.class);
}
WoControl control = business.getControl(effectivePerson, task, WoControl.class);
if (BooleanUtils.isNotTrue(control.getAllowReset())) {
throw new ExceptionAccessDenied(effectivePerson, task);
}
this.existTaskIds = emc.idsEqualAndEqual(Task.class, Task.job_FIELDNAME, task.getJob(), Task.work_FIELDNAME,
task.getWork());
this.identites = business.organization().identity().list(wi.getIdentityList());
// 在新扩充待办人员中去除已经有待办人员
identites.remove(task.getIdentity());
if (ListTools.isEmpty(identites)) {
throw new ExceptionIdentityEmpty();
}
}
}
private void extend(Task task, Boolean replace, List<String> identites) throws Exception {
V2ExtendWi req = new V2ExtendWi();
req.setTask(task.getId());
req.setReplace(replace);
req.setIdentityList(identites);
WrapBoolean resp = ThisApplication.context().applications()
.postQuery(x_processplatform_service_processing.class,
Applications.joinQueryUri("task", "v2", "extend"), req, task.getJob())
.getData(WrapBoolean.class);
if (BooleanUtils.isNotTrue(resp.getValue())) {
throw new ExceptionExtend(task.getId());
}
}
private String processingTask(Task task) throws Exception {
ProcessingWi req = new ProcessingWi();
req.setProcessingType(TaskCompleted.PROCESSINGTYPE_EXTEND);
WoId resp = ThisApplication.context().applications()
.putQuery(x_processplatform_service_processing.class,
Applications.joinQueryUri("task", task.getId(), "processing"), req, task.getJob())
.getData(WoId.class);
if (StringUtils.isEmpty(resp.getId())) {
throw new ExceptionTaskProcessing(task.getId());
} else {
return resp.getId();
}
}
private void processingWork(Task task) throws Exception {
ProcessingAttributes req = new ProcessingAttributes();
req.setType(ProcessingAttributes.TYPE_TASKEXTEND);
req.setSeries(this.series);
WoId resp = ThisApplication.context().applications()
.putQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class,
Applications.joinQueryUri("work", task.getWork(), "processing"), req, task.getJob())
.getData(WoId.class);
if (StringUtils.isEmpty(resp.getId())) {
throw new ExceptionWorkProcessing(task.getWork());
}
}
private void createRecord(Task task, WorkLog workLog) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
concreteRecord = new Record(workLog, task);
// 校验workCompleted,如果存在,那么说明工作已经完成,标识状态为已经完成.
WorkCompleted workCompleted = emc.firstEqual(WorkCompleted.class, WorkCompleted.job_FIELDNAME,
task.getJob());
if (null != workCompleted) {
concreteRecord.setCompleted(true);
concreteRecord.setWorkCompleted(workCompleted.getId());
}
concreteRecord.setPerson(effectivePerson.getDistinguishedName());
concreteRecord.setType(Record.TYPE_TASKEXTEND);
createRecordAdjust(business, task, concreteRecord);
}
WoId resp = ThisApplication.context().applications()
.postQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class,
Applications.joinQueryUri("record", "job", task.getJob()), concreteRecord, task.getJob())
.getData(WoId.class);
if (StringUtils.isBlank(resp.getId())) {
throw new ExceptionExtend(task.getId());
}
}
private void createRecordAdjust(Business business, Task task, Record concreteRecord) throws Exception {
List<String> ids = business.entityManagerContainer().idsEqualAndEqual(Task.class, Task.job_FIELDNAME,
task.getJob(), Task.work_FIELDNAME, task.getWork());
ids = ListUtils.subtract(ids, existTaskIds);
List<Task> list = business.entityManagerContainer().fetch(ids, Task.class,
ListTools.toList(Task.identity_FIELDNAME, Task.job_FIELDNAME, Task.work_FIELDNAME,
Task.activity_FIELDNAME, Task.activityAlias_FIELDNAME, Task.activityName_FIELDNAME,
Task.activityToken_FIELDNAME, Task.activityType_FIELDNAME, Task.identity_FIELDNAME));
final List<String> nextTaskIdentities = new ArrayList<>();
list.stream().collect(Collectors.groupingBy(Task::getActivity, Collectors.toList())).entrySet().stream()
.forEach(o -> {
Task next = o.getValue().get(0);
NextManual nextManual = new NextManual();
nextManual.setActivity(next.getActivity());
nextManual.setActivityAlias(next.getActivityAlias());
nextManual.setActivityName(next.getActivityName());
nextManual.setActivityToken(next.getActivityToken());
nextManual.setActivityType(next.getActivityType());
for (Task t : o.getValue()) {
nextManual.getTaskIdentityList().add(t.getIdentity());
nextTaskIdentities.add(t.getIdentity());
}
concreteRecord.getProperties().getNextManualList().add(nextManual);
});
// 去重
concreteRecord.getProperties().setNextManualTaskIdentityList(ListTools.trim(nextTaskIdentities, true, true));
}
private void updateTaskCompleted() throws Exception {
// 记录下一处理人信息
WrapUpdateNextTaskIdentity req = new WrapUpdateNextTaskIdentity();
req.getTaskCompletedList().add(this.taskCompletedId);
req.setNextTaskIdentityList(concreteRecord.getProperties().getNextManualTaskIdentityList());
ThisApplication.context().applications()
.putQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class,
Applications.joinQueryUri("taskcompleted", "next", "task", "identity"), req, task.getJob())
.getData(WrapBoolean.class);
}
private void updateTask() throws Exception {
// 记录上一处理人信息
if (ListTools.isNotEmpty(newTasks)) {
WrapUpdatePrevTaskIdentity req = new WrapUpdatePrevTaskIdentity();
req.setTaskList(newTasks);
req.setPrevTaskIdentity(task.getIdentity());
req.getPrevTaskIdentityList().add(task.getIdentity());
ThisApplication.context().applications()
.putQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class,
Applications.joinQueryUri("task", "prev", "task", "identity"), req, task.getJob())
.getData(WrapBoolean.class);
}
}
private ActionResult<Wo> result() {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
wo.setValue(true);
result.setData(wo);
return result;
}
public static class Wi extends V2ExtendWi {
private static final long serialVersionUID = -3241215869441470402L;
}
public static class WoControl extends WorkControl {
private static final long serialVersionUID = -8781558581462660831L;
}
public static class Wo extends WrapBoolean {
private static final long serialVersionUID = 4883624438858385234L;
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.x.processplatform.assemble.surface.jaxrs.task;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -22,6 +23,7 @@ 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.processplatform.ManualTaskIdentityMatrix;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.StringTools;
import com.x.processplatform.assemble.surface.Business;
......@@ -32,7 +34,11 @@ import com.x.processplatform.core.entity.content.Task;
import com.x.processplatform.core.entity.content.TaskCompleted;
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkLog;
import com.x.processplatform.core.entity.element.ActivityType;
import com.x.processplatform.core.entity.element.Manual;
import com.x.processplatform.core.entity.element.ManualMode;
import com.x.processplatform.core.express.ProcessingAttributes;
import com.x.processplatform.core.express.assemble.surface.jaxrs.work.V2AddManualTaskIdentityMatrixWi;
import com.x.processplatform.core.express.service.processing.jaxrs.task.ProcessingWi;
import com.x.processplatform.core.express.service.processing.jaxrs.task.V2ResetWi;
......@@ -42,10 +48,14 @@ public class V2Reset extends BaseAction {
// 当前的待办
private Task task;
// 添加的身份
private List<String> identities;
// 当前的workLog,产生record必须
private WorkLog workLog;
// 当前的work
private Work work;
// work活动
private Manual manual;
// 如果在待办身份矩阵中删除自己,那么先把自己的待办转为不参与流程的已办
private List<TaskCompleted> taskCompleteds;
private final String series = StringTools.uniqueToken();
......@@ -53,7 +63,7 @@ public class V2Reset extends BaseAction {
private Wi wi;
private EffectivePerson effectivePerson;
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
ActionResult<Wo> result = new ActionResult<>();
this.wi = this.convertToWrapIn(jsonElement, Wi.class);
......@@ -61,7 +71,7 @@ public class V2Reset extends BaseAction {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
init(business, wi.getTask());
init(business, id, wi);
WoControl control = business.getControl(effectivePerson, this.task, WoControl.class);
......@@ -70,9 +80,9 @@ public class V2Reset extends BaseAction {
}
}
this.reset();
this.reset(this.task, (!wi.getKeep()), identities, manual);
if (BooleanUtils.isTrue(wi.getRemove())) {
if (BooleanUtils.isNotTrue(wi.getKeep())) {
this.processingTask();
}
......@@ -100,26 +110,27 @@ public class V2Reset extends BaseAction {
return result;
}
private void init(Business business, String id) throws Exception {
private void init(Business business, String id, Wi wi) throws Exception {
this.task = business.entityManagerContainer().find(id, Task.class);
if (null == task) {
throw new ExceptionEntityNotExist(id, Task.class);
}
this.workLog = business.entityManagerContainer().firstEqualAndEqual(WorkLog.class, WorkLog.job_FIELDNAME,
task.getJob(), WorkLog.fromActivityToken_FIELDNAME, task.getActivityToken());
if (null == workLog) {
throw new ExceptionEntityNotExist(WorkLog.class);
}
this.work = business.entityManagerContainer().find(task.getWork(), Work.class);
if (null == work) {
throw new ExceptionEntityNotExist(id, Work.class);
}
if (!work.getManualTaskIdentityMatrix().contains(task.getIdentity())) {
throw new ExceptionIdentityNotInMatrix(task.getIdentity());
}
this.manual = (Manual) business.getActivity(work.getActivity(), ActivityType.manual);
this.identities = ListTools.trim(business.organization().identity().list(wi.getIdentityList()), true, true);
// 为办理的前的所有已办,用于在record中记录当前待办转为已办时的上一处理人
this.taskCompleteds = business.entityManagerContainer().listEqual(TaskCompleted.class,
TaskCompleted.activityToken_FIELDNAME, task.getActivityToken());
......@@ -141,16 +152,24 @@ public class V2Reset extends BaseAction {
}
}
private void reset() throws Exception {
V2ResetWi req = new V2ResetWi();
req.setAddBeforeList(this.wi.getAddBeforeList());
req.setExtendList(this.wi.getExtendList());
req.setAddAfterList(this.wi.getAddAfterList());
req.setRemove(this.wi.getRemove());
req.setTask(this.wi.getTask());
WrapBoolean resp = ThisApplication
.context().applications().putQuery(x_processplatform_service_processing.class,
Applications.joinQueryUri("task", "v2", "reset"), req, task.getJob())
private void reset(Task task, boolean remove, List<String> identities, Manual manual) throws Exception {
V2AddManualTaskIdentityMatrixWi req = new V2AddManualTaskIdentityMatrixWi();
req.setIdentity(task.getIdentity());
req.setRemove(remove);
V2AddManualTaskIdentityMatrixWi.Option option = new V2AddManualTaskIdentityMatrixWi.Option();
option.setIdentityList(identities);
if (Objects.equals(ManualMode.single, manual.getManualMode())
|| Objects.equals(ManualMode.grab, manual.getManualMode())) {
option.setPosition(ManualTaskIdentityMatrix.ADD_POSITION_EXTEND);
} else {
option.setPosition(ManualTaskIdentityMatrix.ADD_POSITION_AFTER);
}
List<V2AddManualTaskIdentityMatrixWi.Option> optionList = new ArrayList<>();
optionList.add(option);
req.setOptionList(optionList);
WrapBoolean resp = ThisApplication.context().applications()
.postQuery(x_processplatform_service_processing.class, Applications.joinQueryUri("work", "v2",
task.getWork(), "add", "manual", "task", "identity", "matrix"), req, task.getJob())
.getData(WrapBoolean.class);
if (BooleanUtils.isNotTrue(resp.getValue())) {
throw new ExceptionReset(task.getId());
......
package com.x.processplatform.assemble.surface.jaxrs.work;
import com.x.base.core.project.exception.LanguagePromptException;
class ExceptionAddManualTaskIdentityMatrix extends LanguagePromptException {
private static final long serialVersionUID = -9089355008820123519L;
ExceptionAddManualTaskIdentityMatrix(String workId) {
super("添加待办身份错误, work:{}.", workId);
}
}
package com.x.processplatform.assemble.surface.jaxrs.work;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.exception.LanguagePromptException;
class ExceptionEmptyIdentity extends LanguagePromptException {
private static final long serialVersionUID = 1040883405179987063L;
ExceptionEmptyIdentity(List<String> identities) {
super("指定的身份不存在或者为空:{}.", StringUtils.join(identities, ","));
}
ExceptionEmptyIdentity(String identity) {
super("指定的身份不存在或者为空:{}.", identity);
}
}
package com.x.processplatform.assemble.surface.jaxrs.work;
import com.x.base.core.project.exception.LanguagePromptException;
class ExceptionProcessingWork extends LanguagePromptException {
private static final long serialVersionUID = -9089355008820123519L;
ExceptionProcessingWork(String workId) {
super("流转工作错误, work:{}.", workId);
}
}
package com.x.processplatform.assemble.surface.jaxrs.work;
import java.util.List;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
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.project.Applications;
import com.x.base.core.project.x_processplatform_service_processing;
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.StringTools;
import com.x.processplatform.assemble.surface.Business;
import com.x.processplatform.assemble.surface.ThisApplication;
import com.x.processplatform.assemble.surface.WorkControl;
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.express.ProcessingAttributes;
import com.x.processplatform.core.express.assemble.surface.jaxrs.work.V2AddManualTaskIdentityMatrixWi;
class V2AddManualTaskIdentityMatrix extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(V2AddManualTaskIdentityMatrix.class);
// 当前提交的串号
private final String series = StringTools.uniqueToken();
private Wi wi;
// 当前执行用户
private EffectivePerson effectivePerson;
// 根据输入得到的待办
private Work work = null;
// 指定的身份
private String identity = null;
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
}
this.init(effectivePerson, id, jsonElement);
this.add(wi.getOptionList(), wi.getRemove());
this.processingWork(work);
return result();
}
private void init(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
this.effectivePerson = effectivePerson;
this.wi = this.convertToWrapIn(jsonElement, Wi.class);
this.work = emc.find(id, Work.class);
if (null == work) {
throw new ExceptionEntityNotExist(id, Work.class);
}
WoControl control = business.getControl(effectivePerson, work, WoControl.class);
if (BooleanUtils.isNotTrue(control.getAllowReset())) {
throw new ExceptionAccessDenied(effectivePerson, work);
}
this.identity = business.organization().identity().get(wi.getIdentity());
}
}
private void add(List<V2AddManualTaskIdentityMatrixWi.Option> options, Boolean remove) throws Exception {
V2AddManualTaskIdentityMatrixWi req = new V2AddManualTaskIdentityMatrixWi();
req.setIdentity(identity);
req.setOptionList(options);
req.setRemove(remove);
WrapBoolean resp = ThisApplication.context().applications()
.postQuery(x_processplatform_service_processing.class, Applications.joinQueryUri("work", "v2",
work.getId(), "add", "manual", "task", "identity", "matrix"), req, work.getJob())
.getData(WrapBoolean.class);
if (BooleanUtils.isNotTrue(resp.getValue())) {
throw new ExceptionAddManualTaskIdentityMatrix(work.getId());
}
}
private void processingWork(Work work) throws Exception {
ProcessingAttributes req = new ProcessingAttributes();
req.setType(ProcessingAttributes.TYPE_TASKADD);
req.setSeries(this.series);
WoId resp = ThisApplication.context().applications()
.putQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class,
Applications.joinQueryUri("work", work.getId(), "processing"), req, work.getJob())
.getData(WoId.class);
if (StringUtils.isEmpty(resp.getId())) {
throw new ExceptionProcessingWork(work.getId());
}
}
private ActionResult<Wo> result() {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
wo.setValue(true);
result.setData(wo);
return result;
}
public static class Wi extends V2AddManualTaskIdentityMatrixWi {
private static final long serialVersionUID = -6251874269093504136L;
}
public static class WoControl extends WorkControl {
private static final long serialVersionUID = -8675239528577375846L;
}
public static class Wo extends WrapBoolean {
private static final long serialVersionUID = 8155067200427920853L;
}
}
\ No newline at end of file
package com.x.processplatform.core.express.assemble.surface.jaxrs.work;
import java.util.List;
import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
public class V2AddManualTaskIdentityMatrixWi extends GsonPropertyObject {
private static final long serialVersionUID = -8631082471633729236L;
@FieldDescribe("身份")
private String identity;
@FieldDescribe("操作")
private List<Option> optionList;
@FieldDescribe("是否删除指定待办身份")
private Boolean remove;
public String getIdentity() {
return identity;
}
public void setIdentity(String identity) {
this.identity = identity;
}
public List<Option> getOptionList() {
return optionList;
}
public void setOptionList(List<Option> optionList) {
this.optionList = optionList;
}
public Boolean getRemove() {
return remove;
}
public void setRemove(Boolean remove) {
this.remove = remove;
}
public static class Option {
@FieldDescribe("位置,before,after,first,last,extend")
private String position;
@FieldDescribe("身份")
private List<String> identityList;
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public List<String> getIdentityList() {
return identityList;
}
public void setIdentityList(List<String> identityList) {
this.identityList = identityList;
}
}
}
\ No newline at end of file
package com.x.processplatform.core.express.service.processing.jaxrs.task;
package com.x.processplatform.core.express.assemble.surface.jaxrs.work;
import java.util.ArrayList;
import java.util.List;
......@@ -8,7 +8,7 @@ import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
public class V2AddWi extends GsonPropertyObject {
public class V2AddTaskWi extends GsonPropertyObject {
private static final long serialVersionUID = -3293122515327864483L;
......@@ -21,8 +21,11 @@ public class V2AddWi extends GsonPropertyObject {
@FieldDescribe("是否执行替换")
private Boolean replace;
@FieldDescribe("是否删除")
private String task;
@FieldDescribe("工作标识")
private String work;
@FieldDescribe("定位身份标识")
private String identity;
public List<String> getIdentityList() {
return identityList;
......@@ -40,12 +43,12 @@ public class V2AddWi extends GsonPropertyObject {
this.replace = replace;
}
public String getTask() {
return task;
public String getWork() {
return work;
}
public void setTask(String task) {
this.task = task;
public void setWork(String work) {
this.work = work;
}
public Boolean getAfter() {
......@@ -56,4 +59,12 @@ public class V2AddWi extends GsonPropertyObject {
this.after = after;
}
public String getIdentity() {
return identity;
}
public void setIdentity(String identity) {
this.identity = identity;
}
}
\ No newline at end of file
package com.x.processplatform.core.express.service.processing.jaxrs.task;
package com.x.processplatform.core.express.assemble.surface.jaxrs.work;
import java.util.ArrayList;
import java.util.List;
......@@ -8,7 +8,7 @@ import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
public class V2ExtendWi extends GsonPropertyObject {
public class V2ExtendTaskWi extends GsonPropertyObject {
private static final long serialVersionUID = -3293122515327864483L;
......@@ -18,8 +18,19 @@ public class V2ExtendWi extends GsonPropertyObject {
@FieldDescribe("是否执行替换")
private Boolean replace;
@FieldDescribe("待办标识")
private String task;
@FieldDescribe("工作标识")
private String work;
@FieldDescribe("定位身份标识")
private String identity;
public String getIdentity() {
return identity;
}
public void setIdentity(String identity) {
this.identity = identity;
}
public List<String> getIdentityList() {
return identityList;
......@@ -37,12 +48,12 @@ public class V2ExtendWi extends GsonPropertyObject {
this.replace = replace;
}
public String getTask() {
return task;
public String getWork() {
return work;
}
public void setTask(String task) {
this.task = task;
public void setWork(String work) {
this.work = work;
}
}
\ No newline at end of file
......@@ -14,6 +14,12 @@ public class ProcessingWi extends GsonPropertyObject {
@FieldDescribe("流转类型.")
private String processingType;
@FieldDescribe("路由决策.")
private String routeName;
@FieldDescribe("待办意见.")
private String opinion;
public String getProcessingType() {
return processingType;
}
......@@ -22,4 +28,20 @@ public class ProcessingWi extends GsonPropertyObject {
this.processingType = processingType;
}
public String getRouteName() {
return routeName;
}
public void setRouteName(String routeName) {
this.routeName = routeName;
}
public String getOpinion() {
return opinion;
}
public void setOpinion(String opinion) {
this.opinion = opinion;
}
}
......@@ -11,59 +11,26 @@ public class V2ResetWi extends GsonPropertyObject {
private static final long serialVersionUID = -8631082471633729236L;
@FieldDescribe("待办")
private String task;
@FieldDescribe("保留自身待办.")
private Boolean keep;
@FieldDescribe("在指定待办前添加身份")
private List<String> addBeforeList;
@FieldDescribe("重置身份")
private List<String> identityList;
@FieldDescribe("在指定待办扩充的身份")
private List<String> extendList;
@FieldDescribe("在指定待办后添加身份")
private List<String> addAfterList;
@FieldDescribe("是否删除指定待办身份")
private Boolean remove;
public String getTask() {
return task;
}
public void setTask(String task) {
this.task = task;
}
public List<String> getAddBeforeList() {
return addBeforeList;
}
public void setAddBeforeList(List<String> addBeforeList) {
this.addBeforeList = addBeforeList;
}
public List<String> getExtendList() {
return extendList;
}
public void setExtendList(List<String> extendList) {
this.extendList = extendList;
}
public List<String> getAddAfterList() {
return addAfterList;
public Boolean getKeep() {
return BooleanUtils.isTrue(keep);
}
public void setAddAfterList(List<String> addAfterList) {
this.addAfterList = addAfterList;
public List<String> getIdentityList() {
return identityList;
}
public Boolean getRemove() {
return BooleanUtils.isTrue(remove);
public void setIdentityList(List<String> identityList) {
this.identityList = identityList;
}
public void setRemove(Boolean remove) {
this.remove = remove;
public void setKeep(Boolean keep) {
this.keep = keep;
}
}
\ No newline at end of file
......@@ -46,8 +46,10 @@ class ActionProcessing extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionProcessing.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
LOGGER.debug("execute:{}, id:{}.", effectivePerson::getDistinguishedName, () -> id);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute:{}, id:{}.", effectivePerson::getDistinguishedName, () -> id);
}
final Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
......@@ -61,7 +63,7 @@ class ActionProcessing extends BaseAction {
job = task.getJob();
}
return ProcessPlatformExecutorFactory.get(job).submit(new CallableExecute(wi, id)).get(300, TimeUnit.SECONDS);
return ProcessPlatformExecutorFactory.get(job).submit(new CallableExecute(id, wi)).get(300, TimeUnit.SECONDS);
}
......@@ -71,7 +73,7 @@ class ActionProcessing extends BaseAction {
private String id;
private CallableExecute(Wi wi, String id) {
private CallableExecute(String id, Wi wi) {
this.wi = wi;
this.id = id;
}
......@@ -171,6 +173,7 @@ class ActionProcessing extends BaseAction {
|| StringUtils.isNotEmpty(process.getManualAfterTaskScriptText())));
}
@Override
public ActionResult<Wo> call() throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
......@@ -184,6 +187,12 @@ class ActionProcessing extends BaseAction {
if (null == task) {
throw new ExceptionEntityNotExist(id, Task.class);
}
if (StringUtils.isNotEmpty(wi.getRouteName())) {
task.setRouteName(wi.getRouteName());
}
if (StringUtils.isNotEmpty(wi.getOpinion())) {
task.setOpinion(wi.getOpinion());
}
// 执行办前脚本
callManualBeforeTaskScript(business, task);
// 将待办转为已办
......
......@@ -4,7 +4,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
......@@ -250,51 +249,15 @@ public class TaskAction extends StandardJaxrsAction {
@JaxrsMethodDescribe(value = "V2_重置处理人.", action = V2Reset.class)
@PUT
@Path("v2/reset")
@Path("v2/{id}/reset")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void v2Reset(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
@JaxrsParameterDescribe("标识") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<V2Reset.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Reset().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "V2_在指定待办位置扩充处理人.", action = V2Extend.class)
@POST
@Path("v2/extend")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void v2Extend(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<V2Extend.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Extend().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "V2_在指定待办位置新增处理人.", action = V2Add.class)
@POST
@Path("v2/add")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void v2Add(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<V2Add.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Add().execute(effectivePerson, jsonElement);
result = new V2Reset().execute(effectivePerson, id, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
......
package com.x.processplatform.service.processing.jaxrs.task;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
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.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.processplatform.ManualTaskIdentityMatrix;
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.express.service.processing.jaxrs.task.V2ExtendWi;
import com.x.processplatform.service.processing.Business;
class V2Extend extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(V2Extend.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
final Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
}
Task task = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
task = getTask(business, wi.getTask());
if (null == task) {
throw new ExceptionEntityNotExist(wi.getTask(), Task.class);
}
if (!this.checkWorkExist(business, task.getWork())) {
throw new ExceptionEntityNotExist(task.getWork(), Work.class);
}
}
return ProcessPlatformExecutorFactory.get(task.getJob())
.submit(new CallableImpl(task.getWork(), task.getIdentity(), wi.getReplace(), wi.getIdentityList()))
.get(300, TimeUnit.SECONDS);
}
private Task getTask(Business business, String id) throws Exception {
return business.entityManagerContainer().fetch(id, Task.class,
ListTools.toList(Task.job_FIELDNAME, Task.identity_FIELDNAME, Task.work_FIELDNAME));
}
private boolean checkWorkExist(Business business, String id) throws Exception {
return business.entityManagerContainer().countEqual(Work.class, JpaObject.id_FIELDNAME, id) > 0;
}
private class CallableImpl implements Callable<ActionResult<Wo>> {
private String id;
private String identity;
private Boolean replace;
private List<String> identities;
CallableImpl(String id, String identity, Boolean replace, List<String> identities) {
this.id = id;
this.identity = identity;
this.replace = replace;
this.identities = identities;
}
@Override
public ActionResult<Wo> call() throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
emc.beginTransaction(Work.class);
Work work = emc.find(this.id, Work.class);
ManualTaskIdentityMatrix matrix = work.getManualTaskIdentityMatrix();
matrix.extend(identity, replace, identities);
work.setManualTaskIdentityMatrix(matrix);
emc.check(work, CheckPersistType.all);
emc.commit();
} catch (Exception e) {
LOGGER.error(e);
}
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
wo.setValue(true);
result.setData(wo);
return result;
}
}
public static class Wi extends V2ExtendWi {
private static final long serialVersionUID = 8207729800479548859L;
}
public static class Wo extends WrapBoolean {
private static final long serialVersionUID = 6457473592503074552L;
}
}
\ No newline at end of file
package com.x.processplatform.service.processing.jaxrs.task;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
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.annotation.CheckPersistType;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.executor.ProcessPlatformExecutorFactory;
import com.x.base.core.project.http.ActionResult;
......@@ -19,6 +23,9 @@ import com.x.base.core.project.processplatform.ManualTaskIdentityMatrix;
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.element.ActivityType;
import com.x.processplatform.core.entity.element.Manual;
import com.x.processplatform.core.entity.element.ManualMode;
import com.x.processplatform.core.express.service.processing.jaxrs.task.V2ResetWi;
import com.x.processplatform.service.processing.Business;
......@@ -26,42 +33,36 @@ class V2Reset extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(V2Reset.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
LOGGER.debug("execute:{}, id:{}.", effectivePerson::getDistinguishedName, () -> id);
final Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Task task = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
task = emc.fetch(wi.getTask(), Task.class, ListTools.toList(Task.job_FIELDNAME));
task = emc.fetch(id, Task.class, ListTools.toList(Task.job_FIELDNAME));
if (null == task) {
throw new ExceptionEntityNotExist(wi.getTask(), Task.class);
throw new ExceptionEntityNotExist(id, Task.class);
}
}
return ProcessPlatformExecutorFactory.get(task.getJob()).submit(new CallableImpl(task.getId(),
wi.getAddBeforeList(), wi.getExtendList(), wi.getAddAfterList(), wi.getRemove()))
.get(300, TimeUnit.SECONDS);
return ProcessPlatformExecutorFactory.get(task.getJob())
.submit(new CallableImpl(task.getId(), wi.getIdentityList(), wi.getKeep())).get(300, TimeUnit.SECONDS);
}
private class CallableImpl implements Callable<ActionResult<Wo>> {
private String id;
private List<String> addBeforeIdentities;
private List<String> extendIdentities;
private List<String> addAfterIdentities;
private boolean remove;
private List<String> identityList;
private boolean keep;
private CallableImpl(String id, List<String> addBeforeIdentities, List<String> extendIdentities,
List<String> addAfterIdentities, boolean remove) {
private CallableImpl(String id, List<String> identityList, boolean keep) {
this.id = id;
this.addBeforeIdentities = addBeforeIdentities;
this.extendIdentities = extendIdentities;
this.addAfterIdentities = addAfterIdentities;
this.remove = remove;
this.identityList = identityList;
this.keep = keep;
}
@Override
......@@ -76,21 +77,24 @@ class V2Reset extends BaseAction {
if (null == work) {
throw new ExceptionEntityNotExist(task.getWork(), Work.class);
}
this.addBeforeIdentities = ListTools.trim(business.organization().identity().list(addBeforeIdentities),
true, true);
this.extendIdentities = ListTools.trim(business.organization().identity().list(extendIdentities), true,
true);
this.addAfterIdentities = ListTools.trim(business.organization().identity().list(addAfterIdentities),
true, true);
emc.beginTransaction(Work.class);
ManualTaskIdentityMatrix matrix = work.getManualTaskIdentityMatrix();
matrix.reset(task.getIdentity(), addBeforeIdentities, extendIdentities, addAfterIdentities, remove);
work.setManualTaskIdentityMatrix(matrix);
emc.check(work, CheckPersistType.all);
emc.commit();
Manual manual = (Manual) business.element().get(work.getActivity(), ActivityType.manual);
if (null == manual) {
throw new ExceptionEntityNotExist(work.getActivity(), Manual.class);
}
List<String> identities = business.organization().identity().list(identityList);
if (!ListTools.isEmpty(identities)) {
emc.beginTransaction(Work.class);
ManualTaskIdentityMatrix matrix = work.getManualTaskIdentityMatrix();
if (Objects.equals(manual.getManualMode(), ManualMode.single)
|| Objects.equals(manual.getManualMode(), ManualMode.grab)) {
matrix.add(task.getIdentity(), ManualTaskIdentityMatrix.ADD_POSITION_EXTEND, identities);
} else {
matrix.add(task.getIdentity(), ManualTaskIdentityMatrix.ADD_POSITION_AFTER, identities);
}
work.setManualTaskIdentityMatrix(matrix);
emc.check(work, CheckPersistType.all);
emc.commit();
}
}
Wo wo = new Wo();
wo.setValue(true);
......
package com.x.processplatform.service.processing.jaxrs.task;
package com.x.processplatform.service.processing.jaxrs.work;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.BooleanUtils;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
......@@ -18,16 +21,15 @@ import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.processplatform.ManualTaskIdentityMatrix;
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.express.service.processing.jaxrs.task.V2AddWi;
import com.x.processplatform.core.express.assemble.surface.jaxrs.work.V2AddManualTaskIdentityMatrixWi;
import com.x.processplatform.service.processing.Business;
class V2Add extends BaseAction {
class V2AddManualTaskIdentityMatrix extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(V2Add.class);
private static final Logger LOGGER = LoggerFactory.getLogger(V2AddManualTaskIdentityMatrix.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
final Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
......@@ -35,60 +37,63 @@ class V2Add extends BaseAction {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
}
Task task = null;
Work work = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
task = getTask(business, wi.getTask());
if (null == task) {
throw new ExceptionEntityNotExist(wi.getTask(), Task.class);
}
if (!this.checkWorkExist(business, task.getWork())) {
throw new ExceptionEntityNotExist(task.getWork(), Work.class);
work = getWork(business, id);
if (null == work) {
throw new ExceptionEntityNotExist(id, Work.class);
}
}
return ProcessPlatformExecutorFactory.get(task.getJob()).submit(new CallableImpl(task.getWork(),
task.getIdentity(), wi.getAfter(), wi.getReplace(), wi.getIdentityList())).get(300, TimeUnit.SECONDS);
}
return ProcessPlatformExecutorFactory.get(work.getJob())
.submit(new CallableImpl(work.getId(), wi.getIdentity(), wi.getOptionList(), wi.getRemove()))
.get(300, TimeUnit.SECONDS);
private Task getTask(Business business, String id) throws Exception {
return business.entityManagerContainer().fetch(id, Task.class,
ListTools.toList(Task.job_FIELDNAME, Task.identity_FIELDNAME, Task.work_FIELDNAME));
}
private boolean checkWorkExist(Business business, String id) throws Exception {
return business.entityManagerContainer().countEqual(Work.class, JpaObject.id_FIELDNAME, id) > 0;
private Work getWork(Business business, String id) throws Exception {
List<String> attributes = new ArrayList<>();
attributes.add(Work.job_FIELDNAME);
attributes.add(JpaObject.id_FIELDNAME);
return business.entityManagerContainer().fetch(id, Work.class, attributes);
}
private class CallableImpl implements Callable<ActionResult<Wo>> {
private String id;
private String identity;
private List<V2AddManualTaskIdentityMatrixWi.Option> optionList;
private Boolean remove;
private Boolean after;
private Boolean replace;
private List<String> identities;
CallableImpl(String id, String identity, Boolean after, Boolean replace, List<String> identities) {
CallableImpl(String id, String identity, List<V2AddManualTaskIdentityMatrixWi.Option> optionList,
Boolean remove) {
this.id = id;
this.identity = identity;
this.after = after;
this.replace = replace;
this.identities = identities;
this.optionList = optionList;
this.remove = remove;
}
@Override
public ActionResult<Wo> call() throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
emc.beginTransaction(Work.class);
Work work = emc.find(this.id, Work.class);
if (null == work) {
throw new ExceptionEntityNotExist(id, Work.class);
}
ManualTaskIdentityMatrix matrix = work.getManualTaskIdentityMatrix();
matrix.add(identity, after, replace, identities);
for (V2AddManualTaskIdentityMatrixWi.Option option : optionList) {
List<String> identities = business.organization().identity().list(option.getIdentityList());
if (!ListTools.isEmpty(identities)) {
matrix.add(identity, option.getPosition(), identities);
}
}
if (BooleanUtils.isTrue(remove)) {
matrix.remove(identity);
}
work.setManualTaskIdentityMatrix(matrix);
emc.check(work, CheckPersistType.all);
emc.commit();
......@@ -104,7 +109,7 @@ class V2Add extends BaseAction {
}
public static class Wi extends V2AddWi {
public static class Wi extends V2AddManualTaskIdentityMatrixWi {
private static final long serialVersionUID = 7870902860170655791L;
......
......@@ -41,7 +41,7 @@ class V2Reroute extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
LOGGER.debug("execute:{}, id:{}.", effectivePerson::getDistinguishedName, () -> id);
final String job;
final Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
......@@ -52,7 +52,86 @@ class V2Reroute extends BaseAction {
job = work.getJob();
}
Callable<ActionResult<Wo>> callable = () -> {
// 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(Read.class);
// emc.beginTransaction(WorkLog.class);
// // 重新设置表单
// work.setForm(business.element().lookupSuitableForm(work.getProcess(), activity.getId()));
// // 调度强制把这个标志设置为true,这样可以避免在拟稿状态就调度,系统认为是拟稿状态,默认不创建待办.
// work.setWorkThroughManual(true);
// work.setDestinationActivity(activity.getId());
// work.setDestinationActivityType(activity.getActivityType());
// work.setDestinationRoute("");
// work.setDestinationRouteName("");
// work.getProperties().setManualForceTaskIdentityList(new ArrayList<>());
// if (ListTools.isNotEmpty(wi.getManualForceTaskIdentityList())) {
// work.getProperties().setManualForceTaskIdentityList(wi.getManualForceTaskIdentityList());
// }
// if (BooleanUtils.isTrue(wi.getMergeWork())) {
// // 合并工作
// work.setSplitting(false);
// work.setSplitToken("");
// work.getSplitTokenList().clear();
// work.setSplitValue("");
// removeAllTask(business, work);
// redirectOtherRead(business, work);
// removeOtherWork(business, work);
// removeOtherWorkLog(business, work);
// } else {
// removeTask(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 CallableImpl(id, wi);
return ProcessPlatformExecutorFactory.get(job).submit(callable).get(300, TimeUnit.SECONDS);
}
public static class Wi extends V2RerouteWi {
private static final long serialVersionUID = 4131889338839380226L;
}
public static class Wo extends WrapBoolean {
private static final long serialVersionUID = 6797942626499506636L;
}
private class CallableImpl implements Callable<ActionResult<Wo>> {
private String id;
private Wi wi;
private CallableImpl(String id, Wi wi) {
this.id = id;
this.wi = wi;
}
@Override
public ActionResult<Wo> call() throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Work work;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
......@@ -101,83 +180,70 @@ class V2Reroute extends BaseAction {
wo.setValue(true);
result.setData(wo);
return result;
};
return ProcessPlatformExecutorFactory.get(job).submit(callable).get(300, TimeUnit.SECONDS);
}
public static class Wi extends V2RerouteWi {
private static final long serialVersionUID = 4131889338839380226L;
}
public static class Wo extends WrapBoolean {
}
private static final long serialVersionUID = 6797942626499506636L;
}
private void removeTask(Business business, Work work) throws Exception {
// 删除可能的待办
List<Task> os = business.entityManagerContainer().listEqual(Task.class, Task.work_FIELDNAME, work.getId());
os.stream().forEach(o -> {
try {
business.entityManagerContainer().remove(o, CheckRemoveType.all);
MessageFactory.task_delete(o);
} catch (Exception e) {
LOGGER.error(e);
}
});
}
private void removeTask(Business business, Work work) throws Exception {
// 删除可能的待办
List<Task> os = business.entityManagerContainer().listEqual(Task.class, Task.work_FIELDNAME, work.getId());
os.stream().forEach(o -> {
try {
business.entityManagerContainer().remove(o, CheckRemoveType.all);
MessageFactory.task_delete(o);
} catch (Exception e) {
LOGGER.error(e);
}
});
}
private void redirectOtherRead(Business business, Work work) throws Exception {
business.entityManagerContainer().listEqualAndNotEqual(Read.class, Read.job_FIELDNAME, work.getJob(),
Read.work_FIELDNAME, work.getId()).stream().forEach(o -> {
try {
o.setWork(work.getId());
} catch (Exception e) {
LOGGER.error(e);
}
});
}
private void redirectOtherRead(Business business, Work work) throws Exception {
business.entityManagerContainer()
.listEqualAndNotEqual(Read.class, Read.job_FIELDNAME, work.getJob(), Read.work_FIELDNAME, work.getId())
.stream().forEach(o -> {
try {
o.setWork(work.getId());
} catch (Exception e) {
LOGGER.error(e);
}
});
}
private void removeAllTask(Business business, Work work) throws Exception {
business.entityManagerContainer().listEqual(Task.class, Task.job_FIELDNAME, work.getJob()).stream()
.forEach(o -> {
try {
business.entityManagerContainer().remove(o, CheckRemoveType.all);
MessageFactory.task_delete(o);
} catch (Exception e) {
LOGGER.error(e);
}
});
}
private void removeAllTask(Business business, Work work) throws Exception {
business.entityManagerContainer().listEqual(Task.class, Task.job_FIELDNAME, work.getJob()).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 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);
}
});
}
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);
}
});
}
}
\ No newline at end of file
......@@ -378,4 +378,23 @@ public class WorkAction extends StandardJaxrsAction {
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "V2_添加待办身份矩阵.", action = V2AddManualTaskIdentityMatrix.class)
@POST
@Path("v2/{id}/add/manual/task/identity/matrix")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void v2AddManualTaskIdentityMatrix(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request, @JaxrsParameterDescribe("工作标识") @PathParam("id") String id,
JsonElement jsonElement) {
ActionResult<V2AddManualTaskIdentityMatrix.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2AddManualTaskIdentityMatrix().execute(effectivePerson, id, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
......@@ -2,6 +2,7 @@ package com.x.processplatform.service.processing.processor.manual;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedHashMap;
......@@ -9,7 +10,10 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.script.Bindings;
import javax.script.CompiledScript;
......@@ -21,9 +25,10 @@ import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
......@@ -42,6 +47,7 @@ import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkLog;
import com.x.processplatform.core.entity.element.ActivityType;
import com.x.processplatform.core.entity.element.Manual;
import com.x.processplatform.core.entity.element.ManualMode;
import com.x.processplatform.core.entity.element.Route;
import com.x.processplatform.core.entity.element.util.WorkLogTree;
import com.x.processplatform.core.entity.element.util.WorkLogTree.Node;
......@@ -199,17 +205,31 @@ public class ManualProcessor extends AbstractManualProcessor {
return taskIdentities.identities();
}
// private void calculateRouteTypeBack(AeiObjects aeiObjects, Manual manual, TaskIdentities taskIdentities)
// throws Exception {
// List<String> identities = new ArrayList<>();
// List<WorkLog> workLogs = new ArrayList<>();
// workLogs.addAll(aeiObjects.getUpdateWorkLogs());
// workLogs.addAll(aeiObjects.getCreateWorkLogs());
// for (WorkLog o : aeiObjects.getWorkLogs()) {
// if (!workLogs.contains(o)) {
// workLogs.add(o);
// }
// }
// WorkLogTree tree = new WorkLogTree(workLogs);
// Node node = tree.location(aeiObjects.getWork());
// if (null != node) {
// calculateRouteTypeBackIdentityByTaskCompleted(aeiObjects, manual, taskIdentities, identities, tree, node);
// }
// }
private void calculateRouteTypeBack(AeiObjects aeiObjects, Manual manual, TaskIdentities taskIdentities)
throws Exception {
List<String> identities = new ArrayList<>();
List<WorkLog> workLogs = new ArrayList<>();
workLogs.addAll(aeiObjects.getUpdateWorkLogs());
workLogs.addAll(aeiObjects.getCreateWorkLogs());
for (WorkLog o : aeiObjects.getWorkLogs()) {
if (!workLogs.contains(o)) {
workLogs.add(o);
}
}
List<WorkLog> workLogs = Stream
.concat(Stream.concat(aeiObjects.getUpdateWorkLogs().stream(), aeiObjects.getCreateWorkLogs().stream()),
aeiObjects.getWorkLogs().stream())
.distinct().collect(Collectors.toList());
WorkLogTree tree = new WorkLogTree(workLogs);
Node node = tree.location(aeiObjects.getWork());
if (null != node) {
......@@ -324,14 +344,16 @@ public class ManualProcessor extends AbstractManualProcessor {
protected List<Work> executing(AeiObjects aeiObjects, Manual manual) throws Exception {
List<Work> results = new ArrayList<>();
ManualTaskIdentityMatrix matrix = executingManualTaskIdentityMatrix(aeiObjects, manual);
List<TaskCompleted> taskCompleteds = aeiObjects
.getJoinInquireTaskCompletedsWithActivityToken(aeiObjects.getWork().getActivityToken());
List<TaskCompleted> taskCompleteds = executingJoinInquireCheckRouteNameTaskCompleteds(aeiObjects);
executingCompletedIdentityInTaskCompleteds(aeiObjects, matrix, taskCompleteds);
// 发送ProcessingSignal
aeiObjects.getProcessingAttributes().push(Signal.manualExecute(aeiObjects.getWork().getActivityToken(), manual,
Objects.toString(manual.getManualMode(), ""), matrix.flat()));
if (matrix.isEmpty()) {
results.add(aeiObjects.getWork());
aeiObjects.getTasks().stream().filter(
t -> StringUtils.equalsIgnoreCase(t.getActivityToken(), aeiObjects.getWork().getActivityToken()))
.forEach(aeiObjects::deleteTask);
} else {
switch (manual.getManualMode()) {
case parallel:
......@@ -354,6 +376,23 @@ public class ManualProcessor extends AbstractManualProcessor {
return results;
}
/**
* 获取当前参与流转的已办,同时过滤路由决策在路由中的已办.
*
* @param aeiObjects
* @return
* @throws Exception
*/
private List<TaskCompleted> executingJoinInquireCheckRouteNameTaskCompleteds(AeiObjects aeiObjects)
throws Exception {
List<TaskCompleted> taskCompleteds = aeiObjects
.getJoinInquireTaskCompletedsWithActivityToken(aeiObjects.getWork().getActivityToken());
List<String> routeNames = aeiObjects.getRoutes().stream().map(Route::getName).collect(Collectors.toList());
taskCompleteds = taskCompleteds.stream().filter(t -> routeNames.contains(t.getRouteName()))
.collect(Collectors.toList());
return taskCompleteds;
}
@SuppressWarnings("unchecked")
private ManualTaskIdentityMatrix executingManualTaskIdentityMatrix(AeiObjects aeiObjects, Manual manual)
throws Exception {
......@@ -437,30 +476,32 @@ public class ManualProcessor extends AbstractManualProcessor {
results.add(aeiObjects.getRoutes().get(0));
} else if (aeiObjects.getRoutes().size() > 1) {
// 存在多条路由
Collection<String> routeNames = aeiObjects.getRoutes().stream().map(Route::getName)
.collect(Collectors.toSet());
List<TaskCompleted> taskCompleteds = aeiObjects
.getJoinInquireTaskCompletedsWithActivityToken(aeiObjects.getWork().getActivityToken()).stream()
.sorted(Comparator.comparing(TaskCompleted::getCreateTime)).collect(Collectors.toList());
String name = this.choiceRouteName(taskCompleteds, manual, aeiObjects.getRoutes());
for (Route o : aeiObjects.getRoutes()) {
if (o.getName().equalsIgnoreCase(name)) {
results.add(o);
break;
}
.filter(t -> routeNames.contains(t.getRouteName())).collect(Collectors.toList());
String name = this.choiceRouteName(taskCompleteds, aeiObjects.getRoutes(), manual);
Optional<Route> optional = aeiObjects.getRoutes().stream()
.filter(r -> StringUtils.equalsIgnoreCase(name, r.getName())).findFirst();
if (optional.isPresent()) {
results.add(optional.get());
}
} else {
throw new ExceptionManualNotRoute(manual.getId());
}
if (!results.isEmpty()) {
// 清理掉强制的指定的处理人
aeiObjects.getWork().getProperties().setManualForceTaskIdentityList(new ArrayList<>());
}
return results;
}
/**
* 选择离开活动的路由
* 判断的逻辑如下:
* 1.是否有用户选择了"直接返回优先路由(soleDirect)",同时判断该值是否在路由列表中(可能修改路由名称),如果有就直接返回该值.
* 2.是否有用户选择了"优先路由(sole)",同时判断该值是否在路由列表中(可能修改路由名称),如果有就直接返回该值.
* 3.如果没有soleDirect或者sole被选择,那么根据活动类型进行判断,如果是并行活动(parallel)那么选择最多的路由决策,如果有多个路由决策同样数量,那么选择时间上最晚的那组,如果是single(单人),queue(串行),grab(抢办)那么最后的路由决策作为返回值(需要判断是否在路由列表中).
*
* @param taskCompleteds 按创建时间正序排列好的已办
* @param manual 人工活动节点
......@@ -468,37 +509,19 @@ public class ManualProcessor extends AbstractManualProcessor {
* @return 路由名称
* @throws Exception
*/
private String choiceRouteName(List<TaskCompleted> taskCompleteds, Manual manual, List<Route> routes)
private String choiceRouteName(List<TaskCompleted> taskCompleteds, List<Route> routes, Manual manual)
throws Exception {
String result = "";
// 将已办中的路由选择抽取出来
List<String> selectedRouteNames = ListTools.extractField(taskCompleteds, TaskCompleted.routeName_FIELDNAME,
String.class, false, false);
// 进行优先路由的判断
// 已经开始选择路由,如果选择了soleDirect那么就直接返回了,如果没有选择这个路由在进行sole的判断,顺序是 soleDirct -> sole
// -> max -> latest.
result = choiceSoleDirectIfExist(selectedRouteNames, routes);
if (StringUtils.isEmpty(result)) {
result = choiceSoleIfExist(selectedRouteNames, routes);
}
if (StringUtils.isEmpty(result)) {
switch (manual.getManualMode()) {
case parallel:
result = choiceMaxCountOrLatest(taskCompleteds, routes);
break;
case queue:
case grab:
case single:
default:
result = choiceLatest(selectedRouteNames, routes);
}
}
if (StringUtils.isEmpty(result)) {
throw new ExceptionChoiceRouteNameError(
ListTools.extractProperty(selectedRouteNames, JpaObject.id_FIELDNAME, String.class, false, false));
final Triple<List<TaskCompleted>, List<Route>, Manual> triple = Triple.of(taskCompleteds, routes, manual);
Optional<String> optional = Stream
.<Function<Triple<List<TaskCompleted>, List<Route>, Manual>, Optional<String>>>of(
this::chooseSoleDirectIfExist, this::chooseSoleIfExist, this::chooseMaxCountOrLatest)
.map(f -> f.apply(triple)).filter(Optional::isPresent).findFirst().orElse(Optional.empty());
if (optional.isPresent()) {
return optional.get();
} else {
throw new ExceptionChoiceRouteNameError(ListTools.extractProperty(taskCompleteds,
TaskCompleted.routeName_FIELDNAME, String.class, false, false));
}
return result;
}
/**
......@@ -508,15 +531,9 @@ public class ManualProcessor extends AbstractManualProcessor {
* @param routes
* @return
*/
private String choiceSoleDirectIfExist(List<String> list, List<Route> routes) {
List<String> names = routes.stream().filter(r -> BooleanUtils.isTrue(r.getSoleDirect())).map(Route::getName)
.collect(Collectors.toList());
for (String str : list) {
if (names.contains(str)) {
return str;
}
}
return null;
private Optional<String> chooseSoleDirectIfExist(final Triple<List<TaskCompleted>, List<Route>, Manual> triple) {
return chooseIfExist(triple, r -> BooleanUtils.isTrue(r.getSoleDirect()));
}
/**
......@@ -526,15 +543,17 @@ public class ManualProcessor extends AbstractManualProcessor {
* @param routes
* @return
*/
private String choiceSoleIfExist(List<String> list, List<Route> routes) {
List<String> names = routes.stream().filter(r -> BooleanUtils.isTrue(r.getSole())).map(Route::getName)
.collect(Collectors.toList());
for (String str : list) {
if (names.contains(str)) {
return str;
}
}
return null;
private Optional<String> chooseSoleIfExist(final Triple<List<TaskCompleted>, List<Route>, Manual> triple) {
return chooseIfExist(triple, r -> BooleanUtils.isTrue(r.getSole()));
}
private Optional<String> chooseIfExist(final Triple<List<TaskCompleted>, List<Route>, Manual> triple,
final Predicate<Route> predicate) {
final List<TaskCompleted> taskCompleteds = triple.getLeft();
final List<Route> routes = triple.getMiddle();
final Collection<String> names = routes.stream().filter(predicate).map(Route::getName)
.collect(Collectors.toSet());
return taskCompleteds.stream().map(TaskCompleted::getRouteName).filter(names::contains).findFirst();
}
/**
......@@ -545,44 +564,22 @@ public class ManualProcessor extends AbstractManualProcessor {
* @return
* @throws Exception
*/
private String choiceMaxCountOrLatest(List<TaskCompleted> list, List<Route> routes) throws Exception {
List<String> names = ListTools.extractField(routes, Route.name_FIELDNAME, String.class, false, false);
return list.stream().collect(Collectors.groupingBy(TaskCompleted::getRouteName)).entrySet().stream()
.sorted((o1, o2) -> {
int c = o2.getValue().size() - o1.getValue().size();
private Optional<String> chooseMaxCountOrLatest(Triple<List<TaskCompleted>, List<Route>, Manual> triple) {
if (!Objects.equals(ManualMode.parallel, triple.getRight().getManualMode())) {
return triple.getLeft().stream().sorted(Comparator.comparing(TaskCompleted::getCreateTime).reversed())
.findFirst().map(TaskCompleted::getRouteName);
}
return triple.getLeft().stream().collect(Collectors.groupingBy(TaskCompleted::getRouteName)).entrySet().stream()
.max((o1, o2) -> {
int c = o1.getValue().size() - o2.getValue().size();
if (c == 0) {
Date d1 = o1.getValue().stream()
.sorted(Comparator.comparing(TaskCompleted::getCreateTime).reversed()).findFirst().get()
.getCreateTime();
Date d2 = o2.getValue().stream()
.sorted(Comparator.comparing(TaskCompleted::getCreateTime).reversed()).findFirst().get()
.getCreateTime();
return ObjectUtils.compare(d2, d1);
return ObjectUtils.compare(
o1.getValue().stream().mapToLong(t -> t.getCreateTime().getTime()).max().getAsLong(),
o2.getValue().stream().mapToLong(t -> t.getCreateTime().getTime()).max().getAsLong());
} else {
return c;
}
}).map(Entry::getKey).filter(names::contains).findFirst().orElse(null);
}
/**
* 取得最后一个办理的路由决策,需要判断是否在路由列表中
*
* @param list 通过已办取得的用户选择的路由列表,默认是正序
* @param routes 活动可选择的路由
* @return
*/
private String choiceLatest(List<String> list, List<Route> routes) {
if (ListTools.isEmpty(list)) {
return null;
} else {
List<String> names = routes.stream().map(Route::getName).collect(Collectors.toList());
for (int i = list.size() - 1; i >= 0; i--) {
if (names.contains(list.get(i))) {
return list.get(i);
}
}
return null;
}
}).map(Entry::getKey);
}
// 是否有优先路由
......@@ -590,6 +587,9 @@ public class ManualProcessor extends AbstractManualProcessor {
List<TaskCompleted> taskCompleteds) throws Exception {
if (soleDirect(aeiObjects, taskCompleteds)) {
matrix.clear();
aeiObjects.getTasks().stream().filter(
t -> StringUtils.equalsIgnoreCase(t.getActivityToken(), aeiObjects.getWork().getActivityToken()))
.forEach(aeiObjects::deleteTask);
} else {
task(aeiObjects, manual, matrix.read());
}
......@@ -600,6 +600,9 @@ public class ManualProcessor extends AbstractManualProcessor {
// 是否有优先路由
if (soleDirect(aeiObjects, taskCompleteds)) {
matrix.clear();
aeiObjects.getTasks().stream().filter(
t -> StringUtils.equalsIgnoreCase(t.getActivityToken(), aeiObjects.getWork().getActivityToken()))
.forEach(aeiObjects::deleteTask);
} else {
task(aeiObjects, manual, matrix.flat());
}
......@@ -609,6 +612,9 @@ public class ManualProcessor extends AbstractManualProcessor {
List<TaskCompleted> taskCompleteds) throws Exception {
if (soleDirect(aeiObjects, taskCompleteds)) {
matrix.clear();
aeiObjects.getTasks().stream().filter(
t -> StringUtils.equalsIgnoreCase(t.getActivityToken(), aeiObjects.getWork().getActivityToken()))
.forEach(aeiObjects::deleteTask);
} else {
task(aeiObjects, manual, matrix.read());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册