diff --git a/migration/db/migrations/20240118223117_rename_customer_checkin_record_user_id_to_customer_id.down.sql b/migration/db/migrations/20240118223117_rename_customer_checkin_record_user_id_to_customer_id.down.sql new file mode 100644 index 00000000..b5352486 --- /dev/null +++ b/migration/db/migrations/20240118223117_rename_customer_checkin_record_user_id_to_customer_id.down.sql @@ -0,0 +1 @@ +ALTER TABLE customer_checkin_record RENAME customer_id TO user_id; \ No newline at end of file diff --git a/migration/db/migrations/20240118223117_rename_customer_checkin_record_user_id_to_customer_id.up.sql b/migration/db/migrations/20240118223117_rename_customer_checkin_record_user_id_to_customer_id.up.sql new file mode 100644 index 00000000..7d444643 --- /dev/null +++ b/migration/db/migrations/20240118223117_rename_customer_checkin_record_user_id_to_customer_id.up.sql @@ -0,0 +1 @@ +ALTER TABLE customer_checkin_record RENAME user_id TO customer_id; \ No newline at end of file diff --git a/src/main/java/org/daming/hoteler/api/web/CustomerCheckinRecordController.java b/src/main/java/org/daming/hoteler/api/web/CustomerCheckinRecordController.java index f853e301..4fafb81f 100644 --- a/src/main/java/org/daming/hoteler/api/web/CustomerCheckinRecordController.java +++ b/src/main/java/org/daming/hoteler/api/web/CustomerCheckinRecordController.java @@ -36,7 +36,7 @@ public class CustomerCheckinRecordController { @PostMapping("customer-checkin-record") public DataResponse createCustomerCheckinRecord(@RequestBody CreateCustomerCheckinRecordRequest request) { var ur = new CustomerCheckinRecord() - .setUserId(request.getUserId()) + .setCustomerId(request.getCustomerId()) .setRoomId(request.getRoomId()) .setBeginDate(request.getBeginDate()) .setEndDate(request.getEndDate()); @@ -49,7 +49,7 @@ public DataResponse createCustomerCheckinRecord(@RequestBody CreateCustome public CommonResponse updateCustomerCheckinRecord(@RequestBody UpdateCustomerCheckinRecordRequest request) { var ur = new CustomerCheckinRecord() .setId(request.getId()) - .setUserId(request.getUserId()) + .setCustomerId(request.getCustomerId()) .setRoomId(request.getRoomId()) .setBeginDate(request.getBeginDate()) .setEndDate(request.getEndDate()); diff --git a/src/main/java/org/daming/hoteler/pojo/CustomerCheckinRecord.java b/src/main/java/org/daming/hoteler/pojo/CustomerCheckinRecord.java index ba550170..5256e450 100644 --- a/src/main/java/org/daming/hoteler/pojo/CustomerCheckinRecord.java +++ b/src/main/java/org/daming/hoteler/pojo/CustomerCheckinRecord.java @@ -20,7 +20,7 @@ public class CustomerCheckinRecord implements Serializable { private long id; @JsonFormat(shape = JsonFormat.Shape.STRING) - private long userId; + private long customerId; @JsonFormat(shape = JsonFormat.Shape.STRING) private long roomId; @@ -38,12 +38,12 @@ public CustomerCheckinRecord setId(long id) { return this; } - public long getUserId() { - return userId; + public long getCustomerId() { + return customerId; } - public CustomerCheckinRecord setUserId(long userId) { - this.userId = userId; + public CustomerCheckinRecord setCustomerId(long customerId) { + this.customerId = customerId; return this; } @@ -78,10 +78,10 @@ public CustomerCheckinRecord() { super(); } - public CustomerCheckinRecord(long id, long userId, long roomId, LocalDateTime beginDate, LocalDateTime endDate) { + public CustomerCheckinRecord(long id, long customerId, long roomId, LocalDateTime beginDate, LocalDateTime endDate) { super(); this.id = id; - this.userId = userId; + this.customerId = customerId; this.roomId = roomId; this.beginDate = beginDate; this.endDate = endDate; @@ -91,7 +91,7 @@ public CustomerCheckinRecord(long id, long userId, long roomId, LocalDateTime be public String toString() { return new StringJoiner(", ", CustomerCheckinRecord.class.getSimpleName() + "[", "]") .add("id=" + id) - .add("userId=" + userId) + .add("customerId=" + customerId) .add("roomId=" + roomId) .add("beginDate=" + beginDate) .add("endDate=" + endDate) diff --git a/src/main/java/org/daming/hoteler/pojo/request/CreateCustomerCheckinRecordRequest.java b/src/main/java/org/daming/hoteler/pojo/request/CreateCustomerCheckinRecordRequest.java index 3fa161dd..d0d8eaea 100644 --- a/src/main/java/org/daming/hoteler/pojo/request/CreateCustomerCheckinRecordRequest.java +++ b/src/main/java/org/daming/hoteler/pojo/request/CreateCustomerCheckinRecordRequest.java @@ -16,7 +16,7 @@ public class CreateCustomerCheckinRecordRequest implements Serializable { private static final long serialVersionUID = 3021114417834745800L; @JsonFormat(shape = JsonFormat.Shape.STRING) - private long userId; + private long customerId; @JsonFormat(shape = JsonFormat.Shape.STRING) private long roomId; @@ -25,12 +25,12 @@ public class CreateCustomerCheckinRecordRequest implements Serializable { private LocalDateTime endDate; - public long getUserId() { - return userId; + public long getCustomerId() { + return customerId; } - public void setUserId(long userId) { - this.userId = userId; + public void setCustomerId(long customerId) { + this.customerId = customerId; } public long getRoomId() { @@ -61,9 +61,9 @@ public CreateCustomerCheckinRecordRequest() { super(); } - public CreateCustomerCheckinRecordRequest(long userId, long roomId, LocalDateTime beginDate, LocalDateTime endDate) { + public CreateCustomerCheckinRecordRequest(long customerId, long roomId, LocalDateTime beginDate, LocalDateTime endDate) { super(); - this.userId = userId; + this.customerId = customerId; this.roomId = roomId; this.beginDate = beginDate; this.endDate = endDate; @@ -72,7 +72,7 @@ public CreateCustomerCheckinRecordRequest(long userId, long roomId, LocalDateTim @Override public String toString() { return new StringJoiner(", ", CreateCustomerCheckinRecordRequest.class.getSimpleName() + "[", "]") - .add("userId=" + userId) + .add("customerId=" + customerId) .add("roomId=" + roomId) .add("beginDate=" + beginDate) .add("endDate=" + endDate) diff --git a/src/main/java/org/daming/hoteler/pojo/request/UpdateCustomerCheckinRecordRequest.java b/src/main/java/org/daming/hoteler/pojo/request/UpdateCustomerCheckinRecordRequest.java index e0b38655..7d2a38d2 100644 --- a/src/main/java/org/daming/hoteler/pojo/request/UpdateCustomerCheckinRecordRequest.java +++ b/src/main/java/org/daming/hoteler/pojo/request/UpdateCustomerCheckinRecordRequest.java @@ -20,7 +20,7 @@ public class UpdateCustomerCheckinRecordRequest implements Serializable { private long id; @JsonFormat(shape = JsonFormat.Shape.STRING) - private long userId; + private long customerId; @JsonFormat(shape = JsonFormat.Shape.STRING) private long roomId; @@ -37,12 +37,12 @@ public void setId(long id) { this.id = id; } - public long getUserId() { - return userId; + public long getCustomerId() { + return customerId; } - public void setUserId(long userId) { - this.userId = userId; + public void setCustomerId(long customerId) { + this.customerId = customerId; } public long getRoomId() { @@ -73,10 +73,10 @@ public UpdateCustomerCheckinRecordRequest() { super(); } - public UpdateCustomerCheckinRecordRequest(long id, long userId, long roomId, LocalDateTime beginDate, LocalDateTime endDate) { + public UpdateCustomerCheckinRecordRequest(long id, long customerId, long roomId, LocalDateTime beginDate, LocalDateTime endDate) { super(); this.id = id; - this.userId = userId; + this.customerId = customerId; this.roomId = roomId; this.beginDate = beginDate; this.endDate = endDate; @@ -86,7 +86,7 @@ public UpdateCustomerCheckinRecordRequest(long id, long userId, long roomId, Loc public String toString() { return new StringJoiner(", ", UpdateCustomerCheckinRecordRequest.class.getSimpleName() + "[", "]") .add("id=" + id) - .add("userId=" + userId) + .add("customerId=" + customerId) .add("roomId=" + roomId) .add("beginDate=" + beginDate) .add("endDate=" + endDate) diff --git a/src/main/java/org/daming/hoteler/repository/jdbc/impl/CustomerCheckinRecordDaoImpl.java b/src/main/java/org/daming/hoteler/repository/jdbc/impl/CustomerCheckinRecordDaoImpl.java index 07f708fa..a05a664c 100644 --- a/src/main/java/org/daming/hoteler/repository/jdbc/impl/CustomerCheckinRecordDaoImpl.java +++ b/src/main/java/org/daming/hoteler/repository/jdbc/impl/CustomerCheckinRecordDaoImpl.java @@ -34,8 +34,8 @@ public class CustomerCheckinRecordDaoImpl implements ICustomerCheckinRecordDao { @Override public void create(CustomerCheckinRecord customerCheckinRecord) throws HotelerException { var in = Instant.now(); - var sql = "insert into customer_checkin_record (id, user_id, room_id, begin_date, end_date, create_dt, create_user, update_dt, update_user) values ( ?, ?, ?, ?, ?, statement_timestamp(), 'system', statement_timestamp(), 'system')"; - var params = new Object[] { customerCheckinRecord.getId(), customerCheckinRecord.getUserId(), customerCheckinRecord.getRoomId(), customerCheckinRecord.getBeginDate(), customerCheckinRecord.getEndDate() }; + var sql = "insert into customer_checkin_record (id, customer_id, room_id, begin_date, end_date, create_dt, create_user, update_dt, update_user) values ( ?, ?, ?, ?, ?, statement_timestamp(), 'system', statement_timestamp(), 'system')"; + var params = new Object[] { customerCheckinRecord.getId(), customerCheckinRecord.getCustomerId(), customerCheckinRecord.getRoomId(), customerCheckinRecord.getBeginDate(), customerCheckinRecord.getEndDate() }; try { jdbcTemplate.update(sql, params); } catch (Exception ex) { @@ -49,8 +49,8 @@ public void create(CustomerCheckinRecord customerCheckinRecord) throws HotelerEx @Override public void update(CustomerCheckinRecord customerCheckinRecord) throws HotelerException { var in = Instant.now(); - var sql = "update customer_checkin_record set user_id = ?, room_id = ?, begin_date = ?, end_date = ?, update_dt = statement_timestamp(), update_user = 'system' where id = ?"; - var params = new Object[] { customerCheckinRecord.getUserId(), customerCheckinRecord.getRoomId(), customerCheckinRecord.getBeginDate(), customerCheckinRecord.getEndDate(), customerCheckinRecord.getId() }; + var sql = "update customer_checkin_record set customer_id = ?, room_id = ?, begin_date = ?, end_date = ?, update_dt = statement_timestamp(), update_user = 'system' where id = ?"; + var params = new Object[] { customerCheckinRecord.getCustomerId(), customerCheckinRecord.getRoomId(), customerCheckinRecord.getBeginDate(), customerCheckinRecord.getEndDate(), customerCheckinRecord.getId() }; try { jdbcTemplate.update(sql, params); } catch (Exception ex) { @@ -120,7 +120,7 @@ public List list(LocalDate date) throws HotelerException @Override public List listByRoom(long roomId, LocalDate date) throws HotelerException { - var sql = "select id, user_id, room_id, begin_date, end_date from customer_checkin_record where room_id = ? and begin_date <= ? and ? <= end_date and deleted_at is null order by create_dt desc, update_dt desc"; + var sql = "select id, customer_id, room_id, begin_date, end_date from customer_checkin_record where room_id = ? and begin_date <= ? and ? <= end_date and deleted_at is null order by create_dt desc, update_dt desc"; var params = new Object[] { roomId, date, date }; try { return this.jdbcTemplate.query(sql, (rs, i) -> getCustomerCheckinRecord(rs), params); @@ -133,7 +133,7 @@ public List listByRoom(long roomId, LocalDate date) throw private CustomerCheckinRecord getCustomerCheckinRecord(ResultSet rs) throws SQLException { return new CustomerCheckinRecord() .setId(rs.getLong("id")) - .setUserId(rs.getLong("user_id")) + .setCustomerId(rs.getLong("customer_id")) .setRoomId(rs.getLong("room_id")) .setBeginDate(rs.getTimestamp("begin_date").toLocalDateTime()) .setEndDate(rs.getTimestamp("end_date").toLocalDateTime()); diff --git a/src/main/java/org/daming/hoteler/service/impl/CustomerCheckinRecordServiceImpl.java b/src/main/java/org/daming/hoteler/service/impl/CustomerCheckinRecordServiceImpl.java index 208cee69..6fa8dd66 100644 --- a/src/main/java/org/daming/hoteler/service/impl/CustomerCheckinRecordServiceImpl.java +++ b/src/main/java/org/daming/hoteler/service/impl/CustomerCheckinRecordServiceImpl.java @@ -56,7 +56,7 @@ var record = new CustomerCheckinRecord(); record.setBeginDate(beginDateTime); record.setEndDate(endDateTime); record.setRoomId(customerCheckinRecord.getRoomId()); - record.setUserId(customerCheckinRecord.getUserId()); + record.setCustomerId(customerCheckinRecord.getCustomerId()); if (DateUtils.isToday(begin)) { this.doCreate(record); diff --git a/src/main/java/org/daming/hoteler/service/impl/EventServiceImpl.java b/src/main/java/org/daming/hoteler/service/impl/EventServiceImpl.java index e00b6127..bca4f692 100644 --- a/src/main/java/org/daming/hoteler/service/impl/EventServiceImpl.java +++ b/src/main/java/org/daming/hoteler/service/impl/EventServiceImpl.java @@ -65,7 +65,7 @@ var record = this.jsonMapper.readValue(content, CustomerCheckinRecord.class);; private void processCheckInTimeEvent(HotelerEvent type, CustomerCheckinRecord record) throws SchedulerException { var beginDate = record.getBeginDate(); - var triggerName = String.valueOf( record.getUserId() + record.getRoomId() + record.hashCode()); + var triggerName = String.valueOf( record.getCustomerId() + record.getRoomId() + record.hashCode()); var cron = CronBuilder.cron(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)) .withSecond(FieldExpressionFactory.on(0)) .withMinute(FieldExpressionFactory.on(0)) diff --git a/src/main/resources/db/migration/V202401182231_RENAME_CUSTOMER_CHECKIN_RECORD_USER_ID_TO_CUSTOMER_ID.sql b/src/main/resources/db/migration/V202401182231_RENAME_CUSTOMER_CHECKIN_RECORD_USER_ID_TO_CUSTOMER_ID.sql new file mode 100644 index 00000000..7d444643 --- /dev/null +++ b/src/main/resources/db/migration/V202401182231_RENAME_CUSTOMER_CHECKIN_RECORD_USER_ID_TO_CUSTOMER_ID.sql @@ -0,0 +1 @@ +ALTER TABLE customer_checkin_record RENAME user_id TO customer_id; \ No newline at end of file