diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaGradeManageController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaGradeManageController.java index 66f1417..b7d32ea 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaGradeManageController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaGradeManageController.java @@ -37,6 +37,8 @@ import java.io.IOException; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** * @Author xcj @@ -178,7 +180,7 @@ public class TeaGradeManageController { } -// @AnonymousAccess + // @AnonymousAccess // @GetMapping("/test") // @ApiOperation("测试导出") protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { @@ -319,61 +321,108 @@ public class TeaGradeManageController { } +// private List getTeaExamAndUserDtos(String schoolId, String keyWord, String classId, String examManageId) { +// List list = new ArrayList<>(); +// List stuUsers = userMapper.selectTeaExamAndUserDtos(schoolId, keyWord, classId, examManageId); +// //先拿到用户信息,再用userid查学生分数 +// for (StuUser stuUser : stuUsers) { +// TeaExamAndUserDto teaExamAndUserDto = new TeaExamAndUserDto(); +// String userid = stuUser.getUserid(); +// StuStudentExamExample studentExamExample = new StuStudentExamExample(); +// StuStudentExamExample.Criteria studentExamCriteria = studentExamExample.createCriteria(); +// studentExamCriteria.andUseridEqualTo(userid); +// teaExamAndUserDto.setName(stuUser.getName()); +// teaExamAndUserDto.setStudentId(stuUser.getStudentId()); +// StuClass stuClass = stuClassMapper.selectByPrimaryKey(stuUser.getClassId()); +// teaExamAndUserDto.setClassName(stuClass.getClassName()); +// if (StringUtils.isNotBlank(examManageId)) { +// studentExamCriteria.andExamManageIdEqualTo(examManageId); +// } +// List stuStudentExams = studentExamMapper.selectByExampleWithBLOBs(studentExamExample); +// if (!stuStudentExams.isEmpty()) { +// StuStudentExamWithBLOBs stuStudentExam = stuStudentExams.get(0); +// if (stuStudentExam != null) { +// if (stuStudentExam.getObjectiveScore() != null) { +// teaExamAndUserDto.setObjectiveScore(stuStudentExam.getObjectiveScore()); +// } +// if (stuStudentExam.getCaseScore() != null) { +// teaExamAndUserDto.setCaseScore(stuStudentExam.getCaseScore()); +// } +// if (stuStudentExam.getTotalScore() != null) { +// teaExamAndUserDto.setTotalScore(stuStudentExam.getTotalScore()); +// } +// } +// } +// list.add(teaExamAndUserDto); +// } +// return list; +// } + + private List getTeaExamAndUserDtos(String schoolId, String keyWord, String classId, String examManageId) { - StuUserExample stuUserExample = new StuUserExample(); - StuUserExample.Criteria stuUserCriteria = stuUserExample.createCriteria(); - StuUserExample.Criteria stuUserCriteria1 = stuUserExample.createCriteria(); - stuUserCriteria.andSchoolIdEqualTo(schoolId); - stuUserCriteria.andRoleIdEqualTo(4); - stuUserCriteria1.andRoleIdEqualTo(4); - stuUserCriteria1.andSchoolIdEqualTo(schoolId); - List list = new ArrayList(); - if (StringUtils.isNotBlank(keyWord)) { - stuUserCriteria.andStudentIdEqualTo(keyWord); - stuUserCriteria1.andNameEqualTo(keyWord); - } - if (StringUtils.isNotBlank(classId)) { - stuUserCriteria.andClassIdEqualTo(classId); - stuUserCriteria1.andClassIdEqualTo(classId); - } - stuUserExample.or(stuUserCriteria1); - List stuUsers = userMapper.selectByExample(stuUserExample); - //先拿到用户信息,再用userid查学生分数 + List list = new ArrayList<>(); + + // 批量查询用户信息 + List stuUsers = userMapper.selectTeaExamAndUserDtos(schoolId, keyWord, classId, examManageId); + + // 构建用户id列表 + List userIds = stuUsers.stream() + .map(StuUser::getUserid) + .collect(Collectors.toList()); + + // 构建班级ID列表 + List classIds = stuUsers.stream() + .map(StuUser::getClassId) + .collect(Collectors.toList()); + + // 批量查询学生分数 + StuStudentExamExample studentExamExample = new StuStudentExamExample(); + studentExamExample.createCriteria() + .andUseridIn(userIds) + .andExamManageIdEqualTo(examManageId); + + List stuStudentExams = studentExamMapper.selectByExampleWithBLOBs(studentExamExample); + + // 构建用户id和对应的学生分数的映射关系 + Map userExamMap = stuStudentExams.stream() + .collect(Collectors.toMap(StuStudentExamWithBLOBs::getUserid, Function.identity())); + + List stuClass = stuClassMapper.getByPrimaryKeys(classIds); + + // 构建班级ID与班级对象的映射关系 + Map classMap = stuClass.stream() + .collect(Collectors.toMap(StuClass::getClassId, Function.identity())); + + // 构建结果列表 for (StuUser stuUser : stuUsers) { TeaExamAndUserDto teaExamAndUserDto = new TeaExamAndUserDto(); - String userid = stuUser.getUserid(); - StuStudentExamExample studentExamExample = new StuStudentExamExample(); - StuStudentExamExample.Criteria studentExamCriteria = studentExamExample.createCriteria(); - studentExamCriteria.andUseridEqualTo(userid); teaExamAndUserDto.setName(stuUser.getName()); teaExamAndUserDto.setStudentId(stuUser.getStudentId()); - StuClass stuClass = stuClassMapper.selectByPrimaryKey(stuUser.getClassId()); - teaExamAndUserDto.setClassName(stuClass.getClassName()); - if (StringUtils.isNotBlank(examManageId)) { - studentExamCriteria.andExamManageIdEqualTo(examManageId); - } - StuStudentExamExample example = new StuStudentExamExample(); - example.createCriteria().andUseridEqualTo(userid).andExamManageIdEqualTo(examManageId); - List stuStudentExams = studentExamMapper.selectByExampleWithBLOBs(example); - if (!stuStudentExams.isEmpty()) { - StuStudentExamWithBLOBs stuStudentExam = stuStudentExams.get(0); - if (stuStudentExam != null) { - if (stuStudentExam.getObjectiveScore() != null) { - teaExamAndUserDto.setObjectiveScore(stuStudentExam.getObjectiveScore()); - } - if (stuStudentExam.getCaseScore() != null) { - teaExamAndUserDto.setCaseScore(stuStudentExam.getCaseScore()); - } - if (stuStudentExam.getTotalScore() != null) { - teaExamAndUserDto.setTotalScore(stuStudentExam.getTotalScore()); - } + + // 从映射关系中获取班级对象 + StuClass classdata = classMap.get(stuUser.getClassId()); + teaExamAndUserDto.setClassName(classdata.getClassName()); + + StuStudentExamWithBLOBs stuStudentExam = userExamMap.get(stuUser.getUserid()); + if (stuStudentExam != null) { + if (stuStudentExam.getObjectiveScore() != null) { + teaExamAndUserDto.setObjectiveScore(stuStudentExam.getObjectiveScore()); + } + if (stuStudentExam.getCaseScore() != null) { + teaExamAndUserDto.setCaseScore(stuStudentExam.getCaseScore()); + } + if (stuStudentExam.getTotalScore() != null) { + teaExamAndUserDto.setTotalScore(stuStudentExam.getTotalScore()); } } + list.add(teaExamAndUserDto); } + return list; } + @AnonymousAccess @PostMapping("/getTrainingInfo") @ApiOperation("练习模式--页面展示") diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/UserController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/UserController.java index 3e5e563..a3d4aff 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/UserController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/UserController.java @@ -201,7 +201,7 @@ public class UserController { continue; } StuUser stuUser = new StuUser(); - stuUser.setUserid(IdUtil.randomUUID()); + stuUser.setUserid(userId); stuUser.setStudentId(zyUserInfo.getUsername()); stuUser.setName(name); stuUser.setUsername(username); diff --git a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuClassMapper.java b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuClassMapper.java index cb75f63..60da85c 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuClassMapper.java +++ b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuClassMapper.java @@ -40,4 +40,6 @@ public interface StuClassMapper { String selectClassNameByClassId(@Param("classId")String classId); List selectByPrimaryKeys(@Param("classIds") Set classIds); + + List getByPrimaryKeys(@Param("classIds") List classIds); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuUserMapper.java b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuUserMapper.java index b4f6763..736f891 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuUserMapper.java +++ b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuUserMapper.java @@ -65,4 +65,6 @@ public interface StuUserMapper { + ")" + "") List selectByPrimaryKeys(@Param("userIds") List userIds); + + List selectTeaExamAndUserDtos(@Param("schoolId")String schoolId,@Param("keyWord") String keyWord, @Param("classId")String classId, @Param("examManageId")String examManageId); } \ No newline at end of file diff --git a/src/main/resources/mapper/StuClassMapper.xml b/src/main/resources/mapper/StuClassMapper.xml index a2234d2..d40b343 100644 --- a/src/main/resources/mapper/StuClassMapper.xml +++ b/src/main/resources/mapper/StuClassMapper.xml @@ -208,4 +208,13 @@ #{classId} + + \ No newline at end of file diff --git a/src/main/resources/mapper/StuUserMapper.xml b/src/main/resources/mapper/StuUserMapper.xml index f8a05e3..a98e7f6 100644 --- a/src/main/resources/mapper/StuUserMapper.xml +++ b/src/main/resources/mapper/StuUserMapper.xml @@ -1,372 +1,376 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - - - - - - - userid, name, student_id, class_id, username, password, phone, email, major, role_id, + + + + userid + , name, student_id, class_id, username, password, phone, email, major, role_id, create_time, school_id, school_name, status, exam_status - - - - - delete from stu_userinfo - where userid = #{userid,jdbcType=VARCHAR} - - - delete from stu_userinfo - - - - - - insert into stu_userinfo (userid, name, student_id, - class_id, username, password, - phone, email, major, - role_id, create_time, school_id, - school_name, status, exam_status - ) - values (#{userid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{studentId,jdbcType=VARCHAR}, - #{classId,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, - #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{major,jdbcType=VARCHAR}, - #{roleId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{schoolId,jdbcType=VARCHAR}, - #{schoolName,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{examStatus,jdbcType=VARCHAR} - ) - - - insert into stu_userinfo - - - userid, - - - name, - - - student_id, - - - class_id, - - - username, - - - password, - - - phone, - - - email, - - - major, - - - role_id, - - - create_time, - - - school_id, - - - school_name, - - - status, - - - exam_status, - - - - - #{userid,jdbcType=VARCHAR}, - - - #{name,jdbcType=VARCHAR}, - - - #{studentId,jdbcType=VARCHAR}, - - - #{classId,jdbcType=VARCHAR}, - - - #{username,jdbcType=VARCHAR}, - - - #{password,jdbcType=VARCHAR}, - - - #{phone,jdbcType=VARCHAR}, - - - #{email,jdbcType=VARCHAR}, - - - #{major,jdbcType=VARCHAR}, - - - #{roleId,jdbcType=INTEGER}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - #{schoolId,jdbcType=VARCHAR}, - - - #{schoolName,jdbcType=VARCHAR}, - - - #{status,jdbcType=INTEGER}, - - - #{examStatus,jdbcType=VARCHAR}, - - - - - - update stu_userinfo - - - userid = #{record.userid,jdbcType=VARCHAR}, - - + + + + + delete + from stu_userinfo + where userid = #{userid,jdbcType=VARCHAR} + + + delete from stu_userinfo + + + + + + insert into stu_userinfo (userid, name, student_id, + class_id, username, password, + phone, email, major, + role_id, create_time, school_id, + school_name, status, exam_status) + values (#{userid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{studentId,jdbcType=VARCHAR}, + #{classId,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, + #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{major,jdbcType=VARCHAR}, + #{roleId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{schoolId,jdbcType=VARCHAR}, + #{schoolName,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{examStatus,jdbcType=VARCHAR}) + + + insert into stu_userinfo + + + userid, + + + name, + + + student_id, + + + class_id, + + + username, + + + password, + + + phone, + + + email, + + + major, + + + role_id, + + + create_time, + + + school_id, + + + school_name, + + + status, + + + exam_status, + + + + + #{userid,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{studentId,jdbcType=VARCHAR}, + + + #{classId,jdbcType=VARCHAR}, + + + #{username,jdbcType=VARCHAR}, + + + #{password,jdbcType=VARCHAR}, + + + #{phone,jdbcType=VARCHAR}, + + + #{email,jdbcType=VARCHAR}, + + + #{major,jdbcType=VARCHAR}, + + + #{roleId,jdbcType=INTEGER}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{schoolId,jdbcType=VARCHAR}, + + + #{schoolName,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{examStatus,jdbcType=VARCHAR}, + + + + + + update stu_userinfo + + + userid = #{record.userid,jdbcType=VARCHAR}, + + + name = #{record.name,jdbcType=VARCHAR}, + + + student_id = #{record.studentId,jdbcType=VARCHAR}, + + + class_id = #{record.classId,jdbcType=VARCHAR}, + + + username = #{record.username,jdbcType=VARCHAR}, + + + password = #{record.password,jdbcType=VARCHAR}, + + + phone = #{record.phone,jdbcType=VARCHAR}, + + + email = #{record.email,jdbcType=VARCHAR}, + + + major = #{record.major,jdbcType=VARCHAR}, + + + role_id = #{record.roleId,jdbcType=INTEGER}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + school_id = #{record.schoolId,jdbcType=VARCHAR}, + + + school_name = #{record.schoolName,jdbcType=VARCHAR}, + + + status = #{record.status,jdbcType=INTEGER}, + + + exam_status = #{record.examStatus,jdbcType=VARCHAR}, + + + + + + + + update stu_userinfo + set userid = #{record.userid,jdbcType=VARCHAR}, name = #{record.name,jdbcType=VARCHAR}, - - student_id = #{record.studentId,jdbcType=VARCHAR}, - - class_id = #{record.classId,jdbcType=VARCHAR}, - - username = #{record.username,jdbcType=VARCHAR}, - - password = #{record.password,jdbcType=VARCHAR}, - - phone = #{record.phone,jdbcType=VARCHAR}, - - email = #{record.email,jdbcType=VARCHAR}, - - major = #{record.major,jdbcType=VARCHAR}, - - role_id = #{record.roleId,jdbcType=INTEGER}, - - create_time = #{record.createTime,jdbcType=TIMESTAMP}, - - school_id = #{record.schoolId,jdbcType=VARCHAR}, - - school_name = #{record.schoolName,jdbcType=VARCHAR}, - - status = #{record.status,jdbcType=INTEGER}, - - - exam_status = #{record.examStatus,jdbcType=VARCHAR}, - - - - - - - - update stu_userinfo - set userid = #{record.userid,jdbcType=VARCHAR}, - name = #{record.name,jdbcType=VARCHAR}, - student_id = #{record.studentId,jdbcType=VARCHAR}, - class_id = #{record.classId,jdbcType=VARCHAR}, - username = #{record.username,jdbcType=VARCHAR}, - password = #{record.password,jdbcType=VARCHAR}, - phone = #{record.phone,jdbcType=VARCHAR}, - email = #{record.email,jdbcType=VARCHAR}, - major = #{record.major,jdbcType=VARCHAR}, - role_id = #{record.roleId,jdbcType=INTEGER}, - create_time = #{record.createTime,jdbcType=TIMESTAMP}, - school_id = #{record.schoolId,jdbcType=VARCHAR}, - school_name = #{record.schoolName,jdbcType=VARCHAR}, - status = #{record.status,jdbcType=INTEGER}, - exam_status = #{record.examStatus,jdbcType=VARCHAR} - - - - - - update stu_userinfo - - - name = #{name,jdbcType=VARCHAR}, - - - student_id = #{studentId,jdbcType=VARCHAR}, - - - class_id = #{classId,jdbcType=VARCHAR}, - - - username = #{username,jdbcType=VARCHAR}, - - - password = #{password,jdbcType=VARCHAR}, - - - phone = #{phone,jdbcType=VARCHAR}, - - - email = #{email,jdbcType=VARCHAR}, - - - major = #{major,jdbcType=VARCHAR}, - - - role_id = #{roleId,jdbcType=INTEGER}, - - - create_time = #{createTime,jdbcType=TIMESTAMP}, - - - school_id = #{schoolId,jdbcType=VARCHAR}, - - - school_name = #{schoolName,jdbcType=VARCHAR}, - - - status = #{status,jdbcType=INTEGER}, - - - exam_status = #{examStatus,jdbcType=VARCHAR}, - - - where userid = #{userid,jdbcType=VARCHAR} - - - update stu_userinfo - set name = #{name,jdbcType=VARCHAR}, - student_id = #{studentId,jdbcType=VARCHAR}, - class_id = #{classId,jdbcType=VARCHAR}, - username = #{username,jdbcType=VARCHAR}, - password = #{password,jdbcType=VARCHAR}, - phone = #{phone,jdbcType=VARCHAR}, - email = #{email,jdbcType=VARCHAR}, - major = #{major,jdbcType=VARCHAR}, - role_id = #{roleId,jdbcType=INTEGER}, - create_time = #{createTime,jdbcType=TIMESTAMP}, - school_id = #{schoolId,jdbcType=VARCHAR}, - school_name = #{schoolName,jdbcType=VARCHAR}, - status = #{status,jdbcType=INTEGER}, - exam_status = #{examStatus,jdbcType=VARCHAR} - where userid = #{userid,jdbcType=VARCHAR} - + exam_status = #{record.examStatus,jdbcType=VARCHAR} + + + + + + update stu_userinfo + + + name = #{name,jdbcType=VARCHAR}, + + + student_id = #{studentId,jdbcType=VARCHAR}, + + + class_id = #{classId,jdbcType=VARCHAR}, + + + username = #{username,jdbcType=VARCHAR}, + + + password = #{password,jdbcType=VARCHAR}, + + + phone = #{phone,jdbcType=VARCHAR}, + + + email = #{email,jdbcType=VARCHAR}, + + + major = #{major,jdbcType=VARCHAR}, + + + role_id = #{roleId,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + school_id = #{schoolId,jdbcType=VARCHAR}, + + + school_name = #{schoolName,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=INTEGER}, + + + exam_status = #{examStatus,jdbcType=VARCHAR}, + + + where userid = #{userid,jdbcType=VARCHAR} + + + update stu_userinfo + set name = #{name,jdbcType=VARCHAR}, + student_id = #{studentId,jdbcType=VARCHAR}, + class_id = #{classId,jdbcType=VARCHAR}, + username = #{username,jdbcType=VARCHAR}, + password = #{password,jdbcType=VARCHAR}, + phone = #{phone,jdbcType=VARCHAR}, + email = #{email,jdbcType=VARCHAR}, + major = #{major,jdbcType=VARCHAR}, + role_id = #{roleId,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + school_id = #{schoolId,jdbcType=VARCHAR}, + school_name = #{schoolName,jdbcType=VARCHAR}, + status = #{status,jdbcType=INTEGER}, + exam_status = #{examStatus,jdbcType=VARCHAR} + where userid = #{userid,jdbcType=VARCHAR} + INSERT INTO stu_userinfo (userid, name, student_id, class_id, username, password, phone, email,major, @@ -380,15 +384,15 @@ - - - - - - - - - + + + + + + + + + +