From 4777fc11eb06f1bb6e31791aa9d4bccf4a974ba2 Mon Sep 17 00:00:00 2001 From: lensferno Date: Mon, 10 Jul 2023 15:23:22 +0800 Subject: [PATCH] physics --- external-library/mywust | 2 +- .../exception/GraduateRpcException.java | 1 + .../graduate/services/LoginService.java | 3 +- .../wusthelper/internal/library/Main.java | 2 +- .../wusthelper/internal/physics/Main.java | 2 +- .../internal/physics/api/json/CookieApi.java | 2 +- .../physics/api/json/CourseTableApi.java | 14 +-- .../physics/api/json/CreditStatusApi.java | 45 ------- .../physics/api/json/ExamActivitiesApi.java | 48 -------- .../api/json/ExamDelayApplicationApi.java | 52 -------- .../internal/physics/api/json/ScoreApi.java | 10 +- .../physics/api/json/StudentInfoApi.java | 45 ------- .../physics/api/json/TrainingPlanApi.java | 44 ------- .../exception/PhysicsRpcException.java | 6 +- .../physics/services/LoginService.java | 39 +++--- .../physics/services/ParseService.java | 70 +++-------- .../physics/services/RequestAgentService.java | 115 +++--------------- 17 files changed, 83 insertions(+), 417 deletions(-) delete mode 100644 sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CreditStatusApi.java delete mode 100644 sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamActivitiesApi.java delete mode 100644 sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamDelayApplicationApi.java delete mode 100644 sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/StudentInfoApi.java delete mode 100644 sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/TrainingPlanApi.java diff --git a/external-library/mywust b/external-library/mywust index b7c6145..e186a0d 160000 --- a/external-library/mywust +++ b/external-library/mywust @@ -1 +1 @@ -Subproject commit b7c61453c566c9879314e881648cdb34bf90aaa9 +Subproject commit e186a0d9f014c27aecbfd0775302dcb99ce89619 diff --git a/sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/exception/GraduateRpcException.java b/sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/exception/GraduateRpcException.java index 445c2c4..b92a87f 100644 --- a/sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/exception/GraduateRpcException.java +++ b/sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/exception/GraduateRpcException.java @@ -59,6 +59,7 @@ public class GraduateRpcException extends RpcException { NEED_EVALUATE, AUTH_PASSWORD_WRONG, + AUTH_CAPTCHA_WRONG, AUTH_UNKNOWN_ERROR } } diff --git a/sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/services/LoginService.java b/sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/services/LoginService.java index e915cea..1e88c1e 100644 --- a/sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/services/LoginService.java +++ b/sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/services/LoginService.java @@ -71,8 +71,9 @@ public class LoginService { GraduateRpcException.ErrorCode errorCode = switch (e.getCode()) { case NETWORK_EXCEPTION -> GraduateRpcException.ErrorCode.NETWORK_ERROR; case GRADUATE_PASSWORD_WRONG -> GraduateRpcException.ErrorCode.AUTH_PASSWORD_WRONG; + case GRADUATE_CAPTCHA_WRONG -> GraduateRpcException.ErrorCode.AUTH_CAPTCHA_WRONG; default -> { - log.error("本科生:登录代理请求异常,异常未处理"); + log.error("研究生:登录代理请求异常,异常未处理"); log.error("异常:", e); yield GraduateRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; } diff --git a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/Main.java b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/Main.java index 03782a7..f1f0816 100644 --- a/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/Main.java +++ b/sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/Main.java @@ -11,6 +11,6 @@ import lombok.extern.slf4j.Slf4j; public class Main { @PostConstruct public void run() { - log.info("Undergrad service started."); + log.info("Library service started."); } } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/Main.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/Main.java index 0443296..5af4f12 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/Main.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/Main.java @@ -11,6 +11,6 @@ import lombok.extern.slf4j.Slf4j; public class Main { @PostConstruct public void run() { - log.info("Undergrad service started."); + log.info("Physics service started."); } } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CookieApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CookieApi.java index 9efaa89..c8c7cdc 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CookieApi.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CookieApi.java @@ -19,7 +19,7 @@ public class CookieApi { @Path("/") public String login(@QueryParam("username") @NotNull String username, @QueryParam("password") @NotNull String password) throws RpcException { - return loginService.login(username, password, false); + return loginService.login(username, password); } @GET diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CourseTableApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CourseTableApi.java index 5ecbc5f..1ec7fcc 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CourseTableApi.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CourseTableApi.java @@ -1,6 +1,6 @@ package cn.wustlinghang.wusthelper.internal.physics.api.json; -import cn.wustlinghang.mywust.data.global.Course; +import cn.wustlinghang.mywust.data.physics.PhysicsCourse; import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; import cn.wustlinghang.wusthelper.rpc.exception.RpcException; @@ -27,23 +27,21 @@ public class CourseTableApi { @GET @Path("/") - public List get(@QueryParam("cookie") @NotNull String cookie, - @QueryParam("term") String term) + public List get(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return this.parse(this.agent(cookie, term)); + return this.parse(this.agent(cookie)); } @GET @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie, - @QueryParam("term") String term) + public String agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return agentService.getCourseTable(cookie, term); + return agentService.getCourseTable(cookie); } @POST @Path("/parse") - public List parse(String html) throws RpcException { + public List parse(String html) throws RpcException { return parseService.parseCourseTable(html); } } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CreditStatusApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CreditStatusApi.java deleted file mode 100644 index 2903361..0000000 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CreditStatusApi.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.physics.api.json; - -import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; -import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.validation.constraints.NotNull; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.QueryParam; - -@Path("/credit_status") -@ApplicationScoped -public class CreditStatusApi { - private final RequestAgentService agentService; - private final ParseService parseService; - - public CreditStatusApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; - } - - @GET - @Path("/") - public String get(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - String html = this.agent(cookie); - return this.parse(html); - } - - @GET - @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return agentService.getCreditStatus(cookie); - } - - @POST - @Path("/parse") - public String parse(String html) throws RpcException { - return parseService.parseCreditStatus(html); - } -} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamActivitiesApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamActivitiesApi.java deleted file mode 100644 index 2e50ff8..0000000 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamActivitiesApi.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.physics.api.json; - -import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; -import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.validation.constraints.NotNull; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.QueryParam; - -import java.util.List; - -@Path("/exam_activities") -@ApplicationScoped -public class ExamActivitiesApi { - private final RequestAgentService agentService; - - public ExamActivitiesApi(RequestAgentService agentService) { - this.agentService = agentService; - } - - @GET - @Path("/") - public UndergradExamDelayApiService.ExamActivity[] get( - @QueryParam("cookie") @NotNull String cookie, - @QueryParam("term") @NotNull String term) - throws RpcException { - return this.agent(cookie, term); - } - - @GET - @Path("/agent") - public UndergradExamDelayApiService.ExamActivity[] agent( - @QueryParam("cookie") @NotNull String cookie, - @QueryParam("term") @NotNull String term) - throws RpcException { - return agentService.getExamActivities(cookie, term); - } - - @POST - @Path("/parse") - public List parse(String html) throws RpcException { - throw RpcException.ApiNotImplement(); - } -} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamDelayApplicationApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamDelayApplicationApi.java deleted file mode 100644 index 2227888..0000000 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamDelayApplicationApi.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.physics.api.json; - -import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; -import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; -import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.validation.constraints.NotNull; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.QueryParam; - -import java.util.List; - -@Path("/exam_delay_application") -@ApplicationScoped -public class ExamDelayApplicationApi { - private final RequestAgentService agentService; - private final ParseService parseService; - - public ExamDelayApplicationApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; - } - - @GET - @Path("/") - public List get( - @QueryParam("cookie") @NotNull String cookie, - @QueryParam("term") @NotNull String term, - @QueryParam("activity_id") @NotNull String activityId) - throws RpcException { - return this.parse(this.agent(cookie, term, activityId)); - } - - @GET - @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie, - @QueryParam("term") @NotNull String term, - @QueryParam("activity_id") @NotNull String activityId) - throws RpcException { - return agentService.getExamDelayApplications(cookie, term, activityId); - } - - @POST - @Path("/parse") - public List parse(String html) throws RpcException { - return parseService.parseExamDelayApplications(html); - } -} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ScoreApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ScoreApi.java index 4a6fa68..65fbf30 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ScoreApi.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ScoreApi.java @@ -29,12 +29,12 @@ public class ScoreApi { @Path("/") public List get(@QueryParam("cookie") @NotNull String cookie) throws RpcException { - return this.parse(this.agent(cookie)); + return this.parseAll(this.agent(cookie)); } @GET @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie) + public List agent(@QueryParam("cookie") @NotNull String cookie) throws RpcException { return agentService.getScore(cookie); } @@ -44,4 +44,10 @@ public class ScoreApi { public List parse(String html) throws RpcException { return parseService.parseScore(html); } + + @POST + @Path("/parse/all") + public List parseAll(List pages) throws RpcException { + return parseService.parseAllScore(pages); + } } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/StudentInfoApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/StudentInfoApi.java deleted file mode 100644 index 6ed89a6..0000000 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/StudentInfoApi.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.physics.api.json; - -import cn.wustlinghang.mywust.data.global.StudentInfo; -import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; -import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.validation.constraints.NotNull; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.QueryParam; - -@Path("/student_info") -@ApplicationScoped -public class StudentInfoApi { - private final RequestAgentService agentService; - private final ParseService parseService; - - public StudentInfoApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; - } - - @GET - @Path("/") - public StudentInfo get(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return this.parse(this.agent(cookie)); - } - - @GET - @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return agentService.getStudentInfoPage(cookie); - } - - @POST - @Path("/parse") - public StudentInfo parse(String html) throws RpcException { - return parseService.parseStudentInfo(html); - } -} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/TrainingPlanApi.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/TrainingPlanApi.java deleted file mode 100644 index b65f204..0000000 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/TrainingPlanApi.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.wustlinghang.wusthelper.internal.physics.api.json; - -import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; -import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; -import cn.wustlinghang.wusthelper.rpc.exception.RpcException; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.validation.constraints.NotNull; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.QueryParam; - -@Path("/training_plan") -@ApplicationScoped -public class TrainingPlanApi { - private final RequestAgentService agentService; - private final ParseService parseService; - - public TrainingPlanApi(RequestAgentService agentService, - ParseService parseService) { - this.agentService = agentService; - this.parseService = parseService; - } - - @GET - @Path("/") - public String get(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return this.parse(this.agent(cookie)); - } - - @GET - @Path("/agent") - public String agent(@QueryParam("cookie") @NotNull String cookie) - throws RpcException { - return agentService.getTrainingPlan(cookie); - } - - @POST - @Path("/parse") - public String parse(String html) throws RpcException { - return parseService.parseTrainingPlan(html); - } -} diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/exception/PhysicsRpcException.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/exception/PhysicsRpcException.java index 808e410..699c061 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/exception/PhysicsRpcException.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/exception/PhysicsRpcException.java @@ -14,7 +14,7 @@ public class PhysicsRpcException extends RpcException { typeCode.ordinal(), subModuleCode.ordinal() * 100 + errorCode.ordinal(), new StringJoiner("-") - .add("UNDERGRAD") + .add("PHYSICS") .add(typeCode.name()) .add(subModuleCode.name()) .add(errorCode.name()) @@ -56,6 +56,8 @@ public class PhysicsRpcException extends RpcException { PARSE_ERROR, AUTH_PASSWORD_WRONG, - AUTH_UNKNOWN_ERROR + AUTH_UNKNOWN_ERROR, + + AUTH_USER_NOT_CURRENT_TERM } } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/LoginService.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/LoginService.java index feadd10..6c367e5 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/LoginService.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/LoginService.java @@ -1,7 +1,8 @@ package cn.wustlinghang.wusthelper.internal.physics.services; -import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin; +import cn.wustlinghang.mywust.core.request.service.auth.PhysicsLogin; 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 jakarta.enterprise.context.ApplicationScoped; @@ -13,21 +14,18 @@ import java.io.IOException; @ApplicationScoped public class LoginService { private final RequestClientOption option; - private final UndergraduateLogin undergraduateLogin; + + private final PhysicsLogin physicsLogin; public LoginService(RequestClientOption option, - UndergraduateLogin undergraduateLogin) { + PhysicsLogin physicsLogin) { this.option = option; - this.undergraduateLogin = undergraduateLogin; + this.physicsLogin = physicsLogin; } - public String login(String username, String password, boolean legacy) throws PhysicsRpcException { + public String login(String username, String password) throws PhysicsRpcException { try { - if (legacy) { - return undergraduateLogin.getLoginCookieLegacy(username, password, option); - } else { - return undergraduateLogin.getLoginCookie(username, password, option); - } + return physicsLogin.getLoginCookie(username, password, option); } catch (ApiException e) { throw wrapApiException(e); } catch (IOException e) { @@ -36,12 +34,19 @@ public class LoginService { PhysicsRpcException.SubModuleCode.AUTH, PhysicsRpcException.ErrorCode.NETWORK_ERROR ); + } catch (ParseException e) { + log.error("物理实验:登录时出现页面参数解析问题", e); + throw new PhysicsRpcException( + PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, + PhysicsRpcException.SubModuleCode.AUTH, + PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR + ); } } public boolean verify(String cookie) throws PhysicsRpcException { try { - return !undergraduateLogin.checkCookiesFail(cookie); + return physicsLogin.checkCookie(cookie, option); } catch (IOException e) { throw new PhysicsRpcException( PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, @@ -54,16 +59,10 @@ public class LoginService { private PhysicsRpcException wrapApiException(ApiException e) { PhysicsRpcException.ErrorCode errorCode = switch (e.getCode()) { case NETWORK_EXCEPTION -> PhysicsRpcException.ErrorCode.NETWORK_ERROR; - case UNI_LOGIN_PASSWORD_WRONG -> PhysicsRpcException.ErrorCode.AUTH_PASSWORD_WRONG; - case UNI_LOGIN_USER_NOT_EXISTS -> PhysicsRpcException.ErrorCode.AUTH_USER_NOT_EXISTS; - case UNI_LOGIN_USER_BANNED -> PhysicsRpcException.ErrorCode.AUTH_USER_BANNED; - case UNI_LOGIN_USER_DISABLED -> PhysicsRpcException.ErrorCode.AUTH_USER_DISABLED; - case UNI_LOGIN_NEED_CHANGE_PASSWORD -> PhysicsRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD; - case UNI_LOGIN_USER_NOT_ONLY -> PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; - case UNI_LOGIN_NO_REGISTER -> PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; - case UNI_LOGIN_NEED_TFA -> PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; + case PHYSICS_PASSWORD_WRONG -> PhysicsRpcException.ErrorCode.AUTH_PASSWORD_WRONG; + case PHYSICS_NOT_CURRENT_TERM -> PhysicsRpcException.ErrorCode.AUTH_USER_NOT_CURRENT_TERM; default -> { - log.error("本科生:登录代理请求异常,异常未处理"); + log.error("物理实验:登录代理请求异常,异常未处理"); log.error("异常:", e); yield PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java index a4b3190..ff462ff 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java @@ -1,20 +1,26 @@ package cn.wustlinghang.wusthelper.internal.physics.services; import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser; -import cn.wustlinghang.mywust.data.global.Course; +import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser; import cn.wustlinghang.mywust.data.global.Score; -import cn.wustlinghang.mywust.data.global.StudentInfo; import cn.wustlinghang.mywust.data.physics.PhysicsCourse; -import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; 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 parseCourseTable(String data) throws PhysicsRpcException { try { @@ -30,16 +36,7 @@ public class ParseService { public List parseScore(String data) throws RpcException { try { - if (data.contains("评教")) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.PARSE_EXCEPTION, - PhysicsRpcException.SubModuleCode.SCORE, - PhysicsRpcException.ErrorCode.NEED_EVALUATE - ); - } - - return scoreParser.parse(data); - + return scorePageParser.parse(data); } catch (PhysicsRpcException e) { throw e; } catch (Exception e) { @@ -51,49 +48,20 @@ public class ParseService { } } - public StudentInfo parseStudentInfo(String data) throws RpcException { - try { - return studentInfoPageParser.parse(data); - } catch (Exception e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.PARSE_EXCEPTION, - PhysicsRpcException.SubModuleCode.STUDENT_INFO, - PhysicsRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public String parseTrainingPlan(String data) throws RpcException { + public List parseAllScore(List pages) throws RpcException { try { - return trainingPlanPageParser.parse(data); - } catch (Exception e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.PARSE_EXCEPTION, - PhysicsRpcException.SubModuleCode.TRAINING_PLAN, - PhysicsRpcException.ErrorCode.PARSE_ERROR - ); - } - } - - public String parseCreditStatus(String data) throws RpcException { - try { - return creditStatusParser.parse(data); - } catch (Exception e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.PARSE_EXCEPTION, - PhysicsRpcException.SubModuleCode.CREDIT_STATUS, - PhysicsRpcException.ErrorCode.PARSE_ERROR - ); - } - } + List scores = new ArrayList<>(); + for (String page : pages) { + scores.addAll(scorePageParser.parse(page)); + } - public List parseExamDelayApplications(String data) throws RpcException { - try { - return examDelayParser.parse(data); + return scores; + } catch (PhysicsRpcException e) { + throw e; } catch (Exception e) { throw new PhysicsRpcException( PhysicsRpcException.TypeCode.PARSE_EXCEPTION, - PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, + PhysicsRpcException.SubModuleCode.SCORE, PhysicsRpcException.ErrorCode.PARSE_ERROR ); } diff --git a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java index 18a2d4e..2dc8f71 100644 --- a/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java +++ b/sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java @@ -1,7 +1,9 @@ package cn.wustlinghang.wusthelper.internal.physics.services; -import cn.wustlinghang.mywust.core.request.service.undergraduate.*; +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; @@ -9,54 +11,29 @@ 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 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; + private final PhysicsCourseApiService physicsCourseApiService; + private final PhysicsScoreApiService physicsScoreApiService; + public RequestAgentService(RequestClientOption requestClientOption, + PhysicsCourseApiService physicsCourseApiService, + PhysicsScoreApiService physicsScoreApiService) { this.requestClientOption = requestClientOption; - } - public String getStudentInfoPage(String cookie) throws RpcException { - try { - return studentInfoApiService.getPage(cookie); - } catch (ApiException e) { - throw wrapApiException(e, PhysicsRpcException.SubModuleCode.STUDENT_INFO); - } catch (IOException e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, - PhysicsRpcException.SubModuleCode.STUDENT_INFO, - PhysicsRpcException.ErrorCode.NETWORK_ERROR - ); - } + this.physicsCourseApiService = physicsCourseApiService; + this.physicsScoreApiService = physicsScoreApiService; } - public String getCourseTable(String cookie, String term) throws RpcException { + public String getCourseTable(String cookie) throws RpcException { try { - return courseTableApiService.getPage(term, cookie); + return physicsCourseApiService.getPage(cookie, requestClientOption); } catch (ApiException e) { throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE); } catch (IOException e) { @@ -68,9 +45,9 @@ public class RequestAgentService { } } - public String getScore(String cookie) throws RpcException { + public List getScore(String cookie) throws RpcException { try { - return scoreApiService.getPage(cookie); + return physicsScoreApiService.getAllPages(cookie, requestClientOption); } catch (ApiException e) { throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE); } catch (IOException e) { @@ -79,63 +56,11 @@ public class RequestAgentService { PhysicsRpcException.SubModuleCode.SCORE, PhysicsRpcException.ErrorCode.NETWORK_ERROR ); - } - } - - public String getTrainingPlan(String cookie) throws RpcException { - try { - return trainingPlanApiService.getPage(cookie); - } catch (ApiException e) { - throw wrapApiException(e, PhysicsRpcException.SubModuleCode.TRAINING_PLAN); - } catch (IOException e) { + } catch (ParseException e) { throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, - PhysicsRpcException.SubModuleCode.TRAINING_PLAN, - PhysicsRpcException.ErrorCode.NETWORK_ERROR - ); - } - } - - public String getCreditStatus(String cookie) throws RpcException { - try { - return creditStatusApiService.getPage(cookie, requestClientOption, false); - } catch (ApiException e) { - throw wrapApiException(e, PhysicsRpcException.SubModuleCode.CREDIT_STATUS); - } catch (IOException e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, - PhysicsRpcException.SubModuleCode.CREDIT_STATUS, - PhysicsRpcException.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, PhysicsRpcException.SubModuleCode.EXAM_ACTIVITIES); - } catch (IOException e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, - PhysicsRpcException.SubModuleCode.EXAM_ACTIVITIES, - PhysicsRpcException.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, PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION); - } catch (IOException e) { - throw new PhysicsRpcException( - PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, - PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, - PhysicsRpcException.ErrorCode.NETWORK_ERROR + PhysicsRpcException.TypeCode.OTHER_EXCEPTION, + PhysicsRpcException.SubModuleCode.SCORE, + PhysicsRpcException.ErrorCode.PARSE_ERROR ); } } @@ -153,7 +78,7 @@ public class RequestAgentService { PhysicsRpcException.ErrorCode.COOKIE_INVALID ); default -> { - log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); + log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name()); log.error("异常:", e); yield new PhysicsRpcException( PhysicsRpcException.TypeCode.AUTH_EXCEPTION,