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
package jnpf.controller;
 
import cn.dev33.satoken.annotation.SaCheckPermission;
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.Page;
import jnpf.constant.MsgCode;
import jnpf.emnus.FilePreviewTypeEnum;
import jnpf.constant.FileTypeConstant;
import jnpf.file.FileUploadApi;
import jnpf.model.YozoFileParams;
import jnpf.model.YozoParams;
import jnpf.model.FileListVO;
import jnpf.util.*;
import jnpf.utils.SplicingUrlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 文档在线预览
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2019年9月26日 上午9:18
 */
@Tag(name = "文档在线预览", description = "DocumentPreview")
@RestController
@RequestMapping("/DocumentPreview")
public class DocumentPreviewController {
 
    @Autowired
    private FileUploadApi fileUploadApi;
 
    /**
     * 永中文件预览
     *
     * @param fileId 文件主键
     * @param params 永中模型
     * @param previewType 类型
     * @return
     */
    @Operation(summary = "文件预览")
    @GetMapping("/{fileId}/Preview")
    @Parameters({
            @Parameter(name = "fileId", description = "文件主键",required = true),
            @Parameter(name = "previewType", description = "类型"),
    })
    @SaCheckPermission("extend.documentPreview")
    public ActionResult filePreview(@PathVariable("fileId") String fileId,YozoFileParams params,@RequestParam("previewType") String previewType) {
        List<FileListVO> fileList = fileUploadApi.getFileList(FileTypeConstant.DOCUMENTPREVIEW);
        FileListVO fileListVO = fileList.get(Integer.parseInt(fileId));
        if (fileListVO == null) {
            return ActionResult.fail(MsgCode.ETD111.get());
        }
        String fileName = fileListVO.getFileName();
        if (fileName != null && fileName.contains("/")) {
            fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
        }
        String url = YozoParams.JNPF_DOMAINS + "/api/file/Image/" + FileTypeConstant.DOCUMENTPREVIEW + "/" + fileName + "?fullfilename=" + fileName + "&s=" + UserProvider.getUser().getSecurityKey();;
        String urlPath;
        if (previewType.equals(FilePreviewTypeEnum.YOZO_ONLINE_PREVIEW.getType())){
            params.setUrl(url);
            urlPath = SplicingUrlUtil.getPreviewUrl(params);
            return ActionResult.success("success", XSSEscape.escape(urlPath));
        }
        return ActionResult.success("success",url);
    }
 
    /**
     * 列表
     *
     * @param page 分页模型
     * @return
     */
    @Operation(summary = "获取文档列表")
    @GetMapping
    @SaCheckPermission("extend.documentPreview")
    public ActionResult<List<FileListVO>> list(Page page) {
        List<FileListVO> fileList = fileUploadApi.getFileList(FileTypeConstant.DOCUMENTPREVIEW);
        fileList.stream().forEach(t -> {
            if (t.getFileName() != null) {
                String[] split = t.getFileName().split("/");
                if (split.length > 0) {
                    t.setFileName(split[split.length - 1]);
                }
            }
        });
        if (StringUtil.isNotEmpty(page.getKeyword())) {
            fileList = fileList.stream().filter(t -> t.getFileName().contains(page.getKeyword())).collect(Collectors.toList());
        }
        return ActionResult.success(fileList);
    }
 
    /**
     * 文件下载url
     *
     * @param fileName 名称
     */
//    @NoDataSourceBind()
//    @GetMapping("/down/{fileName}")
//    @Parameters({
//            @Parameter(name = "fileName", description = "名称",required = true),
//    })
//    public void pointDown(@PathVariable("fileName") String fileName) throws DataException, IOException {
//        String path = fileApi.getPath(FileTypeConstant.DOCUMENTPREVIEWPATH);
//        boolean exists = fileApi.fileExists(path, fileName);
//        if (!exists) {
//            throw new DataException(MsgCode.FA006.get());
//        }
//        Response response = fileUploadApi.downFileByte(new UploadFileModel(null, path, fileName));
//        try(InputStream inputStream = response.body().asInputStream()){
//            FileDownloadUtil.outFile(inputStream, fileName);
//        }catch (IOException e){
//            throw new RuntimeException(e);
//        }
//    }
 
 
}