Quellcode durchsuchen

完善答题卡,base64调文件服务参数问题

ywx
王宁 vor 1 Monat
Ursprung
Commit
44be1d576a

+ 13
- 4
sapi/src/main/java/com/xhkjedu/sapi/controller/scantron/ScantronController.java Datei anzeigen

@@ -90,16 +90,25 @@ public class ScantronController {
90 90
     public ResultVo add(@RequestBody TScantron scantron){
91 91
         N_Utils.validation(new Object[]{scantron.getCreateid(),"创建人id",1,scantron.getSchoolid(),"学校id",1,
92 92
                 scantron.getSubjectid(),"科目id",1,scantron.getSname(),"答题卡名称",2});
93
-        scantronService.save(scantron);
94
-        return new ResultVo(0,"保存成功");
93
+        try {
94
+            scantronService.save(scantron);
95
+            return new ResultVo(0,"保存成功");
96
+        }catch (Exception e){
97
+            return new ResultVo(1,"保存失败");
98
+        }
95 99
     }
96 100
 
97 101
     //答题卡-修改
98 102
     @PostMapping("/update")
99 103
     public ResultVo update(@RequestBody TScantron scantron){
100 104
         N_Utils.validation(new Object[]{scantron.getSid(),"答题卡id",1});
101
-        scantronService.update(scantron);
102
-        return new ResultVo(0,"保存成功");
105
+
106
+        try {
107
+            scantronService.update(scantron);
108
+            return new ResultVo(0,"保存成功");
109
+        }catch (Exception e){
110
+            return new ResultVo(1,"保存失败");
111
+        }
103 112
     }
104 113
 
105 114
     //答题卡-删除

+ 1
- 2
sapi/src/main/java/com/xhkjedu/sapi/mapper/scantron/ScantronMapper.java Datei anzeigen

@@ -2,7 +2,6 @@ package com.xhkjedu.sapi.mapper.scantron;
2 2
 
3 3
 import com.xhkjedu.base.TkMapper;
4 4
 import com.xhkjedu.sapi.model.scantron.TScantron;
5
-import com.xhkjedu.sapi.model.system.TSchool;
6 5
 import org.apache.ibatis.annotations.Param;
7 6
 
8 7
 import java.util.List;
@@ -22,7 +21,7 @@ public interface ScantronMapper extends TkMapper<TScantron> {
22 21
     int updateScantronPubliched(@Param("sid")int sid, @Param("publiched")int publiched);
23 22
 
24 23
     //获取答题卡所在学校区域信息
25
-    TSchool getSchoolCloudByScanid(@Param("sid")int sid);
24
+    String getSchoolCloud();
26 25
 
27 26
     //更改pdf地址
28 27
     Integer updatePdfpath(@Param("sid")int sid, @Param("pdfpath")String pdfpath);

+ 22
- 15
sapi/src/main/java/com/xhkjedu/sapi/service/scantron/ScantronService.java Datei anzeigen

@@ -1,16 +1,16 @@
1 1
 package com.xhkjedu.sapi.service.scantron;
2 2
 
3 3
 import com.alibaba.fastjson.JSON;
4
-import com.alibaba.fastjson.JSONArray;
5 4
 import com.xhkjedu.sapi.config.ConfigKey;
6 5
 import com.xhkjedu.sapi.mapper.scantron.ScantronMapper;
7 6
 import com.xhkjedu.sapi.model.scantron.TScantron;
8
-import com.xhkjedu.sapi.model.system.TSchool;
9 7
 import com.xhkjedu.utils.N_Utils;
10 8
 import com.xhkjedu.vo.ResultVo;
11 9
 import org.springframework.stereotype.Service;
10
+import org.springframework.transaction.annotation.Transactional;
12 11
 
13 12
 import javax.annotation.Resource;
13
+import java.net.URLEncoder;
14 14
 import java.util.List;
15 15
 import java.util.Map;
16 16
 
@@ -36,7 +36,8 @@ public class ScantronService {
36 36
     }
37 37
 
38 38
     //答题卡-保存
39
-    public void save(TScantron tScantron){
39
+    @Transactional(rollbackFor = Exception.class)
40
+    public void save(TScantron tScantron) throws Exception{
40 41
         tScantron.setCreatetime(N_Utils.getSecondTimestamp());
41 42
         if(tScantron.getSlayout() > 1){
42 43
             tScantron.setPapertype(1);
@@ -45,20 +46,26 @@ public class ScantronService {
45 46
         }
46 47
         String base64Path = tScantron.getPdfpath();
47 48
         tScantron.setPdfpath(null);
48
-        scantronMapper.insertSelective(tScantron);
49
+        scantronMapper.insertUseGeneratedKeys(tScantron);
49 50
 
50 51
         Integer sid = tScantron.getId();
51
-        String pdfpath = saveScantronPdf(base64Path,sid,tScantron.getSlayout());
52
-        scantronMapper.updatePdfpath(sid,pdfpath);//更改转为路径的pdf地址
52
+        String pdfpath = saveScantronPdf(base64Path,sid,tScantron.getSlayout(),tScantron.getSchoolid());
53
+        if(N_Utils.isNotEmpty(pdfpath)){
54
+            scantronMapper.updatePdfpath(sid,pdfpath);//更改转为路径的pdf地址
55
+        }
53 56
     }
54 57
 
55 58
     //答题卡-保存pdf
56
-    private String saveScantronPdf(String pdfpath,Integer sid,Integer column){
57
-        TSchool school = scantronMapper.getSchoolCloudByScanid(sid);
58
-        List<String> imgList = JSONArray.parseArray(pdfpath, String.class);
59
-        String savefloder = school.getCloudcode() + "/" + school.getSchoolid() + "/scantron/";
60
-        String params = "filepaths=" + imgList + "&savefloder=" + savefloder + "&column=" + column + "&filename=" + sid;
61
-        String fileInfoStr = N_Utils.sendPost(ConfigKey.fileapi + "ba/topdf", params);
59
+    private String saveScantronPdf(String pdfpath,Integer sid,Integer column,Integer schoolid) throws Exception {
60
+        String cloudcode = scantronMapper.getSchoolCloud();
61
+
62
+        String pdfbase64 = URLEncoder.encode(pdfpath,"UTF-8");
63
+        String savefolder = cloudcode + "/" + schoolid + "/scantron/";
64
+        String params = "base64path=" + pdfbase64 + "&savefolder=" + savefolder + "&column=" + column + "&filename=" + sid;
65
+        String fileInfoStr = N_Utils.sendPost(ConfigKey.fileapi + "bs/topdf", params);
66
+        if(N_Utils.isEmpty(fileInfoStr)){
67
+            return "";
68
+        }
62 69
         ResultVo fileResult = JSON.parseObject(fileInfoStr, ResultVo.class);
63 70
         if (fileResult.getCode() == 0 && N_Utils.isNotEmpty(fileResult.getObj())) {
64 71
             return fileResult.getObj().toString();
@@ -68,7 +75,7 @@ public class ScantronService {
68 75
     }
69 76
 
70 77
     //答题卡-修改
71
-    public void update(TScantron tScantron){
78
+    public void update(TScantron tScantron) throws Exception{
72 79
         if(N_Utils.isTrueInteger(tScantron.getSlayout()) && tScantron.getSlayout() > 1){
73 80
             tScantron.setPapertype(1);
74 81
         }else{
@@ -76,9 +83,9 @@ public class ScantronService {
76 83
         }
77 84
 
78 85
         TScantron oldScantron = scantronMapper.selectByPrimaryKey(tScantron.getSid());
79
-        if(!oldScantron.getPdfpath().equals(tScantron.getPdfpath())){
86
+        if(N_Utils.isEmpty(oldScantron.getPdfpath()) || !oldScantron.getPdfpath().equals(tScantron.getPdfpath())){
80 87
             String base64Path = tScantron.getPdfpath();
81
-            String pdfpath = saveScantronPdf(base64Path,tScantron.getSid(),tScantron.getSlayout());
88
+            String pdfpath = saveScantronPdf(base64Path,tScantron.getSid(),tScantron.getSlayout(),oldScantron.getSchoolid());
82 89
             tScantron.setPdfpath(pdfpath);
83 90
         }
84 91
 

+ 2
- 3
sapi/src/main/resources/mapper/scantron/ScantronMapper.xml Datei anzeigen

@@ -29,9 +29,8 @@
29 29
     </update>
30 30
 
31 31
     <!--获取答题卡所在学校区域信息-->
32
-    <select id="getSchoolCloudByScanid" resultType="com.xhkjedu.sapi.model.system.TSchool">
33
-        select schoolid,(select cloudcode from t_cloud order by cloudid limit 1) cloudcode
34
-        from t_scantron where sid=#{sid}
32
+    <select id="getSchoolCloud" resultType="java.lang.String">
33
+        select cloudcode from t_cloud order by cloudid limit 1
35 34
     </select>
36 35
 
37 36
     <!--更改pdf地址-->

+ 10
- 4
smarking/src/main/java/com/xhkjedu/smarking/service/scan/MsScanbatchPaperService.java Datei anzeigen

@@ -290,6 +290,9 @@ public class MsScanbatchPaperService {
290 290
                         assert blockQuestion != null;
291 291
                         return q.getMptqid().equals(blockQuestion.getMptqid());
292 292
                     }).findFirst().orElse(null);
293
+                    if(queAnswer == null){
294
+                        throw new RuntimeException("学生试题信息有误");
295
+                    }
293 296
 
294 297
                     String identifycont = spbquestion.getIdentifycont();
295 298
 
@@ -444,8 +447,7 @@ public class MsScanbatchPaperService {
444 447
             if(hasstu){
445 448
                 //获取答案
446 449
                 MsPaperStudentQuestion stuQuestion = stuQuestions.stream().filter(q -> q.getMptqid().equals(spbquestion.getMptqid())).findFirst().orElse(null);
447
-                String stuanswer = stuQuestion.getStuanswer();
448
-                if(N_Utils.isNotEmpty(qidentify) && N_Utils.isNotEmpty(stuanswer) && !qidentify.equals(stuanswer)){
450
+                if(stuQuestion!=null &&N_Utils.isNotEmpty(qidentify) && N_Utils.isNotEmpty(stuQuestion.getStuanswer()) && !qidentify.equals(stuQuestion.getStuanswer())){
449 451
                     //如果识别结果和学生答案都不为空且不相等,则更改学生答案
450 452
                     stuQuestion.setStuanswer(qidentify);
451 453
                     checkObjectiveQuestion(stuQuestion);
@@ -477,8 +479,12 @@ public class MsScanbatchPaperService {
477 479
 
478 480
         List<MsScanbatch> batchList = msScanbatchPaperMapper.getScanErrorNum(mpid);
479 481
         MsScanbatch msScanbatch = batchList.stream().filter(b -> b.getBatchid().equals(batchid)).findFirst().orElse(null);
480
-        map.put("batchnum",msScanbatch.getScannum());
481
-        int totalnum = batchList.stream().mapToInt(b -> b.getScannum()).sum();
482
+        Integer batchnum = 0;
483
+        if(msScanbatch!= null){
484
+            batchnum = msScanbatch.getScannum();
485
+        }
486
+        map.put("batchnum",batchnum);
487
+        int totalnum = batchList.stream().mapToInt(MsScanbatch::getScannum).sum();
482 488
         map.put("totalnum",totalnum);
483 489
         return map;
484 490
     }

+ 0
- 3
smarking/src/main/java/com/xhkjedu/smarking/service/scan/MsScanbatchService.java Datei anzeigen

@@ -1,7 +1,6 @@
1 1
 package com.xhkjedu.smarking.service.scan;
2 2
 
3 3
 import com.xhkjedu.smarking.mapper.exam.MsClassMapper;
4
-import com.xhkjedu.smarking.mapper.paper.MsPaperMapper;
5 4
 import com.xhkjedu.smarking.mapper.scan.MsScanbatchMapper;
6 5
 import com.xhkjedu.smarking.mapper.scan.MsScanbatchPaperMapper;
7 6
 import com.xhkjedu.smarking.model.exam.MsExam;
@@ -27,8 +26,6 @@ public class MsScanbatchService {
27 26
     @Resource
28 27
     private MsScanbatchMapper msScanbatchMapper;
29 28
     @Resource
30
-    private MsPaperMapper msPaperMapper;
31
-    @Resource
32 29
     private MsScanbatchPaperMapper msScanbatchPaperMapper;
33 30
     @Resource
34 31
     private MsClassMapper msClassMapper;

+ 14
- 6
smarking/src/main/java/com/xhkjedu/smarking/utils/MarkingUtil.java Datei anzeigen

@@ -7,8 +7,10 @@ import com.xhkjedu.utils.N_Utils;
7 7
 import com.xhkjedu.vo.ResultVo;
8 8
 import lombok.extern.slf4j.Slf4j;
9 9
 
10
+import java.io.UnsupportedEncodingException;
10 11
 import java.math.BigDecimal;
11 12
 import java.math.BigInteger;
13
+import java.net.URLEncoder;
12 14
 import java.text.SimpleDateFormat;
13 15
 import java.time.LocalDateTime;
14 16
 import java.time.ZoneId;
@@ -277,22 +279,28 @@ public class MarkingUtil {
277 279
      * @Param [stupic, merged, saveFloder]
278 280
      * @Return java.lang.String
279 281
      **/
280
-    public static String uploadBase64Img(String stupic,Integer merged,String saveFloder){
282
+    public static String uploadBase64Img(String stupic,Integer merged,String saveFloder) {
281 283
         String apiMethod;
282
-        String params;
283 284
         if(merged == 1){
284 285
             //说明上传的图片为单张保存
285
-            params = "base64path=" + stupic;
286 286
             apiMethod = "bs/base";
287 287
         }else{
288 288
             //上传的多张图片需要合并为一张
289
-            List<String> imgList = JSONArray.parseArray(stupic, String.class);
290
-            params = "filepaths=" + imgList;
291 289
             apiMethod = "bs/mbase_merge";
292 290
         }
291
+        String stubase64;//防止内容被更改
292
+        try {
293
+            stubase64 = URLEncoder.encode(stupic, "UTF-8");
294
+        } catch (UnsupportedEncodingException e) {
295
+            log.error("base64格式化内容出错" + e.getMessage());
296
+            throw new RuntimeException(e);
297
+        }
293 298
         //处理字段那种图片路径,base64转图片
294
-        params = params + "&savefolder=" + saveFloder;
299
+        String params = "base64path=" + stubase64 + "&savefolder=" + saveFloder;
295 300
         String fileInfoStr = N_Utils.sendPost(ConfigKey.fileapi + apiMethod, params);
301
+        if(N_Utils.isEmpty(fileInfoStr)){
302
+            return "";
303
+        }
296 304
         ResultVo fileResult = JSON.parseObject(fileInfoStr, ResultVo.class);
297 305
         if (fileResult.getCode() == 0 && N_Utils.isNotEmpty(fileResult.getObj())) {
298 306
             return fileResult.getObj().toString();

Laden…
Abbrechen
Speichern