From c55090bc2ee023f6c494ffee1aecbf801a88d938 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 13 Jul 2026 14:51:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=BB=98=E8=AE=A4=E9=85=92?= =?UTF-8?q?=E5=BA=97=E5=90=AF=E5=8A=A8=E8=A6=86=E7=9B=96=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PlatformIdentityBootstrapRunner.java | 11 +++++----- .../PlatformIdentityBootstrapRunnerTest.java | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/cn/nianxx/thhotel/platform/identity/service/impl/PlatformIdentityBootstrapRunner.java b/server/src/main/java/cn/nianxx/thhotel/platform/identity/service/impl/PlatformIdentityBootstrapRunner.java index 4af1e4a..603c6e1 100644 --- a/server/src/main/java/cn/nianxx/thhotel/platform/identity/service/impl/PlatformIdentityBootstrapRunner.java +++ b/server/src/main/java/cn/nianxx/thhotel/platform/identity/service/impl/PlatformIdentityBootstrapRunner.java @@ -185,7 +185,7 @@ public class PlatformIdentityBootstrapRunner implements ApplicationRunner { } /** - * 初始化默认酒店基础资料,供首个管理员和本地测试环境使用。 + * 初始化默认酒店基础资料;已有酒店由管理后台维护,启动时不覆盖展示名称、时区和排序。 */ private void seedDefaultHotel() { String defaultHotelId = authProperties.getBootstrap().getDefaultHotelId(); @@ -195,17 +195,16 @@ public class PlatformIdentityBootstrapRunner implements ApplicationRunner { PlatformHotelEntity hotel = hotelRepository.findHotelByHotelId(defaultHotelId) .orElseGet(PlatformHotelEntity::new); boolean creating = hotel.getId() == null; + if (!creating) { + return; + } hotel.setHotelId(defaultHotelId); hotel.setHotelName(defaultString(authProperties.getBootstrap().getDefaultHotelName(), defaultHotelId)); hotel.setHotelStatus(PlatformHotelStatus.ACTIVE.name()); hotel.setTimeZone(defaultString(authProperties.getBootstrap().getDefaultHotelTimeZone(), "Asia/Bangkok")); hotel.setSortOrder(10); setAuditTime(hotel, creating); - if (creating) { - hotelRepository.insertHotel(hotel); - } else { - hotelRepository.updateHotel(hotel); - } + hotelRepository.insertHotel(hotel); } /** diff --git a/server/src/test/java/cn/nianxx/thhotel/platform/identity/service/impl/PlatformIdentityBootstrapRunnerTest.java b/server/src/test/java/cn/nianxx/thhotel/platform/identity/service/impl/PlatformIdentityBootstrapRunnerTest.java index 454eb85..af06a5b 100644 --- a/server/src/test/java/cn/nianxx/thhotel/platform/identity/service/impl/PlatformIdentityBootstrapRunnerTest.java +++ b/server/src/test/java/cn/nianxx/thhotel/platform/identity/service/impl/PlatformIdentityBootstrapRunnerTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import cn.nianxx.thhotel.ThHotelApplication; import java.time.LocalDateTime; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -101,4 +102,24 @@ class PlatformIdentityBootstrapRunnerTest { """, Integer.class, viewerRoleId, debugPermissionId); assertThat(staleCount).isZero(); } + + @Test + void shouldNotOverwriteExistingBootstrapHotelDisplayFields() { + jdbcTemplate.update(""" + UPDATE platform_hotel + SET hotel_name = ?, time_zone = ?, sort_order = ? + WHERE hotel_id = 'HOTEL-TEST' + """, "人工维护酒店", "Asia/Shanghai", 66); + + bootstrapRunner.run((ApplicationArguments) null); + + Map hotel = jdbcTemplate.queryForMap(""" + SELECT hotel_name, time_zone, sort_order + FROM platform_hotel + WHERE hotel_id = 'HOTEL-TEST' + """); + assertThat(hotel.get("hotel_name")).isEqualTo("人工维护酒店"); + assertThat(hotel.get("time_zone")).isEqualTo("Asia/Shanghai"); + assertThat(((Number) hotel.get("sort_order")).intValue()).isEqualTo(66); + } }