lensfrex 1 year ago
parent 26aaad57cc
commit 166efc7f1b
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 2867
      doc/Wusthelper-内部rpc接口.postman_collection.json
  2. 2
      external-library/mywust
  3. 14
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookCoverImageApi.java
  4. 20
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/BookDetailApi.java
  5. 20
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/CurrentLoanApi.java
  6. 20
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/LoanHistoryApi.java
  7. 20
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/OverdueSoonApi.java
  8. 14
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/http/SearchApi.java
  9. 33
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java
  10. 32
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BaseService.java
  11. 33
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookCoverImageUrlService.java
  12. 33
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/BookDetailService.java
  13. 33
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/CurrentLoanService.java
  14. 32
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoanHistoryService.java
  15. 32
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/OverdueSoonService.java
  16. 8
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/ParseService.java
  17. 129
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/RequestAgentService.java
  18. 32
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/SearchService.java
  19. 16
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/CourseTableApi.java
  20. 18
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/http/ScoreApi.java
  21. 32
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/BaseService.java
  22. 57
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/CourseTableService.java
  23. 69
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java
  24. 91
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java
  25. 87
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ScoreService.java
  26. 16
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CourseTableApi.java
  27. 16
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/CreditStatusApi.java
  28. 12
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamActivitiesApi.java
  29. 16
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ExamDelayApplicationApi.java
  30. 16
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/ScoreApi.java
  31. 16
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/StudentInfoApi.java
  32. 16
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/http/TrainingPlanApi.java
  33. 32
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/BaseService.java
  34. 58
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/CourseTableService.java
  35. 53
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/CreditStatusService.java
  36. 34
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ExamActivitiesService.java
  37. 51
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ExamDelayApplicationService.java
  38. 132
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java
  39. 166
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java
  40. 58
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ScoreService.java
  41. 49
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/StudentInfoService.java
  42. 48
      sub-services/undergrad/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/TrainingPlanService.java

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit e186a0d9f014c27aecbfd0775302dcb99ce89619 Subproject commit 5fd50991814322760c7f4fb8b17a51ae8270e973

