提交 5b1f12ac 编写于 作者: tangyaolong's avatar tangyaolong

补充tar版本获取系统标识

上级 42913384
......@@ -76,18 +76,21 @@ public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
if (StringUtils.isEmpty(strModelFile))
throw new BadRequestAlertException("模型文件为空", "DynamicModelConfig", "unzip");
List<FileItem> items = JSONArray.parseArray(strModelFile, FileItem.class);
if (!ObjectUtils.isEmpty(items) && items.size() > 1)
if (!ObjectUtils.isEmpty(items) && items.size() > 1) {
throw new BadRequestAlertException("单次只允许上传一个模型文件", "DynamicModelConfig", "unzip");
}
File modelFile = fileService.getFile(items.get(0).getId());
JSONObject system = null;
String unzipPath = modelFile.getParent().replace("ibizutil", "dynamicmodel");
// 文件后缀,
if(".gz".equals(modelFile.getName().substring(modelFile.getName().lastIndexOf(".")))){
String fileName = modelFile.getName().substring(0,modelFile.getName().indexOf("."));
FileHelper.unTarGz(modelFile, unzipPath);
system = getSystem(unzipPath,fileName);
}else if(".zip".equals(modelFile.getName().substring(modelFile.getName().lastIndexOf(".")))){
FileHelper.unzip(modelFile, unzipPath, true);
system = getSystem(unzipPath);
}
JSONObject system = getSystem(unzipPath);
et.setSystemId(system.getString("name"));
} catch (IOException e) {
throw new BadRequestAlertException("解析动态模型文件失败," + e, "DynamicModelConfig", "unzip");
......@@ -297,4 +300,43 @@ public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
}
return system;
}
/**
* 获取系统标识
*
* @param filePath
* @return
*/
private JSONObject getSystem(String filePath,String fileName) {
JSONObject system = null;
InputStream in = null;
byte[] bytes = null;
try {
File file = new File(filePath + File.separator + fileName + File.separator+ "PSSYSTEM.json");
if (!file.exists()) {
throw new BadRequestAlertException(String.format("无法找到动态系统模型文件[%s]", file.getPath()), "DynamicModelConfig", "getSystemId");
}
in = new FileInputStream(file);
bytes = new byte[in.available()];
in.read(bytes);
} catch (Exception e) {
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
}
}
if (bytes != null) {
String strSystem = new String(bytes);
if (!StringUtils.isEmpty(strSystem)) {
system = JSONObject.parseObject(strSystem);
}
}
if (ObjectUtils.isEmpty(system)) {
throw new BadRequestAlertException("无法获取系统标识", "DynamicModelConfig", "getSystem");
}
return system;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册