main
			
			
		
		
							parent
							
								
									eb93192a7b
								
							
						
					
					
						commit
						1396a52945
					
				@ -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(); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -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.StudentInfo; | 
				
			||||
import org.springframework.stereotype.Component; | 
				
			||||
@ -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); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -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(); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -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(); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -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 +1 @@ | 
				
			||||
Subproject commit 0ca9d1a48da91b30933a3dd35e3428bb5207078f | 
				
			||||
Subproject commit 5da31b26d1a8b7560f068d8bf507d01e34c1cdaf | 
				
			||||
					Loading…
					
					
				
		Reference in new issue