parent
166efc7f1b
commit
3d7f498ca0
@ -0,0 +1,32 @@ |
||||
package cn.wustlinghang.wusthelper.internal.graduate.services; |
||||
|
||||
import cn.wustlinghang.mywust.exception.ApiException; |
||||
import cn.wustlinghang.wusthelper.internal.graduate.exception.GraduateRpcException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
@Slf4j |
||||
public abstract class BaseService { |
||||
protected 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 |
||||
); |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,57 @@ |
||||
package cn.wustlinghang.wusthelper.internal.graduate.services; |
||||
|
||||
import cn.wustlinghang.mywust.core.parser.graduate.GraduateCourseTableParser; |
||||
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateCourseTableApiService; |
||||
import cn.wustlinghang.mywust.data.global.Course; |
||||
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 java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
@ApplicationScoped |
||||
public class CourseTableService extends BaseService { |
||||
|
||||
private final RequestClientOption requestClientOption; |
||||
|
||||
private final GraduateCourseTableApiService courseTableApiService; |
||||
private final GraduateCourseTableParser courseTableParser; |
||||
|
||||
public CourseTableService(RequestClientOption requestClientOption, |
||||
GraduateCourseTableApiService courseTableApiService, |
||||
GraduateCourseTableParser courseTableParser) { |
||||
this.requestClientOption = requestClientOption; |
||||
|
||||
this.courseTableApiService = courseTableApiService; |
||||
this.courseTableParser = courseTableParser; |
||||
} |
||||
|
||||
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 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 |
||||
); |
||||
} |
||||
} |
||||
} |
@ -1,83 +0,0 @@ |
||||
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 |
||||
); |
||||
} |
||||
} |
||||
} |
@ -1,122 +0,0 @@ |
||||
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 |
||||
); |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,57 @@ |
||||
package cn.wustlinghang.wusthelper.internal.graduate.services; |
||||
|
||||
import cn.wustlinghang.mywust.core.parser.graduate.GraduateScoreParser; |
||||
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateScoreApiService; |
||||
import cn.wustlinghang.mywust.data.global.Score; |
||||
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 java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
@ApplicationScoped |
||||
public class ScoreService extends BaseService { |
||||
|
||||
private final RequestClientOption requestClientOption; |
||||
|
||||
private final GraduateScoreApiService scoreApiService; |
||||
private final GraduateScoreParser scoreParser; |
||||
|
||||
public ScoreService(RequestClientOption requestClientOption, |
||||
GraduateScoreApiService scoreApiService, |
||||
GraduateScoreParser scoreParser) { |
||||
this.requestClientOption = requestClientOption; |
||||
|
||||
this.scoreApiService = scoreApiService; |
||||
this.scoreParser = scoreParser; |
||||
} |
||||
|
||||
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 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 |
||||
); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,56 @@ |
||||
package cn.wustlinghang.wusthelper.internal.graduate.services; |
||||
|
||||
import cn.wustlinghang.mywust.core.parser.graduate.GraduateStudentInfoPageParser; |
||||
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateStudentInfoApiService; |
||||
import cn.wustlinghang.mywust.data.global.StudentInfo; |
||||
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 java.io.IOException; |
||||
|
||||
@ApplicationScoped |
||||
public class StudentInfoService extends BaseService { |
||||
|
||||
private final RequestClientOption requestClientOption; |
||||
|
||||
private final GraduateStudentInfoApiService studentInfoApiService; |
||||
private final GraduateStudentInfoPageParser studentInfoPageParser; |
||||
|
||||
public StudentInfoService(RequestClientOption requestClientOption, |
||||
GraduateStudentInfoApiService studentInfoApiService, |
||||
GraduateStudentInfoPageParser studentInfoPageParser) { |
||||
this.requestClientOption = requestClientOption; |
||||
|
||||
this.studentInfoApiService = studentInfoApiService; |
||||
this.studentInfoPageParser = studentInfoPageParser; |
||||
} |
||||
|
||||
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 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 |
||||
); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
package cn.wustlinghang.wusthelper.internal.graduate.services; |
||||
|
||||
import cn.wustlinghang.mywust.core.parser.graduate.GraduateTrainingPlanPageParser; |
||||
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateTrainingPlanApiService; |
||||
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 java.io.IOException; |
||||
|
||||
@ApplicationScoped |
||||
public class TrainingPlanService extends BaseService { |
||||
|
||||
private final RequestClientOption requestClientOption; |
||||
|
||||
private final GraduateTrainingPlanApiService trainingPlanApiService; |
||||
private final GraduateTrainingPlanPageParser trainingPlanPageParser; |
||||
|
||||
public TrainingPlanService(RequestClientOption requestClientOption, |
||||
GraduateTrainingPlanApiService trainingPlanApiService, |
||||
GraduateTrainingPlanPageParser trainingPlanPageParser) { |
||||
this.requestClientOption = requestClientOption; |
||||
|
||||
this.trainingPlanApiService = trainingPlanApiService; |
||||
this.trainingPlanPageParser = trainingPlanPageParser; |
||||
} |
||||
|
||||
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 |
||||
); |
||||
} |
||||
} |
||||
|
||||
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 |
||||
); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue