parent
4974bb14f1
commit
c792263bed
@ -1 +1 @@ |
|||||||
Subproject commit 4b32c584249bffec4767d4b6a075af842127d5d2 |
Subproject commit b7c61453c566c9879314e881648cdb34bf90aaa9 |
@ -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,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.ResponseCode; |
||||||
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.ws.rs.core.Response; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.ws.rs.core.Response; |
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.mywust.exception.ParseException; |
||||||
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
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 cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.ws.rs.core.Response; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.validation.ValidationException; |
import jakarta.validation.ValidationException; |
@ -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 cn.wustlinghang.wusthelper.rpc.response.RpcResponse; |
||||||
import com.fasterxml.jackson.databind.ObjectMapper; |
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
import jakarta.ws.rs.WebApplicationException; |
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 com.fasterxml.jackson.databind.ObjectMapper; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
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); |
||||||
|
} |
||||||
|
} |
@ -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.level=DEBUG |
||||||
quarkus.log.file.encoding=UTF-8 |
quarkus.log.file.encoding=UTF-8 |
||||||
|
|
||||||
|
ocr.service.provider=http://ocr.ciduid.top |
||||||
|
|
||||||
|
graduate.max-retry-times=4 |
||||||
|
|
||||||
# 打包成jar时附带依赖 |
# 打包成jar时附带依赖 |
||||||
quarkus.package.type=uber-jar |
quarkus.package.type=uber-jar |
||||||
|
|
||||||
# 原生镜像编译附加参数,去掉后编译会失败 |
# 原生镜像编译附加参数,去掉后编译会失败 |
||||||
# 但也只是能编译完成,目前的编译产物完全不可用,有非常多的严重bug |
# 但也只是能编译完成,目前的编译产物完全不可用,有非常多的严重bug |
||||||
# 现阶段使用jar运行,启动效率虽不如原生程序,但速度尚可 |
# 现阶段使用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 io.quarkus.runtime.Startup; |
||||||
import jakarta.annotation.PostConstruct; |
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 cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.validation.constraints.NotNull; |
import jakarta.validation.constraints.NotNull; |
||||||
import jakarta.ws.rs.GET; |
import jakarta.ws.rs.GET; |
||||||
import jakarta.ws.rs.Path; |
import jakarta.ws.rs.Path; |
||||||
import jakarta.ws.rs.QueryParam; |
import jakarta.ws.rs.QueryParam; |
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
@Path("/cookie") |
@Path("/cookie") |
||||||
public class CookieApi { |
public class CookieApi { |
||||||
private final LoginService loginService; |
private final LoginService loginService; |
@ -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.core.request.service.undergraduate.UndergradExamDelayApiService; |
||||||
import cn.wustlinghang.mywust.data.global.Score; |
import cn.wustlinghang.mywust.data.global.Score; |
||||||
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; |
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService; |
||||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
import jakarta.enterprise.context.ApplicationScoped; |
||||||
import jakarta.validation.constraints.NotNull; |
import jakarta.validation.constraints.NotNull; |
@ -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.mywust.data.undergrad.ExamDelayApplication; |
||||||
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; |
import cn.wustlinghang.wusthelper.internal.library.services.ParseService; |
||||||
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; |
import cn.wustlinghang.wusthelper.internal.library.services.RequestAgentService; |
||||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
import jakarta.enterprise.context.ApplicationScoped; |
||||||
import jakarta.validation.constraints.NotNull; |
import jakarta.validation.constraints.NotNull; |
@ -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.ResponseCode; |
||||||
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.ws.rs.core.Response; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.ws.rs.core.Response; |
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.mywust.exception.ParseException; |
||||||
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
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 cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.ws.rs.core.Response; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.validation.ValidationException; |
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 cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.ws.rs.WebApplicationException; |
import jakarta.ws.rs.WebApplicationException; |
||||||
import jakarta.ws.rs.core.Response; |
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 cn.wustlinghang.wusthelper.rpc.response.RpcResponse; |
||||||
import com.fasterxml.jackson.databind.ObjectMapper; |
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
import jakarta.ws.rs.WebApplicationException; |
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 com.fasterxml.jackson.databind.ObjectMapper; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
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 cn.wustlinghang.mywust.core.parser.undergraduate.*; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
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.auth.UndergraduateLogin; |
||||||
import cn.wustlinghang.mywust.core.request.service.undergraduate.*; |
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; |
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.core.request.service.auth.UndergraduateLogin; |
||||||
import cn.wustlinghang.mywust.exception.ApiException; |
import cn.wustlinghang.mywust.exception.ApiException; |
||||||
import cn.wustlinghang.mywust.network.RequestClientOption; |
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 jakarta.enterprise.context.ApplicationScoped; |
||||||
import lombok.extern.slf4j.Slf4j; |
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.core.parser.undergraduate.*; |
||||||
import cn.wustlinghang.mywust.data.global.Course; |
import cn.wustlinghang.mywust.data.global.Course; |
||||||
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.global.StudentInfo; |
||||||
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; |
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; |
||||||
import cn.wustlinghang.mywust.exception.ParseException; |
import cn.wustlinghang.wusthelper.internal.library.exception.UndergradRpcException; |
||||||
import cn.wustlinghang.wusthelper.internal.undergrad.exception.UndergradRpcException; |
|
||||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
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.core.request.service.undergraduate.*; |
||||||
import cn.wustlinghang.mywust.exception.ApiException; |
import cn.wustlinghang.mywust.exception.ApiException; |
||||||
import cn.wustlinghang.mywust.network.RequestClientOption; |
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 cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
import jakarta.enterprise.context.ApplicationScoped; |
||||||
import lombok.extern.slf4j.Slf4j; |
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 @@ |
|||||||
package cn.wustlinghang.wusthelper.internal.undergrad; |
package cn.wustlinghang.wusthelper.internal.physics; |
||||||
|
|
||||||
import io.quarkus.runtime.Startup; |
import io.quarkus.runtime.Startup; |
||||||
import jakarta.annotation.PostConstruct; |
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 cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.validation.constraints.NotNull; |
import jakarta.validation.constraints.NotNull; |
||||||
import jakarta.ws.rs.GET; |
import jakarta.ws.rs.GET; |
||||||
import jakarta.ws.rs.Path; |
import jakarta.ws.rs.Path; |
||||||
import jakarta.ws.rs.QueryParam; |
import jakarta.ws.rs.QueryParam; |
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
@Path("/cookie") |
@Path("/cookie") |
||||||
public class CookieApi { |
public class CookieApi { |
||||||
private final LoginService loginService; |
private final LoginService loginService; |
@ -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.core.request.service.undergraduate.UndergradExamDelayApiService; |
||||||
import cn.wustlinghang.mywust.data.global.Score; |
import cn.wustlinghang.mywust.data.global.Score; |
||||||
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; |
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; |
||||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
import jakarta.enterprise.context.ApplicationScoped; |
||||||
import jakarta.validation.constraints.NotNull; |
import jakarta.validation.constraints.NotNull; |
@ -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.mywust.data.undergrad.ExamDelayApplication; |
||||||
import cn.wustlinghang.wusthelper.internal.undergrad.services.ParseService; |
import cn.wustlinghang.wusthelper.internal.physics.services.ParseService; |
||||||
import cn.wustlinghang.wusthelper.internal.undergrad.services.RequestAgentService; |
import cn.wustlinghang.wusthelper.internal.physics.services.RequestAgentService; |
||||||
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
import cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
import jakarta.enterprise.context.ApplicationScoped; |
||||||
import jakarta.validation.constraints.NotNull; |
import jakarta.validation.constraints.NotNull; |
@ -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.ResponseCode; |
||||||
import cn.wustlinghang.wusthelper.rpc.response.RpcResponse; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.ws.rs.core.Response; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.ws.rs.core.Response; |
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.mywust.exception.ParseException; |
||||||
import cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
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 cn.wustlinghang.wusthelper.rpc.exception.RpcException; |
||||||
import jakarta.ws.rs.core.Response; |
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 cn.wustlinghang.wusthelper.rpc.response.ResponseCode; |
||||||
import jakarta.validation.ValidationException; |
import jakarta.validation.ValidationException; |
@ -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 cn.wustlinghang.wusthelper.rpc.response.RpcResponse; |
||||||
import com.fasterxml.jackson.databind.ObjectMapper; |
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
import jakarta.ws.rs.WebApplicationException; |
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 com.fasterxml.jackson.databind.ObjectMapper; |
||||||
import jakarta.enterprise.context.ApplicationScoped; |
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); |
||||||
|
} |
||||||
|
} |
@ -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,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 |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue