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

迁移lite代码

上级 75a7cdc9
package cn.ibizlab.core.extensions.service; package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.disk.domain.MetaDynamicModel; 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.IMetaDynamicModelService;
import cn.ibizlab.core.disk.service.impl.MetaDynamicModelServiceImpl; import cn.ibizlab.core.disk.service.impl.MetaDynamicModelServiceImpl;
import cn.ibizlab.util.cache.listener.RedisPublisher; import cn.ibizlab.util.cache.listener.RedisPublisher;
...@@ -43,6 +42,8 @@ import java.util.Map; ...@@ -43,6 +42,8 @@ import java.util.Map;
@Service("MetaDynamicModelExService") @Service("MetaDynamicModelExService")
public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
private static final String wf_regex="\\w+WFv\\d+.json.bpmn";
@Override @Override
protected Class currentModelClass() { protected Class currentModelClass() {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1); return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
...@@ -52,12 +53,8 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -52,12 +53,8 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
private String fileRoot; private String fileRoot;
@Autowired @Autowired
@Lazy
private FileService fileService; private FileService fileService;
@Autowired
DiskCoreService diskCoreService;
@Autowired @Autowired
private IMetaDynamicModelService dynamicModelService; private IMetaDynamicModelService dynamicModelService;
...@@ -65,7 +62,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -65,7 +62,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
@Lazy @Lazy
private IBZWFFeignClient wfClient; private IBZWFFeignClient wfClient;
@Value("${ibiz.dynamic.publishpath:d:/app/file/dynamicModel/publicpath}") @Value("${ibiz.dynamic.publishpath:/app/file/dynamicModel/publicpath}")
private String publishPath; private String publishPath;
@Autowired @Autowired
...@@ -75,14 +72,18 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -75,14 +72,18 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
@Override @Override
public boolean create(MetaDynamicModel et) { public boolean create(MetaDynamicModel et) {
et.setConfigid((String)et.getDefaultKey(true)); et.setConfigid((String)et.getDefaultKey(true));
super.create(et); JSONObject system = unzip(et);
return unzip(et); boolean result = super.create(et);
createSubDynaInst(et,system);
return result;
} }
@Override @Override
public boolean update(MetaDynamicModel et) { public boolean update(MetaDynamicModel et) {
super.update(et); JSONObject system = unzip(et);
return unzip(et); boolean result = super.update(et);
createSubDynaInst(et,system);
return result;
} }
/** /**
...@@ -90,11 +91,10 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -90,11 +91,10 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
* *
* @param et * @param et
*/ */
private boolean unzip(MetaDynamicModel et) { private JSONObject unzip(MetaDynamicModel et) {
try { try {
File modelFile = null; File modelFile = null;
JSONObject system = null; JSONObject system = null;
String strModelFile = et.getModelfile(); String strModelFile = et.getModelfile();
if (StringUtils.isEmpty(strModelFile)){ if (StringUtils.isEmpty(strModelFile)){
throw new BadRequestAlertException("模型文件为空", "MetaDynamicModel", "unzip"); throw new BadRequestAlertException("模型文件为空", "MetaDynamicModel", "unzip");
...@@ -103,9 +103,10 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -103,9 +103,10 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (!ObjectUtils.isEmpty(items) && items.size() > 1) { if (!ObjectUtils.isEmpty(items) && items.size() > 1) {
throw new BadRequestAlertException("单次只允许上传一个模型文件", "MetaDynamicModel", "unzip"); throw new BadRequestAlertException("单次只允许上传一个模型文件", "MetaDynamicModel", "unzip");
} }
File parent = diskCoreService.getFile(items.get(0).getId()); String dirPath = this.fileRoot + "ibizutil" + File.separator + items.get(0).getId();
if (parent.exists()) { File parent = new File(dirPath);
modelFile = parent; if (parent.exists() && parent.isDirectory() && parent.listFiles().length > 0) {
modelFile = new File(FileHelper.getLatestFilePath(parent.listFiles()));
} else { } else {
throw new InternalServerErrorException("文件未找到"); throw new InternalServerErrorException("文件未找到");
} }
...@@ -119,8 +120,28 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -119,8 +120,28 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
}else{ }else{
throw new BadRequestAlertException("文件后缀名异常,请以zip或tar.gz作为后缀名", "MetaDynamicModel", "unzip"); throw new BadRequestAlertException("文件后缀名异常,请以zip或tar.gz作为后缀名", "MetaDynamicModel", "unzip");
} }
et.setDynainstid(system.getString("getPSDynaInstId")); if(!ObjectUtils.isEmpty(system)) {
et.setSystemId(system.getString("name")); 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"); JSONArray array = system.getJSONArray("getPSDynaInsts");
List<MetaDynamicModel> metaDynamicModels = new ArrayList<>(); List<MetaDynamicModel> metaDynamicModels = new ArrayList<>();
if(!ObjectUtils.isEmpty(array)){ if(!ObjectUtils.isEmpty(array)){
...@@ -137,9 +158,6 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -137,9 +158,6 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
} }
dynamicModelService.saveOrUpdateBatch(metaDynamicModels); dynamicModelService.saveOrUpdateBatch(metaDynamicModels);
} }
return true;
} catch (IOException e) {
throw new BadRequestAlertException("解析动态模型文件失败," + e, "MetaDynamicModel", "unzip");
} }
} }
...@@ -153,7 +171,6 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -153,7 +171,6 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
public MetaDynamicModel publish(MetaDynamicModel et) { public MetaDynamicModel publish(MetaDynamicModel et) {
et = get(et.getConfigid()); et = get(et.getConfigid());
String systemId = et.getSystemId(); String systemId = et.getSystemId();
String dynamicId = et.getDynainstid();
String strModelFile = et.getModelfile(); 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"); throw new BadRequestAlertException(String.format("信息不足,请检查[%s]模型数据是否存在系统标识及模型文件", et.getConfigid()), "MetaDynamicModel", "unzip");
...@@ -165,7 +182,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -165,7 +182,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (publishFile.exists()) { if (publishFile.exists()) {
FileHelper.deleteDir(publishFile.getPath()); 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"); String unzipPath = modelFile.getParent().replace("ibizutil", "dynamicmodel");
File unzipFile = new File(unzipPath); File unzipFile = new File(unzipPath);
//拷贝文件到发布目录 //拷贝文件到发布目录
...@@ -185,9 +202,9 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -185,9 +202,9 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
message.put("dynamicModel", et.getConfigname()); message.put("dynamicModel", et.getConfigname());
RedisPublisher redisPublisher = new RedisPublisher(redisOperations, RedisChannelTopic.REDIS_CACHE_DYNAMICMODEL_TOPIC.getChannelTopic()); RedisPublisher redisPublisher = new RedisPublisher(redisOperations, RedisChannelTopic.REDIS_CACHE_DYNAMICMODEL_TOPIC.getChannelTopic());
redisPublisher.publisher(message); redisPublisher.publisher(message);
//激活当前et //激活当前et.
et.setStatus(StaticDict.DynamicModelStatus.ITEM_1.getValue()); 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); update(et);
return et; return et;
} }
...@@ -218,7 +235,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -218,7 +235,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
List<Map<String, Object>> models = new ArrayList<>(); List<Map<String, Object>> models = new ArrayList<>();
File publish = new File(path); File publish = new File(path);
if (!publish.exists()) { 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(); File[] subFiles = publish.listFiles();
if (null != subFiles) { if (null != subFiles) {
...@@ -228,7 +245,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -228,7 +245,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (!ObjectUtils.isEmpty(subModels)) { if (!ObjectUtils.isEmpty(subModels)) {
models.addAll(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; InputStream file = null;
try { try {
file = new FileInputStream(subFile); file = new FileInputStream(subFile);
...@@ -262,7 +279,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -262,7 +279,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
List<Map<String, Object>> models = new ArrayList<>(); List<Map<String, Object>> models = new ArrayList<>();
File publish = new File(pubPath); File publish = new File(pubPath);
if (!publish.exists()) { 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(); File[] subFiles = publish.listFiles();
if (null != subFiles) { if (null != subFiles) {
...@@ -272,7 +289,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -272,7 +289,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
if (!ObjectUtils.isEmpty(subModels)) { if (!ObjectUtils.isEmpty(subModels)) {
models.addAll(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; InputStream file = null;
try { try {
file = new FileInputStream(subFile); file = new FileInputStream(subFile);
...@@ -323,7 +340,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl { ...@@ -323,7 +340,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
try { try {
File file = new File(filePath + File.separator + "PSSYSTEM.json"); File file = new File(filePath + File.separator + "PSSYSTEM.json");
if (!file.exists()) { 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); in = new FileInputStream(file);
bytes = new byte[in.available()]; bytes = new byte[in.available()];
......
...@@ -26,4 +26,9 @@ public class IBZWFFallback implements IBZWFFeignClient { ...@@ -26,4 +26,9 @@ public class IBZWFFallback implements IBZWFFeignClient {
public JSONObject wfstart(String system, String appname, String entity, String businessKey, JSONObject instance) { public JSONObject wfstart(String system, String appname, String entity, String businessKey, JSONObject instance) {
return null; return null;
} }
@Override
public Boolean deployDynaWF(List<Map<String, Object>> bpmnfiles, String dynainstid) {
return null;
}
} }
...@@ -24,4 +24,9 @@ public interface IBZWFFeignClient ...@@ -24,4 +24,9 @@ public interface IBZWFFeignClient
JSONObject wfstart(@PathVariable("system") String system, @PathVariable("appname") String appname, JSONObject wfstart(@PathVariable("system") String system, @PathVariable("appname") String appname,
@PathVariable("entity") String entity, @PathVariable("entity") String entity,
@PathVariable("businessKey") String businessKey, @RequestBody JSONObject instance); @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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册