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

模型解析

上级 caa28ab2
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.domain.FileItem;
import cn.ibizlab.util.service.FileService;
import com.alibaba.fastjson.JSONArray;
import lombok.SneakyThrows;
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;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@Service
@Primary
public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
@Value("${ibiz.filePath:D:/app/file/}")
private String descDir;
@Autowired
private FileService fileService;
@Autowired
@Lazy
private IBZWFFeignClient wfClient;
List<File> logics =new ArrayList<>();
List<Map<String,Object>> workflows = new ArrayList<>();
@Override
public boolean create(DynamicModelConfig et) {
publish(et);
return super.create(et);
}
@Override
public boolean update(DynamicModelConfig et) {
publish(et);
return super.update(et);
}
/**
* 解压缩zip,部署流程及逻辑
* @param et
*/
@SneakyThrows
public void publish(DynamicModelConfig et){
String strModelFile = et.getModelfile();
if(StringUtils.isEmpty(strModelFile))
return;
List<FileItem> items= JSONArray.parseArray(strModelFile,FileItem.class);
if(items.size()==0 || "1".equalsIgnoreCase(et.getStatus()))
return;
String fileName ="";
for(FileItem item:items)
{
File modelFile=fileService.getFile(item.getId());
if(!modelFile.exists())
return;
//1.解压缩
File pathFile = new File(descDir);
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();
String zipEntryName = entry.getName();
InputStream in = zip.getInputStream(entry);
if(StringUtils.isEmpty(rootfile)){
rootfile=zipEntryName;
}
String outPath = (descDir+zipEntryName).replaceAll("\\*", "/").replaceFirst(rootfile,"dynamicmodel/");
//判断路径是否存在,不存在则创建文件路径
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
if(!file.exists())
{
file.mkdirs();
}
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if(new File(outPath).isDirectory())
{
continue;
}
//输出文件路径信息
System.out.println(outPath);
OutputStream out = new FileOutputStream(outPath);
byte[] bytes = new byte[1024];
int 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(workflows.size()>0){
// wfClient.deployBpmnFile(workflows);
// }
et.setStatus("1");
et.setConfigname(fileName);
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册