diff --git a/web/src/main/java/com/ibeetl/jlw/dao/UserExaminationsDao.java b/web/src/main/java/com/ibeetl/jlw/dao/UserExaminationsDao.java index c8eae07..5c72361 100644 --- a/web/src/main/java/com/ibeetl/jlw/dao/UserExaminationsDao.java +++ b/web/src/main/java/com/ibeetl/jlw/dao/UserExaminationsDao.java @@ -49,5 +49,7 @@ public interface UserExaminationsDao extends BaseMapper { List notParticipatingUsers(Long examinationId); - List practiceModeIntegralStatistics(Long classId); + List classPracticeModeIntegral(Long classId); + + PageQuery practiceModeIntegralOrder(PageQuery query, UserExaminationsQuery userExaminationsQuery); } diff --git a/web/src/main/java/com/ibeetl/jlw/entity/UserExaminations.java b/web/src/main/java/com/ibeetl/jlw/entity/UserExaminations.java index 072d633..8570d21 100644 --- a/web/src/main/java/com/ibeetl/jlw/entity/UserExaminations.java +++ b/web/src/main/java/com/ibeetl/jlw/entity/UserExaminations.java @@ -71,6 +71,12 @@ public class UserExaminations extends BaseEntity { //个人的班级内排名 private Integer classOrders; + // 练习模式积分 + private Integer integral; + + // 练习模式积分排名 + private Integer integralOrder; + //个人在团队内排名 private Integer teamOrders; diff --git a/web/src/main/java/com/ibeetl/jlw/entity/UserIntegerExcel.java b/web/src/main/java/com/ibeetl/jlw/entity/UserIntegerExcel.java new file mode 100644 index 0000000..0224c75 --- /dev/null +++ b/web/src/main/java/com/ibeetl/jlw/entity/UserIntegerExcel.java @@ -0,0 +1,30 @@ +package com.ibeetl.jlw.entity; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + + +/* + * 练习积分排名 导出 + * gen by Spring Boot2 Admin 2022-07-20 + */ +@Data +public class UserIntegerExcel { + + @ExcelProperty(value = "排名", index = 0) + private String integralOrder; + + @ExcelProperty(value = "学号", index = 1) + private Long studentId; + + @ExcelProperty(value = "姓名", index = 2) + private String username; + + @ExcelProperty(value = "班级", index = 3) + private String className; + + @ExcelProperty(value = "练习积分", index = 4) + private Long integral; + + +} diff --git a/web/src/main/java/com/ibeetl/jlw/service/UserExaminationsService.java b/web/src/main/java/com/ibeetl/jlw/service/UserExaminationsService.java index 033ee30..7ee3e29 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/UserExaminationsService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/UserExaminationsService.java @@ -1,5 +1,6 @@ package com.ibeetl.jlw.service; +import cn.hutool.core.bean.BeanUtil; import cn.jlw.Exception.GlobalException; import cn.jlw.util.BusinessUtils; import cn.jlw.util.JsonMergeUtil; @@ -443,75 +444,66 @@ public class UserExaminationsService extends CoreBaseService { * @param classId 学生班级ID * @return classOrder班级排名 integral积分 */ - public Map practiceModeIntegral(Long userId, Long classId) { - Map result = new HashMap<>(); - result.put("integral", 0); - final List ues = userExaminationsDao.practiceModeIntegralStatistics(classId); - - final Map> collect = ues.stream().collect(Collectors.groupingBy(UserExaminations::getUserId)); - if (!collect.containsKey(userId)) { - // 没有成绩 - result.put("classOrder", collect.keySet().size() + 1); - return result; + public UserExaminations userPracticeModeIntegral(Long userId, Long classId) { + final List ues = userExaminationsDao.classPracticeModeIntegral(classId); + if (ues.isEmpty()) { + return null; } - - List integrals = new ArrayList<>(); - for (Long sid : collect.keySet()) { - final UserExaminations ue = new UserExaminations(); - ue.setUserId(sid); - ue.setClassOrders(getStudentIntegral(collect.get(sid))); - integrals.add(ue); - } - integrals.sort(Comparator.comparing(UserExaminations::getClassOrders)); - Collections.reverse(integrals); - - int classOrder = 1; - for (UserExaminations integral : integrals) { - if (Objects.equals(integral.getUserId(), userId)) { - result.put("classOrder", classOrder); - result.put("integral", integral.getClassOrders()); - break; + for (UserExaminations ue : ues) { + if (Objects.equals(userId, ue.getUserId())) { + return ue; } - classOrder++; } - return result; + return null; } - private int getStudentIntegral(List userExaminations) { - if (userExaminations == null || userExaminations.isEmpty()) { - return 0; - } - final Map> collect = - userExaminations.stream().filter(i -> i.getMode() != null) - .collect(Collectors.groupingBy(UserExaminations::getMode)); - int totalIntegral = 0; - for (Integer mode : collect.keySet()) { - final List modeUEs = collect.get(mode); - Set flowIds = new HashSet<>(); - for (UserExaminations modeUE : modeUEs) { - flowIds.add(modeUE.getFlowId()); - } - // 完成全部五条流程 - boolean allFlow = flowIds.size() > 4; - if (mode == 0) { - // 个人模式20积分 - totalIntegral += modeUEs.size() * 20; - // 走完全部五个流程的个人练习模式,奖励100积分; - if (allFlow) { - totalIntegral += 100; - } - } else { - // 团队模式50积分 - totalIntegral += modeUEs.size() * 50; - // 走完全部五个流程的团队模式,奖励200积分 - if (allFlow) { - totalIntegral += 200; - } - } + /** + * 练习模式设置积分,完成一个流程的个人或者团队练习,给积分。五个流程,每走完一遍个人练习流程得20积分, + * 每走完一遍团队练习团队中每人得50积分,走完全部五个流程的个人练习模式,奖励100积分; + * 走完全部五个流程的团队模式,奖励200积分。学生端界面显示学生的练习积分及班级排名。 + */ + public PageQuery practiceModeIntegralOrder(UserExaminationsQuery userExaminationsQuery) { + if (!StringUtils.isEmpty(userExaminationsQuery.getUsername())) { + userExaminationsQuery.setClassId(null); } - return totalIntegral; + return userExaminationsDao.practiceModeIntegralOrder(userExaminationsQuery.getPageQuery(), userExaminationsQuery); } +// private int getStudentIntegral(List userExaminations) { +// if (userExaminations == null || userExaminations.isEmpty()) { +// return 0; +// } +// final Map> collect = +// userExaminations.stream().filter(i -> i.getMode() != null) +// .collect(Collectors.groupingBy(UserExaminations::getMode)); +// int totalIntegral = 0; +// for (Integer mode : collect.keySet()) { +// final List modeUEs = collect.get(mode); +// Set flowIds = new HashSet<>(); +// for (UserExaminations modeUE : modeUEs) { +// flowIds.add(modeUE.getFlowId()); +// } +// // 完成全部五条流程 +// boolean allFlow = flowIds.size() > 4; +// if (mode == 0) { +// // 个人模式20积分 +// totalIntegral += modeUEs.size() * 20; +// // 走完全部五个流程的个人练习模式,奖励100积分; +// if (allFlow) { +// totalIntegral += 100; +// } +// } else { +// // 团队模式50积分 +// totalIntegral += modeUEs.size() * 50; +// // 走完全部五个流程的团队模式,奖励200积分 +// if (allFlow) { +// totalIntegral += 200; +// } +// } +// } +// return totalIntegral; +// } + /** * 初始化没有成绩的学生实训考核 */ diff --git a/web/src/main/java/com/ibeetl/jlw/web/UserExaminationsController.java b/web/src/main/java/com/ibeetl/jlw/web/UserExaminationsController.java index 7edb9ba..c1bbcbe 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/UserExaminationsController.java +++ b/web/src/main/java/com/ibeetl/jlw/web/UserExaminationsController.java @@ -208,11 +208,39 @@ public class UserExaminationsController { } /** - * 学生提交实训报告 + * 首页 学生练习积分 */ - @GetMapping("/practiceModeIntegral") + @GetMapping("/userPracticeModeIntegral") @FinancialAuth - public JsonResult> practiceModeIntegral(@FinancialUser Users user) { - return JsonResult.success(userExaminationsService.practiceModeIntegral(user.getId(), user.getClassId())); + public JsonResult userPracticeModeIntegral(@FinancialUser Users user) { + return JsonResult.success(userExaminationsService.userPracticeModeIntegral(user.getId(), user.getClassId())); } + + /** + * 学生练习积分排名 + */ + @GetMapping("/practiceModeIntegralOrder") + @FinancialAuth + public JsonResult> practiceModeIntegralOrder(UserExaminationsQuery userExaminationsQuery) { + return JsonResult.success(userExaminationsService.practiceModeIntegralOrder(userExaminationsQuery)); + } + + /** + * 导出学生练习积分排名 + */ + @GetMapping("/practiceModeIntegralOrder/export") + public void practiceModeIntegralOrderExport(HttpServletResponse response, UserExaminationsQuery userExaminationsQuery) { + userExaminationsQuery.setPage(1); + userExaminationsQuery.setSize(99999); + final List list = userExaminationsService.practiceModeIntegralOrder(userExaminationsQuery).getList(); + response.setCharacterEncoding("utf-8"); + try { + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("练习排名.xlsx", "UTF-8")); + response.setHeader("content-type", "application/octet-stream"); + EasyExcel.write(response.getOutputStream(), UserIntegerExcel.class).sheet("sheet1").doWrite(list); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } diff --git a/web/src/main/java/com/ibeetl/jlw/web/query/UserExaminationsQuery.java b/web/src/main/java/com/ibeetl/jlw/web/query/UserExaminationsQuery.java index 950e532..4af1695 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/query/UserExaminationsQuery.java +++ b/web/src/main/java/com/ibeetl/jlw/web/query/UserExaminationsQuery.java @@ -1,5 +1,6 @@ package com.ibeetl.jlw.web.query; +import cn.hutool.core.bean.BeanUtil; import com.ibeetl.jlw.entity.UserExaminations; import lombok.Data; import lombok.EqualsAndHashCode; @@ -65,32 +66,15 @@ public class UserExaminationsQuery extends PageParam { private String studentId; private String search; private Integer size; + // 练习模式积分 + private Integer integral; + // 练习模式积分排名 + private Integer integralOrder; public UserExaminations pojo(){ UserExaminations pojo = new UserExaminations(); - pojo.setId(this.getId()); - pojo.setFlowId(this.getFlowId()); - pojo.setExaminationId(this.getExaminationId()); - pojo.setUserId(this.getUserId()); - pojo.setTeamId(this.getTeamId()); - pojo.setFinancialId(this.getFinancialId()); - pojo.setInstanceId(this.getInstanceId()); - pojo.setStatus(this.getStatus()); - pojo.setFinishTime(this.getFinishTime()); - pojo.setReportFile(this.getReportFile()); - pojo.setReportName(this.getReportName()); - pojo.setFlowScores(this.getFlowScores()); - pojo.setReportScores(this.getReportScores()); - pojo.setRaiseScores(this.getRaiseScores()); - pojo.setDurationScores(this.getDurationScores()); - pojo.setTotalScores(this.getTotalScores()); - pojo.setClassId(this.getClassId()); - pojo.setClassOrders(this.getClassOrders()); - pojo.setTeamOrders(this.getTeamOrders()); - pojo.setData(this.getData()); - pojo.setCreatedAt(this.getCreatedAt()); - pojo.setUpdatedAt(this.getUpdatedAt()); + BeanUtil.copyProperties(this, pojo); return pojo; } diff --git a/web/src/main/resources/sql/jlw/userExaminations.md b/web/src/main/resources/sql/jlw/userExaminations.md index 920c919..50ae1ad 100644 --- a/web/src/main/resources/sql/jlw/userExaminations.md +++ b/web/src/main/resources/sql/jlw/userExaminations.md @@ -495,23 +495,42 @@ WHERE ) -practiceModeIntegralStatistics +practiceModeIntegralOrder === * 练习模式积分统计 SELECT - t2.examination_id, - t2.flow_id, - t2.instance_id, - t2.class_id, - t2.user_id, - t3.MODE + @pageTag(){ + t1.user_id, t1.integral, t2.class_id, t3.name class_name, t2.username, t2.student_id, + @if(!isEmpty(classId)){ + row_number() over(ORDER BY integral DESC) as integral_order + @} + @if(isEmpty(classId)){ + t1.integral_order + @} + @} FROM - financings t1 - JOIN user_examinations t2 ON t1.instance_id = t2.instance_id - JOIN examinations t3 ON t1.examination_id = t3.id - WHERE - t1.financing_status = 9 - AND t2.class_id = #classId# - AND t3.type = 0 + user_integral t1 + join users t2 on t1.user_id = t2.id + join classes t3 on t3.classes_id = t2.class_id + @if(!isEmpty(classId)){ + and t1.class_id =#classId# + @} + @if(!isEmpty(username)){ + and (t2.username =#username# or t2.student_id =#username#) + @} + order by integral_order + + +classPracticeModeIntegral +=== + +* 班级练习模式积分和排名 + + SELECT + t1.user_id, t1.integral, + row_number() over(ORDER BY integral DESC) as integral_order + FROM + user_integral t1 + where t1.class_id = #classId#