Procházet zdrojové kódy

修改分数、导入补录成绩

ywx
王宁 před 1 měsícem
rodič
revize
c1bb61a3a5

+ 12
- 0
smarking/pom.xml Zobrazit soubor

@@ -20,6 +20,18 @@
20 20
             <version>0.0.1-SNAPSHOT</version>
21 21
         </dependency>
22 22
 
23
+        <!--  导入和导出excel时需要的jar包 -->
24
+        <dependency>
25
+            <groupId>org.apache.poi</groupId>
26
+            <artifactId>poi-ooxml</artifactId>
27
+            <version>3.17</version>
28
+        </dependency>
29
+        <dependency>
30
+            <groupId>org.apache.poi</groupId>
31
+            <artifactId>poi</artifactId>
32
+            <version>3.17</version>
33
+        </dependency>
34
+
23 35
     </dependencies>
24 36
     <dependencyManagement>
25 37
         <dependencies>

+ 22
- 4
smarking/src/main/java/com/xhkjedu/smarking/controller/stupaper/MsPaperStudentQuestionScoreController.java Zobrazit soubor

@@ -3,8 +3,8 @@ package com.xhkjedu.smarking.controller.stupaper;
3 3
 import com.github.pagehelper.PageHelper;
4 4
 import com.github.pagehelper.PageInfo;
5 5
 import com.xhkjedu.smarking.model.exam.MsClassStudent;
6
-import com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestionScore;
7 6
 import com.xhkjedu.smarking.service.stupaper.MsPaperStudentQuestionScoreService;
7
+import com.xhkjedu.smarking.vo.stupaper.PaperStuScoreVo;
8 8
 import com.xhkjedu.utils.N_Utils;
9 9
 import com.xhkjedu.utils.PageUtil;
10 10
 import com.xhkjedu.vo.PageResult;
