main
parent
d714db0891
commit
eb93192a7b
@ -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); |
||||
} |
||||
|
||||
/** |
||||
* 处理参数类型错误的请求异常2(Json解析错误) |
||||
* |
||||
* @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); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
||||
} |
@ -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,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; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public record RpcResponseDto<T>(int code, 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() { |
||||
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); |
||||
} |
||||
|
||||
public static <T> RpcResponseDto<T> error(RpcCommonResponseCode code) { |
||||
return error(code.getCode(), code.getMessage()); |
||||
} |
||||
} |
@ -1,21 +1,19 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> { |
||||
@Override |
||||
public Response toResponse(Exception e) { |
||||
log.error("未知异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"DefaultExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ServerInternalError, "DefaultExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,23 +1,21 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> { |
||||
@Override |
||||
public Response toResponse(IOException e) { |
||||
log.error("IO异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"IOExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.NetworkError, "IOExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,22 +1,20 @@ |
||||
package wusthelper.internal.graduate.api.http.v1.handler; |
||||
|
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> { |
||||
@Override |
||||
public Response toResponse(ParseException e) { |
||||
log.error("解析异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"ParseExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ParseError, "ParseExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,17 +1,19 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.internal.rpc.exception.RpcException; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> { |
||||
@Override |
||||
public Response toResponse(RpcException e) { |
||||
return super.toResponse( |
||||
e.getCode(), |
||||
e.toString(), |
||||
"RpcExceptionHandler"); |
||||
log.debug("RpcException:", e); |
||||
return super.toResponse(e.getCode(), "RpcExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,22 +1,20 @@ |
||||
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.ws.rs.core.Response; |
||||
import jakarta.ws.rs.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class ValidationExceptionHandler extends BaseExceptionHandler |
||||
implements ExceptionMapper<ValidationException> { |
||||
@Override |
||||
public Response toResponse(ValidationException e) { |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ParamWrong, |
||||
"参数错误:" + e.toString(), |
||||
"ValidationExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ParamWrong, "ValidationExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,26 +1,17 @@ |
||||
package wusthelper.internal.graduate.api.http.v1.handler; |
||||
|
||||
import wusthelper.internal.rpc.exception.GraduateRpcException; |
||||
import wusthelper.internal.rpc.exception.RpcException; |
||||
import jakarta.enterprise.context.ApplicationScoped; |
||||
import jakarta.ws.rs.WebApplicationException; |
||||
import jakarta.ws.rs.core.Response; |
||||
import jakarta.ws.rs.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Provider |
||||
@ApplicationScoped |
||||
public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> { |
||||
@Override |
||||
public Response toResponse(WebApplicationException e) { |
||||
return super.toResponse( |
||||
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" |
||||
); |
||||
return super.toResponse(ServiceCode.RequestInvalid, "WebApplicationExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,21 +1,19 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> { |
||||
@Override |
||||
public Response toResponse(Exception e) { |
||||
log.error("未知异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"DefaultExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ServerInternalError, "DefaultExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,23 +1,21 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> { |
||||
@Override |
||||
public Response toResponse(IOException e) { |
||||
log.error("IO异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"IOExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.NetworkError, "IOExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,22 +1,20 @@ |
||||
package wusthelper.internal.library.api.http.v1.handler; |
||||
|
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> { |
||||
@Override |
||||
public Response toResponse(ParseException e) { |
||||
log.error("解析异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"ParseExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ParseError, "ParseExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,17 +1,19 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.internal.rpc.exception.RpcException; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> { |
||||
@Override |
||||
public Response toResponse(RpcException e) { |
||||
return super.toResponse( |
||||
e.getCode(), |
||||
e.toString(), |
||||
"RpcExceptionHandler"); |
||||
log.debug("RpcException:", e); |
||||
return super.toResponse(e.getCode(), "RpcExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,22 +1,20 @@ |
||||
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.ws.rs.core.Response; |
||||
import jakarta.ws.rs.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class ValidationExceptionHandler extends BaseExceptionHandler |
||||
implements ExceptionMapper<ValidationException> { |
||||
@Override |
||||
public Response toResponse(ValidationException e) { |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ParamWrong, |
||||
"参数错误:" + e.toString(), |
||||
"ValidationExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ParamWrong, "ValidationExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,26 +1,17 @@ |
||||
package wusthelper.internal.library.api.http.v1.handler; |
||||
|
||||
import wusthelper.internal.rpc.exception.LibraryRpcException; |
||||
import wusthelper.internal.rpc.exception.RpcException; |
||||
import jakarta.enterprise.context.ApplicationScoped; |
||||
import jakarta.ws.rs.WebApplicationException; |
||||
import jakarta.ws.rs.core.Response; |
||||
import jakarta.ws.rs.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Provider |
||||
@ApplicationScoped |
||||
public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> { |
||||
@Override |
||||
public Response toResponse(WebApplicationException e) { |
||||
return super.toResponse( |
||||
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" |
||||
); |
||||
return super.toResponse(ServiceCode.RequestInvalid, "WebApplicationExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,21 +1,19 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> { |
||||
@Override |
||||
public Response toResponse(Exception e) { |
||||
log.error("未知异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"DefaultExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ServerInternalError, "DefaultExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,23 +1,21 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> { |
||||
@Override |
||||
public Response toResponse(IOException e) { |
||||
log.error("IO异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"IOExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.NetworkError, "IOExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,22 +1,20 @@ |
||||
package wusthelper.internal.physics.api.http.v1.handler; |
||||
|
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class ParseExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<ParseException> { |
||||
@Override |
||||
public Response toResponse(ParseException e) { |
||||
log.error("解析异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"ParseExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ParseError, "ParseExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,17 +1,19 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.internal.rpc.exception.RpcException; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> { |
||||
@Override |
||||
public Response toResponse(RpcException e) { |
||||
return super.toResponse( |
||||
e.getCode(), |
||||
e.toString(), |
||||
"RpcExceptionHandler"); |
||||
log.debug("RpcException:", e); |
||||
return super.toResponse(e.getCode(), "RpcExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,22 +1,20 @@ |
||||
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.ws.rs.core.Response; |
||||
import jakarta.ws.rs.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class ValidationExceptionHandler extends BaseExceptionHandler |
||||
implements ExceptionMapper<ValidationException> { |
||||
@Override |
||||
public Response toResponse(ValidationException e) { |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ParamWrong, |
||||
"参数错误:" + e.toString(), |
||||
"ValidationExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ParamWrong, "ValidationExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,26 +1,17 @@ |
||||
package wusthelper.internal.physics.api.http.v1.handler; |
||||
|
||||
import wusthelper.internal.rpc.exception.PhysicsRpcException; |
||||
import wusthelper.internal.rpc.exception.RpcException; |
||||
import jakarta.enterprise.context.ApplicationScoped; |
||||
import jakarta.ws.rs.WebApplicationException; |
||||
import jakarta.ws.rs.core.Response; |
||||
import jakarta.ws.rs.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Provider |
||||
@ApplicationScoped |
||||
public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> { |
||||
@Override |
||||
public Response toResponse(WebApplicationException e) { |
||||
return super.toResponse( |
||||
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" |
||||
); |
||||
return super.toResponse(ServiceCode.RequestInvalid, "WebApplicationExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,21 +1,19 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class DefaultExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<Exception> { |
||||
@Override |
||||
public Response toResponse(Exception e) { |
||||
log.error("未知异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"DefaultExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ServerInternalError, "DefaultExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,23 +1,21 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class IOExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<IOException> { |
||||
@Override |
||||
public Response toResponse(IOException e) { |
||||
log.error("IO异常:", e); |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ServerInternalError, |
||||
e.toString(), |
||||
"IOExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.NetworkError, "IOExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,17 +1,19 @@ |
||||
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.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.internal.rpc.exception.RpcException; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class RpcExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<RpcException> { |
||||
@Override |
||||
public Response toResponse(RpcException e) { |
||||
return super.toResponse( |
||||
e.getCode(), |
||||
e.toString(), |
||||
"RpcExceptionHandler"); |
||||
log.debug("RpcException:", e); |
||||
return super.toResponse(e.getCode(), "RpcExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,22 +1,20 @@ |
||||
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.ws.rs.core.Response; |
||||
import jakarta.ws.rs.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Slf4j |
||||
@Provider |
||||
@ApplicationScoped |
||||
public class ValidationExceptionHandler extends BaseExceptionHandler |
||||
implements ExceptionMapper<ValidationException> { |
||||
@Override |
||||
public Response toResponse(ValidationException e) { |
||||
return super.toResponse( |
||||
RpcCommonResponseCode.ParamWrong, |
||||
"参数错误:" + e.toString(), |
||||
"ValidationExceptionHandler" |
||||
); |
||||
return super.toResponse(ServiceCode.ParamWrong, "ValidationExceptionHandler"); |
||||
} |
||||
} |
||||
|
@ -1,26 +1,17 @@ |
||||
package wusthelper.internal.undergrad.api.http.v1.handler; |
||||
|
||||
import wusthelper.internal.rpc.exception.UndergradRpcException; |
||||
import wusthelper.internal.rpc.exception.RpcException; |
||||
import jakarta.enterprise.context.ApplicationScoped; |
||||
import jakarta.ws.rs.WebApplicationException; |
||||
import jakarta.ws.rs.core.Response; |
||||
import jakarta.ws.rs.ext.ExceptionMapper; |
||||
import jakarta.ws.rs.ext.Provider; |
||||
import wusthelper.code.ServiceCode; |
||||
|
||||
@Provider |
||||
@ApplicationScoped |
||||
public class WebApplicationExceptionHandler extends BaseExceptionHandler implements ExceptionMapper<WebApplicationException> { |
||||
@Override |
||||
public Response toResponse(WebApplicationException e) { |
||||
return super.toResponse( |
||||
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" |
||||
); |
||||
return super.toResponse(ServiceCode.RequestInvalid, "WebApplicationExceptionHandler"); |
||||
} |
||||
} |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue