main
lensfrex 1 year ago
parent c792263bed
commit 4777fc11eb
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 2
      external-library/mywust
  2. 1
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/exception/GraduateRpcException.java
  3. 3
      sub-services/graduate/src/main/java/cn/wustlinghang/wusthelper/internal/graduate/services/LoginService.java
  4. 2
      sub-services/library/src/main/java/cn/wustlinghang/wusthelper/internal/library/Main.java
  5. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/Main.java
  6. 2
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CookieApi.java
  7. 14
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CourseTableApi.java
  8. 45
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/CreditStatusApi.java
  9. 48
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamActivitiesApi.java
  10. 52
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ExamDelayApplicationApi.java
  11. 10
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/ScoreApi.java
  12. 45
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/StudentInfoApi.java
  13. 44
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/api/json/TrainingPlanApi.java
  14. 6
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/exception/PhysicsRpcException.java
  15. 39
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/LoginService.java
  16. 68
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/ParseService.java
  17. 115
      sub-services/physics/src/main/java/cn/wustlinghang/wusthelper/internal/physics/services/RequestAgentService.java

@ -1 +1 @@
Subproject commit b7c61453c566c9879314e881648cdb34bf90aaa9 Subproject commit e186a0d9f014c27aecbfd0775302dcb99ce89619

@ -59,6 +59,7 @@ public class GraduateRpcException extends RpcException {
NEED_EVALUATE, NEED_EVALUATE,
AUTH_PASSWORD_WRONG, AUTH_PASSWORD_WRONG,
AUTH_CAPTCHA_WRONG,
AUTH_UNKNOWN_ERROR AUTH_UNKNOWN_ERROR
} }
} }

