lensfrex 1 year ago
parent d714db0891
commit eb93192a7b
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 7
      .idea/inspectionProfiles/Project_Default.xml
  2. 13
      backend-main/backend-web/pom.xml
  3. 8
      backend-main/backend-web/src/main/java/wusthelper/WebBackendMain.java
  4. 2
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/TokenTool.java
  5. 12
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/CombineLoginResponse.java
  6. 55
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/CourseResponse.java
  7. 128
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/ScoreResponse.java
  8. 31
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/StudentInfoResponse.java
  9. 127
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/handler/GlobalExceptionHandler.java
  10. 114
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/undergrade/UndergradController.java
  11. 76
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/undergrade/UndergradLoginController.java
  12. 5
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/undergrade/UndergradController.java
  13. 28
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/undergrade/UndergradLoginController.java
  14. 2
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/graduate/GraduateCookieRemote.java
  15. 2
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/graduate/GraduateStudentInfoRemote.java
  16. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/undergrad/CourseTableRemote.java
  17. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/undergrad/CreditStatusRemote.java
  18. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/undergrad/ExamDelayApplicationRemote.java
  19. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/undergrad/ScoreRemote.java
  20. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/undergrad/TrainingPlanRemote.java
  21. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/undergrad/UndergradCookieRemote.java
  22. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/undergrad/UndergradStudentInfoRemote.java
  23. 2
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/graduate/GraduateCookieService.java
  24. 2
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/graduate/GraduateStudentInfoService.java
  25. 3
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/ExamDelayApplicationService.java
  26. 2
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradCookieService.java
  27. 7
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradCourseTableService.java
  28. 7
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradCreditStatusService.java
  29. 7
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradScoreService.java
  30. 13
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradStudentInfoService.java
  31. 7
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradTrainingPlanService.java
  32. 4
      backend-main/backend-web/src/main/java/wusthelper/web/service/cookie/CookieManager.java
  33. 86
      backend-main/backend-web/src/main/java/wusthelper/web/util/StringUtil.java
  34. 6
      backend-main/backend-web/src/main/resources/application.yml
  35. 14
      backend-main/backend-web/src/test/java/wusthelper/TestMain.java
  36. 14
      common/src/main/java/wusthelper/code/ServiceCode.java
  37. 62
      common/src/main/java/wusthelper/internal/rpc/exception/GraduateRpcException.java
  38. 68
      common/src/main/java/wusthelper/internal/rpc/exception/LibraryRpcException.java
  39. 59
      common/src/main/java/wusthelper/internal/rpc/exception/PhysicsRpcException.java
  40. 28
      common/src/main/java/wusthelper/internal/rpc/exception/RpcException.java
  41. 71
      common/src/main/java/wusthelper/internal/rpc/exception/UndergradRpcException.java
  42. 31
      common/src/main/java/wusthelper/internal/rpc/response/RpcCommonResponseCode.java
  43. 9
      common/src/main/java/wusthelper/internal/rpc/response/RpcResponseDto.java
  44. 2
      common/src/main/java/wusthelper/web/exception/ServiceException.java
  45. 22
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/api/http/v1/handler/BaseExceptionHandler.java
  46. 10
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/api/http/v1/handler/DefaultExceptionHandler.java
  47. 10
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/api/http/v1/handler/IOExceptionHandler.java
  48. 10
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/api/http/v1/handler/ParseExceptionHandler.java
  49. 12
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/api/http/v1/handler/RpcExceptionHandler.java
  50. 10
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/api/http/v1/handler/ValidationExceptionHandler.java
  51. 17
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/api/http/v1/handler/WebApplicationExceptionHandler.java
  52. 25
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/services/BaseService.java
  53. 20
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/services/CourseTableService.java
  54. 43
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/services/LoginService.java
  55. 20
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/services/ScoreService.java
  56. 20
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/services/StudentInfoService.java
  57. 18
      sub-services/graduate/src/main/java/wusthelper/internal/graduate/services/TrainingPlanService.java
  58. 22
      sub-services/library/src/main/java/wusthelper/internal/library/api/http/v1/handler/BaseExceptionHandler.java
  59. 10
      sub-services/library/src/main/java/wusthelper/internal/library/api/http/v1/handler/DefaultExceptionHandler.java
  60. 10
      sub-services/library/src/main/java/wusthelper/internal/library/api/http/v1/handler/IOExceptionHandler.java
  61. 10
      sub-services/library/src/main/java/wusthelper/internal/library/api/http/v1/handler/ParseExceptionHandler.java
  62. 12
      sub-services/library/src/main/java/wusthelper/internal/library/api/http/v1/handler/RpcExceptionHandler.java
  63. 10
      sub-services/library/src/main/java/wusthelper/internal/library/api/http/v1/handler/ValidationExceptionHandler.java
  64. 17
      sub-services/library/src/main/java/wusthelper/internal/library/api/http/v1/handler/WebApplicationExceptionHandler.java
  65. 25
      sub-services/library/src/main/java/wusthelper/internal/library/services/BaseService.java
  66. 20
      sub-services/library/src/main/java/wusthelper/internal/library/services/BookCoverImageUrlService.java
  67. 12
      sub-services/library/src/main/java/wusthelper/internal/library/services/BookDetailService.java
  68. 16
      sub-services/library/src/main/java/wusthelper/internal/library/services/BookHoldingService.java
  69. 18
      sub-services/library/src/main/java/wusthelper/internal/library/services/CurrentLoanService.java
  70. 18
      sub-services/library/src/main/java/wusthelper/internal/library/services/LoanHistoryService.java
  71. 47
      sub-services/library/src/main/java/wusthelper/internal/library/services/LoginService.java
  72. 18
      sub-services/library/src/main/java/wusthelper/internal/library/services/OverdueSoonService.java
  73. 18
      sub-services/library/src/main/java/wusthelper/internal/library/services/SearchService.java
  74. 22
      sub-services/physics/src/main/java/wusthelper/internal/physics/api/http/v1/handler/BaseExceptionHandler.java
  75. 10
      sub-services/physics/src/main/java/wusthelper/internal/physics/api/http/v1/handler/DefaultExceptionHandler.java
  76. 10
      sub-services/physics/src/main/java/wusthelper/internal/physics/api/http/v1/handler/IOExceptionHandler.java
  77. 10
      sub-services/physics/src/main/java/wusthelper/internal/physics/api/http/v1/handler/ParseExceptionHandler.java
  78. 12
      sub-services/physics/src/main/java/wusthelper/internal/physics/api/http/v1/handler/RpcExceptionHandler.java
  79. 10
      sub-services/physics/src/main/java/wusthelper/internal/physics/api/http/v1/handler/ValidationExceptionHandler.java
  80. 17
      sub-services/physics/src/main/java/wusthelper/internal/physics/api/http/v1/handler/WebApplicationExceptionHandler.java
  81. 25
      sub-services/physics/src/main/java/wusthelper/internal/physics/services/BaseService.java
  82. 20
      sub-services/physics/src/main/java/wusthelper/internal/physics/services/CourseTableService.java
  83. 43
      sub-services/physics/src/main/java/wusthelper/internal/physics/services/LoginService.java
  84. 34
      sub-services/physics/src/main/java/wusthelper/internal/physics/services/ScoreService.java
  85. 20
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/api/http/v1/handler/BaseExceptionHandler.java
  86. 10
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/api/http/v1/handler/DefaultExceptionHandler.java
  87. 10
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/api/http/v1/handler/IOExceptionHandler.java
  88. 10
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/api/http/v1/handler/ParseExceptionHandler.java
  89. 12
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/api/http/v1/handler/RpcExceptionHandler.java
  90. 10
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/api/http/v1/handler/ValidationExceptionHandler.java
  91. 17
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/api/http/v1/handler/WebApplicationExceptionHandler.java
  92. 3
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/api/http/v1/interceptor/ResponseWrapperInterceptor.java
  93. 1
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/rpc/Register.java
  94. 25
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/services/BaseService.java
  95. 29
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/services/CourseTableService.java
  96. 22
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/services/CreditStatusService.java
  97. 13
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/services/ExamActivitiesService.java
  98. 19
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/services/ExamDelayApplicationService.java
  99. 47
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/services/LoginService.java
  100. 25
      sub-services/undergrad/src/main/java/wusthelper/internal/undergrad/services/ScoreService.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -32,5 +32,12 @@
</list> </list>
</option> </option>
</inspection_tool> </inspection_tool>
<inspection_tool class="IncorrectHttpHeaderInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="customHeaders">
<set>
<option value="Token" />
</set>
</option>
</inspection_tool>
</profile> </profile>
</component> </component>

@ -40,6 +40,11 @@
<artifactId>spring-cloud-starter-openfeign</artifactId> <artifactId>spring-cloud-starter-openfeign</artifactId>
<version>${feign.version}</version> <version>${feign.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>cn.wustlinghang.wusthelper</groupId> <groupId>cn.wustlinghang.wusthelper</groupId>
@ -64,10 +69,10 @@
<build> <build>
<plugins> <plugins>
<plugin> <!-- <plugin>-->
<groupId>org.graalvm.buildtools</groupId> <!-- <groupId>org.graalvm.buildtools</groupId>-->
<artifactId>native-maven-plugin</artifactId> <!-- <artifactId>native-maven-plugin</artifactId>-->
</plugin> <!-- </plugin>-->
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>

@ -9,13 +9,13 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableAsync @EnableAsync
@EnableScheduling @EnableScheduling
@EnableFeignClients(basePackages = {"cn.wustlinghang.wusthelper.web.rpc"}) @EnableFeignClients(basePackages = {"wusthelper.web.rpc"})
@SpringBootApplication(scanBasePackages = { @SpringBootApplication(scanBasePackages = {
// 指定springboot的bean扫描路径,有新增请及时更新 // 指定springboot的bean扫描路径,有新增请及时更新
"cn.wustlinghang.wusthelper.data", "wusthelper.data",
"cn.wustlinghang.wusthelper.web", "wusthelper.web",
}) })
@MapperScan("cn.wustlinghang.wusthelper.data.dao.mapper") @MapperScan("wusthelper.data.dao.mapper")
public class WebBackendMain { public class WebBackendMain {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(WebBackendMain.class); SpringApplication.run(WebBackendMain.class);

@ -9,7 +9,7 @@ import java.time.Duration;
import java.util.Date; import java.util.Date;
@Slf4j @Slf4j
public class Token { public class TokenTool {
private final static String SECRET = "LingHangStudio.WustHelper"; private final static String SECRET = "LingHangStudio.WustHelper";

@ -0,0 +1,12 @@
package wusthelper.web.api.v2.dto.response;
import cn.wustlinghang.mywust.data.global.Course;
import java.util.List;
public record CombineLoginResponse(
String token,
List<CourseResponse> courses,
StudentInfoResponse studentInfoResponse
) {
}

@ -0,0 +1,55 @@
package wusthelper.web.api.v2.dto.response;
import cn.wustlinghang.mywust.data.global.Course;
import lombok.Data;
@Data
public class CourseResponse {
/**
* 课程名称
*/
private String className;
/**
* 教学班
*/
private String teachClass;
/**
* 教师
*/
private String teacher;
/**
* 开始周次
*/
private Integer startWeek;
/**
* 结束周
*/
private Integer endWeek;
/**
* 节数
*/
private Integer section;
/**
* 星期
*/
private Integer weekDay;
/**
* 教室
*/
private String classroom;
public static CourseResponse from(Course course) {
CourseResponse courseResponse = new CourseResponse();
courseResponse.setClassName(course.getName());
courseResponse.setTeachClass(course.getTeachClass());
courseResponse.setTeacher(course.getTeacher());
courseResponse.setStartWeek(course.getStartWeek());
courseResponse.setEndWeek(course.getEndWeek());
courseResponse.setSection((course.getStartSection() + 1) / 2);
courseResponse.setWeekDay(course.getWeekDay());
courseResponse.setClassroom(course.getClassroom().getRoom());
return courseResponse;
}
}

@ -0,0 +1,128 @@
package wusthelper.web.api.v2.dto.response;
import cn.wustlinghang.mywust.data.global.Score;
import lombok.Data;
import wusthelper.web.util.StringUtil;
@Data
public class ScoreResponse {
/**
* 课程编号
*/
private String courseNum;
/**
* 课程名称
*/
private String courseName;
/**
* 成绩
*/
private String grade;
/**
* 学分
*/
private Float courseCredit;
/**
* 总学时
*/
private Float courseHours;
/**
* 绩点
*/
private Float gradePoint;
/**
* 考核方式
*/
private String evaluationMode;
/**
* 考试性质
*/
private String examNature;
/**
* 课程性质
*/
private String courseNature;
/**
* 开课学期
*/
private String schoolTerm;
/**
* 重修标记 0--未重修 1--重修
*/
private Integer rebuildTag;
/**
* 补考标记 0--正常考试 1--补考
*/
private Integer reExamTag;
/**
* 缺考/缓考标记 0--正常 1--缺考 2--缓考
*/
private Integer missExamTag;
public static ScoreResponse from(Score score) {
ScoreResponse scoreResponse = new ScoreResponse();
scoreResponse.setCourseNum(score.getCourseName());
scoreResponse.setCourseName(score.getCourseName());
scoreResponse.setGrade(score.getScore());
//学分
if ("".equals(score.getCredit())) {
scoreResponse.setCourseCredit(0.0F);
} else {
scoreResponse.setCourseCredit(Float.parseFloat(score.getCredit()));
}
//总学时
if ("".equals(score.getCourseHours())) {
scoreResponse.setCourseHours(0.0F);
} else {
scoreResponse.setCourseHours(Float.parseFloat(score.getCourseHours()));
}
//绩点
if (StringUtil.isPositiveNumber(score.getGradePoint())) {
scoreResponse.setGradePoint(Float.parseFloat(score.getGradePoint()));
} else {
scoreResponse.setGradePoint(convertGradePoint(score.getScore()));
}
scoreResponse.setEvaluationMode(score.getEvaluateMethod());
scoreResponse.setExamNature(score.getKind());
scoreResponse.setCourseNature(score.getCourseKind());
scoreResponse.setSchoolTerm(score.getTerm());
// scoreResponse.setRebuildTag();
// scoreResponse.setReExamTag();
// scoreResponse.setMissExamTag();
//补考判断 0--正常考试 1--补考
scoreResponse.setReExamTag(0);
if (score.getFlag().contains("补考") || score.getKind().contains("补考")) {
scoreResponse.setReExamTag(1);
}
//缓考/缺考判断 0--正常 1--缺考 2--缓考
scoreResponse.setMissExamTag(0);
if (score.getFlag().contains("缺考") || score.getKind().contains("缺考")) {
scoreResponse.setMissExamTag(1);
}
if (score.getFlag().contains("缓考") || score.getKind().contains("缓考")) {
scoreResponse.setMissExamTag(2);
}
scoreResponse.setRebuildTag(0);
return scoreResponse;
}
/**
* 转换成绩为学分支持数字成绩和等级成绩
*
* @param gradeStr 成绩字符串
* @return 换算后的学分
*/
private static float convertGradePoint(String gradeStr) {
if (StringUtil.isPositiveNumber(gradeStr)) {
return StringUtil.numberGradeToGradePoint(gradeStr);
} else {
return StringUtil.levelGradeToGradePoint(gradeStr);
}
}
}

@ -0,0 +1,31 @@
package wusthelper.web.api.v2.dto.response;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import lombok.Data;
@Data
public class StudentInfoResponse {
private String stuNum;
private String stuName;
private String nickName;
private String college;
private String major;
private String classes;
public static StudentInfoResponse from(StudentInfo studentInfo) {
StudentInfoResponse studentInfoResponse = new StudentInfoResponse();
studentInfoResponse.setStuNum(studentInfo.getStudentNumber());
studentInfoResponse.setStuName(studentInfo.getName());
studentInfoResponse.setNickName("");
studentInfoResponse.setCollege(studentInfo.getCollege());
studentInfoResponse.setMajor(studentInfo.getMajor());
studentInfoResponse.setClasses(studentInfo.getClazz());
return studentInfoResponse;
}
}

@ -0,0 +1,127 @@
package wusthelper.web.api.v2.handler;
import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import wusthelper.code.ServiceCode;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.response.Response;
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
@ResponseBody
@ExceptionHandler(ServiceException.class)
public Response<Object> baseException(ServiceException e) {
return Response.error(e.getCodeValue(), e.getMessage());
}
@ResponseBody
@ExceptionHandler(FeignException.class)
public Response<Object> baseException(FeignException e) {
log.error("rpc服务异常:{}", e.getMessage());
log.info("堆栈跟踪:", e);
return Response.error(ServiceCode.RpcError);
}
@ResponseBody
@ExceptionHandler(ApiException.class)
public Response<Object> baseException(ApiException e) {
return Response.error(ServiceCode.ServerInternalError, e.getMessage());
}
@ResponseBody
@ExceptionHandler(Exception.class)
public Response<Object> baseException(Exception e) {
log.error("未处理的异常:", e);
return Response.error(ServiceCode.ServerInternalError);
}
/**
* 处理参数不完整的请求异常
*
* @param e 异常
* @return 统一响应
*/
@ResponseBody
@ExceptionHandler(MissingServletRequestParameterException.class)
public Response<Object> handler(MissingServletRequestParameterException e) {
log.debug("请求的参数不完整: " + e.getMessage());
return Response.error(ServiceCode.ParamWrong);
}
/**
* 处理参数类型错误的请求异常请求参数类型错误
*
* @param e 异常
* @return 统一响应
*/
@ResponseBody
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public Response<Object> handler(MethodArgumentTypeMismatchException e) {
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage()));
return Response.error(ServiceCode.ParamWrong);
}
/**
* 处理参数类型错误的请求异常2Json解析错误
*
* @param e 异常
* @return 统一响应
*/
@ResponseBody
@ExceptionHandler(JsonMappingException.class)
public Response<Object> handler(JsonMappingException e) {
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage()));
return Response.error(ServiceCode.ParamWrong);
}
/**
* 处理参数类型错误的请求异常3字段映射错误
*
* @param e 异常
* @return 统一响应
*/
@ResponseBody
@ExceptionHandler(HttpMessageNotReadableException.class)
public Response<Object> handler(HttpMessageNotReadableException e) {
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage()));
return Response.error(ServiceCode.ParamWrong);
}
/**
* 处理请求头中Content-Type字段不正确的异常
*
* @param e 异常
* @return 统一响应
*/
@ResponseBody
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public Response<Object> handler(HttpMediaTypeNotSupportedException e) {
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage()));
return Response.error(ServiceCode.ParamWrong, "请求头\"Contene-Type\"字段有误");
}
/**
* 处理请求方法错误的情况
*
* @param e 异常
* @return 统一响应
*/
@ResponseBody
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public Response<Object> handler(HttpRequestMethodNotSupportedException e) {
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage()));
return Response.error(ServiceCode.RequestInvalid);
}
}

