优化教师信息查询,新增用户角色静态常量类RoleConstants

master
Alan 6 months ago
parent c1da086cb0
commit 5c99839296
  1. 7
      src/main/java/com/teaching/backend/constant/RoleConstants.java
  2. 2
      src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java
  3. 4
      src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java
  4. 2
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  5. 17
      src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java

@ -0,0 +1,7 @@
package com.teaching.backend.constant;
public class RoleConstants {
public static final Long TEACHER_ROLE = 1L;
public static final Long STUDENT_ROLE = 2L;
public static final Long ADMIN_ROLE = 3L;
}

@ -179,7 +179,7 @@ public class UmsUserController {
return CommonResult.failed(); return CommonResult.failed();
} }
@ApiOperation("获取教师信息列表,关联教师的username和name") @ApiOperation("获取教师信息列表,关联教师的userId和name")
@GetMapping("/get_teacherinf_list") @GetMapping("/get_teacherinf_list")
public BaseResponse<List<TeacherInfVO>> getTeacherInfList(){ public BaseResponse<List<TeacherInfVO>> getTeacherInfList(){
List<TeacherInfVO> teacherInfVO = umsUserService.getTeacherInfList(); List<TeacherInfVO> teacherInfVO = umsUserService.getTeacherInfList();

@ -12,8 +12,8 @@ public class TeacherInfVO {
/** /**
* 教师username * 教师username
*/ */
@ApiModelProperty("教师username") @ApiModelProperty("教师userId")
private String username; private Long userId;
/** /**
* 课程封面 * 课程封面
*/ */

@ -42,6 +42,8 @@ import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.teaching.backend.constant.RoleConstants.TEACHER_ROLE;
/** /**
* <p> * <p>
* 服务实现类 * 服务实现类

@ -42,6 +42,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static com.teaching.backend.constant.RoleConstants.TEACHER_ROLE;
@Service @Service
@Slf4j @Slf4j
public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser> implements UmsUserService { public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser> implements UmsUserService {
@ -377,18 +379,17 @@ public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser> impl
} }
throw new UsernameNotFoundException("用户名或密码错误"); throw new UsernameNotFoundException("用户名或密码错误");
} }
@Override @Override
public List<TeacherInfVO> getTeacherInfList() { public List<TeacherInfVO> getTeacherInfList() {
List<UmsTeacher> umsTeachers = umsTeacherMapper.selectList(new LambdaQueryWrapper<UmsTeacher>()); List<UmsUser> umsUserTeachers = query().eq("role_id", TEACHER_ROLE).list();
TeacherInfVO teacherInfVO = null; TeacherInfVO teacherInfVO = null;
List<TeacherInfVO> teacherInfList = new ArrayList<>();; List<TeacherInfVO> teacherInfList = new ArrayList<>();
for (UmsTeacher umsTeacher : umsTeachers) { for (UmsUser umsUserTeacher : umsUserTeachers) {
teacherInfVO = new TeacherInfVO(); teacherInfVO = new TeacherInfVO();
UmsUser umsUser = umsUserMapper.selectOne(new LambdaQueryWrapper<UmsUser>() String teacherName = umsTeacherMapper.selectOne(new LambdaQueryWrapper<>(UmsTeacher.class)
.eq(UmsUser::getId, umsTeacher.getUserId())); .eq(UmsTeacher::getUserId, umsUserTeacher.getId())).getName();
teacherInfVO.setName(umsTeacher.getName()); teacherInfVO.setName(teacherName);
teacherInfVO.setUsername(umsUser.getUsername()); teacherInfVO.setUserId(umsUserTeacher.getId());
teacherInfList.add(teacherInfVO); teacherInfList.add(teacherInfVO);
} }
return teacherInfList; return teacherInfList;

Loading…
Cancel
Save