Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzlite
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzlite
提交
51a756ab
提交
51a756ab
编写于
3月 03, 2021
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
删除无效文件
上级
1569f483
变更
1
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
0 行增加
和
302 行删除
+0
-302
DynamicModelConfigExService.java
.../core/extensions/service/DynamicModelConfigExService.java
+0
-302
未找到文件。
ibzlite-core/src/main/java/cn/ibizlab/core/extensions/service/DynamicModelConfigExService.java
已删除
100644 → 0
浏览文件 @
1569f483
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.cache.listener.RedisPublisher
;
import
cn.ibizlab.util.client.IBZWFFeignClient
;
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.helper.FileHelper
;
import
cn.ibizlab.util.service.FileService
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
lombok.SneakyThrows
;
import
org.apache.commons.io.IOUtils
;
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.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
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.util.*
;
import
java.util.stream.Collectors
;
@Service
@Primary
public
class
DynamicModelConfigExService
extends
DynamicModelConfigServiceImpl
{
@Override
protected
Class
currentModelClass
()
{
return
com
.
baomidou
.
mybatisplus
.
core
.
toolkit
.
ReflectionKit
.
getSuperClassGenericType
(
this
.
getClass
().
getSuperclass
(),
1
);
}
@Value
(
"${ibiz.filePath:/app/file/}"
)
private
String
fileRoot
;
@Autowired
private
FileService
fileService
;
@Autowired
@Lazy
private
IBZWFFeignClient
wfClient
;
@Value
(
"${ibiz.dynamic.publishpath:/app/file/dynamicModel/publicpath}"
)
private
String
publishPath
;
@Autowired
@Lazy
RedisTemplate
<
String
,
Object
>
redisOperations
;
@Override
public
boolean
create
(
DynamicModelConfig
et
)
{
unzip
(
et
);
return
super
.
create
(
et
);
}
/**
* 将zip解压到file目录
*
* @param et
*/
private
void
unzip
(
DynamicModelConfig
et
)
{
try
{
String
strModelFile
=
et
.
getModelfile
();
if
(
StringUtils
.
isEmpty
(
strModelFile
))
throw
new
BadRequestAlertException
(
"模型文件为空"
,
"DynamicModelConfig"
,
"unzip"
);
List
<
FileItem
>
items
=
JSONArray
.
parseArray
(
strModelFile
,
FileItem
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
items
)
&&
items
.
size
()
>
1
)
{
throw
new
BadRequestAlertException
(
"单次只允许上传一个模型文件"
,
"DynamicModelConfig"
,
"unzip"
);
}
File
modelFile
=
fileService
.
getFile
(
items
.
get
(
0
).
getId
());
JSONObject
system
=
null
;
String
unzipPath
=
modelFile
.
getParent
().
replace
(
"ibizutil"
,
"dynamicmodel"
);
if
(
".gz"
.
equals
(
modelFile
.
getName
().
substring
(
modelFile
.
getName
().
lastIndexOf
(
"."
)))){
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
);
}
et
.
setDynainstid
(
system
.
getString
(
"getPSDynaInstId"
));
et
.
setSystemId
(
system
.
getString
(
"name"
));
}
catch
(
IOException
e
)
{
throw
new
BadRequestAlertException
(
"解析动态模型文件失败,"
+
e
,
"DynamicModelConfig"
,
"unzip"
);
}
}
/**
* 发布动态模型
*
* @param et
*/
@SneakyThrows
@Override
public
DynamicModelConfig
publish
(
DynamicModelConfig
et
)
{
et
=
get
(
et
.
getConfigid
());
String
systemId
=
et
.
getSystemId
();
String
strModelFile
=
et
.
getModelfile
();
if
(
StringUtils
.
isEmpty
(
strModelFile
)
&&
StringUtils
.
isEmpty
(
et
.
getSystemId
()))
throw
new
BadRequestAlertException
(
String
.
format
(
"信息不足,请检查[%s]模型数据是否存在系统标识及模型文件"
,
et
.
getConfigid
()),
"DynamicModelConfig"
,
"unzip"
);
List
<
FileItem
>
items
=
JSONArray
.
parseArray
(
strModelFile
,
FileItem
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
items
)
&&
items
.
size
()
>
1
)
throw
new
BadRequestAlertException
(
String
.
format
(
"模型解析失败,[%s]模型文件过多"
,
et
.
getConfigid
()),
"DynamicModelConfig"
,
"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
());
String
unzipPath
=
modelFile
.
getParent
().
replace
(
"ibizutil"
,
"dynamicmodel"
);
File
unzipFile
=
new
File
(
unzipPath
);
//拷贝文件到发布目录
FileHelper
.
copyFolder
(
unzipFile
.
getPath
(),
publishFile
.
getParent
());
File
dynamicFile
=
new
File
(
publishFile
.
getParent
()
+
File
.
separator
+
unzipFile
.
getName
());
if
(
dynamicFile
.
exists
())
{
dynamicFile
.
renameTo
(
publishFile
);
}
List
<
Map
<
String
,
Object
>>
workflow
=
searchWorkFlow
(
publishFile
.
getPath
());
//部署流程
if
(
workflow
.
size
()
>
0
)
{
wfClient
.
deployBpmnFile
(
workflow
);
}
//发送redis广播
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
message
.
put
(
"cacheName"
,
"dynamicModel"
);
message
.
put
(
"dynamicModel"
,
et
.
getConfigname
());
RedisPublisher
redisPublisher
=
new
RedisPublisher
(
redisOperations
,
RedisChannelTopic
.
REDIS_CACHE_DYNAMICMODEL_TOPIC
.
getChannelTopic
());
redisPublisher
.
publisher
(
message
);
//激活当前et.
et
.
setStatus
(
StaticDict
.
DynamicModelStatus
.
ITEM_1
.
getValue
());
update
(
Wrappers
.<
DynamicModelConfig
>
lambdaUpdate
().
set
(
DynamicModelConfig:
:
getStatus
,
StaticDict
.
DynamicModelStatus
.
ITEM_0
.
getValue
()).
eq
(
DynamicModelConfig:
:
getSystemId
,
systemId
));
update
(
et
);
return
et
;
}
/**
* 获取处理逻辑
*
* @param systemId
* @return
*/
@SneakyThrows
public
List
<
Map
<
String
,
Object
>>
getDynamicModel
(
String
systemId
)
{
String
pubPath
=
getPublishPath
()
+
systemId
;
List
<
Map
<
String
,
Object
>>
delogics
=
searchLogic
(
pubPath
);
if
(
ObjectUtils
.
isEmpty
(
delogics
))
{
throw
new
BadRequestAlertException
(
String
.
format
(
"在发布目录[%s]中没有找到系统[%s]动态模型文件"
,
pubPath
,
systemId
),
"DynamicModelConfig"
,
"getDynamicModel"
);
}
return
delogics
;
}
/**
* 从发布目录中查询 bpmn及drl
*
* @param path
* @return
*/
public
List
<
Map
<
String
,
Object
>>
searchLogic
(
String
path
)
{
List
<
Map
<
String
,
Object
>>
models
=
new
ArrayList
<>();
File
publish
=
new
File
(
path
);
if
(!
publish
.
exists
())
{
throw
new
BadRequestAlertException
(
String
.
format
(
"发布目录[%s]不存在"
,
publish
.
getPath
()),
"DynamicModelConfig"
,
"search"
);
}
File
[]
subFiles
=
publish
.
listFiles
();
if
(
null
!=
subFiles
)
{
for
(
File
subFile
:
subFiles
)
{
if
(
subFile
.
isDirectory
())
{
List
<
Map
<
String
,
Object
>>
subModels
=
searchLogic
(
subFile
.
getAbsolutePath
());
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"
)))
{
InputStream
file
=
null
;
try
{
file
=
new
FileInputStream
(
subFile
);
Map
fileMap
=
new
HashMap
();
fileMap
.
put
(
"filename"
,
subFile
.
getName
().
toLowerCase
());
fileMap
.
put
(
"filepath"
,
subFile
.
getPath
().
replace
(
getPublishPath
(),
""
).
toLowerCase
());
fileMap
.
put
(
"filecontent"
,
IOUtils
.
toString
(
file
,
"UTF-8"
));
models
.
add
(
fileMap
);
}
catch
(
IOException
e
)
{
}
finally
{
try
{
if
(
file
!=
null
)
{
file
.
close
();
}
}
catch
(
IOException
e
)
{
}
}
}
}
}
return
models
;
}
/**
* 从查询工作流 bpmn
*
* @param pubPath
* @return
*/
public
List
<
Map
<
String
,
Object
>>
searchWorkFlow
(
String
pubPath
)
{
List
<
Map
<
String
,
Object
>>
models
=
new
ArrayList
<>();
File
publish
=
new
File
(
pubPath
);
if
(!
publish
.
exists
())
{
throw
new
BadRequestAlertException
(
String
.
format
(
"发布目录[%s]不存在"
,
publish
.
getPath
()),
"DynamicModelConfig"
,
"search"
);
}
File
[]
subFiles
=
publish
.
listFiles
();
if
(
null
!=
subFiles
)
{
for
(
File
subFile
:
subFiles
)
{
if
(
subFile
.
isDirectory
())
{
List
<
Map
<
String
,
Object
>>
subModels
=
searchWorkFlow
(
subFile
.
getAbsolutePath
());
if
(!
ObjectUtils
.
isEmpty
(
subModels
))
{
models
.
addAll
(
subModels
);
}
}
else
if
(
subFile
.
isFile
()
&&
(
subFile
.
getName
().
equalsIgnoreCase
(
"PSWFVERSION.json.bpmn"
)))
{
InputStream
file
=
null
;
try
{
file
=
new
FileInputStream
(
subFile
);
Map
fileMap
=
new
HashMap
();
fileMap
.
put
(
subFile
.
getName
(),
IOUtils
.
toString
(
file
,
"UTF-8"
));
models
.
add
(
fileMap
);
}
catch
(
IOException
e
)
{
}
finally
{
try
{
if
(
file
!=
null
)
{
file
.
close
();
}
}
catch
(
IOException
e
)
{
}
}
}
}
}
return
models
;
}
/**
* 获取发布目录
*
* @return
*/
public
String
getPublishPath
()
{
if
(!
StringUtils
.
isEmpty
(
publishPath
))
{
publishPath
=
publishPath
.
replace
(
"\\\\"
,
File
.
separator
).
replace
(
"\\"
,
File
.
separator
).
replace
(
"/"
,
File
.
separator
);
if
(!
publishPath
.
endsWith
(
File
.
separator
))
{
publishPath
=
publishPath
+
File
.
separator
;
}
}
return
publishPath
;
}
/**
* 获取系统标识
*
* @param filePath
* @return
*/
private
JSONObject
getSystem
(
String
filePath
)
{
JSONObject
system
=
null
;
InputStream
in
=
null
;
byte
[]
bytes
=
null
;
try
{
File
file
=
new
File
(
filePath
+
File
.
separator
+
"PSSYSTEM.json"
);
if
(!
file
.
exists
())
{
throw
new
BadRequestAlertException
(
String
.
format
(
"无法找到动态系统模型文件[%s]"
,
file
.
getPath
()),
"DynamicModelConfig"
,
"getSystemId"
);
}
in
=
new
FileInputStream
(
file
);
bytes
=
new
byte
[
in
.
available
()];
in
.
read
(
bytes
);
}
catch
(
Exception
e
)
{
}
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
e
)
{
}
}
if
(
bytes
!=
null
)
{
String
strSystem
=
new
String
(
bytes
);
if
(!
StringUtils
.
isEmpty
(
strSystem
))
{
system
=
JSONObject
.
parseObject
(
strSystem
);
}
}
if
(
ObjectUtils
.
isEmpty
(
system
))
{
throw
new
BadRequestAlertException
(
"无法获取系统标识"
,
"DynamicModelConfig"
,
"getSystem"
);
}
return
system
;
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录