Browse Source

综合报告-排行榜-列表

ywx
雍文秀 3 weeks ago
parent
commit
b31dae58b6

+ 4
- 9
smarking/src/main/java/com/xhkjedu/smarking/controller/report/ZhReportController.java View File

@@ -57,7 +57,7 @@ public class ZhReportController {
57 57
     }
58 58
 
59 59
     /**
60
-     * @Description 排行榜
60
+     * @Description 排行榜-列表
61 61
      * @Date 2025/1/6 9:11
62 62
      * @Author YWX
63 63
      * @Param [params]
@@ -65,18 +65,13 @@ public class ZhReportController {
65 65
      **/
66 66
     @PostMapping("/phb")
67 67
     public ResultVo listStudentForPhb(@RequestBody StudentParams params) {
68
-        Integer page = params.getPage();
69
-        Integer pageSize = params.getPageSize();
70 68
         N_Utils.validation(new Object[]{
71 69
                 params.getExamid(), "考试id", 1
72
-                , params.getClassids(), "班级", 2
70
+                , params.getSubjectid(), "科目", 3
71
+                , params.getClassids(), "班级", 3
73 72
                 , params.getFields(), "指标", 3
74
-                , page, "显示页码", 1, pageSize, "显示条数", 1
75 73
         });
76
-        PageHelper.startPage(page, pageSize);
77
-        List<Map> list = msrStudentService.listStudentForPhb(params);
78
-        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
79
-        return new ResultVo(0, "获取成功", pageResult);
74
+        return new ResultVo(0, "获取成功", msrStudentService.listStudentForPhb(params));
80 75
     }
81 76
 
82 77
     /*

+ 2
- 3
smarking/src/main/java/com/xhkjedu/smarking/mapper/report/reportstu/MsrStudentMapper.java View File

@@ -6,8 +6,7 @@ import com.xhkjedu.smarking.vo.report.reportother.ExamReportParams;
6 6
 import com.xhkjedu.smarking.vo.report.reportstu.StudentParams;
7 7
 import org.apache.ibatis.annotations.Param;
8 8
 
9
-import java.util.List;
10
-import java.util.Map;
9
+import java.util.*;
11 10
 
12 11
 /**
13 12
  * @Description 阅卷报告-学生成绩分析表 Mapper 接口
@@ -27,5 +26,5 @@ public interface MsrStudentMapper extends TkMapper<MsrStudent> {
27 26
     List<Map<String, Object>> listScoreForZgl(@Param("examid") Integer examid,@Param("subjectid") String subjectid);
28 27
 
29 28
     //综合报告-排行榜
30
-    List<Map> listStudentForPhb(@Param("sql") String sql,@Param("params") StudentParams params);
29
+    List<Map> listStudentForPhb(@Param("sql") String sql, @Param("params") StudentParams params);
31 30
 }

+ 79
- 21
smarking/src/main/java/com/xhkjedu/smarking/service/report/report/MsrStudentService.java View File

@@ -2,14 +2,15 @@ package com.xhkjedu.smarking.service.report.report;
2 2
 
3 3
 import com.xhkjedu.smarking.mapper.report.reportstu.MsrStudentMapper;
4 4
 import com.xhkjedu.smarking.mapper.report.reportstu.MsrStudentPointMapper;
5
-import com.xhkjedu.smarking.model.report.reportstu.MsrStudent;
5
+import com.xhkjedu.smarking.utils.MarkingUtil;
6 6
 import com.xhkjedu.smarking.vo.report.reportother.ExamReportParams;
7 7
 import com.xhkjedu.smarking.vo.report.reportstu.StudentParams;
8
+import com.xhkjedu.utils.N_Utils;
8 9
 import org.springframework.stereotype.Service;
9 10
 
10 11
 import javax.annotation.Resource;
11
-import java.util.List;
12
-import java.util.Map;
12
+import java.util.*;
13
+import java.util.stream.Collectors;
13 14
 
14 15
 /**
15 16
  * @Description:学生报告信息
@@ -24,17 +25,17 @@ public class MsrStudentService {
24 25
     private MsrStudentPointMapper msrStudentPointMapper;
25 26
 
26 27
     //综合报告-小分表-列表
27
-    public List<Map<String,Object>> listStuScoreAndRank(Integer examid, String subjectid){
28
-        return msrStudentMapper.listStuScoreAndRankByExamidAndSubjectid(examid,subjectid);
28
+    public List<Map<String, Object>> listStuScoreAndRank(Integer examid, String subjectid) {
29
+        return msrStudentMapper.listStuScoreAndRankByExamidAndSubjectid(examid, subjectid);
29 30
     }
30 31
 
31 32
     //学生报告-学生各学科试题分析
32
-    public List<Map<String,Object>> listStuSubjectQuestions(ExamReportParams params){
33
+    public List<Map<String, Object>> listStuSubjectQuestions(ExamReportParams params) {
33 34
         return msrStudentMapper.listStuSubjectQuestions(params);
34 35
     }
35 36
 
36 37
     //学生报告-学生各学科知识点分析
37
-    public List<Map<String,Object>> listStuPoints(ExamReportParams params){
38
+    public List<Map<String, Object>> listStuPoints(ExamReportParams params) {
38 39
         return msrStudentPointMapper.listStuPoints(params);
39 40
     }
40 41
 
@@ -45,44 +46,101 @@ public class MsrStudentService {
45 46
      * @Param [params]
46 47
      * @Return java.lang.Object
47 48
      **/
