|
|
|
@ -2,10 +2,15 @@ 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; |
|
|
|
@ -15,12 +20,15 @@ public class RequestAgentService { |
|
|
|
|
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) { |
|
|
|
|
UndergradExamDelayApiService examDelayApiService, |
|
|
|
|
RequestClientOption requestClientOption) { |
|
|
|
|
|
|
|
|
|
this.courseTableApiService = courseTableApiService; |
|
|
|
|
this.scoreApiService = scoreApiService; |
|
|
|
@ -28,35 +36,131 @@ public class RequestAgentService { |
|
|
|
|
this.trainingPlanApiService = trainingPlanApiService; |
|
|
|
|
this.creditStatusApiService = creditStatusApiService; |
|
|
|
|
this.examDelayApiService = examDelayApiService; |
|
|
|
|
|
|
|
|
|
this.requestClientOption = requestClientOption; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String getStudentInfoPage(String cookie) throws IOException, ApiException { |
|
|
|
|
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 IOException, ApiException { |
|
|
|
|
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 IOException, ApiException { |
|
|
|
|
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 IOException, ApiException { |
|
|
|
|
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 IOException, ApiException { |
|
|
|
|
return creditStatusApiService.getPage(cookie, null, false); |
|
|
|
|
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 IOException, ApiException { |
|
|
|
|
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 IOException, ApiException { |
|
|
|
|
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 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|