@ -0,0 +1,114 @@
package wusthelper.web.api.v2.module.undergrade;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import wusthelper.web.api.v2.TokenTool;
import wusthelper.web.api.v2.dto.response.CourseResponse;
import wusthelper.web.api.v2.dto.response.ScoreResponse;
import wusthelper.web.api.v2.dto.response.StudentInfoResponse;
import wusthelper.web.response.Response;
import wusthelper.web.service.campus.undergrad.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@RestController
@RequestMapping("/v2/jwc")
public class UndergradController {
private final UndergradStudentInfoService studentInfoService;
private final UndergradCourseTableService courseTableService;
private final UndergradScoreService scoreService;
private final UndergradCreditStatusService creditStatusService;
private final UndergradTrainingPlanService trainingPlanService;
public UndergradController(UndergradStudentInfoService studentInfoService,
UndergradCourseTableService courseTableService,
UndergradScoreService scoreService,
UndergradCreditStatusService creditStatusService,
UndergradTrainingPlanService trainingPlanService) {
this.studentInfoService = studentInfoService;
this.courseTableService = courseTableService;
this.scoreService = scoreService;
this.creditStatusService = creditStatusService;
this.trainingPlanService = trainingPlanService;
}
@RequestMapping("/get-student-info")
public Response<StudentInfoResponse> getStudentInfo(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var studentInfo = studentInfoService.getStudentInfo(user);
return Response.success(StudentInfoResponse.from(studentInfo));
}
@RequestMapping("/get-curriculum")
public Response<List<CourseResponse>> getCourses(@RequestHeader("Token") String token,
@RequestParam(value = "schoolTerm") String term) {
var user = TokenTool.getStudentNumber(token);
var courses = courseTableService.getCourseTable(user, term);
var courseResponsesList = new ArrayList<CourseResponse>(courses.size());
for (var course : courses) {
courseResponsesList.add(CourseResponse.from(course));
}
return Response.success(courseResponsesList);
}
@RequestMapping("/get-grade")
public Response<List<ScoreResponse>> getScore(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var scores = scoreService.getScore(user);
var scoreResponseList = new ArrayList<ScoreResponse>(scores.size());
// 课程
Set<String> courseSet = new HashSet<>(scores.size());
// 课程+学期
Set<String> courseTermSet = new HashSet<>(scores.size());
for (var score : scores) {
var scoreResponse = ScoreResponse.from(score);
// 重修判断 0--未重修 1--重修
// 课程是否重复出现
scoreResponse.setRebuildTag(0);
String courseNumAndSchoolTerm = score.getCourseNumber() + score.getTerm();
if (courseSet.contains(score.getCourseNumber())) {
// 本次考试非补考 且本学期只有一次本课程号的课程,则表明本此考试为重修
if (scoreResponse.getReExamTag() == 0 && !courseTermSet.contains(courseNumAndSchoolTerm)) {
scoreResponse.setRebuildTag(1);
}
}
courseSet.add(score.getCourseNumber());
courseTermSet.add(courseNumAndSchoolTerm);
// 缓考不显示
if (scoreResponse.getMissExamTag() != 2) {
scoreResponseList.add(scoreResponse);
}
}
return Response.success(scoreResponseList);
}
@RequestMapping("/get-credit")
public Response<String> getCreditStatus(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var page = creditStatusService.getCreditStatus(user);
return Response.success(page);
}
@RequestMapping("/get-scheme")
public Response<String> getTrainingPlan(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var page = trainingPlanService.getTrainingPlan(user);
return Response.success(page);
}
}

@ -0,0 +1,76 @@
package wusthelper.web.api.v2.module.undergrade;
import org.springframework.web.bind.annotation.*;
import wusthelper.web.api.v2.TokenTool;
import wusthelper.web.api.v2.dto.response.CombineLoginResponse;
import wusthelper.web.api.v2.dto.response.CourseResponse;
import wusthelper.web.api.v2.dto.response.StudentInfoResponse;
import wusthelper.web.response.Response;
import wusthelper.web.service.campus.GeneralUserLoginService;
import wusthelper.web.service.campus.undergrad.UndergradCourseTableService;
import wusthelper.web.service.campus.undergrad.UndergradStudentInfoService;
import java.util.ArrayList;
@RestController
@RequestMapping("/v2/jwc")
public class UndergradLoginController {
private final GeneralUserLoginService generalUserLoginService;
private final UndergradStudentInfoService studentInfoService;
private final UndergradCourseTableService courseTableService;
public UndergradLoginController(GeneralUserLoginService generalUserLoginService,
UndergradStudentInfoService studentInfoService,
UndergradCourseTableService courseTableService) {
this.generalUserLoginService = generalUserLoginService;
this.studentInfoService = studentInfoService;
this.courseTableService = courseTableService;
}
@PostMapping("/login")
public Response<String> login(@RequestParam(value = "stuNum") String username,
@RequestParam(value = "jwcPwd") String password,
@RequestHeader(name = "Platform", required = false) String platform) {
var user = generalUserLoginService.login(username, password, GeneralUserLoginService.UserType.Undergrad);
String token = TokenTool.signToken(user.getUid(), user.getStuNum());
return Response.success(token);
}
/**
* v2接口的组合登录其实没必要所谓的请求减负在这里没啥太大用处这点压力算不上什么
* 不仅没必要还增大了登陆耗时容易超时
* v3版本时将会移除
*
* @param username 用户名
* @param password 密码
* @param term 学期
* @param platform 平台
* @return .
*/
@PostMapping("/combine-login")
public Response<CombineLoginResponse> combineLogin(@RequestParam(value = "stuNum") String username,
@RequestParam(value = "jwcPwd") String password,
@RequestParam(value = "term") String term,
@RequestHeader(name = "Platform", required = false) String platform) {
var user = generalUserLoginService.login(username, password, GeneralUserLoginService.UserType.Undergrad);
var studentInfo = studentInfoService.getStudentInfo(username);
var courses = courseTableService.getCourseTable(username, term);
var studentResponse = StudentInfoResponse.from(studentInfo);
var courseResponses = new ArrayList<CourseResponse>(courses.size());
for (var course : courses) {
courseResponses.add(CourseResponse.from(course));
}
String token = TokenTool.signToken(user.getUid(), user.getStuNum());
var response = new CombineLoginResponse(token, courseResponses, studentResponse);
return Response.success(response);
}
}

@ -1,5 +0,0 @@
package wusthelper.web.api.v2.undergrade;
public class UndergradController {
}

@ -1,28 +0,0 @@
package wusthelper.web.api.v2.undergrade;
import org.springframework.web.bind.annotation.*;
import wusthelper.web.api.v2.Token;
import wusthelper.web.response.Response;
import wusthelper.web.service.campus.GeneralUserLoginService;
@RestController
@RequestMapping("/jwc")
public class UndergradLoginController {
private final GeneralUserLoginService generalUserLoginService;
public UndergradLoginController(GeneralUserLoginService generalUserLoginService) {
this.generalUserLoginService = generalUserLoginService;
}
@PostMapping("/login")
public Response<String> login(@RequestParam(value = "username") String username,
@RequestParam(value = "jwcPwd") String password,
@RequestHeader(name = "Platform", required = false) String platform) {
var user = generalUserLoginService.login(username, password, GeneralUserLoginService.UserType.Undergrad);
String token = Token.signToken(user.getUid(), user.getStuNum());
return Response.success(token);
}
}