@ -1,8 +1,7 @@
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.global.Score;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService; import cn.wustlinghang.wusthelper.internal.library.services.BookCoverImageUrlService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
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;
@ -16,13 +15,10 @@ import java.util.List;
@Path("/cover_image") @Path("/cover_image")
@ApplicationScoped @ApplicationScoped
public class BookCoverImageApi { public class BookCoverImageApi {
private final RequestAgentService agentService; private final BookCoverImageUrlService service;
private final ParseService parseService;
public BookCoverImageApi(RequestAgentService agentService, public BookCoverImageApi(BookCoverImageUrlService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -36,7 +32,7 @@ public class BookCoverImageApi {
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("isbn") @NotNull String isbn) public String agent(@QueryParam("isbn") @NotNull String isbn)
throws RpcException { throws RpcException {
return agentService.getBookCoverImageUrl(isbn); return service.getBookCoverImageUrl(isbn);
} }
@POST @POST

@ -1,8 +1,7 @@
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.global.Score;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService; import cn.wustlinghang.wusthelper.internal.library.services.BookDetailService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
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;
@ -16,27 +15,24 @@ import java.util.List;
@Path("/book_detail") @Path("/book_detail")
@ApplicationScoped @ApplicationScoped
public class BookDetailApi { public class BookDetailApi {
private final RequestAgentService agentService; private final BookDetailService service;
private final ParseService parseService;
public BookDetailApi(RequestAgentService agentService, public BookDetailApi(BookDetailService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("isbn") @NotNull String isbn) public List<Score> get(@QueryParam("id") @NotNull String id)
throws RpcException { throws RpcException {
return this.parse(this.agent(isbn)); return this.parse(this.agent(id));
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("isbn") @NotNull String isbn) public String agent(@QueryParam("id") @NotNull String id)
throws RpcException { throws RpcException {
return agentService.getBookCoverImageUrl(isbn); return service.getBookDetail(id);
} }
@POST @POST

@ -1,8 +1,7 @@
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.global.Score;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService; import cn.wustlinghang.wusthelper.internal.library.services.CurrentLoanService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
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;
@ -16,27 +15,24 @@ import java.util.List;
@Path("/current_loan") @Path("/current_loan")
@ApplicationScoped @ApplicationScoped
public class CurrentLoanApi { public class CurrentLoanApi {
private final RequestAgentService agentService; private final CurrentLoanService service;
private final ParseService parseService;
public CurrentLoanApi(RequestAgentService agentService, public CurrentLoanApi(CurrentLoanService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("isbn") @NotNull String isbn) public List<Score> get(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return this.parse(this.agent(isbn)); return this.parse(this.agent(cookie));
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("isbn") @NotNull String isbn) public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getBookCoverImageUrl(isbn); return service.getCurrentLoan(cookie);
} }
@POST @POST

@ -1,8 +1,7 @@
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.global.Score;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService; import cn.wustlinghang.wusthelper.internal.library.services.LoanHistoryService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
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;
@ -16,27 +15,24 @@ import java.util.List;
@Path("/loan_history") @Path("/loan_history")
@ApplicationScoped @ApplicationScoped
public class LoanHistoryApi { public class LoanHistoryApi {
private final RequestAgentService agentService; private final LoanHistoryService service;
private final ParseService parseService;
public LoanHistoryApi(RequestAgentService agentService, public LoanHistoryApi(LoanHistoryService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("isbn") @NotNull String isbn) public List<Score> get(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return this.parse(this.agent(isbn)); return this.parse(this.agent(cookie));
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("isbn") @NotNull String isbn) public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getBookCoverImageUrl(isbn); return service.getLoanHistory(cookie);
} }
@POST @POST

@ -1,8 +1,7 @@
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.global.Score;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService; import cn.wustlinghang.wusthelper.internal.library.services.OverdueSoonService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
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;
@ -16,27 +15,24 @@ import java.util.List;
@Path("/overdue_soon") @Path("/overdue_soon")
@ApplicationScoped @ApplicationScoped
public class OverdueSoonApi { public class OverdueSoonApi {
private final RequestAgentService agentService; private final OverdueSoonService service;
private final ParseService parseService;
public OverdueSoonApi(RequestAgentService agentService, public OverdueSoonApi(OverdueSoonService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@Path("/") @Path("/")
public List<Score> get(@QueryParam("isbn") @NotNull String isbn) public List<Score> get(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return this.parse(this.agent(isbn)); return this.parse(this.agent(cookie));
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("isbn") @NotNull String isbn) public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getBookCoverImageUrl(isbn); return service.getOverdueSoon(cookie);
} }
@POST @POST

@ -1,8 +1,7 @@
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.global.Score;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService; import cn.wustlinghang.wusthelper.internal.library.services.SearchService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
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;
@ -16,13 +15,10 @@ import java.util.List;
@Path("/search") @Path("/search")
@ApplicationScoped @ApplicationScoped
public class SearchApi { public class SearchApi {
private final RequestAgentService agentService; private final SearchService service;
private final ParseService parseService;
public SearchApi(RequestAgentService agentService, public SearchApi(SearchService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -38,7 +34,7 @@ public class SearchApi {
@QueryParam("page") @NotNull int page, @QueryParam("page") @NotNull int page,
@QueryParam("page_size") @NotNull int pageSize) @QueryParam("page_size") @NotNull int pageSize)
throws RpcException { throws RpcException {
return agentService.search(keyword, page, pageSize); return service.search(keyword, page, pageSize);
} }
@POST @POST

@ -1,9 +1,7 @@
package cn.wustlinghang.wusthelper.internal.library.bean; package cn.wustlinghang.wusthelper.internal.library.bean;
import cn.wustlinghang.mywust.core.request.service.auth.LibraryLogin; import cn.wustlinghang.mywust.core.request.service.auth.LibraryLogin;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin; import cn.wustlinghang.mywust.core.request.service.library.*;
import cn.wustlinghang.mywust.core.request.service.library.LibraryApiService;
import cn.wustlinghang.mywust.core.request.service.undergraduate.*;
import cn.wustlinghang.mywust.network.RequestClientOption; import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.mywust.network.Requester; import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.okhttp.SimpleOkhttpRequester; import cn.wustlinghang.mywust.network.okhttp.SimpleOkhttpRequester;
@ -34,7 +32,32 @@ public class MywustRequestAgentBeans {
} }
@Singleton @Singleton
public LibraryApiService libraryApiService(Requester requester) { public BookCoverImageUrlApiService bookCoverImageUrlApiService(Requester requester) {
return new LibraryApiService(requester); return new BookCoverImageUrlApiService(requester);
}
@Singleton
public BookDetailApiService bookDetailApiService(Requester requester) {
return new BookDetailApiService(requester);
}
@Singleton
public CurrentLoanApiService currentLoanApiService(Requester requester) {
return new CurrentLoanApiService(requester);
}
@Singleton
public LoanHistoryApiService loanHistoryApiService(Requester requester) {
return new LoanHistoryApiService(requester);
}
@Singleton
public OverdueSoonApiService overdueSoonApiService(Requester requester) {
return new OverdueSoonApiService(requester);
}
@Singleton
public SearchApiService searchApiService(Requester requester) {
return new SearchApiService(requester);
} }
} }

@ -0,0 +1,32 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class BaseService {
protected LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) {
return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new LibraryRpcException(
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
subModuleCode,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new LibraryRpcException(
LibraryRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
LibraryRpcException.ErrorCode.COOKIE_INVALID
);
default -> {
log.error("图书馆:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e);
yield new LibraryRpcException(
LibraryRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
LibraryRpcException.ErrorCode.COOKIE_INVALID
);
}
};
}
}

@ -0,0 +1,33 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.BookCoverImageUrlApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class BookCoverImageUrlService extends BaseService {
private final BookCoverImageUrlApiService service;
public BookCoverImageUrlService(BookCoverImageUrlApiService service) {
this.service = service;
}
public String getBookCoverImageUrl(String isbn) throws RpcException {
try {
return service.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
);
}
}
}

@ -0,0 +1,33 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.BookDetailApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class BookDetailService extends BaseService {
private final BookDetailApiService service;
public BookDetailService(BookDetailApiService service) {
this.service = service;
}
public String getBookDetail(String bookId) throws RpcException {
try {
return service.getBookDetail(bookId);
} 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
);
}
}
}

@ -0,0 +1,33 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.CurrentLoanApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class CurrentLoanService extends BaseService {
private final CurrentLoanApiService service;
public CurrentLoanService(CurrentLoanApiService service) {
this.service = service;
}
public String getCurrentLoan(String cookie) throws RpcException {
try {
return service.getCurrentLoan(cookie);
} 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
);
}
}
}

@ -0,0 +1,32 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.LoanHistoryApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class LoanHistoryService extends BaseService {
private final LoanHistoryApiService service;
public LoanHistoryService(LoanHistoryApiService service) {
this.service = service;
}
public String getLoanHistory(String cookie) throws RpcException {
try {
return service.getLoanHistory(cookie);
} 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
);
}
}
}

@ -0,0 +1,32 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.OverdueSoonApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class OverdueSoonService extends BaseService {
private final OverdueSoonApiService service;
public OverdueSoonService(OverdueSoonApiService service) {
this.service = service;
}
public String getOverdueSoon(String cookie) throws RpcException {
try {
return service.getOverdueSoon(cookie);
} 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
);
}
}
}

@ -0,0 +1,8 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class ParseService {
}

@ -1,129 +0,0 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.LibraryApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
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;
@Slf4j
@ApplicationScoped
public class RequestAgentService {
private final LibraryApiService libraryApiService;
public RequestAgentService(LibraryApiService libraryApiService) {
this.libraryApiService = libraryApiService;
}
public String getBookCoverImageUrl(String isbn) throws RpcException {
try {
return libraryApiService.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 String getBookDetail(String bookId) throws RpcException {
try {
return libraryApiService.getBookDetail(bookId);
} 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 String getCurrentLoan(String cookie) throws RpcException {
try {
return libraryApiService.getCurrentLoan(cookie);
} 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
);
}
}
public String search(String keyword, int page, int pageSize) throws RpcException {
try {
return libraryApiService.search(keyword, page, pageSize);
} 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 String getLoanHistory(String cookie) throws RpcException {
try {
return libraryApiService.getLoanHistory(cookie);
} 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
);
}
}
public String getOverdueSoon(String cookie) throws RpcException {
try {
return libraryApiService.getOverdueSoon(cookie);
} 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
);
}
}
private LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) {
return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new LibraryRpcException(
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
subModuleCode,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new LibraryRpcException(
LibraryRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
LibraryRpcException.ErrorCode.COOKIE_INVALID
);
default -> {
log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e);
yield new LibraryRpcException(
LibraryRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
LibraryRpcException.ErrorCode.COOKIE_INVALID
);
}
};
}
}

