From 93dd731bbe904cdedb5b9ce2b938f98433e00d87 Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Fri, 26 Apr 2024 18:13:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=92=8Cmapper=20xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tea/TeaGradeManageController.java | 59 ++++++++++++++--- .../controller/tea/UserController.java | 14 +++- .../entity/tea_dto/TeaExamManageCountDto.java | 11 ++++ .../entity/tea_dto/TeaTrainingInfoDTO.java | 3 + .../mapper/StuTrainingMapper.java | 2 +- .../mapper/StuUserMapper.java | 9 ++- .../mapper/TeaAndStudentExamMapper.java | 5 ++ .../tea/impl/TeaGradeManageServiceImpl.java | 66 ++++++++++--------- src/main/resources/mapper/StuUserMapper.xml | 23 ++++--- 9 files changed, 136 insertions(+), 56 deletions(-) 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 4e2395e..af76f5e 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 @@ -64,24 +64,51 @@ public class TeaGradeManageController { @AnonymousAccess @PostMapping("/getExamInfo") @ApiOperation("考试模式--页面展示(学生端实战考核复用)") - public ResultEntity getExamInfo(@RequestParam Integer index, - @RequestParam Integer size, - @ApiParam("ManyAnswer为考试时间,JudgeAnswer为发布人") @RequestParam String schoolId) { - PageHelper.startPage(index, size); + public ResultEntity> getExamInfo(@RequestParam Integer index, + @RequestParam Integer size, + @ApiParam("ManyAnswer为考试时间,JudgeAnswer为发布人") @RequestParam String schoolId) { TeaExamManageExample teaExamManageExample = new TeaExamManageExample(); teaExamManageExample.createCriteria().andSchoolIdEqualTo(schoolId); List teaExamManages = teaExamManageMapper.selectByExample(teaExamManageExample); List teaExamManageCountDtos = new ArrayList<>(); for (TeaExamManage teaExamManage : teaExamManages) { + List nameList = new ArrayList<>(); TeaExamManageCountDto copyexamManageWithBLOBs = new TeaExamManageCountDto(); + int num = 0; + //获取班级和考试人数 + String classId = teaAndStudentExamMapper.selectByExamId(teaExamManage.getExamManageId()); + String[] split = classId.split(","); + for (String s : split) { + StuClass stuClass = stuClassMapper.selectByPrimaryKey(s); + String className = stuClass.getClassName(); + nameList.add(className); + int count = userMapper.selectNumByClass(s); + num = num + count; + } + copyexamManageWithBLOBs.setExamClass(nameList); + copyexamManageWithBLOBs.setExamNum(num); BeanUtils.copyProperties(teaExamManage, copyexamManageWithBLOBs); Date startTime = teaExamManage.getStartTime(); Date endTime = teaExamManage.getEndTime(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String startTimeString = formatter.format(startTime); String endTimeString = formatter.format(endTime); - + Date date = new Date(); // 当前日期 + Date endtimeDtae = teaExamManage.getEndTime(); // 从 teaExamManage 对象中获取的日期 + Date startTimeDtae = teaExamManage.getStartTime(); + long now = date.getTime(); + long end = endtimeDtae.getTime(); + long start = startTimeDtae.getTime(); + if (now > end) { + // 当前 大于 结束时间 + copyexamManageWithBLOBs.setExamStatus("已结束"); + } else if (now < start) { + // 当前 小于 开始时间 + copyexamManageWithBLOBs.setExamStatus("未开始"); + } else { + copyexamManageWithBLOBs.setExamStatus("进行中"); + } String concatenatedTimeString = startTimeString + " -- " + endTimeString; copyexamManageWithBLOBs.setExamTime(concatenatedTimeString); //考试时间 String userId = teaExamManage.getUserId(); @@ -89,7 +116,8 @@ public class TeaGradeManageController { copyexamManageWithBLOBs.setName(stuUser.getName()); //发布人 teaExamManageCountDtos.add(copyexamManageWithBLOBs); } - return new ResultEntity<>(new PageInfo(teaExamManageCountDtos)); + PageUtil.pageHelper(teaExamManageCountDtos, index, size); + return new ResultEntity<>(new PageInfo<>(teaExamManageCountDtos)); } @AnonymousAccess @@ -300,7 +328,7 @@ public class TeaGradeManageController { public ResultEntity> getReportCorrect(@RequestParam String schoolId, @RequestParam Integer index, @RequestParam Integer size, - @RequestParam String module, + @RequestParam(required = false) String module, @RequestParam(required = false) String classId, @RequestParam(required = false) String keyWord) { @@ -333,7 +361,7 @@ public class TeaGradeManageController { SysWeightExample sysWeightExample = new SysWeightExample(); sysWeightExample.createCriteria().andCourseIdEqualTo(sysWeight.getCourseId()); List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); - if (sysWeights.isEmpty()) {//有 update + if (!sysWeights.isEmpty()) {//有 update sysWeightMapper.updateByPrimaryKey(sysWeight); } else { //没有 insert sysWeightMapper.insert(sysWeight); @@ -349,6 +377,21 @@ public class TeaGradeManageController { return new ResultEntity<>(moduleBySchoolId); } + @AnonymousAccess + @PostMapping("/getModuleByCourseId") + @ApiOperation("练习模式--权重回显") + public ResultEntity getModuleBySchoolId(@RequestParam String courseId, + @RequestParam String schoolId) { + SysWeightExample sysWeightExample = new SysWeightExample(); + sysWeightExample.createCriteria().andSchoolIdEqualTo(schoolId).andCourseIdEqualTo(courseId); + List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); + if (sysWeights.isEmpty()) { + //todo 是否需要设置默认权重 + return new ResultEntity<>(new SysWeight()); + } + return new ResultEntity<>(sysWeights.get(0)); + } + @AnonymousAccess @PostMapping("/getTheoryInfo") 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 34f36d7..7998a05 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 @@ -9,6 +9,7 @@ import com.sztzjy.financial_bigdata.config.security.JwtUser; import com.sztzjy.financial_bigdata.config.security.LoginResult; import com.sztzjy.financial_bigdata.config.security.TokenProvider; import com.sztzjy.financial_bigdata.entity.*; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import com.sztzjy.financial_bigdata.entity.stu_dto.StuUserDto; import com.sztzjy.financial_bigdata.mapper.StuClassMapper; import com.sztzjy.financial_bigdata.mapper.StuUserMapper; @@ -30,6 +31,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.time.LocalDateTime; @@ -51,6 +53,9 @@ public class UserController { private ITeaUserService userService; @Autowired private SysLoginLogMapper sysLoginLogMapper; + @Autowired + private AuthenticationManagerBuilder authenticationManagerBuilder; + // 用户登录时记录的信息 private static LocalDateTime loginTime; private static String loginIp; @@ -65,10 +70,15 @@ public class UserController { @RequestParam String userName, HttpServletRequest request, @RequestParam(required = false) String TOKEN) throws Exception { - JwtUser jwtUser; String passWord = RsaUtil.decryptByPrivateKey(passwordEncode); if (StringUtils.isBlank(TOKEN)) { + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userName, passWord); + System.out.println(authenticationToken); + Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken); + SecurityContextHolder.getContext().setAuthentication(authentication); + JwtUser jwtUser1 = (JwtUser) authentication.getPrincipal(); + String token = TokenProvider.createToken(jwtUser1); // 1、子系统直接登录 StuUserExample stuUserExample = new StuUserExample(); stuUserExample.createCriteria().andUsernameEqualTo(userName).andPasswordEqualTo(passWord); @@ -89,6 +99,7 @@ public class UserController { map.put("userId", user.getUserid()); String uuid = getIPAndPlace(request, user.getName(), user.getUserid(), user.getStudentId()); map.put("logId", uuid); + map.put("token", token); return new ResultEntity(HttpStatus.OK, map); } } else { // 2、智云单点登录 @@ -116,6 +127,7 @@ public class UserController { map.put("schoolId", loginResult.getSchoolId()); map.put("classId", loginResult.getClassId()); map.put("userId", loginResult.getUserId()); + map.put("token", token); String uuid = getIPAndPlace(request, loginResult.getName(), loginResult.getUserId(), jwtUser.getUsername()); //todo 学号暂时没有 map.put("logId", uuid); return new ResultEntity(HttpStatus.OK, map); //todo 从智云登录后将用户添加到本地用户表 diff --git a/src/main/java/com/sztzjy/financial_bigdata/entity/tea_dto/TeaExamManageCountDto.java b/src/main/java/com/sztzjy/financial_bigdata/entity/tea_dto/TeaExamManageCountDto.java index ee7b952..21cc89c 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/entity/tea_dto/TeaExamManageCountDto.java +++ b/src/main/java/com/sztzjy/financial_bigdata/entity/tea_dto/TeaExamManageCountDto.java @@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; + /** * @Author xcj * @Date 2024/3/14 @@ -37,4 +39,13 @@ public class TeaExamManageCountDto { @ApiModelProperty("LOGO地址") private String logoAddress; + + @ApiModelProperty("状态") + private String examStatus; + + @ApiModelProperty("考试人数") + private int examNum; + + @ApiModelProperty("考试班级") + private List examClass; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/entity/tea_dto/TeaTrainingInfoDTO.java b/src/main/java/com/sztzjy/financial_bigdata/entity/tea_dto/TeaTrainingInfoDTO.java index ac9aca5..9858cb8 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/entity/tea_dto/TeaTrainingInfoDTO.java +++ b/src/main/java/com/sztzjy/financial_bigdata/entity/tea_dto/TeaTrainingInfoDTO.java @@ -15,6 +15,9 @@ import java.math.BigDecimal; public class TeaTrainingInfoDTO { private String userId; + @ApiModelProperty("实训ID") + private String trainingId; + @ApiModelProperty("排名") private int rank; diff --git a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuTrainingMapper.java b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuTrainingMapper.java index 7aab15e..edaa87d 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuTrainingMapper.java +++ b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuTrainingMapper.java @@ -42,7 +42,7 @@ public interface StuTrainingMapper { int updateByPrimaryKey(StuTraining record); - @Select("select count(progress) FROM stu_training WHERE progress = 1 and user_id = #{userId}") + @Select("select count(progress) FROM stu_training WHERE progress = 6 and user_id = #{userId}") int selectProgressFinish(@Param("userId") String userId); @Select("SELECT COUNT(progress) FROM stu_training WHERE user_id = #{userId} AND (exp_training_score <> 0 AND exp_training_score IS NOT NULL)") 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 61da1b7..04f9e25 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuUserMapper.java +++ b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuUserMapper.java @@ -40,9 +40,12 @@ public interface StuUserMapper { void batchInsertStudents(List users); - List selectByCondition(@Param("classId") String classId, + List selectByCondition(@Param("schoolId") String schoolId, @Param("module") String module, - @Param("keyWord") String keyWord, - @Param("schoolId") String schoolId); + @Param("classId") String classId, + @Param("keyWord") String keyWord); + + @Select("select count(*) from stu_userinfo where class_id = #{s}") + int selectNumByClass(@Param("s") String s); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/financial_bigdata/mapper/TeaAndStudentExamMapper.java b/src/main/java/com/sztzjy/financial_bigdata/mapper/TeaAndStudentExamMapper.java index c5d0bfa..071c563 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/mapper/TeaAndStudentExamMapper.java +++ b/src/main/java/com/sztzjy/financial_bigdata/mapper/TeaAndStudentExamMapper.java @@ -6,6 +6,8 @@ import java.util.List; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + @Mapper public interface TeaAndStudentExamMapper { long countByExample(TeaAndStudentExamExample example); @@ -29,4 +31,7 @@ public interface TeaAndStudentExamMapper { int updateByPrimaryKeySelective(TeaAndStudentExam record); int updateByPrimaryKey(TeaAndStudentExam record); + + @Select("select class_id from tea_and_student_exam where exam_manage_id =#{examManageId}") + String selectByExamId(@Param("examManageId") String examManageId); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaGradeManageServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaGradeManageServiceImpl.java index 7dcb4c5..e9f5842 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaGradeManageServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaGradeManageServiceImpl.java @@ -47,10 +47,9 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { private StuTrainingMapper stuTrainingMapper; - @Override - public PageInfo getTrainingInfo(Integer index, Integer size, String schoolId, String keyWord, String classId,String userId) { - List list = getTeaTrainingInfoDTOS(schoolId, keyWord, classId,userId); + public PageInfo getTrainingInfo(Integer index, Integer size, String schoolId, String keyWord, String classId, String userId) { + List list = getTeaTrainingInfoDTOS(schoolId, keyWord, classId, userId); list.sort(new TotalScoreComparator()); int i = 0; for (TeaTrainingInfoDTO teaTrainingInfoDTO : list) { @@ -68,8 +67,8 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { * @Date 2024/3/19 */ @Override - public void exportTrainingInfo(HttpServletResponse response, String schoolId, String keyWord, String classId,String userId) { - List list = getTeaTrainingInfoDTOS(schoolId, keyWord, classId,userId); + public void exportTrainingInfo(HttpServletResponse response, String schoolId, String keyWord, String classId, String userId) { + List list = getTeaTrainingInfoDTOS(schoolId, keyWord, classId, userId); //导出的表名 String title = IdUtil.simpleUUID(); //表中第一行表头字段 @@ -175,7 +174,9 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { SysCourseChapter sysCourseChapter = sysCourseChapterMapper.selectByPrimaryKey(stuTrainingWithBLOB.getChapterId()); TeaTrainingDto newData = new TeaTrainingDto(); BeanUtils.copyProperties(stuTrainingWithBLOBs, newData); - newData.setTaskModule(sysCourseChapter.getChapterName()); + if (sysCourseChapter != null) { + newData.setTaskModule(sysCourseChapter.getChapterName()); + } if (StringUtils.isNotBlank(stuTrainingWithBLOB.getReportId())) { String reportId = stuTrainingWithBLOB.getReportId(); TrainingReport trainingReport = trainingReportMapper.selectByPrimaryKey(reportId); @@ -282,7 +283,7 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } - private List getTeaTrainingInfoDTOS(String schoolId, String keyWord, String classId,String userId) { + private List getTeaTrainingInfoDTOS(String schoolId, String keyWord, String classId, String userId) { StuUserExample userExample = new StuUserExample(); StuUserExample.Criteria criteria = userExample.createCriteria(); criteria.andSchoolIdEqualTo(schoolId); @@ -300,7 +301,7 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { if (stuUsers.isEmpty()) { return null; } else { - for (StuUser stuUser : stuUsers) { + for (StuUser stuUser : stuUsers) { //先查出学校下所有的用户ID,再根据USERid去实训表中查实训记录,实训记录为空就跳过,有数据就封装 TeaTrainingInfoDTO teaTrainingInfoDTO = new TeaTrainingInfoDTO(); StuClass stuClass = classMapper.selectByPrimaryKey(stuUser.getClassId()); //封装user表的数据 @@ -308,32 +309,28 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { teaTrainingInfoDTO.setStudentId(stuUser.getStudentId()); teaTrainingInfoDTO.setName(stuUser.getName()); teaTrainingInfoDTO.setUserId(stuUser.getUserid()); - //求实训进度 + + //看用户在实训表有没有记录 StuTrainingExample stuTrainingExample = new StuTrainingExample(); - stuTrainingExample.createCriteria().andProgressEqualTo(BigDecimal.valueOf(6)).andUserIdEqualTo(stuUser.getUserid()); //进度为6代表这个章节完成了 + stuTrainingExample.createCriteria().andUserIdEqualTo(stuUser.getUserid()); List stuTrainings = trainingMapper.selectByExampleWithBLOBs(stuTrainingExample); - int trainingSize = stuTrainingMapper.selectProgressFinish(userId); //已学任务数量 - if (stuTrainings.isEmpty()) { - teaTrainingInfoDTO.setProgress(BigDecimal.ZERO); //实训表为0设置为0 - teaTrainingInfoDTO.setTotalScore(BigDecimal.ZERO); - list.add(teaTrainingInfoDTO); - } - if (trainingSize != 0 && chapterNum != 0) { - int i = chapterNum / trainingSize; //综合进度 - teaTrainingInfoDTO.setProgress(BigDecimal.valueOf(i)); - } - - //求综合得分 拿到每个已完成的章节分数 - BigDecimal totalScore = BigDecimal.valueOf(0); - if (stuTrainings.isEmpty()) { - list.add(teaTrainingInfoDTO); + int trainingSize = stuTrainingMapper.selectProgressFinish(stuUser.getUserid()); //已学任务数量 + if (stuTrainings.isEmpty()) { //实训为空跳过这个用户 continue; } for (StuTrainingWithBLOBs stuTrainingWithBLOB : stuTrainings) { + if (trainingSize != 0 && chapterNum != 0) { + int i = trainingSize / chapterNum; //综合进度 + teaTrainingInfoDTO.setProgress(BigDecimal.valueOf(i)); + } + + //求综合得分 拿到每个已完成的章节分数 + BigDecimal totalScore = BigDecimal.valueOf(0); + teaTrainingInfoDTO.setTrainingId(stuTrainingWithBLOB.getTrainingId()); TrainingReport trainingReport = trainingReportMapper.selectByPrimaryKey(stuTrainingWithBLOB.getReportId()); BigDecimal reportScore = null; - if (trainingReport!=null){ + if (trainingReport != null) { reportScore = trainingReport.getTeacherScore(); } BigDecimal expTrainingScore = stuTrainingWithBLOB.getExpTrainingScore(); @@ -355,11 +352,11 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { if (learningEvalScore != null && BigDecimal.ZERO.compareTo(learningEvalScore) == 0) { totalScore = totalScore.add(learningEvalScore); } + int score = totalScore.intValue() / chapterNum; //已完成的模块分数/总模块数量 + teaTrainingInfoDTO.setTotalScore(BigDecimal.valueOf(score)); } + list.add(teaTrainingInfoDTO); } - int score = totalScore.intValue() / chapterNum; //已完成的模块分数/总模块数量 - teaTrainingInfoDTO.setTotalScore(BigDecimal.valueOf(score)); - list.add(teaTrainingInfoDTO); } return list; } @@ -368,11 +365,18 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { public class TotalScoreComparator implements Comparator { @Override public int compare(TeaTrainingInfoDTO o1, TeaTrainingInfoDTO o2) { - return Integer.compare(o2.getTotalScore().intValueExact(), o1.getTotalScore().intValueExact()); + if (o2.getTotalScore() == null && o1.getTotalScore() == null) { + return 0; + } else if (o1 == null) { + return -1; + } else if (o2 == null) { + return 1; + } else { + return Integer.compare(o2.getTotalScore().intValueExact(), o1.getTotalScore().intValueExact()); + } } } - /* 按得分比较排序 * @author xcj * @Date 2023/11/6 diff --git a/src/main/resources/mapper/StuUserMapper.xml b/src/main/resources/mapper/StuUserMapper.xml index 7c10f4b..046cd1d 100644 --- a/src/main/resources/mapper/StuUserMapper.xml +++ b/src/main/resources/mapper/StuUserMapper.xml @@ -386,18 +386,17 @@ from stu_userinfo u JOIN training_report r ON u.userid = r.user_id JOIN stu_class sc ON u.class_id = sc.class_id - - AND u.school_id = #{schoolId} - - AND r.chapter_name = #{module} - - - AND u.class_id = #{classId} - - - AND (u.name = #{keyWord} OR u.student_id = #{keyWord}) - - + where + u.school_id = #{schoolId} + + AND u.class_id = #{classId} + + + AND r.chapter_name = #{module} + + + AND (u.name = #{keyWord} OR u.student_id = #{keyWord}) + ORDER BY r.teacher_score DESC