main
lensfrex 1 year ago
parent bc8ee2e5b1
commit 43f0c9a5c4
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 1
      .idea/vcs.xml
  2. 2
      external-library/mywust
  3. 24
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java
  4. 18
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java
  5. 36
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookHoldingApi.java
  6. 28
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java
  7. 29
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java
  8. 28
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java
  9. 32
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java
  10. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/handler/BaseExceptionHandler.java
  11. 5
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java
  12. 8
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java
  13. 26
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java
  14. 11
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java
  15. 42
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookHoldingService.java
  16. 21
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java
  17. 25
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java
  18. 5
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoginService.java
  19. 21
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java
  20. 21
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java
  21. 5
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java

@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/external-library/mywust" vcs="Git" />
</component> </component>
</project> </project>

@ -1 +1 @@
Subproject commit 99e1ea7c8fe539c2c6d942b0b32a7d4445298f4f Subproject commit a18aa81d71123f54e959866e93c7ceb56b03ade4

@ -1,16 +1,16 @@
package cn.wustlinghang.wusthelper.internal.library.api.http; 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.internal.library.services.BookCoverImageUrlService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.QueryParam;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
@Path("/cover_image") @Path("/cover_image")
@ApplicationScoped @ApplicationScoped
@ -23,22 +23,26 @@ public class BookCoverImageApi {
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("isbn") @NotNull String isbn) public Object get(@QueryParam("isbn") @NotNull String isbn)
throws RpcException { throws RpcException {
return this.parse(this.agent(isbn)); if (isbn.contains(",")) {
return this.batch(isbn);
} else {
return this.agent(isbn);
}
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("isbn") @NotNull String isbn) public List<String> agent(@QueryParam("isbn") @NotNull String isbn)
throws RpcException { throws RpcException {
return service.getBookCoverImageUrl(isbn); return service.getBookCoverImageUrl(isbn);
} }
@POST @GET
@Path("/parse") @Path("/batch")
public List<Score> parse(String html) throws RpcException { public Map<String, List<String>> batch(@QueryParam("isbn") @NotNull String isbn)
// return parseService.parseScore(html); throws RpcException {
return null; return service.getBookCoverImageUrl(Arrays.stream(isbn.split(",")).toList());
} }
} }

@ -1,17 +1,14 @@
package cn.wustlinghang.wusthelper.internal.library.api.http; 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.internal.library.services.BookDetailService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.QueryParam;
import java.util.List;
@Path("/book_detail") @Path("/book_detail")
@ApplicationScoped @ApplicationScoped
public class BookDetailApi { public class BookDetailApi {
@ -23,22 +20,15 @@ public class BookDetailApi {
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("id") @NotNull String id) public BookDetail get(@QueryParam("id") @NotNull String id)
throws RpcException { throws RpcException {
return this.parse(this.agent(id)); return this.agent(id);
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("id") @NotNull String id) public BookDetail agent(@QueryParam("id") @NotNull String id)
throws RpcException { throws RpcException {
return service.getBookDetail(id); return service.getBookDetail(id);
} }
@POST
@Path("/parse")
public List<Score> parse(String html) throws RpcException {
// return parseService.parseScore(html);
return null;
}
} }

@ -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<BookHolding> get(@QueryParam("id") @NotNull String id)
throws RpcException {
return this.agent(id);
}
@GET
@Path("/agent")
public List<BookHolding> agent(@QueryParam("id") @NotNull String id)
throws RpcException {
return service.getHoldings(id);
}
}

@ -1,12 +1,13 @@
package cn.wustlinghang.wusthelper.internal.library.api.http; 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.internal.library.services.CurrentLoanService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.QueryParam;
@ -23,22 +24,19 @@ public class CurrentLoanApi {
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("cookie") @NotNull String cookie) public PagingResult<List<CurrentLoanBook>> get(@QueryParam("cookie") @NotNull String cookie,
throws RpcException { @DefaultValue("1") @QueryParam("page") int page,
return this.parse(this.agent(cookie)); @DefaultValue("100") @QueryParam("page_size") int pageSize
) throws RpcException {
return this.agent(cookie, page, pageSize);
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public PagingResult<List<CurrentLoanBook>> agent(@QueryParam("cookie") @NotNull String cookie,
throws RpcException { @DefaultValue("1") @QueryParam("page") int page,
return service.getCurrentLoan(cookie); @DefaultValue("100") @QueryParam("page_size") int pageSize
} ) throws RpcException {
return service.getCurrentLoan(cookie, page, pageSize);
@POST
@Path("/parse")
public List<Score> parse(String html) throws RpcException {
// return parseService.parseScore(html);
return null;
} }
} }