@@ -37,11 +37,29 @@ public class MsPaperStudentQuestionScoreController {
37 37
      * @return com.xhkjedu.vo.ResultVo
38 38
      **/
39 39
     @PostMapping("/save")
40
-    public ResultVo save(@RequestBody MsPaperStudentQuestionScore msPaperStudentQuestionScore) {
41
-        msPaperStudentQuestionScoreService.add(msPaperStudentQuestionScore);
40
+    public ResultVo save(@RequestBody PaperStuScoreVo stuscore) {
41
+        N_Utils.validation(new Object[]{stuscore.getMpsid(), "学生试卷id", 1});
42
+        if(N_Utils.isListEmpty(stuscore.getQuescores())){
43
+            return new ResultVo(1, "试题不能为空");
44
+        }
45
+        msPaperStudentQuestionScoreService.add(stuscore);
42 46
         return new ResultVo(0, "保存成功");
43 47
     }
44 48
 
49
+    /*
50
+     * @Description 修改分数-班级学生成绩
51
+     * @Date 2024/11/13 10:09:35
52
+     * @Author WN
53
+     * @Param [cs]
54
+     * @Return com.xhkjedu.vo.ResultVo
55
+     **/
56
+    @PostMapping("/list_stu")
57
+    public ResultVo listClassStudentScore(@RequestBody MsClassStudent cs) {
58
+        N_Utils.validation(new Object[]{cs.getExamid(), "考试id", 1, cs.getSubjectid(), "科目id", 2,cs.getClass(),"班级id",1});
59
+        List<Map<String, Object>> list = msPaperStudentQuestionScoreService.listClassStudentScores(cs);
60
+        return new ResultVo(0, "获取成功", list);
61
+    }
62
+
45 63
     /*
46 64
      * @Description 修改分数-修改历史
47 65
      * @Date 2024/11/11 17:57:01
@@ -49,7 +67,7 @@ public class MsPaperStudentQuestionScoreController {
49 67
      * @Param [cs]
50 68
      * @Return com.xhkjedu.vo.ResultVo
51 69
      **/
52
-    @PostMapping("/list")
70
+    @PostMapping("/list_history")
53 71
     public ResultVo queryList(@RequestBody MsClassStudent cs) {
54 72
         Integer page = cs.getPage();
55 73
         Integer size = cs.getPageSize();

+ 23
- 0
smarking/src/main/java/com/xhkjedu/smarking/controller/stupaper/MsPaperStudentScoreController.java Zobrazit soubor

@@ -10,10 +10,12 @@ import com.xhkjedu.utils.N_Utils;
10 10
 import com.xhkjedu.utils.PageUtil;
11 11
 import com.xhkjedu.vo.PageResult;
12 12
 import com.xhkjedu.vo.ResultVo;
13
+import lombok.extern.slf4j.Slf4j;
13 14
 import org.springframework.web.bind.annotation.PostMapping;
14 15
 import org.springframework.web.bind.annotation.RequestBody;
15 16
 import org.springframework.web.bind.annotation.RequestMapping;
16 17
 import org.springframework.web.bind.annotation.RestController;
18
+import org.springframework.web.multipart.MultipartFile;
17 19
 
18 20
 import javax.annotation.Resource;
19 21
 import java.util.List;
@@ -24,6 +26,7 @@ import java.util.Map;
24 26
  * @Author: WN
25 27
  * @Date: 2024/11/12 10:57:15
26 28
  **/
29
+@Slf4j
27 30
 @RestController
28 31
 @RequestMapping("/mstuc")
29 32
 public class MsPaperStudentScoreController {
@@ -141,4 +144,24 @@ public class MsPaperStudentScoreController {
141 144
         PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
142 145
         return new ResultVo(0, "获取成功",pageResult);
143 146
     }
147
+
148
+    /*
149
+     * @Description 补录成绩-导入
150
+     * @Date 2024/11/13 16:09:32
151
+     * @Author WN
152
+     * @Param [stuScoreVo, file]
153
+     * @Return com.xhkjedu.vo.ResultVo
154
+     **/
155
+    @PostMapping("/save_import")
156
+    public ResultVo saveBatchForImport(MsPaperStudentScore stuScoreVo, MultipartFile file) {
157
+        N_Utils.validation(new Object[]{stuScoreVo.getExamid(), "考试id", 1});
158
+
159
+        try {
160
+            msPaperStudentScoreService.saveBatch(stuScoreVo, file);
161
+            return new ResultVo(0, "保存成功");
162
+        }catch (Exception e){
163
+            log.error("补录成绩导入失败", e.getMessage());
164
+            return new ResultVo(1, "保存失败");
165
+        }
166
+    }
144 167
 }

+ 4
- 0
smarking/src/main/java/com/xhkjedu/smarking/mapper/stupaper/MsPaperStudentQuestionMapper.java Zobrazit soubor

@@ -4,6 +4,7 @@ import com.xhkjedu.base.TkMapper;
4 4
 import com.xhkjedu.smarking.model.paper.MsPaperQtypeQuestion;
5 5
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudentBlock;
6 6
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestion;
7
+import com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestionScore;
7 8
 import com.xhkjedu.smarking.vo.stupaper.QuestionAnswerVo;
8 9
 import org.apache.ibatis.annotations.Param;
9 10
 
@@ -45,4 +46,7 @@ public interface MsPaperStudentQuestionMapper extends TkMapper<MsPaperStudentQue
45 46
 
46 47
     //更新学生单题批阅信息
47 48
     void checkByMptqidAndStudentId(@Param("list") List<MsPaperStudentQuestion> list,@Param("block") MsPaperStudentBlock block);
49
+
50
+    //修改分数-批量修改分值
51
+    int updateBatchStuscore(@Param("list") List<MsPaperStudentQuestionScore> list);
48 52
 }

+ 6
- 0
smarking/src/main/java/com/xhkjedu/smarking/mapper/stupaper/MsPaperStudentQuestionScoreMapper.java Zobrazit soubor

@@ -2,6 +2,7 @@ package com.xhkjedu.smarking.mapper.stupaper;
2 2
 
3 3
 import com.xhkjedu.base.TkMapper;
4 4
 import com.xhkjedu.smarking.model.exam.MsClassStudent;
5
+import com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestion;
5 6
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestionScore;
6 7
 import org.apache.ibatis.annotations.Param;
7 8
 
@@ -17,4 +18,9 @@ public interface MsPaperStudentQuestionScoreMapper extends TkMapper<MsPaperStude
17 18
 
18 19
     //修改分数-修改记录
19 20
     List<Map<String, Object>> listStuQuestionScore(@Param("stu") MsClassStudent stu);
21
+
22
+    //修改分数-班级学生
23
+    List<Map<String, Object>> listClassStudentScores(@Param("stu") MsClassStudent stu);
24
+    //修改分数-学生试卷
25
+    List<MsPaperStudentQuestion> listStudentQuestions(@Param("mpsid") Integer mpsid);
20 26
 }

+ 10
- 0
smarking/src/main/java/com/xhkjedu/smarking/mapper/stupaper/MsPaperStudentScoreMapper.java Zobrazit soubor

@@ -1,8 +1,11 @@
1 1
 package com.xhkjedu.smarking.mapper.stupaper;
2 2
 
3 3
 import com.xhkjedu.base.TkMapper;
4
+import com.xhkjedu.smarking.model.exam.MsClass;
4 5
 import com.xhkjedu.smarking.model.exam.MsClassStudent;
5 6
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudentScore;
7
+import com.xhkjedu.smarking.vo.exam.ESubjectVo;
8
+import com.xhkjedu.smarking.vo.stupaper.PaperStuScoreVo;
6 9
 import org.apache.ibatis.annotations.Param;
7 10
 
8 11
 import java.util.List;
@@ -28,4 +31,11 @@ public interface MsPaperStudentScoreMapper extends TkMapper<MsPaperStudentScore>
28 31
     List<Map<String,Object>> listStudentsForAdd(@Param("examid")Integer examid,@Param("classid")Integer classid);
29 32
     //补录成绩-新增补录-学生科目分数
30 33
     List<Map<String,Object>> listStudentSubjectScores(@Param("examid")Integer examid,@Param("studentid")Integer studentid);
34
+
35
+    //补录成绩-批量新增-考试科目
36
+    List<ESubjectVo> listSubjectsByExamid(@Param("examid")Integer examid);
37
+    //补录成绩-导入-考试班级
38
+    List<MsClass> listClassesByExamid(@Param("examid")Integer examid);
39
+    //补录成绩-导入-考试学生
40
+    List<PaperStuScoreVo> listStudentScoreByExamid(@Param("examid")Integer examid);
31 41
 }

