通过尝试ftp连接将二维码文件下装到装置中
This commit is contained in:
@@ -73,6 +73,8 @@ import com.njcn.web.factory.PageFactory;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPReply;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.docx4j.jaxb.Context;
|
||||
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||
@@ -139,6 +141,21 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
@Value("${qr.dev.port}")
|
||||
private Integer devPort;
|
||||
|
||||
@Value("${qr.dev.path}")
|
||||
private String devPath;
|
||||
|
||||
@Value("${qr.gcDev.name}")
|
||||
private String gcDevName;
|
||||
|
||||
@Value("${qr.gcDev.password}")
|
||||
private String gcDevPsd;
|
||||
|
||||
@Value("${qr.gcDev.port}")
|
||||
private Integer gcDevPort;
|
||||
|
||||
@Value("${qr.gcDev.path}")
|
||||
private String gcDevPath;
|
||||
|
||||
private final IPqDevService iPqDevService;
|
||||
private final PqDevMapper pqDevMapper;
|
||||
|
||||
@@ -616,6 +633,54 @@ 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理检测报告上传云服务器并生成二维码下装到装置
|
||||
@@ -646,16 +711,27 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
byte[] finalBinData = ImageConverter.convertToBinFormat(bufferedImage);
|
||||
String base64String = Base64.getEncoder().encodeToString(finalBinData);
|
||||
|
||||
// 测试ftp是否连接成功
|
||||
|
||||
|
||||
// 组装设备通讯模块的参数
|
||||
SocketMsg<String> sendFileMsg = new SocketMsg<>();
|
||||
sendFileMsg.setOperateCode(SourceOperateCodeEnum.FTP_SEND_01.getValue());
|
||||
sendFileMsg.setRequestId(SourceOperateCodeEnum.FTP_SEND_01.getValue());
|
||||
|
||||
// 组装业务数据
|
||||
JSONObject data = new JSONObject();
|
||||
data.set("name", devName);
|
||||
data.set("password", devPsd);
|
||||
data.set("port", devPort);
|
||||
data.set("path", "ftp://" + devIp + "/etc/qrc.bin");
|
||||
if (testFTPConnection(cloudUrl, devPort, devName, devPsd)) {
|
||||
data.set("name", devName);
|
||||
data.set("password", devPsd);
|
||||
data.set("port", devPort);
|
||||
data.set("path", "ftp://" + devIp + devPath);
|
||||
} else {
|
||||
data.set("name", gcDevName);
|
||||
data.set("password", gcDevPsd);
|
||||
data.set("port", gcDevPort);
|
||||
data.set("path", "ftp://" + devIp + gcDevPath);
|
||||
}
|
||||
data.set("file", base64String);
|
||||
sendFileMsg.setData(data.toString());
|
||||
String msg = JSON.toJSONString(sendFileMsg);
|
||||
|
||||
Reference in New Issue
Block a user