@ -71,8 +71,9 @@ public class LoginService {
GraduateRpcException.ErrorCode errorCode = switch (e.getCode()) { GraduateRpcException.ErrorCode errorCode = switch (e.getCode()) {
case NETWORK_EXCEPTION -> GraduateRpcException.ErrorCode.NETWORK_ERROR; case NETWORK_EXCEPTION -> GraduateRpcException.ErrorCode.NETWORK_ERROR;
case GRADUATE_PASSWORD_WRONG -> GraduateRpcException.ErrorCode.AUTH_PASSWORD_WRONG; case GRADUATE_PASSWORD_WRONG -> GraduateRpcException.ErrorCode.AUTH_PASSWORD_WRONG;
case GRADUATE_CAPTCHA_WRONG -> GraduateRpcException.ErrorCode.AUTH_CAPTCHA_WRONG;
default -> { default -> {
log.error("本科生:登录代理请求异常,异常未处理"); log.error("研究生:登录代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield GraduateRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; yield GraduateRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
} }

@ -11,6 +11,6 @@ import lombok.extern.slf4j.Slf4j;
public class Main { public class Main {
@PostConstruct @PostConstruct
public void run() { public void run() {
log.info("Undergrad service started."); log.info("Library service started.");
} }
} }

@ -11,6 +11,6 @@ import lombok.extern.slf4j.Slf4j;
public class Main { public class Main {
@PostConstruct @PostConstruct
public void run() { public void run() {
log.info("Undergrad service started."); log.info("Physics service started.");
} }
} }

@ -19,7 +19,7 @@ public class CookieApi {
@Path("/") @Path("/")
public String login(@QueryParam("username") @NotNull String username, public String login(@QueryParam("username") @NotNull String username,
@QueryParam("password") @NotNull String password) throws RpcException { @QueryParam("password") @NotNull String password) throws RpcException {
return loginService.login(username, password, false); return loginService.login(username, password);
} }
@GET @GET

@ -1,6 +1,6 @@
package cn.wustlinghang.wusthelper.internal.physics.api.json; package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.data.global.Course; import cn.wustlinghang.mywust.data.physics.PhysicsCourse;
import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; import cn.wustlinghang.wusthelper.internal.physics.services.ParseService;
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
@ -27,23 +27,21 @@ public class CourseTableApi {
@GET @GET
@Path("/") @Path("/")
public List<Course> get(@QueryParam("cookie") @NotNull String cookie, public List<PhysicsCourse> get(@QueryParam("cookie") @NotNull String cookie)
@QueryParam("term") String term)
throws RpcException { throws RpcException {
return this.parse(this.agent(cookie, term)); return this.parse(this.agent(cookie));
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie, public String agent(@QueryParam("cookie") @NotNull String cookie)
@QueryParam("term") String term)
throws RpcException { throws RpcException {
return agentService.getCourseTable(cookie, term); return agentService.getCourseTable(cookie);
} }
@POST @POST
@Path("/parse") @Path("/parse")
public List<Course> parse(String html) throws RpcException { public List<PhysicsCourse> parse(String html) throws RpcException {
return parseService.parseCourseTable(html); return parseService.parseCourseTable(html);
} }
} }

@ -1,45 +0,0 @@
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.wusthelper.internal.physics.services.ParseService;
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
@Path("/credit_status")
@ApplicationScoped
public class CreditStatusApi {
private final RequestAgentService agentService;
private final ParseService parseService;
public CreditStatusApi(RequestAgentService agentService,
ParseService parseService) {
this.agentService = agentService;
this.parseService = parseService;
}
@GET
@Path("/")
public String get(@QueryParam("cookie") @NotNull String cookie)
throws RpcException {
String html = this.agent(cookie);
return this.parse(html);
}
@GET
@Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException {
return agentService.getCreditStatus(cookie);
}
@POST
@Path("/parse")
public String parse(String html) throws RpcException {
return parseService.parseCreditStatus(html);
}
}

@ -1,48 +0,0 @@
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService;
import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.util.List;
@Path("/exam_activities")
@ApplicationScoped
public class ExamActivitiesApi {
private final RequestAgentService agentService;
public ExamActivitiesApi(RequestAgentService agentService) {
this.agentService = agentService;
}
@GET
@Path("/")
public UndergradExamDelayApiService.ExamActivity[] get(
@QueryParam("cookie") @NotNull String cookie,
@QueryParam("term") @NotNull String term)
throws RpcException {
return this.agent(cookie, term);
}
@GET
@Path("/agent")
public UndergradExamDelayApiService.ExamActivity[] agent(
@QueryParam("cookie") @NotNull String cookie,
@QueryParam("term") @NotNull String term)
throws RpcException {
return agentService.getExamActivities(cookie, term);
}
@POST
@Path("/parse")
public List<Score> parse(String html) throws RpcException {
throw RpcException.ApiNotImplement();
}
}

@ -1,52 +0,0 @@
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import cn.wustlinghang.wusthelper.internal.physics.services.ParseService;
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import java.util.List;
@Path("/exam_delay_application")
@ApplicationScoped
public class ExamDelayApplicationApi {
private final RequestAgentService agentService;
private final ParseService parseService;
public ExamDelayApplicationApi(RequestAgentService agentService,
ParseService parseService) {
this.agentService = agentService;
this.parseService = parseService;
}
@GET
@Path("/")
public List<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);
}
}

@ -29,12 +29,12 @@ public class ScoreApi {
@Path("/") @Path("/")
public List<Score> get(@QueryParam("cookie") @NotNull String cookie) public List<Score> get(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return this.parse(this.agent(cookie)); return this.parseAll(this.agent(cookie));
} }
@GET @GET
@Path("/agent") @Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie) public List<String> agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException { throws RpcException {
return agentService.getScore(cookie); return agentService.getScore(cookie);
} }
@ -44,4 +44,10 @@ public class ScoreApi {
public List<Score> parse(String html) throws RpcException { public List<Score> parse(String html) throws RpcException {
return parseService.parseScore(html); return parseService.parseScore(html);
} }
@POST
@Path("/parse/all")
public List<Score> parseAll(List<String> pages) throws RpcException {
return parseService.parseAllScore(pages);
}
} }

@ -1,45 +0,0 @@
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import cn.wustlinghang.wusthelper.internal.physics.services.ParseService;
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
@Path("/student_info")
@ApplicationScoped
public class StudentInfoApi {
private final RequestAgentService agentService;
private final ParseService parseService;
public StudentInfoApi(RequestAgentService agentService,
ParseService parseService) {
this.agentService = agentService;
this.parseService = parseService;
}
@GET
@Path("/")
public StudentInfo get(@QueryParam("cookie") @NotNull String cookie)
throws RpcException {
return this.parse(this.agent(cookie));
}
@GET
@Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException {
return agentService.getStudentInfoPage(cookie);
}
@POST
@Path("/parse")
public StudentInfo parse(String html) throws RpcException {
return parseService.parseStudentInfo(html);
}
}

@ -1,44 +0,0 @@
package cn.wustlinghang.wusthelper.internal.physics.api.json;
import cn.wustlinghang.wusthelper.internal.physics.services.ParseService;
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
@Path("/training_plan")
@ApplicationScoped
public class TrainingPlanApi {
private final RequestAgentService agentService;
private final ParseService parseService;
public TrainingPlanApi(RequestAgentService agentService,
ParseService parseService) {
this.agentService = agentService;
this.parseService = parseService;
}
@GET
@Path("/")
public String get(@QueryParam("cookie") @NotNull String cookie)
throws RpcException {
return this.parse(this.agent(cookie));
}
@GET
@Path("/agent")
public String agent(@QueryParam("cookie") @NotNull String cookie)
throws RpcException {
return agentService.getTrainingPlan(cookie);
}
@POST
@Path("/parse")
public String parse(String html) throws RpcException {
return parseService.parseTrainingPlan(html);
}
}

@ -14,7 +14,7 @@ public class PhysicsRpcException extends RpcException {
typeCode.ordinal(), typeCode.ordinal(),
subModuleCode.ordinal() * 100 + errorCode.ordinal(), subModuleCode.ordinal() * 100 + errorCode.ordinal(),
new StringJoiner("-") new StringJoiner("-")
.add("UNDERGRAD") .add("PHYSICS")
.add(typeCode.name()) .add(typeCode.name())
.add(subModuleCode.name()) .add(subModuleCode.name())
.add(errorCode.name()) .add(errorCode.name())
@ -56,6 +56,8 @@ public class PhysicsRpcException extends RpcException {
PARSE_ERROR, PARSE_ERROR,
AUTH_PASSWORD_WRONG, AUTH_PASSWORD_WRONG,
AUTH_UNKNOWN_ERROR AUTH_UNKNOWN_ERROR,
AUTH_USER_NOT_CURRENT_TERM
} }
} }

