Merge remote-tracking branch 'origin/qr_branch'

# Conflicts:
#	entrance/src/main/resources/application.yml
This commit is contained in:
2025-07-18 14:55:08 +08:00

View File

@@ -618,17 +618,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);
@@ -636,69 +627,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);
@@ -751,8 +682,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());
@@ -762,6 +711,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());
}
}
}
/**
* 根据计划绑定的报告模板生成报告
* 注:该方法目前属于同用信息占位符替换,数据页为面向对象动态填充拼凑方式