forked from kidgrow-microservices-platform

zhaoxiaohao
2020-08-12 3dcb4e0ebfd43190957f556d886917b2a2ffa064
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
package com.kidgrow.filecenter.controller;
 
import com.kidgrow.common.model.PageResult;
import com.kidgrow.common.model.Result;
import com.kidgrow.common.model.ResultBody;
import com.kidgrow.filecenter.model.FileInfo;
import com.kidgrow.filecenter.service.IFileService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.util.Map;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @Description: 文件上传<br>
 * @Project: <br>
 * @CreateDate: Created in 2020/2/18 11:41 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 */
@RestController
public class FileController {
    @Resource
    private IFileService fileService;
 
    /**
     * 文件上传
     * 根据fileType选择上传方式
     *
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping(value="/files-anon",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public FileInfo upload(@RequestParam("file") MultipartFile file) throws Exception {
        return fileService.upload(file);
    }
 
 
    /**
     * 文件上传
     * 根据fileType选择上传方式
     *
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping(value="/files-upload",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public FileInfo feignUpload(@RequestPart("file") MultipartFile file,@RequestParam String imgType) throws Exception {
        return fileService.upload(file,imgType);
    }
    /**
     * 文件上传 返回带缩略图地址的对象,缩略图在path字段
     *
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping(value="/files-thupload",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public FileInfo thUpload(@RequestPart("file") MultipartFile file,@RequestParam String imgType) throws Exception {
        return fileService.uploadForThumbnails(file,imgType);
    }
    /**
     * base64上传图片
     */
    @PostMapping(value="baseUplaod",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public FileInfo baseUplaod(@RequestParam("file") String file,@RequestParam("imgType") String imgType,
                               @RequestParam("hospitalId") String hospitalId,@RequestParam("departmentId") String departmentId){
        return fileService.baseUplaod(file,imgType,hospitalId,departmentId);
    }
    /**
     * base64图片下载
     */
    @PostMapping(value="baseDownLoad")
    public ResultBody baseDownLoad(@RequestBody Map<String,Object> map) throws Exception{
        String url = MapUtils.getString(map, "url");
        if (StringUtils.isBlank(url)) {
            return ResultBody.failed("请输入地址");
        }
        return fileService.baseDownLoad(map);
    }
 
    /**
     * 文件删除
     *
     * @param id
     */
    @DeleteMapping("/files/{id}")
    public Result delete(@PathVariable String id) {
        try {
            fileService.delete(id);
            return Result.succeed("操作成功");
        } catch (Exception ex) {
            return Result.failed("操作失败");
        }
    }
 
    /**
     * 文件查询
     *
     * @param params
     * @return
     */
    @GetMapping("/files")
    public PageResult<FileInfo> findFiles(@RequestParam Map<String, Object> params) {
        return fileService.findList(params);
    }
}