diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 9661ac7..90d78de 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/external-library/mywust b/external-library/mywust index 99e1ea7..a18aa81 160000 --- a/external-library/mywust +++ b/external-library/mywust @@ -1 +1 @@ -Subproject commit 99e1ea7c8fe539c2c6d942b0b32a7d4445298f4f +Subproject commit a18aa81d71123f54e959866e93c7ceb56b03ade4 diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java index 94c57f6..f3b11c5 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java @@ -1,16 +1,16 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; -import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.wusthelper.internal.library.services.BookCoverImageUrlService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; +import java.util.Arrays; import java.util.List; +import java.util.Map; @Path("/cover_image") @ApplicationScoped @@ -23,22 +23,26 @@ public class BookCoverImageApi { @GET @Path("/") - public List get(@QueryParam("isbn") @NotNull String isbn) + public Object get(@QueryParam("isbn") @NotNull String isbn) throws RpcException { - return this.parse(this.agent(isbn)); + if (isbn.contains(",")) { + return this.batch(isbn); + } else { + return this.agent(isbn); + } } @GET @Path("/agent") - public String agent(@QueryParam("isbn") @NotNull String isbn) + public List agent(@QueryParam("isbn") @NotNull String isbn) throws RpcException { return service.getBookCoverImageUrl(isbn); } - @POST - @Path("/parse") - public List parse(String html) throws RpcException { -// return parseService.parseScore(html); - return null; + @GET + @Path("/batch") + public Map> batch(@QueryParam("isbn") @NotNull String isbn) + throws RpcException { + return service.getBookCoverImageUrl(Arrays.stream(isbn.split(",")).toList()); } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java index 70de036..7631cca 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java @@ -1,17 +1,14 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; -import cn.wustlinghang.mywust.data.global.Score; +import cn.wustlinghang.mywust.data.library.parsed.BookDetail; import cn.wustlinghang.wusthelper.internal.library.services.BookDetailService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; -import java.util.List; - @Path("/book_detail") @ApplicationScoped public class BookDetailApi { @@ -23,22 +20,15 @@ public class BookDetailApi { @GET @Path("/") - public List get(@QueryParam("id") @NotNull String id) + public BookDetail get(@QueryParam("id") @NotNull String id) throws RpcException { - return this.parse(this.agent(id)); + return this.agent(id); } @GET @Path("/agent") - public String agent(@QueryParam("id") @NotNull String id) + public BookDetail agent(@QueryParam("id") @NotNull String id) throws RpcException { return service.getBookDetail(id); } - - @POST - @Path("/parse") - public List parse(String html) throws RpcException { -// return parseService.parseScore(html); - return null; - } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookHoldingApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookHoldingApi.java new file mode 100644 index 0000000..e4a1687 --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookHoldingApi.java @@ -0,0 +1,36 @@ +package cn.wustlinghang.wusthelper.internal.library.api.http; + +import cn.wustlinghang.mywust.data.library.parsed.BookHolding; +import cn.wustlinghang.wusthelper.internal.library.services.BookHoldingService; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +import java.util.List; + +@Path("/holdings") +@ApplicationScoped +public class BookHoldingApi { + private final BookHoldingService service; + + public BookHoldingApi(BookHoldingService service) { + this.service = service; + } + + @GET + @Path("/") + public List get(@QueryParam("id") @NotNull String id) + throws RpcException { + return this.agent(id); + } + + @GET + @Path("/agent") + public List agent(@QueryParam("id") @NotNull String id) + throws RpcException { + return service.getHoldings(id); + } +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java index 552e8dc..8810de8 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java @@ -1,12 +1,13 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; -import cn.wustlinghang.mywust.data.global.Score; +import cn.wustlinghang.mywust.data.library.PagingResult; +import cn.wustlinghang.mywust.data.library.origin.CurrentLoanBook; import cn.wustlinghang.wusthelper.internal.library.services.CurrentLoanService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.DefaultValue; import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; @@ -23,22 +24,19 @@ public class CurrentLoanApi { @GET @Path("/") - public List get(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return this.parse(this.agent(cookie)); + public PagingResult> get(@QueryParam("cookie") @NotNull String cookie, + @DefaultValue("1") @QueryParam("page") int page, + @DefaultValue("100") @QueryParam("page_size") int pageSize + ) throws RpcException { + return this.agent(cookie, page, pageSize); } @GET @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return service.getCurrentLoan(cookie); - } - - @POST - @Path("/parse") - public List parse(String html) throws RpcException { -// return parseService.parseScore(html); - return null; + public PagingResult> agent(@QueryParam("cookie") @NotNull String cookie, + @DefaultValue("1") @QueryParam("page") int page, + @DefaultValue("100") @QueryParam("page_size") int pageSize + ) throws RpcException { + return service.getCurrentLoan(cookie, page, pageSize); } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java index 3ec5953..c00e6d8 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java @@ -1,12 +1,14 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; -import cn.wustlinghang.mywust.data.global.Score; +import cn.wustlinghang.mywust.data.library.PagingResult; +import cn.wustlinghang.mywust.data.library.origin.BaseLoanBook; +import cn.wustlinghang.mywust.data.library.origin.HistoryLoanBook; import cn.wustlinghang.wusthelper.internal.library.services.LoanHistoryService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.DefaultValue; import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; @@ -23,22 +25,19 @@ public class LoanHistoryApi { @GET @Path("/") - public List get(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return this.parse(this.agent(cookie)); + public PagingResult> get(@QueryParam("cookie") @NotNull String cookie, + @DefaultValue("1") @QueryParam("page") int page, + @DefaultValue("100") @QueryParam("page_size") int pageSize + ) throws RpcException { + return this.agent(cookie, page, pageSize); } @GET @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return service.getLoanHistory(cookie); - } - - @POST - @Path("/parse") - public List parse(String html) throws RpcException { -// return parseService.parseScore(html); - return null; + public PagingResult> agent(@QueryParam("cookie") @NotNull String cookie, + @DefaultValue("1") @QueryParam("page") int page, + @DefaultValue("100") @QueryParam("page_size") int pageSize + ) throws RpcException { + return service.getLoanHistory(cookie, page, pageSize); } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java index 137a222..0701949 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java @@ -1,12 +1,13 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; -import cn.wustlinghang.mywust.data.global.Score; +import cn.wustlinghang.mywust.data.library.PagingResult; +import cn.wustlinghang.mywust.data.library.origin.BaseLoanBook; import cn.wustlinghang.wusthelper.internal.library.services.OverdueSoonService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.DefaultValue; import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; @@ -23,22 +24,19 @@ public class OverdueSoonApi { @GET @Path("/") - public List get(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return this.parse(this.agent(cookie)); + public PagingResult> get(@QueryParam("cookie") @NotNull String cookie, + @DefaultValue("1") @QueryParam("page") int page, + @DefaultValue("100") @QueryParam("page_size") int pageSize + ) throws RpcException { + return this.agent(cookie, page, pageSize); } @GET @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return service.getOverdueSoon(cookie); - } - - @POST - @Path("/parse") - public List parse(String html) throws RpcException { -// return parseService.parseScore(html); - return null; + public PagingResult> agent(@QueryParam("cookie") @NotNull String cookie, + @DefaultValue("1") @QueryParam("page") int page, + @DefaultValue("100") @QueryParam("page_size") int pageSize + ) throws RpcException { + return service.getOverdueSoon(cookie, page, pageSize); } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java index 58f77a1..1c6fa6f 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java @@ -1,12 +1,13 @@ package cn.wustlinghang.wusthelper.internal.library.api.http; -import cn.wustlinghang.mywust.data.global.Score; +import cn.wustlinghang.mywust.data.library.PagingResult; +import cn.wustlinghang.mywust.data.library.origin.BookSearchResult; import cn.wustlinghang.wusthelper.internal.library.services.SearchService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.DefaultValue; import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; @@ -23,26 +24,21 @@ public class SearchApi { @GET @Path("/") - public List get(@QueryParam("keyword") @NotNull String keyword, - @QueryParam("page") @NotNull int page, - @QueryParam("page_size") @NotNull int pageSize) - throws RpcException { - return this.parse(this.agent(keyword, page, pageSize)); + public PagingResult> get( + @QueryParam("keyword") @NotNull String keyword, + @DefaultValue("1") @QueryParam("page") int page, + @DefaultValue("20") @QueryParam("page_size") int pageSize + ) throws RpcException { + return this.agent(keyword, page, pageSize); } @GET @Path("/agent") - public String agent(@QueryParam("keyword") @NotNull String keyword, - @QueryParam("page") @NotNull int page, - @QueryParam("page_size") @NotNull int pageSize) - throws RpcException { + public PagingResult> agent( + @QueryParam("keyword") @NotNull String keyword, + @DefaultValue("1") @QueryParam("page") int page, + @DefaultValue("20") @QueryParam("page_size") int pageSize + ) throws RpcException { return service.search(keyword, page, pageSize); } - - @POST - @Path("/parse") - public List parse(String html) throws RpcException { -// return parseService.parseScore(html); - return null; - } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/handler/BaseExceptionHandler.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/handler/BaseExceptionHandler.java index e203af6..6e4971c 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/handler/BaseExceptionHandler.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/handler/BaseExceptionHandler.java @@ -17,7 +17,7 @@ public abstract class BaseExceptionHandler { } public Response toResponse(int code, String msg, String handlerName) { - return toResponse(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code, msg, handlerName); + return toResponse(Response.Status.OK.getStatusCode(), code, msg, handlerName); } public Response toResponse(int status, int code, String msg, String handlerName) { diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java index 07a8caa..ebc0b5b 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java @@ -41,6 +41,11 @@ public class MywustRequestAgentBeans { return new BookDetailApiService(requester); } + @Singleton + public BookHoldingApiService bookHoldingApiService(Requester requester) { + return new BookHoldingApiService(requester); + } + @Singleton public CurrentLoanApiService currentLoanApiService(Requester requester) { return new CurrentLoanApiService(requester); diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java index 15481a4..9dce075 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java @@ -1,9 +1,17 @@ package cn.wustlinghang.wusthelper.internal.library.services; +import cn.wustlinghang.mywust.data.library.parsed.BookHolding; import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; import lombok.extern.slf4j.Slf4j; +import java.io.IOException; +import java.util.List; + @Slf4j public abstract class BaseService { protected LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) { diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java index 1c99e83..6d303d6 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java @@ -7,18 +7,34 @@ import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import java.io.IOException; +import java.util.List; +import java.util.Map; @ApplicationScoped public class BookCoverImageUrlService extends BaseService { - private final BookCoverImageUrlApiService service; + private final BookCoverImageUrlApiService api; - public BookCoverImageUrlService(BookCoverImageUrlApiService service) { - this.service = service; + public BookCoverImageUrlService(BookCoverImageUrlApiService api) { + this.api = api; } - public String getBookCoverImageUrl(String isbn) throws RpcException { + public List getBookCoverImageUrl(String isbn) throws RpcException { try { - return service.getBookCoverImageUrl(isbn); + return api.getBookCoverImageUrl(isbn); + } catch (ApiException e) { + throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); + } catch (IOException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + LibraryRpcException.SubModuleCode.PUBLIC_API, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + } + } + + public Map> getBookCoverImageUrl(List isbnList) throws RpcException { + try { + return api.getBookCoverImageUrl(isbnList); } catch (ApiException e) { throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); } catch (IOException e) { diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java index 6e3e459..370b9f3 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java @@ -1,6 +1,7 @@ package cn.wustlinghang.wusthelper.internal.library.services; import cn.wustlinghang.mywust.core.request.service.library.BookDetailApiService; +import cn.wustlinghang.mywust.data.library.parsed.BookDetail; import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; @@ -10,15 +11,15 @@ import java.io.IOException; @ApplicationScoped public class BookDetailService extends BaseService { - private final BookDetailApiService service; + private final BookDetailApiService api; - public BookDetailService(BookDetailApiService service) { - this.service = service; + public BookDetailService(BookDetailApiService api) { + this.api = api; } - public String getBookDetail(String bookId) throws RpcException { + public BookDetail getBookDetail(String bookId) throws RpcException { try { - return service.getBookDetail(bookId); + return api.getBookDetail(bookId); } catch (ApiException e) { throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); } catch (IOException e) { diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookHoldingService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookHoldingService.java new file mode 100644 index 0000000..20bfa34 --- /dev/null +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookHoldingService.java @@ -0,0 +1,42 @@ +package cn.wustlinghang.wusthelper.internal.library.services; + +import cn.wustlinghang.mywust.core.request.service.library.BookHoldingApiService; +import cn.wustlinghang.mywust.data.library.parsed.BookHolding; +import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; +import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; +import cn.wustlinghang.wusthelper.rpc.exception.RpcException; +import jakarta.enterprise.context.ApplicationScoped; + +import java.io.IOException; +import java.util.List; + +@ApplicationScoped +public class BookHoldingService extends BaseService { + private final BookHoldingApiService api; + + public BookHoldingService(BookHoldingApiService api) { + this.api = api; + } + + public List getHoldings(String id) + throws RpcException { + try { + return api.getHoldingList(id); + } catch (ApiException e) { + throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); + } catch (IOException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.NETWORK_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.NETWORK_ERROR + ); + } catch (ParseException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.PARSE_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.PARSE_ERROR + ); + } + } +} diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java index 70fdec7..950c84a 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java @@ -1,24 +1,29 @@ package cn.wustlinghang.wusthelper.internal.library.services; import cn.wustlinghang.mywust.core.request.service.library.CurrentLoanApiService; +import cn.wustlinghang.mywust.data.library.PagingResult; +import cn.wustlinghang.mywust.data.library.origin.CurrentLoanBook; import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import java.io.IOException; +import java.util.List; @ApplicationScoped public class CurrentLoanService extends BaseService { - private final CurrentLoanApiService service; + private final CurrentLoanApiService api; - public CurrentLoanService(CurrentLoanApiService service) { - this.service = service; + public CurrentLoanService(CurrentLoanApiService api) { + this.api = api; } - public String getCurrentLoan(String cookie) throws RpcException { + public PagingResult> getCurrentLoan(String cookie, int page, int pageSize) + throws RpcException { try { - return service.getCurrentLoan(cookie); + return api.getCurrentLoan(cookie, page, pageSize); } catch (ApiException e) { throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); } catch (IOException e) { @@ -27,6 +32,12 @@ public class CurrentLoanService extends BaseService { LibraryRpcException.SubModuleCode.PERSONAL_API, LibraryRpcException.ErrorCode.NETWORK_ERROR ); + } catch (ParseException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.PARSE_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.PARSE_ERROR + ); } } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java index 1a87cac..1475ae1 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java @@ -1,24 +1,32 @@ package cn.wustlinghang.wusthelper.internal.library.services; import cn.wustlinghang.mywust.core.request.service.library.LoanHistoryApiService; +import cn.wustlinghang.mywust.data.library.PagingResult; +import cn.wustlinghang.mywust.data.library.origin.BaseLoanBook; +import cn.wustlinghang.mywust.data.library.origin.HistoryLoanBook; import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; +import lombok.extern.slf4j.Slf4j; import java.io.IOException; +import java.util.List; +@Slf4j @ApplicationScoped public class LoanHistoryService extends BaseService { - private final LoanHistoryApiService service; + private final LoanHistoryApiService api; - public LoanHistoryService(LoanHistoryApiService service) { - this.service = service; + public LoanHistoryService(LoanHistoryApiService api) { + this.api = api; } - public String getLoanHistory(String cookie) throws RpcException { + public PagingResult> getLoanHistory(String cookie, int page, int pageSize) + throws RpcException { try { - return service.getLoanHistory(cookie); + return api.getLoanHistory(cookie, page, pageSize); } catch (ApiException e) { throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); } catch (IOException e) { @@ -27,6 +35,13 @@ public class LoanHistoryService extends BaseService { LibraryRpcException.SubModuleCode.PERSONAL_API, LibraryRpcException.ErrorCode.NETWORK_ERROR ); + } catch (ParseException e) { + log.error("解析错误:", e); + throw new LibraryRpcException( + LibraryRpcException.TypeCode.PARSE_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.PARSE_ERROR + ); } } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoginService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoginService.java index 9463c12..cc90a1f 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoginService.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoginService.java @@ -55,9 +55,8 @@ public class LoginService { case UNI_LOGIN_USER_BANNED -> LibraryRpcException.ErrorCode.AUTH_USER_BANNED; case UNI_LOGIN_USER_DISABLED -> LibraryRpcException.ErrorCode.AUTH_USER_DISABLED; case UNI_LOGIN_NEED_CHANGE_PASSWORD -> LibraryRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD; - case UNI_LOGIN_USER_NOT_ONLY -> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; - case UNI_LOGIN_NO_REGISTER -> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; - case UNI_LOGIN_NEED_TFA -> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; + case UNI_LOGIN_USER_NOT_ONLY, UNI_LOGIN_NEED_TFA, UNI_LOGIN_NO_REGISTER + -> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; default -> { log.error("图书馆:登录代理请求异常,异常未处理"); log.error("异常:", e); diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java index 11491f7..c39dfb1 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java @@ -1,24 +1,29 @@ package cn.wustlinghang.wusthelper.internal.library.services; import cn.wustlinghang.mywust.core.request.service.library.OverdueSoonApiService; +import cn.wustlinghang.mywust.data.library.PagingResult; +import cn.wustlinghang.mywust.data.library.origin.BaseLoanBook; import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import java.io.IOException; +import java.util.List; @ApplicationScoped public class OverdueSoonService extends BaseService { - private final OverdueSoonApiService service; + private final OverdueSoonApiService api; - public OverdueSoonService(OverdueSoonApiService service) { - this.service = service; + public OverdueSoonService(OverdueSoonApiService api) { + this.api = api; } - public String getOverdueSoon(String cookie) throws RpcException { + public PagingResult> getOverdueSoon(String cookie, int page, int pageSize) + throws RpcException { try { - return service.getOverdueSoon(cookie); + return api.getOverdueSoon(cookie, page, pageSize); } catch (ApiException e) { throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); } catch (IOException e) { @@ -27,6 +32,12 @@ public class OverdueSoonService extends BaseService { LibraryRpcException.SubModuleCode.PERSONAL_API, LibraryRpcException.ErrorCode.NETWORK_ERROR ); + } catch (ParseException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.PARSE_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.PARSE_ERROR + ); } } } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java index 8f6f9ff..465c551 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java @@ -1,24 +1,29 @@ package cn.wustlinghang.wusthelper.internal.library.services; import cn.wustlinghang.mywust.core.request.service.library.SearchApiService; +import cn.wustlinghang.mywust.data.library.PagingResult; +import cn.wustlinghang.mywust.data.library.origin.BookSearchResult; import cn.wustlinghang.mywust.exception.ApiException; +import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped; import java.io.IOException; +import java.util.List; @ApplicationScoped public class SearchService extends BaseService { - private final SearchApiService service; + private final SearchApiService api; - public SearchService(SearchApiService service) { - this.service = service; + public SearchService(SearchApiService api) { + this.api = api; } - public String search(String keyword, int page, int pageSize) throws RpcException { + public PagingResult> search(String keyword, int page, int pageSize) + throws RpcException { try { - return service.search(keyword, page, pageSize); + return api.search(keyword, page, pageSize); } catch (ApiException e) { throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); } catch (IOException e) { @@ -27,6 +32,12 @@ public class SearchService extends BaseService { LibraryRpcException.SubModuleCode.PUBLIC_API, LibraryRpcException.ErrorCode.NETWORK_ERROR ); + } catch (ParseException e) { + throw new LibraryRpcException( + LibraryRpcException.TypeCode.PARSE_EXCEPTION, + LibraryRpcException.SubModuleCode.PERSONAL_API, + LibraryRpcException.ErrorCode.PARSE_ERROR + ); } } } \ No newline at end of file diff --git a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java index a0177ba..bdac6f1 100644 --- a/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java +++ b/sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java @@ -62,9 +62,8 @@ public class LoginService { case UNI_LOGIN_USER_DISABLED -> UndergradRpcException.ErrorCode.AUTH_USER_DISABLED; case UNI_LOGIN_NEED_CHANGE_PASSWORD -> UndergradRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD; case UNDERGRAD_BANNED_IN_EXCLUSIVE_TIME -> UndergradRpcException.ErrorCode.AUTH_BANNED_IN_EXCLUSIVE_TIME; - case UNI_LOGIN_USER_NOT_ONLY -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; - case UNI_LOGIN_NO_REGISTER -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; - case UNI_LOGIN_NEED_TFA -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; + case UNI_LOGIN_USER_NOT_ONLY, UNI_LOGIN_NO_REGISTER, UNI_LOGIN_NEED_TFA + -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; default -> { log.error("本科生:登录代理请求异常,异常未处理"); log.error("异常:", e);