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