liurunyu
2024-10-23 0cba67398a247b8f1a6db09cc3aed26aff17dfc0
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
package com.dy.pipIrrWebFile.get;
 
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pipIrrGlobal.dyFile.FileOperate;
import com.dy.pipIrrGlobal.dyFile.FileRestVo;
import com.dy.pipIrrGlobal.pojoFi.WebFile;
import com.dy.pipIrrGlobal.voFi.VoPhoto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * @author ZhuBaoMin
 * @date 2024-10-22 15:26
 * @LastEditTime 2024-10-22 15:26
 * @Description 获取文件控制类
 */
 
@Slf4j
@RestController
@RequestMapping(path = "get")
@RequiredArgsConstructor
public class GetFileCtrl {
    private final GetFileSv getFileSv;
 
    @Autowired
    private FileOperate fileOp ;
 
    @Value("${dy.webFile.fmUrl}")
    private String fmUrl ;
 
    /**
     * 根据图片ID获取图片路径
     * @param photoId
     * @return
     */
    @GetMapping(path = "/getPhotoFile")
    @SsoAop()
    public BaseResponse<VoPhoto> getPhotoFile(@RequestParam("photoId") Long photoId) {
        try {
 
            // 根据图片ID获取图片文件对象,从图片文件对象中获取文件路径、扩展名、缩略图文件路径
            WebFile webFile = getFileSv.getWebFileById(photoId);
            if(webFile == null) {
                return BaseResponseUtils.buildErrorMsg("图标ID错误");
            }
            String filePath = webFile.getFilePath();
            String extName = webFile.getExtName();
            String filePathZip = filePath.substring(0, filePath.indexOf('.')) + "_." + extName;
 
            FileRestVo frVo = fileOp.parseHashcode(fmUrl, webFile.hash);
 
            VoPhoto photo = new VoPhoto();
            photo.setDownloadPath(frVo.fileWebDownloadPath + photoId);
            photo.setWebPath(frVo.fileWebUrl + filePath);
            photo.setWebPathZip(frVo.fileWebUrl + filePathZip);
 
            return BaseResponseUtils.buildSuccess(photo);
        } catch (Exception e) {
            log.error("获取图片文件异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
 
}