修复默认酒店启动覆盖名称问题
This commit is contained in:
@@ -185,7 +185,7 @@ public class PlatformIdentityBootstrapRunner implements ApplicationRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化默认酒店基础资料,供首个管理员和本地测试环境使用。
|
* 初始化默认酒店基础资料;已有酒店由管理后台维护,启动时不覆盖展示名称、时区和排序。
|
||||||
*/
|
*/
|
||||||
private void seedDefaultHotel() {
|
private void seedDefaultHotel() {
|
||||||
String defaultHotelId = authProperties.getBootstrap().getDefaultHotelId();
|
String defaultHotelId = authProperties.getBootstrap().getDefaultHotelId();
|
||||||
@@ -195,17 +195,16 @@ public class PlatformIdentityBootstrapRunner implements ApplicationRunner {
|
|||||||
PlatformHotelEntity hotel = hotelRepository.findHotelByHotelId(defaultHotelId)
|
PlatformHotelEntity hotel = hotelRepository.findHotelByHotelId(defaultHotelId)
|
||||||
.orElseGet(PlatformHotelEntity::new);
|
.orElseGet(PlatformHotelEntity::new);
|
||||||
boolean creating = hotel.getId() == null;
|
boolean creating = hotel.getId() == null;
|
||||||
|
if (!creating) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
hotel.setHotelId(defaultHotelId);
|
hotel.setHotelId(defaultHotelId);
|
||||||
hotel.setHotelName(defaultString(authProperties.getBootstrap().getDefaultHotelName(), defaultHotelId));
|
hotel.setHotelName(defaultString(authProperties.getBootstrap().getDefaultHotelName(), defaultHotelId));
|
||||||
hotel.setHotelStatus(PlatformHotelStatus.ACTIVE.name());
|
hotel.setHotelStatus(PlatformHotelStatus.ACTIVE.name());
|
||||||
hotel.setTimeZone(defaultString(authProperties.getBootstrap().getDefaultHotelTimeZone(), "Asia/Bangkok"));
|
hotel.setTimeZone(defaultString(authProperties.getBootstrap().getDefaultHotelTimeZone(), "Asia/Bangkok"));
|
||||||
hotel.setSortOrder(10);
|
hotel.setSortOrder(10);
|
||||||
setAuditTime(hotel, creating);
|
setAuditTime(hotel, creating);
|
||||||
if (creating) {
|
|
||||||
hotelRepository.insertHotel(hotel);
|
hotelRepository.insertHotel(hotel);
|
||||||
} else {
|
|
||||||
hotelRepository.updateHotel(hotel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
|
|
||||||
import cn.nianxx.thhotel.ThHotelApplication;
|
import cn.nianxx.thhotel.ThHotelApplication;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -101,4 +102,24 @@ class PlatformIdentityBootstrapRunnerTest {
|
|||||||
""", Integer.class, viewerRoleId, debugPermissionId);
|
""", Integer.class, viewerRoleId, debugPermissionId);
|
||||||
assertThat(staleCount).isZero();
|
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<String, Object> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user