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

View File

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