Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
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
liyuan
byit-myth-job
Commits
c0189004
Commit
c0189004
authored
Mar 11, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
参数替换工具开发
parent
379551a0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
7 deletions
+49
-7
PlaceholderUtils.java
...on/src/main/java/com/byit/job/utils/PlaceholderUtils.java
+49
-7
No files found.
byit-myth-core/myth-core-common/src/main/java/com/byit/job/utils/PlaceholderUtils.java
View file @
c0189004
package
com
.
byit
.
job
.
utils
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.job.dto.ScriptParamAndPlaceholderDto
;
import
lombok.extern.java.Log
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -10,6 +13,7 @@ import java.io.IOException;
import
java.nio.ByteBuffer
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -28,6 +32,10 @@ public class PlaceholderUtils {
* 占位符后缀
*/
private
static
final
String
PLACEHOLDER_SUFFIX
=
"}"
;
/**
* 补批时间参数占位符
*/
private
static
final
String
DATE_KEY
=
"biz_date"
;
/**
* 占位符数据替换
...
...
@@ -72,15 +80,49 @@ public class PlaceholderUtils {
return
sbt
.
toString
().
getBytes
(
StandardCharsets
.
UTF_8
);
}
public
static
void
main
(
String
[]
args
)
{
String
text
=
"123${name},1232321${sex}123123"
;
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"name"
,
"皇甫科星"
);
map
.
put
(
"sex"
,
"'男'"
);
byte
[]
bytes
=
resolvePlaceholders
(
text
.
getBytes
(
StandardCharsets
.
UTF_8
),
map
);
public
static
String
paramPlaceholder
(
String
runParam
,
String
thisDate
){
ScriptParamAndPlaceholderDto
scriptParamAndPlaceholderDto
=
JSON
.
parseObject
(
runParam
,
ScriptParamAndPlaceholderDto
.
class
);
Map
<
String
,
String
>
placeholder
=
scriptParamAndPlaceholderDto
.
getPlaceholder
();
Map
<
String
,
String
>
param
=
scriptParamAndPlaceholderDto
.
getParam
();
/**
* 替换时间参数
*/
if
(
CollectionUtil
.
isNotEmpty
(
placeholder
)
&&
placeholder
.
containsKey
(
DATE_KEY
))
{
placeholder
.
put
(
DATE_KEY
,
thisDate
);
}
/**
* 替换时间占位符
*/
if
(
CollectionUtil
.
isNotEmpty
(
param
)
&&
param
.
containsKey
(
DATE_KEY
)){
param
.
put
(
DATE_KEY
,
thisDate
);
}
System
.
out
.
println
(
new
String
(
bytes
,
StandardCharsets
.
UTF_8
)
);
return
JSON
.
toJSONString
(
scriptParamAndPlaceholderDto
);
}
public
static
void
main
(
String
[]
args
)
{
ScriptParamAndPlaceholderDto
sc
=
new
ScriptParamAndPlaceholderDto
();
Map
<
String
,
String
>
m1
=
new
HashMap
<>(
2
);
Map
<
String
,
String
>
m2
=
new
HashMap
<>(
2
);
m1
.
put
(
DATE_KEY
,
"2018年12月12日"
);
m1
.
put
(
"name"
,
"狗子"
);
m2
.
put
(
DATE_KEY
,
"2010年10月10日"
);
m2
.
put
(
"age"
,
"1000"
);
sc
.
setPlaceholder
(
m2
);
sc
.
setParam
(
m1
);
String
toJSONString
=
JSON
.
toJSONString
(
sc
);
String
s
=
paramPlaceholder
(
toJSONString
,
"2020/3/12 15:13"
);
System
.
out
.
println
(
s
);
}
}
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