limit 1, CookieManager, CourseResponse

main
lensfrex 1 year ago
parent 693e23f779
commit 155c577792
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 45
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/dto/response/CourseResponse.java
  2. 44
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/graduate/GraduateController.java
  3. 12
      backend-main/backend-web/src/main/java/wusthelper/web/api/v2/module/undergrade/UndergradController.java
  4. 1
      backend-main/backend-web/src/main/java/wusthelper/web/service/cookie/CookieManager.java

@ -6,6 +6,10 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Data @Data
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@ -63,6 +67,47 @@ public class CourseResponse {
courseResponse.setClassroom(course.getClassroom().getRoom()); courseResponse.setClassroom(course.getClassroom().getRoom());
return courseResponse; return courseResponse;
}
/**
* 切课将连着的几节课切开来
*
* @param courses mywust类型的CourseList
* @return List<CourseResponse>
*/
public static List<CourseResponse> convertCourseList(Collection<Course> courses) {
List<CourseResponse> courseResponses = new ArrayList<>(courses.size() * 2);
CourseResponse.CourseResponseBuilder builder = CourseResponse.builder();
for (Course course : courses) {
builder.className(course.getName());
builder.teachClass(course.getTeachClass());
builder.classroom(course.getClassroom().getRoom());
builder.startWeek(course.getStartWeek());
builder.endWeek(course.getEndWeek());
builder.weekDay(course.getWeekDay());
builder.teacher(course.getTeacher());
int startSection = course.getStartSection();
int endSection = course.getEndSection();
int courseSize = endSection - startSection + 1;
// 课程大小大于2的将课程按两节两节分割,只有一节的按两节处理
if (courseSize > 2) {
for (int i = 0; i < courseSize / 2; i++) {
int splitStartSection = startSection + i * 2;
int section = splitStartSection - (splitStartSection / 2);
builder.section(section);
courseResponses.add(builder.build());
}
} else {
builder.section(startSection - (startSection / 2));
courseResponses.add(builder.build());
}
}
return courseResponses;
} }
} }

@ -56,53 +56,11 @@ public class GraduateController {
var user = TokenTool.getStudentNumber(token); var user = TokenTool.getStudentNumber(token);
var courses = courseTableService.getCourseTable(user); var courses = courseTableService.getCourseTable(user);
LinkedHashSet<Course> filteredCourse = new LinkedHashSet<>(courses); LinkedHashSet<Course> filteredCourse = new LinkedHashSet<>(courses);
var resultList = convertCourseList(filteredCourse); var resultList = CourseResponse.convertCourseList(filteredCourse);
return Response.success(V2ResponseCode.YJS_GETCOURSE_SUC.getCode(), resultList); return Response.success(V2ResponseCode.YJS_GETCOURSE_SUC.getCode(), resultList);
} }
/**
* 切课将连着的几节课切开来
*
* @param courses mywust类型的CourseList
* @return List<CourseResponse>
*/
private List<CourseResponse> convertCourseList(Collection<Course> courses) {
List<CourseResponse> courseResponses = new ArrayList<>(courses.size() * 2);
CourseResponse.CourseResponseBuilder builder = CourseResponse.builder();
for (Course course : courses) {
builder.className(course.getName());
builder.teachClass(course.getTeachClass());
builder.classroom(course.getClassroom().getRoom());
builder.startWeek(course.getStartWeek());
builder.endWeek(course.getEndWeek());
builder.weekDay(course.getWeekDay());
builder.teacher(course.getTeacher());
int startSection = course.getStartSection();
int endSection = course.getEndSection();
int courseSize = endSection - startSection + 1;
// 课程大小大于2的将课程按两节两节分割,只有一节的按两节处理
if (courseSize > 2) {
for (int i = 0; i < courseSize / 2; i++) {
int splitStartSection = startSection + i * 2;
int section = splitStartSection - (splitStartSection / 2);
builder.section(section);
courseResponses.add(builder.build());
}
} else {
builder.section(startSection - (startSection / 2));
courseResponses.add(builder.build());
}
}
return courseResponses;
}
@RequestMapping("/get-grade") @RequestMapping("/get-grade")
public Response<List<GraduateScoreResponse>> getScore(@RequestHeader("Token") String token) { public Response<List<GraduateScoreResponse>> getScore(@RequestHeader("Token") String token) {
var user = TokenTool.getStudentNumber(token); var user = TokenTool.getStudentNumber(token);

@ -1,5 +1,6 @@
package wusthelper.web.api.v2.module.undergrade; package wusthelper.web.api.v2.module.undergrade;
import cn.wustlinghang.mywust.data.global.Course;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -13,10 +14,7 @@ import wusthelper.web.api.v2.dto.response.undergrad.StudentInfoResponse;
import wusthelper.web.response.Response; import wusthelper.web.response.Response;
import wusthelper.web.service.campus.undergrad.*; import wusthelper.web.service.campus.undergrad.*;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@RequireToken @RequireToken
@RestController @RestController
@ -55,10 +53,8 @@ public class UndergradController {
@RequestParam(value = "schoolTerm") String term) { @RequestParam(value = "schoolTerm") String term) {
var user = TokenTool.getStudentNumber(token); var user = TokenTool.getStudentNumber(token);
var courses = courseTableService.getCourseTable(user, term); var courses = courseTableService.getCourseTable(user, term);
var resultList = new ArrayList<CourseResponse>(courses.size()); var filteredCourse = new LinkedHashSet<>(courses);
for (var course : courses) { var resultList = CourseResponse.convertCourseList(filteredCourse);
resultList.add(CourseResponse.from(course));
}
return Response.success(V2ResponseCode.JWC_GETCURRICULUM_SUC.getCode(), resultList); return Response.success(V2ResponseCode.JWC_GETCURRICULUM_SUC.getCode(), resultList);
} }

@ -88,6 +88,7 @@ public class CookieManager {
public String refreshCookie(String username, CookieType cookieType) { public String refreshCookie(String username, CookieType cookieType) {
var student = studentMapper.selectOne(new QueryWrapper<UserBasic>() var student = studentMapper.selectOne(new QueryWrapper<UserBasic>()
.eq("stu_num", username) .eq("stu_num", username)
.last("limit 1")
.eq("deleted", 0) .eq("deleted", 0)
); );

Loading…
Cancel
Save