lensfrex 2 years ago
parent eb93192a7b
commit 1396a52945
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 1
      .idea/inspectionProfiles/Project_Default.xml
  2. 8
      README.md
  3. 20
      backend-main/backend-web/pom.xml
  4. 2
      backend-main/backend-web/src/main/java/wusthelper/WebBackendMain.java
  5. 22
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/TokenTool.java
  6. 7
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/CourseResponse.java
  7. 32
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/GraduateScoreResponse.java
  8. 56
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/GraduateStudentInfoResponse.java
  9. 61
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/PhysicsCourseResponse.java
  10. 81
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/graduate/GraduateController.java
  11. 28
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/graduate/GraduateLoginController.java
  12. 54
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/physics/PhysicsController.java
  13. 25
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/physics/PhysicsLoginController.java
  14. 12
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/undergrade/UndergradController.java
  15. 12
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/undergrade/UndergradLoginController.java
  16. 2
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/graduate/GraduateCookieRemote.java
  17. 27
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/graduate/GraduateCourseTableRemote.java
  18. 27
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/graduate/GraduateScoreRemote.java
  19. 2
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/graduate/GraduateStudentInfoRemote.java
  20. 24
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/graduate/GraduateTrainingPlanRemote.java
  21. 18
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/physics/PhysicsCookieRemote.java
  22. 28
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/physics/PhysicsCourseTableRemote.java
  23. 27
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/physics/PhysicsScoreRemote.java
  24. 2
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/undergrad/UndergradCookieRemote.java
  25. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/undergrad/UndergradCourseTableRemote.java
  26. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/undergrad/UndergradCreditStatusRemote.java
  27. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/undergrad/UndergradExamDelayApplicationRemote.java
  28. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/undergrad/UndergradScoreRemote.java
  29. 2
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/undergrad/UndergradStudentInfoRemote.java
  30. 4
      backend-main/backend-web/src/main/java/wusthelper/web/rpc/http/undergrad/UndergradTrainingPlanRemote.java
  31. 99
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/GeneralUserLoginService.java
  32. 126
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/UserLoginService.java
  33. 2
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/graduate/GraduateCookieService.java
  34. 34
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/graduate/GraduateCourseTableService.java
  35. 33
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/graduate/GraduateScoreService.java
  36. 2
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/graduate/GraduateStudentInfoService.java
  37. 30
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/graduate/GraduateTrainingPlanService.java
  38. 28
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/library/LibraryCookieService.java
  39. 30
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/physics/PhysicsCookieService.java
  40. 35
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/physics/PhysicsCourseTableService.java
  41. 33
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/physics/PhysicsScoreService.java
  42. 2
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradCookieService.java
  43. 6
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradCourseTableService.java
  44. 6
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradCreditStatusService.java
  45. 10
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradExamDelayApplicationService.java
  46. 6
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradScoreService.java
  47. 2
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradStudentInfoService.java
  48. 6
      backend-main/backend-web/src/main/java/wusthelper/web/service/campus/undergrad/UndergradTrainingPlanService.java
  49. 8
      backend-main/backend-web/src/main/java/wusthelper/web/service/cookie/CookieManager.java
  50. 10
      backend-main/backend-web/src/main/java/wusthelper/web/util/GlobalLogger.java
  51. 19
      backend-main/backend-web/src/main/java/wusthelper/web/util/StringUtil.java
  52. 14
      backend-main/backend-web/src/main/resources/application.yml
  53. 2
      backend-main/backend-web/src/test/java/wusthelper/TestMain.java
  54. 2
      external-library/mywust

@ -36,6 +36,7 @@
<option name="customHeaders">
<set>
<option value="Token" />
<option value="Platform" />
</set>
</option>
</inspection_tool>

@ -15,7 +15,7 @@
当某模块更新或下线时,可以在不重启整个项目的情况下进行更新,同时如果有多个实例部署,可及时切换到可用节点上,从而避免整个项目的完全重启而导致服务完全中断,只要对外api网关模块仍在运行,就可使用仍在运行的模块继续提供一定的服务,提高可用性,同时由于各个模块被拆分,因此相较于以前更为轻量,在模块更新或重启时也能更快的恢复服务
该项目意在探索新技术,同时提高后端服务的可用性
- 随时有可能脑抽大改结构
@lensferno
@ -41,6 +41,8 @@ Java 17+
## 关于Mywust库的导入问题
待补充
---
## API文档
@ -51,10 +53,14 @@ Java 17+
## 构建
待补充
---
## 运行
待补充
---
就先这样吧,手累了

@ -22,6 +22,7 @@
<idgen.version>1.0.6</idgen.version>
<java-jwt.version>4.4.0</java-jwt.version>
<lettuce.bersion>6.2.5.RELEASE</lettuce.bersion>
</properties>
<dependencies>
@ -29,6 +30,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
@ -65,6 +71,20 @@
<version>${java-jwt.version}</version>
</dependency>
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>${lettuce.bersion}</version>
</dependency>
</dependencies>
<build>

@ -1,6 +1,8 @@
package wusthelper;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

