借书/还书/续借/逾期管理
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
package com.mzh.library.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class BorrowRecord {
|
||||
private static final DateTimeFormatter DISPLAY_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
|
||||
private long id;
|
||||
private long readerId;
|
||||
private String readerIdentifier;
|
||||
private String readerName;
|
||||
private long bookId;
|
||||
private String bookIdentifier;
|
||||
private String bookTitle;
|
||||
private LocalDateTime borrowedAt;
|
||||
private LocalDateTime dueAt;
|
||||
private LocalDateTime returnedAt;
|
||||
private int renewalCount;
|
||||
private BorrowRecordStatus status;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getReaderId() {
|
||||
return readerId;
|
||||
}
|
||||
|
||||
public void setReaderId(long readerId) {
|
||||
this.readerId = readerId;
|
||||
}
|
||||
|
||||
public String getReaderIdentifier() {
|
||||
return readerIdentifier;
|
||||
}
|
||||
|
||||
public void setReaderIdentifier(String readerIdentifier) {
|
||||
this.readerIdentifier = readerIdentifier;
|
||||
}
|
||||
|
||||
public String getReaderName() {
|
||||
return readerName;
|
||||
}
|
||||
|
||||
public void setReaderName(String readerName) {
|
||||
this.readerName = readerName;
|
||||
}
|
||||
|
||||
public long getBookId() {
|
||||
return bookId;
|
||||
}
|
||||
|
||||
public void setBookId(long bookId) {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
|
||||
public String getBookIdentifier() {
|
||||
return bookIdentifier;
|
||||
}
|
||||
|
||||
public void setBookIdentifier(String bookIdentifier) {
|
||||
this.bookIdentifier = bookIdentifier;
|
||||
}
|
||||
|
||||
public String getBookTitle() {
|
||||
return bookTitle;
|
||||
}
|
||||
|
||||
public void setBookTitle(String bookTitle) {
|
||||
this.bookTitle = bookTitle;
|
||||
}
|
||||
|
||||
public LocalDateTime getBorrowedAt() {
|
||||
return borrowedAt;
|
||||
}
|
||||
|
||||
public void setBorrowedAt(LocalDateTime borrowedAt) {
|
||||
this.borrowedAt = borrowedAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getDueAt() {
|
||||
return dueAt;
|
||||
}
|
||||
|
||||
public void setDueAt(LocalDateTime dueAt) {
|
||||
this.dueAt = dueAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getReturnedAt() {
|
||||
return returnedAt;
|
||||
}
|
||||
|
||||
public void setReturnedAt(LocalDateTime returnedAt) {
|
||||
this.returnedAt = returnedAt;
|
||||
}
|
||||
|
||||
public int getRenewalCount() {
|
||||
return renewalCount;
|
||||
}
|
||||
|
||||
public void setRenewalCount(int renewalCount) {
|
||||
this.renewalCount = renewalCount;
|
||||
}
|
||||
|
||||
public BorrowRecordStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(BorrowRecordStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public boolean isOverdue() {
|
||||
return BorrowRecordStatus.ACTIVE == status
|
||||
&& returnedAt == null
|
||||
&& dueAt != null
|
||||
&& dueAt.isBefore(LocalDateTime.now());
|
||||
}
|
||||
|
||||
public String getDisplayStatusCode() {
|
||||
return isOverdue() ? BorrowRecordSearchCriteria.OVERDUE_STATUS : status.getCode();
|
||||
}
|
||||
|
||||
public String getDisplayStatusName() {
|
||||
return isOverdue() ? "Overdue" : status.getDisplayName();
|
||||
}
|
||||
|
||||
public String getBorrowedAtText() {
|
||||
return format(borrowedAt);
|
||||
}
|
||||
|
||||
public String getDueAtText() {
|
||||
return format(dueAt);
|
||||
}
|
||||
|
||||
public String getReturnedAtText() {
|
||||
return format(returnedAt);
|
||||
}
|
||||
|
||||
private String format(LocalDateTime value) {
|
||||
return value == null ? "" : DISPLAY_FORMAT.format(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.mzh.library.entity;
|
||||
|
||||
public class BorrowRecordSearchCriteria {
|
||||
public static final String OVERDUE_STATUS = "overdue";
|
||||
|
||||
private String readerIdentifier;
|
||||
private String bookIdentifier;
|
||||
private String statusCode;
|
||||
|
||||
public BorrowRecordSearchCriteria() {
|
||||
}
|
||||
|
||||
public BorrowRecordSearchCriteria(String readerIdentifier, String bookIdentifier, String statusCode) {
|
||||
this.readerIdentifier = trim(readerIdentifier);
|
||||
this.bookIdentifier = trim(bookIdentifier);
|
||||
this.statusCode = trim(statusCode);
|
||||
}
|
||||
|
||||
public String getReaderIdentifier() {
|
||||
return readerIdentifier;
|
||||
}
|
||||
|
||||
public void setReaderIdentifier(String readerIdentifier) {
|
||||
this.readerIdentifier = trim(readerIdentifier);
|
||||
}
|
||||
|
||||
public String getBookIdentifier() {
|
||||
return bookIdentifier;
|
||||
}
|
||||
|
||||
public void setBookIdentifier(String bookIdentifier) {
|
||||
this.bookIdentifier = trim(bookIdentifier);
|
||||
}
|
||||
|
||||
public String getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(String statusCode) {
|
||||
this.statusCode = trim(statusCode);
|
||||
}
|
||||
|
||||
public boolean isOverdueOnly() {
|
||||
return OVERDUE_STATUS.equals(statusCode);
|
||||
}
|
||||
|
||||
private String trim(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mzh.library.entity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum BorrowRecordStatus {
|
||||
ACTIVE("active", "Active"),
|
||||
RETURNED("returned", "Returned");
|
||||
|
||||
private final String code;
|
||||
private final String displayName;
|
||||
|
||||
BorrowRecordStatus(String code, String displayName) {
|
||||
this.code = code;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public static BorrowRecordStatus fromCode(String code) {
|
||||
if (code == null || code.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Borrow record status is required");
|
||||
}
|
||||
|
||||
String normalized = code.trim().toLowerCase(Locale.ROOT);
|
||||
for (BorrowRecordStatus status : values()) {
|
||||
if (status.code.equals(normalized)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unsupported borrow record status: " + code);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user