提交 6b203ae1 编写于 作者: tangyaolong's avatar tangyaolong

迁移lite代码

上级 c0260653
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;
import cn.ibizlab.util.client.IBZWFFeignClient;
......@@ -8,6 +10,7 @@ import cn.ibizlab.util.dict.StaticDict;
import cn.ibizlab.util.domain.FileItem;
import cn.ibizlab.util.enums.RedisChannelTopic;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.errors.InternalServerErrorException;
import cn.ibizlab.util.helper.FileHelper;
import cn.ibizlab.util.service.FileService;
import com.alibaba.fastjson.JSONArray;
......@@ -22,13 +25,11 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -51,13 +52,20 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
private String fileRoot;
@Autowired
@Lazy
private FileService fileService;
@Autowired
DiskCoreService diskCoreService;
@Autowired
private IMetaDynamicModelService dynamicModelService;
@Autowired
@Lazy
private IBZWFFeignClient wfClient;
@Value("${ibiz.dynamic.publishpath:/app/file/dynamicModel/publicpath}")
@Value("${ibiz.dynamic.publishpath:d:/app/file/dynamicModel/publicpath}")
private String publishPath;
@Autowired
......@@ -66,8 +74,15 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
@Override
public boolean create(MetaDynamicModel et) {
unzip(et);
return super.create(et);
et.setConfigid((String)et.getDefaultKey(true));
super.create(et);
return unzip(et);
}
@Override
public boolean update(MetaDynamicModel et) {
super.update(et);
return unzip(et);
}
/**
......@@ -75,8 +90,11 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
*
* @param et
*/
private void unzip(MetaDynamicModel et) {
private boolean unzip(MetaDynamicModel et) {
try {
File modelFile = null;
JSONObject system = null;
String strModelFile = et.getModelfile();
if (StringUtils.isEmpty(strModelFile)){
throw new BadRequestAlertException("模型文件为空", "MetaDynamicModel", "unzip");
......@@ -85,19 +103,41 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (!ObjectUtils.isEmpty(items) && items.size() > 1) {
throw new BadRequestAlertException("单次只允许上传一个模型文件", "MetaDynamicModel", "unzip");
}
File modelFile = fileService.getFile(items.get(0).getId());
JSONObject system = null;
File parent = diskCoreService.getFile(items.get(0).getId());
if (parent.exists()) {
modelFile = parent;
} else {
throw new InternalServerErrorException("文件未找到");
}
String unzipPath = modelFile.getParent().replace("ibizutil", "dynamicmodel");
if(".gz".equals(modelFile.getName().substring(modelFile.getName().lastIndexOf(".")))){
if(".tar.gz".equals(modelFile.getName().substring(modelFile.getName().indexOf(".")))){
FileHelper.unTarGz(modelFile, unzipPath, true);
system = getSystem(unzipPath);
}else if(".zip".equals(modelFile.getName().substring(modelFile.getName().lastIndexOf(".")))){
FileHelper.unzip(modelFile, unzipPath, true);
system = getSystem(unzipPath);
}else{
throw new BadRequestAlertException("文件后缀名异常,请以zip或tar.gz作为后缀名", "MetaDynamicModel", "unzip");
}
et.setDynainstid(system.getString("getPSDynaInstId"));
et.setSystemId(system.getString("name"));
JSONArray array = system.getJSONArray("getPSDynaInsts");
List<MetaDynamicModel> metaDynamicModels = new ArrayList<>();
if(!ObjectUtils.isEmpty(array)){
for(int i = 0; i < array.size(); i++) {
MetaDynamicModel model = new MetaDynamicModel();
JSONObject obj = array.getJSONObject(i);
model.setConfigname(obj.get("name").toString());
model.setDynainstid(obj.get("id").toString());
model.setConfigid(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,et.getSystemId(),obj.get("id").toString()).getBytes()));
model.setStatus("0");
model.setPdynainstid(et.getConfigid());
model.setSystemId(et.getSystemId());
metaDynamicModels.add(model);
}
dynamicModelService.saveOrUpdateBatch(metaDynamicModels);
}
return true;
} catch (IOException e) {
throw new BadRequestAlertException("解析动态模型文件失败," + e, "MetaDynamicModel", "unzip");
}
......@@ -113,20 +153,19 @@ 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())){
if (StringUtils.isEmpty(strModelFile) && StringUtils.isEmpty(et.getSystemId()))
throw new BadRequestAlertException(String.format("信息不足,请检查[%s]模型数据是否存在系统标识及模型文件", et.getConfigid()), "MetaDynamicModel", "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(String.format("模型解析失败,[%s]模型文件过多", et.getConfigid()), "MetaDynamicModel", "unzip");
}
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());
File modelFile = diskCoreService.getFile(items.get(0).getId());
String unzipPath = modelFile.getParent().replace("ibizutil", "dynamicmodel");
File unzipFile = new File(unzipPath);
//拷贝文件到发布目录
......@@ -138,7 +177,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
List<Map<String, Object>> workflow = searchWorkFlow(publishFile.getPath());
//部署流程
if (workflow.size() > 0) {
wfClient.deployBpmnFile(workflow);
wfClient.deployDynaWF(workflow,et.getDynainstid());
}
//发送redis广播
Map<String, Object> message = new HashMap<>();
......@@ -146,9 +185,9 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
message.put("dynamicModel", et.getConfigname());
RedisPublisher redisPublisher = new RedisPublisher(redisOperations, RedisChannelTopic.REDIS_CACHE_DYNAMICMODEL_TOPIC.getChannelTopic());
redisPublisher.publisher(message);
//激活当前et.
//激活当前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;
}
......@@ -277,7 +316,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
* @param filePath
* @return
*/
private JSONObject getSystem(String filePath) {
private JSONObject getSystem(String filePath) throws UnsupportedEncodingException {
JSONObject system = null;
InputStream in = null;
byte[] bytes = null;
......@@ -299,7 +338,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
}
}
if (bytes != null) {
String strSystem = new String(bytes);
String strSystem = new String(bytes,"utf8");
if (!StringUtils.isEmpty(strSystem)) {
system = JSONObject.parseObject(strSystem);
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册