Skip to content

Commit

Permalink
feat: 条目更新时更新update_time字段 (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao authored Nov 13, 2024
1 parent ec0326f commit 44d6f06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## 优化

- 条目条件查询接口
- 条目更新时更新update_time字段

# 0.20.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public synchronized Mono<Subject> create(Subject subject) {
Assert.notNull(subject, "'subject' must not be null.");
Assert.notNull(subject.getType(), "'subject.type' must not be null.");
return copyProperties(subject, new SubjectEntity())
.map(subjectEntity -> {
subjectEntity.setUpdateTime(LocalDateTime.now());
return subjectEntity;
})
.flatMap(subjectRepository::save)
.doOnNext(entity -> applicationContext.publishEvent(new SubjectAddEvent(this, entity)))
.flatMap(subjectEntity -> copyProperties(subjectEntity, subject));
Expand All @@ -182,7 +186,8 @@ public Mono<Void> update(Subject subject) {
.flatMap(this::publishSubjectUpdateEvent)
.flatMap(entity -> {
Map<SqlIdentifier, Object> map = new HashMap<>();
map.put(SqlIdentifier.unquoted("update_time"), entity.getUpdateTime());
map.put(SqlIdentifier.unquoted("update_time"),
entity.getUpdateTime() == null ? LocalDateTime.now() : entity.getUpdateTime());
map.put(SqlIdentifier.unquoted("name"), entity.getName());
map.put(SqlIdentifier.unquoted("nameCn"), entity.getNameCn());
map.put(SqlIdentifier.unquoted("cover"), entity.getCover());
Expand Down

0 comments on commit 44d6f06

Please sign in to comment.