48
-    public List<Map> listStudentForPhb(StudentParams params) {
49
+    public Object listStudentForPhb(StudentParams params) {
49 50
         List<String> fields = params.getFields();
50 51
         StringBuilder sql = new StringBuilder();
51
-        sql.append("s.rsid");
52
-        boolean user = false;
52
+        sql.append("s.studentid,s.subjectid,s.classid");
53
+        sql.append(",if(s.subjectid='zf','总分',(select ts.subjectname from t_subject ts where ts.subjectid=s.subjectid)) as subjectname");
54
+        boolean showClass = false;
55
+        List<String> userFields = new ArrayList<>();
56
+        List<String> subjectFields = new ArrayList<>();
53 57
         if (fields.contains("姓名")) {
54 58
             sql.append(",u.username as studentname");
55
-            user = true;
59
+            userFields.add("studentname");
56 60
         }
57 61
         if (fields.contains("考号")) {
58 62
             sql.append(",u.examno");
59
-            user = true;
63
+            userFields.add("examno");
60 64
         }
61 65
         if (fields.contains("学号")) {
62 66
             sql.append(",u.studentno");
63
-            user = true;
67
+            userFields.add("studentno");
64 68
         }
65 69
         if (fields.contains("班级")) {
66 70
             sql.append(",(select c.classname from t_class c where c.classid=s.classid) as classname");
71
+            showClass = true;
67 72
         }
68 73
         if (fields.contains("分数")) {
69 74
             sql.append(",s.stuscore");
70
-        }if (fields.contains("等级")) {
75
+            subjectFields.add("stuscore");
76
+        }
77
+        if (fields.contains("等级")) {
71 78
             sql.append(",s.gradevalue");
72
-        }if (fields.contains("学校排名")) {
79
+            subjectFields.add("gradevalue");
80
+        }
81
+        if (fields.contains("学校排名")) {
73 82
             sql.append(",s.schoolrank");
74
-        }if (fields.contains("班级排名")) {
83
+            subjectFields.add("schoolrank");
84
+        }
85
+        if (fields.contains("班级排名")) {
75 86
             sql.append(",s.classrank");
76
-        }if (fields.contains("标准分")) {
87
+            subjectFields.add("classrank");
88
+        }
89
+        if (fields.contains("标准分")) {
77 90
             sql.append(",s.bzf");
78
-        }if (fields.contains("超均率")) {
91
+            subjectFields.add("bzf");
92
+        }
93
+        if (fields.contains("超均率")) {
79 94
             sql.append(",s.cjl");
95
+            subjectFields.add("cjl");
80 96
         }
81 97
         sql.append(" from msr_student s ");
82
-        if (user) {
98
+        if (N_Utils.isListNotEmpty(userFields)) {
83 99
             sql.append(" inner join t_user u on s.studentid=u.userid ");
100
+            String studentname = params.getStudentname();
101
+            if (N_Utils.isNotEmpty(studentname)) {
102
+                sql.append(" and (u.username like '%").append(studentname).append("%'");
103
+                sql.append(" or u.examno like '%").append(studentname).append("%'");
104
+                sql.append(" or u.studentno like '%").append(studentname).append("%')");
105
+            }
106
+        }
107
+        List<Map> list = msrStudentMapper.listStudentForPhb(sql.toString(), params);
108
+        Map<String, List<Map>> collect = list.stream().collect(Collectors.groupingBy(
109
+                m -> m.get("studentid") + "_" + m.get("classid"), LinkedHashMap::new, Collectors.toList()));
110
+        List<Map<String, Object>> result = new ArrayList<>();
111
+        for (Map.Entry<String, List<Map>> entry : collect.entrySet()) {
112
+            List<Map> values = entry.getValue();
113
+            Map<String, Object> map = new LinkedHashMap<>();
114
+            map.put("studentid", entry.getKey().split("_")[0]);
115
+            for (String field : userFields) {
116
+                map.put(field, values.get(0).get(field));
117
+            }
118
+            if (showClass) {
119
+                map.put("classname", values.get(0).get("classname"));
120
+            }
121
+            List<LinkedHashMap> subjectList = new ArrayList<>();
122
+            for (Map m : values) {
123
+                LinkedHashMap<String, Object> subjectMap = new LinkedHashMap<>();
124
+                subjectMap.put("subjectid", m.get("subjectid"));
125
+                subjectMap.put("subjectname", m.get("subjectname"));
126
+                for (String field : subjectFields) {
127
+                    subjectMap.put(field, m.get(field));
128
+                }
129
+                subjectList.add(subjectMap);
130
+            }
131
+            map.put("subjectList", subjectList);
132
+            result.add(map);
133
+        }
134
+
135
+        String fieldname = params.getFieldname();
136
+        if (N_Utils.isNotEmpty(fieldname)) {
137
+            result = MarkingUtil.sortBySubjectField(result, params.getSubjectid(), fieldname, params.getOd());
138
+        }
139
+        if (N_Utils.isTrueInteger(params.getPage())) {
140
+            return MarkingUtil.getPageResult(params.getPage(), params.getPageSize(), result);
141
+        } else {
142
+            return result;
84 143
         }
85
-        List<Map> list=msrStudentMapper.listStudentForPhb(sql.toString(), params);
86
-        return list;
87 144
     }
145
+
88 146
 }

+ 83
- 17
smarking/src/main/java/com/xhkjedu/smarking/utils/MarkingUtil.java View File

@@ -11,6 +11,7 @@ import com.xhkjedu.smarking.vo.report.reportother.RankGroupVo;
11 11
 import com.xhkjedu.smarking.vo.report.reportother.SzJsonVo;
12 12
 import com.xhkjedu.smarking.vo.report.reportsubject.SectionScoreVo;
13 13
 import com.xhkjedu.utils.N_Utils;
14
+import com.xhkjedu.vo.PageResult;
14 15
 import com.xhkjedu.vo.ResultVo;
15 16
 import lombok.extern.slf4j.Slf4j;
16 17
 
@@ -458,7 +459,7 @@ public class MarkingUtil {
458 459
     }
459 460
 
460 461
     //计算占比,保留4为小数,乘以100后2位小数
461
-    public static double calculateRate(Object v1,Object v2){
462
+    public static double calculateRate(Object v1, Object v2) {
462 463
         BigDecimal b1 = new BigDecimal(v1.toString());
463 464
         BigDecimal b2 = new BigDecimal(v2.toString());
464 465
 
@@ -549,7 +550,7 @@ public class MarkingUtil {
549 550
     }
550 551
 
551 552
     //排名分组计算 参数[总名次,分组数] 如:第一组(第1-10名)
552
-    public static List<RankGroupVo> rankGroup(Integer total,Integer groupNum) {
553
+    public static List<RankGroupVo> rankGroup(Integer total, Integer groupNum) {
553 554
         List<RankGroupVo> rtnList = new ArrayList<>();
554 555
         if (groupNum > total) groupNum = total;
555 556
 
@@ -586,7 +587,7 @@ public class MarkingUtil {
586 587
     }
587 588
 
588 589
     //分数排名
589
-    public static Map<Double,Integer> fspm(List<Double> scores) {
590
+    public static Map<Double, Integer> fspm(List<Double> scores) {
590 591
         //倒序排
591 592
         scores.sort(Collections.reverseOrder());
592 593
         // 创建一个地图来存储分数和出现次数
@@ -603,7 +604,7 @@ public class MarkingUtil {
603 604
     }
604 605
 
605 606
     //人数排名
606
-    public static Map<Integer,Integer> rspm(List<Integer> nums) {
607
+    public static Map<Integer, Integer> rspm(List<Integer> nums) {
607 608
         //倒序排
608 609
         nums.sort(Collections.reverseOrder());
609 610
         // 创建一个地图来存储分数和出现次数
@@ -676,16 +677,16 @@ public class MarkingUtil {
676 677
     }
677 678
 
678 679
     // 分数段 分数分段
679
-    public static List<RankGroupVo> fdScore(Double totalScore,int fdscore){
680
+    public static List<RankGroupVo> fdScore(Double totalScore, int fdscore) {
680 681
         List<RankGroupVo> rtnList = new ArrayList<>();
681 682
         for (int i = 0; i < totalScore; i += fdscore) {
682 683
             int end = (int) Math.min(i + fdscore, totalScore);
683 684
 
684 685
             String groupname = "[" + i + "~" + end;
685
-            if(end == totalScore){
686
-                groupname+="]";
687
-            }else {
688
-                groupname+=")";
686
+            if (end == totalScore) {
687
+                groupname += "]";
688
+            } else {
689
+                groupname += ")";
689 690
             }
690 691
 
691 692
             RankGroupVo rgvo = new RankGroupVo();
@@ -696,11 +697,12 @@ public class MarkingUtil {
696 697
         }
697 698
         return rtnList;
698 699
     }
700
+
699 701
     //分数分段 试题1分1段
700
-    public static List<SectionScoreVo> fdScoreForOne(Double totalScore){
702
+    public static List<SectionScoreVo> fdScoreForOne(Double totalScore) {
701 703
         List<SectionScoreVo> rtnList = new ArrayList<>();
702
-        for (int i = 0; i < totalScore; i ++) {
703
-            double end = Math.min(i+1, totalScore);
704
+        for (int i = 0; i < totalScore; i++) {
705
+            double end = Math.min(i + 1, totalScore);
704 706
             SectionScoreVo rgvo = new SectionScoreVo();
705 707
             rgvo.setSectionname("[" + i + "~" + end + ")");
706 708
             rgvo.setMinvalue(i);
@@ -735,6 +737,7 @@ public class MarkingUtil {
735 737
     }
736 738
 
737 739
     private static int index = 0;
740
+
738 741
     //根据表达式计算
739 742
     public static double evaluate(String expression) {
740 743
         index = 0;
@@ -826,7 +829,7 @@ public class MarkingUtil {
826 829
 
827 830
     //获取报告参数
828 831
     public static List<MsrReportparam> getMsrReportParams(MsrReportparamMapper msrReportparamMapper
829
-            ,Integer examid, String rpbelong, String reportcode) {
832
+            , Integer examid, String rpbelong, String reportcode) {
830 833
         List<MsrReportparam> list = msrReportparamMapper.listReportparamByRpbelong(examid, rpbelong, reportcode);
831 834
         if (N_Utils.isListEmpty(list) && !"all".equals(reportcode)) {
832 835
             list = msrReportparamMapper.listReportparamByRpbelong(examid, rpbelong, "all");
@@ -834,11 +837,74 @@ public class MarkingUtil {
834 837
         return list;
835 838
     }
836 839
 
840
+    // 获取指定字段的值
841
+    public static double getFieldValueAsDouble(Map<String, Object> subject, String field) {
842
+        Object value = subject.get(field);
843
+        if (value instanceof Number) {
844
+            return ((Number) value).doubleValue();
845
+        } else if (value instanceof String && isNumeric((String) value)) {
846
+            return Double.parseDouble((String) value);
847
+        }
848
+        throw new IllegalArgumentException("Unknown or non-numeric field: " + field);
849
+    }
850
+
851
+    // 判断字符串是否为数字
852
+    public static boolean isNumeric(String strNum) {
853
+        if (strNum == null) {
854
+            return false;
855
+        }
856
+        try {
857
+            Double.parseDouble(strNum);
858
+        } catch (NumberFormatException nfe) {
859
+            return false;
860
+        }
861
+        return true;
862
+    }
863
+
864
+    // 根据指定科目字段排序
865
+    public static List<Map<String, Object>> sortBySubjectField(List<Map<String, Object>> students
866
+            , String subjectid, String field, Integer od) {
867
+        if ("classname".equals(field)) {
868
+            if (od.equals(2)) {//降序
869
+                return students.stream().sorted(Comparator.comparing(student -> student.get("classname").toString(), Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList());
870
+            } else {//升序
871
+                return students.stream().sorted(Comparator.comparing(student -> student.get("classname").toString(), Comparator.nullsLast(Comparator.naturalOrder()))).collect(Collectors.toList());
872
+            }
873
+        }
874
+        Comparator<Map<String, Object>> studentComparator = Comparator.comparingDouble((Map<String, Object> student) -> {
875
+            // 获取并转换subjectList为List<Map<String, Object>>
876
+            @SuppressWarnings("unchecked")
877
+            List<Map<String, Object>> subjectList = (List<Map<String, Object>>) student.get("subjectList");
878
+
879
+            // 查找与subjectid匹配的第一个科目,并根据field获取其值
880
+            return subjectList.stream()
881
+                              .filter(subject -> subjectid.equals(subject.get("subjectid")))
882
+                              .mapToDouble(subject -> MarkingUtil.getFieldValueAsDouble(subject, field))
883
+                              .findFirst().orElse(Double.NaN);
884
+        }); // 如果是数值型字段,通常希望降序排列
885
+        if (od.equals(2)) {
886
+            studentComparator = studentComparator.reversed();
887
+        }
888
+
889
+        // 对学生列表进行排序
890
+        return students.stream().sorted(studentComparator).collect(Collectors.toList());
891
+    }
892
+
893
+    //分页
894
+    public static PageResult getPageResult(Integer page, Integer pageSize, List<?> list) {
895
+        int start = (page - 1) * pageSize;
896
+        PageResult pageResult = new PageResult();
897
+        pageResult.setTotal(list.size());
898
+        list = list.stream().skip(start).limit(pageSize).collect(Collectors.toList());
899
+        pageResult.setList(list);
900
+        return pageResult;
901
+    }
902
+
837 903
     public static void main(String[] args) {
838
-       List<RankGroupVo> list = fdScore(1.0,5);
839
-       for (RankGroupVo rgvo : list) {
840
-           System.out.println(rgvo.getGroupname() + ";" + rgvo.getMinvalue() + "-" + rgvo.getMaxvalue());
904
+        List<RankGroupVo> list = fdScore(1.0, 5);
905
+        for (RankGroupVo rgvo : list) {
906
+            System.out.println(rgvo.getGroupname() + ";" + rgvo.getMinvalue() + "-" + rgvo.getMaxvalue());
841 907
 
842
-       }
908
+        }
843 909
     }
844 910
 }

+ 3
- 5
smarking/src/main/java/com/xhkjedu/smarking/vo/report/reportstu/StudentParams.java View File

@@ -14,14 +14,12 @@ import java.util.List;
14 14
 public class StudentParams extends BaseBean {
15 15
 
16 16
     private Integer examid;//考试ID
17
-
18 17
     private String subjectid;//科目ID
19
-
20 18
     private List<String> subjectids;//科目ID
21
-
22 19
     private Integer classid;//班级ID
23
-
24 20
     private List<Integer> classids;//多个班级id
25
-
26 21
     private List<String> fields;//指标字段
22
+    private String studentname;//姓名
23
+    private String fieldname;//排序字段
24
+    private Integer od;//标识排序类型1升序2降序
27 25
 }

+ 0
- 3
smarking/src/main/resources/mapper/report/reportstu/MsrStudentMapper.xml View File

@@ -76,9 +76,6 @@
76 76
     <select id="listStudentForPhb" resultType="java.util.Map">
77 77
         select ${sql}
78 78
         where s.examid=#{params.examid}
79
-        <foreach collection="params.classids" item="classid" open="and s.classid in(" separator="," close=")">
80
-            ${classid}
81
-        </foreach>
82 79
         <foreach collection="params.subjectids" item="subjectid" open="and s.subjectid in(" separator="," close=")">
83 80
             #{subjectid}
84 81
         </foreach>

Loading…
Cancel
Save