@ -1,12 +1,14 @@
package cn.wustlinghang.wusthelper.internal.library.api.http; 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.internal.library.services.LoanHistoryService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.QueryParam;
@ -23,22 +25,19 @@ public class LoanHistoryApi {
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("cookie") @NotNull String cookie) public PagingResult<List<HistoryLoanBook>> get(@QueryParam("cookie") @NotNull String cookie,
throws RpcException { @DefaultValue("1") @QueryParam("page") int page,
return this.parse(this.agent(cookie)); @DefaultValue("100") @QueryParam("page_size") int pageSize
) throws RpcException {
return this.agent(cookie, page, pageSize);
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public PagingResult<List<HistoryLoanBook>> agent(@QueryParam("cookie") @NotNull String cookie,
throws RpcException { @DefaultValue("1") @QueryParam("page") int page,
return service.getLoanHistory(cookie); @DefaultValue("100") @QueryParam("page_size") int pageSize
} ) throws RpcException {
return service.getLoanHistory(cookie, page, pageSize);
@POST
@Path("/parse")
public List<Score> parse(String html) throws RpcException {
// return parseService.parseScore(html);
return null;
} }
} }

@ -1,12 +1,13 @@
package cn.wustlinghang.wusthelper.internal.library.api.http; 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.internal.library.services.OverdueSoonService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.QueryParam;
@ -23,22 +24,19 @@ public class OverdueSoonApi {
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("cookie") @NotNull String cookie) public PagingResult<List<BaseLoanBook>> get(@QueryParam("cookie") @NotNull String cookie,
throws RpcException { @DefaultValue("1") @QueryParam("page") int page,
return this.parse(this.agent(cookie)); @DefaultValue("100") @QueryParam("page_size") int pageSize
) throws RpcException {
return this.agent(cookie, page, pageSize);
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public PagingResult<List<BaseLoanBook>> agent(@QueryParam("cookie") @NotNull String cookie,
throws RpcException { @DefaultValue("1") @QueryParam("page") int page,
return service.getOverdueSoon(cookie); @DefaultValue("100") @QueryParam("page_size") int pageSize
} ) throws RpcException {
return service.getOverdueSoon(cookie, page, pageSize);
@POST
@Path("/parse")
public List<Score> parse(String html) throws RpcException {
// return parseService.parseScore(html);
return null;
} }
} }

@ -1,12 +1,13 @@
package cn.wustlinghang.wusthelper.internal.library.api.http; 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.internal.library.services.SearchService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.QueryParam;
@ -23,26 +24,21 @@ public class SearchApi {
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("keyword") @NotNull String keyword, public PagingResult<List<BookSearchResult>> get(
@QueryParam("page") @NotNull int page, @QueryParam("keyword") @NotNull String keyword,
@QueryParam("page_size") @NotNull int pageSize) @DefaultValue("1") @QueryParam("page") int page,
throws RpcException { @DefaultValue("20") @QueryParam("page_size") int pageSize
return this.parse(this.agent(keyword, page, pageSize)); ) throws RpcException {
return this.agent(keyword, page, pageSize);
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("keyword") @NotNull String keyword, public PagingResult<List<BookSearchResult>> agent(
@QueryParam("page") @NotNull int page, @QueryParam("keyword") @NotNull String keyword,
@QueryParam("page_size") @NotNull int pageSize) @DefaultValue("1") @QueryParam("page") int page,
throws RpcException { @DefaultValue("20") @QueryParam("page_size") int pageSize
) throws RpcException {
return service.search(keyword, page, pageSize); return service.search(keyword, page, pageSize);
} }
@POST
@Path("/parse")
public List<Score> parse(String html) throws RpcException {
// return parseService.parseScore(html);
return null;
}
} }

@ -17,7 +17,7 @@ public abstract class BaseExceptionHandler {
} }
public Response toResponse(int code, String msg, String handlerName) { 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) { public Response toResponse(int status, int code, String msg, String handlerName) {

@ -41,6 +41,11 @@ public class MywustRequestAgentBeans {
return new BookDetailApiService(requester); return new BookDetailApiService(requester);
} }
@Singleton
public BookHoldingApiService bookHoldingApiService(Requester requester) {
return new BookHoldingApiService(requester);
}
@Singleton @Singleton
public CurrentLoanApiService currentLoanApiService(Requester requester) { public CurrentLoanApiService currentLoanApiService(Requester requester) {
return new CurrentLoanApiService(requester); return new CurrentLoanApiService(requester);

@ -1,9 +1,17 @@
package cn.wustlinghang.wusthelper.internal.library.services; package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.data.library.parsed.BookHolding;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; 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 lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.List;
@Slf4j @Slf4j
public abstract class BaseService { public abstract class BaseService {
protected LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) { protected LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) {

@ -7,18 +7,34 @@ import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map;
@ApplicationScoped @ApplicationScoped
public class BookCoverImageUrlService extends BaseService { public class BookCoverImageUrlService extends BaseService {
private final BookCoverImageUrlApiService service; private final BookCoverImageUrlApiService api;
public BookCoverImageUrlService(BookCoverImageUrlApiService service) { public BookCoverImageUrlService(BookCoverImageUrlApiService api) {
this.service = service; this.api = api;
} }
public String getBookCoverImageUrl(String isbn) throws RpcException { public List<String> getBookCoverImageUrl(String isbn) throws RpcException {
try { 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<String, List<String>> getBookCoverImageUrl(List<String> isbnList) throws RpcException {
try {
return api.getBookCoverImageUrl(isbnList);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API);
} catch (IOException e) { } catch (IOException e) {

@ -1,6 +1,7 @@
package cn.wustlinghang.wusthelper.internal.library.services; package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.BookDetailApiService; 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.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
@ -10,15 +11,15 @@ import java.io.IOException;
@ApplicationScoped @ApplicationScoped
public class BookDetailService extends BaseService { public class BookDetailService extends BaseService {
private final BookDetailApiService service; private final BookDetailApiService api;
public BookDetailService(BookDetailApiService service) { public BookDetailService(BookDetailApiService api) {
this.service = service; this.api = api;
} }
public String getBookDetail(String bookId) throws RpcException { public BookDetail getBookDetail(String bookId) throws RpcException {
try { try {
return service.getBookDetail(bookId); return api.getBookDetail(bookId);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API);
} catch (IOException e) { } catch (IOException e) {

@ -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<BookHolding> 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
);
}
}
}

@ -1,24 +1,29 @@
package cn.wustlinghang.wusthelper.internal.library.services; package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.CurrentLoanApiService; 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.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException; import java.io.IOException;
import java.util.List;
@ApplicationScoped @ApplicationScoped
public class CurrentLoanService extends BaseService { public class CurrentLoanService extends BaseService {
private final CurrentLoanApiService service; private final CurrentLoanApiService api;
public CurrentLoanService(CurrentLoanApiService service) { public CurrentLoanService(CurrentLoanApiService api) {
this.service = service; this.api = api;
} }
public String getCurrentLoan(String cookie) throws RpcException { public PagingResult<List<CurrentLoanBook>> getCurrentLoan(String cookie, int page, int pageSize)
throws RpcException {
try { try {
return service.getCurrentLoan(cookie); return api.getCurrentLoan(cookie, page, pageSize);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API);
} catch (IOException e) { } catch (IOException e) {
@ -27,6 +32,12 @@ public class CurrentLoanService extends BaseService {
LibraryRpcException.SubModuleCode.PERSONAL_API, LibraryRpcException.SubModuleCode.PERSONAL_API,
LibraryRpcException.ErrorCode.NETWORK_ERROR LibraryRpcException.ErrorCode.NETWORK_ERROR
); );
} catch (ParseException e) {
throw new LibraryRpcException(
LibraryRpcException.TypeCode.PARSE_EXCEPTION,
LibraryRpcException.SubModuleCode.PERSONAL_API,
LibraryRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -1,24 +1,32 @@
package cn.wustlinghang.wusthelper.internal.library.services; package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.LoanHistoryApiService; 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.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException; import java.io.IOException;
import java.util.List;
@Slf4j
@ApplicationScoped @ApplicationScoped
public class LoanHistoryService extends BaseService { public class LoanHistoryService extends BaseService {
private final LoanHistoryApiService service; private final LoanHistoryApiService api;
public LoanHistoryService(LoanHistoryApiService service) { public LoanHistoryService(LoanHistoryApiService api) {
this.service = service; this.api = api;
} }
public String getLoanHistory(String cookie) throws RpcException { public PagingResult<List<HistoryLoanBook>> getLoanHistory(String cookie, int page, int pageSize)
throws RpcException {
try { try {
return service.getLoanHistory(cookie); return api.getLoanHistory(cookie, page, pageSize);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API);
} catch (IOException e) { } catch (IOException e) {
@ -27,6 +35,13 @@ public class LoanHistoryService extends BaseService {
LibraryRpcException.SubModuleCode.PERSONAL_API, LibraryRpcException.SubModuleCode.PERSONAL_API,
LibraryRpcException.ErrorCode.NETWORK_ERROR 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
);
} }
} }
} }

@ -55,9 +55,8 @@ public class LoginService {
case UNI_LOGIN_USER_BANNED -> LibraryRpcException.ErrorCode.AUTH_USER_BANNED; case UNI_LOGIN_USER_BANNED -> LibraryRpcException.ErrorCode.AUTH_USER_BANNED;
case UNI_LOGIN_USER_DISABLED -> LibraryRpcException.ErrorCode.AUTH_USER_DISABLED; 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_NEED_CHANGE_PASSWORD -> LibraryRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD;
case UNI_LOGIN_USER_NOT_ONLY -> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; case UNI_LOGIN_USER_NOT_ONLY, UNI_LOGIN_NEED_TFA, UNI_LOGIN_NO_REGISTER
case UNI_LOGIN_NO_REGISTER -> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; -> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
case UNI_LOGIN_NEED_TFA -> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
default -> { default -> {
log.error("图书馆:登录代理请求异常,异常未处理"); log.error("图书馆:登录代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);

@ -1,24 +1,29 @@
package cn.wustlinghang.wusthelper.internal.library.services; package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.OverdueSoonApiService; 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.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException; import java.io.IOException;
import java.util.List;
@ApplicationScoped @ApplicationScoped
public class OverdueSoonService extends BaseService { public class OverdueSoonService extends BaseService {
private final OverdueSoonApiService service; private final OverdueSoonApiService api;
public OverdueSoonService(OverdueSoonApiService service) { public OverdueSoonService(OverdueSoonApiService api) {
this.service = service; this.api = api;
} }
public String getOverdueSoon(String cookie) throws RpcException { public PagingResult<List<BaseLoanBook>> getOverdueSoon(String cookie, int page, int pageSize)
throws RpcException {
try { try {
return service.getOverdueSoon(cookie); return api.getOverdueSoon(cookie, page, pageSize);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API); throw wrapApiException(e, LibraryRpcException.SubModuleCode.PERSONAL_API);
} catch (IOException e) { } catch (IOException e) {
@ -27,6 +32,12 @@ public class OverdueSoonService extends BaseService {
LibraryRpcException.SubModuleCode.PERSONAL_API, LibraryRpcException.SubModuleCode.PERSONAL_API,
LibraryRpcException.ErrorCode.NETWORK_ERROR LibraryRpcException.ErrorCode.NETWORK_ERROR
); );
} catch (ParseException e) {
throw new LibraryRpcException(
LibraryRpcException.TypeCode.PARSE_EXCEPTION,
LibraryRpcException.SubModuleCode.PERSONAL_API,
LibraryRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -1,24 +1,29 @@
package cn.wustlinghang.wusthelper.internal.library.services; package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.SearchApiService; 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.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException; import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException; import java.io.IOException;
import java.util.List;
@ApplicationScoped @ApplicationScoped
public class SearchService extends BaseService { public class SearchService extends BaseService {
private final SearchApiService service; private final SearchApiService api;
public SearchService(SearchApiService service) { public SearchService(SearchApiService api) {
this.service = service; this.api = api;
} }
public String search(String keyword, int page, int pageSize) throws RpcException { public PagingResult<List<BookSearchResult>> search(String keyword, int page, int pageSize)
throws RpcException {
try { try {
return service.search(keyword, page, pageSize); return api.search(keyword, page, pageSize);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API); throw wrapApiException(e, LibraryRpcException.SubModuleCode.PUBLIC_API);
} catch (IOException e) { } catch (IOException e) {
@ -27,6 +32,12 @@ public class SearchService extends BaseService {
LibraryRpcException.SubModuleCode.PUBLIC_API, LibraryRpcException.SubModuleCode.PUBLIC_API,
LibraryRpcException.ErrorCode.NETWORK_ERROR LibraryRpcException.ErrorCode.NETWORK_ERROR
); );
} catch (ParseException e) {
throw new LibraryRpcException(
LibraryRpcException.TypeCode.PARSE_EXCEPTION,
LibraryRpcException.SubModuleCode.PERSONAL_API,
LibraryRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -62,9 +62,8 @@ public class LoginService {
case UNI_LOGIN_USER_DISABLED -> UndergradRpcException.ErrorCode.AUTH_USER_DISABLED; case UNI_LOGIN_USER_DISABLED -> UndergradRpcException.ErrorCode.AUTH_USER_DISABLED;
case UNI_LOGIN_NEED_CHANGE_PASSWORD -> UndergradRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD; 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 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_USER_NOT_ONLY, UNI_LOGIN_NO_REGISTER, UNI_LOGIN_NEED_TFA
case UNI_LOGIN_NO_REGISTER -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
case UNI_LOGIN_NEED_TFA -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
default -> { default -> {
log.error("本科生:登录代理请求异常,异常未处理"); log.error("本科生:登录代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);

Loading…
Cancel
Save