@ -1,7 +1,8 @@
package cn.wustlinghang.wusthelper.internal.physics.services; package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.core.request.service.auth.UndergraduateLogin; import cn.wustlinghang.mywust.core.request.service.auth.PhysicsLogin;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.RequestClientOption; import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
@ -13,21 +14,18 @@ import java.io.IOException;
@ApplicationScoped @ApplicationScoped
public class LoginService { public class LoginService {
private final RequestClientOption option; private final RequestClientOption option;
private final UndergraduateLogin undergraduateLogin;
private final PhysicsLogin physicsLogin;
public LoginService(RequestClientOption option, public LoginService(RequestClientOption option,
UndergraduateLogin undergraduateLogin) { PhysicsLogin physicsLogin) {
this.option = option; this.option = option;
this.undergraduateLogin = undergraduateLogin; this.physicsLogin = physicsLogin;
} }
public String login(String username, String password, boolean legacy) throws PhysicsRpcException { public String login(String username, String password) throws PhysicsRpcException {
try { try {
if (legacy) { return physicsLogin.getLoginCookie(username, password, option);
return undergraduateLogin.getLoginCookieLegacy(username, password, option);
} else {
return undergraduateLogin.getLoginCookie(username, password, option);
}
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
@ -36,12 +34,19 @@ public class LoginService {
PhysicsRpcException.SubModuleCode.AUTH, PhysicsRpcException.SubModuleCode.AUTH,
PhysicsRpcException.ErrorCode.NETWORK_ERROR PhysicsRpcException.ErrorCode.NETWORK_ERROR
); );
} catch (ParseException e) {
log.error("物理实验:登录时出现页面参数解析问题", e);
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.AUTH,
PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR
);
} }
} }
public boolean verify(String cookie) throws PhysicsRpcException { public boolean verify(String cookie) throws PhysicsRpcException {
try { try {
return !undergraduateLogin.checkCookiesFail(cookie); return physicsLogin.checkCookie(cookie, option);
} catch (IOException e) { } catch (IOException e) {
throw new PhysicsRpcException( throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
@ -54,16 +59,10 @@ public class LoginService {
private PhysicsRpcException wrapApiException(ApiException e) { private PhysicsRpcException wrapApiException(ApiException e) {
PhysicsRpcException.ErrorCode errorCode = switch (e.getCode()) { PhysicsRpcException.ErrorCode errorCode = switch (e.getCode()) {
case NETWORK_EXCEPTION -> PhysicsRpcException.ErrorCode.NETWORK_ERROR; case NETWORK_EXCEPTION -> PhysicsRpcException.ErrorCode.NETWORK_ERROR;
case UNI_LOGIN_PASSWORD_WRONG -> PhysicsRpcException.ErrorCode.AUTH_PASSWORD_WRONG; case PHYSICS_PASSWORD_WRONG -> PhysicsRpcException.ErrorCode.AUTH_PASSWORD_WRONG;
case UNI_LOGIN_USER_NOT_EXISTS -> PhysicsRpcException.ErrorCode.AUTH_USER_NOT_EXISTS; case PHYSICS_NOT_CURRENT_TERM -> PhysicsRpcException.ErrorCode.AUTH_USER_NOT_CURRENT_TERM;
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 -> { default -> {
log.error("本科生:登录代理请求异常,异常未处理"); log.error("物理实验:登录代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; yield PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR;
} }

@ -1,20 +1,26 @@
package cn.wustlinghang.wusthelper.internal.physics.services; package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser; import cn.wustlinghang.mywust.core.parser.physics.PhysicsCoursePageParser;
import cn.wustlinghang.mywust.data.global.Course; import cn.wustlinghang.mywust.core.parser.physics.PhysicsScorePageParser;
import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import cn.wustlinghang.mywust.data.physics.PhysicsCourse; 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.internal.physics.exception.PhysicsRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@ApplicationScoped @ApplicationScoped
public class ParseService { public class ParseService {
private final PhysicsCoursePageParser coursePageParser; private final PhysicsCoursePageParser coursePageParser;
private final PhysicsScorePageParser scorePageParser;
public ParseService(PhysicsCoursePageParser coursePageParser,
PhysicsScorePageParser scorePageParser) {
this.coursePageParser = coursePageParser;
this.scorePageParser = scorePageParser;
}
public List<PhysicsCourse> parseCourseTable(String data) throws PhysicsRpcException { public List<PhysicsCourse> parseCourseTable(String data) throws PhysicsRpcException {
try { try {
@ -30,16 +36,7 @@ public class ParseService {
public List<Score> parseScore(String data) throws RpcException { public List<Score> parseScore(String data) throws RpcException {
try { try {
if (data.contains("评教")) { return scorePageParser.parse(data);
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.NEED_EVALUATE
);
}
return scoreParser.parse(data);
} catch (PhysicsRpcException e) { } catch (PhysicsRpcException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
@ -51,49 +48,20 @@ public class ParseService {
} }
} }
public StudentInfo parseStudentInfo(String data) throws RpcException { public List<Score> parseAllScore(List<String> pages) throws RpcException {
try { try {
return studentInfoPageParser.parse(data); List<Score> scores = new ArrayList<>();
} catch (Exception e) { for (String page : pages) {
throw new PhysicsRpcException( scores.addAll(scorePageParser.parse(page));
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.STUDENT_INFO,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
} }
public String parseTrainingPlan(String data) throws RpcException { return scores;
try { } catch (PhysicsRpcException e) {
return trainingPlanPageParser.parse(data); throw e;
} 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) { } catch (Exception e) {
throw new PhysicsRpcException( throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.PARSE_EXCEPTION, PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION, PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR PhysicsRpcException.ErrorCode.PARSE_ERROR
); );
} }

@ -1,7 +1,9 @@
package cn.wustlinghang.wusthelper.internal.physics.services; package cn.wustlinghang.wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.core.request.service.undergraduate.*; import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiService;
import cn.wustlinghang.mywust.core.request.service.physics.PhysicsScoreApiService;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.RequestClientOption; import cn.wustlinghang.mywust.network.RequestClientOption;
import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException; import cn.wustlinghang.wusthelper.internal.physics.exception.PhysicsRpcException;
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; import cn.wustlinghang.wusthelper.rpc.exception.RpcException;
@ -9,54 +11,29 @@ import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.io.IOException; import java.io.IOException;
import java.util.List;
@Slf4j @Slf4j
@ApplicationScoped @ApplicationScoped
public class RequestAgentService { 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; private final RequestClientOption requestClientOption;
public RequestAgentService(UndergradCourseTableApiService courseTableApiService, private final PhysicsCourseApiService physicsCourseApiService;
UndergradScoreApiService scoreApiService, private final PhysicsScoreApiService physicsScoreApiService;
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;
public RequestAgentService(RequestClientOption requestClientOption,
PhysicsCourseApiService physicsCourseApiService,
PhysicsScoreApiService physicsScoreApiService) {
this.requestClientOption = requestClientOption; this.requestClientOption = requestClientOption;
}
public String getStudentInfoPage(String cookie) throws RpcException { this.physicsCourseApiService = physicsCourseApiService;
try { this.physicsScoreApiService = physicsScoreApiService;
return studentInfoApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.STUDENT_INFO);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.STUDENT_INFO,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
} }
public String getCourseTable(String cookie, String term) throws RpcException { public String getCourseTable(String cookie) throws RpcException {
try { try {
return courseTableApiService.getPage(term, cookie); return physicsCourseApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE); throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE);
} catch (IOException e) { } catch (IOException e) {
@ -68,9 +45,9 @@ public class RequestAgentService {
} }
} }
public String getScore(String cookie) throws RpcException { public List<String> getScore(String cookie) throws RpcException {
try { try {
return scoreApiService.getPage(cookie); return physicsScoreApiService.getAllPages(cookie, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE); throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE);
} catch (IOException e) { } catch (IOException e) {
@ -79,63 +56,11 @@ public class RequestAgentService {
PhysicsRpcException.SubModuleCode.SCORE, PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR PhysicsRpcException.ErrorCode.NETWORK_ERROR
); );
} } catch (ParseException e) {
}
public String getTrainingPlan(String cookie) throws RpcException {
try {
return trainingPlanApiService.getPage(cookie);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.TRAINING_PLAN);
} catch (IOException e) {
throw new PhysicsRpcException( throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, PhysicsRpcException.TypeCode.OTHER_EXCEPTION,
PhysicsRpcException.SubModuleCode.TRAINING_PLAN, PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR PhysicsRpcException.ErrorCode.PARSE_ERROR
);
}
}
public String getCreditStatus(String cookie) throws RpcException {
try {
return creditStatusApiService.getPage(cookie, requestClientOption, false);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.CREDIT_STATUS);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.CREDIT_STATUS,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public UndergradExamDelayApiService.ExamActivity[] getExamActivities(String cookie, String term)
throws RpcException {
try {
return examDelayApiService.getActivities(term, cookie);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.EXAM_ACTIVITIES);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.EXAM_ACTIVITIES,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
}
}
public String getExamDelayApplications(String cookie, String term, String activityId)
throws RpcException {
try {
return examDelayApiService.getPage(term, activityId, cookie);
} catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION);
} catch (IOException e) {
throw new PhysicsRpcException(
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
); );
} }
} }
@ -153,7 +78,7 @@ public class RequestAgentService {
PhysicsRpcException.ErrorCode.COOKIE_INVALID PhysicsRpcException.ErrorCode.COOKIE_INVALID
); );
default -> { default -> {
log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name());
log.error("异常:", e); log.error("异常:", e);
yield new PhysicsRpcException( yield new PhysicsRpcException(
PhysicsRpcException.TypeCode.AUTH_EXCEPTION, PhysicsRpcException.TypeCode.AUTH_EXCEPTION,

Loading…
Cancel
Save