Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdisk
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdisk
提交
6b203ae1
提交
6b203ae1
编写于
3月 17, 2021
作者:
tangyaolong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
迁移lite代码
上级
c0260653
变更
1
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
61 行增加
和
22 行删除
+61
-22
MetaDynamicModelExService.java
...ab/core/extensions/service/MetaDynamicModelExService.java
+61
-22
未找到文件。
ibzdisk-core/src/main/java/cn/ibizlab/core/extensions/service/MetaDynamicModelExService.java
浏览文件 @
6b203ae1
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.impl.MetaDynamicModelServiceImpl
;
import
cn.ibizlab.core.disk.service.impl.MetaDynamicModelServiceImpl
;
import
cn.ibizlab.util.cache.listener.RedisPublisher
;
import
cn.ibizlab.util.cache.listener.RedisPublisher
;
import
cn.ibizlab.util.client.IBZWFFeignClient
;
import
cn.ibizlab.util.client.IBZWFFeignClient
;
...
@@ -8,6 +10,7 @@ import cn.ibizlab.util.dict.StaticDict;
...
@@ -8,6 +10,7 @@ import cn.ibizlab.util.dict.StaticDict;
import
cn.ibizlab.util.domain.FileItem
;
import
cn.ibizlab.util.domain.FileItem
;
import
cn.ibizlab.util.enums.RedisChannelTopic
;
import
cn.ibizlab.util.enums.RedisChannelTopic
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.InternalServerErrorException
;
import
cn.ibizlab.util.helper.FileHelper
;
import
cn.ibizlab.util.helper.FileHelper
;
import
cn.ibizlab.util.service.FileService
;
import
cn.ibizlab.util.service.FileService
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
...
@@ -22,13 +25,11 @@ import org.springframework.context.annotation.Lazy;
...
@@ -22,13 +25,11 @@ import org.springframework.context.annotation.Lazy;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.File
;
import
java.io.*
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -51,13 +52,20 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
...
@@ -51,13 +52,20 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
private
String
fileRoot
;
private
String
fileRoot
;
@Autowired
@Autowired
@Lazy
private
FileService
fileService
;
private
FileService
fileService
;
@Autowired
DiskCoreService
diskCoreService
;
@Autowired
private
IMetaDynamicModelService
dynamicModelService
;
@Autowired
@Autowired
@Lazy
@Lazy
private
IBZWFFeignClient
wfClient
;
private
IBZWFFeignClient
wfClient
;
@Value
(
"${ibiz.dynamic.publishpath:/app/file/dynamicModel/publicpath}"
)
@Value
(
"${ibiz.dynamic.publishpath:
d:
/app/file/dynamicModel/publicpath}"
)
private
String
publishPath
;
private
String
publishPath
;
@Autowired
@Autowired
...
@@ -66,8 +74,15 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
...
@@ -66,8 +74,15 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
@Override
@Override
public
boolean
create
(
MetaDynamicModel
et
)
{
public
boolean
create
(
MetaDynamicModel
et
)
{
unzip
(
et
);
et
.
setConfigid
((
String
)
et
.
getDefaultKey
(
true
));
return
super
.
create
(
et
);
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 {
...
@@ -75,8 +90,11 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
*
*
* @param et
* @param et
*/
*/
private
void
unzip
(
MetaDynamicModel
et
)
{
private
boolean
unzip
(
MetaDynamicModel
et
)
{
try
{
try
{
File
modelFile
=
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"
);
...
@@ -85,19 +103,41 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
...
@@ -85,19 +103,41 @@ 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
modelFile
=
fileService
.
getFile
(
items
.
get
(
0
).
getId
());
File
parent
=
diskCoreService
.
getFile
(
items
.
get
(
0
).
getId
());
JSONObject
system
=
null
;
if
(
parent
.
exists
())
{
modelFile
=
parent
;
}
else
{
throw
new
InternalServerErrorException
(
"文件未找到"
);
}
String
unzipPath
=
modelFile
.
getParent
().
replace
(
"ibizutil"
,
"dynamicmodel"
);
String
unzipPath
=
modelFile
.
getParent
().
replace
(
"ibizutil"
,
"dynamicmodel"
);
if
(
".
gz"
.
equals
(
modelFile
.
getName
().
substring
(
modelFile
.
getName
().
lastI
ndexOf
(
"."
)))){
if
(
".
tar.gz"
.
equals
(
modelFile
.
getName
().
substring
(
modelFile
.
getName
().
i
ndexOf
(
"."
)))){
FileHelper
.
unTarGz
(
modelFile
,
unzipPath
,
true
);
FileHelper
.
unTarGz
(
modelFile
,
unzipPath
,
true
);
system
=
getSystem
(
unzipPath
);
system
=
getSystem
(
unzipPath
);
}
else
if
(
".zip"
.
equals
(
modelFile
.
getName
().
substring
(
modelFile
.
getName
().
lastIndexOf
(
"."
)))){
}
else
if
(
".zip"
.
equals
(
modelFile
.
getName
().
substring
(
modelFile
.
getName
().
lastIndexOf
(
"."
)))){
FileHelper
.
unzip
(
modelFile
,
unzipPath
,
true
);
FileHelper
.
unzip
(
modelFile
,
unzipPath
,
true
);
system
=
getSystem
(
unzipPath
);
system
=
getSystem
(
unzipPath
);
}
else
{
throw
new
BadRequestAlertException
(
"文件后缀名异常,请以zip或tar.gz作为后缀名"
,
"MetaDynamicModel"
,
"unzip"
);
}
}
et
.
setDynainstid
(
system
.
getString
(
"getPSDynaInstId"
));
et
.
setDynainstid
(
system
.
getString
(
"getPSDynaInstId"
));
et
.
setSystemId
(
system
.
getString
(
"name"
));
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
)
{
}
catch
(
IOException
e
)
{
throw
new
BadRequestAlertException
(
"解析动态模型文件失败,"
+
e
,
"MetaDynamicModel"
,
"unzip"
);
throw
new
BadRequestAlertException
(
"解析动态模型文件失败,"
+
e
,
"MetaDynamicModel"
,
"unzip"
);
}
}
...
@@ -113,20 +153,19 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
...
@@ -113,20 +153,19 @@ 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"
);
}
List
<
FileItem
>
items
=
JSONArray
.
parseArray
(
strModelFile
,
FileItem
.
class
);
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"
);
throw
new
BadRequestAlertException
(
String
.
format
(
"模型解析失败,[%s]模型文件过多"
,
et
.
getConfigid
()),
"MetaDynamicModel"
,
"unzip"
);
}
File
publishFile
=
new
File
(
getPublishPath
()
+
systemId
+
File
.
separator
+
et
.
getDynainstid
());
File
publishFile
=
new
File
(
getPublishPath
()
+
systemId
+
File
.
separator
+
et
.
getDynainstid
());
//删除发布目录中的历史文件
//删除发布目录中的历史文件
if
(
publishFile
.
exists
())
{
if
(
publishFile
.
exists
())
{
FileHelper
.
deleteDir
(
publishFile
.
getPath
());
FileHelper
.
deleteDir
(
publishFile
.
getPath
());
}
}
File
modelFile
=
fil
eService
.
getFile
(
items
.
get
(
0
).
getId
());
File
modelFile
=
diskCor
eService
.
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
);
//拷贝文件到发布目录
//拷贝文件到发布目录
...
@@ -138,7 +177,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
...
@@ -138,7 +177,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
List
<
Map
<
String
,
Object
>>
workflow
=
searchWorkFlow
(
publishFile
.
getPath
());
List
<
Map
<
String
,
Object
>>
workflow
=
searchWorkFlow
(
publishFile
.
getPath
());
//部署流程
//部署流程
if
(
workflow
.
size
()
>
0
)
{
if
(
workflow
.
size
()
>
0
)
{
wfClient
.
deploy
BpmnFile
(
workflow
);
wfClient
.
deploy
DynaWF
(
workflow
,
et
.
getDynainstid
()
);
}
}
//发送redis广播
//发送redis广播
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
Map
<
String
,
Object
>
message
=
new
HashMap
<>();
...
@@ -146,9 +185,9 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
...
@@ -146,9 +185,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
));
update
(
Wrappers
.<
MetaDynamicModel
>
lambdaUpdate
().
set
(
MetaDynamicModel:
:
getStatus
,
StaticDict
.
DynamicModelStatus
.
ITEM_0
.
getValue
()).
eq
(
MetaDynamicModel:
:
getSystemId
,
systemId
)
.
eq
(
MetaDynamicModel:
:
getDynainstid
,
dynamicId
)
);
update
(
et
);
update
(
et
);
return
et
;
return
et
;
}
}
...
@@ -277,7 +316,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
...
@@ -277,7 +316,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
* @param filePath
* @param filePath
* @return
* @return
*/
*/
private
JSONObject
getSystem
(
String
filePath
)
{
private
JSONObject
getSystem
(
String
filePath
)
throws
UnsupportedEncodingException
{
JSONObject
system
=
null
;
JSONObject
system
=
null
;
InputStream
in
=
null
;
InputStream
in
=
null
;
byte
[]
bytes
=
null
;
byte
[]
bytes
=
null
;
...
@@ -299,7 +338,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
...
@@ -299,7 +338,7 @@ public class MetaDynamicModelExService extends MetaDynamicModelServiceImpl {
}
}
}
}
if
(
bytes
!=
null
)
{
if
(
bytes
!=
null
)
{
String
strSystem
=
new
String
(
bytes
);
String
strSystem
=
new
String
(
bytes
,
"utf8"
);
if
(!
StringUtils
.
isEmpty
(
strSystem
))
{
if
(!
StringUtils
.
isEmpty
(
strSystem
))
{
system
=
JSONObject
.
parseObject
(
strSystem
);
system
=
JSONObject
.
parseObject
(
strSystem
);
}
}
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录