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