@ -20,7 +20,7 @@ public class TokenTool {
/**
* 签发Token
*
* @return
* @return token
*/
public static String signToken(Long uid, String studentNumber) {
try {
@ -34,7 +34,7 @@ public class TokenTool {
.withExpiresAt(expireAt)
.sign(jwtAlgorithm);
} catch (Exception e) {
log.error("[{}]:Token签发工具类>签发Token异常, 空指针异常: uid={},studentNumber={}",
log.error("[{}]:Token签发工具类>签发Token异常: uid={},studentNumber={}",
Thread.currentThread().getStackTrace()[1].getMethodName(),
uid, studentNumber);
throw new RuntimeException("[JwtUtil.signToken()]");
@ -44,10 +44,10 @@ public class TokenTool {
/**
* 校验Token
*
* @param token
* @return
* @param token token
* @return 是否有效
*/
public static boolean verifyToken(String token) {
public static boolean verify(String token) {
try {
JWT.require(jwtAlgorithm)
.build()
@ -60,20 +60,20 @@ public class TokenTool {
}
/**
* Token 负载StuId
* 从token获取uid
*
* @param token
* @return
* @param token token
* @return uid
*/
public static String getUid(String token) {
return JWT.decode(token).getClaim("StuId").asString();
}
/**
* Token 负载StuNum
* 从token获取学号
*
* @param token
* @return
* @param token token
* @return 学号
*/
public static String getStudentNumber(String token) {
return JWT.decode(token).getClaim("StuNum").asString();

@ -9,30 +9,37 @@ public class CourseResponse {
* 课程名称
*/
private String className;
/**
* 教学班
*/
private String teachClass;
/**
* 教师
*/
private String teacher;
/**
* 开始周次
*/
private Integer startWeek;
/**
* 结束周
*/
private Integer endWeek;
/**
* 节数
*/
private Integer section;
/**
* 星期
*/
private Integer weekDay;
/**
* 教室
*/

@ -0,0 +1,32 @@
package wusthelper.web.api.v2.dto.response;
import cn.wustlinghang.mywust.data.global.Score;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class GraduateScoreResponse {
//课程名
private String name;
//课程学分
private Double credit;
//选修学期
private Integer term;
//得分
private String point;
public static GraduateScoreResponse from(Score score) {
GraduateScoreResponse graduateScoreResponse = new GraduateScoreResponse();
graduateScoreResponse.setName(score.getCourseName());
graduateScoreResponse.setCredit(Double.parseDouble(score.getCredit()));
graduateScoreResponse.setTerm(Integer.parseInt(score.getTerm()));
graduateScoreResponse.setPoint(score.getGradePoint());
return graduateScoreResponse;
}
}

@ -0,0 +1,56 @@
package wusthelper.web.api.v2.dto.response;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import wusthelper.web.util.StringUtil;
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GraduateStudentInfoResponse {
private Long id;
//学号
private String studentNum;
//密码
private String password;
//姓名
private String name;
//学位
private String degree;
//导师姓名
private String tutorName;
//学院
private String academy;
//专业
private String specialty;
//年级
private Integer grade;
//头像
private String avatar;
public static GraduateStudentInfoResponse from(StudentInfo studentInfo) {
GraduateStudentInfoResponse graduateStudentInfoResponse = new GraduateStudentInfoResponse();
// graduateStudentInfo.setId();
graduateStudentInfoResponse.setStudentNum(studentInfo.getStudentNumber());
// graduateStudentInfo.setPassword();
graduateStudentInfoResponse.setName(studentInfo.getName());
graduateStudentInfoResponse.setDegree("");
graduateStudentInfoResponse.setTutorName("");
graduateStudentInfoResponse.setAcademy(studentInfo.getCollege());
graduateStudentInfoResponse.setSpecialty(studentInfo.getMajor());
int grade = StringUtil.getGradeFromStudentNumber(studentInfo.getStudentNumber());
graduateStudentInfoResponse.setGrade(grade);
graduateStudentInfoResponse.setAvatar("");
return graduateStudentInfoResponse;
}
}

@ -0,0 +1,61 @@
package wusthelper.web.api.v2.dto.response;
import cn.wustlinghang.mywust.data.physics.PhysicsCourse;
import lombok.Data;
import wusthelper.WebBackendMain;
import wusthelper.web.util.GlobalLogger;
import java.sql.Date;
import java.text.SimpleDateFormat;
@Data
public class PhysicsCourseResponse {
private String courseName;
private String teacherName;
private Integer week;
private Integer weekDay;
private Date courseDate;
private Integer startSection;
private Integer endSection;
private String buildingName;
private String areaNum;
private String roomNum;
private String campusName;
public static PhysicsCourseResponse from(PhysicsCourse course) {
PhysicsCourseResponse physicsCourseResponse = new PhysicsCourseResponse();
physicsCourseResponse.setCourseName(course.getName());
physicsCourseResponse.setTeacherName(course.getTeacher());
physicsCourseResponse.setWeek(course.getStartWeek());
physicsCourseResponse.setWeekDay(course.getWeekDay());
physicsCourseResponse.setStartSection(course.getStartSection());
physicsCourseResponse.setEndSection(course.getEndSection());
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date parseDate = formatter.parse(course.getDate());
physicsCourseResponse.setCourseDate(new java.sql.Date(parseDate.getTime()));
} catch (Exception e) {
GlobalLogger.log.error("物理实验课程解析错误,{}", e.getMessage());
GlobalLogger.log.debug("", e);
}
var place = course.getClassroom();
physicsCourseResponse.setBuildingName(place.getBuilding());
physicsCourseResponse.setAreaNum(place.getArea());
physicsCourseResponse.setRoomNum(place.getRoom());
physicsCourseResponse.setCampusName(place.getCampus());
return physicsCourseResponse;
}
}

@ -0,0 +1,81 @@
package wusthelper.web.api.v2.module.graduate;
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.GraduateScoreResponse;
import wusthelper.web.api.v2.dto.response.GraduateStudentInfoResponse;
import wusthelper.web.api.v2.dto.response.StudentInfoResponse;
import wusthelper.web.response.Response;
import wusthelper.web.service.campus.graduate.GraduateCourseTableService;
import wusthelper.web.service.campus.graduate.GraduateScoreService;
import wusthelper.web.service.campus.graduate.GraduateStudentInfoService;
import wusthelper.web.service.campus.graduate.GraduateTrainingPlanService;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/v2/yjs")
public class GraduateController {
private final GraduateStudentInfoService studentInfoService;
private final GraduateCourseTableService courseTableService;
private final GraduateScoreService scoreService;
private final GraduateTrainingPlanService trainingPlanService;
public GraduateController(GraduateStudentInfoService studentInfoService,
GraduateCourseTableService courseTableService,
GraduateScoreService scoreService,
GraduateTrainingPlanService trainingPlanService) {
this.studentInfoService = studentInfoService;
this.courseTableService = courseTableService;
this.scoreService = scoreService;
this.trainingPlanService = trainingPlanService;
}
@RequestMapping("/get-student-info")
public Response<GraduateStudentInfoResponse> getStudentInfo(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var studentInfo = studentInfoService.getStudentInfo(user);
var response = GraduateStudentInfoResponse.from(studentInfo);
return Response.success(response);
}
@RequestMapping("/get-course")
public Response<List<CourseResponse>> getCourses(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var courses = courseTableService.getCourseTable(user);
var resultList = new ArrayList<CourseResponse>(courses.size());
for (var course : courses) {
resultList.add(CourseResponse.from(course));
}
return Response.success(resultList);
}
@RequestMapping("/get-grade")
public Response<List<GraduateScoreResponse>> getScore(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var scores = scoreService.getScore(user);
var resultList = new ArrayList<GraduateScoreResponse>(scores.size());
for (var score : scores) {
resultList.add(GraduateScoreResponse.from(score));
}
return Response.success(resultList);
}
@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,28 @@
package wusthelper.web.api.v2.module.graduate;
import org.springframework.web.bind.annotation.*;
import wusthelper.web.api.v2.TokenTool;
import wusthelper.web.response.Response;
import wusthelper.web.service.campus.UserLoginService;
@RestController
@RequestMapping("/v2/yjs")
public class GraduateLoginController {
private final UserLoginService userLoginService;
public GraduateLoginController(UserLoginService userLoginService) {
this.userLoginService = userLoginService;
}
@PostMapping("/login")
public Response<String> login(@RequestParam("stuNum") String username,
@RequestParam("jwcPwd") String password,
@RequestHeader(name = "Platform", required = false) String platform) {
var user = userLoginService.login(username, password, UserLoginService.LoginType.Graduate);
String token = TokenTool.signToken(user.getUid(), user.getStuNum());
return Response.success(token);
}
}

@ -0,0 +1,54 @@
package wusthelper.web.api.v2.module.physics;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
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.PhysicsCourseResponse;
import wusthelper.web.api.v2.dto.response.ScoreResponse;
import wusthelper.web.response.Response;
import wusthelper.web.service.campus.physics.PhysicsCourseTableService;
import wusthelper.web.service.campus.physics.PhysicsScoreService;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/v2/wlsy")
public class PhysicsController {
private final PhysicsCourseTableService courseTableService;
private final PhysicsScoreService scoreService;
public PhysicsController(PhysicsCourseTableService courseTableService,
PhysicsScoreService scoreService) {
this.courseTableService = courseTableService;
this.scoreService = scoreService;
}
@RequestMapping("/get-course")
public Response<List<PhysicsCourseResponse>> getCourses(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var courses = courseTableService.getCourseTable(user);
var resultList = new ArrayList<PhysicsCourseResponse>(courses.size());
for (var course : courses) {
resultList.add(PhysicsCourseResponse.from(course));
}
return Response.success(resultList);
}
@RequestMapping("/get-grade")
public Response<List<ScoreResponse>> getScore(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token);
var scores = scoreService.getScore(user);
var resultList = new ArrayList<ScoreResponse>(scores.size());
for (var score : scores) {
resultList.add(ScoreResponse.from(score));
}
return Response.success(resultList);
}
}

@ -0,0 +1,25 @@
package wusthelper.web.api.v2.module.physics;
import org.springframework.web.bind.annotation.*;
import wusthelper.web.api.v2.TokenTool;
import wusthelper.web.response.Response;
import wusthelper.web.service.campus.UserLoginService;
@RestController
@RequestMapping("/v2/wlsy")
public class PhysicsLoginController {
private final UserLoginService userLoginService;
public PhysicsLoginController(UserLoginService userLoginService) {
this.userLoginService = userLoginService;
}
@PostMapping("/login")
public Response<Object> login(@RequestParam("wlsyPwd") String password,
@RequestHeader("Token") String token) {
String username = TokenTool.getStudentNumber(token);
userLoginService.login(username, password, UserLoginService.LoginType.Graduate);
return Response.success();
}
}

@ -52,19 +52,19 @@ public class UndergradController {
@RequestParam(value = "schoolTerm") String term) {
var user = TokenTool.getStudentNumber(token);
var courses = courseTableService.getCourseTable(user, term);
var courseResponsesList = new ArrayList<CourseResponse>(courses.size());
var resultList = new ArrayList<CourseResponse>(courses.size());
for (var course : courses) {
courseResponsesList.add(CourseResponse.from(course));
resultList.add(CourseResponse.from(course));
}
return Response.success(courseResponsesList);
return Response.success(resultList);
}
@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());
var resultList = new ArrayList<ScoreResponse>(scores.size());
// 课程
Set<String> courseSet = new HashSet<>(scores.size());
@ -89,11 +89,11 @@ public class UndergradController {
// 缓考不显示
if (scoreResponse.getMissExamTag() != 2) {
scoreResponseList.add(scoreResponse);
resultList.add(scoreResponse);
}
}
return Response.success(scoreResponseList);
return Response.success(resultList);
}
@RequestMapping("/get-credit")

@ -6,7 +6,7 @@ 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.UserLoginService;
import wusthelper.web.service.campus.undergrad.UndergradCourseTableService;
import wusthelper.web.service.campus.undergrad.UndergradStudentInfoService;
@ -15,16 +15,16 @@ import java.util.ArrayList;
@RestController
@RequestMapping("/v2/jwc")
public class UndergradLoginController {
private final GeneralUserLoginService generalUserLoginService;
private final UserLoginService userLoginService;
private final UndergradStudentInfoService studentInfoService;
private final UndergradCourseTableService courseTableService;
public UndergradLoginController(GeneralUserLoginService generalUserLoginService,
public UndergradLoginController(UserLoginService userLoginService,
UndergradStudentInfoService studentInfoService,
UndergradCourseTableService courseTableService) {
this.generalUserLoginService = generalUserLoginService;
this.userLoginService = userLoginService;
this.studentInfoService = studentInfoService;
this.courseTableService = courseTableService;
}
@ -34,7 +34,7 @@ public class UndergradLoginController {
@RequestParam(value = "jwcPwd") String password,
@RequestHeader(name = "Platform", required = false) String platform) {
var user = generalUserLoginService.login(username, password, GeneralUserLoginService.UserType.Undergrad);
var user = userLoginService.login(username, password, UserLoginService.LoginType.Undergrad);
String token = TokenTool.signToken(user.getUid(), user.getStuNum());
@ -58,7 +58,7 @@ public class UndergradLoginController {
@RequestParam(value = "term") String term,
@RequestHeader(name = "Platform", required = false) String platform) {
var user = generalUserLoginService.login(username, password, GeneralUserLoginService.UserType.Undergrad);
var user = userLoginService.login(username, password, UserLoginService.LoginType.Undergrad);
var studentInfo = studentInfoService.getStudentInfo(username);
var courses = courseTableService.getCourseTable(username, term);

@ -1,4 +1,4 @@
package wusthelper.web.rpc.graduate;
package wusthelper.web.rpc.http.graduate;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;

@ -0,0 +1,27 @@
package wusthelper.web.rpc.http.graduate;
import cn.wustlinghang.mywust.data.global.Course;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import wusthelper.internal.rpc.response.RpcResponseDto;
import java.util.List;
@Component
@FeignClient(name = "wusthelper.graduate", contextId = "graduate-courseTable")
public interface GraduateCourseTableRemote {
String ROOT_PATH = "/course_table";
@GetMapping(ROOT_PATH)
RpcResponseDto<List<Course>> get(@RequestParam("cookie") String cookie);
@GetMapping(ROOT_PATH + "/agent")
RpcResponseDto<String> agent(@RequestParam("cookie") @NotNull String cookie);
@PostMapping(ROOT_PATH + "/parse")
RpcResponseDto<List<Course>> parse(String html);
}

@ -0,0 +1,27 @@
package wusthelper.web.rpc.http.graduate;
import cn.wustlinghang.mywust.data.global.Score;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import wusthelper.internal.rpc.response.RpcResponseDto;
import java.util.List;
@Component
@FeignClient(name = "wusthelper.graduate", contextId = "graduate-score")
public interface GraduateScoreRemote {
String ROOT_PATH = "/score";
@GetMapping(ROOT_PATH)
RpcResponseDto<List<Score>> get(@RequestParam("cookie") String cookie);
@GetMapping(ROOT_PATH + "/agent")
RpcResponseDto<String> agent(@RequestParam("cookie") @NotNull String cookie);
@PostMapping(ROOT_PATH + "/parse")
RpcResponseDto<List<Score>> parse(String html);
}

@ -1,4 +1,4 @@
package wusthelper.web.rpc.graduate;
package wusthelper.web.rpc.http.graduate;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import jakarta.validation.constraints.NotNull;

@ -0,0 +1,24 @@
package wusthelper.web.rpc.http.graduate;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import wusthelper.internal.rpc.response.RpcResponseDto;
@Component
@FeignClient(name = "wusthelper.graduate", contextId = "graduate-trainingPlan")
public interface GraduateTrainingPlanRemote {
String ROOT_PATH = "/training_plan";
@GetMapping(ROOT_PATH)
RpcResponseDto<String> get(@RequestParam("cookie") String cookie);
@GetMapping(ROOT_PATH + "/agent")
RpcResponseDto<String> agent(@RequestParam("cookie") @NotNull String cookie);
@PostMapping(ROOT_PATH + "/parse")
RpcResponseDto<String> parse(String html);
}

@ -0,0 +1,18 @@
package wusthelper.web.rpc.http.physics;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import wusthelper.internal.rpc.response.RpcResponseDto;
@FeignClient(name = "wusthelper.physics", contextId = "physics-cookie")
public interface PhysicsCookieRemote {
String COOKIE_ROOT_PATH = "/cookie";
@GetMapping(COOKIE_ROOT_PATH)
RpcResponseDto<String> login(@RequestParam("username") String username,
@RequestParam("password") String password);
@GetMapping(COOKIE_ROOT_PATH + "/verify")
RpcResponseDto<Boolean> verify(@RequestParam("cookie") String cookie);
}

@ -0,0 +1,28 @@
package wusthelper.web.rpc.http.physics;
import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.mywust.data.physics.PhysicsCourse;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import wusthelper.internal.rpc.response.RpcResponseDto;
import java.util.List;
@Component
@FeignClient(name = "wusthelper.physics", contextId = "physics-courseTable")
public interface PhysicsCourseTableRemote {
String ROOT_PATH = "/course_table";
@GetMapping(ROOT_PATH)
RpcResponseDto<List<PhysicsCourse>> get(@RequestParam("cookie") String cookie);
@GetMapping(ROOT_PATH + "/agent")
RpcResponseDto<String> agent(@RequestParam("cookie") @NotNull String cookie);
@PostMapping(ROOT_PATH + "/parse")
RpcResponseDto<List<Course>> parse(String html);
}

@ -0,0 +1,27 @@
package wusthelper.web.rpc.http.physics;
import cn.wustlinghang.mywust.data.global.Score;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import wusthelper.internal.rpc.response.RpcResponseDto;
import java.util.List;
@Component
@FeignClient(name = "wusthelper.physics", contextId = "physics-score")
public interface PhysicsScoreRemote {
String ROOT_PATH = "/score";
@GetMapping(ROOT_PATH)
RpcResponseDto<List<Score>> get(@RequestParam("cookie") String cookie);
@GetMapping(ROOT_PATH + "/agent")
RpcResponseDto<String> agent(@RequestParam("cookie") @NotNull String cookie);
@PostMapping(ROOT_PATH + "/parse")
RpcResponseDto<List<Score>> parse(String html);
}

@ -1,4 +1,4 @@
package wusthelper.web.rpc.undergrad;
package wusthelper.web.rpc.http.undergrad;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto;

@ -1,4 +1,4 @@
package wusthelper.web.rpc.undergrad;
package wusthelper.web.rpc.http.undergrad;
import cn.wustlinghang.mywust.data.global.Course;
import org.springframework.stereotype.Component;
@ -13,7 +13,7 @@ import java.util.List;
@Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-courseTable")
public interface CourseTableRemote {
public interface UndergradCourseTableRemote {
String ROOT_PATH = "/course_table";
@GetMapping(ROOT_PATH)

@ -1,4 +1,4 @@
package wusthelper.web.rpc.undergrad;
package wusthelper.web.rpc.http.undergrad;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto;
@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-creditStatus")
public interface CreditStatusRemote {
public interface UndergradCreditStatusRemote {
String ROOT_PATH = "/credit_status";
@GetMapping(ROOT_PATH)

@ -1,4 +1,4 @@
package wusthelper.web.rpc.undergrad;
package wusthelper.web.rpc.http.undergrad;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import org.springframework.stereotype.Component;
@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-examDelayApplication")
public interface ExamDelayApplicationRemote {
public interface UndergradExamDelayApplicationRemote {
String ROOT_PATH = "/exam_delay_application";
@GetMapping(ROOT_PATH)

@ -1,4 +1,4 @@
package wusthelper.web.rpc.undergrad;
package wusthelper.web.rpc.http.undergrad;
import cn.wustlinghang.mywust.data.global.Score;
import org.springframework.stereotype.Component;
@ -13,7 +13,7 @@ import java.util.List;
@Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-score")
public interface ScoreRemote {
public interface UndergradScoreRemote {
String ROOT_PATH = "/score";
@GetMapping(ROOT_PATH)

@ -1,4 +1,4 @@
package wusthelper.web.rpc.undergrad;
package wusthelper.web.rpc.http.undergrad;
import cn.wustlinghang.mywust.data.global.StudentInfo;
import org.springframework.stereotype.Component;

@ -1,4 +1,4 @@
package wusthelper.web.rpc.undergrad;
package wusthelper.web.rpc.http.undergrad;
import org.springframework.stereotype.Component;
import wusthelper.internal.rpc.response.RpcResponseDto;
@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@Component
@FeignClient(name = "wusthelper.undergrad", contextId = "undergrad-trainingPlan")
public interface TrainingPlanRemote {
public interface UndergradTrainingPlanRemote {
String ROOT_PATH = "/training_plan";
@GetMapping(ROOT_PATH)

@ -1,99 +0,0 @@
package wusthelper.web.service.campus;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yitter.idgen.YitIdHelper;
import org.springframework.stereotype.Service;
import wusthelper.data.dao.mapper.StudentMapper;
import wusthelper.data.dao.mapper.UserBasicMapper;
import wusthelper.data.entity.Student;
import wusthelper.data.entity.UserBasic;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.service.campus.graduate.GraduateCookieService;
import wusthelper.web.service.campus.undergrad.UndergradCookieService;
import wusthelper.web.service.cookie.CookieManager;
import wusthelper.web.util.PasswordCodec;
/**
* 通用的用户登录信息服务包括登录和已存储的用户信息获取等同时自动存入新用户基本信息
*/
@Service
public class GeneralUserLoginService {
private final UserBasicMapper studentMapper;
private final PasswordCodec passwordCodec;
private final UndergradCookieService undergradCookieService;
private final GraduateCookieService graduateCookieService;
public GeneralUserLoginService(UserBasicMapper studentMapper,
PasswordCodec passwordCodec,
UndergradCookieService undergradCookieService,
GraduateCookieService graduateCookieService) {
this.studentMapper = studentMapper;
this.passwordCodec = passwordCodec;
this.undergradCookieService = undergradCookieService;
this.graduateCookieService = graduateCookieService;
}
public enum UserType {Undergrad, Graduate}
/**
* 登录验证同时自动存库基本信息
*
* @param username 用户名即学号
* @param password 密码明文原文
* @param userType 用户类型现在有本科生和研究生
* @return 用户信息
*/
public UserBasic login(String username, String password, UserType userType) {
var cookie = switch (userType) {
case Undergrad -> undergradCookieService.getLoginCookie(username, password);
case Graduate -> graduateCookieService.getLoginCookie(username, password);
};
var cookieType = switch (userType) {
case Undergrad -> CookieType.Undergrad;
case Graduate -> CookieType.Graduate;
};
// 保存cookie,并将用户基本信息存库
CookieManager.store(username, cookie, cookieType);
return this.saveOrUpdateUser(username, password, userType);
}
private UserBasic saveOrUpdateUser(String username, String password, UserType userType) {
var query = new QueryWrapper<UserBasic>()
.eq("stu_num", username)
.eq("deleted", 0)
.last("limit 1");
var user = studentMapper.selectOne(query);
if (user != null) {
var encrypted = passwordCodec.encode(password);
user.setOfficialPwd(encrypted);
if (userType == UserType.Undergrad) {
user.setLibPwd(encrypted);
}
studentMapper.update(user, query);
} else {
var uid = YitIdHelper.nextId();
user = UserBasic.builder()
.uid(uid)
.stuNum(username)
.build();
var encrypted = passwordCodec.encode(password);
user.setOfficialPwd(encrypted);
if (userType == UserType.Undergrad) {
user.setLibPwd(encrypted);
}
studentMapper.insert(user);
}
return user;
}
}

@ -0,0 +1,126 @@
package wusthelper.web.service.campus;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yitter.idgen.YitIdHelper;
import org.springframework.stereotype.Service;
import wusthelper.data.dao.mapper.UserBasicMapper;
import wusthelper.data.entity.UserBasic;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.service.campus.graduate.GraduateCookieService;
import wusthelper.web.service.campus.library.LibraryCookieService;
import wusthelper.web.service.campus.physics.PhysicsCookieService;
import wusthelper.web.service.campus.undergrad.UndergradCookieService;
import wusthelper.web.service.cookie.CookieManager;
import wusthelper.web.util.PasswordCodec;
/**
* 通用的用户登录信息服务包括登录和已存储的用户信息获取等同时自动存入新用户密码信息
*/
@Service
public class UserLoginService {
private final UserBasicMapper studentMapper;
private final PasswordCodec passwordCodec;
private final UndergradCookieService undergradCookieService;
private final GraduateCookieService graduateCookieService;
private final LibraryCookieService libraryCookieService;
private final PhysicsCookieService physicsCookieService;
public UserLoginService(UserBasicMapper studentMapper,
PasswordCodec passwordCodec,
UndergradCookieService undergradCookieService,
GraduateCookieService graduateCookieService,
LibraryCookieService libraryCookieService,
PhysicsCookieService physicsCookieService) {
this.studentMapper = studentMapper;
this.passwordCodec = passwordCodec;
this.undergradCookieService = undergradCookieService;
this.graduateCookieService = graduateCookieService;
this.libraryCookieService = libraryCookieService;
this.physicsCookieService = physicsCookieService;
}
public enum LoginType {Undergrad, Graduate, Library, Physics}
/**
* 登录验证同时自动存库基本信息
*
* @param username 用户名即学号
* @param password 密码明文原文
* @param loginType 用户类型现在有本科生和研究生
* @return 用户信息
*/
public UserBasic login(String username, String password, LoginType loginType) {
var cookie = switch (loginType) {
case Undergrad -> undergradCookieService.getLoginCookie(username, password);
case Graduate -> graduateCookieService.getLoginCookie(username, password);
case Library -> libraryCookieService.getLoginCookie(username, password);
case Physics -> physicsCookieService.getLoginCookie(username, password);
};
var cookieType = switch (loginType) {
case Undergrad -> CookieType.Undergrad;
case Graduate -> CookieType.Graduate;
case Library -> CookieType.Library;
case Physics -> CookieType.Physics;
};
// 保存cookie,并将用户基本信息存库
CookieManager.store(username, cookie, cookieType);
return this.saveOrUpdateUser(username, password, loginType);
}
private UserBasic saveOrUpdateUser(String username, String password, LoginType loginType) {
var user = studentMapper.selectOne(new QueryWrapper<UserBasic>()
.eq("stu_num", username)
.eq("deleted", 0)
.last("limit 1")
);
if (user != null) {
this.fillPassword(password, user, loginType);
this.updateUser(username, user);
} else {
user = this.newUser(username, password, loginType);
}
return user;
}
private void updateUser(String username, UserBasic user) {
studentMapper.update(user, new QueryWrapper<UserBasic>()
.eq("stu_num", username)
.eq("deleted", 0)
.last("limit 1")
);
}
private UserBasic newUser(String username, String password, LoginType loginType) {
var uid = YitIdHelper.nextId();
UserBasic user = UserBasic.builder()
.uid(uid)
.stuNum(username)
.build();
this.fillPassword(password, user, loginType);
studentMapper.insert(user);
return user;
}
private void fillPassword(String password, UserBasic user, LoginType loginType) {
var encrypted = passwordCodec.encode(password);
switch (loginType) {
case Undergrad -> {
user.setOfficialPwd(encrypted);
user.setLibPwd(encrypted);
}
case Graduate -> user.setOfficialPwd(encrypted);
case Library -> user.setLibPwd(encrypted);
case Physics -> user.setPhysicsPwd(encrypted);
}
}
}

@ -3,7 +3,7 @@ package wusthelper.web.service.campus.graduate;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.graduate.GraduateCookieRemote;
import wusthelper.web.rpc.http.graduate.GraduateCookieRemote;
@Service
public class GraduateCookieService {

@ -0,0 +1,34 @@
package wusthelper.web.service.campus.graduate;
import cn.wustlinghang.mywust.data.global.Course;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.http.graduate.GraduateCourseTableRemote;
import wusthelper.web.service.cookie.CookieManager;
import java.util.List;
@Service
public class GraduateCourseTableService {
private final GraduateCourseTableRemote courseTableRemote;
private final CookieManager cookieManager;
public GraduateCourseTableService(GraduateCourseTableRemote courseTableRemote, CookieManager cookieManager) {
this.courseTableRemote = courseTableRemote;
this.cookieManager = cookieManager;
}
public List<Course> getCourseTable(String user) {
String cookie = cookieManager.getCookie(user, CookieType.Graduate);
var rpcResp = courseTableRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.error(rpcResp.code());
}
// todo 异步存用户课表,异常判断等等
return rpcResp.data();
}
}

@ -0,0 +1,33 @@
package wusthelper.web.service.campus.graduate;
import cn.wustlinghang.mywust.data.global.Score;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.http.graduate.GraduateScoreRemote;
import wusthelper.web.service.cookie.CookieManager;
import java.util.List;
@Service
public class GraduateScoreService {
private final GraduateScoreRemote scoreRemote;
private final CookieManager cookieManager;
public GraduateScoreService(GraduateScoreRemote scoreRemote, CookieManager cookieManager) {
this.scoreRemote = scoreRemote;
this.cookieManager = cookieManager;
}
public List<Score> getScore(String user) {
String cookie = cookieManager.getCookie(user, CookieType.Graduate);
var rpcResp = scoreRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.error(rpcResp.code());
}
// todo 异步存用户课表,异常判断等等
return rpcResp.data();
}
}

@ -5,7 +5,7 @@ import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.graduate.GraduateStudentInfoRemote;
import wusthelper.web.rpc.http.graduate.GraduateStudentInfoRemote;
import wusthelper.web.service.cookie.CookieManager;
import wusthelper.web.service.student.StudentService;

@ -0,0 +1,30 @@
package wusthelper.web.service.campus.graduate;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.http.graduate.GraduateTrainingPlanRemote;
import wusthelper.web.service.cookie.CookieManager;
@Service
public class GraduateTrainingPlanService {
private final GraduateTrainingPlanRemote trainingPlanRemote;
private final CookieManager cookieManager;
public GraduateTrainingPlanService(GraduateTrainingPlanRemote trainingPlanRemote, CookieManager cookieManager) {
this.trainingPlanRemote = trainingPlanRemote;
this.cookieManager = cookieManager;
}
public String getTrainingPlan(String user) {
String cookie = cookieManager.getCookie(user, CookieType.Graduate);
var rpcResp = trainingPlanRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.error(rpcResp.code());
}
// todo 异步存用户课表,异常判断等等
return rpcResp.data();
}
}

@ -0,0 +1,28 @@
package wusthelper.web.service.campus.library;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.http.graduate.GraduateCookieRemote;
@Service
public class LibraryCookieService {
private final GraduateCookieRemote graduateCookieRemote;
public LibraryCookieService(GraduateCookieRemote graduateCookieRemote) {
this.graduateCookieRemote = graduateCookieRemote;
}
public String getLoginCookie(String username, String password) throws ServiceException {
var rpcResp = graduateCookieRemote.login(username, password);
if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.error(rpcResp.code());
}
return rpcResp.data();
}
public Boolean checkCookie(String cookie) {
return graduateCookieRemote.verify(cookie).data();
}
}

@ -0,0 +1,30 @@
package wusthelper.web.service.campus.physics;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.http.physics.PhysicsCookieRemote;
import wusthelper.web.service.cookie.CookieManager;
@Service
public class PhysicsCookieService {
private final PhysicsCookieRemote physicsCookieRemote;
public PhysicsCookieService(PhysicsCookieRemote physicsCookieRemote) {
this.physicsCookieRemote = physicsCookieRemote;
}
public String getLoginCookie(String username, String password) throws ServiceException {
var rpcResp = physicsCookieRemote.login(username, password);
if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.error(rpcResp.code());
}
return rpcResp.data();
}
public Boolean checkCookie(String cookie) {
return physicsCookieRemote.verify(cookie).data();
}
}

@ -0,0 +1,35 @@
package wusthelper.web.service.campus.physics;
import cn.wustlinghang.mywust.data.global.Course;
import cn.wustlinghang.mywust.data.physics.PhysicsCourse;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.http.physics.PhysicsCourseTableRemote;
import wusthelper.web.service.cookie.CookieManager;
import java.util.List;
@Service
public class PhysicsCourseTableService {
private final PhysicsCourseTableRemote courseTableRemote;
private final CookieManager cookieManager;
public PhysicsCourseTableService(PhysicsCourseTableRemote courseTableRemote, CookieManager cookieManager) {
this.courseTableRemote = courseTableRemote;
this.cookieManager = cookieManager;
}
public List<PhysicsCourse> getCourseTable(String user) {
String cookie = cookieManager.getCookie(user, CookieType.Physics);
var rpcResp = courseTableRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.error(rpcResp.code());
}
// todo 异步存用户课表,异常判断等等
return rpcResp.data();
}
}

@ -0,0 +1,33 @@
package wusthelper.web.service.campus.physics;
import cn.wustlinghang.mywust.data.global.Score;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.http.physics.PhysicsScoreRemote;
import wusthelper.web.service.cookie.CookieManager;
import java.util.List;
@Service
public class PhysicsScoreService {
private final PhysicsScoreRemote scoreRemote;
private final CookieManager cookieManager;
public PhysicsScoreService(PhysicsScoreRemote scoreRemote, CookieManager cookieManager) {
this.scoreRemote = scoreRemote;
this.cookieManager = cookieManager;
}
public List<Score> getScore(String user) {
String cookie = cookieManager.getCookie(user, CookieType.Physics);
var rpcResp = scoreRemote.get(cookie);
if (rpcResp.code() != ServiceCode.Ok) {
ServiceException.error(rpcResp.code());
}
// todo 异步存用户课表,异常判断等等
return rpcResp.data();
}
}

@ -3,7 +3,7 @@ package wusthelper.web.service.campus.undergrad;
import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.UndergradCookieRemote;
import wusthelper.web.rpc.http.undergrad.UndergradCookieRemote;
@Service
public class UndergradCookieService {

@ -3,7 +3,7 @@ package wusthelper.web.service.campus.undergrad;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.CourseTableRemote;
import wusthelper.web.rpc.http.undergrad.UndergradCourseTableRemote;
import wusthelper.web.service.cookie.CookieManager;
import cn.wustlinghang.mywust.data.global.Course;
import org.springframework.stereotype.Service;
@ -12,11 +12,11 @@ import java.util.List;
@Service
public class UndergradCourseTableService {
private final CourseTableRemote courseTableRemote;
private final UndergradCourseTableRemote courseTableRemote;
private final CookieManager cookieManager;
public UndergradCourseTableService(CourseTableRemote courseTableRemote, CookieManager cookieManager) {
public UndergradCourseTableService(UndergradCourseTableRemote courseTableRemote, CookieManager cookieManager) {
this.courseTableRemote = courseTableRemote;
this.cookieManager = cookieManager;
}

@ -3,16 +3,16 @@ package wusthelper.web.service.campus.undergrad;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.CreditStatusRemote;
import wusthelper.web.rpc.http.undergrad.UndergradCreditStatusRemote;
import wusthelper.web.service.cookie.CookieManager;
import org.springframework.stereotype.Service;
@Service
public class UndergradCreditStatusService {
private final CreditStatusRemote creditStatusRemote;
private final UndergradCreditStatusRemote creditStatusRemote;
private final CookieManager cookieManager;
public UndergradCreditStatusService(CreditStatusRemote creditStatusRemote, CookieManager cookieManager) {
public UndergradCreditStatusService(UndergradCreditStatusRemote creditStatusRemote, CookieManager cookieManager) {
this.creditStatusRemote = creditStatusRemote;
this.cookieManager = cookieManager;
}

@ -2,19 +2,19 @@ package wusthelper.web.service.campus.undergrad;
import wusthelper.code.ServiceCode;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.ExamDelayApplicationRemote;
import wusthelper.web.rpc.http.undergrad.UndergradExamDelayApplicationRemote;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.service.cookie.CookieManager;
import cn.wustlinghang.mywust.data.undergrad.ExamDelayApplication;
import org.springframework.stereotype.Service;
@Service
public class ExamDelayApplicationService {
private final ExamDelayApplicationRemote examDelayApplicationRemote;
public class UndergradExamDelayApplicationService {
private final UndergradExamDelayApplicationRemote examDelayApplicationRemote;
private final CookieManager cookieManager;
public ExamDelayApplicationService(ExamDelayApplicationRemote examDelayApplicationRemote,
CookieManager cookieManager) {
public UndergradExamDelayApplicationService(UndergradExamDelayApplicationRemote examDelayApplicationRemote,
CookieManager cookieManager) {
this.examDelayApplicationRemote = examDelayApplicationRemote;
this.cookieManager = cookieManager;
}

@ -3,7 +3,7 @@ package wusthelper.web.service.campus.undergrad;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.ScoreRemote;
import wusthelper.web.rpc.http.undergrad.UndergradScoreRemote;
import wusthelper.web.service.cookie.CookieManager;
import cn.wustlinghang.mywust.data.global.Score;
import org.springframework.stereotype.Service;
@ -12,10 +12,10 @@ import java.util.List;
@Service
public class UndergradScoreService {
private final ScoreRemote scoreRemote;
private final UndergradScoreRemote scoreRemote;
private final CookieManager cookieManager;
public UndergradScoreService(ScoreRemote scoreRemote, CookieManager cookieManager) {
public UndergradScoreService(UndergradScoreRemote scoreRemote, CookieManager cookieManager) {
this.scoreRemote = scoreRemote;
this.cookieManager = cookieManager;
}

@ -5,7 +5,7 @@ import org.springframework.stereotype.Service;
import wusthelper.code.ServiceCode;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.UndergradStudentInfoRemote;
import wusthelper.web.rpc.http.undergrad.UndergradStudentInfoRemote;
import wusthelper.web.service.cookie.CookieManager;
import wusthelper.web.service.student.StudentService;

@ -2,17 +2,17 @@ package wusthelper.web.service.campus.undergrad;
import wusthelper.code.ServiceCode;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.rpc.undergrad.TrainingPlanRemote;
import wusthelper.web.rpc.http.undergrad.UndergradTrainingPlanRemote;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.service.cookie.CookieManager;
import org.springframework.stereotype.Service;
@Service
public class UndergradTrainingPlanService {
private final TrainingPlanRemote trainingPlanRemote;
private final UndergradTrainingPlanRemote trainingPlanRemote;
private final CookieManager cookieManager;
public UndergradTrainingPlanService(TrainingPlanRemote trainingPlanRemote, CookieManager cookieManager) {
public UndergradTrainingPlanService(UndergradTrainingPlanRemote trainingPlanRemote, CookieManager cookieManager) {
this.trainingPlanRemote = trainingPlanRemote;
this.cookieManager = cookieManager;
}

@ -7,6 +7,7 @@ import wusthelper.data.entity.Student;
import wusthelper.web.data.entity.CookieType;
import wusthelper.web.exception.ServiceException;
import wusthelper.web.service.campus.graduate.GraduateCookieService;
import wusthelper.web.service.campus.physics.PhysicsCookieService;
import wusthelper.web.service.campus.undergrad.UndergradCookieService;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@ -21,20 +22,23 @@ public class CookieManager {
private static final Cache<String, String> cookiePool = Caffeine.newBuilder()
.expireAfterWrite(2, TimeUnit.HOURS)
.initialCapacity(256)
.maximumSize(2048)
.maximumSize(1024)
.build();
private final UndergradCookieService undergradCookieService;
private final GraduateCookieService graduateCookieService;
private final PhysicsCookieService physicsCookieService;
private final StudentMapper studentMapper;
public CookieManager(UndergradCookieService undergradCookieService,
GraduateCookieService graduateCookieService,
PhysicsCookieService physicsCookieService,
StudentMapper studentMapper) {
this.undergradCookieService = undergradCookieService;
this.graduateCookieService = graduateCookieService;
this.physicsCookieService = physicsCookieService;
this.studentMapper = studentMapper;
}
@ -67,6 +71,7 @@ public class CookieManager {
return switch (cookieType) {
case Undergrad -> undergradCookieService.checkCookie(cookie);
case Graduate -> graduateCookieService.checkCookie(cookie);
case Physics -> physicsCookieService.checkCookie(cookie);
default -> false;
};
}
@ -94,6 +99,7 @@ public class CookieManager {
return switch (cookieType) {
case Undergrad -> undergradCookieService.getLoginCookie(username, password);
case Graduate -> graduateCookieService.getLoginCookie(username, password);
case Physics -> physicsCookieService.getLoginCookie(username, password);
default -> null;
};
}

@ -0,0 +1,10 @@
package wusthelper.web.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GlobalLogger {
public static final Logger log = LoggerFactory.getLogger("wusthelper");
}

@ -1,5 +1,7 @@
package wusthelper.web.util;
import java.time.LocalDateTime;
public class StringUtil {
public static boolean isPositiveNumber(final String str) {
@ -83,4 +85,21 @@ public class StringUtil {
return 0.0F;
}
}
/**
* 从学号获取年级入学年份
*
* @param studentNumber 学号
* @return 年级入学年份
*/
public static int getGradeFromStudentNumber(String studentNumber) {
if (studentNumber.length() > 4) {
String gradeStr = studentNumber.substring(0, 4);
if (StringUtil.isPositiveNumber(gradeStr)) {
return Integer.parseInt(gradeStr);
}
}
return LocalDateTime.now().getYear();
}
}

@ -22,7 +22,19 @@ spring:
url: jdbc:mysql://localhost:3306/wust_helper?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
username: root
password: Test2333!
devtools:
restart:
enabled: true
data:
redis:
host: localhost
port: 6379
password: Test2333!
jedis:
pool:
max-idle: 16
max-active: 32
min-idle: 8
server:
port: ${RUN_PORT}

@ -37,7 +37,7 @@ public class TestMain {
public static void main(String[] args) {
String token = TokenTool.signToken(1233487L, "202118194039");
boolean valid = TokenTool.verifyToken(token);
boolean valid = TokenTool.verify(token);
var uid = TokenTool.getUid(token);
var studentNumber = TokenTool.getStudentNumber(token);
log.info(token);

@ -1 +1 @@
Subproject commit 0ca9d1a48da91b30933a3dd35e3428bb5207078f
Subproject commit 5da31b26d1a8b7560f068d8bf507d01e34c1cdaf
Loading…
Cancel
Save