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 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()); } } }