提交 40c4871c 编写于 作者: tangyaolong's avatar tangyaolong

lite代码兼容disk,删除无引用代码

上级 74aac998
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.disk.domain.MetaDynamicModel;
import cn.ibizlab.core.disk.extensions.service.DiskCoreService;
import cn.ibizlab.core.disk.service.IMetaDynamicModelService;
import cn.ibizlab.core.disk.service.impl.MetaDynamicModelServiceImpl;
import cn.ibizlab.util.cache.listener.RedisPublisher;
......@@ -49,11 +50,8 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
}
@Value("${ibiz.filePath:/app/file/}")
private String fileRoot;
@Autowired
private FileService fileService;
DiskCoreService diskCoreService;
@Autowired
private IMetaDynamicModelService dynamicModelService;
......@@ -62,7 +60,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
@Lazy
private IBZWFFeignClient wfClient;
@Value("${ibiz.dynamic.publishpath:/app/file/dynamicModel/publicpath}")
@Value("${ibiz.dynamic.publishpath:d:/app/file/dynamicModel/publicpath/net-disk}")
private String publishPath;
@Autowired
......@@ -103,10 +101,9 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (!ObjectUtils.isEmpty(items) && items.size() > 1) {
throw new BadRequestAlertException("单次只允许上传一个模型文件", "MetaDynamicModel", "unzip");
}
String dirPath = this.fileRoot + "ibizutil" + File.separator + items.get(0).getId();
File parent = new File(dirPath);
if (parent.exists() && parent.isDirectory() && parent.listFiles().length > 0) {
modelFile = new File(FileHelper.getLatestFilePath(parent.listFiles()));
File parent = diskCoreService.getFile(items.get(0).getId());
if (parent.exists()) {
modelFile = parent;
} else {
throw new InternalServerErrorException("文件未找到");
}
......@@ -171,18 +168,22 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
public MetaDynamicModel publish(MetaDynamicModel et) {
et = get(et.getConfigid());
String systemId = et.getSystemId();
String dynamicId = et.getDynainstid();
String strModelFile = et.getModelfile();
if (StringUtils.isEmpty(strModelFile) && StringUtils.isEmpty(et.getSystemId()))
throw new BadRequestAlertException(String.format("信息不足,请检查[%s]模型数据是否存在系统标识及模型文件", et.getConfigid()), "MetaDynamicModel", "unzip");
throw new BadRequestAlertException(String.format("信息不足,请检查[%s]模型数据是否存在系统标识及模型文件", et.getConfigid()), "MetaDynamicModel", "publish");
List<FileItem> items = JSONArray.parseArray(strModelFile, FileItem.class);
if (!ObjectUtils.isEmpty(items) && items.size() > 1)
throw new BadRequestAlertException(String.format("模型解析失败,[%s]模型文件过多", et.getConfigid()), "MetaDynamicModel", "unzip");
throw new BadRequestAlertException(String.format("模型解析失败,[%s]模型文件过多", et.getConfigid()), "MetaDynamicModel", "publish");
File publishFile = new File(getPublishPath() + systemId + File.separator + et.getDynainstid());
//删除发布目录中的历史文件
if (publishFile.exists()) {
FileHelper.deleteDir(publishFile.getPath());
}
File modelFile = fileService.getFile(items.get(0).getId());
if(ObjectUtils.isEmpty(items)){
throw new BadRequestAlertException(String.format("文件不存在,请在发布前确认文件是否已经上传!", et.getConfigid()), "MetaDynamicModel", "publish");
}
File modelFile = diskCoreService.getFile(items.get(0).getId());
String unzipPath = modelFile.getParent().replace("ibizutil", "dynamicmodel");
File unzipFile = new File(unzipPath);
//拷贝文件到发布目录
......@@ -204,70 +205,11 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
redisPublisher.publisher(message);
//激活当前et.
et.setStatus(StaticDict.DynamicModelStatus.ITEM_1.getValue());
update(Wrappers.<MetaDynamicModel>lambdaUpdate().set(MetaDynamicModel::getStatus, StaticDict.DynamicModelStatus.ITEM_0.getValue()).eq(MetaDynamicModel::getSystemId, systemId));
update(Wrappers.<MetaDynamicModel>lambdaUpdate().set(MetaDynamicModel::getStatus, StaticDict.DynamicModelStatus.ITEM_0.getValue()).eq(MetaDynamicModel::getSystemId, systemId).eq(MetaDynamicModel::getDynainstid, dynamicId));
update(et);
return et;
}
/**
* 获取处理逻辑
*
* @param systemId
* @return
*/
@SneakyThrows
public List<Map<String, Object>> getDynamicModel(String systemId) {
String pubPath = getPublishPath() + systemId;
List<Map<String, Object>> delogics = searchLogic(pubPath);
if (ObjectUtils.isEmpty(delogics)) {
throw new BadRequestAlertException(String.format("在发布目录[%s]中没有找到系统[%s]动态模型文件", pubPath, systemId), "MetaDynamicModel", "getDynamicModel");
}
return delogics;
}
/**
* 从发布目录中查询 bpmn及drl
*
* @param path
* @return
*/
public List<Map<String, Object>> searchLogic(String path) {
List<Map<String, Object>> models = new ArrayList<>();
File publish = new File(path);
if (!publish.exists()) {
throw new BadRequestAlertException(String.format("发布目录[%s]不存在", publish.getPath()), "MetaDynamicModel", "searchLogic");
}
File[] subFiles = publish.listFiles();
if (null != subFiles) {
for (File subFile : subFiles) {
if (subFile.isDirectory()) {
List<Map<String, Object>> subModels = searchLogic(subFile.getAbsolutePath());
if (!ObjectUtils.isEmpty(subModels)) {
models.addAll(subModels);
}
} else if (subFile.isFile() && (!subFile.getName().matches(wf_regex)) && (subFile.getName().endsWith(".bpmn") || subFile.getName().endsWith(".drl"))) {
InputStream file = null;
try {
file = new FileInputStream(subFile);
Map fileMap = new HashMap();
fileMap.put("filename", subFile.getName().toLowerCase());
fileMap.put("filepath", subFile.getPath().replace(getPublishPath(), "").toLowerCase());
fileMap.put("filecontent", IOUtils.toString(file, "UTF-8"));
models.add(fileMap);
} catch (IOException e) {
} finally {
try {
if (file != null) {
file.close();
}
} catch (IOException e) {
}
}
}
}
}
return models;
}
/**
* 从查询工作流 bpmn
......
......@@ -7,15 +7,7 @@ import org.springframework.util.StringUtils;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
......@@ -139,36 +131,6 @@ public class FileHelper {
}
}
/**
* 获取相同路径下最新的文件
* @param files 传入文件组
* @return
*/
public static String getLatestFilePath(File[] files) {
if (files == null) {
return null;
}
BasicFileAttributes attr = null;
Map<Long,String> compareMap = new HashMap();
Long format = 0L;
try {
for (File file : files) {
Path path = file.toPath();
attr = Files.readAttributes(path, BasicFileAttributes.class);
Instant instant = attr.creationTime().toInstant();
Long compareDate = Long.parseLong(DateTimeFormatter.ofPattern("yyyyMMddHHmmss").withZone(ZoneId.systemDefault()).format(instant));
format = compareDate > format ? compareDate : format ;
compareMap.put(format,path.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
return compareMap.get(format);
}
/**
* 构建目录
* @param outputDir
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册