main
lensfrex 1 year ago
parent 4974bb14f1
commit c792263bed
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 1
      .idea/vcs.xml
  2. 2
      external-library/mywust
  3. 4
      sub-services/.flattened-pom.xml
  4. 21
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/Main.java
  5. 8
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/CookieApi.java
  6. 19
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/CourseTableApi.java
  7. 9
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/ScoreApi.java
  8. 11
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/StudentInfoApi.java
  9. 10
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/TrainingPlanApi.java
  10. 2
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/handler/BaseExceptionHandler.java
  11. 2
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/handler/DefaultExceptionHandler.java
  12. 2
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/handler/IOExceptionHandler.java
  13. 2
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/handler/ParseExceptionHandler.java
  14. 2
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/handler/RpcExceptionHandler.java
  15. 2
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/handler/ValidationExceptionHandler.java
  16. 12
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/handler/WebApplicationExceptionHandler.java
  17. 4
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/api/json/interceptor/ResponseWrapperInterceptor.java
  18. 2
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/bean/JacksonBean.java
  19. 29
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/bean/MywustParserBeans.java
  20. 63
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/bean/MywustRequestAgentBeans.java
  21. 19
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/exception/GraduateRpcException.java
  22. 87
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/services/LoginService.java
  23. 83
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/services/ParseService.java
  24. 122
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/services/RequestAgentService.java
  25. 49
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/CreditStatusApi.java
  26. 36
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustParserBeans.java
  27. 63
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustRequestAgentBeans.java
  28. 78
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java
  29. 132
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java
  30. 8
      sub-services/graduate/src/main/resources/application.properties
  31. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/Main.java
  32. 6
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/CookieApi.java
  33. 9
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/CourseTableApi.java
  34. 10
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/CreditStatusApi.java
  35. 4
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/ExamActivitiesApi.java
  36. 6
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/ExamDelayApplicationApi.java
  37. 9
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/ScoreApi.java
  38. 11
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/StudentInfoApi.java
  39. 10
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/TrainingPlanApi.java
  40. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/handler/BaseExceptionHandler.java
  41. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/handler/DefaultExceptionHandler.java
  42. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/handler/IOExceptionHandler.java
  43. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/handler/ParseExceptionHandler.java
  44. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/handler/RpcExceptionHandler.java
  45. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/handler/ValidationExceptionHandler.java
  46. 4
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/handler/WebApplicationExceptionHandler.java
  47. 4
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/api/json/interceptor/ResponseWrapperInterceptor.java
  48. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/JacksonBean.java
  49. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustParserBeans.java
  50. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/bean/MywustRequestAgentBeans.java
  51. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/exception/UndergradRpcException.java
  52. 4
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/LoginService.java
  53. 5
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/ParseService.java
  54. 4
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/services/RequestAgentService.java
  55. 16
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/Main.java
  56. 48
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/ExamActivitiesApi.java
  57. 36
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustParserBeans.java
  58. 78
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/LoginService.java
  59. 166
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/RequestAgentService.java
  60. 2
      sub-services/library/src/main/resources/application.properties
  61. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/Main.java
  62. 6
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CookieApi.java
  63. 9
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CourseTableApi.java
  64. 10
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CreditStatusApi.java
  65. 4
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamActivitiesApi.java
  66. 6
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamDelayApplicationApi.java
  67. 9
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ScoreApi.java
  68. 11
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/StudentInfoApi.java
  69. 10
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/TrainingPlanApi.java
  70. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/handler/BaseExceptionHandler.java
  71. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/handler/DefaultExceptionHandler.java
  72. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/handler/IOExceptionHandler.java
  73. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/handler/ParseExceptionHandler.java
  74. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/handler/RpcExceptionHandler.java
  75. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/handler/ValidationExceptionHandler.java
  76. 12
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/handler/WebApplicationExceptionHandler.java
  77. 4
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/interceptor/ResponseWrapperInterceptor.java
  78. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/bean/JacksonBean.java
  79. 19
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/bean/MywustParserBeans.java
  80. 46
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/bean/MywustRequestAgentBeans.java
  81. 24
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/exception/PhysicsRpcException.java
  82. 78
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/LoginService.java
  83. 101
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java
  84. 94
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java
  85. 52
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/api/json/ExamDelayApplicationApi.java
  86. 63
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/bean/MywustRequestAgentBeans.java
  87. 132
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/undergrad/services/ParseService.java
  88. 2
      sub-services/physics/src/main/resources/application.properties
  89. 4
      sub-services/pom.xml
  90. 2
      sub-services/undergrad/src/main/resources/application.properties

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

@ -1 +1 @@
Subproject commit 4b32c584249bffec4767d4b6a075af842127d5d2
Subproject commit b7c61453c566c9879314e881648cdb34bf90aaa9

@ -8,13 +8,13 @@
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>cn.wustlinghang</groupId>
<groupId>cn.wustlinghang.mywust</groupId>
<artifactId>mywust-core</artifactId>
<version>0.0.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.wustlinghang</groupId>
<groupId>cn.wustlinghang.mywust</groupId>
<artifactId>mywust-network-okhttp</artifactId>
<version>0.0.2-SNAPSHOT</version>
<scope>compile</scope>

@ -0,0 +1,21 @@
package cn.wustlinghang.wusthelper.internal.graduate;
import io.quarkus.runtime.Startup;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.config.inject.ConfigProperties;
import org.eclipse.microprofile.config.inject.ConfigProperty;
@Slf4j
@Startup
@Singleton
public class Main {
@ConfigProperty(name = "ocr.service.provider", defaultValue = "http://localhost:12800")
String ocrUrl;
@PostConstruct
public void run() {
log.info("Graduate service started. Using '{}' for login OCR service provider.", ocrUrl);
}
}

