提交 275a512b 编写于 作者: Z zhourui

#332 develop

上级 c46d2113
...@@ -5,6 +5,7 @@ import java.util.Comparator; ...@@ -5,6 +5,7 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.script.Bindings; import javax.script.Bindings;
...@@ -249,7 +250,7 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -249,7 +250,7 @@ public class AeiObjects extends GsonPropertyObject {
if (null == this.workLogs) { if (null == this.workLogs) {
List<WorkLog> os = this.business.entityManagerContainer().listEqual(WorkLog.class, WorkLog.job_FIELDNAME, List<WorkLog> os = this.business.entityManagerContainer().listEqual(WorkLog.class, WorkLog.job_FIELDNAME,
this.work.getJob()); this.work.getJob());
/* 保持和前端得到的相同排序 */ // 保持和前端得到的相同排序
this.workLogs = os.stream() this.workLogs = os.stream()
.sorted(Comparator.comparing(WorkLog::getFromTime, Comparator.nullsLast(Date::compareTo)) .sorted(Comparator.comparing(WorkLog::getFromTime, Comparator.nullsLast(Date::compareTo))
.thenComparing(WorkLog::getArrivedTime, Comparator.nullsLast(Date::compareTo))) .thenComparing(WorkLog::getArrivedTime, Comparator.nullsLast(Date::compareTo)))
...@@ -298,9 +299,8 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -298,9 +299,8 @@ public class AeiObjects extends GsonPropertyObject {
} }
public List<TaskCompleted> getJoinInquireTaskCompleteds() throws Exception { public List<TaskCompleted> getJoinInquireTaskCompleteds() throws Exception {
return this.getTaskCompleteds().stream().filter(o -> { return this.getTaskCompleteds().stream().filter(o -> BooleanUtils.isNotFalse(o.getJoinInquire()))
return BooleanUtils.isNotFalse(o.getJoinInquire()); .collect(Collectors.toList());
}).collect(Collectors.toList());
} }
public List<Read> getReads() throws Exception { public List<Read> getReads() throws Exception {
...@@ -538,7 +538,6 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -538,7 +538,6 @@ public class AeiObjects extends GsonPropertyObject {
this.commitDocumentVersion(); this.commitDocumentVersion();
this.commitRecord(); this.commitRecord();
this.commitAttachment(); this.commitAttachment();
// this.getWorkDataHelper().update(this.getData());
this.commitData(); this.commitData();
this.commitDynamicEntity(); this.commitDynamicEntity();
this.entityManagerContainer().commit(); this.entityManagerContainer().commit();
...@@ -721,9 +720,9 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -721,9 +720,9 @@ public class AeiObjects extends GsonPropertyObject {
private void executeMapping() throws Exception { private void executeMapping() throws Exception {
for (Mapping m : this.getMappings()) { for (Mapping m : this.getMappings()) {
/* 仅处理最后work转workCompleted的事件 */ // 仅处理最后work转workCompleted的事件
if ((!this.getCreateWorkCompleteds().isEmpty()) || (!this.getUpdateTaskCompleteds().isEmpty())) { if ((!this.getCreateWorkCompleteds().isEmpty()) || (!this.getUpdateTaskCompleteds().isEmpty())) {
List<WorkCompleted> list = new ArrayList<WorkCompleted>(); List<WorkCompleted> list = new ArrayList<>();
list.addAll(this.getCreateWorkCompleteds()); list.addAll(this.getCreateWorkCompleteds());
list.addAll(this.getUpdateWorkCompleteds()); list.addAll(this.getUpdateWorkCompleteds());
for (WorkCompleted workCompleted : list) { for (WorkCompleted workCompleted : list) {
...@@ -733,7 +732,7 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -733,7 +732,7 @@ public class AeiObjects extends GsonPropertyObject {
this.entityManagerContainer().beginTransaction(cls); this.entityManagerContainer().beginTransaction(cls);
JpaObject o = this.entityManagerContainer().find(workCompleted.getJob(), cls); JpaObject o = this.entityManagerContainer().find(workCompleted.getJob(), cls);
if (null == o) { if (null == o) {
o = (JpaObject) cls.newInstance(); o = cls.newInstance();
o.setId(workCompleted.getJob()); o.setId(workCompleted.getJob());
this.entityManagerContainer().persist(o, CheckPersistType.all); this.entityManagerContainer().persist(o, CheckPersistType.all);
} }
...@@ -914,7 +913,7 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -914,7 +913,7 @@ public class AeiObjects extends GsonPropertyObject {
commitTaskCompletedCreatePart(); commitTaskCompletedCreatePart();
// 更新已办 // 更新已办
commitTaskCompletedUpdatePart(); commitTaskCompletedUpdatePart();
// 删除已办 // 删除已办 */
commitTaskCompletedDeletePart(); commitTaskCompletedDeletePart();
} }
} }
...@@ -946,22 +945,19 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -946,22 +945,19 @@ public class AeiObjects extends GsonPropertyObject {
private void commitTaskCompletedDeletePart() { private void commitTaskCompletedDeletePart() {
this.getDeleteTaskCompleteds().stream().forEach(o -> { this.getDeleteTaskCompleteds().stream().forEach(o -> {
TaskCompleted obj;
try { try {
// 要删除此已经办前此人其他的已办lastest标记为true TaskCompleted deleteTaskCompleted = this.business.entityManagerContainer().find(o.getId(),
TaskCompleted lastest = this.getTaskCompleteds().stream() TaskCompleted.class);
.filter(p -> StringUtils.equals(o.getPerson(), p.getPerson()) if (null != deleteTaskCompleted) {
&& (!StringUtils.equals(o.getId(), p.getId()))) this.business.entityManagerContainer().remove(deleteTaskCompleted, CheckRemoveType.all);
.sorted(Comparator // 要删除此已经办前此人其他的已办lastest标记为true
.comparing(TaskCompleted::getStartTime, Comparator.nullsFirst(Date::compareTo)) this.getTaskCompleteds().stream()
.reversed()) .filter(p -> StringUtils.equals(o.getPerson(), p.getPerson())
.findFirst().orElse(null); && (!StringUtils.equals(o.getId(), p.getId())))
if (null != lastest) { .sorted(Comparator
lastest.setLatest(true); .comparing(TaskCompleted::getStartTime, Comparator.nullsFirst(Date::compareTo))
} .reversed())
obj = this.business.entityManagerContainer().find(o.getId(), TaskCompleted.class); .findFirst().ifPresent(q -> q.setLatest(true));
if (null != obj) {
this.business.entityManagerContainer().remove(obj, CheckRemoveType.all);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(e); logger.error(e);
...@@ -985,27 +981,33 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -985,27 +981,33 @@ public class AeiObjects extends GsonPropertyObject {
private void commitReadCreatePart() { private void commitReadCreatePart() {
// 去重可能的在同一次提交中产生的对同一个人的多份Read // 去重可能的在同一次提交中产生的对同一个人的多份Read
this.getCreateReads().stream().collect(Collectors.groupingBy(o -> o.getJob() + "#" + o.getPerson())).entrySet() this.getCreateReads().stream().collect(Collectors.groupingBy(o -> o.getJob() + "#" + o.getPerson())).entrySet()
.forEach(entry -> { .forEach(
Read obj = entry.getValue().stream() entry -> entry
.sorted(Comparator.comparing(Read::getCreateTime, Comparator.nullsFirst(Date::compareTo)) .getValue().stream().sorted(
.reversed().thenComparing( Comparator
Comparator.comparing(Read::getId, Comparator.nullsLast(String::compareTo)))) .comparing(Read::getCreateTime, Comparator.nullsFirst(Date::compareTo))
.findFirst().get(); .reversed()
try { .thenComparing(Comparator.comparing(Read::getId,
Read existed = this.getReads().stream().filter(p -> StringUtils.equals(obj.getJob(), p.getJob()) Comparator.nullsLast(String::compareTo))))
&& StringUtils.equals(obj.getPerson(), p.getPerson())).findFirst().orElse(null); .findFirst().ifPresent(o -> {
// 不存在内容重复的待阅 try {
if (null == existed) { Optional<Read> existOptional = this.getReads().stream()
this.business.entityManagerContainer().persist(obj, CheckPersistType.all); .filter(p -> StringUtils.equals(o.getJob(), p.getJob())
/* 创建待阅的参阅 */ && StringUtils.equals(o.getPerson(), p.getPerson()))
this.createReview(new Review(this.getWork(), obj.getPerson())); .findFirst();
} else { // 不存在内容重复的待阅
obj.copyTo(existed, JpaObject.FieldsUnmodify); if (!existOptional.isPresent()) {
} this.business.entityManagerContainer().persist(o, CheckPersistType.all);
} catch (Exception e) { // 创建待阅的参阅
logger.error(e); this.createReview(new Review(this.getWork(), o.getPerson()));
} } else {
}); o.copyTo(existOptional.get(), JpaObject.FieldsUnmodify);
}
} catch (Exception e) {
logger.error(e);
}
}));
} }
private void commitReadUpdatePart() { private void commitReadUpdatePart() {
...@@ -1047,18 +1049,19 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -1047,18 +1049,19 @@ public class AeiObjects extends GsonPropertyObject {
private void commitReadCompletedCreatePart() { private void commitReadCompletedCreatePart() {
this.getCreateReadCompleteds().stream().forEach(o -> { this.getCreateReadCompleteds().stream().forEach(o -> {
ReadCompleted obj;
try { try {
// 已阅唯一 // 已阅唯一
obj = this.getReadCompleteds().stream().filter(p -> StringUtils.equals(o.getJob(), p.getJob()) Optional<ReadCompleted> optional = this.getReadCompleteds().stream()
&& StringUtils.equals(o.getPerson(), p.getPerson())).findFirst().orElse(null); .filter(p -> StringUtils.equals(o.getJob(), p.getJob())
if (null == obj) { && StringUtils.equals(o.getPerson(), p.getPerson()))
.findFirst();
if (!optional.isPresent()) {
this.business.entityManagerContainer().persist(o, CheckPersistType.all); this.business.entityManagerContainer().persist(o, CheckPersistType.all);
// 创建已阅参阅 // 创建已阅参阅
this.createReview(new Review(this.getWork(), o.getPerson())); this.createReview(new Review(this.getWork(), o.getPerson()));
} else { } else {
// 如果逻辑上相同的已阅已经存在,覆盖内容. // 如果逻辑上相同的已阅已经存在,覆盖内容.
o.copyTo(obj, JpaObject.FieldsUnmodify); o.copyTo(optional.get(), JpaObject.FieldsUnmodify);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(e); logger.error(e);
...@@ -1106,28 +1109,27 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -1106,28 +1109,27 @@ public class AeiObjects extends GsonPropertyObject {
private void commitReviewCreatePart() { private void commitReviewCreatePart() {
// 去重可能的在同一次提交中产生的对同一个人的多份Review // 去重可能的在同一次提交中产生的对同一个人的多份Review
this.getCreateReviews().stream().collect(Collectors.groupingBy(o -> o.getJob() + "#" + o.getPerson())) this.getCreateReviews().stream().collect(Collectors.groupingBy(o -> o.getJob() + "#" + o.getPerson()))
.entrySet().forEach(entry -> { .entrySet()
Review obj = entry.getValue().stream() .forEach(entry -> entry.getValue().stream()
.sorted(Comparator.comparing(Review::getCreateTime, Comparator.nullsFirst(Date::compareTo)) .sorted(Comparator.comparing(Review::getCreateTime, Comparator.nullsFirst(Date::compareTo))
.reversed().thenComparing(Comparator.comparing(Review::getId, .reversed().thenComparing(
Comparator.nullsLast(String::compareTo)))) Comparator.comparing(Review::getId, Comparator.nullsLast(String::compareTo))))
.findFirst().get(); .findFirst().ifPresent(o -> {
try { try {
// 参阅唯一 Optional<Review> existOptional = this.getReviews().stream()
Review existed = this.getReviews().stream() .filter(p -> StringUtils.equals(o.getJob(), p.getJob())
.filter(p -> StringUtils.equals(obj.getJob(), p.getJob()) && StringUtils.equals(o.getPerson(), p.getPerson()))
&& StringUtils.equals(obj.getPerson(), p.getPerson())) .findFirst();
.findFirst().orElse(null); if (!existOptional.isPresent()) {
if (null == existed) { this.business.entityManagerContainer().persist(o, CheckPersistType.all);
this.business.entityManagerContainer().persist(obj, CheckPersistType.all); } else {
} else { // 如果逻辑上相同的已阅已经存在,覆盖内容.
// 如果逻辑上相同的已阅已经存在,覆盖内容. o.copyTo(existOptional.get(), JpaObject.FieldsUnmodify);
obj.copyTo(existed, JpaObject.FieldsUnmodify); }
} } catch (Exception e) {
} catch (Exception e) { logger.error(e);
logger.error(e); }
} }));
});
} }
private void commitReviewUpdatePart() { private void commitReviewUpdatePart() {
...@@ -1159,7 +1161,7 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -1159,7 +1161,7 @@ public class AeiObjects extends GsonPropertyObject {
|| ListTools.isNotEmpty(this.getDeleteDocumentVersions()) || ListTools.isNotEmpty(this.getDeleteDocumentVersions())
|| ListTools.isNotEmpty(this.getUpdateDocumentVersions())) { || ListTools.isNotEmpty(this.getUpdateDocumentVersions())) {
this.entityManagerContainer().beginTransaction(DocumentVersion.class); this.entityManagerContainer().beginTransaction(DocumentVersion.class);
/* 保存版式文件 */ // 保存版式文件
this.getCreateDocumentVersions().stream().forEach(o -> { this.getCreateDocumentVersions().stream().forEach(o -> {
try { try {
this.business.entityManagerContainer().persist(o, CheckPersistType.all); this.business.entityManagerContainer().persist(o, CheckPersistType.all);
...@@ -1177,9 +1179,8 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -1177,9 +1179,8 @@ public class AeiObjects extends GsonPropertyObject {
}); });
// 删除版式文件 // 删除版式文件
this.getDeleteDocumentVersions().stream().forEach(o -> { this.getDeleteDocumentVersions().stream().forEach(o -> {
DocumentVersion obj;
try { try {
obj = this.business.entityManagerContainer().find(o.getId(), DocumentVersion.class); DocumentVersion obj = this.business.entityManagerContainer().find(o.getId(), DocumentVersion.class);
if (null != obj) { if (null != obj) {
this.business.entityManagerContainer().remove(obj, CheckRemoveType.all); this.business.entityManagerContainer().remove(obj, CheckRemoveType.all);
} }
...@@ -1230,9 +1231,8 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -1230,9 +1231,8 @@ public class AeiObjects extends GsonPropertyObject {
this.entityManagerContainer().beginTransaction(Attachment.class); this.entityManagerContainer().beginTransaction(Attachment.class);
// 保存,更新附件是不可能的,删除附件 // 保存,更新附件是不可能的,删除附件
this.getDeleteAttachments().stream().forEach(o -> { this.getDeleteAttachments().stream().forEach(o -> {
Attachment obj;
try { try {
obj = this.business.entityManagerContainer().find(o.getId(), Attachment.class); Attachment obj = this.business.entityManagerContainer().find(o.getId(), Attachment.class);
if (null != obj) { if (null != obj) {
StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class, StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
obj.getStorage()); obj.getStorage());
...@@ -1251,11 +1251,11 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -1251,11 +1251,11 @@ public class AeiObjects extends GsonPropertyObject {
private void commitData() throws Exception { private void commitData() throws Exception {
List<Attachment> os = ListUtils.subtract(this.getAttachments(), this.getDeleteAttachments()); List<Attachment> os = ListUtils.subtract(this.getAttachments(), this.getDeleteAttachments());
os = ListUtils.sum(os, this.getCreateAttachments()); os = ListUtils.sum(os, this.getCreateAttachments());
Data data = this.getData().removeWork().removeAttachmentList().setAttachmentList(os); Data d = this.getData().removeWork().removeAttachmentList().setAttachmentList(os);
if (ListTools.isNotEmpty(this.getCreateWorkCompleteds())) { if (ListTools.isNotEmpty(this.getCreateWorkCompleteds())) {
data.setWork(this.getCreateWorkCompleteds().get(0)); d.setWork(this.getCreateWorkCompleteds().get(0));
} else { } else {
data.setWork(this.getWork()); d.setWork(this.getWork());
} }
this.getWorkDataHelper().update(data); this.getWorkDataHelper().update(data);
} }
...@@ -1401,18 +1401,26 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -1401,18 +1401,26 @@ public class AeiObjects extends GsonPropertyObject {
private void messageCreateRead() { private void messageCreateRead() {
// 去重可能的在同一次提交中产生的对同一个人的多份Read // 去重可能的在同一次提交中产生的对同一个人的多份Read
this.getCreateReads().stream().collect(Collectors.groupingBy(o -> o.getJob() + "#" + o.getPerson())).entrySet() this.getCreateReads().stream().collect(Collectors.groupingBy(o -> o.getJob() + "#" + o.getPerson())).entrySet()
.forEach(entry -> { .forEach(
Read obj = entry.getValue().stream() entry -> entry
.sorted(Comparator.comparing(Read::getCreateTime, Comparator.nullsFirst(Date::compareTo)) .getValue().stream().sorted(
.reversed().thenComparing( Comparator
Comparator.comparing(Read::getId, Comparator.nullsLast(String::compareTo)))) .comparing(Read::getCreateTime, Comparator.nullsFirst(Date::compareTo))
.findFirst().get(); .reversed()
try { .thenComparing(Comparator.comparing(Read::getId,
MessageFactory.read_create(obj); Comparator.nullsLast(String::compareTo))))
} catch (Exception e) { .findFirst().ifPresent(o -> {
logger.error(e); try {
} if (this.getReads().stream()
}); .noneMatch(p -> StringUtils.equals(o.getJob(), p.getJob())
&& StringUtils.equals(o.getPerson(), p.getPerson()))) {
// 不存在内容重复的待阅
MessageFactory.read_create(o);
}
} catch (Exception e) {
logger.error(e);
}
}));
} }
private void messageDeleteReadCompleted() throws Exception { private void messageDeleteReadCompleted() throws Exception {
...@@ -1436,18 +1444,22 @@ public class AeiObjects extends GsonPropertyObject { ...@@ -1436,18 +1444,22 @@ public class AeiObjects extends GsonPropertyObject {
private void messageCreateReview() { private void messageCreateReview() {
// 去重可能的在同一次提交中产生的对同一个人的多份Review // 去重可能的在同一次提交中产生的对同一个人的多份Review
this.getCreateReviews().stream().collect(Collectors.groupingBy(o -> o.getJob() + "#" + o.getPerson())) this.getCreateReviews().stream().collect(Collectors.groupingBy(o -> o.getJob() + "#" + o.getPerson()))
.entrySet().forEach(entry -> { .entrySet()
Review obj = entry.getValue().stream() .forEach(entry -> entry.getValue().stream()
.sorted(Comparator.comparing(Review::getCreateTime, Comparator.nullsFirst(Date::compareTo)) .sorted(Comparator.comparing(Review::getCreateTime, Comparator.nullsFirst(Date::compareTo))
.reversed().thenComparing(Comparator.comparing(Review::getId, .reversed().thenComparing(
Comparator.nullsLast(String::compareTo)))) Comparator.comparing(Review::getId, Comparator.nullsLast(String::compareTo))))
.findFirst().get(); .findFirst().ifPresent(o -> {
try { try {
MessageFactory.review_create(obj); if (this.getReviews().stream().noneMatch(p -> StringUtils.equals(o.getJob(), p.getJob())
} catch (Exception e) { && StringUtils.equals(o.getPerson(), p.getPerson()))) {
logger.error(e); // 不存在内容重复的待阅
} MessageFactory.review_create(o);
}); }
} catch (Exception e) {
logger.error(e);
}
}));
} }
private void messageDeleteAttachment() throws Exception { private void messageDeleteAttachment() throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册