代码优化

master
Alan 5 months ago
parent 1fb6d20b7a
commit dc41ea4fe3
  1. 2
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  2. 2
      src/main/java/com/teaching/backend/mapper/umsAdmin/UmsTeacherMapper.java
  3. 4
      src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsTeacher.java
  4. 3
      src/main/java/com/teaching/backend/model/query/CourseQuery.java
  5. 16
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  6. 4
      src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java
  7. 3
      src/main/resources/application.yml

@ -66,7 +66,7 @@ public class CoursesController {
@ApiOperation("查询课程列表") @ApiOperation("查询课程列表")
@ValidateParams({"username"}) @ValidateParams({"username","roleId"})
@GetMapping("/page") @GetMapping("/page")
public BaseResponse<PageDTO<CoursesVO>> getCourses(CourseQuery courseQuery){ public BaseResponse<PageDTO<CoursesVO>> getCourses(CourseQuery courseQuery){
PageDTO<CoursesVO> coursesList = coursesService.queryCourses(courseQuery); PageDTO<CoursesVO> coursesList = coursesService.queryCourses(courseQuery);

@ -14,5 +14,5 @@ import com.teaching.backend.model.entity.umsAdmin.UmsTeacher;
public interface UmsTeacherMapper extends BaseMapper<UmsTeacher> { public interface UmsTeacherMapper extends BaseMapper<UmsTeacher> {
boolean updateTeacherInfo(UmsTeacher umsTeacher); boolean updateTeacherInfo(UmsTeacher umsTeacher);
UmsTeacher selectByUserId(Integer userId); UmsTeacher selectByUserId(Long userId);
} }

@ -44,7 +44,7 @@ public class UmsTeacher implements Serializable {
private String education; private String education;
//学位 //学位
private String academicDegree; private String degree;
//职称 //职称
private String professionalTitle; private String professionalTitle;
@ -59,7 +59,7 @@ public class UmsTeacher implements Serializable {
private String politicalStatus; private String politicalStatus;
//user_id //user_id
private Integer userId; private Long userId;
} }

@ -15,6 +15,9 @@ public class CourseQuery extends PageQuery {
@ApiModelProperty(value = "用户的username",required = true) @ApiModelProperty(value = "用户的username",required = true)
private String username; private String username;
@ApiModelProperty(value = "用户的角色id",required = true)
private Long roleId;
@ApiModelProperty("课程任课教师") @ApiModelProperty("课程任课教师")
private String teacher; private String teacher;

@ -158,21 +158,25 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
// throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); // throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT);
// } // }
UmsUser umsAdmin = umsUserMapper.selectOne(new LambdaQueryWrapper<UmsUser>() // UmsUser umsUser = umsUserMapper.selectOne(new LambdaQueryWrapper<UmsUser>()
.eq(UmsUser::getUsername, username)); // .eq(UmsUser::getUsername, username));
UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper<UmsAdminRoleRelation>() // UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper<UmsAdminRoleRelation>()
.eq(UmsAdminRoleRelation::getAdminId, umsAdmin.getId())); // .eq(UmsAdminRoleRelation::getAdminId, umsUser.getId()));
int roleId = Math.toIntExact(umsAdminRoleRelation.getRoleId()); // int roleId = Math.toIntExact(umsAdminRoleRelation.getRoleId());
int roleId = Math.toIntExact(courseQuery.getRoleId());
PageDTO<CoursesVO> coursesVOPageDTO; PageDTO<CoursesVO> coursesVOPageDTO;
switch (roleId) { switch (roleId) {
//教师--也是管理员--但是只能看自己的课程,有搜索功能
case 1: case 1:
coursesVOPageDTO = queryForTeacher(courseQuery, username); coursesVOPageDTO = queryForTeacher(courseQuery, username);
break; break;
//学生
case 2: case 2:
coursesVOPageDTO = queryForStudent(courseQuery, username); coursesVOPageDTO = queryForStudent(courseQuery, username);
break; break;
//这个对应的是以后的院系管理员 这个才能看别的教师的课程
case 3: case 3:
coursesVOPageDTO = queryForAdmin(courseQuery); coursesVOPageDTO = queryForAdmin(courseQuery);
break; break;
@ -233,7 +237,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
// System.out.println(umsAdminTea); // System.out.println(umsAdminTea);
UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper<UmsTeacher>() UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper<UmsTeacher>()
.eq(UmsTeacher::getUserId, umsUserTea.getId())); .eq(UmsTeacher::getUserId, umsUserTea.getId()));
System.out.println(umsTeacher); // System.out.println(umsTeacher);
if (umsTeacher == null){ if (umsTeacher == null){
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS);
} }

@ -375,10 +375,10 @@ public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser> impl
List<TeacherInfVO> teacherInfList = new ArrayList<>();; List<TeacherInfVO> teacherInfList = new ArrayList<>();;
for (UmsTeacher umsTeacher : umsTeachers) { for (UmsTeacher umsTeacher : umsTeachers) {
teacherInfVO = new TeacherInfVO(); teacherInfVO = new TeacherInfVO();
UmsUser umsAdmin = umsUserMapper.selectOne(new LambdaQueryWrapper<UmsUser>() UmsUser umsUser = umsUserMapper.selectOne(new LambdaQueryWrapper<UmsUser>()
.eq(UmsUser::getId, umsTeacher.getUserId())); .eq(UmsUser::getId, umsTeacher.getUserId()));
teacherInfVO.setName(umsTeacher.getName()); teacherInfVO.setName(umsTeacher.getName());
teacherInfVO.setUsername(umsAdmin.getUsername()); teacherInfVO.setUsername(umsUser.getUsername());
teacherInfList.add(teacherInfVO); teacherInfList.add(teacherInfVO);
} }
return teacherInfList; return teacherInfList;

@ -12,6 +12,9 @@ spring:
matching-strategy: ant_path_matcher matching-strategy: ant_path_matcher
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://127.0.0.1:3306/teaching_db
# username: root
# password: root
url: jdbc:mysql://rm-bp189rd5595301145do.mysql.rds.aliyuncs.com:3306/teaching_db url: jdbc:mysql://rm-bp189rd5595301145do.mysql.rds.aliyuncs.com:3306/teaching_db
username: root123 username: root123
password: Zjh@111111 password: Zjh@111111

Loading…
Cancel
Save