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

优化初始化模型逻辑

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