练习积分排名

master
c1769 2 years ago
parent 6239cc67ff
commit ded8cfe1bc

@ -49,5 +49,7 @@ public interface UserExaminationsDao extends BaseMapper<UserExaminations> {
List<UserExaminations> notParticipatingUsers(Long examinationId); List<UserExaminations> notParticipatingUsers(Long examinationId);
List<UserExaminations> practiceModeIntegralStatistics(Long classId); List<UserExaminations> classPracticeModeIntegral(Long classId);
PageQuery<UserIntegerExcel> practiceModeIntegralOrder(PageQuery query, UserExaminationsQuery userExaminationsQuery);
} }

@ -71,6 +71,12 @@ public class UserExaminations extends BaseEntity {
//个人的班级内排名 //个人的班级内排名
private Integer classOrders; private Integer classOrders;
// 练习模式积分
private Integer integral;
// 练习模式积分排名
private Integer integralOrder;
//个人在团队内排名 //个人在团队内排名
private Integer teamOrders; private Integer teamOrders;

@ -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;
}

@ -1,5 +1,6 @@
package com.ibeetl.jlw.service; package com.ibeetl.jlw.service;
import cn.hutool.core.bean.BeanUtil;
import cn.jlw.Exception.GlobalException; import cn.jlw.Exception.GlobalException;
import cn.jlw.util.BusinessUtils; import cn.jlw.util.BusinessUtils;
import cn.jlw.util.JsonMergeUtil; import cn.jlw.util.JsonMergeUtil;
@ -443,75 +444,66 @@ public class UserExaminationsService extends CoreBaseService<UserExaminations> {
* @param classId ID * @param classId ID
* @return classOrder integral * @return classOrder integral
*/ */
public Map<String, Integer> practiceModeIntegral(Long userId, Long classId) { public UserExaminations userPracticeModeIntegral(Long userId, Long classId) {
Map<String, Integer> result = new HashMap<>(); final List<UserExaminations> ues = userExaminationsDao.classPracticeModeIntegral(classId);
result.put("integral", 0); if (ues.isEmpty()) {
final List<UserExaminations> ues = userExaminationsDao.practiceModeIntegralStatistics(classId); return null;
final Map<Long, List<UserExaminations>> collect = ues.stream().collect(Collectors.groupingBy(UserExaminations::getUserId));
if (!collect.containsKey(userId)) {
// 没有成绩
result.put("classOrder", collect.keySet().size() + 1);
return result;
} }
for (UserExaminations ue : ues) {
List<UserExaminations> integrals = new ArrayList<>(); if (Objects.equals(userId, ue.getUserId())) {
for (Long sid : collect.keySet()) { return ue;
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;
} }
classOrder++;
} }
return result; return null;
} }
private int getStudentIntegral(List<UserExaminations> userExaminations) { /**
if (userExaminations == null || userExaminations.isEmpty()) { * 20
return 0; * 50100
} * 200
final Map<Integer, List<UserExaminations>> collect = */
userExaminations.stream().filter(i -> i.getMode() != null) public PageQuery<UserIntegerExcel> practiceModeIntegralOrder(UserExaminationsQuery userExaminationsQuery) {
.collect(Collectors.groupingBy(UserExaminations::getMode)); if (!StringUtils.isEmpty(userExaminationsQuery.getUsername())) {
int totalIntegral = 0; userExaminationsQuery.setClassId(null);
for (Integer mode : collect.keySet()) {
final List<UserExaminations> modeUEs = collect.get(mode);
Set<Long> 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; return userExaminationsDao.practiceModeIntegralOrder(userExaminationsQuery.getPageQuery(), userExaminationsQuery);
} }
// private int getStudentIntegral(List<UserExaminations> userExaminations) {
// if (userExaminations == null || userExaminations.isEmpty()) {
// return 0;
// }
// final Map<Integer, List<UserExaminations>> collect =
// userExaminations.stream().filter(i -> i.getMode() != null)
// .collect(Collectors.groupingBy(UserExaminations::getMode));
// int totalIntegral = 0;
// for (Integer mode : collect.keySet()) {
// final List<UserExaminations> modeUEs = collect.get(mode);
// Set<Long> 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;
// }
/** /**
* *
*/ */

@ -208,11 +208,39 @@ public class UserExaminationsController {
} }
/** /**
* *
*/ */
@GetMapping("/practiceModeIntegral") @GetMapping("/userPracticeModeIntegral")
@FinancialAuth @FinancialAuth
public JsonResult<Map<String, Integer>> practiceModeIntegral(@FinancialUser Users user) { public JsonResult<UserExaminations> userPracticeModeIntegral(@FinancialUser Users user) {
return JsonResult.success(userExaminationsService.practiceModeIntegral(user.getId(), user.getClassId())); return JsonResult.success(userExaminationsService.userPracticeModeIntegral(user.getId(), user.getClassId()));
} }
/**
*
*/
@GetMapping("/practiceModeIntegralOrder")
@FinancialAuth
public JsonResult<PageQuery<UserIntegerExcel>> 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<UserIntegerExcel> 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);
}
}
} }

@ -1,5 +1,6 @@
package com.ibeetl.jlw.web.query; package com.ibeetl.jlw.web.query;
import cn.hutool.core.bean.BeanUtil;
import com.ibeetl.jlw.entity.UserExaminations; import com.ibeetl.jlw.entity.UserExaminations;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -65,32 +66,15 @@ public class UserExaminationsQuery extends PageParam {
private String studentId; private String studentId;
private String search; private String search;
private Integer size; private Integer size;
// 练习模式积分
private Integer integral;
// 练习模式积分排名
private Integer integralOrder;
public UserExaminations pojo(){ public UserExaminations pojo(){
UserExaminations pojo = new UserExaminations(); UserExaminations pojo = new UserExaminations();
pojo.setId(this.getId()); BeanUtil.copyProperties(this, pojo);
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());
return pojo; return pojo;
} }

@ -495,23 +495,42 @@ WHERE
) )
practiceModeIntegralStatistics practiceModeIntegralOrder
=== ===
* 练习模式积分统计 * 练习模式积分统计
SELECT SELECT
t2.examination_id, @pageTag(){
t2.flow_id, t1.user_id, t1.integral, t2.class_id, t3.name class_name, t2.username, t2.student_id,
t2.instance_id, @if(!isEmpty(classId)){
t2.class_id, row_number() over(ORDER BY integral DESC) as integral_order
t2.user_id, @}
t3.MODE @if(isEmpty(classId)){
t1.integral_order
@}
@}
FROM FROM
financings t1 user_integral t1
JOIN user_examinations t2 ON t1.instance_id = t2.instance_id join users t2 on t1.user_id = t2.id
JOIN examinations t3 ON t1.examination_id = t3.id join classes t3 on t3.classes_id = t2.class_id
WHERE @if(!isEmpty(classId)){
t1.financing_status = 9 and t1.class_id =#classId#
AND t2.class_id = #classId# @}
AND t3.type = 0 @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#

Loading…
Cancel
Save