Commit 3b1e1453 authored by wujipeng's avatar wujipeng
Browse files

我的成绩-汇总

parent c48f5b07
...@@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode; ...@@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class ExamStudentDTO extends ExamStudentEntity { public class ExamStudentDTO extends ExamStudentEntity {
private int pageNum; private int pageNum;
private int pageSize; private int pageSize;
......
...@@ -29,8 +29,10 @@ public class ExamStudentEntity { ...@@ -29,8 +29,10 @@ public class ExamStudentEntity {
private int examId; private int examId;
@ApiModelProperty(value = "学员id")
private String studentId; private String studentId;
@ApiModelProperty(value = "考试成绩")
private Double score; private Double score;
@ApiModelProperty(value = "考试开始时间") @ApiModelProperty(value = "考试开始时间")
......
package com.platform.business.model.vo; package com.platform.business.model.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.platform.business.model.entity.ExamStudentEntity; import com.platform.business.model.entity.ExamStudentEntity;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Date;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class ExamStudentVO extends ExamStudentEntity { public class ExamStudentVO extends ExamStudentEntity {
@ApiModelProperty(value = "考试名称")
private String examName;
@ApiModelProperty(value = "考试类型")
private String type;
@ApiModelProperty(value = "班级均分")
private Double avgScore;
@ApiModelProperty(value = "排名")
private Integer rank;
private String studentName; private String studentName;
private String className; private String className;
private String examName;
private String idCard; private String idCard;
private String factory; private String factory;
private String phone; private String phone;
private String examTime; @ApiModelProperty(value = "考试时间")
@JsonFormat(pattern = "MM-dd", timezone = "GMT+8")
private Date examTime;
@ApiModelProperty(value = "总题数") @ApiModelProperty(value = "总题数")
private Integer totalNum; private Integer totalNum;
......
package com.platform.business.controller; package com.platform.business.controller;
import com.platform.business.model.dto.ExamStudentDTO; import com.platform.business.model.dto.ExamStudentDTO;
import com.platform.business.model.vo.ExamStudentVO;
import com.platform.business.service.ExamStudentService; import com.platform.business.service.ExamStudentService;
import com.platform.business.utils.JwtTokenUtil;
import com.platform.controller.BaseController; import com.platform.controller.BaseController;
import com.platform.model.resp.Result;
import com.platform.page.TableDataInfo; import com.platform.page.TableDataInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import java.util.Map;
@RestController @RestController
@RequestMapping("/exam/student") @RequestMapping("/exam/student")
public class ExamStudentController extends BaseController { public class ExamStudentController extends BaseController {
@Resource @Resource
private ExamStudentService examStudentService; private ExamStudentService examStudentService;
@Resource @ApiOperation(value = "我的成绩-成绩明细")
private JwtTokenUtil jwtTokenUtil; @PostMapping("/page")
@PostMapping("/queryByStudentId") public TableDataInfo page(@RequestBody ExamStudentDTO examStudentDTO) {
public TableDataInfo queryByStudentId(@RequestBody ExamStudentDTO examStudentDTO, HttpServletRequest httpServletRequest) {
String token = httpServletRequest.getHeader("Authorization");
String userName = jwtTokenUtil.getUsernameFromToken(token);
startPage(examStudentDTO.getPageNum(), examStudentDTO.getPageSize()); startPage(examStudentDTO.getPageNum(), examStudentDTO.getPageSize());
return getDataTable(examStudentService.queryByStudentId(userName)); return getDataTable(examStudentService.page(examStudentDTO));
}
@ApiOperation(value = "我的成绩-汇总")
@GetMapping("/summary/{studentId}")
public Result<Map<String, String>> summary(@PathVariable String studentId) {
return Result.data(examStudentService.summary(studentId));
} }
} }
...@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map;
@Mapper @Mapper
public interface ExamStudentMapper extends BaseMapper<ExamStudentEntity> { public interface ExamStudentMapper extends BaseMapper<ExamStudentEntity> {
...@@ -16,11 +17,14 @@ public interface ExamStudentMapper extends BaseMapper<ExamStudentEntity> { ...@@ -16,11 +17,14 @@ public interface ExamStudentMapper extends BaseMapper<ExamStudentEntity> {
List<ExamStudentVO> queryByClassIdAndExamId(@Param("classId") Integer classId,@Param("examId") Integer examId); List<ExamStudentVO> queryByClassIdAndExamId(@Param("classId") Integer classId,@Param("examId") Integer examId);
List<ExamStudentVO> queryByStudentId(@Param("studentId") String studentId); List<ExamStudentVO> page(@Param("studentId") String studentId);
ExamStudentVO paperDetail(@Param("id") Integer id); ExamStudentVO paperDetail(@Param("id") Integer id);
List<ExamStudentVO> queryOneself(@Param("userId") String userId); List<ExamStudentVO> queryOneself(@Param("userId") String userId);
List<ExamStudentVO> queryOneselfTeacher(@Param("userId")String userId); List<ExamStudentVO> queryOneselfTeacher(@Param("userId")String userId);
Map<String, String> summary(@Param("studentId") String studentId);
} }
package com.platform.business.service; package com.platform.business.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.platform.business.model.dto.ExamStudentDTO;
import com.platform.business.model.entity.ExamStudentEntity; import com.platform.business.model.entity.ExamStudentEntity;
import com.platform.business.model.vo.ExamStudentVO; import com.platform.business.model.vo.ExamStudentVO;
import java.util.List; import java.util.List;
import java.util.Map;
public interface ExamStudentService extends IService<ExamStudentEntity> { public interface ExamStudentService extends IService<ExamStudentEntity> {
...@@ -18,7 +20,7 @@ public interface ExamStudentService extends IService<ExamStudentEntity> { ...@@ -18,7 +20,7 @@ public interface ExamStudentService extends IService<ExamStudentEntity> {
List<ExamStudentVO> queryByClassIdAndExamId( Integer classId, Integer examId); List<ExamStudentVO> queryByClassIdAndExamId( Integer classId, Integer examId);
List<ExamStudentVO> queryByStudentId(String userName); List<ExamStudentVO> page(ExamStudentDTO examStudentDTO);
ExamStudentVO paperDetail(Integer id); ExamStudentVO paperDetail(Integer id);
...@@ -26,4 +28,6 @@ public interface ExamStudentService extends IService<ExamStudentEntity> { ...@@ -26,4 +28,6 @@ public interface ExamStudentService extends IService<ExamStudentEntity> {
List<ExamStudentVO> queryOneselfTeacher(String userId); List<ExamStudentVO> queryOneselfTeacher(String userId);
Map<String, String> summary(String studentId);
} }
...@@ -2,21 +2,24 @@ package com.platform.business.service.impl; ...@@ -2,21 +2,24 @@ package com.platform.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.ExamStudentMapper; import com.platform.business.mapper.ExamStudentMapper;
import com.platform.business.model.dto.ExamStudentDTO;
import com.platform.business.model.entity.ExamStudentEntity; import com.platform.business.model.entity.ExamStudentEntity;
import com.platform.business.model.vo.ExamStudentVO; import com.platform.business.model.vo.ExamStudentVO;
import com.platform.business.model.vo.UserVO;
import com.platform.business.service.ExamStudentService; import com.platform.business.service.ExamStudentService;
import com.platform.business.service.UserService; import com.platform.business.service.UserService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamStudentEntity> implements ExamStudentService { public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamStudentEntity> implements ExamStudentService {
@Resource @Resource
private UserService userService; private UserService userService;
@Override @Override
public List<ExamStudentVO> queryByExamId(int id) { public List<ExamStudentVO> queryByExamId(int id) {
return baseMapper.queryByExamId(id); return baseMapper.queryByExamId(id);
...@@ -29,14 +32,8 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam ...@@ -29,14 +32,8 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam
} }
@Override @Override
public List<ExamStudentVO> queryByStudentId(String userName){ public List<ExamStudentVO> page(ExamStudentDTO examStudentDTO) {
UserVO userVO = userService.getUserMessage(userName); return baseMapper.page(examStudentDTO.getStudentId());
String studentId = userVO.getId();
List<ExamStudentVO> examStudentVOList = baseMapper.queryByStudentId(studentId);
for (ExamStudentVO examStudentVO : examStudentVOList){
examStudentVO.setStudentName(userVO.getNickName());
}
return examStudentVOList;
} }
@Override @Override
...@@ -53,4 +50,17 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam ...@@ -53,4 +50,17 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam
public List<ExamStudentVO> queryOneselfTeacher(String userId) { public List<ExamStudentVO> queryOneselfTeacher(String userId) {
return baseMapper.queryOneselfTeacher(userId); return baseMapper.queryOneselfTeacher(userId);
} }
@Override
public Map<String, String> summary(String studentId) {
Map<String, String> result = new HashMap<>();
Map<String, String> summary = baseMapper.summary(studentId);
if (summary != null && !summary.isEmpty()) {
result.put("平均成绩", summary.get("overallAvgScore"));
result.put("班级排名", summary.get("classRank"));
result.put("最高分", summary.get("highestScore"));
result.put("考试次数", summary.get("examCount"));
}
return result;
}
} }
...@@ -482,41 +482,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme ...@@ -482,41 +482,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
return userVO; return userVO;
} }
// @Override
// public UserVO getUserMessage(String userName) {
// // 1. 获取基础用户信息
// UserVO userVO = baseMapper.queryByUserName(userName);
// if (userVO == null) {
// return null;
// }
// // 2. 获取用户所有角色
// List<SysPhoneRoleEntity> allRoles = new ArrayList<>();
// // 获取系统分配的角色
// List<SysPhoneRoleEntity> sysPhoneRoleEntities = sysPhoneRoleService.queryByPhone(userName);
// if (CollectionUtils.isNotEmpty(sysPhoneRoleEntities)) {
// allRoles.addAll(sysPhoneRoleEntities);
// }
// // 获取用户的固有角色(从userVO中)
// String roleName = userVO.getRoleName();
// if (StringUtils.isNotBlank(roleName)) {
// SysPhoneRoleEntity userRole = new SysPhoneRoleEntity();
// userRole.setRoleName(roleName);
// userRole.setPhone(userName);
// allRoles.add(userRole);
// }
// //去重
// allRoles = allRoles.stream().distinct().collect(Collectors.toList());
// // 3. 设置角色列表到userVO
// userVO.setSysPhoneRoleEntities(allRoles);
// // 4. 获取角色对应的菜单权限
// Integer roleId = userVO.getRoleId();
// if (roleId != null) {
// List<SysRoleAndMenuVO> menuList = sysRoleAndMenuService.queryByRoleId(roleId);
// userVO.setSysMenuEntities(menuList);
// }
// return userVO;
// }
@Override @Override
public UserVO queryByUserName(String userName) { public UserVO queryByUserName(String userName) {
return baseMapper.queryByUserName(userName); return baseMapper.queryByUserName(userName);
......
...@@ -46,29 +46,22 @@ ...@@ -46,29 +46,22 @@
and es.mark_flag = 0 and es.mark_flag = 0
</select> </select>
<select id="queryByStudentId" resultType="com.platform.business.model.vo.ExamStudentVO"> <select id="page" resultType="com.platform.business.model.vo.ExamStudentVO">
select SELECT
es.id, es.id,
es.score score, e.name AS examName,
es.class_id classId, es.score,
es.student_id studentId, e.exam_time AS examTime,
c.name className, AVG(es.score) OVER (PARTITION BY es.exam_id) AS avgScore,
e.name examName, RANK() OVER (PARTITION BY es.exam_id ORDER BY es.score DESC) AS rank
e.exam_time examTime FROM
from
exam_student es exam_student es
left join LEFT JOIN
class c exam e ON es.exam_id = e.id
on WHERE
es.class_id = c.id
left join
exam e
on
es.exam_id = e.id
where
es.student_id = #{studentId} es.student_id = #{studentId}
ORDER BY ORDER BY
STR_TO_DATE(SUBSTRING_INDEX(e.exam_time, '-', 1), '%Y.%m.%d %H:%i:%s') DESC e.exam_time DESC;
</select> </select>
<select id="paperDetail" resultType="com.platform.business.model.vo.ExamStudentVO"> <select id="paperDetail" resultType="com.platform.business.model.vo.ExamStudentVO">
select es.id, select es.id,
...@@ -110,4 +103,28 @@ ...@@ -110,4 +103,28 @@
e.chief_id = #{userId} or e.invigilation_id like concat('%',#{userId},'%') e.chief_id = #{userId} or e.invigilation_id like concat('%',#{userId},'%')
); );
</select> </select>
<select id="summary" resultType="java.util.Map">
SELECT
-- 所有考试的平均分:该学生的所有考试分数的平均值
ROUND(AVG(es.score), 1) AS overallAvgScore,
-- 班级排名:按班级分组,计算每个学生的总平均分,然后按总平均分降序排名
RANK() OVER (PARTITION BY es.class_id ORDER BY AVG(es.score) DESC) AS classRank,
-- 最高分:该学生所有考试中的最高得分
MAX(es.score) AS highestScore,
-- 考试次数:该学生参加的考试总次数
COUNT(es.id) AS examCount
FROM
exam_student es
LEFT JOIN
exam e
ON
es.exam_id = e.id
WHERE
es.student_id = #{studentId}
-- 建议加上分数非空判断,避免拉低平均分或影响排名准确性
AND
es.score IS NOT NULL
GROUP BY
es.class_id;
</select>
</mapper> </mapper>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment