Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swiftMtMx
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
isc-v3.1-tmp
swiftMtMx
Commits
2c15fa67
Commit
2c15fa67
authored
Jul 14, 2022
by
chengzhuoshen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加mx报文转要素的功能
parent
fc76d9fb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
204 additions
and
0 deletions
+204
-0
AbstractMx2ElementCreator.java
...rilliance/swift/mx2element/AbstractMx2ElementCreator.java
+138
-0
Mx2ElementCreator.java
...va/com/brilliance/swift/mx2element/Mx2ElementCreator.java
+8
-0
Mx2ElementCreatorManager.java
...brilliance/swift/mx2element/Mx2ElementCreatorManager.java
+38
-0
Mx2ElementPacs008001Creator.java
...ft/mx2element/pacs008001/Mx2ElementPacs008001Creator.java
+12
-0
pacs00800108.properties
...tCore/src/main/resources/template/pacs00800108.properties
+8
-0
No files found.
swiftCore/src/main/java/com/brilliance/swift/mx2element/AbstractMx2ElementCreator.java
0 → 100644
View file @
2c15fa67
package
com
.
brilliance
.
swift
.
mx2element
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.brilliance.swift.exception.SwiftException
;
import
com.prowidesoftware.swift.model.mx.AbstractMX
;
import
org.apache.commons.io.FileUtils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.net.URL
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
public
abstract
class
AbstractMx2ElementCreator
implements
Mx2ElementCreator
{
protected
AbstractMX
abstractMX
;
protected
String
xmlStr
;
protected
Map
<
String
,
Object
>
maps
=
new
LinkedHashMap
<>();
public
AbstractMX
getAbstractMX
()
{
return
abstractMX
;
}
public
void
setAbstractMX
(
AbstractMX
abstractMX
)
{
this
.
abstractMX
=
abstractMX
;
}
public
String
getXmlStr
()
{
return
xmlStr
;
}
public
void
setXmlStr
(
String
xmlStr
)
{
this
.
xmlStr
=
xmlStr
;
}
@Override
public
Map
<
String
,
Object
>
buildElement
()
{
try
{
//AbstractMX abstractMX = AbstractMX.parse(xmlStr);
String
messageType
=
abstractMX
.
getMxId
().
getBusinessProcess
().
name
()
+
abstractMX
.
getMxId
().
getFunctionality
()
+
abstractMX
.
getMxId
().
getVariant
()
+
abstractMX
.
getMxId
().
getVersion
();
maps
.
put
(
"messageType"
,
messageType
);
String
gsonStr
=
abstractMX
.
toJson
();
Map
<
String
,
Object
>
mxGsonMaps
=
JSON
.
parseObject
(
gsonStr
);
String
fileName
=
"/template/"
+
messageType
+
".properties"
;
/*InputStream resourceAsStream = AbstractMx2ElementCreator.class.getResourceAsStream(fileName);
Properties properties = new Properties();
properties.load(resourceAsStream);
Set<Object> keySet = properties.keySet();
for (Object keyObj : keySet) {
String key = (String) keyObj;
String path = properties.getProperty(key);
Object value = getXmlValue(mxGsonMaps, path);
if (value != null) {
maps.put(key, value);
}
}*/
URL
url
=
AbstractMx2ElementCreator
.
class
.
getResource
(
fileName
);
File
propertyFile
=
new
File
(
url
.
getPath
());
List
<
String
>
properties
=
FileUtils
.
readLines
(
propertyFile
);
if
(
properties
.
size
()
>
0
)
{
for
(
String
property
:
properties
)
{
if
(
property
.
startsWith
(
"#"
))
{
continue
;
//过滤注释
}
String
[]
strArr
=
property
.
split
(
"="
);
if
(
strArr
.
length
!=
2
)
{
continue
;
//过滤掉不符合规则的配置
}
String
key
=
strArr
[
0
];
String
path
=
strArr
[
1
];
Object
value
=
getXmlValue
(
mxGsonMaps
,
path
);
if
(
value
!=
null
)
{
maps
.
put
(
key
,
value
);
}
}
}
}
catch
(
IOException
e
)
{
throw
new
SwiftException
(
e
.
getMessage
());
}
return
maps
;
}
protected
Object
getXmlValue
(
Map
<
String
,
Object
>
jsonMaps
,
String
path
)
{
Object
value
=
null
;
if
(
path
.
indexOf
(
"?"
)
>
0
)
{
String
[]
childPaths
=
path
.
split
(
"\\?"
);
for
(
String
childPath
:
childPaths
)
{
value
=
getXmlValue
(
jsonMaps
,
childPath
);
if
(
value
!=
null
)
{
return
value
;
}
}
}
//获取数据类型,&分隔,默认是string
String
type
=
"string"
;
if
(
path
.
indexOf
(
"&"
)
>
-
1
)
{
type
=
path
.
substring
(
path
.
indexOf
(
"&"
)+
1
);
path
=
path
.
substring
(
0
,
path
.
indexOf
(
"&"
));
}
//需要用. split,然后循环遍历json获取值
String
[]
paths
=
path
.
split
(
"\\."
);
Map
<
String
,
Object
>
tmpMaps
=
jsonMaps
;
for
(
String
p
:
paths
)
{
Object
obj
=
tmpMaps
.
get
(
p
);
if
(
obj
==
null
)
return
null
;
if
(
obj
instanceof
JSONArray
)
{
JSONArray
jsonArray
=
(
JSONArray
)
obj
;
obj
=
jsonArray
.
get
(
0
);
if
(
obj
instanceof
JSONObject
)
{
tmpMaps
=
(
Map
<
String
,
Object
>)
obj
;
}
else
{
return
jsonArray
;
}
}
else
if
(
obj
instanceof
JSONObject
)
{
tmpMaps
=
(
Map
<
String
,
Object
>)
obj
;
}
else
{
if
(
"bigdecimal"
.
equals
(
type
))
{
value
=
new
BigDecimal
(
String
.
valueOf
(
obj
));
}
else
if
(
"boolean"
.
equals
(
type
))
{
value
=
Boolean
.
valueOf
(
String
.
valueOf
(
obj
));
}
else
{
value
=
String
.
valueOf
(
obj
);
}
break
;
}
}
return
value
;
}
}
swiftCore/src/main/java/com/brilliance/swift/mx2element/Mx2ElementCreator.java
0 → 100644
View file @
2c15fa67
package
com
.
brilliance
.
swift
.
mx2element
;
import
java.util.Map
;
public
interface
Mx2ElementCreator
{
Map
<
String
,
Object
>
buildElement
();
}
swiftCore/src/main/java/com/brilliance/swift/mx2element/Mx2ElementCreatorManager.java
0 → 100644
View file @
2c15fa67
package
com
.
brilliance
.
swift
.
mx2element
;
import
com.brilliance.swift.exception.SwiftException
;
import
com.brilliance.swift.mx2element.pacs008001.Mx2ElementPacs008001Creator
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.prowidesoftware.swift.model.mx.AbstractMX
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
public
class
Mx2ElementCreatorManager
{
public
String
mx2Element
(
String
xmlStr
)
throws
SwiftException
{
AbstractMX
abstractMX
=
AbstractMX
.
parse
(
xmlStr
);
String
messageType
=
(
abstractMX
.
getMxId
().
getBusinessProcess
().
name
()
+
"."
+
abstractMX
.
getMxId
().
getFunctionality
()
+
"."
+
abstractMX
.
getMxId
().
getVariant
())
//+ abstractMX.getMxId().getVersion())
.
trim
();
AbstractMx2ElementCreator
creator
=
getCreator
(
messageType
);
creator
.
setAbstractMX
(
abstractMX
);
creator
.
setXmlStr
(
xmlStr
);
Map
<
String
,
Object
>
maps
=
creator
.
buildElement
();
Gson
gson
=
new
GsonBuilder
().
setPrettyPrinting
().
create
();
return
gson
.
toJson
(
maps
,
LinkedHashMap
.
class
);
}
public
AbstractMx2ElementCreator
getCreator
(
String
messageType
)
{
if
(
"pacs.008.001"
.
equals
(
messageType
))
{
return
new
Mx2ElementPacs008001Creator
();
}
else
{
throw
new
SwiftException
(
"Invalid message type"
);
}
}
}
swiftCore/src/main/java/com/brilliance/swift/mx2element/pacs008001/Mx2ElementPacs008001Creator.java
0 → 100644
View file @
2c15fa67
package
com
.
brilliance
.
swift
.
mx2element
.
pacs008001
;
import
com.brilliance.swift.mx2element.AbstractMx2ElementCreator
;
import
java.util.Map
;
public
class
Mx2ElementPacs008001Creator
extends
AbstractMx2ElementCreator
{
@Override
public
Map
<
String
,
Object
>
buildElement
()
{
return
super
.
buildElement
();
}
}
swiftCore/src/main/resources/template/pacs00800108.properties
0 → 100644
View file @
2c15fa67
frBic
=
appHdr.fr.fiId.finInstnId.bicfi?appHdr.fr.orgId.id.orgId.anyBIC
toBic
=
appHdr.to.fiId.finInstnId.bicfi?appHdr.to.orgId.id.orgId.anyBIC
bizMsgIdr
=
fiToFICstmrCdtTrf.cdtTrfTxInf.pmtId.instrId?fiToFICstmrCdtTrf.grpHdr.msgId?appHdr.bizMsgIdr
msgDefIdr
=
appHdr.msgDefIdr
bizSvc
=
appHdr.bizSvc
creDt
=
fiToFICstmrCdtTrf.grpHdr.creDtTm?appHdr.creDt
priority
=
appHdr.prty
dbtrAdrLines
=
fiToFICstmrCdtTrf.cdtTrfTxInf.dbtr.pstlAdr.adrLine
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