提交 8c4107fe 编写于 作者: zhouweidong's avatar zhouweidong

优化初始化模型逻辑

上级 413c5b35
......@@ -3,16 +3,19 @@ package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.lite.domain.DynamicModelConfig;
import cn.ibizlab.core.lite.service.impl.DynamicModelConfigServiceImpl;
import cn.ibizlab.util.client.IBZWFFeignClient;
import cn.ibizlab.util.dict.StaticDict;
import cn.ibizlab.util.domain.FileItem;
import cn.ibizlab.util.service.FileService;
import com.alibaba.fastjson.JSONArray;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
......@@ -27,7 +30,9 @@ import java.util.zip.ZipFile;
public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
@Value("${ibiz.filePath:/app/file/}")
private String descDir;
private String fileRoot;
private final String workflowFilename="PSWFVERSION.json.bpm";
@Autowired
private FileService fileService;
......@@ -50,54 +55,46 @@ public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
/**
* 解压缩zip,部署流程及逻辑
*
* @param et
*/
@SneakyThrows
public void publish(DynamicModelConfig et){
List<File> logics =new ArrayList<>();
List<Map<String,Object>> workflows = new ArrayList<>();
public void publish(DynamicModelConfig et) {
String strModelFile = et.getModelfile();
if(StringUtils.isEmpty(strModelFile))
if (StringUtils.isEmpty(strModelFile))
return;
List<FileItem> items= JSONArray.parseArray(strModelFile,FileItem.class);
if(items.size()==0 || "1".equalsIgnoreCase(et.getStatus()))
List<FileItem> items = JSONArray.parseArray(strModelFile, FileItem.class);
if (items.size() == 0 || StaticDict.DynamicModelStatus.ITEM_1.getValue().equalsIgnoreCase(et.getStatus()))
return;
String fileName ="";
for(FileItem item:items)
{
File modelFile=fileService.getFile(item.getId());
if(!modelFile.exists())
String fileName = "";
String modelName = "";
List<Map<String, Object>> workflow = new ArrayList<>();
for (FileItem item : items) {
File modelFile = fileService.getFile(item.getId());
if (!modelFile.exists())
return;
//1.解压缩
File pathFile = new File(descDir);
if(!pathFile.exists())
{
File pathFile = new File(fileRoot);
if (!pathFile.exists()) {
pathFile.mkdirs();
}
String rootfile ="";
//解决zip文件中有中文目录或者中文文件
ZipFile zip = new ZipFile(modelFile, Charset.forName("GBK"));
fileName=item.getName();
for(Enumeration entries = zip.entries(); entries.hasMoreElements();)
{
ZipEntry entry = (ZipEntry)entries.nextElement();
fileName = item.getName();
for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String zipEntryName = entry.getName();
InputStream in = zip.getInputStream(entry);
if(StringUtils.isEmpty(rootfile)){
rootfile=zipEntryName;
if (StringUtils.isEmpty(modelName)) {
modelName = zipEntryName;
}
String outPath = (descDir+zipEntryName).replaceAll("\\*", "/").replaceFirst(rootfile,"dynamicmodel/");
String outPath = (fileRoot + zipEntryName).replaceAll("\\*", "/").replaceFirst(modelName, "dynamicmodel/");
//判断路径是否存在,不存在则创建文件路径
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
if(!file.exists())
{
if (!file.exists()) {
file.mkdirs();
}
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if(new File(outPath).isDirectory())
{
if (new File(outPath).isDirectory()) {
continue;
}
//输出文件路径信息
......@@ -105,26 +102,24 @@ public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
OutputStream out = new FileOutputStream(outPath);
byte[] bytes = new byte[1024];
int len;
while((len=in.read(bytes))>0)
{
out.write(bytes,0,len);
while ((len = in.read(bytes)) > 0) {
out.write(bytes, 0, len);
}
in.close();
out.close();
if(outPath.endsWith("PSWFVERSION.json.bpm")){
File tempFile = new File(outPath);
workflows.add(new HashMap<String, Object>() {{
put(tempFile.getName(), new String(bytes));
if (outPath.endsWith(workflowFilename)) {
File bpmn = new File(outPath);
workflow.add(new HashMap<String, Object>() {{
put(bpmn.getName(), IOUtils.toString(zip.getInputStream(entry)));
}});
}
in.close();
out.close();
}
}
// //部署流程
// if(workflows.size()>0){
// wfClient.deployBpmnFile(workflows);
// }
et.setStatus("1");
//部署流程
if (workflow.size() > 0) {
wfClient.deployBpmnFile(workflow);
}
et.setStatus(StaticDict.DynamicModelStatus.ITEM_1.getValue());
et.setConfigname(fileName);
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册