Parcourir la source

pdf添加自定义文件夹兼容

ywx
王宁 il y a 1 mois
Parent
révision
fdb519b0d7

+ 53
- 53
sapi/src/main/java/com/xhkjedu/sapi/controller/scantron/ScantronController.java Voir le fichier

@@ -40,16 +40,16 @@ public class ScantronController {
40 40
      * @Return com.xhkjedu.vo.ResultVo
41 41
      **/
42 42
     @PostMapping("/list_my")
43
-    public ResultVo listMy(@RequestBody TScantron scantron){
43
+    public ResultVo listMy(@RequestBody TScantron scantron) {
44 44
         Integer page = scantron.getPage();
45 45
         Integer pageSize = scantron.getPageSize();
46 46
         Integer createid = scantron.getCreateid();
47 47
         Integer schoolid = scantron.getSchoolid();
48
-        N_Utils.validation(new Object[]{page,"显示页码",1,pageSize,"显示条数",1,createid,"用户id",1,schoolid,"学校id",1});
48
+        N_Utils.validation(new Object[]{page, "显示页码", 1, pageSize, "显示条数", 1, createid, "用户id", 1, schoolid, "学校id", 1});
49 49
         PageHelper.startPage(page, pageSize);
50
-        List<Map<String,Object>> list = scantronService.listScantrons(scantron);
50
+        List<Map<String, Object>> list = scantronService.listScantrons(scantron);
51 51
         PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
52
-        return new ResultVo(0,"查询成功",pageResult);
52
+        return new ResultVo(0, "查询成功", pageResult);
53 53
     }
54 54
 
55 55
     /*
@@ -60,96 +60,96 @@ public class ScantronController {
60 60
      * @Return com.xhkjedu.vo.ResultVo
61 61
      **/
62 62
     @PostMapping("/list")
63
-    public ResultVo list(@RequestBody TScantron scantron){
63
+    public ResultVo list(@RequestBody TScantron scantron) {
64 64
         Integer page = scantron.getPage();
65 65
         Integer pageSize = scantron.getPageSize();
66 66
         Integer createid = scantron.getCreateid();
67 67
         Integer schoolid = scantron.getSchoolid();
68
-        N_Utils.validation(new Object[]{page,"显示页码",1,pageSize,"显示条数",1,createid,"教师id",1,schoolid,"学校id",1});
68
+        N_Utils.validation(new Object[]{page, "显示页码", 1, pageSize, "显示条数", 1, createid, "教师id", 1, schoolid, "学校id", 1});
69 69
 
70
-        //获取用户类型
70
+        // 获取用户类型
71 71
         UserVo userVo = userService.getUserTypeAndSubjectid(createid);
72
-        if(userVo.getUsertype() == 1){
73
-            //设置教师科目
72
+        if (userVo.getUsertype() == 1) {
73
+            // 设置教师科目
74 74
             scantron.setSubjectid(userVo.getSubjectid());
75 75
         }
76
-        if(userVo.getUsertype() == 0){
77
-            //管理员看到学校所有
76
+        if (userVo.getUsertype() == 0) {
77
+            // 管理员看到学校所有
78 78
             scantron.setCreateid(null);
79 79
         }
80
-        scantron.setPubliched(1);//全部查看公开的
80
+        scantron.setPubliched(1);// 全部查看公开的
81 81
 
82 82
         PageHelper.startPage(page, pageSize);
83
-        List<Map<String,Object>> list = scantronService.listScantrons(scantron);
83
+        List<Map<String, Object>> list = scantronService.listScantrons(scantron);
84 84
         PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
85
-        return new ResultVo(0,"查询成功",pageResult);
85
+        return new ResultVo(0, "查询成功", pageResult);
86 86
     }
87 87
 
88
-    //答题卡-新增
88
+    // 答题卡-新增
89 89
     @PostMapping("/add")
90
-    public ResultVo add(@RequestBody TScantron scantron){
91
-        N_Utils.validation(new Object[]{scantron.getCreateid(),"创建人id",1,scantron.getSchoolid(),"学校id",1,
92
-                scantron.getSubjectid(),"科目id",1,scantron.getSname(),"答题卡名称",2});
90
+    public ResultVo add(@RequestBody TScantron scantron) {
91
+        N_Utils.validation(new Object[]{scantron.getCreateid(), "创建人id", 1, scantron.getSchoolid(), "学校id", 1,
92
+                scantron.getSubjectid(), "科目id", 1, scantron.getSname(), "答题卡名称", 2});
93 93
         try {
94
-            scantronService.save(scantron);
95
-            return new ResultVo(0,"保存成功");
96
-        }catch (Exception e){
97
-            return new ResultVo(1,"保存失败");
94
+            String pdfpath = scantronService.save(scantron);
95
+            return new ResultVo(0, "保存成功", pdfpath);
96
+        } catch (Exception e) {
97
+            return new ResultVo(1, "保存失败");
98 98
         }
99 99
     }
100 100
 
101
-    //答题卡-修改
101
+    // 答题卡-修改
102 102
     @PostMapping("/update")
103
-    public ResultVo update(@RequestBody TScantron scantron){
104
-        N_Utils.validation(new Object[]{scantron.getSid(),"答题卡id",1});
103
+    public ResultVo update(@RequestBody TScantron scantron) {
104
+        N_Utils.validation(new Object[]{scantron.getSid(), "答题卡id", 1});
105 105
 
106 106
         try {
107
-            scantronService.update(scantron);
108
-            return new ResultVo(0,"保存成功");
109
-        }catch (Exception e){
110
-            return new ResultVo(1,"保存失败");
107
+            String pdfpath = scantronService.update(scantron);
108
+            return new ResultVo(0, "保存成功", pdfpath);
109
+        } catch (Exception e) {
110
+            return new ResultVo(1, "保存失败");
111 111
         }
112 112
     }
113 113
 
114
-    //答题卡-删除
114
+    // 答题卡-删除
115 115
     @PostMapping("/delete")
116
-    public ResultVo delete(@RequestBody TScantron scantron){
117
-        N_Utils.validation(new Object[]{scantron.getSid(),"答题卡id",1});
116
+    public ResultVo delete(@RequestBody TScantron scantron) {
117
+        N_Utils.validation(new Object[]{scantron.getSid(), "答题卡id", 1});
118 118
         scantronService.delete(scantron.getSid());
119
-        return new ResultVo(0,"删除成功");
119
+        return new ResultVo(0, "删除成功");
120 120
     }
121
-    //答题卡-详情
121
+
122
+    // 答题卡-详情
122 123
     @PostMapping("/detail")
123
-    public ResultVo detail(@RequestBody TScantron scantron){
124
-        N_Utils.validation(new Object[]{scantron.getSid(),"答题卡id",1});
124
+    public ResultVo detail(@RequestBody TScantron scantron) {
125
+        N_Utils.validation(new Object[]{scantron.getSid(), "答题卡id", 1});
125 126
         TScantron st = scantronService.detail(scantron.getSid());
126
-        return new ResultVo(0,"获取成功",st);
127
+        return new ResultVo(0, "获取成功", st);
127 128
     }
128 129
 
129
-    //答题卡-公开
130
+    // 答题卡-公开
130 131
     @PostMapping("/pub")
131
-    public ResultVo updatePubliched(@RequestBody TScantron scantron){
132
-        N_Utils.validation(new Object[]{scantron.getSid(),"答题卡id",1});
133
-        scantronService.updateScantronPubliched(scantron.getSid(),1);
134
-        return new ResultVo(0,"设置成功");
132
+    public ResultVo updatePubliched(@RequestBody TScantron scantron) {
133
+        N_Utils.validation(new Object[]{scantron.getSid(), "答题卡id", 1});
134
+        scantronService.updateScantronPubliched(scantron.getSid(), 1);
135
+        return new ResultVo(0, "设置成功");
135 136
     }
136
-    //答题卡-取消公开
137
+
138
+    // 答题卡-取消公开
137 139
     @PostMapping("/unpub")
138
-    public ResultVo updateUnPubliched(@RequestBody TScantron scantron){
139
-        N_Utils.validation(new Object[]{scantron.getSid(),"答题卡id",1});
140
-        scantronService.updateScantronPubliched(scantron.getSid(),2);
141
-        return new ResultVo(0,"设置成功");
140
+    public ResultVo updateUnPubliched(@RequestBody TScantron scantron) {
141
+        N_Utils.validation(new Object[]{scantron.getSid(), "答题卡id", 1});
142
+        scantronService.updateScantronPubliched(scantron.getSid(), 2);
143
+        return new ResultVo(0, "设置成功");
142 144
     }
143 145
 
144
-    //答题卡-复用
146
+    // 答题卡-复用
145 147
     @PostMapping("/copy")
146
-    public ResultVo copyScantron(@RequestBody TScantron scantron){
147
-        N_Utils.validation(new Object[]{scantron.getSid(),"答题卡id",1,scantron.getCreateid(),"创建人id",1});
148
+    public ResultVo copyScantron(@RequestBody TScantron scantron) {
149
+        N_Utils.validation(new Object[]{scantron.getSid(), "答题卡id", 1, scantron.getCreateid(), "创建人id", 1});
148 150
         TScantron st = scantronService.copyScantron(scantron);
149
-        return new ResultVo(0,"复用成功",st);
151
+        return new ResultVo(0, "复用成功", st);
150 152
     }
151 153
 
152 154
 
153
-
154
-
155 155
 }

+ 14
- 6
sapi/src/main/java/com/xhkjedu/sapi/service/scantron/ScantronService.java Voir le fichier

@@ -37,7 +37,7 @@ public class ScantronService {
37 37
 
38 38
     //答题卡-保存
39 39
     @Transactional(rollbackFor = Exception.class)
40
-    public void save(TScantron tScantron) throws Exception{
40
+    public String save(TScantron tScantron) throws Exception{
41 41
         tScantron.setCreatetime(N_Utils.getSecondTimestamp());
42 42
         if(tScantron.getSlayout() > 1){
43 43
             tScantron.setPapertype(1);
@@ -49,19 +49,20 @@ public class ScantronService {
49 49
         scantronMapper.insertUseGeneratedKeys(tScantron);
50 50
 
51 51
         Integer sid = tScantron.getId();
52
-        String pdfpath = saveScantronPdf(base64Path,sid,tScantron.getSlayout(),tScantron.getSchoolid());
52
+        String pdfpath = saveScantronPdf(base64Path,tScantron.getSname(),sid,tScantron.getSlayout(),tScantron.getSchoolid());
53 53
         if(N_Utils.isNotEmpty(pdfpath)){
54 54
             scantronMapper.updatePdfpath(sid,pdfpath);//更改转为路径的pdf地址
55 55
         }
56
+        return pdfpath;
56 57
     }
57 58
 
58 59
     //答题卡-保存pdf
59
-    private String saveScantronPdf(String pdfpath,Integer sid,Integer column,Integer schoolid) throws Exception {
60
+    private String saveScantronPdf(String pdfpath,String sname,Integer sid,Integer column,Integer schoolid) throws Exception {
60 61
         String cloudcode = scantronMapper.getSchoolCloud();
61 62
 
62 63
         String pdfbase64 = URLEncoder.encode(pdfpath,"UTF-8");
63 64
         String savefolder = cloudcode + "/" + schoolid + "/scantron/";
64
-        String params = "base64path=" + pdfbase64 + "&savefolder=" + savefolder + "&column=" + column + "&filename=" + sid;
65
+        String params = "base64path=" + pdfbase64 + "&savefolder=" + savefolder + "&column=" + column + "&filename=" + sname + "&customefolder=" + sid;
65 66
         String fileInfoStr = N_Utils.sendPost(ConfigKey.fileapi + "bs/topdf", params);
66 67
         if(N_Utils.isEmpty(fileInfoStr)){
67 68
             return "";
@@ -75,7 +76,7 @@ public class ScantronService {
75 76
     }
76 77
 
77 78
     //答题卡-修改
78
-    public void update(TScantron tScantron) throws Exception{
79
+    public String update(TScantron tScantron) throws Exception{
79 80
         if(N_Utils.isTrueInteger(tScantron.getSlayout()) && tScantron.getSlayout() > 1){
80 81
             tScantron.setPapertype(1);
81 82
         }else{
@@ -83,13 +84,20 @@ public class ScantronService {
83 84
         }
84 85
 
85 86
         TScantron oldScantron = scantronMapper.selectByPrimaryKey(tScantron.getSid());
87
+        String rtnPdfpath = oldScantron.getPdfpath();
86 88
         if(N_Utils.isEmpty(oldScantron.getPdfpath()) || !oldScantron.getPdfpath().equals(tScantron.getPdfpath())){
87 89
             String base64Path = tScantron.getPdfpath();
88
-            String pdfpath = saveScantronPdf(base64Path,tScantron.getSid(),tScantron.getSlayout(),oldScantron.getSchoolid());
90
+            String sname = tScantron.getSname();
91
+            if(N_Utils.isEmpty(sname)){
92
+                sname = oldScantron.getSname();
93
+            }
94
+            String pdfpath = saveScantronPdf(base64Path,sname,tScantron.getSid(),tScantron.getSlayout(),oldScantron.getSchoolid());
89 95
             tScantron.setPdfpath(pdfpath);
96
+            rtnPdfpath = pdfpath;
90 97
         }
91 98
 
92 99
         scantronMapper.updateByPrimaryKeySelective(tScantron);
100
+        return rtnPdfpath;
93 101
     }
94 102
 
95 103
     //答题卡-删除

Chargement…
Annuler
Enregistrer