Browse Source

pdf添加自定义文件夹兼容

ywx
王宁 1 month ago
parent
commit
fdb519b0d7

+ 53
- 53
sapi/src/main/java/com/xhkjedu/sapi/controller/scantron/ScantronController.java View File

40
      * @Return com.xhkjedu.vo.ResultVo
40
      * @Return com.xhkjedu.vo.ResultVo
41
      **/
41
      **/
42
     @PostMapping("/list_my")
42
     @PostMapping("/list_my")
43
-    public ResultVo listMy(@RequestBody TScantron scantron){
43
+    public ResultVo listMy(@RequestBody TScantron scantron) {
44
         Integer page = scantron.getPage();
44
         Integer page = scantron.getPage();
45
         Integer pageSize = scantron.getPageSize();
45
         Integer pageSize = scantron.getPageSize();
46
         Integer createid = scantron.getCreateid();
46
         Integer createid = scantron.getCreateid();
47
         Integer schoolid = scantron.getSchoolid();
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
         PageHelper.startPage(page, pageSize);
49
         PageHelper.startPage(page, pageSize);
50
-        List<Map<String,Object>> list = scantronService.listScantrons(scantron);
50
+        List<Map<String, Object>> list = scantronService.listScantrons(scantron);
51
         PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
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
      * @Return com.xhkjedu.vo.ResultVo
60
      * @Return com.xhkjedu.vo.ResultVo
61
      **/
61
      **/
62
     @PostMapping("/list")
62
     @PostMapping("/list")
63
-    public ResultVo list(@RequestBody TScantron scantron){
63
+    public ResultVo list(@RequestBody TScantron scantron) {
64
         Integer page = scantron.getPage();
64
         Integer page = scantron.getPage();
65
         Integer pageSize = scantron.getPageSize();
65
         Integer pageSize = scantron.getPageSize();
66
         Integer createid = scantron.getCreateid();
66
         Integer createid = scantron.getCreateid();
67
         Integer schoolid = scantron.getSchoolid();
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
         UserVo userVo = userService.getUserTypeAndSubjectid(createid);
71
         UserVo userVo = userService.getUserTypeAndSubjectid(createid);
72
-        if(userVo.getUsertype() == 1){
73
-            //设置教师科目
72
+        if (userVo.getUsertype() == 1) {
73
+            // 设置教师科目
74
             scantron.setSubjectid(userVo.getSubjectid());
74
             scantron.setSubjectid(userVo.getSubjectid());
75
         }
75
         }
76
-        if(userVo.getUsertype() == 0){
77
-            //管理员看到学校所有
76
+        if (userVo.getUsertype() == 0) {
77
+            // 管理员看到学校所有
78
             scantron.setCreateid(null);
78
             scantron.setCreateid(null);
79
         }
79
         }
80
-        scantron.setPubliched(1);//全部查看公开的
80
+        scantron.setPubliched(1);// 全部查看公开的
81
 
81
 
82
         PageHelper.startPage(page, pageSize);
82
         PageHelper.startPage(page, pageSize);
83
-        List<Map<String,Object>> list = scantronService.listScantrons(scantron);
83
+        List<Map<String, Object>> list = scantronService.listScantrons(scantron);
84
         PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
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
     @PostMapping("/add")
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
         try {
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
     @PostMapping("/update")
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
         try {
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
     @PostMapping("/delete")
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
         scantronService.delete(scantron.getSid());
118
         scantronService.delete(scantron.getSid());
119
-        return new ResultVo(0,"删除成功");
119
+        return new ResultVo(0, "删除成功");
120
     }
120
     }
121
-    //答题卡-详情
121
+
122
+    // 答题卡-详情
122
     @PostMapping("/detail")
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
         TScantron st = scantronService.detail(scantron.getSid());
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
     @PostMapping("/pub")
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
     @PostMapping("/unpub")
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
     @PostMapping("/copy")
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
         TScantron st = scantronService.copyScantron(scantron);
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 View File

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

Loading…
Cancel
Save