二维码下装独立抽取

This commit is contained in:
2025-07-18 14:38:02 +08:00
parent b5e5286411
commit a6b0509179
2 changed files with 87 additions and 89 deletions

View File

@@ -615,17 +615,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
}
out.close();
this.updateDevAndPlanState(devReportParam.getDevId(), devReportParam.getPlanId());
sendReportToCloud(pqDevVO.getIp(), reportFullPath, pqDevVO.getCreateId() + ".docx");
// // 检测报告上云
// Future<?> future = executor.submit(() -> {
// sendReportToCloud(pqDevVO.getIp(), reportFullPath, pqDevVO.getCreateId() + ".docx");
// });
// try {
// future.get();
// } catch (Exception e) {
// log.error("检测报告上云异常,异常为:"+e.getMessage());
// }
sendQrToDevice(pqDevVO.getIp(), pqDevVO.getCreateId() + ".docx");
} catch (IOException e) {
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e);
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR);
@@ -633,69 +624,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
});
}
/**
* 测试FTP连接
*
* @param host FTP服务器地址
* @param port FTP端口
* @param username 用户名
* @param password 密码
* @return 连接是否成功
*/
public static boolean testFTPConnection(String host, int port, String username, String password) {
FTPClient ftpClient = new FTPClient();
private void sendQrToDevice(String devIp, String reportName) {
try {
// 连接FTP服务器
ftpClient.connect(host, port);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode)) {
System.err.println("FTP服务器拒绝连接回复代码: " + replyCode);
return false;
}
// 登录FTP服务器
boolean loginSuccess = ftpClient.login(username, password);
if (!loginSuccess) {
System.err.println("FTP登录失败请检查用户名和密码");
return false;
}
// 设置传输模式为被动模式
//ftpClient.enterLocalPassiveMode();
// 设置文件传输类型为二进制
//ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("FTP连接测试成功!");
return true;
} catch (IOException e) {
System.err.println("FTP连接测试失败: " + e.getMessage());
return false;
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException e) {
System.err.println("关闭FTP连接时出错: " + e.getMessage());
}
}
}
/**
* 处理检测报告上传云服务器并生成二维码下装到装置
* 做成异步执行
*
* @param devIp 设备IP
* @param reportFullPath 检测报告本地全路径
* @param reportName 检测报告名称
*/
public void sendReportToCloud(String devIp, String reportFullPath, String reportName) {
// 将文件上传至目标服务器
File file = new File(reportFullPath);
try {
ResponseEntity<String> responseEntity = restTemplateUtil.uploadFile(cloudUrl + "/upload", file);
if (responseEntity.getStatusCode().is2xxSuccessful()) {
// 上传没问题后拼接url生成二维码并将二维码转为bin格式文件传递给设备通讯模块
String qrUrl = cloudUrl + "/download/" + reportName;
BufferedImage bufferedImage = QrCodeUtil.generate(qrUrl, 148, 148);
@@ -748,8 +679,26 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
} else {
channel.writeAndFlush(msg + "\n");
}
} catch (Exception e) {
// 进行日志记录入口
System.out.println("异常为:" + e.getMessage());
}
}
/**
* 处理检测报告上传云服务器并生成二维码下装到装置
* 做成异步执行
*
* @param devIp 设备IP
* @param reportFullPath 检测报告本地全路径
* @param reportName 检测报告名称
*/
public void sendReportToCloud(String devIp, String reportFullPath, String reportName) {
// 将文件上传至目标服务器
File file = new File(reportFullPath);
try {
ResponseEntity<String> responseEntity = restTemplateUtil.uploadFile(cloudUrl + "/upload", file);
} catch (Exception e) {
// 进行日志记录入口
System.out.println("异常为:" + e.getMessage());
@@ -759,6 +708,55 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
}
/**
* 测试FTP连接
*
* @param host FTP服务器地址
* @param port FTP端口
* @param username 用户名
* @param password 密码
* @return 连接是否成功
*/
public static boolean testFTPConnection(String host, int port, String username, String password) {
FTPClient ftpClient = new FTPClient();
try {
// 连接FTP服务器
ftpClient.connect(host, port);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode)) {
System.err.println("FTP服务器拒绝连接回复代码: " + replyCode);
return false;
}
// 登录FTP服务器
boolean loginSuccess = ftpClient.login(username, password);
if (!loginSuccess) {
System.err.println("FTP登录失败请检查用户名和密码");
return false;
}
// 设置传输模式为被动模式
//ftpClient.enterLocalPassiveMode();
// 设置文件传输类型为二进制
//ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("FTP连接测试成功!");
return true;
} catch (IOException e) {
System.err.println("FTP连接测试失败: " + e.getMessage());
return false;
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException e) {
System.err.println("关闭FTP连接时出错: " + e.getMessage());
}
}
}
/**
* 根据计划绑定的报告模板生成报告
* 注:该方法目前属于同用信息占位符替换,数据页为面向对象动态填充拼凑方式

View File

@@ -6,7 +6,7 @@ spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.24:13306/pqs91003?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
url: jdbc:mysql://192.168.1.24:13306/pqs9100_2f?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
username: root
password: njcnpqs
# url: jdbc:mysql://localhost:3306/pqs91001?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=CTT