优化
This commit is contained in:
@@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class NettyTcpServer {
|
||||
|
||||
@Value("${tcp.server.port:9005}")
|
||||
@Value("${tcp.server.port:27526}")
|
||||
private int port;
|
||||
|
||||
@Value("${tcp.server.boss-threads:1}")
|
||||
|
||||
@@ -6,9 +6,6 @@ import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.x.file.storage.core.FileInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -38,7 +35,7 @@ public class VmCommandController {
|
||||
private SimpleRequestMatcher requestMatcher;
|
||||
|
||||
@Autowired
|
||||
private FileService fileService;
|
||||
private FileService fileService;
|
||||
|
||||
@GetMapping("/send")
|
||||
public String sendAndWait(@RequestParam String msg) {
|
||||
@@ -83,30 +80,30 @@ public class VmCommandController {
|
||||
LocalDate now = LocalDate.now();
|
||||
String yearMonth = now.format(DateTimeFormatter.ofPattern("yyyyMM"));
|
||||
String day = now.format(DateTimeFormatter.ofPattern("dd"));
|
||||
|
||||
|
||||
// 构建完整的文件路径
|
||||
// 格式: C:/Users/14725/Desktop/material/202603/20260312/001.bmp
|
||||
String filePath = String.format("%s/%s/%s%s/%s", BASE_PATH, yearMonth, yearMonth, day, PHOTO_NAME);
|
||||
|
||||
|
||||
// 读取图片文件
|
||||
Path imagePath = Paths.get(filePath);
|
||||
|
||||
|
||||
// 检查文件是否存在
|
||||
if (!Files.exists(imagePath)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
|
||||
// 读取文件字节
|
||||
byte[] imageBytes = Files.readAllBytes(imagePath);
|
||||
|
||||
|
||||
// 设置响应头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.valueOf("image/bmp"));
|
||||
headers.setContentLength(imageBytes.length);
|
||||
|
||||
|
||||
// 返回图片
|
||||
return new ResponseEntity<>(imageBytes, headers, HttpStatus.OK);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
@@ -136,11 +133,10 @@ public class VmCommandController {
|
||||
// 将文件转换为MultipartFile
|
||||
File file = imagePath.toFile();
|
||||
FileInputStream input = new FileInputStream(file);
|
||||
MultipartFile multipartFile = new MockMultipartFile(
|
||||
file.getName(), // 文件名
|
||||
file.getName(), // 原始文件名
|
||||
"image/bmp", // 内容类型
|
||||
input // 文件输入流
|
||||
MultipartFile multipartFile = new MockMultipartFile(file.getName(), // 文件名
|
||||
file.getName(), // 原始文件名
|
||||
"image/bmp", // 内容类型
|
||||
input // 文件输入流
|
||||
);
|
||||
|
||||
// 构建MinIO存储路径
|
||||
|
||||
Reference in New Issue
Block a user