微调
This commit is contained in:
@@ -55,7 +55,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
|||||||
page.getRecords().forEach(pqIcdPath -> {
|
page.getRecords().forEach(pqIcdPath -> {
|
||||||
PqIcdPath.FileVO fileVO = new PqIcdPath.FileVO();
|
PqIcdPath.FileVO fileVO = new PqIcdPath.FileVO();
|
||||||
fileVO.setUrl(commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt");
|
fileVO.setUrl(commInstallPath + "\\DeviceControl\\Config\\" + pqIcdPath.getName() + ".txt");
|
||||||
fileVO.setName(pqIcdPath.getName()+ ".txt");
|
fileVO.setName(pqIcdPath.getName() + ".txt");
|
||||||
pqIcdPath.setMappingFile(fileVO);
|
pqIcdPath.setMappingFile(fileVO);
|
||||||
});
|
});
|
||||||
return page;
|
return page;
|
||||||
@@ -74,53 +74,62 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
|||||||
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
|
long FILE_SIZE_LIMIT = 1 * 1024 * 1024;
|
||||||
MultipartFile mappingFile = param.getMappingFile();
|
MultipartFile mappingFile = param.getMappingFile();
|
||||||
|
|
||||||
// if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
|
if (ObjectUtil.isNotNull(mappingFile) && !mappingFile.isEmpty()) {
|
||||||
// String mappingFilename = mappingFile.getOriginalFilename();
|
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 (!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脚本
|
// 以管理员身份运行bat脚本
|
||||||
String batFilePath = commInstallPath + "\\重启通讯服务.bat";
|
String batFilePath = commInstallPath + "\\重启所有服务.bat";
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().exec(batFilePath);
|
Runtime.getRuntime().exec(batFilePath);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("重启通讯服务失败", e);
|
log.error("重启通讯服务失败", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.save(pqIcdPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCommInstallPath() {
|
private String getCommInstallPath() {
|
||||||
// String workDir = System.getProperty("user.dir");
|
String workDir = System.getProperty("user.dir");
|
||||||
String workDir = "D:\\program\\CN_Gather";
|
// String workDir = "D:\\program\\CN_Gather";
|
||||||
// 获取映射文件存放文件夹
|
// 获取映射文件存放文件夹
|
||||||
String dirPath = workDir.substring(0, workDir.lastIndexOf("\\")) + "\\9100";
|
String dirPath = workDir.substring(0, workDir.lastIndexOf("\\")) + "\\9100";
|
||||||
return dirPath;
|
return dirPath;
|
||||||
@@ -149,7 +158,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// 如果文件存在,则先删除
|
// 如果文件存在,则先删除
|
||||||
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config" + mappingFilename;
|
String mappingFilePath = commInstallPath + "\\DeviceControl\\Config\\" + mappingFilename;
|
||||||
Path path = Paths.get(mappingFilePath);
|
Path path = Paths.get(mappingFilePath);
|
||||||
File file = path.toFile();
|
File file = path.toFile();
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@@ -167,6 +176,9 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
|||||||
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
|
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.executeRestartCmd(commInstallPath);
|
||||||
|
|
||||||
return this.updateById(pqIcdPath);
|
return this.updateById(pqIcdPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user