From 44d6f0643f90929d0d267079fbb43452badac077 Mon Sep 17 00:00:00 2001 From: ChiveHao Date: Wed, 13 Nov 2024 12:30:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9D=A1=E7=9B=AE=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=96=B0update=5Ftime=E5=AD=97=E6=AE=B5=20(#?= =?UTF-8?q?736)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.MD | 1 + .../core/subject/service/impl/SubjectServiceImpl.java | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index c79958d6..0d80080d 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -7,6 +7,7 @@ ## 优化 - 条目条件查询接口 +- 条目更新时更新update_time字段 # 0.20.3 diff --git a/server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java b/server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java index 8fcaffd9..855b4a13 100644 --- a/server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java +++ b/server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java @@ -158,6 +158,10 @@ public synchronized Mono 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)); @@ -182,7 +186,8 @@ public Mono update(Subject subject) { .flatMap(this::publishSubjectUpdateEvent) .flatMap(entity -> { Map 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());