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