Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
s_guodong
gjjs-bd-common
Commits
ec73e535
Commit
ec73e535
authored
Sep 22, 2023
by
吴佳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加saveMdlData 和 loadMdlData 供模板保存时使用
parent
016979a6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
147 additions
and
4 deletions
+147
-4
MdaUtils.java
...in/java/com/brilliance/mda/runtime/mda/util/MdaUtils.java
+147
-4
No files found.
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/MdaUtils.java
View file @
ec73e535
...
...
@@ -26,16 +26,16 @@ import org.springframework.util.ClassUtils;
import
org.springframework.util.CollectionUtils
;
import
java.io.*
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.math.BigDecimal
;
import
java.net.InetAddress
;
import
java.net.URLEncoder
;
import
java.net.UnknownHostException
;
import
java.nio.charset.Charset
;
import
java.sql.Timestamp
;
import
java.text.DecimalFormat
;
import
java.text.Format
;
import
java.text.MessageFormat
;
import
java.text.SimpleDateFormat
;
import
java.text.*
;
import
java.util.*
;
import
java.util.concurrent.Semaphore
;
...
...
@@ -955,6 +955,65 @@ public class MdaUtils {
log
.
error
(
"模型序列化异常"
,
e
);
}
}
/**
* 模板数据保存
**/
public
static
void
saveMdlData
(
IModule
module
,
IStream
os
)
{
//在第一行写入module 名字
os
.
insertLine
(
0
,
module
.
getName
());
writeData
(
""
,
module
,
os
);
}
/**
* 递归保存模型中的叶子节点
**/
private
static
void
writeData
(
String
parentDir
,
IModule
module
,
IStream
os
)
{
String
thisDir
=
""
;
if
(
parentDir
.
length
()
!=
0
){
thisDir
=
parentDir
+
"/"
;
}
String
moduleName
=
module
.
getClass
().
getName
();
String
subDir
=
thisDir
+
module
.
getName
();
Class
moduleClass
=
module
.
getClass
();
Field
[]
fields
=
moduleClass
.
getDeclaredFields
();
String
fieldName
=
""
;
String
getMethodName
=
""
;
Object
fieldVal
=
null
;
Method
method
=
null
;
for
(
Field
field:
fields
){
fieldName
=
field
.
getName
();
if
(
fieldName
.
equalsIgnoreCase
(
"log"
)){
continue
;
}
getMethodName
=
"get"
+
fieldName
.
substring
(
0
,
1
).
toUpperCase
()
+
fieldName
.
substring
(
1
);
try
{
method
=
moduleClass
.
getDeclaredMethod
(
getMethodName
);
fieldVal
=
method
.
invoke
(
module
);
if
(!
MdaUtils
.
isEmpty
(
fieldVal
)
&&
!(
fieldVal
instanceof
IControl
))
{
//如果是IMODULE 属性 ,递归获取
if
(
fieldVal
instanceof
IModule
)
{
writeData
(
subDir
,
(
IModule
)
fieldVal
,
os
);
}
else
{
String
newFieldVal
=
""
;
if
(
field
.
getType
().
getName
().
equals
(
"java.util.Date"
)){
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
newFieldVal
=
simpleDateFormat
.
format
((
Date
)
fieldVal
);
}
else
{
newFieldVal
=
fieldVal
.
toString
();
}
String
line
=
subDir
+
"/"
+
fieldName
+
"="
+
newFieldVal
;
os
.
insertLine
(
0
,
line
);
}
}
}
catch
(
IllegalAccessException
e
)
{
log
.
error
(
"模型{}中执行方法{}时出错"
,
moduleName
,
getMethodName
);
}
catch
(
InvocationTargetException
e
)
{
log
.
error
(
"模型{}中执行方法{}时出错"
,
moduleName
,
getMethodName
);
}
catch
(
NoSuchMethodException
e
)
{
log
.
error
(
"方法{}未找到"
,
getMethodName
);
}
}
}
public
static
String
getCodetableLabel
(
String
codetable
,
String
key
)
{
IContext
ctx
=
MdaEnv
.
getContext
();
...
...
@@ -962,6 +1021,90 @@ public class MdaUtils {
return
Codetables
.
getCodetableLabel
(
key
,
codetable
,
locale
.
getLanguage
());
}
public
static
void
loadMdlData
(
IModule
module
,
IStream
stream
)
{
module
.
clear
();
List
<
String
>
lines
=
stream
.
getRows
();
if
(
lines
.
size
()
>
0
){
for
(
String
line
:
lines
)
{
Class
moduleClass
=
module
.
getClass
();
if
(
moduleClass
.
getName
().
toUpperCase
().
indexOf
(
line
.
toUpperCase
())
!=
-
1
){
continue
;
}
String
val
=
line
.
split
(
"="
)[
1
].
trim
();
String
key
=
line
.
split
(
"="
)[
0
].
trim
();
String
[]
fields
=
key
.
split
(
"/"
);
readData
(
1
,
module
,
fields
,
val
);
}
}
}
private
static
void
readData
(
int
index
,
IModule
module
,
String
[]
fields
,
String
oldval
)
{
String
fieldName
=
fields
[
index
];
Class
moduleClass
=
module
.
getClass
();
String
moduleName
=
moduleClass
.
getName
();
Method
getMethod
=
null
;
Method
setMethod
=
null
;
if
(
index
==
fields
.
length
-
1
){
//叶子节点赋值
//获取setXXX方法名
String
setMethodName
=
"set"
+
fieldName
.
substring
(
0
,
1
).
toUpperCase
()
+
fieldName
.
substring
(
1
);
try
{
Field
field
=
moduleClass
.
getDeclaredField
(
fieldName
);
Class
fieldTyp
=
field
.
getType
();
//获取setXXX方法
setMethod
=
moduleClass
.
getDeclaredMethod
(
setMethodName
,
field
.
getType
());
//根据类型 对数据进行处理
Object
val
=
null
;
if
(
field
.
getType
().
getName
().
equals
(
"java.lang.Integer"
)){
val
=
Integer
.
parseInt
(
oldval
);
}
else
if
(
field
.
getType
().
getName
().
equals
(
"java.math.BigDecimal"
)){
val
=
new
BigDecimal
(
oldval
);
}
else
if
(
field
.
getType
().
getName
().
equals
(
"java.util.Date"
)){
//String转Date
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
try
{
val
=
simpleDateFormat
.
parse
(
oldval
);
}
catch
(
ParseException
e
)
{
log
.
error
(
"日期{}格式不正确"
,
oldval
);
}
}
else
{
val
=
oldval
.
toString
();
}
setMethod
.
invoke
(
module
,
val
);
}
catch
(
NoSuchMethodException
e
)
{
log
.
error
(
"方法{}未找到"
,
setMethodName
);
}
catch
(
IllegalAccessException
e
)
{
log
.
error
(
"模型{}中执行方法{}时出错"
,
moduleName
,
setMethodName
);
}
catch
(
InvocationTargetException
e
)
{
log
.
error
(
"模型{}中执行方法{}时出错"
,
moduleName
,
setMethodName
);
}
catch
(
NoSuchFieldException
e
)
{
log
.
error
(
"模型{}中属性{}未找到"
,
moduleName
,
fieldName
);
}
}
else
{
//非叶子节点继续迭代
//获取setXXX方法名
String
getMethodName
=
"get"
+
fieldName
.
substring
(
0
,
1
).
toUpperCase
()
+
fieldName
.
substring
(
1
);
try
{
//查询getXXX方法
getMethod
=
moduleClass
.
getDeclaredMethod
(
getMethodName
);
//获取下次递归的模型
IModule
subModule
=
(
IModule
)
getMethod
.
invoke
(
module
);
//递归
index
++;
readData
(
index
,
subModule
,
fields
,
oldval
);
}
catch
(
IllegalAccessException
e
)
{
log
.
error
(
"模型{}中执行方法{}时出错"
,
moduleName
,
getMethodName
);
}
catch
(
InvocationTargetException
e
)
{
log
.
error
(
"模型{}中执行方法{}时出错"
,
moduleName
,
getMethodName
);
}
catch
(
NoSuchMethodException
e
)
{
log
.
error
(
"模型{}方法{}未找到"
,
moduleName
,
getMethodName
);
}
}
}
public
static
String
getCodetableLabel
(
List
<
CodetableItem
>
codeTable
,
String
key
)
{
String
label
=
""
;
if
(!
CollectionUtils
.
isEmpty
(
codeTable
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment