This commit is contained in:
caozehui
2025-11-13 14:20:50 +08:00
parent 1cbed2a620
commit 1df9c8d703

View File

@@ -74,53 +74,62 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
MultipartFile mappingFile = param.getMappingFile();
// if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
// String mappingFilename = mappingFile.getOriginalFilename();
//
// if (!mappingFilename.endsWith(".txt")) {
// throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
// }
// if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
// throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
// }
//
// try {
// // 如果文件存在,则先删除
// String mappingFilePath = commInstallPath + "\\DeviceControl\\Config" + mappingFilename;
// Path path = Paths.get(mappingFilePath);
// File file = path.toFile();
// if (file.exists()) {
// file.delete();
// }
//
// // 保存文件
// byte[] bytes = mappingFile.getBytes();
// BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
// bufferedOutputStream.write(bytes);
// bufferedOutputStream.flush();
//
// bufferedOutputStream.close();
// } catch (IOException e) {
// throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
// }
// } else {
// throw new BusinessException(IcdResponseEnum.FILE_NOT_NULL);
// }
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
String mappingFilename = mappingFile.getOriginalFilename();
if (!mappingFilename.endsWith(".txt")) {
throw new BusinessException(IcdResponseEnum.FILE_TYPE_ERROR);
}
if (mappingFile.getSize() > FILE_SIZE_LIMIT) {
throw new BusinessException(IcdResponseEnum.FILE_SIZE_ERROR);
}
try {
// 如果文件存在,则先删除
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
Path path = Paths.get(mappingFilePath);
File file = path.toFile();
if (file.exists()) {
file.delete();
}
// 保存文件
byte[] bytes = mappingFile.getBytes();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(mappingFilePath));
bufferedOutputStream.write(bytes);
bufferedOutputStream.flush();
bufferedOutputStream.close();
} catch (IOException e) {
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
}
} else {
throw new BusinessException(IcdResponseEnum.FILE_NOT_NULL);
}
this.executeRestartCmd(commInstallPath);
return this.save(pqIcdPath);
}
/**
* 执行重启通讯服务脚本
*
* @param commInstallPath
*/
private void executeRestartCmd(String commInstallPath) {
// 以管理员身份运行bat脚本
String batFilePath = commInstallPath + "\\重启通讯服务.bat";
String batFilePath = commInstallPath + "\\重启所有服务.bat";
try {
Runtime.getRuntime().exec(batFilePath);
} catch (IOException e) {
log.error("重启通讯服务失败", e);
}
return this.save(pqIcdPath);
}
private String getCommInstallPath() {
// String workDir = System.getProperty("user.dir");
String workDir = "D:\\program\\CN_Gather";
String workDir = System.getProperty("user.dir");
// String workDir = "D:\\program\\CN_Gather";
// 获取映射文件存放文件夹
String dirPath = workDir.substring(0, workDir.lastIndexOf("\\")) + "\\9100";
return dirPath;
@@ -149,7 +158,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
try {
// 如果文件存在,则先删除
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config" + mappingFilename;
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
Path path = Paths.get(mappingFilePath);
File file = path.toFile();
if (file.exists()) {
@@ -167,6 +176,9 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
}
}
this.executeRestartCmd(commInstallPath);
return this.updateById(pqIcdPath);
}