|
|
@@ -6,7 +6,7 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections4.ListUtils;
|
|
|
@@ -21,7 +21,6 @@ import com.x.base.core.entity.dataitem.ItemCategory;
|
|
|
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.gson.GsonPropertyObject;
|
|
|
import com.x.base.core.project.http.ActionResult;
|
|
|
import com.x.base.core.project.http.EffectivePerson;
|
|
|
@@ -53,61 +52,64 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
ActionResult<Wo> execute(EffectivePerson effectivePerson, String workOrWorkCompleted) throws Exception {
|
|
|
ActionResult<Wo> result = new ActionResult<>();
|
|
|
|
|
|
- CompletableFuture<Wo> _wo = CompletableFuture.supplyAsync(() -> {
|
|
|
- Wo wo = null;
|
|
|
- Work work = null;
|
|
|
- try {
|
|
|
- try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
- work = emc.find(workOrWorkCompleted, Work.class);
|
|
|
- }
|
|
|
- if (null != work) {
|
|
|
- wo = this.work(effectivePerson, work);
|
|
|
- } else {
|
|
|
- WorkCompleted workCompleted = null;
|
|
|
- try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
- workCompleted = emc.flag(workOrWorkCompleted, WorkCompleted.class);
|
|
|
- if (null != workCompleted) {
|
|
|
- wo = this.workCompleted(effectivePerson, workCompleted);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e);
|
|
|
+ Wo wo = new Wo();
|
|
|
+ Work work = null;
|
|
|
+ WorkCompleted workCompleted = null;
|
|
|
+ try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
+ work = emc.find(workOrWorkCompleted, Work.class);
|
|
|
+ if (null == work) {
|
|
|
+ workCompleted = emc.flag(workOrWorkCompleted, WorkCompleted.class);
|
|
|
}
|
|
|
- return wo;
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
- CompletableFuture<Boolean> _control = CompletableFuture.supplyAsync(() -> {
|
|
|
- Boolean value = false;
|
|
|
- try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
- Business business = new Business(emc);
|
|
|
- value = business.readableWithWorkOrWorkCompleted(effectivePerson, workOrWorkCompleted,
|
|
|
- new ExceptionEntityNotExist(workOrWorkCompleted));
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e);
|
|
|
+ CompletableFuture<Boolean> checkControlFuture = this.checkControlFuture(effectivePerson, workOrWorkCompleted);
|
|
|
+
|
|
|
+ if (null != work) {
|
|
|
+ CompletableFuture<Void> workJsonFuture = this.workJsonFuture(work, wo);
|
|
|
+ CompletableFuture<Void> activityRouteFuture = this.activityRouteFuture(work, wo);
|
|
|
+ CompletableFuture<Void> dataFuture = this.dataFuture(work, wo);
|
|
|
+ CompletableFuture<Void> taskFuture = this.taskFuture(effectivePerson, work.getJob(), wo);
|
|
|
+ CompletableFuture<Void> readFuture = this.readFuture(effectivePerson, work.getJob(), wo);
|
|
|
+ CompletableFuture<Void> creatorIdentityFuture = this.creatorIdentityFuture(work.getCreatorIdentity(), wo);
|
|
|
+ CompletableFuture<Void> creatorPersonFuture = this.creatorPersonFuture(work.getCreatorPerson(), wo);
|
|
|
+ CompletableFuture<Void> creatorUnitFuture = this.creatorUnitFuture(work.getCreatorUnit(), wo);
|
|
|
+ CompletableFuture<Void> attachmentFuture = this.attachmentFuture(effectivePerson, work.getJob(), wo);
|
|
|
+ workJsonFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ activityRouteFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ dataFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ taskFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ readFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ creatorIdentityFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ creatorPersonFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ creatorUnitFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ attachmentFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ for (WoTask woTask : wo.getTaskList()) {
|
|
|
+ wo.getRecordList().add(taskToRecord(woTask));
|
|
|
}
|
|
|
- return value;
|
|
|
- });
|
|
|
-
|
|
|
- if (BooleanUtils.isFalse(_control.get())) {
|
|
|
+ } else if (null != workCompleted) {
|
|
|
+ CompletableFuture<Void> workCompletedJsonFuture = this.workCompletedJsonFuture(workCompleted, wo);
|
|
|
+ CompletableFuture<Void> workCompletedDataFuture = this.workCompletedDataFuture(workCompleted, wo);
|
|
|
+ CompletableFuture<Void> readFuture = readFuture(effectivePerson, workCompleted.getJob(), wo);
|
|
|
+ CompletableFuture<Void> creatorIdentityFuture = creatorIdentityFuture(workCompleted.getCreatorIdentity(),
|
|
|
+ wo);
|
|
|
+ CompletableFuture<Void> creatorPersonFuture = creatorPersonFuture(workCompleted.getCreatorPerson(), wo);
|
|
|
+ CompletableFuture<Void> creatorUnitFuture = creatorUnitFuture(workCompleted.getCreatorUnit(), wo);
|
|
|
+ CompletableFuture<Void> attachmentFuture = attachmentFuture(effectivePerson, workCompleted.getJob(), wo);
|
|
|
+ workCompletedJsonFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ workCompletedDataFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ readFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ creatorIdentityFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ creatorPersonFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ creatorUnitFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ attachmentFuture.get(10, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (BooleanUtils.isFalse(checkControlFuture.get(10, TimeUnit.SECONDS))) {
|
|
|
throw new ExceptionAccessDenied(effectivePerson, workOrWorkCompleted);
|
|
|
}
|
|
|
- result.setData(_wo.get());
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
- private Wo work(EffectivePerson effectivePerson, Work work) throws InterruptedException, ExecutionException {
|
|
|
- Wo wo = new Wo();
|
|
|
- CompletableFuture
|
|
|
- .allOf(workJson(work, wo), activity(work, wo), data(work, wo), task(effectivePerson, work, wo),
|
|
|
- read(effectivePerson, work.getJob(), wo), creatorIdentity(work.getCreatorIdentity(), wo),
|
|
|
- creatorPerson(work.getCreatorPerson(), wo), creatorUnit(work.getCreatorUnit(), wo),
|
|
|
- attachment(effectivePerson, work.getJob(), wo), record(effectivePerson, work.getJob(), wo))
|
|
|
- .get();
|
|
|
- for (WoTask woTask : wo.getTaskList()) {
|
|
|
- wo.getRecordList().add(taskToRecord(woTask));
|
|
|
- }
|
|
|
- return wo;
|
|
|
+ result.setData(wo);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
private WoRecord taskToRecord(WoTask woTask) {
|
|
|
@@ -126,7 +128,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
return o;
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> data(Work work, Wo wo) {
|
|
|
+ private CompletableFuture<Void> dataFuture(Work work, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
List<Item> list = emc.listEqualAndEqual(Item.class, DataItem.bundle_FIELDNAME, work.getJob(),
|
|
|
@@ -144,58 +146,12 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> record(EffectivePerson effectivePerson, String job, Wo wo) {
|
|
|
- return CompletableFuture.runAsync(() -> {
|
|
|
- try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
- wo.setRecordList(emc.fetchEqual(Record.class, WoRecord.copier, Record.job_FIELDNAME, job).stream()
|
|
|
- .sorted(Comparator.comparing(WoRecord::getOrder)).collect(Collectors.toList()));
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
- private CompletableFuture<Void> completedRecord(EffectivePerson effectivePerson, WorkCompleted workCompleted,
|
|
|
- Wo wo) {
|
|
|
+ private CompletableFuture<Void> taskFuture(EffectivePerson effectivePerson, String job, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
- if (ListTools.isNotEmpty(workCompleted.getProperties().getRecordList())) {
|
|
|
- wo.setRecordList(WoRecord.copier.copy(workCompleted.getProperties().getRecordList()).stream()
|
|
|
- .sorted(Comparator.comparing(WoRecord::getOrder)).collect(Collectors.toList()));
|
|
|
- } else {
|
|
|
- wo.setRecordList(emc
|
|
|
- .fetchEqual(Record.class, WoRecord.copier, Record.job_FIELDNAME, workCompleted.getJob())
|
|
|
- .stream().sorted(Comparator.comparing(WoRecord::getOrder)).collect(Collectors.toList()));
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private CompletableFuture<Void> activity(Work work, Wo wo) {
|
|
|
- return CompletableFuture.runAsync(() -> {
|
|
|
- try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
- Business business = new Business(emc);
|
|
|
- Activity activity = business.getActivity(work);
|
|
|
- if (null != activity) {
|
|
|
- WoActivity woActivity = new WoActivity();
|
|
|
- activity.copyTo(woActivity);
|
|
|
- wo.setActivity(woActivity);
|
|
|
- if (Objects.equals(ActivityType.manual, activity.getActivityType())) {
|
|
|
- wo.setRouteList(WoRoute.copier.copy(business.route().pick(((Manual) activity).getRouteList())));
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private CompletableFuture<Void> task(EffectivePerson effectivePerson, Work work, Wo wo) {
|
|
|
- return CompletableFuture.runAsync(() -> {
|
|
|
- try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
- wo.setTaskList(WoTask.copier.copy(emc.listEqual(Task.class, Task.job_FIELDNAME, work.getJob())));
|
|
|
+ wo.setTaskList(WoTask.copier.copy(emc.listEqual(Task.class, Task.job_FIELDNAME, job)));
|
|
|
wo.setCurrentTaskIndex(
|
|
|
ListUtils.indexOf(wo.getTaskList(), e -> effectivePerson.isPerson(e.getPerson())));
|
|
|
} catch (Exception e) {
|
|
|
@@ -204,7 +160,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> attachment(EffectivePerson effectivePerson, String job, Wo wo) {
|
|
|
+ private CompletableFuture<Void> attachmentFuture(EffectivePerson effectivePerson, String job, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
Business business = new Business(emc);
|
|
|
@@ -237,7 +193,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> read(EffectivePerson effectivePerson, String job, Wo wo) {
|
|
|
+ private CompletableFuture<Void> readFuture(EffectivePerson effectivePerson, String job, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
wo.setReadList(WoRead.copier.copy(emc.listEqual(Read.class, Read.job_FIELDNAME, job)));
|
|
|
@@ -249,7 +205,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> workJson(Work work, Wo wo) {
|
|
|
+ private CompletableFuture<Void> workJsonFuture(Work work, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try {
|
|
|
wo.setWork(gson.toJsonTree(WoWork.copier.copy(work)));
|
|
|
@@ -259,7 +215,26 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> creatorIdentity(String creatorIdentity, Wo wo) {
|
|
|
+ private CompletableFuture<Void> activityRouteFuture(Work work, Wo wo) {
|
|
|
+ return CompletableFuture.runAsync(() -> {
|
|
|
+ WoActivity woActivity = new WoActivity();
|
|
|
+ try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
+ Business business = new Business(emc);
|
|
|
+ Activity activity = business.getActivity(work);
|
|
|
+ if (null != activity) {
|
|
|
+ activity.copyTo(woActivity);
|
|
|
+ wo.setActivity(woActivity);
|
|
|
+ if (Objects.equals(ActivityType.manual, activity.getActivityType())) {
|
|
|
+ wo.setRouteList(WoRoute.copier.copy(business.route().pick(((Manual) activity).getRouteList())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private CompletableFuture<Void> creatorIdentityFuture(String creatorIdentity, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
Business business = new Business(emc);
|
|
|
@@ -270,7 +245,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> creatorPerson(String creatorPerson, Wo wo) {
|
|
|
+ private CompletableFuture<Void> creatorPersonFuture(String creatorPerson, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
Business business = new Business(emc);
|
|
|
@@ -281,7 +256,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> creatorUnit(String creatorUnit, Wo wo) {
|
|
|
+ private CompletableFuture<Void> creatorUnitFuture(String creatorUnit, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
Business business = new Business(emc);
|
|
|
@@ -292,19 +267,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private Wo workCompleted(EffectivePerson effectivePerson, WorkCompleted workCompleted)
|
|
|
- throws InterruptedException, ExecutionException {
|
|
|
- Wo wo = new Wo();
|
|
|
- CompletableFuture.allOf(completedJson(workCompleted, wo), completedData(workCompleted, wo),
|
|
|
- read(effectivePerson, workCompleted.getJob(), wo),
|
|
|
- creatorIdentity(workCompleted.getCreatorIdentity(), wo),
|
|
|
- creatorPerson(workCompleted.getCreatorPerson(), wo), creatorUnit(workCompleted.getCreatorUnit(), wo),
|
|
|
- attachment(effectivePerson, workCompleted.getJob(), wo),
|
|
|
- completedRecord(effectivePerson, workCompleted, wo)).get();
|
|
|
- return wo;
|
|
|
- }
|
|
|
-
|
|
|
- private CompletableFuture<Void> completedJson(WorkCompleted workCompleted, Wo wo) {
|
|
|
+ private CompletableFuture<Void> workCompletedJsonFuture(WorkCompleted workCompleted, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
try {
|
|
|
wo.setWork(gson.toJsonTree(WoWorkCompleted.copier.copy(workCompleted)));
|
|
|
@@ -314,7 +277,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private CompletableFuture<Void> completedData(WorkCompleted workCompleted, Wo wo) {
|
|
|
+ private CompletableFuture<Void> workCompletedDataFuture(WorkCompleted workCompleted, Wo wo) {
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
if (BooleanUtils.isTrue(workCompleted.getMerged())) {
|
|
|
wo.setData(workCompleted.getProperties().getData());
|
|
|
@@ -395,6 +358,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
|
|
|
public static class Wo extends GsonPropertyObject {
|
|
|
|
|
|
+ private static final long serialVersionUID = -2651851022553574012L;
|
|
|
// work和workCompleted都有
|
|
|
private JsonElement work;
|
|
|
// work和workCompleted都有
|
|
|
@@ -416,8 +380,8 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
// work和workCompleted都有
|
|
|
private List<WoAttachment> attachmentList;
|
|
|
|
|
|
- // work和workCompleted都有
|
|
|
- private List<WoRecord> recordList;
|
|
|
+ // work和workCompleted都有,需要先行初始化,因为record可能为空
|
|
|
+ private List<WoRecord> recordList = new ArrayList<>();
|
|
|
|
|
|
// 只有work有
|
|
|
private WoActivity activity;
|
|
|
@@ -680,6 +644,9 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
}
|
|
|
|
|
|
public static class WoAttachment extends Attachment {
|
|
|
+
|
|
|
+ private static final long serialVersionUID = -5323646346508661416L;
|
|
|
+
|
|
|
static WrapCopier<Attachment, WoAttachment> copier = WrapCopierFactory.wo(Attachment.class, WoAttachment.class,
|
|
|
null, JpaObject.FieldsInvisibleIncludeProperites);
|
|
|
|
|
|
@@ -696,6 +663,7 @@ class V2GetWorkOrWorkCompleted extends BaseAction {
|
|
|
|
|
|
public static class WoAttachmentControl extends GsonPropertyObject {
|
|
|
|
|
|
+ private static final long serialVersionUID = -1159880170066584166L;
|
|
|
private Boolean allowRead = false;
|
|
|
private Boolean allowEdit = false;
|
|
|
private Boolean allowControl = false;
|