lyh
3 天以前 b508ec38ddf9ed93d4435e8f1e3c4effef798aaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package com.lxzn.nc.controller;
 
import com.lxzn.api.nc.DocInfoControllerApi;
import com.lxzn.framework.domain.nc.DocFile;
import com.lxzn.framework.domain.nc.DocInfo;
import com.lxzn.framework.domain.nc.request.DocInfoQueryRequest;
import com.lxzn.framework.domain.nc.request.DocInfoUploadRequest;
import com.lxzn.framework.model.response.CommonCode;
import com.lxzn.framework.model.response.QueryListResponseResult;
import com.lxzn.framework.model.response.QueryPageResponseResult;
import com.lxzn.framework.model.response.ResponseResult;
import com.lxzn.framework.utils.ValidateUtil;
import com.lxzn.framework.utils.file.FileUtil;
import com.lxzn.nc.service.IDocInfoService;
import javafx.scene.shape.VLineTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
 
@RestController
@RequestMapping("/nc/doc")
public class DocInfoController implements DocInfoControllerApi {
    @Autowired
    private IDocInfoService docInfoService;
    @Override
    @PostMapping("/add")
    public ResponseResult addDocInfo(@RequestParam("file") MultipartFile file, DocInfoUploadRequest docInfo) {
        boolean b = docInfoService.addDocInfo(file, docInfo);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @PutMapping("/edit/{id}")
    public ResponseResult editDocInfo(@PathVariable("id") String id, @RequestBody DocInfo docInfo) {
        boolean b = docInfoService.editDocInfo(id, docInfo);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @DeleteMapping("/delete")
    public ResponseResult deleteDocInfo(@RequestParam("id") String id) {
        boolean b = docInfoService.deleteDocInfo(id);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @PostMapping("/push/{id}")
    public ResponseResult pushDocFile(@PathVariable("id") String id, @RequestParam("file") MultipartFile file) {
        boolean b = docInfoService.pushDocFile(id, file);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @GetMapping("/pull/{id}")
    public ResponseResult pullDocFile(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) {
        return docInfoService.pullDocFile(request, response, id);
    }
 
    @Override
    @PutMapping("/cancel/pull/{id}")
    public ResponseResult cancelPullDocInfo(@PathVariable("id") String id) {
        boolean b = docInfoService.cancelPullDocInfo(id);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @PutMapping("/publish/{id}")
    public ResponseResult publishDocInfo(@PathVariable("id") String id) {
        boolean b = docInfoService.publishDocInfo(id);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @PutMapping("/republish/{id}")
    public ResponseResult republishDocInfo(@PathVariable("id") String id) {
        boolean b = docInfoService.republishDocInfo(id);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @PutMapping("/pigeonhole/{id}")
    public ResponseResult pigeonholeDocInfo(@PathVariable("id") String id) {
        boolean b = docInfoService.pigeonholeDocInfo(id);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @GetMapping("/find/page/{page}/{size}")
    public QueryPageResponseResult<DocInfo> findPageList(@PathVariable("page") int page, @PathVariable("size") int size, DocInfoQueryRequest docQuery) {
        return docInfoService.findPageList(page, size, docQuery);
    }
 
    @Override
    @GetMapping("/find/page/device/{page}/{size}")
    public QueryPageResponseResult<DocInfo> findPageListByDevice(@PathVariable("page") int page, @PathVariable("size") int size, DocInfoQueryRequest docQuery) {
        return docInfoService.findPageListByDevice(page, size, docQuery);
    }
 
    @Override
    @GetMapping("/preview/{id}")
    public QueryListResponseResult previewDocFile(@PathVariable("id") String id) {
        DocFile docFile = docInfoService.previewDocFile(id);
        if(!ValidateUtil.validateString(docFile.getFilePath()) || !ValidateUtil.validateString(docFile.getFileName())
//                || !ValidateUtil.validateString(docFile.getFileSuffix())
                || !ValidateUtil.validateString(docFile.getFileEncodeName()))
            return new QueryListResponseResult(CommonCode.FAIL, null);
        String filePath = docFile.getFilePath();
        String fileEncodeName = docFile.getFileEncodeName();
        List<String> list = FileUtil.readFile(fileEncodeName, filePath);
        if(list == null || list.isEmpty())
            return new QueryListResponseResult(CommonCode.FAIL, null);
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
    }
 
    @Override
    @GetMapping("/preview/pdf/{id}")
    public ResponseResult previewPdfDocFile(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) {
        DocFile docFile = docInfoService.previewDocFile(id);
        if(!ValidateUtil.validateString(docFile.getFilePath()) || !ValidateUtil.validateString(docFile.getFileName()) ||
                /*!ValidateUtil.validateString(docFile.getFileSuffix()) ||*/ !ValidateUtil.validateString(docFile.getFileEncodeName()))
            return new ResponseResult(CommonCode.FAIL);
        String fileName;
        if(ValidateUtil.validateString(docFile.getFileSuffix())) {
            fileName = docFile.getFileName() + "." + docFile.getFileSuffix();
        }else {
            fileName = docFile.getFileName();
        }
        String filePath = docFile.getFilePath();
        String fileEncodeName = docFile.getFileEncodeName();
        FileUtil.downLoadFile(response, fileEncodeName, filePath, fileName);
        return null;
    }
 
    @Override
    @GetMapping("/find/list")
    public QueryListResponseResult<DocInfo> findList(DocInfoQueryRequest docQuery) {
        return docInfoService.findList(docQuery);
    }
 
    @Override
    @PostMapping("/batch/remove")
    public ResponseResult batchRemoveDocInfo(@RequestBody String[] docIds) {
        boolean b = docInfoService.batchRemoveDocInfo(docIds);
        if(!b)
            return new ResponseResult(CommonCode.FAIL);
        return new ResponseResult(CommonCode.SUCCESS);
    }
 
    @Override
    @GetMapping("/download/{id}")
    public ResponseResult downloadDocFile(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) {
        return docInfoService.downloadDocFile(request, response, id);
    }
}