This commit is contained in:
牛子源 2025-05-17 12:44:23 +08:00
parent 29dd5d9671
commit fd770581a7
2 changed files with 21 additions and 12 deletions

View File

@ -3,6 +3,7 @@ package com.syjiaer.clinic.server.common.config;
import com.syjiaer.clinic.server.common.exception.MessageException;
import com.syjiaer.clinic.server.common.exception.VerifyException;
import com.syjiaer.clinic.server.common.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@ -11,6 +12,7 @@ import org.springframework.stereotype.Component;
import java.net.http.HttpResponse;
@Slf4j
@Component // 将当前类交给spring管理
@Aspect // 声明这是一个AOP类
public class ControllerAspect {
@ -40,7 +42,7 @@ public class ControllerAspect {
result.setMessage("系统异常");
result.setData(null);
result.setCode(101);
e.printStackTrace();
log.error(e.getMessage());
return result;
}
}

View File

@ -42,26 +42,33 @@ public class FileController extends BaseController {
@RequestMapping("/getImage/{fileName}")
@NoAuthCheck
public ResponseEntity<Resource> getImage(@PathVariable String fileName) {
return fileService.getImage(fileName);
try {
return fileService.getImage(fileName);
} catch (Exception e) {
return ResponseEntity.notFound().build();
}
}
@RequestMapping("/download/{token}")
@NoAuthCheck
public ResponseEntity<Resource> download(@PathVariable String token){
JSONObject jsonObject =cacheUtil.get(token);
String filename=jsonObject.getString("path");
Path path = Paths.get(filename);
Resource resource= null;
try {
JSONObject jsonObject =cacheUtil.get(token);
String filename=jsonObject.getString("path");
Path path = Paths.get(filename);
Resource resource= null;
resource = new UrlResource(path.toUri());
} catch (MalformedURLException e) {
throw new MessageException("创建下载失败");
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
.body(resource);
} catch (Exception e) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
.body(resource);
}