+ 51
- 10
smarking/src/main/java/com/xhkjedu/smarking/service/stupaper/MsPaperStudentQuestionScoreService.java Zobrazit soubor

@@ -1,15 +1,18 @@
1 1
 package com.xhkjedu.smarking.service.stupaper;
2 2
 
3
+import com.xhkjedu.smarking.mapper.stupaper.MsPaperStudentMapper;
3 4
 import com.xhkjedu.smarking.mapper.stupaper.MsPaperStudentQuestionMapper;
4 5
 import com.xhkjedu.smarking.mapper.stupaper.MsPaperStudentQuestionScoreMapper;
5 6
 import com.xhkjedu.smarking.model.exam.MsClassStudent;
6 7
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestion;
7 8
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestionScore;
9
+import com.xhkjedu.smarking.vo.stupaper.PaperStuScoreVo;
8 10
 import com.xhkjedu.utils.N_Utils;
9 11
 import org.springframework.stereotype.Service;
10 12
 import org.springframework.transaction.annotation.Transactional;
11 13
 
12 14
 import javax.annotation.Resource;
15
+import java.util.ArrayList;
13 16
 import java.util.List;
14 17
 import java.util.Map;
15 18
 
@@ -24,6 +27,8 @@ public class MsPaperStudentQuestionScoreService {
24 27
     private MsPaperStudentQuestionScoreMapper msPaperStudentQuestionScoreMapper;
25 28
     @Resource
26 29
     private MsPaperStudentQuestionMapper msPaperStudentQuestionMapper;
30
+    @Resource
31
+    private MsPaperStudentMapper msPaperStudentMapper;
27 32
 
28 33
     /**
29 34
      * @Description 新增
@@ -33,17 +38,53 @@ public class MsPaperStudentQuestionScoreService {
33 38
      * @return void
34 39
      **/
35 40
     @Transactional(rollbackFor = Exception.class)
36
-    public void add(MsPaperStudentQuestionScore msPaperStudentQuestionScore){
37
-        //获取学生试卷试题信息
38
-        MsPaperStudentQuestion msPaperStudentQuestion = msPaperStudentQuestionMapper.selectByPrimaryKey(msPaperStudentQuestionScore.getMpsqsid());
39
-        msPaperStudentQuestionScore.setExamid(msPaperStudentQuestion.getExamid());
40
-        msPaperStudentQuestionScore.setMpid(msPaperStudentQuestion.getMpid());
41
-        msPaperStudentQuestionScore.setStudentid(msPaperStudentQuestion.getStudentid());
42
-        msPaperStudentQuestionScore.setQn(msPaperStudentQuestion.getQn());
43
-        msPaperStudentQuestionScore.setPrescore(msPaperStudentQuestion.getStuscore());
44
-        msPaperStudentQuestionScore.setCreatetime(N_Utils.getSecondTimestamp());
45
-        msPaperStudentQuestionScoreMapper.insert(msPaperStudentQuestionScore);//保存修改分数记录
41
+    public void add(PaperStuScoreVo paperStuScoreVo){
42
+        //获取试卷中所有试题
43
+        List<MsPaperStudentQuestion> stuQuestions = msPaperStudentQuestionScoreMapper.listStudentQuestions(paperStuScoreVo.getMpsid());
44
+        List<MsPaperStudentQuestionScore> stuscores = paperStuScoreVo.getQuescores();
45
+        List<MsPaperStudentQuestionScore> saveStuscores = new ArrayList<>();
46
+        Integer timestamp = N_Utils.getSecondTimestamp();
47
+        Integer createid = paperStuScoreVo.getCreateid();
48
+
49
+        List<Integer> mpsids = new ArrayList<>();
50
+        Integer mpid = null;
51
+
52
+        for(MsPaperStudentQuestionScore stuscore : stuscores){
53
+            if(stuscore.getStuscore()!=null){
54
+
55
+                stuscore.setCreateid(createid);
56
+                stuscore.setCreatetime(timestamp);
57
+                MsPaperStudentQuestion ques = stuQuestions.stream().filter(q -> q.getMpsqid().equals(stuscore.getMpsqid())).findFirst().orElse(null);
58
+                stuscore.setMpid(ques.getMpid());
59
+                stuscore.setExamid(ques.getExamid());
60
+                stuscore.setSubjectid(ques.getSubjectid());
61
+                stuscore.setStudentid(ques.getStudentid());
62
+                stuscore.setQn(ques.getQn());
63
+                stuscore.setPrescore(ques.getStuscore());
64
+                saveStuscores.add(stuscore);
65
+                mpsids.add(ques.getMpsid());
66
+                mpid = ques.getMpid();
67
+            }
68
+        }
69
+
70
+        if(N_Utils.isListNotEmpty(saveStuscores)){
71
+            msPaperStudentQuestionScoreMapper.insertList(saveStuscores);
72
+            //修改学生试题分数
73
+            msPaperStudentQuestionMapper.updateBatchStuscore(saveStuscores);
74
+            //批量修改学生试卷总分
75
+            msPaperStudentMapper.updateBathStudentPaperScoreByMpsid(mpid, mpsids);
76
+        }
77
+    }
46 78
 
79
+    /*
80
+     * @Description 修改分数-班级学生
81
+     * @Date 2024/11/13 9:58:55
82
+     * @Author WN
83
+     * @Param [student]
84
+     * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
85
+     **/
86
+    public List<Map<String,Object>> listClassStudentScores(MsClassStudent student){
87
+        return msPaperStudentQuestionScoreMapper.listClassStudentScores(student);
47 88
     }
48 89
 
49 90
 

+ 23
- 1
smarking/src/main/java/com/xhkjedu/smarking/service/stupaper/MsPaperStudentScoreService.java Zobrazit soubor

@@ -2,16 +2,21 @@ package com.xhkjedu.smarking.service.stupaper;
2 2
 
3 3
 import com.xhkjedu.smarking.mapper.stupaper.MsPaperStudentMapper;
4 4
 import com.xhkjedu.smarking.mapper.stupaper.MsPaperStudentScoreMapper;
5
+import com.xhkjedu.smarking.model.exam.MsClass;
5 6
 import com.xhkjedu.smarking.model.exam.MsClassStudent;
6 7
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudent;
7 8
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudentScore;
9
+import com.xhkjedu.smarking.utils.ImportUtil;
10
+import com.xhkjedu.smarking.vo.exam.ESubjectVo;
8 11
 import com.xhkjedu.smarking.vo.stupaper.PaperStuScoreVo;
9 12
 import com.xhkjedu.utils.N_Utils;
10 13
 import org.springframework.stereotype.Service;
11 14
 import org.springframework.transaction.annotation.Transactional;
15
+import org.springframework.web.multipart.MultipartFile;
12 16
 
13 17
 import javax.annotation.Resource;
14 18
 import java.util.ArrayList;
19
+import java.util.HashMap;
15 20
 import java.util.List;
16 21
 import java.util.Map;
17 22
 
@@ -143,7 +148,24 @@ public class MsPaperStudentScoreService {
143 148
         return msPaperStudentScoreMapper.listStudentSubjectScores(examid, studentid);
144 149
     }
145 150
 
146
-    public void saveBatch(){
151
+    @Transactional(rollbackFor = Exception.class)
152
+    public void saveBatch(MsPaperStudentScore mpstuScore, MultipartFile file) throws Exception{
147 153
         //表格中学生在考生管理找不到时:统一成:学生不存在或没有参加本次考试
154
+
155
+        //获取考试的所有科目
156
+        List<ESubjectVo> subjects = msPaperStudentScoreMapper.listSubjectsByExamid(mpstuScore.getExamid());
157
+        Map<String,ESubjectVo> subjectMap = subjects.stream().collect(HashMap::new, (m,v)->m.put(v.getSubjectid(),v), HashMap::putAll);
158
+        //考试班级
159
+        List<MsClass> classes = msPaperStudentScoreMapper.listClassesByExamid(mpstuScore.getExamid());
160
+        List<String> classNames = classes.stream().map(MsClass::getClassname).collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
161
+        //获取考试的所有学生
162
+        List<PaperStuScoreVo> allStudents = msPaperStudentScoreMapper.listStudentScoreByExamid(mpstuScore.getExamid());
163
+        Map<String,PaperStuScoreVo> stuMap = allStudents.stream().collect(HashMap::new, (m,v)->m.put(v.getExamno(),v), HashMap::putAll);
164
+
165
+        List<MsPaperStudentScore> saveScore = ImportUtil.readExcelStudentScore(file, subjectMap, stuMap,classNames, mpstuScore.getCreateid());
166
+        if(!saveScore.isEmpty()){
167
+            msPaperStudentScoreMapper.insertList(saveScore);//保存补录历史
168
+            msPaperStudentMapper.updateBatchStuScoreForFillScore(saveScore);//修改学生得分
169
+        }
148 170
     }
149 171
 }

+ 303
- 0
smarking/src/main/java/com/xhkjedu/smarking/utils/ImportUtil.java Zobrazit soubor

@@ -0,0 +1,303 @@
1
+package com.xhkjedu.smarking.utils;
2
+
3
+import com.xhkjedu.smarking.model.stupaper.MsPaperStudentScore;
4
+import com.xhkjedu.smarking.vo.exam.ESubjectVo;
5
+import com.xhkjedu.smarking.vo.stupaper.PaperStuScoreVo;
6
+import com.xhkjedu.utils.N_Utils;
7
+import lombok.extern.slf4j.Slf4j;
8
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
9
+import org.apache.poi.ss.usermodel.*;
10
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
11
+import org.springframework.stereotype.Component;
12
+import org.springframework.web.multipart.MultipartFile;
13
+
14
+import java.io.InputStream;
15
+import java.text.DecimalFormat;
16
+import java.text.SimpleDateFormat;
17
+import java.util.ArrayList;
18
+import java.util.HashMap;
19
+import java.util.List;
20
+import java.util.Map;
21
+
22
+/*
23
+ * @Description:导入
24
+ * @Author: WN
25
+ * @Date: 2024/11/13 11:31:52
26
+ **/
27
+@Component
28
+@Slf4j
29
+public class ImportUtil {
30
+    //2003- 版本的excel
31
+    private final static String excel2003L = ".xls";
32
+    //2007+ 版本的excel
33
+    private final static String excel2007U = ".xlsx";
34
+
35
+
36
+    public static List<MsPaperStudentScore> readExcelStudentScore(MultipartFile file, Map<String,ESubjectVo> subjectMap,Map<String,PaperStuScoreVo> stuMap,List<String> classNames,Integer createid) throws Exception {
37
+        List<MsPaperStudentScore> rtnList = new ArrayList<>();//需要保存的学生分数
38
+        Integer timestamp = N_Utils.getSecondTimestamp();
39
+
40
+        try {
41
+            // 数据校验
42
+            isExcelEmpty(file);
43
+            InputStream in = file.getInputStream();
44
+            String fileName = file.getOriginalFilename();
45
+            Workbook work = getWorkbook(in, fileName);
46
+            //遍历所有sheet
47
+            for (int i = 0; i < work.getNumberOfSheets(); i++) {
48
+                Sheet sheet = work.getSheetAt(i);
49
+                int rows = sheet.getLastRowNum(); // 获取最后一个实际行的下标,比行数小1
50
+                String sheetName = sheet.getSheetName();//根据sheet名称获取科目信息
51
+                //获取科目信息
52
+                if(!subjectMap.containsKey(sheetName)) throw new Exception("科目信息不存在");
53
+
54
+                ESubjectVo subject = subjectMap.get(sheetName);//sheet对应科目信息
55
+
56
+                int firstRowNum = sheet.getFirstRowNum(); // 获取第一个实际行的下标,(firstRowNum=0)
57
+                Row row = sheet.getRow(firstRowNum);//标题行
58
+                String titleName = "姓名性别班级准考证号补录成绩";//标题格式
59
+                StringBuilder sb = new StringBuilder();
60
+                sb.append(row.getCell(0));//姓名
61
+                sb.append(row.getCell(1));//性别
62
+                sb.append(row.getCell(2));//班级
63
+                sb.append(row.getCell(3));//准考证号
64
+                sb.append(row.getCell(4));//补录成绩
65
+                String importTitleName = sb.toString().replaceAll(" |(必填)", "");
66
+                if(!titleName.equals(importTitleName)) throw new Exception("标题格式不正确");
67
+
68
+                Map<String, String> nameMap = new HashMap<>();
69
+
70
+                /*
71
+                 * 遍历当前sheet中的所有行
72
+                 * 排除第一行  第一行为标题头 不纳入遍历
73
+                 */
74
+                for (int x = firstRowNum + 1; x <= rows; x++) {
75
+                    // 获取行
76
+                    row = sheet.getRow(x);
77
+                    if (row == null) {//若此行为空,则跳出循环继续下一行
78
+                        continue;
79
+                    } else if (isEmptyCell(row.getCell(0)) && isEmptyCell(row.getCell(1))) {
80
+                        continue;
81
+                    }
82
+                    PaperStuScoreVo stu = new PaperStuScoreVo();// 每一行一个学生信息
83
+                    int firstCellNum = row.getFirstCellNum();// 每一行的第一列,(firstCellNum=0)
84
+                    if (firstCellNum == 1) throw new Exception("第" + (x + 1) + "行姓名不能为空");
85
+                    int lastCellNum = row.getLastCellNum();// 每一行的最后一列,获取列数,比最后一列列标大1
86
+                    //遍历所有的列
87
+                    for (int y = firstCellNum; y < lastCellNum; y++) {
88
+                        Cell cell = row.getCell(y);
89
+                        if (y == 0) {   // 姓名
90
+                            if (isEmptyCell(cell)) {
91
+                                throw new Exception("第" + (x + 1) + "行姓名不能为空");
92
+                            } else {
93
+                                stu.setStudentname(getCellValue(cell));
94
+                            }
95
+                        } else if (y == 1) {//性别
96
+                            if (isEmptyCell(cell)) {
97
+                                stu.setUsersex(0);
98
+                            } else {
99
+                                String usersex = getCellValue(cell);
100
+                                if (usersex.equals("女")) {
101
+                                    stu.setUsersex(2);
102
+                                } else if (usersex.equals("男")) {
103
+                                    stu.setUsersex(1);
104
+                                } else {
105
+                                    stu.setUsersex(0);
106
+                                }
107
+                            }
108
+                        } else if (y == 2) {//班级
109
+                            if (isEmptyCell(cell)) {
110
+                                throw new Exception("第" + (x + 1) + "行班级不能为空");
111
+                            } else {
112
+                                String classname = getCellValue(cell);
113
+                                if(!classNames.contains(classname)){
114
+                                    throw new Exception("第" + (x + 1) + "行班级不存在");
115
+                                }else{
116
+                                    stu.setClassname(classname);
117
+                                }
118
+                            }
119
+                        } else if (y == 3) {//准考证号
120
+                            if (isEmptyCell(cell)) {
121
+                                throw new Exception("第" + (x + 1) + "行准考证号不能为空");
122
+                            } else {
123
+                                String examno = getCellValue(cell);
124
+                                if(!stuMap.containsKey(examno)) {
125
+                                    throw new Exception("第" + (x + 1) + "行准考证号不存在");
126
+                                }else{
127
+                                    stu.setExamno(examno);
128
+                                }
129
+
130
+                            }
131
+                        } else if (y == 4) {//补录成绩
132
+                            String fillScore = getCellValue(cell);
133
+                            if(N_Utils.isEmpty(fillScore)){
134
+                                stu.setStuscore(null);
135
+                            }else{
136
+                                stu.setStuscore(Double.parseDouble(fillScore));
137
+                            }
138
+                        }
139
+                    }
140
+                    //判断学生信息对应用户是否存在
141
+                    PaperStuScoreVo oldStu = stuMap.get(stu.getExamno());
142
+                    if(stu.getStuscore() !=null && oldStu.getStuscoretype() != 1){
143
+                        //说明设置了分数,则进行用户其他信息教研
144
+                        if(!stu.getStudentname().equals(oldStu.getStudentname()) || !stu.getClassname().equals(oldStu.getClassname())){
145
+                            throw new Exception("第" + (x + 1) + "行学生不存在或没有参加本次考试");
146
+                        }else{
147
+                            MsPaperStudentScore score = setPaperStudentScore(oldStu,subject.getSubjectid(),stu.getStuscore(),createid,timestamp);
148
+                            rtnList.add(score);
149
+                        }
150
+                    }
151
+                }
152
+            }
153
+
154
+        } catch (Exception e) {
155
+            log.error("读取Excel文件失败", e.getMessage());
156
+            throw new Exception("读取Excel文件失败");
157
+        }
158
+        return rtnList;
159
+    }
160
+
161
+    private static MsPaperStudentScore setPaperStudentScore(PaperStuScoreVo oldStu, String subjectid, double stuscore, Integer createid, Integer timestamp) {
162
+        MsPaperStudentScore stuScore = new MsPaperStudentScore();
163
+        stuScore.setExamid(oldStu.getExamid());
164
+        stuScore.setMpid(oldStu.getMpid());
165
+        stuScore.setSubjectid(subjectid);
166
+        stuScore.setStudentid(oldStu.getStudentid());
167
+        stuScore.setFillpre(oldStu.getStuscore());
168
+        stuScore.setFillscore(stuscore);
169
+        stuScore.setCreateid(createid);
170
+        stuScore.setCreatetime(timestamp);
171
+        return stuScore;
172
+    }
173
+
174
+
175
+    /**
176
+     * 根据文件后缀,自适应上传文件的版本
177
+     *
178
+     * @return org.apache.poi.ss.usermodel.Workbook
179
+     * @Param [inStr, fileName]
180
+     * @Author ywx
181
+     * @Date 2020/6/3 16:42
182
+     **/
183
+    public static Workbook getWorkbook(InputStream inStr, String fileName) throws Exception {
184
+        Workbook wb;
185
+        String fileType = fileName.substring(fileName.lastIndexOf("."));
186
+        if (excel2003L.equals(fileType)) {
187
+            wb = new HSSFWorkbook(inStr);  //2003-
188
+        } else if (excel2007U.equals(fileType)) {
189
+            wb = new XSSFWorkbook(inStr);  //2007+
190
+        } else {
191
+            throw new Exception("Excel格式解析有误!");
192
+        }
193
+        return wb;
194
+    }
195
+
196
+    /**
197
+     * 判断单元格是否是空值
198
+     *
199
+     * @return java.lang.Boolean
200
+     * @Param [cell]
201
+     * @Author ywx
202
+     * @Date 2020/6/3 16:37
203
+     **/
204
+    public static Boolean isEmptyCell(Cell cell) {
205
+        if (cell != null) {
206
+            Boolean rtn = true;
207
+            if (N_Utils.isNotEmpty(getCellValue(cell))) {
208
+                rtn = false;
209
+            }
210
+            return rtn;
211
+        } else {
212
+            return true;
213
+        }
214
+    }
215
+
216
+    /**
217
+     * 对表格中数值进行格式化
218
+     *
219
+     * @return java.lang.Object
220
+     * @Param [cell]
221
+     * @Author ywx
222
+     * @Date 2020/6/3 16:41
223
+     **/
224
+    public static String getCellValue(Cell cell) {
225
+        String value = null;
226
+        if (cell == null) return value;
227
+        DecimalFormat df = new DecimalFormat("0");  //格式化number String字符
228
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  //日期格式化
229
+        DecimalFormat df2 = new DecimalFormat("0");  //格式化数字
230
+        switch (cell.getCellTypeEnum()) {
231
+            case STRING:
232
+                value = cell.getRichStringCellValue().getString();
233
+                break;
234
+            case NUMERIC:
235
+                String cellStyle = cell.getCellStyle().getDataFormatString();
236
+                if ("General".equals(cellStyle)) {
237
+                    Double d = cell.getNumericCellValue();
238
+                    if (d.toString().contains("E")) {
239
+                        cell.setCellType(CellType.STRING);
240
+                        value = cell.getStringCellValue();
241
+                    } else {
242
+                        value = df.format(d);
243
+                    }
244
+                } else if ("m/d/yy".equals(cellStyle)) {
245
+                    value = sdf.format(cell.getDateCellValue());
246
+                } else {
247
+                    // 处理数字单元格,可能是整数或双精度浮点数
248
+                    if (cell.getCellStyle().getDataFormat() == 0) {
249
+                        // 假定没有特殊的数字格式,则处理为双精度浮点数
250
+                        value = cell.getNumericCellValue()+"";
251
+                    } else {
252
+                        value = df2.format(cell.getNumericCellValue());
253
+                    }
254
+                }
255
+                break;
256
+            case BOOLEAN:
257
+                boolean rtn = cell.getBooleanCellValue();
258
+                if (rtn) {
259
+                    value = "1";//真
260
+                } else {
261
+                    value = "0";//假
262
+                }
263
+                break;
264
+            case BLANK:
265
+                value = "";
266
+                break;
267
+            case FORMULA://读取excel公式的值
268
+                try {
269
+                    value = String.valueOf(cell.getNumericCellValue());
270
+                } catch (IllegalStateException e) {
271
+                    value = String.valueOf(cell.getRichStringCellValue());
272
+                }
273
+                break;
274
+            default:
275
+                break;
276
+        }
277
+        return N_Utils.strTrim(value);
278
+    }
279
+
280
+    /**
281
+     * 检验Excel内容是否为空
282
+     *
283
+     * @return void
284
+     * @Param [file]
285
+     * @Author ywx
286
+     * @Date 2020/6/3 16:36
287
+     **/
288
+    public static void isExcelEmpty(MultipartFile file) throws Exception {
289
+        if (null == file || file.isEmpty()) {
290
+            throw new Exception("文件不存在!");
291
+        }
292
+        InputStream in = file.getInputStream();
293
+        String fileName = file.getOriginalFilename();
294
+        Workbook work = getWorkbook(in, fileName);
295
+        if (null == work) {
296
+            throw new Exception("Excel内容为空!");
297
+        }
298
+        Integer sheet_size = work.getNumberOfSheets();
299
+        if (sheet_size == 0) {
300
+            throw new Exception("Excel内容为空!");
301
+        }
302
+    }
303
+}

+ 22
- 0
smarking/src/main/java/com/xhkjedu/smarking/vo/stupaper/PaperStuScoreVo.java Zobrazit soubor

@@ -1,5 +1,6 @@
1 1
 package com.xhkjedu.smarking.vo.stupaper;
2 2
 
3
+import com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestionScore;
3 4
 import com.xhkjedu.smarking.model.stupaper.MsPaperStudentScore;
4 5
 import lombok.Data;
5 6
 
@@ -19,5 +20,26 @@ public class PaperStuScoreVo {
19 20
 
20 21
     private Integer createid;// 创建人ID
21 22
 
23
+    private Integer mpsid;//学生试卷ID
24
+
22 25
     private List<MsPaperStudentScore> stuscores;//学生考试成绩列表
26
+
27
+    private List<MsPaperStudentQuestionScore> quescores;//学生试题分
28
+
29
+    private String studentname;
30
+
31
+    private Integer usersex;
32
+
33
+    private Integer classid;
34
+
35
+    private String classname;
36
+
37
+    private String examno;
38
+
39
+    private Double stuscore;
40
+
41
+    private Integer stuscoretype;//学生得分类型0默认1考试得分2补录得分
42
+
43
+    private Integer mpid;
44
+
23 45
 }

+ 2
- 1
smarking/src/main/resources/mapper/paper/MsPaperBlockMapper.xml Zobrazit soubor

@@ -19,6 +19,7 @@
19 19
             <result property="bqorder" column="bqorder"/>
20 20
             <result property="mergeqid" column="mergeqid"/>
21 21
             <result property="mergeqn" column="mergeqn"/>
22
+            <result property="mergescore" column="mergescore"/>
22 23
             <result property="scorestepway" column="scorestepway"/>
23 24
             <result property="scorestep" column="scorestep"/>
24 25
         </collection>
@@ -27,7 +28,7 @@
27 28
     <!--获取题块及题块下试题-->
28 29
     <select id="listPaperBlockQuestions" resultMap="paperBlockResultMap">
29 30
         select b.mblockid,b.mpid,b.blockname,b.blocktype,b.blockorder,b.bqnum,b.bqscore,
30
-        q.mbqid,q.mbqtype,q.mptqid,q.bqn,q.bqscore,q.bqorder,q.mergeqid,q.mergeqn,q.scorestepway,q.scorestep
31
+        q.mbqid,q.mbqtype,q.mptqid,q.bqn,q.bqscore,q.bqorder,q.mergeqid,q.mergeqn,q.mergescore,q.scorestepway,q.scorestep
31 32
         from ms_paper_block b
32 33
         left join ms_paper_block_question q on b.mblockid=q.mblockid
33 34
         left join ms_paper p on b.mpid=p.mpid

+ 7
- 0
smarking/src/main/resources/mapper/stupaper/MsPaperStudentQuestionMapper.xml Zobrazit soubor

@@ -207,4 +207,11 @@
207 207
         left join ms_paper p on q.mpid=p.mpid
208 208
         where ps.mspid=1 and q.mblockid=1 order by q.mptqid
209 209
     </select>
210
+
211
+    <!--修改分数-批量修改分值-->
212
+    <update id="updateBatchStuscore">
213
+        <foreach collection="list" item="q" separator=";">
214
+            update ms_paper_student_question set stuscore=#{q.stuscore} where mpsqid=#{q.mpsqid}
215
+        </foreach>
216
+    </update>
210 217
 </mapper>

+ 19
- 1
smarking/src/main/resources/mapper/stupaper/MsPaperStudentQuestionScoreMapper.xml Zobrazit soubor

@@ -11,7 +11,7 @@
11 11
         left join ms_class_student cs on q.examid=cs.examid and q.subjectid=cs.subjectid and q.studentid=cs.studentid
12 12
         left join ms_class c on q.examid=c.examid and q.subjectid=c.subjectid and cs.classid=c.classid
13 13
         where q.examid=#{stu.examid}
14
-        <if test="stu.subjectid!=null and stu.stu.subjectid!=''">
14
+        <if test="stu.subjectid!=null and stu.subjectid!=''">
15 15
             and q.subjectid=#{stu.subjectid}
16 16
         </if>
17 17
         <if test="stu.classid!=null and stu.classid!=0">
@@ -23,4 +23,22 @@
23 23
         order by q.createtime desc,c.classtype
24 24
     </select>
25 25
 
26
+    <!--修改分数-班级学生-->
27
+    <select id="listClassStudentScores" resultType="java.util.Map">
28
+        select distinct ps.mpsid,ps.studentid,ps.stuscore,c.classname,u.username studentname,u.usersex,u.examno,e.gradeid
29
+        from ms_paper_student ps
30
+        left join ms_class_student cs on ps.examid=cs.examid and ps.subjectid=cs.subjectid
31
+        left join ms_class c on ps.examid=c.examid and ps.subjectid=c.subjectid and cs.classid=c.classid
32
+        left join t_user u on ps.studentid=u.userid
33
+        left join ms_exam e on ps.examid=e.examid
34
+        where ps.examid=#{stu.examid} and ps.subjectid=#{stu.subjectid} and cs.classid=#{stu.classid} order by cs.mcsid
35
+    </select>
36
+
37
+    <!--修改分数-学生试卷-->
38
+    <select id="listStudentQuestions" resultType="com.xhkjedu.smarking.model.stupaper.MsPaperStudentQuestion">
39
+        select mpsqid,studentid,examid,mpid,subjectid,qn,qscore,stuscore from ms_paper_student_question where mpsid=#{mpsid} order by qorder
40
+    </select>
41
+
42
+
43
+
26 44
 </mapper>

+ 19
- 0
smarking/src/main/resources/mapper/stupaper/MsPaperStudentScoreMapper.xml Zobrazit soubor

@@ -73,5 +73,24 @@
73 73
         where ps.examid=#{examid} and ps.studentid=#{studentid} order by s.msid
74 74
     </select>
75 75
 
76
+    <!--补录成绩-导入-考试科目-->
77
+    <select id="listSubjectsByExamid" resultType="com.xhkjedu.smarking.vo.exam.ESubjectVo">
78
+        select subjectid,subjectname from ms_subject where examid=#{examid} order by msid
79
+    </select>
80
+    <!--补录成绩-导入-考试班级-->
81
+    <select id="listClassesByExamid" resultType="com.xhkjedu.smarking.model.exam.MsClass">
82
+        select * from ms_class where examid=#{examid} order by classtype
83
+    </select>
84
+    <!--补录成绩-导入-考试学生-->
85
+    <select id="listStudentScoreByExamid" resultType="com.xhkjedu.smarking.vo.stupaper.PaperStuScoreVo">
86
+        select distinct cs.studentid,cs.subjectid,cs.examid,cs.classid,c.classname,ps.mpsid,ps.mpid,ps.subjectid,
87
+        ps.stuscore,ps.stuscoretype,u.username as studentname,u.usersex,u.examno
88
+        from ms_class_student cs
89
+        left join ms_paper_student ps on ps.examid=cs.examid and ps.subjectid=cs.subjectid and ps.studentid=cs.studentid
90
+        left join ms_class c on ps.examid=c.examid and ps.subjectid=c.subjectid and cs.classid=c.classid
91
+        left join t_user u on ps.studentid=u.userid
92
+        where cs.examid=#{examid} order by cs.mcsid
93
+    </select>
94
+
76 95
 
77 96
 </mapper>

Načítá se…
Zrušit
Uložit