Compare commits
1 Commits
master_lz
...
d60966dd3f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d60966dd3f |
@@ -2,7 +2,6 @@ package top.wms.admin.controller.tcp.service;
|
|||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import top.wms.admin.controller.tcp.manager.ChannelManager;
|
import top.wms.admin.controller.tcp.manager.ChannelManager;
|
||||||
import top.wms.admin.controller.tcp.model.VMResult;
|
import top.wms.admin.controller.tcp.model.VMResult;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -61,7 +60,7 @@ public class CommandService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
|
|
||||||
@Scheduled(cron = "*/1 * * * * ?")
|
// @Scheduled(cron = "*/3 * * * * ?")
|
||||||
public void sendAndWait() {
|
public void sendAndWait() {
|
||||||
// 1. 检查连接
|
// 1. 检查连接
|
||||||
log.info("查询时间========");
|
log.info("查询时间========");
|
||||||
|
|||||||
@@ -1,30 +1,13 @@
|
|||||||
package top.wms.admin.controller.vm;
|
package top.wms.admin.controller.vm;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import io.netty.channel.Channel;
|
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.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.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import top.continew.starter.core.validation.CheckUtils;
|
import top.continew.starter.core.validation.CheckUtils;
|
||||||
import top.wms.admin.controller.tcp.config.SimpleRequestMatcher;
|
import top.wms.admin.controller.tcp.config.SimpleRequestMatcher;
|
||||||
import top.wms.admin.controller.tcp.manager.ChannelManager;
|
import top.wms.admin.controller.tcp.manager.ChannelManager;
|
||||||
import top.wms.admin.system.service.FileService;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@@ -37,9 +20,6 @@ public class VmCommandController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SimpleRequestMatcher requestMatcher;
|
private SimpleRequestMatcher requestMatcher;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FileService fileService;
|
|
||||||
|
|
||||||
@GetMapping("/send")
|
@GetMapping("/send")
|
||||||
public String sendAndWait(@RequestParam String msg) {
|
public String sendAndWait(@RequestParam String msg) {
|
||||||
// 1. 检查连接
|
// 1. 检查连接
|
||||||
@@ -65,101 +45,4 @@ public class VmCommandController {
|
|||||||
return response; // 直接返回VM的响应
|
return response; // 直接返回VM的响应
|
||||||
}
|
}
|
||||||
|
|
||||||
// 基础路径
|
|
||||||
private static final String BASE_PATH = "C:/Users/14725/Desktop/material";
|
|
||||||
|
|
||||||
// 固定照片名称
|
|
||||||
private static final String PHOTO_NAME = "001.bmp";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取最新的001.bmp照片
|
|
||||||
*
|
|
||||||
* @return 图片文件
|
|
||||||
*/
|
|
||||||
/*@GetMapping("/latest-photo")
|
|
||||||
public ResponseEntity<byte[]> getLatestPhoto() {
|
|
||||||
try {
|
|
||||||
// 获取当前日期
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@GetMapping("/latest-photo")
|
|
||||||
public String getLatestPhoto() {
|
|
||||||
try {
|
|
||||||
// 获取当前日期
|
|
||||||
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 null; // 或者抛出异常,根据业务需求决定
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将文件转换为MultipartFile
|
|
||||||
File file = imagePath.toFile();
|
|
||||||
FileInputStream input = new FileInputStream(file);
|
|
||||||
MultipartFile multipartFile = new MockMultipartFile(
|
|
||||||
file.getName(), // 文件名
|
|
||||||
file.getName(), // 原始文件名
|
|
||||||
"image/bmp", // 内容类型
|
|
||||||
input // 文件输入流
|
|
||||||
);
|
|
||||||
|
|
||||||
// 构建MinIO存储路径
|
|
||||||
String photoStoragePath = "catch" + DateUtil.today() + "/";
|
|
||||||
|
|
||||||
// 使用现有的fileService上传到MinIO
|
|
||||||
FileInfo fileInfo = fileService.upload(multipartFile, photoStoragePath, null, true, true);
|
|
||||||
|
|
||||||
// 检查上传结果
|
|
||||||
CheckUtils.throwIfNull(fileInfo, "照片上传失败");
|
|
||||||
|
|
||||||
// 关闭输入流
|
|
||||||
input.close();
|
|
||||||
return fileInfo.getUrl();
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new RuntimeException("处理图片失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import java.util.regex.Pattern;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class AHDZCConnect {
|
public class AHDZCConnect {
|
||||||
|
|
||||||
private static final String PORT_NAME = "COM12";
|
private static final String PORT_NAME = "COM5";
|
||||||
private static final int BAUD_RATE = 9600;
|
private static final int BAUD_RATE = 9600;
|
||||||
private static final int DATA_BITS = 8;
|
private static final int DATA_BITS = 8;
|
||||||
private static final int STOP_BITS = 1;
|
private static final int STOP_BITS = 1;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ spring.datasource:
|
|||||||
# 请务必提前创建好名为 wms_admin 的数据库,如果使用其他数据库名请注意同步修改 DB_NAME 配置
|
# 请务必提前创建好名为 wms_admin 的数据库,如果使用其他数据库名请注意同步修改 DB_NAME 配置
|
||||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||||
username: root
|
username: root
|
||||||
password: test123$
|
password: root
|
||||||
# PostgreSQL 配置
|
# PostgreSQL 配置
|
||||||
# url: jdbc:p6spy:mysql://192.168.2.30:${DB_PORT:3306}/continew?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
# url: jdbc:p6spy:mysql://192.168.2.30:${DB_PORT:3306}/continew?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||||
# username: ${DB_USER:root}
|
# username: ${DB_USER:root}
|
||||||
|
|||||||
Reference in New Issue
Block a user