@ -0,0 +1,32 @@
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.SearchApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.library.exception.LibraryRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class SearchService extends BaseService {
private final SearchApiService service;
public SearchService(SearchApiService service) {
this.service = service;
}
public String search(String keyword, int page, int pageSize) throws RpcException {
try {
return service.search(keyword, page, pageSize);
} 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
);
}
}
}

@ -1,8 +1,7 @@
package cn.wustlinghang.wusthelper.internal.physics.api.http; package cn.wustlinghang.wusthelper.internal.physics.api.http;
import cn.wustlinghang.mywust.data.physics.PhysicsCourse; import cn.wustlinghang.mywust.data.physics.PhysicsCourse;
import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; import cn.wustlinghang.wusthelper.internal.physics.services.CourseTableService;
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService;
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;
@ -16,13 +15,10 @@ import java.util.List;
@Path("/course_table") @Path("/course_table")
@ApplicationScoped @ApplicationScoped
public class CourseTableApi { public class CourseTableApi {
private final RequestAgentService agentService; private final CourseTableService service;
private final ParseService parseService;
public CourseTableApi(RequestAgentService agentService, public CourseTableApi(CourseTableService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -36,12 +32,12 @@ public class CourseTableApi {
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getCourseTable(cookie); return service.getCourseTable(cookie);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public List<PhysicsCourse> parse(String html) throws RpcException { public List<PhysicsCourse> parse(String html) throws RpcException {
return parseService.parseCourseTable(html); return service.parseCourseTable(html);
} }
} }

@ -1,8 +1,7 @@
package cn.wustlinghang.wusthelper.internal.physics.api.http; package cn.wustlinghang.wusthelper.internal.physics.api.http;
import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; import cn.wustlinghang.wusthelper.internal.physics.services.ScoreService;
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService;
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;
@ -16,13 +15,10 @@ import java.util.List;
@Path("/score") @Path("/score")
@ApplicationScoped @ApplicationScoped
public class ScoreApi { public class ScoreApi {
private final RequestAgentService agentService; private final ScoreService service;
private final ParseService parseService;
public ScoreApi(RequestAgentService agentService, public ScoreApi(ScoreService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -36,18 +32,18 @@ public class ScoreApi {
@Path("/agent") @Path("/agent")
public List<String> agent(@QueryParam("cookie") @NotNull String cookie) public List<String> agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getScore(cookie); return service.getScore(cookie);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public List<Score> parse(String html) throws RpcException { public List<Score> parse(String html) throws RpcException {
return parseService.parseScore(html); return service.parseScore(html);
} }
@POST @POST
@Path("/parse/all") @Path("/parse/all")
public List<Score> parseAll(List<String> pages) throws RpcException { public List<Score> parseAll(List<String> pages) throws RpcException {
return parseService.parseAllScore(pages); return service.parseScore(pages);
} }
} }

@ -0,0 +1,32 @@
package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class BaseService {
protected PhysicsRpcException wrapApiException(ApiException e, PhysicsRpcException.SubModuleCode subModuleCode) {
return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
subModuleCode,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new PhysicsRpcException(
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
PhysicsRpcException.ErrorCode.COOKIE_INVALID
);
default -> {
log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e);
yield new PhysicsRpcException(
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
PhysicsRpcException.ErrorCode.COOKIE_INVALID
);
}
};
}
}

@ -0,0 +1,57 @@
package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser;
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiService;
import cn.wustlinghang.mywust.data.physics.PhysicsCourse;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
import java.util.List;
@ApplicationScoped
public class CourseTableService extends BaseService {
private final RequestClientOption requestClientOption;
private final PhysicsCourseApiService agent;
private final PhysicsCoursePageParser parser;
public CourseTableService(RequestClientOption requestClientOption,
PhysicsCourseApiService agent,
PhysicsCoursePageParser parser) {
this.requestClientOption = requestClientOption;
this.agent = agent;
this.parser = parser;
}
public String getCourseTable(String cookie) throws RpcException {
try {
return agent.getPage(cookie, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.COURSE_TABLE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public List<PhysicsCourse> parseCourseTable(String data) throws PhysicsRpcException {
try {
return parser.parse(data);
} catch (Exception e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.COURSE_TABLE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -1,69 +0,0 @@
package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser;
import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.data.physics.PhysicsCourse;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.List;
@ApplicationScoped
public class ParseService {
private final PhysicsCoursePageParser coursePageParser;
private final PhysicsScorePageParser scorePageParser;
public ParseService(PhysicsCoursePageParser coursePageParser,
PhysicsScorePageParser scorePageParser) {
this.coursePageParser = coursePageParser;
this.scorePageParser = scorePageParser;
}
public List<PhysicsCourse> parseCourseTable(String data) throws PhysicsRpcException {
try {
return coursePageParser.parse(data);
} catch (Exception e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.COURSE_TABLE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
public List<Score> parseScore(String data) throws RpcException {
try {
return scorePageParser.parse(data);
} catch (PhysicsRpcException e) {
throw e;
} catch (Exception e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
public List<Score> parseAllScore(List<String> pages) throws RpcException {
try {
List<Score> scores = new ArrayList<>();
for (String page : pages) {
scores.addAll(scorePageParser.parse(page));
}
return scores;
} catch (PhysicsRpcException e) {
throw e;
} catch (Exception e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -1,91 +0,0 @@
package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiService;
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsScoreApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
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 RequestAgentService {
private final RequestClientOption requestClientOption;
private final PhysicsCourseApiService physicsCourseApiService;
private final PhysicsScoreApiService physicsScoreApiService;
public RequestAgentService(RequestClientOption requestClientOption,
PhysicsCourseApiService physicsCourseApiService,
PhysicsScoreApiService physicsScoreApiService) {
this.requestClientOption = requestClientOption;
this.physicsCourseApiService = physicsCourseApiService;
this.physicsScoreApiService = physicsScoreApiService;
}
public String getCourseTable(String cookie) throws RpcException {
try {
return physicsCourseApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.COURSE_TABLE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public List<String> getScore(String cookie) throws RpcException {
try {
return physicsScoreApiService.getAllPages(cookie, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.OTHER_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
private PhysicsRpcException wrapApiException(ApiException e, PhysicsRpcException.SubModuleCode subModuleCode) {
return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
subModuleCode,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new PhysicsRpcException(
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
PhysicsRpcException.ErrorCode.COOKIE_INVALID
);
default -> {
log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e);
yield new PhysicsRpcException(
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
PhysicsRpcException.ErrorCode.COOKIE_INVALID
);
}
};
}
}

@ -0,0 +1,87 @@
package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser;
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsScoreApiService;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ApplicationScoped
public class ScoreService extends BaseService {
private final RequestClientOption requestClientOption;
private final PhysicsScoreApiService agent;
private final PhysicsScorePageParser parser;
public ScoreService(RequestClientOption requestClientOption,
PhysicsScoreApiService agent,
PhysicsScorePageParser parser) {
this.requestClientOption = requestClientOption;
this.agent = agent;
this.parser = parser;
}
public List<String> getScore(String cookie) throws RpcException {
try {
return agent.getAllPages(cookie, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.OTHER_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
public List<Score> parseScore(String data) throws RpcException {
try {
return parser.parse(data);
} catch (PhysicsRpcException e) {
throw e;
} catch (Exception e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
public List<Score> parseScore(List<String> pages) throws RpcException {
try {
List<Score> scores = new ArrayList<>();
for (String page : pages) {
scores.addAll(parser.parse(page));
}
return scores;
} catch (PhysicsRpcException e) {
throw e;
} catch (Exception e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -1,8 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.http; package cn.wustlinghang.wusthelper.internal.undergrad.api.http;
import cn.wustlinghang.mywust.data.global.Course; import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; import cn.wustlinghang.wusthelper.internal.undergrad.services.CourseTableService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -16,13 +15,10 @@ import java.util.List;
@Path("/course_table") @Path("/course_table")
@ApplicationScoped @ApplicationScoped
public class CourseTableApi { public class CourseTableApi {
private final RequestAgentService agentService; private final CourseTableService service;
private final ParseService parseService;
public CourseTableApi(RequestAgentService agentService, public CourseTableApi(CourseTableService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -38,12 +34,12 @@ public class CourseTableApi {
public String agent(@QueryParam("cookie") @NotNull String cookie, public String agent(@QueryParam("cookie") @NotNull String cookie,
@QueryParam("term") String term) @QueryParam("term") String term)
throws RpcException { throws RpcException {
return agentService.getCourseTable(cookie, term); return service.getCourseTable(cookie, term);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public List<Course> parse(String html) throws RpcException { public List<Course> parse(String html) throws RpcException {
return parseService.parseCourseTable(html); return service.parseCourseTable(html);
} }
} }

@ -1,7 +1,6 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.http; package cn.wustlinghang.wusthelper.internal.undergrad.api.http;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; import cn.wustlinghang.wusthelper.internal.undergrad.services.CreditStatusService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -13,13 +12,10 @@ import jakarta.ws.rs.QueryParam;
@Path("/credit_status") @Path("/credit_status")
@ApplicationScoped @ApplicationScoped
public class CreditStatusApi { public class CreditStatusApi {
private final RequestAgentService agentService; private final CreditStatusService service;
private final ParseService parseService;
public CreditStatusApi(RequestAgentService agentService, public CreditStatusApi(CreditStatusService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -34,12 +30,12 @@ public class CreditStatusApi {
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getCreditStatus(cookie); return service.getCreditStatus(cookie);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public String parse(String html) throws RpcException { public String parse(String html) throws RpcException {
return parseService.parseCreditStatus(html); return service.parseCreditStatus(html);
} }
} }

@ -2,7 +2,7 @@ package cn.wustlinghang.wusthelper.internal.undergrad.api.http;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService;
import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; import cn.wustlinghang.wusthelper.internal.undergrad.services.ExamActivitiesService;
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;
@ -16,10 +16,10 @@ import java.util.List;
@Path("/exam_activities") @Path("/exam_activities")
@ApplicationScoped @ApplicationScoped
public class ExamActivitiesApi { public class ExamActivitiesApi {
private final RequestAgentService agentService; private final ExamActivitiesService service;
public ExamActivitiesApi(RequestAgentService agentService) { public ExamActivitiesApi(ExamActivitiesService service) {
this.agentService = agentService; this.service = service;
} }
@GET @GET
@ -37,12 +37,12 @@ public class ExamActivitiesApi {
@QueryParam("cookie") @NotNull String cookie, @QueryParam("cookie") @NotNull String cookie,
@QueryParam("term") @NotNull String term) @QueryParam("term") @NotNull String term)
throws RpcException { throws RpcException {
return agentService.getExamActivities(cookie, term); return service.getExamActivities(cookie, term);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public List<Score> parse(String html) throws RpcException { public List<Score> parse() throws RpcException {
throw RpcException.ApiNotImplement(); throw RpcException.ApiNotImplement();
} }
} }

@ -1,8 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.http; package cn.wustlinghang.wusthelper.internal.undergrad.api.http;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; import cn.wustlinghang.wusthelper.internal.undergrad.services.ExamDelayApplicationService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -16,13 +15,10 @@ import java.util.List;
@Path("/exam_delay_application") @Path("/exam_delay_application")
@ApplicationScoped @ApplicationScoped
public class ExamDelayApplicationApi { public class ExamDelayApplicationApi {
private final RequestAgentService agentService; private final ExamDelayApplicationService service;
private final ParseService parseService;
public ExamDelayApplicationApi(RequestAgentService agentService, public ExamDelayApplicationApi(ExamDelayApplicationService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -41,12 +37,12 @@ public class ExamDelayApplicationApi {
@QueryParam("term") @NotNull String term, @QueryParam("term") @NotNull String term,
@QueryParam("activity_id") @NotNull String activityId) @QueryParam("activity_id") @NotNull String activityId)
throws RpcException { throws RpcException {
return agentService.getExamDelayApplications(cookie, term, activityId); return service.getExamDelayApplications(cookie, term, activityId);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public List<ExamDelayApplication> parse(String html) throws RpcException { public List<ExamDelayApplication> parse(String html) throws RpcException {
return parseService.parseExamDelayApplications(html); return service.parseExamDelayApplications(html);
} }
} }

@ -1,8 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.http; package cn.wustlinghang.wusthelper.internal.undergrad.api.http;
import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; import cn.wustlinghang.wusthelper.internal.undergrad.services.ScoreService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -16,13 +15,10 @@ import java.util.List;
@Path("/score") @Path("/score")
@ApplicationScoped @ApplicationScoped
public class ScoreApi { public class ScoreApi {
private final RequestAgentService agentService; private final ScoreService service;
private final ParseService parseService;
public ScoreApi(RequestAgentService agentService, public ScoreApi(ScoreService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -36,12 +32,12 @@ public class ScoreApi {
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getScore(cookie); return service.getScore(cookie);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public List<Score> parse(String html) throws RpcException { public List<Score> parse(String html) throws RpcException {
return parseService.parseScore(html); return service.parseScore(html);
} }
} }

@ -1,8 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.http; package cn.wustlinghang.wusthelper.internal.undergrad.api.http;
import cn.wustlinghang.mywust.data.global.StudentInfo; import cn.wustlinghang.mywust.data.global.StudentInfo;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; import cn.wustlinghang.wusthelper.internal.undergrad.services.StudentInfoService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -14,13 +13,10 @@ import jakarta.ws.rs.QueryParam;
@Path("/student_info") @Path("/student_info")
@ApplicationScoped @ApplicationScoped
public class StudentInfoApi { public class StudentInfoApi {
private final RequestAgentService agentService; private final StudentInfoService service;
private final ParseService parseService;
public StudentInfoApi(RequestAgentService agentService, public StudentInfoApi(StudentInfoService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -34,12 +30,12 @@ public class StudentInfoApi {
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getStudentInfoPage(cookie); return service.getStudentInfoPage(cookie);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public StudentInfo parse(String html) throws RpcException { public StudentInfo parse(String html) throws RpcException {
return parseService.parseStudentInfo(html); return service.parseStudentInfo(html);
} }
} }

@ -1,7 +1,6 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.http; package cn.wustlinghang.wusthelper.internal.undergrad.api.http;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; import cn.wustlinghang.wusthelper.internal.undergrad.services.TrainingPlanService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -13,13 +12,10 @@ import jakarta.ws.rs.QueryParam;
@Path("/training_plan") @Path("/training_plan")
@ApplicationScoped @ApplicationScoped
public class TrainingPlanApi { public class TrainingPlanApi {
private final RequestAgentService agentService; private final TrainingPlanService service;
private final ParseService parseService;
public TrainingPlanApi(RequestAgentService agentService, public TrainingPlanApi(TrainingPlanService service) {
ParseService parseService) { this.service = service;
this.agentService = agentService;
this.parseService = parseService;
} }
@GET @GET
@ -33,12 +29,12 @@ public class TrainingPlanApi {
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getTrainingPlan(cookie); return service.getTrainingPlan(cookie);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public String parse(String html) throws RpcException { public String parse(String html) throws RpcException {
return parseService.parseTrainingPlan(html); return service.parseTrainingPlan(html);
} }
} }

@ -0,0 +1,32 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class BaseService {
protected UndergradRpcException wrapApiException(ApiException e, UndergradRpcException.SubModuleCode subModuleCode) {
return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new UndergradRpcException(
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.COOKIE_INVALID
);
default -> {
log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e);
yield new UndergradRpcException(
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.COOKIE_INVALID
);
}
};
}
}

@ -0,0 +1,58 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCourseTableParser;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCourseTableApiService;
import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
import java.util.List;
@ApplicationScoped
public class CourseTableService extends BaseService {
private final UndergradCourseTableParser courseTableParser;
private final UndergradCourseTableApiService courseTableApiService;
public CourseTableService(UndergradCourseTableParser courseTableParser,
UndergradCourseTableApiService courseTableApiService) {
this.courseTableParser = courseTableParser;
this.courseTableApiService = courseTableApiService;
}
public String getCourseTable(String cookie, String term) throws RpcException {
try {
return courseTableApiService.getPage(term, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.COURSE_TABLE);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public List<Course> parseCourseTable(String data) throws UndergradRpcException {
try {
if (data.contains("评教")) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.NEED_EVALUATE
);
}
return courseTableParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -0,0 +1,53 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCreditStatusParser;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCreditStatusApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class CreditStatusService extends BaseService {
private final UndergradCreditStatusApiService creditStatusApiService;
private final UndergradCreditStatusParser creditStatusParser;
private final RequestClientOption requestClientOption;
public CreditStatusService(UndergradCreditStatusApiService creditStatusApiService,
UndergradCreditStatusParser creditStatusParser,
RequestClientOption requestClientOption) {
this.creditStatusApiService = creditStatusApiService;
this.creditStatusParser = creditStatusParser;
this.requestClientOption = requestClientOption;
}
public String getCreditStatus(String cookie) throws RpcException {
try {
return creditStatusApiService.getPage(cookie, requestClientOption, false);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.CREDIT_STATUS);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.CREDIT_STATUS,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String parseCreditStatus(String data) throws RpcException {
try {
return creditStatusParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.CREDIT_STATUS,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -0,0 +1,34 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class ExamActivitiesService extends BaseService {
private final UndergradExamDelayApiService examDelayApiService;
public ExamActivitiesService(UndergradExamDelayApiService examDelayApiService) {
this.examDelayApiService = examDelayApiService;
}
public UndergradExamDelayApiService.ExamActivity[] getExamActivities(String cookie, String term)
throws RpcException {
try {
return examDelayApiService.getActivities(term, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
}

@ -0,0 +1,51 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradExamDelayParser;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
import java.util.List;
@ApplicationScoped
public class ExamDelayApplicationService extends BaseService {
private final UndergradExamDelayApiService examDelayApiService;
private final UndergradExamDelayParser examDelayParser;
public ExamDelayApplicationService(UndergradExamDelayApiService examDelayApiService,
UndergradExamDelayParser examDelayParser) {
this.examDelayApiService = examDelayApiService;
this.examDelayParser = examDelayParser;
}
public String getExamDelayApplications(String cookie, String term, String activityId)
throws RpcException {
try {
return examDelayApiService.getPage(term, activityId, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public List<ExamDelayApplication> parseExamDelayApplications(String data) throws RpcException {
try {
return examDelayParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -1,132 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.parser.undergraduate.*;
import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
@ApplicationScoped
public class ParseService {
private final UndergradCourseTableParser courseTableParser;
private final UndergradScoreParser scoreParser;
private final UndergradStudentInfoPageParser studentInfoPageParser;
private final UndergradTrainingPlanPageParser trainingPlanPageParser;
private final UndergradCreditStatusParser creditStatusParser;
private final UndergradExamDelayParser examDelayParser;
public ParseService(UndergradCourseTableParser courseTableParser,
UndergradScoreParser scoreParser,
UndergradStudentInfoPageParser studentInfoPageParser,
UndergradTrainingPlanPageParser trainingPlanPageParser,
UndergradCreditStatusParser creditStatusParser,
UndergradExamDelayParser examDelayParser) {
this.courseTableParser = courseTableParser;
this.scoreParser = scoreParser;
this.studentInfoPageParser = studentInfoPageParser;
this.trainingPlanPageParser = trainingPlanPageParser;
this.creditStatusParser = creditStatusParser;
this.examDelayParser = examDelayParser;
}
public List<Course> parseCourseTable(String data) throws UndergradRpcException {
try {
if (data.contains("评教")) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.NEED_EVALUATE
);
}
return courseTableParser.parse(data);
} catch (UndergradRpcException e) {
throw e;
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
public List<Score> parseScore(String data) throws RpcException {
try {
if (data.contains("评教")) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.NEED_EVALUATE
);
}
return scoreParser.parse(data);
} catch (UndergradRpcException e) {
throw e;
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
public StudentInfo parseStudentInfo(String data) throws RpcException {
try {
return studentInfoPageParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.STUDENT_INFO,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
public String parseTrainingPlan(String data) throws RpcException {
try {
return trainingPlanPageParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.TRAINING_PLAN,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
public String parseCreditStatus(String data) throws RpcException {
try {
return creditStatusParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.CREDIT_STATUS,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
public List<ExamDelayApplication> parseExamDelayApplications(String data) throws RpcException {
try {
return examDelayParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -1,166 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.request.service.undergraduate.*;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
@Slf4j
@ApplicationScoped
public class RequestAgentService {
private final UndergradCourseTableApiService courseTableApiService;
private final UndergradScoreApiService scoreApiService;
private final UndergradStudentInfoApiService studentInfoApiService;
private final UndergradTrainingPlanApiService trainingPlanApiService;
private final UndergradCreditStatusApiService creditStatusApiService;
private final UndergradExamDelayApiService examDelayApiService;
private final RequestClientOption requestClientOption;
public RequestAgentService(UndergradCourseTableApiService courseTableApiService,
UndergradScoreApiService scoreApiService,
UndergradStudentInfoApiService studentInfoApiService,
UndergradTrainingPlanApiService trainingPlanApiService,
UndergradCreditStatusApiService creditStatusApiService,
UndergradExamDelayApiService examDelayApiService,
RequestClientOption requestClientOption) {
this.courseTableApiService = courseTableApiService;
this.scoreApiService = scoreApiService;
this.studentInfoApiService = studentInfoApiService;
this.trainingPlanApiService = trainingPlanApiService;
this.creditStatusApiService = creditStatusApiService;
this.examDelayApiService = examDelayApiService;
this.requestClientOption = requestClientOption;
}
public String getStudentInfoPage(String cookie) throws RpcException {
try {
return studentInfoApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.STUDENT_INFO);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.STUDENT_INFO,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getCourseTable(String cookie, String term) throws RpcException {
try {
return courseTableApiService.getPage(term, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.COURSE_TABLE);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getScore(String cookie) throws RpcException {
try {
return scoreApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.SCORE);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getTrainingPlan(String cookie) throws RpcException {
try {
return trainingPlanApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.TRAINING_PLAN);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.TRAINING_PLAN,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getCreditStatus(String cookie) throws RpcException {
try {
return creditStatusApiService.getPage(cookie, requestClientOption, false);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.CREDIT_STATUS);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.CREDIT_STATUS,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public UndergradExamDelayApiService.ExamActivity[] getExamActivities(String cookie, String term)
throws RpcException {
try {
return examDelayApiService.getActivities(term, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getExamDelayApplications(String cookie, String term, String activityId)
throws RpcException {
try {
return examDelayApiService.getPage(term, activityId, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
private UndergradRpcException wrapApiException(ApiException e, UndergradRpcException.SubModuleCode subModuleCode) {
return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new UndergradRpcException(
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.COOKIE_INVALID
);
default -> {
log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e);
yield new UndergradRpcException(
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.COOKIE_INVALID
);
}
};
}
}

@ -0,0 +1,58 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradScoreParser;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradScoreApiService;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
import java.util.List;
@ApplicationScoped
public class ScoreService extends BaseService {
private final UndergradScoreApiService scoreApiService;
private final UndergradScoreParser scoreParser;
public ScoreService(UndergradScoreApiService scoreApiService,
UndergradScoreParser scoreParser) {
this.scoreApiService = scoreApiService;
this.scoreParser = scoreParser;
}
public String getScore(String cookie) throws RpcException {
try {
return scoreApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.SCORE);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public List<Score> parseScore(String data) throws RpcException {
try {
if (data.contains("评教")) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.NEED_EVALUATE
);
}
return scoreParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -0,0 +1,49 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradStudentInfoPageParser;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradStudentInfoApiService;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class StudentInfoService extends BaseService {
private final UndergradStudentInfoApiService studentInfoApiService;
private final UndergradStudentInfoPageParser studentInfoPageParser;
public StudentInfoService(UndergradStudentInfoApiService studentInfoApiService,
UndergradStudentInfoPageParser studentInfoPageParser) {
this.studentInfoApiService = studentInfoApiService;
this.studentInfoPageParser = studentInfoPageParser;
}
public String getStudentInfoPage(String cookie) throws RpcException {
try {
return studentInfoApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.STUDENT_INFO);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.STUDENT_INFO,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public StudentInfo parseStudentInfo(String data) throws RpcException {
try {
return studentInfoPageParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.STUDENT_INFO,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -0,0 +1,48 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradTrainingPlanPageParser;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradTrainingPlanApiService;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException;
@ApplicationScoped
public class TrainingPlanService extends BaseService {
private final UndergradTrainingPlanApiService trainingPlanApiService;
private final UndergradTrainingPlanPageParser trainingPlanPageParser;
public TrainingPlanService(UndergradTrainingPlanApiService trainingPlanApiService,
UndergradTrainingPlanPageParser trainingPlanPageParser) {
this.trainingPlanApiService = trainingPlanApiService;
this.trainingPlanPageParser = trainingPlanPageParser;
}
public String getTrainingPlan(String cookie) throws RpcException {
try {
return trainingPlanApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.TRAINING_PLAN);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.TRAINING_PLAN,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String parseTrainingPlan(String data) throws RpcException {
try {
return trainingPlanPageParser.parse(data);
} catch (Exception e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.TRAINING_PLAN,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
}
}
}
Loading…
Cancel
Save