ny
23 小时以前 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package jnpf.controller;
 
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import jnpf.base.ActionResult;
import jnpf.base.vo.PaginationVO;
import jnpf.constant.MsgCode;
import jnpf.emnus.FilePreviewTypeEnum;
import jnpf.file.YozoApi;
import jnpf.model.SuffixParams;
import jnpf.model.YozoFileParams;
import jnpf.model.YozoParams;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
 
/**
 * 文档在线编辑
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2021/5/7
 */
@Tag(name = "文档在线预览编辑", description = "DocumentEdit")
//@RestController
//@RequestMapping("/DocumentEdit")
public class DocumentEditController {
 
    @Autowired
    private YozoApi yozoApi;
 
    /**
     * 上传本地文件
     *
     * @param file 文件
     * @return
     * @throws IOException
     */
    @PostMapping(value = "/uploadLocalFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "上传本地文件")
    public ActionResult yozoUploadLocalFile(MultipartFile file) throws IOException {
        return yozoApi.upload(file);
    }
 
    /**
     * 新建文件
     *
     * @param fileName     名称
     * @param templateType 类型
     * @return
     */
    @GetMapping("/create")
    @Operation(summary = "新建文件")
    @Parameters({
            @Parameter(name = "fileName", description = "名称"),
            @Parameter(name = "templateType", description = "类型"),
    })
    public ActionResult newCreate(@RequestParam("fileName") String fileName, @RequestParam("templateType") String templateType) {
        return yozoApi.newCreate(fileName, templateType);
    }
 
    /**
     * 删除文件版本
     *
     * @param fileVersionId 主键
     * @return
     */
    @GetMapping("/deleteVersion")
    @Operation(summary = "删除文件版本")
    @Parameters({
            @Parameter(name = "fileVersionId", description = "主键"),
    })
    public ActionResult deleteVersion(@RequestParam("fileVersionId") String fileVersionId) {
        return yozoApi.deleteVersion(fileVersionId);
    }
 
    /**
     * 批量删除文件版本
     *
     * @param fileVersionIds 批量主键
     * @return
     */
    @GetMapping("/batchDelete")
    @Operation(summary = "批量删除文件版本")
    @Parameters({
            @Parameter(name = "fileVersionIds", description = "批量主键"),
    })
    public ActionResult batchDelete(@RequestParam("fileVersionIds") String[] fileVersionIds) {
        return yozoApi.batchDelete(fileVersionIds);
    }
 
    /**
     * 在线编辑
     *
     * @param fileVersionId 主键
     * @return
     */
    @GetMapping("/onlineEditFile")
    @Operation(summary = "在线编辑")
    @Parameters({
            @Parameter(name = "fileVersionId", description = "主键"),
    })
    public ActionResult onlineEditFile(@RequestParam("fileVersionId") String fileVersionId) {
        return yozoApi.editFile(fileVersionId);
    }
 
    /**
     * 文档列表
     *
     * @param pageModel 分页模型
     * @return
     */
    @PostMapping("/documentList")
    @Operation(summary = "文档列表")
    public ActionResult documentList(PaginationVO pageModel) {
        return yozoApi.documentList(pageModel);
    }
 
    /**
     * 本地同步编辑过后的文件
     *
     * @param fileVersionId 主键
     * @return
     */
    @GetMapping("/updateFile")
    @Operation(summary = "本地同步编辑过后的文件")
    @Parameters({
            @Parameter(name = "fileVersionId", description = "主键"),
    })
    public ActionResult updateFile(@RequestParam("fileVersionId") String fileVersionId) {
        return yozoApi.updateFile(fileVersionId);
    }
 
    /**
     * 本地预览
     *
     * @param filename    名称
     * @param params      预览模型
     * @param previewType 类型
     * @return
     */
    @GetMapping("/storageFilePreview")
    @Operation(summary = "本地预览")
    @Parameters({
            @Parameter(name = "filename", description = "名称"),
            @Parameter(name = "previewType", description = "类型"),
    })
    public Object OnlinePreview(@RequestParam("filename") String filename, SuffixParams params, @RequestParam("previewType") String previewType) throws UnsupportedEncodingException {
        String url;
        String fileName = filename.substring(0, filename.lastIndexOf("."));
        String suffix = filename.substring(filename.lastIndexOf(".") + 1);
        if (previewType.equals(FilePreviewTypeEnum.YOZO_ONLINE_PREVIEW.getType())) {
            url = YozoParams.JNPF_DOMAINS + "/api/extend/DocumentPreview/down/" + fileName + "/" + suffix;
        } else {
            url = YozoParams.JNPF_DOMAINS + "/api/extend/DocumentPreview/pointDown/" + fileName + "." + suffix;
            url = URLEncoder.encode(url, "utf-8");
        }
        YozoFileParams fileParams = new YozoFileParams();
        BeanUtils.copyProperties(params, fileParams);
        fileParams.setUrl(url);
        return this.previewType(previewType, fileParams);
    }
 
    /**
     * 选择预览方式 yozo:永中预览;  doc:kk文档预览;
     * 说明 采用永中url方式预览时,请注意域名是否对应
     *
     * @param previewType
     * @param params
     * @return
     */
    public ActionResult previewType(String previewType, YozoFileParams params) {
        if (params.getUrl() == null) {
            return ActionResult.fail(MsgCode.ETD115.get());
        }
        if (previewType.equals(FilePreviewTypeEnum.YOZO_ONLINE_PREVIEW.getType())) {
            return yozoApi.getUrl(params);
        }
        //加密
        byte[] sb = params.getUrl().getBytes();
        String s = new String(Base64.encodeBase64(sb));
        if (previewType.equals(FilePreviewTypeEnum.LOCAL_PREVIEW.getType())) {
            String url = YozoParams.JNPF_DOMAINS + "/api/file/onlinePreview?url=" + s;
            return ActionResult.success("success", url);
        }
        return ActionResult.fail(MsgCode.ETD116.get());
    }
}