提交 74aac998 编写于 作者: tangyaolong's avatar tangyaolong

迁移lite代码

上级 75a7cdc9
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;
......@@ -43,6 +42,8 @@ import java.util.Map;
@Service("MetaDynamicModelExService")
public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
private static final String wf_regex="\\w+WFv\\d+.json.bpmn";
@Override
protected Class currentModelClass() {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
......@@ -52,12 +53,8 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
private String fileRoot;
@Autowired
@Lazy
private FileService fileService;
@Autowired
DiskCoreService diskCoreService;
@Autowired
private IMetaDynamicModelService dynamicModelService;
......@@ -65,7 +62,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
@Lazy
private IBZWFFeignClient wfClient;
@Value("${ibiz.dynamic.publishpath:d:/app/file/dynamicModel/publicpath}")
@Value("${ibiz.dynamic.publishpath:/app/file/dynamicModel/publicpath}")
private String publishPath;
@Autowired
......@@ -75,14 +72,18 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
@Override
public boolean create(MetaDynamicModel et) {
et.setConfigid((String)et.getDefaultKey(true));
super.create(et);
return unzip(et);
JSONObject system = unzip(et);
boolean result = super.create(et);
createSubDynaInst(et,system);
return result;
}
@Override
public boolean update(MetaDynamicModel et) {
super.update(et);
return unzip(et);
JSONObject system = unzip(et);
boolean result = super.update(et);
createSubDynaInst(et,system);
return result;
}
/**
......@@ -90,11 +91,10 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
*
* @param et
*/
private boolean unzip(MetaDynamicModel et) {
private JSONObject unzip(MetaDynamicModel et) {
try {
File modelFile = null;
JSONObject system = null;
String strModelFile = et.getModelfile();
if (StringUtils.isEmpty(strModelFile)){
throw new BadRequestAlertException("模型文件为空", "MetaDynamicModel", "unzip");
......@@ -103,9 +103,10 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (!ObjectUtils.isEmpty(items) && items.size() > 1) {
throw new BadRequestAlertException("单次只允许上传一个模型文件", "MetaDynamicModel", "unzip");
}
File parent = diskCoreService.getFile(items.get(0).getId());
if (parent.exists()) {
modelFile = parent;
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()));
} else {
throw new InternalServerErrorException("文件未找到");
}
......@@ -119,8 +120,28 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
}else{
throw new BadRequestAlertException("文件后缀名异常,请以zip或tar.gz作为后缀名", "MetaDynamicModel", "unzip");
}
et.setDynainstid(system.getString("getPSDynaInstId"));
et.setSystemId(system.getString("name"));
if(!ObjectUtils.isEmpty(system)) {
String dynainst = system.getString("getPSDynaInstId");
String sysid = system.getString("name");
if(!StringUtils.isEmpty(dynainst))
et.setDynainstid(dynainst);
if(!StringUtils.isEmpty(sysid))
et.setSystemId(sysid);
}
return system;
} catch (IOException e) {
throw new BadRequestAlertException("解析动态模型文件失败," + e, "MetaDynamicModel", "unzip");
}
}
/**
* 创建副本实例
* @param et
* @param system
* @return
*/
private void createSubDynaInst(MetaDynamicModel et,JSONObject system){
if(!ObjectUtils.isEmpty(system)){
JSONArray array = system.getJSONArray("getPSDynaInsts");
List<MetaDynamicModel> metaDynamicModels = new ArrayList<>();
if(!ObjectUtils.isEmpty(array)){
......@@ -137,9 +158,6 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
}
dynamicModelService.saveOrUpdateBatch(metaDynamicModels);
}
return true;
} catch (IOException e) {
throw new BadRequestAlertException("解析动态模型文件失败," + e, "MetaDynamicModel", "unzip");
}
}
......@@ -153,7 +171,6 @@ 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");
......@@ -165,7 +182,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (publishFile.exists()) {
FileHelper.deleteDir(publishFile.getPath());
}
File modelFile = diskCoreService.getFile(items.get(0).getId());
File modelFile = fileService.getFile(items.get(0).getId());
String unzipPath = modelFile.getParent().replace("ibizutil", "dynamicmodel");
File unzipFile = new File(unzipPath);
//拷贝文件到发布目录
......@@ -185,9 +202,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).eq(MetaDynamicModel::getDynainstid, dynamicId));
update(Wrappers.<MetaDynamicModel>lambdaUpdate().set(MetaDynamicModel::getStatus, StaticDict.DynamicModelStatus.ITEM_0.getValue()).eq(MetaDynamicModel::getSystemId, systemId));
update(et);
return et;
}
......@@ -218,7 +235,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
List<Map<String, Object>> models = new ArrayList<>();
File publish = new File(path);
if (!publish.exists()) {
throw new BadRequestAlertException(String.format("发布目录[%s]不存在", publish.getPath()), "MetaDynamicModel", "search");
throw new BadRequestAlertException(String.format("发布目录[%s]不存在", publish.getPath()), "MetaDynamicModel", "searchLogic");
}
File[] subFiles = publish.listFiles();
if (null != subFiles) {
......@@ -228,7 +245,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (!ObjectUtils.isEmpty(subModels)) {
models.addAll(subModels);
}
} else if (subFile.isFile() && (!subFile.getName().equalsIgnoreCase("PSWFVERSION.json.bpmn")) && (subFile.getName().endsWith(".bpmn") || subFile.getName().endsWith(".drl"))) {
} 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);
......@@ -262,7 +279,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
List<Map<String, Object>> models = new ArrayList<>();
File publish = new File(pubPath);
if (!publish.exists()) {
throw new BadRequestAlertException(String.format("发布目录[%s]不存在", publish.getPath()), "MetaDynamicModel", "search");
throw new BadRequestAlertException(String.format("发布目录[%s]不存在", publish.getPath()), "MetaDynamicModel", "searchWorkFlow");
}
File[] subFiles = publish.listFiles();
if (null != subFiles) {
......@@ -272,7 +289,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (!ObjectUtils.isEmpty(subModels)) {
models.addAll(subModels);
}
} else if (subFile.isFile() && (subFile.getName().equalsIgnoreCase("PSWFVERSION.json.bpmn"))) {
} else if (subFile.isFile() && (subFile.getName().matches(wf_regex))) {
InputStream file = null;
try {
file = new FileInputStream(subFile);
......@@ -323,7 +340,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
try {
File file = new File(filePath + File.separator + "PSSYSTEM.json");
if (!file.exists()) {
throw new BadRequestAlertException(String.format("无法找到动态系统模型文件[%s]", file.getPath()), "MetaDynamicModel", "getSystemId");
throw new BadRequestAlertException(String.format("无法找到动态系统模型文件[%s]", file.getPath()), "MetaDynamicModel", "getSystem");
}
in = new FileInputStream(file);
bytes = new byte[in.available()];
......
......@@ -26,4 +26,9 @@ public class IBZWFFallback implements IBZWFFeignClient {
public JSONObject wfstart(String system, String appname, String entity, String businessKey, JSONObject instance) {
return null;
}
@Override
public Boolean deployDynaWF(List<Map<String, Object>> bpmnfiles, String dynainstid) {
return null;
}
}
......@@ -24,4 +24,9 @@ public interface IBZWFFeignClient
JSONObject wfstart(@PathVariable("system") String system, @PathVariable("appname") String appname,
@PathVariable("entity") String entity,
@PathVariable("businessKey") String businessKey, @RequestBody JSONObject instance);
@RequestMapping(method = RequestMethod.POST, value = "/deploybpmn")
Boolean deployDynaWF(@RequestBody List<Map<String,Object>> bpmnfiles , @RequestHeader("dynainstid") String dynainstid);
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册