@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
@FeignClient(name = "wusthelper.graduate", contextId = "cookie") @FeignClient(name = "wusthelper.graduate", contextId = "graduate-cookie")
public interface GraduateCookieRemote { public interface GraduateCookieRemote {
String COOKIE_ROOT_PATH = "/cookie"; String COOKIE_ROOT_PATH = "/cookie";

@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
@FeignClient(name = "wusthelper.graduate", contextId = "studentInfo") @FeignClient(name = "wusthelper.graduate", contextId = "graduate-studentInfo")
public interface GraduateStudentInfoRemote { public interface GraduateStudentInfoRemote {
String ROOT_PATH = "/student_info"; String ROOT_PATH = "/student_info";

@ -1,6 +1,7 @@
package wusthelper.web.rpc.undergrad; package wusthelper.web.rpc.undergrad;
import cn.wustlinghang.mywust.data.global.Course; import cn.wustlinghang.mywust.data.global.Course;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -10,7 +11,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
@FeignClient(name = "wusthelper.undergrad", contextId = "courseTable") @Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-courseTable")
public interface CourseTableRemote { public interface CourseTableRemote {
String ROOT_PATH = "/course_table"; String ROOT_PATH = "/course_table";

@ -1,5 +1,6 @@
package wusthelper.web.rpc.undergrad; package wusthelper.web.rpc.undergrad;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -7,7 +8,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "wusthelper.undergrad", contextId = "creditStatus") @Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-creditStatus")
public interface CreditStatusRemote { public interface CreditStatusRemote {
String ROOT_PATH = "/credit_status"; String ROOT_PATH = "/credit_status";

@ -1,6 +1,7 @@
package wusthelper.web.rpc.undergrad; package wusthelper.web.rpc.undergrad;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -8,7 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "wusthelper.undergrad", contextId = "examDelayApplication") @Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-examDelayApplication")
public interface ExamDelayApplicationRemote { public interface ExamDelayApplicationRemote {
String ROOT_PATH = "/exam_delay_application"; String ROOT_PATH = "/exam_delay_application";

@ -1,6 +1,7 @@
package wusthelper.web.rpc.undergrad; package wusthelper.web.rpc.undergrad;
import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.mywust.data.global.Score;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -10,7 +11,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
@FeignClient(name = "wusthelper.undergrad", contextId = "score") @Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-score")
public interface ScoreRemote { public interface ScoreRemote {
String ROOT_PATH = "/score"; String ROOT_PATH = "/score";

@ -1,5 +1,6 @@
package wusthelper.web.rpc.undergrad; package wusthelper.web.rpc.undergrad;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -7,7 +8,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "wusthelper.undergrad", contextId = "trainingPlan") @Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-trainingPlan")
public interface TrainingPlanRemote { public interface TrainingPlanRemote {
String ROOT_PATH = "/training_plan"; String ROOT_PATH = "/training_plan";

@ -1,11 +1,13 @@
package wusthelper.web.rpc.undergrad; package wusthelper.web.rpc.undergrad;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "wusthelper.undergrad", contextId = "cookie") @Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-cookie")
public interface UndergradCookieRemote { public interface UndergradCookieRemote {
String COOKIE_ROOT_PATH = "/cookie"; String COOKIE_ROOT_PATH = "/cookie";

@ -1,6 +1,7 @@
package wusthelper.web.rpc.undergrad; package wusthelper.web.rpc.undergrad;
import cn.wustlinghang.mywust.data.global.StudentInfo; import cn.wustlinghang.mywust.data.global.StudentInfo;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -8,7 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "wusthelper.undergrad", contextId = "studentInfo") @Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-studentInfo")
public interface UndergradStudentInfoRemote { public interface UndergradStudentInfoRemote {
String ROOT_PATH = "/student_info"; String ROOT_PATH = "/student_info";

@ -16,7 +16,7 @@ public class GraduateCookieService {
public String getLoginCookie(String username, String password) throws ServiceException { public String getLoginCookie(String username, String password) throws ServiceException {
var rpcResp = graduateCookieRemote.login(username, password); var rpcResp = graduateCookieRemote.login(username, password);
if (rpcResp.code() != ServiceCode.Ok) { if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.of(rpcResp.code()); ServiceException.error(rpcResp.code());
} }
return rpcResp.data(); return rpcResp.data();

@ -35,7 +35,7 @@ public class GraduateStudentInfoService {
public StudentInfo getStudentInfo(String user, String cookie) { public StudentInfo getStudentInfo(String user, String cookie) {
var response = graduateStudentInfoRemote.get(cookie); var response = graduateStudentInfoRemote.get(cookie);
if (response.code() != ServiceCode.Ok) { if (response.code() != ServiceCode.Ok) {
ServiceException.of(response.code()); ServiceException.error(response.code());
} }
var studentInfo = response.data(); var studentInfo = response.data();

@ -6,7 +6,6 @@ import wusthelper.web.rpc.undergrad.ExamDelayApplicationRemote;
import wusthelper.web.data.entity.CookieType; import wusthelper.web.data.entity.CookieType;
import wusthelper.web.service.cookie.CookieManager; import wusthelper.web.service.cookie.CookieManager;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import wusthelper.internal.rpc.response.RpcCommonResponseCode;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@ -24,7 +23,7 @@ public class ExamDelayApplicationService {
String cookie = cookieManager.getCookie(user, CookieType.Undergrad); String cookie = cookieManager.getCookie(user, CookieType.Undergrad);
var rpcResp = examDelayApplicationRemote.get(cookie, term, activityId); var rpcResp = examDelayApplicationRemote.get(cookie, term, activityId);
if (rpcResp.code() != ServiceCode.Ok) { if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.of(rpcResp.code()); ServiceException.error(rpcResp.code());
} }
// todo 异步存用户课表,异常判断等等 // todo 异步存用户课表,异常判断等等

@ -17,7 +17,7 @@ public class UndergradCookieService {
public String getLoginCookie(String username, String password) throws ServiceException { public String getLoginCookie(String username, String password) throws ServiceException {
var rpcResp = undergradCookieRemote.login(username, password); var rpcResp = undergradCookieRemote.login(username, password);
if (rpcResp.code() != ServiceCode.Ok) { if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.of(rpcResp.code()); ServiceException.error(rpcResp.code());
} }
return rpcResp.data(); return rpcResp.data();

@ -6,18 +6,17 @@ import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.CourseTableRemote; import wusthelper.web.rpc.undergrad.CourseTableRemote;
import wusthelper.web.service.cookie.CookieManager; import wusthelper.web.service.cookie.CookieManager;
import cn.wustlinghang.mywust.data.global.Course; import cn.wustlinghang.mywust.data.global.Course;
import wusthelper.internal.rpc.response.RpcCommonResponseCode;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@Service @Service
public class CourseTableService { public class UndergradCourseTableService {
private final CourseTableRemote courseTableRemote; private final CourseTableRemote courseTableRemote;
private final CookieManager cookieManager; private final CookieManager cookieManager;
public CourseTableService(CourseTableRemote courseTableRemote, CookieManager cookieManager) { public UndergradCourseTableService(CourseTableRemote courseTableRemote, CookieManager cookieManager) {
this.courseTableRemote = courseTableRemote; this.courseTableRemote = courseTableRemote;
this.cookieManager = cookieManager; this.cookieManager = cookieManager;
} }
@ -26,7 +25,7 @@ public class CourseTableService {
String cookie = cookieManager.getCookie(user, CookieType.Undergrad); String cookie = cookieManager.getCookie(user, CookieType.Undergrad);
var rpcResp = courseTableRemote.get(cookie, term); var rpcResp = courseTableRemote.get(cookie, term);
if (rpcResp.code() != ServiceCode.Ok) { if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.of(rpcResp.code()); ServiceException.error(rpcResp.code());
} }
// todo 异步存用户课表,异常判断等等 // todo 异步存用户课表,异常判断等等

@ -5,15 +5,14 @@ import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException; import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.CreditStatusRemote; import wusthelper.web.rpc.undergrad.CreditStatusRemote;
import wusthelper.web.service.cookie.CookieManager; import wusthelper.web.service.cookie.CookieManager;
import wusthelper.internal.rpc.response.RpcCommonResponseCode;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class CreditStatusService { public class UndergradCreditStatusService {
private final CreditStatusRemote creditStatusRemote; private final CreditStatusRemote creditStatusRemote;
private final CookieManager cookieManager; private final CookieManager cookieManager;
public CreditStatusService(CreditStatusRemote creditStatusRemote, CookieManager cookieManager) { public UndergradCreditStatusService(CreditStatusRemote creditStatusRemote, CookieManager cookieManager) {
this.creditStatusRemote = creditStatusRemote; this.creditStatusRemote = creditStatusRemote;
this.cookieManager = cookieManager; this.cookieManager = cookieManager;
} }
@ -22,7 +21,7 @@ public class CreditStatusService {
String cookie = cookieManager.getCookie(user, CookieType.Undergrad); String cookie = cookieManager.getCookie(user, CookieType.Undergrad);
var rpcResp = creditStatusRemote.get(cookie); var rpcResp = creditStatusRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) { if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.of(rpcResp.code()); ServiceException.error(rpcResp.code());
} }
// todo 异步存用户课表,异常判断等等 // todo 异步存用户课表,异常判断等等

@ -6,17 +6,16 @@ import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.ScoreRemote; import wusthelper.web.rpc.undergrad.ScoreRemote;
import wusthelper.web.service.cookie.CookieManager; import wusthelper.web.service.cookie.CookieManager;
import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.mywust.data.global.Score;
import wusthelper.internal.rpc.response.RpcCommonResponseCode;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@Service @Service
public class ScoreService { public class UndergradScoreService {
private final ScoreRemote scoreRemote; private final ScoreRemote scoreRemote;
private final CookieManager cookieManager; private final CookieManager cookieManager;
public ScoreService(ScoreRemote scoreRemote, CookieManager cookieManager) { public UndergradScoreService(ScoreRemote scoreRemote, CookieManager cookieManager) {
this.scoreRemote = scoreRemote; this.scoreRemote = scoreRemote;
this.cookieManager = cookieManager; this.cookieManager = cookieManager;
} }
@ -25,7 +24,7 @@ public class ScoreService {
String cookie = cookieManager.getCookie(user, CookieType.Undergrad); String cookie = cookieManager.getCookie(user, CookieType.Undergrad);
var rpcResp = scoreRemote.get(cookie); var rpcResp = scoreRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) { if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.of(rpcResp.code()); ServiceException.error(rpcResp.code());
} }
// todo 异步存用户课表,异常判断等等 // todo 异步存用户课表,异常判断等等

@ -8,7 +8,6 @@ import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.UndergradStudentInfoRemote; import wusthelper.web.rpc.undergrad.UndergradStudentInfoRemote;
import wusthelper.web.service.cookie.CookieManager; import wusthelper.web.service.cookie.CookieManager;
import wusthelper.web.service.student.StudentService; import wusthelper.web.service.student.StudentService;
import wusthelper.web.util.PasswordCodec;
@Service @Service
public class UndergradStudentInfoService { public class UndergradStudentInfoService {
@ -28,21 +27,21 @@ public class UndergradStudentInfoService {
this.studentService = studentService; this.studentService = studentService;
} }
public StudentInfo getStudentInfo(String user) { public StudentInfo getStudentInfo(String studentNumber) {
String cookie = cookieManager.getCookie(user, CookieType.Undergrad); String cookie = cookieManager.getCookie(studentNumber, CookieType.Undergrad);
return getStudentInfo(user, cookie); return getStudentInfo(studentNumber, cookie);
} }
public StudentInfo getStudentInfo(String user, String cookie) { public StudentInfo getStudentInfo(String studentNumber, String cookie) {
var rpcResp = undergradStudentInfoRemote.get(cookie); var rpcResp = undergradStudentInfoRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) { if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.of(rpcResp.code()); ServiceException.error(rpcResp.code());
} }
var studentInfo = rpcResp.data(); var studentInfo = rpcResp.data();
studentService.saveOrUpdateUserAsync(user, studentInfo); studentService.saveOrUpdateUserAsync(studentNumber, studentInfo);
return studentInfo; return studentInfo;
} }
} }

@ -5,15 +5,14 @@ import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.TrainingPlanRemote; import wusthelper.web.rpc.undergrad.TrainingPlanRemote;
import wusthelper.web.data.entity.CookieType; import wusthelper.web.data.entity.CookieType;
import wusthelper.web.service.cookie.CookieManager; import wusthelper.web.service.cookie.CookieManager;
import wusthelper.internal.rpc.response.RpcCommonResponseCode;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class TrainingPlanService { public class UndergradTrainingPlanService {
private final TrainingPlanRemote trainingPlanRemote; private final TrainingPlanRemote trainingPlanRemote;
private final CookieManager cookieManager; private final CookieManager cookieManager;
public TrainingPlanService(TrainingPlanRemote trainingPlanRemote, CookieManager cookieManager) { public UndergradTrainingPlanService(TrainingPlanRemote trainingPlanRemote, CookieManager cookieManager) {
this.trainingPlanRemote = trainingPlanRemote; this.trainingPlanRemote = trainingPlanRemote;
this.cookieManager = cookieManager; this.cookieManager = cookieManager;
} }
@ -22,7 +21,7 @@ public class TrainingPlanService {
String cookie = cookieManager.getCookie(user, CookieType.Undergrad); String cookie = cookieManager.getCookie(user, CookieType.Undergrad);
var rpcResp = trainingPlanRemote.get(cookie); var rpcResp = trainingPlanRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) { if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.of(rpcResp.code()); ServiceException.error(rpcResp.code());
} }
// todo 异步存用户课表,异常判断等等 // todo 异步存用户课表,异常判断等等

@ -78,7 +78,7 @@ public class CookieManager {
); );
if (student == null) { if (student == null) {
ServiceException.of(ServiceCode.UserNotExists); ServiceException.error(ServiceCode.UserNotExists);
} }
String password = switch (cookieType) { String password = switch (cookieType) {
@ -88,7 +88,7 @@ public class CookieManager {
}; };
if (password == null) { if (password == null) {
ServiceException.of(ServiceCode.ParamWrong); ServiceException.error(ServiceCode.ParamWrong);
} }
return switch (cookieType) { return switch (cookieType) {

@ -0,0 +1,86 @@
package wusthelper.web.util;
public class StringUtil {
public static boolean isPositiveNumber(final String str) {
if (str == null || "".equals(str)) {
return false;
}
int length = str.length();
for (int i = 0; i < length; i++) {
int ch = str.charAt(i);
// 判断字符0-9,还有.
// 负数不考虑
if ((ch < 48 || ch > 57 ) && ch != 46) {
return false;
}
}
return true;
}
/**
* 成绩换算成学分
*
* @param gradeString 数字成绩字符串
* @return 换算后的学分
*/
public static float numberGradeToGradePoint(String gradeString) {
float gradeFloat = Float.parseFloat(gradeString);
if (gradeFloat >= 90.0F) {
return 4.0F;
} else if (gradeFloat >= 85.0F) {
return 3.7F;
} else if (gradeFloat >= 82.0F) {
return 3.3F;
} else if (gradeFloat >= 78.0F) {
return 3.0F;
} else if (gradeFloat >= 75.0F) {
return 2.7F;
} else if (gradeFloat >= 72.0F) {
return 2.3F;
} else if (gradeFloat >= 68.0F) {
return 2.0F;
} else if (gradeFloat >= 64.0F) {
return 1.5F;
} else if (gradeFloat >= 60.0F) {
return 1.0F;
} else {
return 0.0F;
}
}
/**
* 等级成绩换算成学分
*
* @param gradeLevel 成绩等级
* @return 换算后的学分
*/
public static float levelGradeToGradePoint(String gradeLevel) {
switch (gradeLevel) {
case "A":
return 4.0F;
case "A-":
return 3.7F;
case "B+":
return 3.3F;
case "B":
return 3.0F;
case "B-":
return 2.7F;
case "C+":
return 2.3F;
case "C":
return 2.0F;
case "C-":
return 1.5F;
case "D":
return 1.0F;
case "F":
return 0.0F;
default:
return 0.0F;
}
}
}

@ -7,6 +7,9 @@ spring:
import: optional:file:.env[.properties] import: optional:file:.env[.properties]
application: application:
name: wusthelper-backend-main name: wusthelper-backend-main
# main:
# allow-bean-definition-overriding: true
# main.allow-bean-definition-overriding = true
cloud: cloud:
consul: consul:
@ -22,3 +25,6 @@ spring:
server: server:
port: ${RUN_PORT} port: ${RUN_PORT}
wusthelper:
password-encode-key: wusthelper

@ -11,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import wusthelper.web.api.v2.Token; import wusthelper.web.api.v2.TokenTool;
@Slf4j @Slf4j
@EnableAsync @EnableAsync
@ -27,19 +27,19 @@ import wusthelper.web.api.v2.Token;
"wusthelper.data", "wusthelper.data",
"wusthelper.web", "wusthelper.web",
}) })
@MapperScan("cn.wustlinghang.wusthelper.data.dao.mapper") @MapperScan("wusthelper.data.dao.mapper")
public class TestMain { public class TestMain {
@Test @Test
public void jwtTest() { public void jwtTest() {
String token = Token.signToken(1233487L, "202118194039"); String token = TokenTool.signToken(1233487L, "202118194039");
log.info(token); log.info(token);
} }
public static void main(String[] args) { public static void main(String[] args) {
String token = Token.signToken(1233487L, "202118194039"); String token = TokenTool.signToken(1233487L, "202118194039");
boolean valid = Token.verifyToken(token); boolean valid = TokenTool.verifyToken(token);
var uid = Token.getUid(token); var uid = TokenTool.getUid(token);
var studentNumber = Token.getStudentNumber(token); var studentNumber = TokenTool.getStudentNumber(token);
log.info(token); log.info(token);
log.info("{}", valid); log.info("{}", valid);
log.info(uid); log.info(uid);

@ -21,12 +21,13 @@ public class ServiceCode {
public static final int UserNotExists = 20_001; // 用户不存在 public static final int UserNotExists = 20_001; // 用户不存在
// 本科生 // 本科生
public static final int UndergradUserNotExists = 30_001; // 本科生:用户不存在 public static final int UndergradPasswordWrong = 30_001; // 本科生:密码错误
public static final int UndergradUserBanned = 30_002; // 本科生:封号 public static final int UndergradUserNotExists = 30_002; // 本科生:用户不存在
public static final int UndergradUserDisabled = 30_003; // 本科生:用户账号禁用 public static final int UndergradUserBanned = 30_003; // 本科生:封号
public static final int UndergradPasswordNeedModify = 30_004; // 本科生:用户密码需要更改 public static final int UndergradUserDisabled = 30_004; // 本科生:用户账号禁用
public static final int UndergradBannedInExclusiveTime = 30_005; // 本科生:专属选课时间段账号被禁用(--> _ --) public static final int UndergradPasswordNeedModify = 30_005; // 本科生:用户密码需要更改
public static final int UndergradNeedEvaluate = 30_006; // 本科生:需要评教 public static final int UndergradBannedInExclusiveTime = 30_006; // 本科生:专属选课时间段账号被禁用(--> _ --)
public static final int UndergradNeedEvaluate = 30_007; // 本科生:需要评教
// 研究生 // 研究生
public static final int GraduatePasswordWrong = 40_001; // 研究生:密码错误 public static final int GraduatePasswordWrong = 40_001; // 研究生:密码错误
@ -62,6 +63,7 @@ public class ServiceCode {
text.put(ParseError, "解析错误"); text.put(ParseError, "解析错误");
// 本科生 // 本科生
text.put(UndergradPasswordWrong, "本科生:密码错误");
text.put(UndergradUserNotExists, "本科生:用户不存在"); text.put(UndergradUserNotExists, "本科生:用户不存在");
text.put(UndergradUserBanned, "本科生:封号"); text.put(UndergradUserBanned, "本科生:封号");
text.put(UndergradUserDisabled, "本科生:用户账号禁用"); text.put(UndergradUserDisabled, "本科生:用户账号禁用");

@ -1,62 +0,0 @@
package wusthelper.internal.rpc.exception;
import java.util.StringJoiner;
public class GraduateRpcException extends RpcException {
public GraduateRpcException(TypeCode typeCode,
SubModuleCode subModuleCode,
ErrorCode errorCode) {
super(GRADUATE_MODULE,
typeCode.ordinal(),
subModuleCode.ordinal() * 100 + errorCode.ordinal(),
new StringJoiner("/")
.add("GRADUATE")
.add(typeCode.name())
.add(subModuleCode.name())
.add(errorCode.name())
.toString()
);
}
/**
* 异常类型编码
*/
public enum TypeCode {
// 网络异常类型
NETWORK_EXCEPTION,
// 参数异常类型
PARAM_EXCEPTION,
// 权限认证异常类型
AUTH_EXCEPTION,
// 网页解析异常类型
PARSE_EXCEPTION,
// 其他的异常类型
OTHER_EXCEPTION
}
/**
* 子模块编码
*/
public enum SubModuleCode {
COMMON, AUTH, COURSE_TABLE, SCORE, STUDENT_INFO, TRAINING_PLAN
}
/**
* 具体错误编码
*/
public enum ErrorCode {
REQUEST_INVALID,
PARAM_INVALID,
COOKIE_INVALID,
NETWORK_ERROR,
PARSE_ERROR,
// 需要评教
NEED_EVALUATE,
AUTH_PASSWORD_WRONG,
AUTH_CAPTCHA_WRONG,
AUTH_UNKNOWN_ERROR
}
}

@ -1,68 +0,0 @@
package wusthelper.internal.rpc.exception;
import java.util.StringJoiner;
public class LibraryRpcException extends RpcException {
public LibraryRpcException(TypeCode typeCode,
SubModuleCode subModuleCode,
ErrorCode errorCode) {
super(LIBRARY_MODULE,
typeCode.ordinal(),
subModuleCode.ordinal() * 100 + errorCode.ordinal(),
new StringJoiner("/")
.add("LIBRARY")
.add(typeCode.name())
.add(subModuleCode.name())
.add(errorCode.name())
.toString()
);
}
/**
* 异常类型编码
*/
public enum TypeCode {
// 网络异常类型
NETWORK_EXCEPTION,
// 参数异常类型
PARAM_EXCEPTION,
// 权限认证异常类型
AUTH_EXCEPTION,
// 网页解析异常类型
PARSE_EXCEPTION,
// 其他的异常类型
OTHER_EXCEPTION
}
/**
* 子模块编码
*/
public enum SubModuleCode {
COMMON, AUTH,
COVER_IMAGE, BOOK_DETAIL, BOOK_HOLDING, SEARCH,
CURRENT_LOAN, LOAN_HISTORY, OVERDUE_SOON,
}
/**
* 具体错误编码
*/
public enum ErrorCode {
REQUEST_INVALID,
PARAM_INVALID,
COOKIE_INVALID,
NETWORK_ERROR,
PARSE_ERROR,
AUTH_PASSWORD_WRONG,
// 用户不存在
AUTH_USER_NOT_EXISTS,
// 封号
AUTH_USER_BANNED,
// 用户账号禁用
AUTH_USER_DISABLED,
// 用户密码需要更改
AUTH_NEED_CHANGE_PASSWORD,
AUTH_UNKNOWN_ERROR
}
}

@ -1,59 +0,0 @@
package wusthelper.internal.rpc.exception;
import java.util.StringJoiner;
public class PhysicsRpcException extends RpcException {
public PhysicsRpcException(TypeCode typeCode,
SubModuleCode subModuleCode,
ErrorCode errorCode) {
super(PHYSICS_MODULE,
typeCode.ordinal(),
subModuleCode.ordinal() * 100 + errorCode.ordinal(),
new StringJoiner("/")
.add("PHYSICS")
.add(typeCode.name())
.add(subModuleCode.name())
.add(errorCode.name())
.toString()
);
}
/**
* 异常类型编码
*/
public enum TypeCode {
// 网络异常类型
NETWORK_EXCEPTION,
// 参数异常类型
PARAM_EXCEPTION,
// 权限认证异常类型
AUTH_EXCEPTION,
// 网页解析异常类型
PARSE_EXCEPTION,
// 其他的异常类型
OTHER_EXCEPTION
}
/**
* 子模块编码
*/
public enum SubModuleCode {
COMMON, AUTH, COURSE_TABLE, SCORE
}
/**
* 具体错误编码
*/
public enum ErrorCode {
REQUEST_INVALID,
PARAM_INVALID,
COOKIE_INVALID,
NETWORK_ERROR,
PARSE_ERROR,
AUTH_PASSWORD_WRONG,
AUTH_UNKNOWN_ERROR,
AUTH_USER_NOT_CURRENT_TERM
}
}

@ -1,31 +1,17 @@
package wusthelper.internal.rpc.exception; package wusthelper.internal.rpc.exception;
public abstract class RpcException extends RuntimeException { import wusthelper.code.ServiceCode;
protected final int code;
public static final int UNDERGRAD_MODULE = 1; public class RpcException extends RuntimeException {
public static final int GRADUATE_MODULE = 2; protected final int code;
public static final int LIBRARY_MODULE = 3;
public static final int PHYSICS_MODULE = 4;
private static final int MODULE_CODE_OFFSET = 100_0000;
private static final int TYPE_CODE_OFFSET = 1_0000;
public RpcException(int code, String message) { public RpcException(int code, String message) {
super(message); super(message);
this.code = code; this.code = code;
} }
public RpcException(int code) { public RpcException(int code) {
this(code, String.valueOf(code)); this(code, ServiceCode.getDescribe(code));
}
public RpcException(int module, int type, int exceptionCode) {
this((module * MODULE_CODE_OFFSET) + (type * TYPE_CODE_OFFSET) + (exceptionCode));
}
public RpcException(int module, int type, int exceptionCode, String message) {
this((module * MODULE_CODE_OFFSET) + (type * TYPE_CODE_OFFSET) + (exceptionCode), message);
} }
public int getCode() { public int getCode() {
@ -33,10 +19,10 @@ public abstract class RpcException extends RuntimeException {
} }
public static RpcException ApiNotImplement() { public static RpcException ApiNotImplement() {
return new RpcException(-1, "接口未实现") {}; return new RpcException(-1, null);
} }
public static int toIntCode(int module, int type, int exceptionCode) { public static void error(int code) {
return (module * MODULE_CODE_OFFSET) + (type * TYPE_CODE_OFFSET) + (exceptionCode); throw new RpcException(code);
} }
} }

@ -1,71 +0,0 @@
package wusthelper.internal.rpc.exception;
import java.util.StringJoiner;
public class UndergradRpcException extends RpcException {
public UndergradRpcException(TypeCode typeCode,
SubModuleCode subModuleCode,
ErrorCode errorCode) {
super(UNDERGRAD_MODULE,
typeCode.ordinal(),
subModuleCode.ordinal() * 100 + errorCode.ordinal(),
new StringJoiner("/")
.add("UNDERGRAD")
.add(typeCode.name())
.add(subModuleCode.name())
.add(errorCode.name())
.toString()
);
}
/**
* 异常类型编码
*/
public enum TypeCode {
// 网络异常类型
NETWORK_EXCEPTION,
// 参数异常类型
PARAM_EXCEPTION,
// 权限认证异常类型
AUTH_EXCEPTION,
// 网页解析异常类型
PARSE_EXCEPTION,
// 其他的异常类型
OTHER_EXCEPTION
}
/**
* 子模块编码
*/
public enum SubModuleCode {
COMMON, AUTH, COURSE_TABLE, CREDIT_STATUS, SCORE,
STUDENT_INFO, TRAINING_PLAN, EXAM_ACTIVITIES, EXAM_DELAY_APPLICATION
}
/**
* 具体错误编码
*/
public enum ErrorCode {
REQUEST_INVALID,
PARAM_INVALID,
COOKIE_INVALID,
NETWORK_ERROR,
PARSE_ERROR,
AUTH_PASSWORD_WRONG,
// 用户不存在
AUTH_USER_NOT_EXISTS,
// 封号
AUTH_USER_BANNED,
// 用户账号禁用
AUTH_USER_DISABLED,
// 用户密码需要更改
AUTH_NEED_CHANGE_PASSWORD,
// 专属选课时间段账号被禁用(--> _ --)
AUTH_BANNED_IN_EXCLUSIVE_TIME,
AUTH_UNKNOWN_ERROR,
// 需要评教
NEED_EVALUATE,
}
}

@ -1,31 +0,0 @@
/*
* Class created by lensfrex.
*/
package wusthelper.internal.rpc.response;
public enum RpcCommonResponseCode {
Success(20000, "成功"),
ParamWrong(30001, "参数错误"),
ServerInternalError(50000, "服务器内部错误"),
ApiNotImplement(0, "接口未实现"),
;
private final int code;
private final String message;
RpcCommonResponseCode(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}

@ -1,22 +1,19 @@
package wusthelper.internal.rpc.response; package wusthelper.internal.rpc.response;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import wusthelper.code.ServiceCode;
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public record RpcResponseDto<T>(int code, T data) { public record RpcResponseDto<T>(int code, T data) {
public static <T> RpcResponseDto<T> success(T data) { public static <T> RpcResponseDto<T> success(T data) {
return new RpcResponseDto<>(RpcCommonResponseCode.Success.getCode(), data); return new RpcResponseDto<>(ServiceCode.Ok, data);
} }
public static <T> RpcResponseDto<T> success() { public static <T> RpcResponseDto<T> success() {
return success(null); return success(null);
} }
public static <T> RpcResponseDto<T> error(int code, String message) { public static <T> RpcResponseDto<T> error(int code) {
return new RpcResponseDto<>(code, null); return new RpcResponseDto<>(code, null);
} }
public static <T> RpcResponseDto<T> error(RpcCommonResponseCode code) {
return error(code.getCode(), code.getMessage());
}
} }

@ -37,7 +37,7 @@ public class ServiceException extends RuntimeException {
* @param code 错误码 * @param code 错误码
* @throws ServiceException . * @throws ServiceException .
*/ */
public static void of(int code) throws ServiceException { public static void error(int code) throws ServiceException {
throw new ServiceException(code); throw new ServiceException(code);
} }
} }

@ -1,35 +1,31 @@
package wusthelper.internal.graduate.api.http.v1.handler; package wusthelper.internal.graduate.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode;
import wusthelper.internal.rpc.response.RpcResponseDto;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.response.RpcResponseDto;
public abstract class BaseExceptionHandler { public abstract class BaseExceptionHandler {
public static final String EXCEPTION_HEADER_KEY = "X-exception-handler"; public static final String EXCEPTION_HEADER_KEY = "X-exception-handler";
private static final ObjectMapper objectMapper = new ObjectMapper(); private static final ObjectMapper objectMapper = new ObjectMapper();
public Response toResponse(RpcCommonResponseCode code, String msg, String handlerName) { public Response toResponse(int code, String handlerName) {
return toResponse(code.getCode(), msg, handlerName); return toResponse(Response.Status.OK, code, handlerName);
}
public Response toResponse(int code, String msg, String handlerName) {
return toResponse(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code, msg, handlerName);
} }
public Response toResponse(int status, int code, String msg, String handlerName) { public Response toResponse(int status, int code, String handlerName) {
return toResponse(Response.Status.fromStatusCode(status), code, msg, handlerName); return toResponse(Response.Status.fromStatusCode(status), code, handlerName);
} }
public Response toResponse(Response.Status status, int code, String msg, String handlerName) { public Response toResponse(Response.Status status, int code, String handlerName) {
Object response; Object response;
try { try {
response = objectMapper.writeValueAsString(RpcResponseDto.error(code, msg)); response = objectMapper.writeValueAsString(RpcResponseDto.error(code));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
response = RpcResponseDto.error(RpcCommonResponseCode.ServerInternalError); response = RpcResponseDto.error(ServiceCode.ServerInternalError);
} }
return Response.status(status) return Response.status(status)

@ -1,21 +1,19 @@
package wusthelper.internal.graduate.api.http.v1.handler; package wusthelper.internal.graduate.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> { public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> {
@Override @Override
public Response toResponse(Exception e) { public Response toResponse(Exception e) {
log.error("未知异常:", e); log.error("未知异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.ServerInternalError, "DefaultExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"DefaultExceptionHandler"
);
} }
} }

@ -1,23 +1,21 @@
package wusthelper.internal.graduate.api.http.v1.handler; package wusthelper.internal.graduate.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import java.io.IOException; import java.io.IOException;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> { public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> {
@Override @Override
public Response toResponse(IOException e) { public Response toResponse(IOException e) {
log.error("IO异常:", e); log.error("IO异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.NetworkError, "IOExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"IOExceptionHandler"
);
} }
} }

@ -1,22 +1,20 @@
package wusthelper.internal.graduate.api.http.v1.handler; package wusthelper.internal.graduate.api.http.v1.handler;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> { public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> {
@Override @Override
public Response toResponse(ParseException e) { public Response toResponse(ParseException e) {
log.error("解析异常:", e); log.error("解析异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.ParseError, "ParseExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"ParseExceptionHandler"
);
} }
} }

@ -1,17 +1,19 @@
package wusthelper.internal.graduate.api.http.v1.handler; package wusthelper.internal.graduate.api.http.v1.handler;
import wusthelper.internal.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j;
import wusthelper.internal.rpc.exception.RpcException;
@Slf4j
@Provider @Provider
@ApplicationScoped
public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> { public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> {
@Override @Override
public Response toResponse(RpcException e) { public Response toResponse(RpcException e) {
return super.toResponse( log.debug("RpcException:", e);
e.getCode(), return super.toResponse(e.getCode(), "RpcExceptionHandler");
e.toString(),
"RpcExceptionHandler");
} }
} }

@ -1,22 +1,20 @@
package wusthelper.internal.graduate.api.http.v1.handler; package wusthelper.internal.graduate.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.ValidationException; import jakarta.validation.ValidationException;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class ValidationExceptionHandler extends BaseExceptionHandler public class ValidationExceptionHandler extends BaseExceptionHandler
implements ExceptionMapper<ValidationException> { implements ExceptionMapper<ValidationException> {
@Override @Override
public Response toResponse(ValidationException e) { public Response toResponse(ValidationException e) {
return super.toResponse( return super.toResponse(ServiceCode.ParamWrong, "ValidationExceptionHandler");
RpcCommonResponseCode.ParamWrong,
"参数错误:" + e.toString(),
"ValidationExceptionHandler"
);
} }
} }

@ -1,26 +1,17 @@
package wusthelper.internal.graduate.api.http.v1.handler; package wusthelper.internal.graduate.api.http.v1.handler;
import wusthelper.internal.rpc.exception.GraduateRpcException; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.internal.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;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import wusthelper.code.ServiceCode;
@Provider @Provider
@ApplicationScoped
public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> { public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> {
@Override @Override
public Response toResponse(WebApplicationException e) { public Response toResponse(WebApplicationException e) {
return super.toResponse( return super.toResponse(ServiceCode.RequestInvalid, "WebApplicationExceptionHandler");
e.getResponse().getStatus(),
RpcException.toIntCode(
GraduateRpcException.GRADUATE_MODULE,
GraduateRpcException.SubModuleCode.COMMON.ordinal(),
GraduateRpcException.TypeCode.OTHER_EXCEPTION.ordinal() * 100
+ GraduateRpcException.ErrorCode.REQUEST_INVALID.ordinal()
),
e.getMessage(),
"WebApplicationExceptionHandler"
);
} }
} }

@ -1,31 +1,20 @@
package wusthelper.internal.graduate.services; package wusthelper.internal.graduate.services;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.GraduateRpcException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
@Slf4j @Slf4j
public abstract class BaseService { public abstract class BaseService {
protected GraduateRpcException wrapApiException(ApiException e, GraduateRpcException.SubModuleCode subModuleCode) { protected RpcException wrapApiException(ApiException e) {
return switch (e.getCode()) { return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new GraduateRpcException( case NETWORK_EXCEPTION -> new RpcException(ServiceCode.NetworkError);
GraduateRpcException.TypeCode.NETWORK_EXCEPTION, case COOKIE_INVALID -> new RpcException(ServiceCode.CookieInvalid);
subModuleCode,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new GraduateRpcException(
GraduateRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
GraduateRpcException.ErrorCode.COOKIE_INVALID
);
default -> { default -> {
log.error("研究生:{}代理请求异常,异常未处理", subModuleCode.name()); log.error("研究生:代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield new GraduateRpcException( yield new RpcException(ServiceCode.Unknown);
GraduateRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
GraduateRpcException.ErrorCode.COOKIE_INVALID
);
} }
}; };
} }

@ -5,9 +5,9 @@ import cn.wustlinghang.mywust.core.request.service.graduate.GraduateCourseTableA
import cn.wustlinghang.mywust.data.global.Course; import cn.wustlinghang.mywust.data.global.Course;
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 wusthelper.internal.rpc.exception.GraduateRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -33,25 +33,17 @@ public class CourseTableService extends BaseService {
try { try {
return courseTableApiService.getPage(cookie, requestClientOption); return courseTableApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, GraduateRpcException.SubModuleCode.COURSE_TABLE); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.NetworkError);
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.COURSE_TABLE,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
public List<Course> parseCourseTable(String data) throws GraduateRpcException { public List<Course> parseCourseTable(String data) throws RpcException {
try { try {
return courseTableParser.parse(data); return courseTableParser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.ParseError);
GraduateRpcException.TypeCode.PARSE_EXCEPTION,
GraduateRpcException.SubModuleCode.COURSE_TABLE,
GraduateRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -3,10 +3,11 @@ package wusthelper.internal.graduate.services;
import cn.wustlinghang.mywust.core.request.service.auth.GraduateLogin; import cn.wustlinghang.mywust.core.request.service.auth.GraduateLogin;
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 wusthelper.internal.rpc.exception.GraduateRpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.config.inject.ConfigProperty;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
@ -29,59 +30,43 @@ public class LoginService {
this.maxRetryTimes = maxRetryTimes; this.maxRetryTimes = maxRetryTimes;
} }
public String login(String username, String password) throws GraduateRpcException { public String login(String username, String password) throws RpcException {
try { try {
return graduateLogin.getLoginCookie(username, password, maxRetryTimes, requestClientOption); return graduateLogin.getLoginCookie(username, password, maxRetryTimes, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.NetworkError);
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.AUTH,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
public boolean verify(String cookie) throws GraduateRpcException { public boolean verify(String cookie) throws RpcException {
try { try {
graduateLogin.checkCookies(cookie, requestClientOption); graduateLogin.checkCookies(cookie, requestClientOption);
return true; return true;
} catch (IOException e) { } catch (IOException e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.NetworkError);
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.AUTH,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ApiException e) { } catch (ApiException e) {
if (e.getCode() == ApiException.Code.NETWORK_EXCEPTION) { if (e.getCode() == ApiException.Code.NETWORK_EXCEPTION) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.NetworkError);
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.AUTH,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
} }
return false; return false;
} }
} }
private GraduateRpcException wrapApiException(ApiException e) { private RpcException wrapApiException(ApiException e) {
GraduateRpcException.ErrorCode errorCode = switch (e.getCode()) { int errorCode = switch (e.getCode()) {
case NETWORK_EXCEPTION -> GraduateRpcException.ErrorCode.NETWORK_ERROR; case NETWORK_EXCEPTION -> ServiceCode.NetworkError;
case GRADUATE_PASSWORD_WRONG -> GraduateRpcException.ErrorCode.AUTH_PASSWORD_WRONG; case GRADUATE_PASSWORD_WRONG -> ServiceCode.GraduatePasswordWrong;
case GRADUATE_CAPTCHA_WRONG -> GraduateRpcException.ErrorCode.AUTH_CAPTCHA_WRONG; case GRADUATE_CAPTCHA_WRONG -> ServiceCode.GraduateCaptchaWrong;
default -> { default -> {
log.error("研究生:登录代理请求异常,异常未处理"); log.error("研究生:登录代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield GraduateRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; yield ServiceCode.Unknown;
} }
}; };
return new GraduateRpcException( return new RpcException(errorCode);
GraduateRpcException.TypeCode.AUTH_EXCEPTION,
GraduateRpcException.SubModuleCode.AUTH,
errorCode
);
} }
} }

@ -5,9 +5,9 @@ import cn.wustlinghang.mywust.core.request.service.graduate.GraduateScoreApiServ
import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.mywust.data.global.Score;
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 wusthelper.internal.rpc.exception.GraduateRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -24,7 +24,7 @@ public class ScoreService extends BaseService {
GraduateScoreApiService scoreApiService, GraduateScoreApiService scoreApiService,
GraduateScoreParser scoreParser) { GraduateScoreParser scoreParser) {
this.requestClientOption = requestClientOption; this.requestClientOption = requestClientOption;
this.scoreApiService = scoreApiService; this.scoreApiService = scoreApiService;
this.scoreParser = scoreParser; this.scoreParser = scoreParser;
} }
@ -33,13 +33,9 @@ public class ScoreService extends BaseService {
try { try {
return scoreApiService.getPage(cookie, requestClientOption); return scoreApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, GraduateRpcException.SubModuleCode.SCORE); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.NetworkError);
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.SCORE,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
@ -47,11 +43,7 @@ public class ScoreService extends BaseService {
try { try {
return scoreParser.parse(data); return scoreParser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.ParseError);
GraduateRpcException.TypeCode.PARSE_EXCEPTION,
GraduateRpcException.SubModuleCode.SCORE,
GraduateRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -5,9 +5,9 @@ import cn.wustlinghang.mywust.core.request.service.graduate.GraduateStudentInfoA
import cn.wustlinghang.mywust.data.global.StudentInfo; import cn.wustlinghang.mywust.data.global.StudentInfo;
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 wusthelper.internal.rpc.exception.GraduateRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
@ -23,7 +23,7 @@ public class StudentInfoService extends BaseService {
GraduateStudentInfoApiService studentInfoApiService, GraduateStudentInfoApiService studentInfoApiService,
GraduateStudentInfoPageParser studentInfoPageParser) { GraduateStudentInfoPageParser studentInfoPageParser) {
this.requestClientOption = requestClientOption; this.requestClientOption = requestClientOption;
this.studentInfoApiService = studentInfoApiService; this.studentInfoApiService = studentInfoApiService;
this.studentInfoPageParser = studentInfoPageParser; this.studentInfoPageParser = studentInfoPageParser;
} }
@ -32,13 +32,9 @@ public class StudentInfoService extends BaseService {
try { try {
return studentInfoApiService.getPage(cookie, requestClientOption); return studentInfoApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, GraduateRpcException.SubModuleCode.STUDENT_INFO); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.NetworkError);
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.STUDENT_INFO,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
@ -46,11 +42,7 @@ public class StudentInfoService extends BaseService {
try { try {
return studentInfoPageParser.parse(data); return studentInfoPageParser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.ParseError);
GraduateRpcException.TypeCode.PARSE_EXCEPTION,
GraduateRpcException.SubModuleCode.STUDENT_INFO,
GraduateRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -4,9 +4,9 @@ import cn.wustlinghang.mywust.core.parser.graduate.GraduateTrainingPlanPageParse
import cn.wustlinghang.mywust.core.request.service.graduate.GraduateTrainingPlanApiService; import cn.wustlinghang.mywust.core.request.service.graduate.GraduateTrainingPlanApiService;
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 wusthelper.internal.rpc.exception.GraduateRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
@ -31,13 +31,9 @@ public class TrainingPlanService extends BaseService {
try { try {
return trainingPlanApiService.getPage(cookie, requestClientOption); return trainingPlanApiService.getPage(cookie, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, GraduateRpcException.SubModuleCode.TRAINING_PLAN); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.NetworkError);
GraduateRpcException.TypeCode.NETWORK_EXCEPTION,
GraduateRpcException.SubModuleCode.TRAINING_PLAN,
GraduateRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
@ -45,11 +41,7 @@ public class TrainingPlanService extends BaseService {
try { try {
return trainingPlanPageParser.parse(data); return trainingPlanPageParser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new GraduateRpcException( throw new RpcException(ServiceCode.ParseError);
GraduateRpcException.TypeCode.PARSE_EXCEPTION,
GraduateRpcException.SubModuleCode.TRAINING_PLAN,
GraduateRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -1,35 +1,31 @@
package wusthelper.internal.library.api.http.v1.handler; package wusthelper.internal.library.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode;
import wusthelper.internal.rpc.response.RpcResponseDto;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.response.RpcResponseDto;
public abstract class BaseExceptionHandler { public abstract class BaseExceptionHandler {
public static final String EXCEPTION_HEADER_KEY = "X-exception-handler"; public static final String EXCEPTION_HEADER_KEY = "X-exception-handler";
private static final ObjectMapper objectMapper = new ObjectMapper(); private static final ObjectMapper objectMapper = new ObjectMapper();
public Response toResponse(RpcCommonResponseCode code, String msg, String handlerName) { public Response toResponse(int code, String handlerName) {
return toResponse(code.getCode(), msg, handlerName); return toResponse(Response.Status.OK, code, handlerName);
}
public Response toResponse(int code, String msg, String handlerName) {
return toResponse(Response.Status.OK.getStatusCode(), code, msg, handlerName);
} }
public Response toResponse(int status, int code, String msg, String handlerName) { public Response toResponse(int status, int code, String handlerName) {
return toResponse(Response.Status.fromStatusCode(status), code, msg, handlerName); return toResponse(Response.Status.fromStatusCode(status), code, handlerName);
} }
public Response toResponse(Response.Status status, int code, String msg, String handlerName) { public Response toResponse(Response.Status status, int code, String handlerName) {
Object response; Object response;
try { try {
response = objectMapper.writeValueAsString(RpcResponseDto.error(code, msg)); response = objectMapper.writeValueAsString(RpcResponseDto.error(code));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
response = RpcResponseDto.error(RpcCommonResponseCode.ServerInternalError); response = RpcResponseDto.error(ServiceCode.ServerInternalError);
} }
return Response.status(status) return Response.status(status)

@ -1,21 +1,19 @@
package wusthelper.internal.library.api.http.v1.handler; package wusthelper.internal.library.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> { public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> {
@Override @Override
public Response toResponse(Exception e) { public Response toResponse(Exception e) {
log.error("未知异常:", e); log.error("未知异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.ServerInternalError, "DefaultExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"DefaultExceptionHandler"
);
} }
} }

@ -1,23 +1,21 @@
package wusthelper.internal.library.api.http.v1.handler; package wusthelper.internal.library.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import java.io.IOException; import java.io.IOException;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> { public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> {
@Override @Override
public Response toResponse(IOException e) { public Response toResponse(IOException e) {
log.error("IO异常:", e); log.error("IO异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.NetworkError, "IOExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"IOExceptionHandler"
);
} }
} }

@ -1,22 +1,20 @@
package wusthelper.internal.library.api.http.v1.handler; package wusthelper.internal.library.api.http.v1.handler;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> { public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> {
@Override @Override
public Response toResponse(ParseException e) { public Response toResponse(ParseException e) {
log.error("解析异常:", e); log.error("解析异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.ParseError, "ParseExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"ParseExceptionHandler"
);
} }
} }

@ -1,17 +1,19 @@
package wusthelper.internal.library.api.http.v1.handler; package wusthelper.internal.library.api.http.v1.handler;
import wusthelper.internal.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j;
import wusthelper.internal.rpc.exception.RpcException;
@Slf4j
@Provider @Provider
@ApplicationScoped
public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> { public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> {
@Override @Override
public Response toResponse(RpcException e) { public Response toResponse(RpcException e) {
return super.toResponse( log.debug("RpcException:", e);
e.getCode(), return super.toResponse(e.getCode(), "RpcExceptionHandler");
e.toString(),
"RpcExceptionHandler");
} }
} }

@ -1,22 +1,20 @@
package wusthelper.internal.library.api.http.v1.handler; package wusthelper.internal.library.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.ValidationException; import jakarta.validation.ValidationException;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class ValidationExceptionHandler extends BaseExceptionHandler public class ValidationExceptionHandler extends BaseExceptionHandler
implements ExceptionMapper<ValidationException> { implements ExceptionMapper<ValidationException> {
@Override @Override
public Response toResponse(ValidationException e) { public Response toResponse(ValidationException e) {
return super.toResponse( return super.toResponse(ServiceCode.ParamWrong, "ValidationExceptionHandler");
RpcCommonResponseCode.ParamWrong,
"参数错误:" + e.toString(),
"ValidationExceptionHandler"
);
} }
} }

@ -1,26 +1,17 @@
package wusthelper.internal.library.api.http.v1.handler; package wusthelper.internal.library.api.http.v1.handler;
import wusthelper.internal.rpc.exception.LibraryRpcException; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.internal.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;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import wusthelper.code.ServiceCode;
@Provider @Provider
@ApplicationScoped
public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> { public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> {
@Override @Override
public Response toResponse(WebApplicationException e) { public Response toResponse(WebApplicationException e) {
return super.toResponse( return super.toResponse(ServiceCode.RequestInvalid, "WebApplicationExceptionHandler");
e.getResponse().getStatus(),
RpcException.toIntCode(
LibraryRpcException.LIBRARY_MODULE,
LibraryRpcException.SubModuleCode.COMMON.ordinal(),
LibraryRpcException.TypeCode.OTHER_EXCEPTION.ordinal() * 100
+ LibraryRpcException.ErrorCode.REQUEST_INVALID.ordinal()
),
e.getMessage(),
"WebApplicationExceptionHandler"
);
} }
} }

@ -1,31 +1,20 @@
package wusthelper.internal.library.services; package wusthelper.internal.library.services;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.LibraryRpcException; import wusthelper.code.ServiceCode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.internal.rpc.exception.RpcException;
@Slf4j @Slf4j
public abstract class BaseService { public abstract class BaseService {
protected LibraryRpcException wrapApiException(ApiException e, LibraryRpcException.SubModuleCode subModuleCode) { protected RpcException wrapApiException(ApiException e) {
return switch (e.getCode()) { return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new LibraryRpcException( case NETWORK_EXCEPTION -> new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION, case COOKIE_INVALID -> new RpcException(ServiceCode.CookieInvalid);
subModuleCode,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new LibraryRpcException(
LibraryRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
LibraryRpcException.ErrorCode.COOKIE_INVALID
);
default -> { default -> {
log.error("图书馆:{}代理请求异常,异常未处理", subModuleCode.name()); log.error("图书馆:代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield new LibraryRpcException( yield new RpcException(ServiceCode.Unknown);
LibraryRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
LibraryRpcException.ErrorCode.COOKIE_INVALID
);
} }
}; };
} }

@ -2,9 +2,9 @@ package wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.BookCoverImageUrlApiService; import cn.wustlinghang.mywust.core.request.service.library.BookCoverImageUrlApiService;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.LibraryRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -22,13 +22,9 @@ public class BookCoverImageUrlService extends BaseService {
try { try {
return api.getBookCoverImageUrl(isbn); return api.getBookCoverImageUrl(isbn);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.COVER_IMAGE); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.COVER_IMAGE,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
@ -36,13 +32,9 @@ public class BookCoverImageUrlService extends BaseService {
try { try {
return api.getBookCoverImageUrl(isbnList); return api.getBookCoverImageUrl(isbnList);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.COVER_IMAGE); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.COVER_IMAGE,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }

@ -3,9 +3,9 @@ package wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.library.BookDetailApiService; import cn.wustlinghang.mywust.core.request.service.library.BookDetailApiService;
import cn.wustlinghang.mywust.data.library.parsed.BookDetail; import cn.wustlinghang.mywust.data.library.parsed.BookDetail;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.LibraryRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
@ -21,13 +21,9 @@ public class BookDetailService extends BaseService {
try { try {
return api.getBookDetail(bookId); return api.getBookDetail(bookId);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.BOOK_DETAIL); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.BOOK_DETAIL,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }

@ -4,7 +4,7 @@ import cn.wustlinghang.mywust.core.request.service.library.BookHoldingApiService
import cn.wustlinghang.mywust.data.library.parsed.BookHolding; import cn.wustlinghang.mywust.data.library.parsed.BookHolding;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.exception.LibraryRpcException; import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException; import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
@ -24,19 +24,11 @@ public class BookHoldingService extends BaseService {
try { try {
return api.getHoldingList(id); return api.getHoldingList(id);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.BOOK_HOLDING); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.BOOK_HOLDING,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) { } catch (ParseException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.ParseError);
LibraryRpcException.TypeCode.PARSE_EXCEPTION,
LibraryRpcException.SubModuleCode.BOOK_HOLDING,
LibraryRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -5,9 +5,9 @@ import cn.wustlinghang.mywust.data.library.PagingResult;
import cn.wustlinghang.mywust.data.library.origin.CurrentLoanBook; import cn.wustlinghang.mywust.data.library.origin.CurrentLoanBook;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.exception.LibraryRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -25,19 +25,11 @@ public class CurrentLoanService extends BaseService {
try { try {
return api.getCurrentLoan(cookie, page, pageSize); return api.getCurrentLoan(cookie, page, pageSize);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.CURRENT_LOAN); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.CURRENT_LOAN,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) { } catch (ParseException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.ParseError);
LibraryRpcException.TypeCode.PARSE_EXCEPTION,
LibraryRpcException.SubModuleCode.CURRENT_LOAN,
LibraryRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -5,10 +5,10 @@ import cn.wustlinghang.mywust.data.library.PagingResult;
import cn.wustlinghang.mywust.data.library.origin.HistoryLoanBook; import cn.wustlinghang.mywust.data.library.origin.HistoryLoanBook;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.exception.LibraryRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -27,20 +27,12 @@ public class LoanHistoryService extends BaseService {
try { try {
return api.getLoanHistory(cookie, page, pageSize); return api.getLoanHistory(cookie, page, pageSize);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.LOAN_HISTORY); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.LOAN_HISTORY,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) { } catch (ParseException e) {
log.error("解析错误:", e); log.error("解析错误:", e);
throw new LibraryRpcException( throw new RpcException(ServiceCode.ParseError);
LibraryRpcException.TypeCode.PARSE_EXCEPTION,
LibraryRpcException.SubModuleCode.LOAN_HISTORY,
LibraryRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -3,9 +3,10 @@ package wusthelper.internal.library.services;
import cn.wustlinghang.mywust.core.request.service.auth.LibraryLogin; import cn.wustlinghang.mywust.core.request.service.auth.LibraryLogin;
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 wusthelper.internal.rpc.exception.LibraryRpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
@ -21,53 +22,41 @@ public class LoginService {
this.libraryLogin = libraryLogin; this.libraryLogin = libraryLogin;
} }
public String login(String username, String password) throws LibraryRpcException { public String login(String username, String password) throws RpcException {
try { try {
return libraryLogin.getLoginCookie(username, password, option); return libraryLogin.getLoginCookie(username, password, option);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.AUTH,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
public boolean verify(String cookie) throws LibraryRpcException { public boolean verify(String cookie) throws RpcException {
try { try {
return libraryLogin.checkCookie(cookie, option); return libraryLogin.checkCookie(cookie, option);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.AUTH,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
private LibraryRpcException wrapApiException(ApiException e) { private RpcException wrapApiException(ApiException e) {
LibraryRpcException.ErrorCode errorCode = switch (e.getCode()) { int errorCode = switch (e.getCode()) {
case NETWORK_EXCEPTION -> LibraryRpcException.ErrorCode.NETWORK_ERROR; case NETWORK_EXCEPTION -> ServiceCode.NetworkError;
case UNI_LOGIN_PASSWORD_WRONG -> LibraryRpcException.ErrorCode.AUTH_PASSWORD_WRONG; case UNI_LOGIN_PASSWORD_WRONG -> ServiceCode.UndergradPasswordWrong;
case UNI_LOGIN_USER_NOT_EXISTS -> LibraryRpcException.ErrorCode.AUTH_USER_NOT_EXISTS; case UNI_LOGIN_USER_NOT_EXISTS -> ServiceCode.UndergradUserNotExists;
case UNI_LOGIN_USER_BANNED -> LibraryRpcException.ErrorCode.AUTH_USER_BANNED; case UNI_LOGIN_USER_BANNED -> ServiceCode.UndergradUserBanned;
case UNI_LOGIN_USER_DISABLED -> LibraryRpcException.ErrorCode.AUTH_USER_DISABLED; case UNI_LOGIN_USER_DISABLED -> ServiceCode.UndergradUserDisabled;
case UNI_LOGIN_NEED_CHANGE_PASSWORD -> LibraryRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD; case UNI_LOGIN_NEED_CHANGE_PASSWORD -> ServiceCode.UndergradPasswordNeedModify;
case UNI_LOGIN_USER_NOT_ONLY, UNI_LOGIN_NEED_TFA, UNI_LOGIN_NO_REGISTER case UNDERGRAD_BANNED_IN_EXCLUSIVE_TIME -> ServiceCode.UndergradBannedInExclusiveTime;
-> LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; case UNI_LOGIN_USER_NOT_ONLY, UNI_LOGIN_NO_REGISTER, UNI_LOGIN_NEED_TFA -> ServiceCode.Unknown;
default -> { default -> {
log.error("图书馆:登录代理请求异常,异常未处理"); log.error("图书馆:登录代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield LibraryRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; yield ServiceCode.Unknown;
} }
}; };
return new LibraryRpcException( return new RpcException(errorCode);
LibraryRpcException.TypeCode.AUTH_EXCEPTION,
LibraryRpcException.SubModuleCode.AUTH,
errorCode
);
} }
} }

@ -5,9 +5,9 @@ import cn.wustlinghang.mywust.data.library.PagingResult;
import cn.wustlinghang.mywust.data.library.origin.BaseLoanBook; import cn.wustlinghang.mywust.data.library.origin.BaseLoanBook;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.exception.LibraryRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -25,19 +25,11 @@ public class OverdueSoonService extends BaseService {
try { try {
return api.getOverdueSoon(cookie, page, pageSize); return api.getOverdueSoon(cookie, page, pageSize);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.OVERDUE_SOON); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.OVERDUE_SOON,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) { } catch (ParseException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.ParseError);
LibraryRpcException.TypeCode.PARSE_EXCEPTION,
LibraryRpcException.SubModuleCode.OVERDUE_SOON,
LibraryRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -5,9 +5,9 @@ import cn.wustlinghang.mywust.data.library.PagingResult;
import cn.wustlinghang.mywust.data.library.origin.BookSearchResult; import cn.wustlinghang.mywust.data.library.origin.BookSearchResult;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.exception.LibraryRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -25,19 +25,11 @@ public class SearchService extends BaseService {
try { try {
return api.search(keyword, page, pageSize); return api.search(keyword, page, pageSize);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, LibraryRpcException.SubModuleCode.SEARCH); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.NetworkError);
LibraryRpcException.TypeCode.NETWORK_EXCEPTION,
LibraryRpcException.SubModuleCode.SEARCH,
LibraryRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) { } catch (ParseException e) {
throw new LibraryRpcException( throw new RpcException(ServiceCode.ParseError);
LibraryRpcException.TypeCode.PARSE_EXCEPTION,
LibraryRpcException.SubModuleCode.SEARCH,
LibraryRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -1,35 +1,31 @@
package wusthelper.internal.physics.api.http.v1.handler; package wusthelper.internal.physics.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode;
import wusthelper.internal.rpc.response.RpcResponseDto;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.response.RpcResponseDto;
public abstract class BaseExceptionHandler { public abstract class BaseExceptionHandler {
public static final String EXCEPTION_HEADER_KEY = "X-exception-handler"; public static final String EXCEPTION_HEADER_KEY = "X-exception-handler";
private static final ObjectMapper objectMapper = new ObjectMapper(); private static final ObjectMapper objectMapper = new ObjectMapper();
public Response toResponse(RpcCommonResponseCode code, String msg, String handlerName) { public Response toResponse(int code, String handlerName) {
return toResponse(code.getCode(), msg, handlerName); return toResponse(Response.Status.OK, code, handlerName);
}
public Response toResponse(int code, String msg, String handlerName) {
return toResponse(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code, msg, handlerName);
} }
public Response toResponse(int status, int code, String msg, String handlerName) { public Response toResponse(int status, int code, String handlerName) {
return toResponse(Response.Status.fromStatusCode(status), code, msg, handlerName); return toResponse(Response.Status.fromStatusCode(status), code, handlerName);
} }
public Response toResponse(Response.Status status, int code, String msg, String handlerName) { public Response toResponse(Response.Status status, int code, String handlerName) {
Object response; Object response;
try { try {
response = objectMapper.writeValueAsString(RpcResponseDto.error(code, msg)); response = objectMapper.writeValueAsString(RpcResponseDto.error(code));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
response = RpcResponseDto.error(RpcCommonResponseCode.ServerInternalError); response = RpcResponseDto.error(ServiceCode.ServerInternalError);
} }
return Response.status(status) return Response.status(status)

@ -1,21 +1,19 @@
package wusthelper.internal.physics.api.http.v1.handler; package wusthelper.internal.physics.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> { public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> {
@Override @Override
public Response toResponse(Exception e) { public Response toResponse(Exception e) {
log.error("未知异常:", e); log.error("未知异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.ServerInternalError, "DefaultExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"DefaultExceptionHandler"
);
} }
} }

@ -1,23 +1,21 @@
package wusthelper.internal.physics.api.http.v1.handler; package wusthelper.internal.physics.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import java.io.IOException; import java.io.IOException;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> { public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> {
@Override @Override
public Response toResponse(IOException e) { public Response toResponse(IOException e) {
log.error("IO异常:", e); log.error("IO异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.NetworkError, "IOExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"IOExceptionHandler"
);
} }
} }

@ -1,22 +1,20 @@
package wusthelper.internal.physics.api.http.v1.handler; package wusthelper.internal.physics.api.http.v1.handler;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> { public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> {
@Override @Override
public Response toResponse(ParseException e) { public Response toResponse(ParseException e) {
log.error("解析异常:", e); log.error("解析异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.ParseError, "ParseExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"ParseExceptionHandler"
);
} }
} }

@ -1,17 +1,19 @@
package wusthelper.internal.physics.api.http.v1.handler; package wusthelper.internal.physics.api.http.v1.handler;
import wusthelper.internal.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j;
import wusthelper.internal.rpc.exception.RpcException;
@Slf4j
@Provider @Provider
@ApplicationScoped
public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> { public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> {
@Override @Override
public Response toResponse(RpcException e) { public Response toResponse(RpcException e) {
return super.toResponse( log.debug("RpcException:", e);
e.getCode(), return super.toResponse(e.getCode(), "RpcExceptionHandler");
e.toString(),
"RpcExceptionHandler");
} }
} }

@ -1,22 +1,20 @@
package wusthelper.internal.physics.api.http.v1.handler; package wusthelper.internal.physics.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.ValidationException; import jakarta.validation.ValidationException;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class ValidationExceptionHandler extends BaseExceptionHandler public class ValidationExceptionHandler extends BaseExceptionHandler
implements ExceptionMapper<ValidationException> { implements ExceptionMapper<ValidationException> {
@Override @Override
public Response toResponse(ValidationException e) { public Response toResponse(ValidationException e) {
return super.toResponse( return super.toResponse(ServiceCode.ParamWrong, "ValidationExceptionHandler");
RpcCommonResponseCode.ParamWrong,
"参数错误:" + e.toString(),
"ValidationExceptionHandler"
);
} }
} }

@ -1,26 +1,17 @@
package wusthelper.internal.physics.api.http.v1.handler; package wusthelper.internal.physics.api.http.v1.handler;
import wusthelper.internal.rpc.exception.PhysicsRpcException; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.internal.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;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import wusthelper.code.ServiceCode;
@Provider @Provider
@ApplicationScoped
public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> { public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> {
@Override @Override
public Response toResponse(WebApplicationException e) { public Response toResponse(WebApplicationException e) {
return super.toResponse( return super.toResponse(ServiceCode.RequestInvalid, "WebApplicationExceptionHandler");
e.getResponse().getStatus(),
RpcException.toIntCode(
PhysicsRpcException.PHYSICS_MODULE,
PhysicsRpcException.SubModuleCode.COMMON.ordinal(),
PhysicsRpcException.TypeCode.OTHER_EXCEPTION.ordinal() * 100
+ PhysicsRpcException.ErrorCode.REQUEST_INVALID.ordinal()
),
e.getMessage(),
"WebApplicationExceptionHandler"
);
} }
} }

@ -1,31 +1,20 @@
package wusthelper.internal.physics.services; package wusthelper.internal.physics.services;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.PhysicsRpcException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
@Slf4j @Slf4j
public abstract class BaseService { public abstract class BaseService {
protected PhysicsRpcException wrapApiException(ApiException e, PhysicsRpcException.SubModuleCode subModuleCode) { protected RpcException wrapApiException(ApiException e) {
return switch (e.getCode()) { return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new PhysicsRpcException( case NETWORK_EXCEPTION -> new RpcException(ServiceCode.NetworkError);
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION, case COOKIE_INVALID -> new RpcException(ServiceCode.CookieInvalid);
subModuleCode,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new PhysicsRpcException(
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
PhysicsRpcException.ErrorCode.COOKIE_INVALID
);
default -> { default -> {
log.error("物理实验:{}代理请求异常,异常未处理", subModuleCode.name()); log.error("物理实验:代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield new PhysicsRpcException( yield new RpcException(ServiceCode.Unknown);
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
PhysicsRpcException.ErrorCode.COOKIE_INVALID
);
} }
}; };
} }

@ -5,9 +5,9 @@ import cn.wustlinghang.mywust.core.request.service.physics.PhysicsCourseApiServi
import cn.wustlinghang.mywust.data.physics.PhysicsCourse; import cn.wustlinghang.mywust.data.physics.PhysicsCourse;
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 wusthelper.internal.rpc.exception.PhysicsRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -33,25 +33,17 @@ public class CourseTableService extends BaseService {
try { try {
return agent.getPage(cookie, requestClientOption); return agent.getPage(cookie, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.COURSE_TABLE); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new PhysicsRpcException( throw new RpcException(ServiceCode.NetworkError);
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.COURSE_TABLE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
public List<PhysicsCourse> parseCourseTable(String data) throws PhysicsRpcException { public List<PhysicsCourse> parseCourseTable(String data) throws RpcException {
try { try {
return parser.parse(data); return parser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new PhysicsRpcException( throw new RpcException(ServiceCode.ParseError);
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.COURSE_TABLE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -4,9 +4,10 @@ import cn.wustlinghang.mywust.core.request.service.auth.PhysicsLogin;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.RequestClientOption; import cn.wustlinghang.mywust.network.RequestClientOption;
import wusthelper.internal.rpc.exception.PhysicsRpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
@ -23,55 +24,39 @@ public class LoginService {
this.physicsLogin = physicsLogin; this.physicsLogin = physicsLogin;
} }
public String login(String username, String password) throws PhysicsRpcException { public String login(String username, String password) throws RpcException {
try { try {
return physicsLogin.getLoginCookie(username, password, option); return physicsLogin.getLoginCookie(username, password, option);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new PhysicsRpcException( throw new RpcException(ServiceCode.NetworkError);
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.AUTH,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) { } catch (ParseException e) {
log.error("物理实验:登录时出现页面参数解析问题", e); log.error("物理实验:登录时出现页面参数解析问题", e);
throw new PhysicsRpcException( throw new RpcException(ServiceCode.ParseError);
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.AUTH,
PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR
);
} }
} }
public boolean verify(String cookie) throws PhysicsRpcException { public boolean verify(String cookie) throws RpcException {
try { try {
return physicsLogin.checkCookie(cookie, option); return physicsLogin.checkCookie(cookie, option);
} catch (IOException e) { } catch (IOException e) {
throw new PhysicsRpcException( throw new RpcException(ServiceCode.NetworkError);
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.AUTH,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
private PhysicsRpcException wrapApiException(ApiException e) { private RpcException wrapApiException(ApiException e) {
PhysicsRpcException.ErrorCode errorCode = switch (e.getCode()) { int errorCode = switch (e.getCode()) {
case NETWORK_EXCEPTION -> PhysicsRpcException.ErrorCode.NETWORK_ERROR; case NETWORK_EXCEPTION -> ServiceCode.NetworkError;
case PHYSICS_PASSWORD_WRONG -> PhysicsRpcException.ErrorCode.AUTH_PASSWORD_WRONG; case PHYSICS_PASSWORD_WRONG -> ServiceCode.PhysicsPasswordWrong;
case PHYSICS_NOT_CURRENT_TERM -> PhysicsRpcException.ErrorCode.AUTH_USER_NOT_CURRENT_TERM; case PHYSICS_NOT_CURRENT_TERM -> ServiceCode.PhysicsUserNotCurrentTerm;
default -> { default -> {
log.error("物理实验:登录代理请求异常,异常未处理"); log.error("物理实验:登录代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield PhysicsRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; yield ServiceCode.Unknown;
} }
}; };
return new PhysicsRpcException( return new RpcException(errorCode);
PhysicsRpcException.TypeCode.AUTH_EXCEPTION,
PhysicsRpcException.SubModuleCode.AUTH,
errorCode
);
} }
} }

@ -6,9 +6,9 @@ import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import cn.wustlinghang.mywust.network.RequestClientOption; import cn.wustlinghang.mywust.network.RequestClientOption;
import wusthelper.internal.rpc.exception.PhysicsRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,19 +35,11 @@ public class ScoreService extends BaseService {
try { try {
return agent.getAllPages(cookie, requestClientOption); return agent.getAllPages(cookie, requestClientOption);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, PhysicsRpcException.SubModuleCode.SCORE); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new PhysicsRpcException( throw new RpcException(ServiceCode.NetworkError);
PhysicsRpcException.TypeCode.NETWORK_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.NETWORK_ERROR
);
} catch (ParseException e) { } catch (ParseException e) {
throw new PhysicsRpcException( throw new RpcException(ServiceCode.ParseError);
PhysicsRpcException.TypeCode.OTHER_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
@ -55,14 +47,10 @@ public class ScoreService extends BaseService {
public List<Score> parseScore(String data) throws RpcException { public List<Score> parseScore(String data) throws RpcException {
try { try {
return parser.parse(data); return parser.parse(data);
} catch (PhysicsRpcException e) { } catch (RpcException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new PhysicsRpcException( throw new RpcException(ServiceCode.ParseError);
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
@ -74,14 +62,10 @@ public class ScoreService extends BaseService {
} }
return scores; return scores;
} catch (PhysicsRpcException e) { } catch (RpcException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new PhysicsRpcException( throw new RpcException(ServiceCode.ParseError);
PhysicsRpcException.TypeCode.PARSE_EXCEPTION,
PhysicsRpcException.SubModuleCode.SCORE,
PhysicsRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -1,6 +1,6 @@
package wusthelper.internal.undergrad.api.http.v1.handler; package wusthelper.internal.undergrad.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -12,24 +12,20 @@ public abstract class BaseExceptionHandler {
private static final ObjectMapper objectMapper = new ObjectMapper(); private static final ObjectMapper objectMapper = new ObjectMapper();
public Response toResponse(RpcCommonResponseCode code, String msg, String handlerName) { public Response toResponse(int code, String handlerName) {
return toResponse(code.getCode(), msg, handlerName); return toResponse(Response.Status.OK, code, handlerName);
} }
public Response toResponse(int code, String msg, String handlerName) { public Response toResponse(int status, int code, String handlerName) {
return toResponse(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code, msg, handlerName); return toResponse(Response.Status.fromStatusCode(status), code, handlerName);
} }
public Response toResponse(int status, int code, String msg, String handlerName) { public Response toResponse(Response.Status status, int code, String handlerName) {
return toResponse(Response.Status.fromStatusCode(status), code, msg, handlerName);
}
public Response toResponse(Response.Status status, int code, String msg, String handlerName) {
Object response; Object response;
try { try {
response = objectMapper.writeValueAsString(RpcResponseDto.error(code, msg)); response = objectMapper.writeValueAsString(RpcResponseDto.error(code));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
response = RpcResponseDto.error(RpcCommonResponseCode.ServerInternalError); response = RpcResponseDto.error(ServiceCode.ServerInternalError);
} }
return Response.status(status) return Response.status(status)

@ -1,21 +1,19 @@
package wusthelper.internal.undergrad.api.http.v1.handler; package wusthelper.internal.undergrad.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> { public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> {
@Override @Override
public Response toResponse(Exception e) { public Response toResponse(Exception e) {
log.error("未知异常:", e); log.error("未知异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.ServerInternalError, "DefaultExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"DefaultExceptionHandler"
);
} }
} }

@ -1,23 +1,21 @@
package wusthelper.internal.undergrad.api.http.v1.handler; package wusthelper.internal.undergrad.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import java.io.IOException; import java.io.IOException;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> { public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> {
@Override @Override
public Response toResponse(IOException e) { public Response toResponse(IOException e) {
log.error("IO异常:", e); log.error("IO异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.NetworkError, "IOExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"IOExceptionHandler"
);
} }
} }

@ -1,7 +1,8 @@
package wusthelper.internal.undergrad.api.http.v1.handler; package wusthelper.internal.undergrad.api.http.v1.handler;
import cn.wustlinghang.mywust.exception.ParseException; import cn.wustlinghang.mywust.exception.ParseException;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.code.ServiceCode;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
@ -9,14 +10,11 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> { public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> {
@Override @Override
public Response toResponse(ParseException e) { public Response toResponse(ParseException e) {
log.error("解析异常:", e); log.error("解析异常:", e);
return super.toResponse( return super.toResponse(ServiceCode.ParseError, "ParseExceptionHandler");
RpcCommonResponseCode.ServerInternalError,
e.toString(),
"ParseExceptionHandler"
);
} }
} }

@ -1,17 +1,19 @@
package wusthelper.internal.undergrad.api.http.v1.handler; package wusthelper.internal.undergrad.api.http.v1.handler;
import wusthelper.internal.rpc.exception.RpcException; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j;
import wusthelper.internal.rpc.exception.RpcException;
@Slf4j
@Provider @Provider
@ApplicationScoped
public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> { public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> {
@Override @Override
public Response toResponse(RpcException e) { public Response toResponse(RpcException e) {
return super.toResponse( log.debug("RpcException:", e);
e.getCode(), return super.toResponse(e.getCode(), "RpcExceptionHandler");
e.toString(),
"RpcExceptionHandler");
} }
} }

@ -1,22 +1,20 @@
package wusthelper.internal.undergrad.api.http.v1.handler; package wusthelper.internal.undergrad.api.http.v1.handler;
import wusthelper.internal.rpc.response.RpcCommonResponseCode; import jakarta.enterprise.context.ApplicationScoped;
import jakarta.validation.ValidationException; import jakarta.validation.ValidationException;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
@Slf4j @Slf4j
@Provider @Provider
@ApplicationScoped
public class ValidationExceptionHandler extends BaseExceptionHandler public class ValidationExceptionHandler extends BaseExceptionHandler
implements ExceptionMapper<ValidationException> { implements ExceptionMapper<ValidationException> {
@Override @Override
public Response toResponse(ValidationException e) { public Response toResponse(ValidationException e) {
return super.toResponse( return super.toResponse(ServiceCode.ParamWrong, "ValidationExceptionHandler");
RpcCommonResponseCode.ParamWrong,
"参数错误:" + e.toString(),
"ValidationExceptionHandler"
);
} }
} }

@ -1,26 +1,17 @@
package wusthelper.internal.undergrad.api.http.v1.handler; package wusthelper.internal.undergrad.api.http.v1.handler;
import wusthelper.internal.rpc.exception.UndergradRpcException; import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.internal.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;
import jakarta.ws.rs.ext.ExceptionMapper; import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider; import jakarta.ws.rs.ext.Provider;
import wusthelper.code.ServiceCode;
@Provider @Provider
@ApplicationScoped
public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> { public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> {
@Override @Override
public Response toResponse(WebApplicationException e) { public Response toResponse(WebApplicationException e) {
return super.toResponse( return super.toResponse(ServiceCode.RequestInvalid, "WebApplicationExceptionHandler");
e.getResponse().getStatus(),
RpcException.toIntCode(
UndergradRpcException.UNDERGRAD_MODULE,
UndergradRpcException.SubModuleCode.COMMON.ordinal(),
UndergradRpcException.TypeCode.OTHER_EXCEPTION.ordinal() * 100
+ UndergradRpcException.ErrorCode.REQUEST_INVALID.ordinal()
),
e.getMessage(),
"WebApplicationExceptionHandler"
);
} }
} }

@ -1,5 +1,6 @@
package wusthelper.internal.undergrad.api.http.v1.interceptor; package wusthelper.internal.undergrad.api.http.v1.interceptor;
import jakarta.enterprise.context.ApplicationScoped;
import wusthelper.internal.undergrad.api.http.v1.handler.BaseExceptionHandler; import wusthelper.internal.undergrad.api.http.v1.handler.BaseExceptionHandler;
import wusthelper.internal.rpc.response.RpcResponseDto; import wusthelper.internal.rpc.response.RpcResponseDto;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -13,6 +14,7 @@ import jakarta.ws.rs.ext.WriterInterceptorContext;
import java.io.IOException; import java.io.IOException;
@Provider @Provider
@ApplicationScoped
public class ResponseWrapperInterceptor implements WriterInterceptor { public class ResponseWrapperInterceptor implements WriterInterceptor {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
@ -22,6 +24,7 @@ public class ResponseWrapperInterceptor implements WriterInterceptor {
@Override @Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
System.out.println("ResponseWrapperInterceptor.aroundWriteTo");
boolean hasException = context.getHeaders().get(BaseExceptionHandler.EXCEPTION_HEADER_KEY) != null; boolean hasException = context.getHeaders().get(BaseExceptionHandler.EXCEPTION_HEADER_KEY) != null;
if (!hasException) { if (!hasException) {
Object data = context.getEntity(); Object data = context.getEntity();

@ -28,6 +28,7 @@ public class Register {
.consulAddress(rpcConfig.getConsulAddress()) .consulAddress(rpcConfig.getConsulAddress())
.localServicePort(rpcConfig.getLocalServicePort()) .localServicePort(rpcConfig.getLocalServicePort())
.serviceName(rpcConfig.getServiceName()) .serviceName(rpcConfig.getServiceName())
.token("")
.build(); .build();
this.register = new FrpConsulRegister(registerConfig, frpConfig, requester, objectMapper); this.register = new FrpConsulRegister(registerConfig, frpConfig, requester, objectMapper);

@ -1,31 +1,20 @@
package wusthelper.internal.undergrad.services; package wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.UndergradRpcException; import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public abstract class BaseService { public abstract class BaseService {
protected UndergradRpcException wrapApiException(ApiException e, UndergradRpcException.SubModuleCode subModuleCode) { protected RpcException wrapApiException(ApiException e) {
return switch (e.getCode()) { return switch (e.getCode()) {
case NETWORK_EXCEPTION -> new UndergradRpcException( case NETWORK_EXCEPTION -> new RpcException(ServiceCode.NetworkError);
UndergradRpcException.TypeCode.NETWORK_EXCEPTION, case COOKIE_INVALID -> new RpcException(ServiceCode.CookieInvalid);
subModuleCode,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
case COOKIE_INVALID -> new UndergradRpcException(
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.COOKIE_INVALID
);
default -> { default -> {
log.error("本科生:{}代理请求异常,异常未处理", subModuleCode.name()); log.error("本科生:代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield new UndergradRpcException( yield new RpcException(ServiceCode.Unknown);
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
subModuleCode,
UndergradRpcException.ErrorCode.COOKIE_INVALID
);
} }
}; };
} }

@ -4,13 +4,15 @@ import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCourseTablePars
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCourseTableApiService; import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCourseTableApiService;
import cn.wustlinghang.mywust.data.global.Course; import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.UndergradRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@Slf4j
@ApplicationScoped @ApplicationScoped
public class CourseTableService extends BaseService { public class CourseTableService extends BaseService {
private final UndergradCourseTableParser courseTableParser; private final UndergradCourseTableParser courseTableParser;
@ -26,33 +28,22 @@ public class CourseTableService extends BaseService {
try { try {
return courseTableApiService.getPage(term, cookie); return courseTableApiService.getPage(term, cookie);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.COURSE_TABLE); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new UndergradRpcException( throw new RpcException(ServiceCode.NetworkError);
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
public List<Course> parseCourseTable(String data) throws UndergradRpcException { public List<Course> parseCourseTable(String data) throws RpcException {
try { try {
if (data.contains("评教")) { if (data.contains("评教")) {
throw new UndergradRpcException( throw new RpcException(ServiceCode.UndergradNeedEvaluate);
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.NEED_EVALUATE
);
} }
return courseTableParser.parse(data); return courseTableParser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new UndergradRpcException( log.error("解析错误:", e);
UndergradRpcException.TypeCode.PARSE_EXCEPTION, throw new RpcException(ServiceCode.ParseError);
UndergradRpcException.SubModuleCode.COURSE_TABLE,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -4,18 +4,21 @@ import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradCreditStatusPar
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCreditStatusApiService; import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradCreditStatusApiService;
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 wusthelper.internal.rpc.exception.UndergradRpcException;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import java.io.IOException; import java.io.IOException;
@Slf4j
@ApplicationScoped @ApplicationScoped
public class CreditStatusService extends BaseService { public class CreditStatusService extends BaseService {
private final UndergradCreditStatusApiService creditStatusApiService; private final UndergradCreditStatusApiService creditStatusApiService;
private final UndergradCreditStatusParser creditStatusParser; private final UndergradCreditStatusParser creditStatusParser;
private final RequestClientOption requestClientOption; private final RequestClientOption requestClientOption;
public CreditStatusService(UndergradCreditStatusApiService creditStatusApiService, public CreditStatusService(UndergradCreditStatusApiService creditStatusApiService,
UndergradCreditStatusParser creditStatusParser, UndergradCreditStatusParser creditStatusParser,
RequestClientOption requestClientOption) { RequestClientOption requestClientOption) {
@ -29,13 +32,9 @@ public class CreditStatusService extends BaseService {
try { try {
return creditStatusApiService.getPage(cookie, requestClientOption, false); return creditStatusApiService.getPage(cookie, requestClientOption, false);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.CREDIT_STATUS); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new UndergradRpcException( throw new RpcException(ServiceCode.NetworkError);
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.CREDIT_STATUS,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
@ -43,11 +42,8 @@ public class CreditStatusService extends BaseService {
try { try {
return creditStatusParser.parse(data); return creditStatusParser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new UndergradRpcException( log.error("解析错误:", e);
UndergradRpcException.TypeCode.PARSE_EXCEPTION, throw new RpcException(ServiceCode.ParseError);
UndergradRpcException.SubModuleCode.CREDIT_STATUS,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -2,12 +2,14 @@ package wusthelper.internal.undergrad.services;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.UndergradRpcException; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException; import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException; import java.io.IOException;
@Slf4j
@ApplicationScoped @ApplicationScoped
public class ExamActivitiesService extends BaseService { public class ExamActivitiesService extends BaseService {
private final UndergradExamDelayApiService examDelayApiService; private final UndergradExamDelayApiService examDelayApiService;
@ -21,13 +23,10 @@ public class ExamActivitiesService extends BaseService {
try { try {
return examDelayApiService.getActivities(term, cookie); return examDelayApiService.getActivities(term, cookie);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new UndergradRpcException( log.error("解析错误:", e);
UndergradRpcException.TypeCode.NETWORK_EXCEPTION, throw new RpcException(ServiceCode.NetworkError);
UndergradRpcException.SubModuleCode.EXAM_ACTIVITIES,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }

@ -4,13 +4,15 @@ import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradExamDelayParser
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService; import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradExamDelayApiService;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication; import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.UndergradRpcException; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException; import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@Slf4j
@ApplicationScoped @ApplicationScoped
public class ExamDelayApplicationService extends BaseService { public class ExamDelayApplicationService extends BaseService {
private final UndergradExamDelayApiService examDelayApiService; private final UndergradExamDelayApiService examDelayApiService;
@ -27,13 +29,9 @@ public class ExamDelayApplicationService extends BaseService {
try { try {
return examDelayApiService.getPage(term, activityId, cookie); return examDelayApiService.getPage(term, activityId, cookie);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new UndergradRpcException( throw new RpcException(ServiceCode.NetworkError);
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
@ -41,11 +39,8 @@ public class ExamDelayApplicationService extends BaseService {
try { try {
return examDelayParser.parse(data); return examDelayParser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new UndergradRpcException( log.error("解析错误:", e);
UndergradRpcException.TypeCode.PARSE_EXCEPTION, throw new RpcException(ServiceCode.ParseError);
UndergradRpcException.SubModuleCode.EXAM_DELAY_APPLICATION,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

@ -3,7 +3,8 @@ package wusthelper.internal.undergrad.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 wusthelper.internal.rpc.exception.UndergradRpcException; import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -21,7 +22,7 @@ public class LoginService {
this.undergraduateLogin = undergraduateLogin; this.undergraduateLogin = undergraduateLogin;
} }
public String login(String username, String password, boolean legacy) throws UndergradRpcException { public String login(String username, String password, boolean legacy) throws RpcException {
try { try {
if (legacy) { if (legacy) {
return undergraduateLogin.getLoginCookieLegacy(username, password, option); return undergraduateLogin.getLoginCookieLegacy(username, password, option);
@ -31,50 +32,38 @@ public class LoginService {
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new UndergradRpcException( throw new RpcException(ServiceCode.NetworkError);
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
public boolean verify(String cookie) throws UndergradRpcException { public boolean verify(String cookie) throws RpcException {
try { try {
return undergraduateLogin.testCookie(cookie); return undergraduateLogin.testCookie(cookie);
} catch (ApiException e) { } catch (ApiException e) {
return false; return false;
} catch (IOException e) { } catch (IOException e) {
throw new UndergradRpcException( throw new RpcException(ServiceCode.NetworkError);
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
private UndergradRpcException wrapApiException(ApiException e) { private RpcException wrapApiException(ApiException e) {
UndergradRpcException.ErrorCode errorCode = switch (e.getCode()) { int code = switch (e.getCode()) {
case NETWORK_EXCEPTION -> UndergradRpcException.ErrorCode.NETWORK_ERROR; case NETWORK_EXCEPTION -> ServiceCode.NetworkError;
case UNI_LOGIN_PASSWORD_WRONG -> UndergradRpcException.ErrorCode.AUTH_PASSWORD_WRONG; case UNI_LOGIN_PASSWORD_WRONG -> ServiceCode.UndergradPasswordWrong;
case UNI_LOGIN_USER_NOT_EXISTS -> UndergradRpcException.ErrorCode.AUTH_USER_NOT_EXISTS; case UNI_LOGIN_USER_NOT_EXISTS -> ServiceCode.UndergradUserNotExists;
case UNI_LOGIN_USER_BANNED -> UndergradRpcException.ErrorCode.AUTH_USER_BANNED; case UNI_LOGIN_USER_BANNED -> ServiceCode.UndergradUserBanned;
case UNI_LOGIN_USER_DISABLED -> UndergradRpcException.ErrorCode.AUTH_USER_DISABLED; case UNI_LOGIN_USER_DISABLED -> ServiceCode.UndergradUserDisabled;
case UNI_LOGIN_NEED_CHANGE_PASSWORD -> UndergradRpcException.ErrorCode.AUTH_NEED_CHANGE_PASSWORD; case UNI_LOGIN_NEED_CHANGE_PASSWORD -> ServiceCode.UndergradPasswordNeedModify;
case UNDERGRAD_BANNED_IN_EXCLUSIVE_TIME -> UndergradRpcException.ErrorCode.AUTH_BANNED_IN_EXCLUSIVE_TIME; case UNDERGRAD_BANNED_IN_EXCLUSIVE_TIME -> ServiceCode.UndergradBannedInExclusiveTime;
case UNI_LOGIN_USER_NOT_ONLY, UNI_LOGIN_NO_REGISTER, UNI_LOGIN_NEED_TFA case UNI_LOGIN_USER_NOT_ONLY, UNI_LOGIN_NO_REGISTER, UNI_LOGIN_NEED_TFA
-> UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; -> ServiceCode.Unknown;
default -> { default -> {
log.error("本科生:登录代理请求异常,异常未处理"); log.error("本科生:登录代理请求异常,异常未处理");
log.error("异常:", e); log.error("异常:", e);
yield UndergradRpcException.ErrorCode.AUTH_UNKNOWN_ERROR; yield ServiceCode.Unknown;
} }
}; };
return new UndergradRpcException( return new RpcException(code);
UndergradRpcException.TypeCode.AUTH_EXCEPTION,
UndergradRpcException.SubModuleCode.AUTH,
errorCode
);
} }
} }

@ -4,13 +4,15 @@ import cn.wustlinghang.mywust.core.parser.undergraduate.UndergradScoreParser;
import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradScoreApiService; import cn.wustlinghang.mywust.core.request.service.undergraduate.UndergradScoreApiService;
import cn.wustlinghang.mywust.data.global.Score; import cn.wustlinghang.mywust.data.global.Score;
import cn.wustlinghang.mywust.exception.ApiException; import cn.wustlinghang.mywust.exception.ApiException;
import wusthelper.internal.rpc.exception.UndergradRpcException; import lombok.extern.slf4j.Slf4j;
import wusthelper.code.ServiceCode;
import wusthelper.internal.rpc.exception.RpcException; import wusthelper.internal.rpc.exception.RpcException;
import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.ApplicationScoped;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@Slf4j
@ApplicationScoped @ApplicationScoped
public class ScoreService extends BaseService { public class ScoreService extends BaseService {
private final UndergradScoreApiService scoreApiService; private final UndergradScoreApiService scoreApiService;
@ -26,33 +28,22 @@ public class ScoreService extends BaseService {
try { try {
return scoreApiService.getPage(cookie); return scoreApiService.getPage(cookie);
} catch (ApiException e) { } catch (ApiException e) {
throw wrapApiException(e, UndergradRpcException.SubModuleCode.SCORE); throw wrapApiException(e);
} catch (IOException e) { } catch (IOException e) {
throw new UndergradRpcException( throw new RpcException(ServiceCode.NetworkError);
UndergradRpcException.TypeCode.NETWORK_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.NETWORK_ERROR
);
} }
} }
public List<Score> parseScore(String data) throws RpcException { public List<Score> parseScore(String data) throws RpcException {
try { try {
if (data.contains("评教")) { if (data.contains("评教")) {
throw new UndergradRpcException( throw new RpcException(ServiceCode.UndergradNeedEvaluate);
UndergradRpcException.TypeCode.PARSE_EXCEPTION,
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.NEED_EVALUATE
);
} }
return scoreParser.parse(data); return scoreParser.parse(data);
} catch (Exception e) { } catch (Exception e) {
throw new UndergradRpcException( log.error("解析错误:", e);
UndergradRpcException.TypeCode.PARSE_EXCEPTION, throw new RpcException(ServiceCode.ParseError);
UndergradRpcException.SubModuleCode.SCORE,
UndergradRpcException.ErrorCode.PARSE_ERROR
);
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save