@ -1,14 +1,12 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.graduate.api.json;
import cn.wustlinghang.wusthelper.internal.undergrad.services.LoginService;
import cn.wustlinghang.wusthelper.internal.graduate.services.LoginService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/cookie")
public class CookieApi {
private final LoginService loginService;
@ -21,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

@ -1,10 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.graduate.api.json;
import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.graduate.services.ParseService;
import cn.wustlinghang.wusthelper.internal.graduate.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -13,7 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
import java.util.List;
@Path("/course_table")
@ -30,18 +27,16 @@ public class CourseTableApi {
@GET
@Path("/")
public List<Course> get(@QueryParam("cookie") @NotNull String cookie,
@QueryParam("term") String term)
public List<Course> 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

@ -1,10 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.graduate.api.json;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.graduate.services.ParseService;
import cn.wustlinghang.wusthelper.internal.graduate.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -13,7 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
import java.util.List;
@Path("/score")

@ -1,11 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.graduate.api.json;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.graduate.services.ParseService;
import cn.wustlinghang.wusthelper.internal.graduate.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -14,8 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/student_info")
@ApplicationScoped
public class StudentInfoApi {

@ -1,9 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.graduate.api.json;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.graduate.services.ParseService;
import cn.wustlinghang.wusthelper.internal.graduate.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -12,8 +10,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/training_plan")
@ApplicationScoped
public class TrainingPlanApi {

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.graduate.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.graduate.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.graduate.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.graduate.api.json.handler;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.graduate.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.graduate.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.validation.ValidationException;

@ -1,6 +1,6 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.graduate.api.json.handler;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.internal.graduate.exception.GraduateRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
@ -14,10 +14,10 @@ public class WebApplicationExceptionHandler extends BaseExceptionHandler impleme
return super.toResponse(
e.getResponse().getStatus(),
RpcException.toIntCode(
UndergradRpcException.UNDERGRAD_MODULE,
UndergradRpcException.SubModuleCode.COMMON.ordinal(),
UndergradRpcException.TypeCode.OTHER_EXCEPTION.ordinal() * 100
+ UndergradRpcException.ErrorCode.REQUEST_INVALID.ordinal()
GraduateRpcException.UNDERGRAD_MODULE,
GraduateRpcException.SubModuleCode.COMMON.ordinal(),
GraduateRpcException.TypeCode.OTHER_EXCEPTION.ordinal() * 100
+ GraduateRpcException.ErrorCode.REQUEST_INVALID.ordinal()
),
e.getMessage(),
"WebApplicationExceptionHandler"

@ -1,6 +1,6 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.interceptor;
package cn.wustlinghang.wusthelper.internal.graduate.api.json.interceptor;
import cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler.BaseExceptionHandler;
import cn.wustlinghang.wusthelper.internal.graduate.api.json.handler.BaseExceptionHandler;
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.ws.rs.WebApplicationException;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
package cn.wustlinghang.wusthelper.internal.graduate.bean;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.enterprise.context.ApplicationScoped;

@ -0,0 +1,29 @@
package cn.wustlinghang.wusthelper.internal.graduate.bean;
import cn.wustlinghang.mywust.core.parser.graduate.GraduateCourseTableParser;
import cn.wustlinghang.mywust.core.parser.graduate.GraduateScoreParser;
import cn.wustlinghang.mywust.core.parser.graduate.GraduateStudentInfoPageParser;
import cn.wustlinghang.mywust.core.parser.graduate.GraduateTrainingPlanPageParser;
import jakarta.inject.Singleton;
public class MywustParserBeans {
@Singleton
public GraduateCourseTableParser graduateCourseTableParser() {
return new GraduateCourseTableParser();
}
@Singleton
public GraduateScoreParser graduateScoreParser() {
return new GraduateScoreParser();
}
@Singleton
public GraduateStudentInfoPageParser graduateStudentInfoPageParser() {
return new GraduateStudentInfoPageParser();
}
@Singleton
public GraduateTrainingPlanPageParser graduateTrainingPlanPageParser() {
return new GraduateTrainingPlanPageParser();
}
}

@ -0,0 +1,63 @@
package cn.wustlinghang.wusthelper.internal.graduate.bean;
import cn.wustlinghang.mywust.core.request.service.auth.GraduateLogin;
import cn.wustlinghang.mywust.core.request.service.captcha.solver.DdddOcrCaptchaSolver;
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateCourseTableApiService;
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateScoreApiService;
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateStudentInfoApiService;
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateTrainingPlanApiService;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.okhttp.SimpleOkhttpRequester;
import jakarta.inject.Singleton;
import org.eclipse.microprofile.config.inject.ConfigProperty;
public class MywustRequestAgentBeans {
@Singleton
public Requester requester() {
// RequestClientOption option = new RequestClientOption();
// RequestClientOption.Proxy proxy = RequestClientOption.Proxy.builder()
// .address("127.0.0.1")
// .port(8080)
// .build();
// option.setProxy(proxy);
//
// return new SimpleOkhttpRequester(option, true);
return new SimpleOkhttpRequester(new RequestClientOption(), true);
}
@Singleton
public RequestClientOption requestClientOption() {
return new RequestClientOption();
}
@Singleton
public GraduateLogin graduateLogin(
@ConfigProperty(name = "ocr.service.provider", defaultValue = "http://localhost:12800")
String ocrProvider,
Requester requester) {
return new GraduateLogin(requester, new DdddOcrCaptchaSolver(ocrProvider, requester));
}
@Singleton
public GraduateCourseTableApiService graduateCourseTableApiService(Requester requester) {
return new GraduateCourseTableApiService(requester);
}
@Singleton
public GraduateScoreApiService graduateScoreApiService(Requester requester) {
return new GraduateScoreApiService(requester);
}
@Singleton
public GraduateStudentInfoApiService graduateStudentInfoApiService(Requester requester) {
return new GraduateStudentInfoApiService(requester);
}
@Singleton
public GraduateTrainingPlanApiService graduateTrainingPlanApiService(Requester requester) {
return new GraduateTrainingPlanApiService(requester);
}
}

@ -1,20 +1,20 @@
package cn.wustlinghang.wusthelper.internal.undergrad.exception;
package cn.wustlinghang.wusthelper.internal.graduate.exception;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import java.util.StringJoiner;
public class UndergradRpcException extends RpcException {
public class GraduateRpcException extends RpcException {
public static final int UNDERGRAD_MODULE = 1;
public UndergradRpcException(TypeCode typeCode,
public GraduateRpcException(TypeCode typeCode,
SubModuleCode subModuleCode,
ErrorCode errorCode) {
super(UNDERGRAD_MODULE,
typeCode.ordinal(),
subModuleCode.ordinal() * 100 + errorCode.ordinal(),
new StringJoiner("-")
.add("UNDERGRAD")
.add("GRADUATE")
.add(typeCode.name())
.add(subModuleCode.name())
.add(errorCode.name())
@ -42,8 +42,7 @@ public class UndergradRpcException extends RpcException {
* 子模块编码
*/
public enum SubModuleCode {
COMMON, AUTH, COURSE_TABLE, CREDIT_STATUS, SCORE,
STUDENT_INFO, TRAINING_PLAN, EXAM_ACTIVITIES, EXAM_DELAY_APPLICATION
COMMON, AUTH, COURSE_TABLE, SCORE, STUDENT_INFO, TRAINING_PLAN
}
/**
@ -60,14 +59,6 @@ public class UndergradRpcException extends RpcException {
NEED_EVALUATE,
AUTH_PASSWORD_WRONG,
// 用户不存在
AUTH_USER_NOT_EXISTS,
// 封号
AUTH_USER_BANNED,
// 用户账号禁用
AUTH_USER_DISABLED,
// 用户账号需要更改
AUTH_NEED_CHANGE_PASSWORD,
AUTH_UNKNOWN_ERROR
}
}

@ -0,0 +1,87 @@
package cn.wustlinghang.wusthelper.internal.graduate.services;
import cn.wustlinghang.mywust.core.request.service.auth.GraduateLogin;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.graduate.exception.GraduateRpcException;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.config.inject.ConfigProperties;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import java.io.IOException;
@Slf4j
@ApplicationScoped
public class LoginService {
private final RequestClientOption requestClientOption;
private final GraduateLogin graduateLogin;
private final int maxRetryTimes;
public LoginService(RequestClientOption requestClientOption,
GraduateLogin graduateLogin,
@ConfigProperty(name = "graduate.max-retry-times", defaultValue = "4")
int maxRetryTimes) {
this.requestClientOption = requestClientOption;
this.graduateLogin = graduateLogin;
this.maxRetryTimes = maxRetryTimes;
}
public String login(String username, String password) throws GraduateRpcException {
try {
return graduateLogin.getLoginCookie(username, password, maxRetryTimes, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e);
} catch (IOException e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.AUTH,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public boolean verify(String cookie) throws GraduateRpcException {
try {
graduateLogin.checkCookies(cookie, requestClientOption);
return true;
} catch (IOException e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.AUTH,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ApiException e) {
if (e.getCode() == ApiException.Code.NETWORK_EXCEPTION) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.AUTH,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
}
return false;
}
}
private GraduateRpcException wrapApiException(ApiException e) {
GraduateRpcException.ErrorCode errorCode = switch (e.getCode()) {
case NETWORK_EXCEPTION -> GraduateRpcException.ErrorCode.NETWORK_ERROR;
case GRADUATE_PASSWORD_WRONG -> GraduateRpcException.ErrorCode.AUTH_PASSWORD_WRONG;
default -> {
log.error("本科生:登录代理请求异常,异常未处理");
log.error("异常:", e);
yield GraduateRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
}
};
return new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.AUTH,
errorCode
);
}
}

@ -0,0 +1,83 @@
package cn.wustlinghang.wusthelper.internal.graduate.services;
import cn.wustlinghang.mywust.core.parser.graduate.GraduateCourseTableParser;
import cn.wustlinghang.mywust.core.parser.graduate.GraduateScoreParser;
import cn.wustlinghang.mywust.core.parser.graduate.GraduateStudentInfoPageParser;
import cn.wustlinghang.mywust.core.parser.graduate.GraduateTrainingPlanPageParser;
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.wusthelper.internal.graduate.exception.GraduateRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.List;
@ApplicationScoped
public class ParseService {
private final GraduateCourseTableParser courseTableParser;
private final GraduateScoreParser scoreParser;
private final GraduateStudentInfoPageParser studentInfoPageParser;
private final GraduateTrainingPlanPageParser trainingPlanPageParser;
public ParseService(GraduateCourseTableParser courseTableParser,
GraduateScoreParser scoreParser,
GraduateStudentInfoPageParser studentInfoPageParser,
GraduateTrainingPlanPageParser trainingPlanPageParser) {
this.courseTableParser = courseTableParser;
this.scoreParser = scoreParser;
this.studentInfoPageParser = studentInfoPageParser;
this.trainingPlanPageParser = trainingPlanPageParser;
}
public List<Course> parseCourseTable(String data) throws GraduateRpcException {
try {
return courseTableParser.parse(data);
} catch (Exception e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.PARSE_EXCEPTION,
GraduateRpcException.SubModuleCode.COURSE_TABLE,
GraduateRpcException.ErrorCode.PARSE_ERROR
);
}
}
public List<Score> parseScore(String data) throws RpcException {
try {
return scoreParser.parse(data);
} catch (Exception e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.PARSE_EXCEPTION,
GraduateRpcException.SubModuleCode.SCORE,
GraduateRpcException.ErrorCode.PARSE_ERROR
);
}
}
public StudentInfo parseStudentInfo(String data) throws RpcException {
try {
return studentInfoPageParser.parse(data);
} catch (Exception e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.PARSE_EXCEPTION,
GraduateRpcException.SubModuleCode.STUDENT_INFO,
GraduateRpcException.ErrorCode.PARSE_ERROR
);
}
}
public String parseTrainingPlan(String data) throws RpcException {
try {
return trainingPlanPageParser.parse(data);
} catch (Exception e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.PARSE_EXCEPTION,
GraduateRpcException.SubModuleCode.TRAINING_PLAN,
GraduateRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -0,0 +1,122 @@
package cn.wustlinghang.wusthelper.internal.graduate.services;
import cn.wustlinghang.mywust.core.request.service.auth.GraduateLogin;
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateCourseTableApiService;
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateScoreApiService;
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateStudentInfoApiService;
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateTrainingPlanApiService;
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.graduate.exception.GraduateRpcException;
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 RequestClientOption requestClientOption;
private final GraduateCourseTableApiService courseTableApiService;
private final GraduateScoreApiService scoreApiService;
private final GraduateStudentInfoApiService studentInfoApiService;
private final GraduateTrainingPlanApiService trainingPlanApiService;
public RequestAgentService(RequestClientOption requestClientOption,
GraduateCourseTableApiService courseTableApiService,
GraduateScoreApiService scoreApiService,
GraduateStudentInfoApiService studentInfoApiService,
GraduateTrainingPlanApiService trainingPlanApiService) {
this.requestClientOption = requestClientOption;
this.courseTableApiService = courseTableApiService;
this.scoreApiService = scoreApiService;
this.studentInfoApiService = studentInfoApiService;
this.trainingPlanApiService = trainingPlanApiService;
}
public String getStudentInfoPage(String cookie) throws RpcException {
try {
return studentInfoApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e, GraduateRpcException.SubModuleCode.STUDENT_INFO);
} catch (IOException e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.STUDENT_INFO,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getCourseTable(String cookie) throws RpcException {
try {
return courseTableApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e, GraduateRpcException.SubModuleCode.COURSE_TABLE);
} catch (IOException e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.COURSE_TABLE,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getScore(String cookie) throws RpcException {
try {
return scoreApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e, GraduateRpcException.SubModuleCode.SCORE);
} catch (IOException e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.SCORE,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getTrainingPlan(String cookie) throws RpcException {
try {
return trainingPlanApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) {
throw wrapApiException(e, GraduateRpcException.SubModuleCode.TRAINING_PLAN);
} catch (IOException e) {
throw new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.TRAINING_PLAN,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
}
}
private GraduateRpcException wrapApiException(ApiException e, GraduateRpcException.SubModuleCode subModuleCode) {
return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new GraduateRpcException(
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
subModuleCode,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new GraduateRpcException(
GraduateRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
GraduateRpcException.ErrorCode.COOKIE_INVALID
);
default -> {
log.error("研究生:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e);
yield new GraduateRpcException(
GraduateRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
GraduateRpcException.ErrorCode.COOKIE_INVALID
);
}
};
}
}

@ -1,49 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.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.io.IOException;
@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);
}
}

@ -1,36 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
import cn.wustlinghang.mywust.core.parser.undergraduate.*;
import jakarta.enterprise.context.ApplicationScoped;
public class MywustParserBeans {
@ApplicationScoped
public UndergradCourseTableParser undergradCourseTableParser() {
return new UndergradCourseTableParser();
}
@ApplicationScoped
public UndergradScoreParser undergradScoreParser() {
return new UndergradScoreParser();
}
@ApplicationScoped
public UndergradStudentInfoPageParser undergradStudentInfoPageParser() {
return new UndergradStudentInfoPageParser();
}
@ApplicationScoped
public UndergradTrainingPlanPageParser undergradTrainingPlanPageParser() {
return new UndergradTrainingPlanPageParser();
}
@ApplicationScoped
public UndergradCreditStatusParser undergradCreditStatusParser() {
return new UndergradCreditStatusParser();
}
@ApplicationScoped
public UndergradExamDelayParser undergradExamDelayParser() {
return new UndergradExamDelayParser();
}
}

@ -1,63 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin;
import cn.wustlinghang.mywust.core.request.service.undergraduate.*;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.okhttp.SimpleOkhttpRequester;
import jakarta.inject.Singleton;
public class MywustRequestAgentBeans {
@Singleton
public RequestClientOption requestClientOption() {
RequestClientOption.Proxy proxy = RequestClientOption.Proxy.builder()
.address("127.0.0.1")
.port(8080)
.build();
RequestClientOption option = new RequestClientOption();
// option.setProxy(proxy);
return option;
}
@Singleton
public Requester requester(RequestClientOption option) {
return new SimpleOkhttpRequester(option, true);
}
@Singleton
public UndergraduateLogin undergraduateLogin(Requester requester) {
return new UndergraduateLogin(requester);
}
@Singleton
public UndergradCourseTableApiService undergradCourseTableApiService(Requester requester) {
return new UndergradCourseTableApiService(requester);
}
@Singleton
public UndergradScoreApiService undergradScoreApiService(Requester requester) {
return new UndergradScoreApiService(requester);
}
@Singleton
public UndergradStudentInfoApiService undergradStudentInfoApiService(Requester requester) {
return new UndergradStudentInfoApiService(requester);
}
@Singleton
public UndergradTrainingPlanApiService undergradTrainingPlanApiService(Requester requester) {
return new UndergradTrainingPlanApiService(requester);
}
@Singleton
public UndergradCreditStatusApiService undergradCreditStatusApiService(Requester requester) {
return new UndergradCreditStatusApiService(requester);
}
@Singleton
public UndergradExamDelayApiService undergradExamDelayApiService(Requester requester) {
return new UndergradExamDelayApiService(requester);
}
}

@ -1,78 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
@Slf4j
@ApplicationScoped
public class LoginService {
private final RequestClientOption option;
private final UndergraduateLogin undergraduateLogin;
public LoginService(RequestClientOption option,
UndergraduateLogin undergraduateLogin) {
this.option = option;
this.undergraduateLogin = undergraduateLogin;
}
public String login(String username, String password, boolean legacy) throws UndergradRpcException {
try {
if (legacy) {
return undergraduateLogin.getLoginCookieLegacy(username, password, option);
} else {
return undergraduateLogin.getLoginCookie(username, password, option);
}
} catch (ApiException e) {
throw wrapApiException(e);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public boolean verify(String cookie) throws UndergradRpcException {
try {
return !undergraduateLogin.checkCookiesFail(cookie);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
private UndergradRpcException wrapApiException(ApiException e) {
UndergradRpcException.ErrorCode errorCode = switch (e.getCode()) {
case NETWORK_EXCEPTION -> UndergradRpcException.ErrorCode.NETWORK_ERROR;
case UNI_LOGIN_PASSWORD_WRONG -> UndergradRpcException.ErrorCode.AUTH_PASSWORD_WRONG;
case UNI_LOGIN_USER_NOT_EXISTS -> UndergradRpcException.ErrorCode.AUTH_USER_NOT_EXISTS;
case UNI_LOGIN_USER_BANNED -> UndergradRpcException.ErrorCode.AUTH_USER_BANNED;
case UNI_LOGIN_USER_DISABLED -> UndergradRpcException.ErrorCode.AUTH_USER_DISABLED;
case UNI_LOGIN_NEED_CHANGE_PASSWORD -> UndergradRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD;
case UNI_LOGIN_USER_NOT_ONLY -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
case UNI_LOGIN_NO_REGISTER -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
case UNI_LOGIN_NEED_TFA -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
default -> {
log.error("本科生:登录代理请求异常,异常未处理");
log.error("异常:", e);
yield UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
}
};
return new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
errorCode
);
}
}

@ -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,11 +1,15 @@
quarkus.http.port=22800
quarkus.http.port=22802
#quarkus.log.level=DEBUG
quarkus.log.file.encoding=UTF-8
ocr.service.provider=http://ocr.ciduid.top
graduate.max-retry-times=4
# 打包成jar时附带依赖
quarkus.package.type=uber-jar
# 原生镜像编译附加参数,去掉后编译会失败
# 但也只是能编译完成,目前的编译产物完全不可用,有非常多的严重bug
# 现阶段使用jar运行,启动效率虽不如原生程序,但速度尚可
quarkus.native.additional-build-args="--initialize-at-run-time=cn.wustlinghang.mywust"
quarkus.native.additional-build-args=--initialize-at-run-time=cn.wustlinghang.mywust

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad;
package cn.wustlinghang.wusthelper.internal.library;
import io.quarkus.runtime.Startup;
import jakarta.annotation.PostConstruct;

@ -1,14 +1,12 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.library.api.json;
import cn.wustlinghang.wusthelper.internal.undergrad.services.LoginService;
import cn.wustlinghang.wusthelper.internal.library.services.LoginService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/cookie")
public class CookieApi {
private final LoginService loginService;

@ -1,10 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.library.api.json;
import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -13,7 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
import java.util.List;
@Path("/course_table")

@ -1,9 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.library.api.json;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -12,8 +10,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/credit_status")
@ApplicationScoped
public class CreditStatusApi {

@ -1,8 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.library.api.json;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;

@ -1,8 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.library.api.json;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;

@ -1,10 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.library.api.json;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -13,7 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
import java.util.List;
@Path("/score")

@ -1,11 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.library.api.json;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -14,8 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/student_info")
@ApplicationScoped
public class StudentInfoApi {

@ -1,9 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.library.api.json;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
import cn.wustlinghang.wusthelper.internal.library.services.ParseService;
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
@ -12,8 +10,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/training_plan")
@ApplicationScoped
public class TrainingPlanApi {

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.library.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.library.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.library.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.library.api.json.handler;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.library.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.library.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.validation.ValidationException;

@ -1,6 +1,6 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.library.api.json.handler;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.internal.library.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;

@ -1,6 +1,6 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.interceptor;
package cn.wustlinghang.wusthelper.internal.library.api.json.interceptor;
import cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler.BaseExceptionHandler;
import cn.wustlinghang.wusthelper.internal.library.api.json.handler.BaseExceptionHandler;
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.ws.rs.WebApplicationException;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
package cn.wustlinghang.wusthelper.internal.library.bean;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.enterprise.context.ApplicationScoped;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
package cn.wustlinghang.wusthelper.internal.library.bean;
import cn.wustlinghang.mywust.core.parser.undergraduate.*;
import jakarta.enterprise.context.ApplicationScoped;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
package cn.wustlinghang.wusthelper.internal.library.bean;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin;
import cn.wustlinghang.mywust.core.request.service.undergraduate.*;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.exception;
package cn.wustlinghang.wusthelper.internal.library.exception;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;

@ -1,9 +1,9 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
package cn.wustlinghang.wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.internal.library.exception.UndergradRpcException;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;

@ -1,12 +1,11 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
package cn.wustlinghang.wusthelper.internal.library.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.internal.library.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;

@ -1,9 +1,9 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
package cn.wustlinghang.wusthelper.internal.library.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.internal.library.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;

@ -1,16 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad;
import io.quarkus.runtime.Startup;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Startup
@Singleton
public class Main {
@PostConstruct
public void run() {
log.info("Undergrad service started.");
}
}

@ -1,48 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.wusthelper.internal.undergrad.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<Score> parse(String html) throws RpcException {
throw RpcException.ApiNotImplement();
}
}

@ -1,36 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
import cn.wustlinghang.mywust.core.parser.undergraduate.*;
import jakarta.enterprise.context.ApplicationScoped;
public class MywustParserBeans {
@ApplicationScoped
public UndergradCourseTableParser undergradCourseTableParser() {
return new UndergradCourseTableParser();
}
@ApplicationScoped
public UndergradScoreParser undergradScoreParser() {
return new UndergradScoreParser();
}
@ApplicationScoped
public UndergradStudentInfoPageParser undergradStudentInfoPageParser() {
return new UndergradStudentInfoPageParser();
}
@ApplicationScoped
public UndergradTrainingPlanPageParser undergradTrainingPlanPageParser() {
return new UndergradTrainingPlanPageParser();
}
@ApplicationScoped
public UndergradCreditStatusParser undergradCreditStatusParser() {
return new UndergradCreditStatusParser();
}
@ApplicationScoped
public UndergradExamDelayParser undergradExamDelayParser() {
return new UndergradExamDelayParser();
}
}

@ -1,78 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
@Slf4j
@ApplicationScoped
public class LoginService {
private final RequestClientOption option;
private final UndergraduateLogin undergraduateLogin;
public LoginService(RequestClientOption option,
UndergraduateLogin undergraduateLogin) {
this.option = option;
this.undergraduateLogin = undergraduateLogin;
}
public String login(String username, String password, boolean legacy) throws UndergradRpcException {
try {
if (legacy) {
return undergraduateLogin.getLoginCookieLegacy(username, password, option);
} else {
return undergraduateLogin.getLoginCookie(username, password, option);
}
} catch (ApiException e) {
throw wrapApiException(e);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public boolean verify(String cookie) throws UndergradRpcException {
try {
return !undergraduateLogin.checkCookiesFail(cookie);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
}
}
private UndergradRpcException wrapApiException(ApiException e) {
UndergradRpcException.ErrorCode errorCode = switch (e.getCode()) {
case NETWORK_EXCEPTION -> UndergradRpcException.ErrorCode.NETWORK_ERROR;
case UNI_LOGIN_PASSWORD_WRONG -> UndergradRpcException.ErrorCode.AUTH_PASSWORD_WRONG;
case UNI_LOGIN_USER_NOT_EXISTS -> UndergradRpcException.ErrorCode.AUTH_USER_NOT_EXISTS;
case UNI_LOGIN_USER_BANNED -> UndergradRpcException.ErrorCode.AUTH_USER_BANNED;
case UNI_LOGIN_USER_DISABLED -> UndergradRpcException.ErrorCode.AUTH_USER_DISABLED;
case UNI_LOGIN_NEED_CHANGE_PASSWORD -> UndergradRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD;
case UNI_LOGIN_USER_NOT_ONLY -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
case UNI_LOGIN_NO_REGISTER -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
case UNI_LOGIN_NEED_TFA -> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
default -> {
log.error("本科生:登录代理请求异常,异常未处理");
log.error("异常:", e);
yield UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
}
};
return new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
errorCode
);
}
}

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

@ -1,4 +1,4 @@
quarkus.http.port=22800
quarkus.http.port=22804
#quarkus.log.level=DEBUG
quarkus.log.file.encoding=UTF-8

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad;
package cn.wustlinghang.wusthelper.internal.physics;
import io.quarkus.runtime.Startup;
import jakarta.annotation.PostConstruct;

@ -1,14 +1,12 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.wusthelper.internal.undergrad.services.LoginService;
import cn.wustlinghang.wusthelper.internal.physics.services.LoginService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/cookie")
public class CookieApi {
private final LoginService loginService;

@ -1,10 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -13,7 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
import java.util.List;
@Path("/course_table")

@ -1,9 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -12,8 +10,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/credit_status")
@ApplicationScoped
public class CreditStatusApi {

@ -1,8 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
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.undergrad.services.RequestAgentService;
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;

@ -1,8 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;

@ -1,10 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -13,7 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
import java.util.List;
@Path("/score")

@ -1,11 +1,8 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -14,8 +11,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/student_info")
@ApplicationScoped
public class StudentInfoApi {

@ -1,9 +1,7 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService;
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;
@ -12,8 +10,6 @@ import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.io.IOException;
@Path("/training_plan")
@ApplicationScoped
public class TrainingPlanApi {

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.physics.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.physics.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.physics.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.physics.api.json.handler;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.physics.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.ws.rs.core.Response;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.physics.api.json.handler;
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode;
import jakarta.validation.ValidationException;

@ -1,6 +1,6 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler;
package cn.wustlinghang.wusthelper.internal.physics.api.json.handler;
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
@ -14,10 +14,10 @@ public class WebApplicationExceptionHandler extends BaseExceptionHandler impleme
return super.toResponse(
e.getResponse().getStatus(),
RpcException.toIntCode(
UndergradRpcException.UNDERGRAD_MODULE,
UndergradRpcException.SubModuleCode.COMMON.ordinal(),
UndergradRpcException.TypeCode.OTHER_EXCEPTION.ordinal() * 100
+ UndergradRpcException.ErrorCode.REQUEST_INVALID.ordinal()
PhysicsRpcException.PHYSICS_MODULE,
PhysicsRpcException.SubModuleCode.COMMON.ordinal(),
PhysicsRpcException.TypeCode.OTHER_EXCEPTION.ordinal() * 100
+ PhysicsRpcException.ErrorCode.REQUEST_INVALID.ordinal()
),
e.getMessage(),
"WebApplicationExceptionHandler"

@ -1,6 +1,6 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json.interceptor;
package cn.wustlinghang.wusthelper.internal.physics.api.json.interceptor;
import cn.wustlinghang.wusthelper.internal.undergrad.api.json.handler.BaseExceptionHandler;
import cn.wustlinghang.wusthelper.internal.physics.api.json.handler.BaseExceptionHandler;
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.ws.rs.WebApplicationException;

@ -1,4 +1,4 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
package cn.wustlinghang.wusthelper.internal.physics.bean;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.enterprise.context.ApplicationScoped;

@ -0,0 +1,19 @@
package cn.wustlinghang.wusthelper.internal.physics.bean;
import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser;
import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser;
import cn.wustlinghang.mywust.core.parser.undergraduate.*;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Singleton;
public class MywustParserBeans {
@Singleton
public PhysicsCoursePageParser physicsCoursePageParser() {
return new PhysicsCoursePageParser();
}
@Singleton
public PhysicsScorePageParser physicsScorePageParser() {
return new PhysicsScorePageParser();
}
}

@ -0,0 +1,46 @@
package cn.wustlinghang.wusthelper.internal.physics.bean;
import cn.wustlinghang.mywust.core.request.service.auth.PhysicsLogin;
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiService;
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsScoreApiService;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.okhttp.SimpleOkhttpRequester;
import jakarta.inject.Singleton;
public class MywustRequestAgentBeans {
@Singleton
public RequestClientOption requestClientOption() {
RequestClientOption.Proxy proxy = RequestClientOption.Proxy.builder()
.address("127.0.0.1")
.port(8080)
.build();
RequestClientOption option = new RequestClientOption();
// option.setProxy(proxy);
return option;
}
@Singleton
public Requester requester(RequestClientOption option) {
return new SimpleOkhttpRequester(option, true);
// return new SimpleOkhttpRequester(true);
}
@Singleton
public PhysicsLogin physicsLogin(Requester requester) {
return new PhysicsLogin(requester);
}
@Singleton
public PhysicsCourseApiService physicsCourseApiService(Requester requester) {
return new PhysicsCourseApiService(requester);
}
@Singleton
public PhysicsScoreApiService physicsScoreApiService(Requester requester) {
return new PhysicsScoreApiService(requester);
}
}

@ -1,16 +1,16 @@
package cn.wustlinghang.wusthelper.internal.undergrad.exception;
package cn.wustlinghang.wusthelper.internal.physics.exception;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import java.util.StringJoiner;
public class UndergradRpcException extends RpcException {
public static final int UNDERGRAD_MODULE = 1;
public class PhysicsRpcException extends RpcException {
public static final int PHYSICS_MODULE = 4;
public UndergradRpcException(TypeCode typeCode,
public PhysicsRpcException(TypeCode typeCode,
SubModuleCode subModuleCode,
ErrorCode errorCode) {
super(UNDERGRAD_MODULE,
super(PHYSICS_MODULE,
typeCode.ordinal(),
subModuleCode.ordinal() * 100 + errorCode.ordinal(),
new StringJoiner("-")
@ -42,8 +42,7 @@ public class UndergradRpcException extends RpcException {
* 子模块编码
*/
public enum SubModuleCode {
COMMON, AUTH, COURSE_TABLE, CREDIT_STATUS, SCORE,
STUDENT_INFO, TRAINING_PLAN, EXAM_ACTIVITIES, EXAM_DELAY_APPLICATION
COMMON, AUTH, COURSE_TABLE, SCORE
}
/**
@ -56,18 +55,7 @@ public class UndergradRpcException extends RpcException {
NETWORK_ERROR,
PARSE_ERROR,
// 需要评教
NEED_EVALUATE,
AUTH_PASSWORD_WRONG,
// 用户不存在
AUTH_USER_NOT_EXISTS,
// 封号
AUTH_USER_BANNED,
// 用户账号禁用
AUTH_USER_DISABLED,
// 用户账号需要更改
AUTH_NEED_CHANGE_PASSWORD,
AUTH_UNKNOWN_ERROR
}
}

@ -0,0 +1,78 @@
package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
@Slf4j
@ApplicationScoped
public class LoginService {
private final RequestClientOption option;
private final UndergraduateLogin undergraduateLogin;
public LoginService(RequestClientOption option,
UndergraduateLogin undergraduateLogin) {
this.option = option;
this.undergraduateLogin = undergraduateLogin;
}
public String login(String username, String password, boolean legacy) throws PhysicsRpcException {
try {
if (legacy) {
return undergraduateLogin.getLoginCookieLegacy(username, password, option);
} else {
return undergraduateLogin.getLoginCookie(username, password, option);
}
} catch (ApiException e) {
throw wrapApiException(e);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.AUTH,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public boolean verify(String cookie) throws PhysicsRpcException {
try {
return !undergraduateLogin.checkCookiesFail(cookie);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.AUTH,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
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;
default -> {
log.error("本科生:登录代理请求异常,异常未处理");
log.error("异常:", e);
yield PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
}
};
return new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.AUTH,
errorCode
);
}
}

@ -0,0 +1,101 @@
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.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.List;
@ApplicationScoped
public class ParseService {
private final PhysicsCoursePageParser coursePageParser;
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 {
if (data.contains("评教")) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.NEED_EVALUATE
);
}
return scoreParser.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 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 {
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
);
}
}
public List<ExamDelayApplication> parseExamDelayApplications(String data) throws RpcException {
try {
return examDelayParser.parse(data);
} catch (Exception e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
}

@ -1,9 +1,9 @@
package cn.wustlinghang.wusthelper.internal.undergrad.services;
package cn.wustlinghang.wusthelper.internal.physics.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.internal.physics.exception.PhysicsRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
@ -44,12 +44,12 @@ public class RequestAgentService {
try {
return studentInfoApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.STUDENT_INFO);
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.STUDENT_INFO);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.STUDENT_INFO,
UndergradRpcException.ErrorCode.NETWORK_ERROR
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.STUDENT_INFO,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
@ -58,12 +58,12 @@ public class RequestAgentService {
try {
return courseTableApiService.getPage(term, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.COURSE_TABLE);
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.NETWORK_ERROR
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.COURSE_TABLE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
@ -72,12 +72,12 @@ public class RequestAgentService {
try {
return scoreApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.SCORE);
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.NETWORK_ERROR
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
@ -86,12 +86,12 @@ public class RequestAgentService {
try {
return trainingPlanApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.TRAINING_PLAN);
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.TRAINING_PLAN);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.TRAINING_PLAN,
UndergradRpcException.ErrorCode.NETWORK_ERROR
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.TRAINING_PLAN,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
@ -100,12 +100,12 @@ public class RequestAgentService {
try {
return creditStatusApiService.getPage(cookie, requestClientOption, false);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.CREDIT_STATUS);
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.CREDIT_STATUS);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.CREDIT_STATUS,
UndergradRpcException.ErrorCode.NETWORK_ERROR
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.CREDIT_STATUS,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
@ -115,12 +115,12 @@ public class RequestAgentService {
try {
return examDelayApiService.getActivities(term, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES);
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.EXAM_ACTIVITIES);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES,
UndergradRpcException.ErrorCode.NETWORK_ERROR
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.EXAM_ACTIVITIES,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
@ -130,35 +130,35 @@ public class RequestAgentService {
try {
return examDelayApiService.getPage(term, activityId, cookie);
} catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION);
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION);
} catch (IOException e) {
throw new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
UndergradRpcException.ErrorCode.NETWORK_ERROR
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
private UndergradRpcException wrapApiException(ApiException e, UndergradRpcException.SubModuleCode subModuleCode) {
private PhysicsRpcException wrapApiException(ApiException e, PhysicsRpcException.SubModuleCode subModuleCode) {
return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new UndergradRpcException(
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
case NETWORK_EXCEPTION -> new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.NETWORK_ERROR
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new UndergradRpcException(
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
case COOKIE_INVALID -> new PhysicsRpcException(
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.COOKIE_INVALID
PhysicsRpcException.ErrorCode.COOKIE_INVALID
);
default -> {
log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e);
yield new UndergradRpcException(
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
yield new PhysicsRpcException(
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.COOKIE_INVALID
PhysicsRpcException.ErrorCode.COOKIE_INVALID
);
}
};

@ -1,52 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.api.json;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService;
import cn.wustlinghang.wusthelper.internal.undergrad.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<ExamDelayApplication> 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<ExamDelayApplication> parse(String html) throws RpcException {
return parseService.parseExamDelayApplications(html);
}
}

@ -1,63 +0,0 @@
package cn.wustlinghang.wusthelper.internal.undergrad.bean;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin;
import cn.wustlinghang.mywust.core.request.service.undergraduate.*;
import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.mywust.network.Requester;
import cn.wustlinghang.mywust.network.okhttp.SimpleOkhttpRequester;
import jakarta.inject.Singleton;
public class MywustRequestAgentBeans {
@Singleton
public RequestClientOption requestClientOption() {
RequestClientOption.Proxy proxy = RequestClientOption.Proxy.builder()
.address("127.0.0.1")
.port(8080)
.build();
RequestClientOption option = new RequestClientOption();
// option.setProxy(proxy);
return option;
}
@Singleton
public Requester requester(RequestClientOption option) {
return new SimpleOkhttpRequester(option, true);
}
@Singleton
public UndergraduateLogin undergraduateLogin(Requester requester) {
return new UndergraduateLogin(requester);
}
@Singleton
public UndergradCourseTableApiService undergradCourseTableApiService(Requester requester) {
return new UndergradCourseTableApiService(requester);
}
@Singleton
public UndergradScoreApiService undergradScoreApiService(Requester requester) {
return new UndergradScoreApiService(requester);
}
@Singleton
public UndergradStudentInfoApiService undergradStudentInfoApiService(Requester requester) {
return new UndergradStudentInfoApiService(requester);
}
@Singleton
public UndergradTrainingPlanApiService undergradTrainingPlanApiService(Requester requester) {
return new UndergradTrainingPlanApiService(requester);
}
@Singleton
public UndergradCreditStatusApiService undergradCreditStatusApiService(Requester requester) {
return new UndergradCreditStatusApiService(requester);
}
@Singleton
public UndergradExamDelayApiService undergradExamDelayApiService(Requester requester) {
return new UndergradExamDelayApiService(requester);
}
}

@ -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,4 +1,4 @@
quarkus.http.port=22800
quarkus.http.port=22806
#quarkus.log.level=DEBUG
quarkus.log.file.encoding=UTF-8

@ -26,12 +26,12 @@
<dependencies>
<dependency>
<groupId>cn.wustlinghang</groupId>
<groupId>cn.wustlinghang.mywust</groupId>
<artifactId>mywust-core</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.wustlinghang</groupId>
<groupId>cn.wustlinghang.mywust</groupId>
<artifactId>mywust-network-okhttp</artifactId>
<version>${mywust.version}</version>
</dependency>

@ -8,4 +8,4 @@ quarkus.package.type=uber-jar
# 原生镜像编译附加参数,去掉后编译会失败
# 但也只是能编译完成,目前的编译产物完全不可用,有非常多的严重bug
# 现阶段使用jar运行,启动效率虽不如原生程序,但速度尚可
quarkus.native.additional-build-args="--initialize-at-run-time=cn.wustlinghang.mywust"
quarkus.native.additional-build-args=--initialize-at-run-time=cn.wustlinghang.mywust,--initialize-at-run-time=cn.wustlinghang.wusthelper,--enable-url-protocols=https
Loading…
Cancel
Save