Commit 3c58b693 by zhanghou

完成mt196,mt296到camt02900109的开发

parent 96673f33
......@@ -8,6 +8,7 @@ import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.brilliance.swift.vo.common.*;
import com.prowidesoftware.swift.model.field.Field23E;
import com.prowidesoftware.swift.model.field.Field76;
import java.text.ParseException;
import java.util.*;
......@@ -1421,7 +1422,90 @@ public abstract class AbstractMt2MxParseField implements Mt2MxParseField {
}
}
}
protected void mt_To_mxField76(String mt76, Map<String, Object> maps){
String mt76Value = mt76.replace("\r\n//", "").trim();
String status = mt76Value.substring(1,5);
String reason = mt76Value.substring(6,10);
String additionalInformation = "";
//MXReasonList = {AC04, AGNT, AM04, ARDT, CUST, INDM, LEGL, NOAS, NOOR, PTNA, RQDA}
if("AC04".equals(reason)||"AGNT".equals(reason)||"AM04".equals(reason)
||"ARDT".equals(reason)||"CUST".equals(reason)||"INDM".equals(reason)
||"LEGL".equals(reason)||"NOAS".equals(reason)||"NOOR".equals(reason)
||"PTNA".equals(reason)||"RQDA".equals(reason)){
if(mt76Value.length()>10){
additionalInformation = mt76Value.substring(11);
}
}else {
additionalInformation = mt76Value.substring(6);
if ("RJCR".equals(status)){
reason = "NARR";
}else {
reason = "";
}
}
Map<String, Object> cxlStsRsnInfMaps = null;
JSONArray cxlStsRsnInfJsonArray = null;
if(maps.containsKey("txInfAndSts")){
cxlStsRsnInfJsonArray = (JSONArray) maps.get("cxlStsRsnInf");
if (cxlStsRsnInfJsonArray.size()>0) {
cxlStsRsnInfMaps = (Map<String, Object>)cxlStsRsnInfJsonArray.get(0);
} else {
cxlStsRsnInfMaps = new HashMap<>();
cxlStsRsnInfJsonArray.add(cxlStsRsnInfMaps);
}
}else {
cxlStsRsnInfJsonArray = new JSONArray();
cxlStsRsnInfMaps = new HashMap<>();
maps.put("cxlStsRsnInf",cxlStsRsnInfJsonArray);
cxlStsRsnInfJsonArray.add(cxlStsRsnInfMaps);
}
if(StringUtil.isNotEmpty(reason)){
Map<String, Object> rsnMaps = null;
if(cxlStsRsnInfMaps.containsKey("rsn")){
rsnMaps = (Map<String, Object>)cxlStsRsnInfMaps.get("rsn");
}else {
rsnMaps = new HashMap<>();
cxlStsRsnInfMaps.put("rsn",rsnMaps);
}
rsnMaps.put("cd",reason);
}
List<String> list = new ArrayList<>();
if(additionalInformation.length()>210){
additionalInformation = additionalInformation.substring(0,209) + "+";
}
if (additionalInformation.length()>105){
list.add(additionalInformation.substring(0,105));
list.add(additionalInformation.substring(105));
}
JSONArray addtlInfJsonArray = null;
if(cxlStsRsnInfMaps.containsKey("addtlInf")){
addtlInfJsonArray = (JSONArray) cxlStsRsnInfMaps.get("cxlStsRsnInf");
}else {
addtlInfJsonArray = new JSONArray();
cxlStsRsnInfMaps.put("addtlInf",addtlInfJsonArray);
}
addtlInfJsonArray.addAll(list);
}
protected String getMxType(String mtType){
String mxType = "";
if("103".equals(mtType)){
mxType = "pacs.008";
}else if("104".equals(mtType)){
mxType = "pacs.003";
}else if("202".equals(mtType)||"205".equals(mtType)){
mxType = "pacs.009";
}else if("204".equals(mtType)){
mxType = "pacs.010";
}else if(mtType.matches("10[0-9]{1}")||mxType.matches("20[0-9]{1}")){
mxType = "MT" + mtType;
}else {
mxType = "MT" + mtType;
}
return mxType;
}
/**
* MT 转 MX 转换函数结束
*/
}
package com.brilliance.swift.mt2mx;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.Mt2MxCamt029001Creator;
import com.brilliance.swift.mt2mx.pacs008001.Mt2MxPacs008001Creator;
import com.prowidesoftware.swift.model.mt.AbstractMT;
......@@ -42,6 +43,8 @@ public class Mt2MxCreatorManager {
String messageType = abstractMT.getMessageType();
if ("103".equals(messageType)) {
return new Mt2MxPacs008001Creator();
}else if("196".equals(messageType)||"296".equals(messageType)) {
return new Mt2MxCamt029001Creator();
} else {
throw new SwiftException("ERROR", "Invalid message type");
}
......
package com.brilliance.swift.mt2mx.camt029001;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.mt2mx.AbstractMt2MxParseField;
import java.util.HashMap;
import java.util.Map;
public abstract class AbstractMt2MxCamt029001ParseField extends AbstractMt2MxParseField {
protected Map<String, Object> appHdrMaps = null;
protected Map<String, Object> assgnmtMaps = null;
protected Map<String, Object> stsMaps = null;
protected Map<String, Object> cxlDtlsMaps = null;
@Override
public void initJsonMaps() {
super.initJsonMaps();
appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
Map<String, Object> rsltnOfInvstgtnMaps = (Map<String, Object>)jsonMaps.get("rsltnOfInvstgtn");
assgnmtMaps = (Map<String, Object>)rsltnOfInvstgtnMaps.get("assgnmt");
stsMaps = (Map<String, Object>)rsltnOfInvstgtnMaps.get("sts");
JSONArray cxlDtlsJsonArray = (JSONArray) rsltnOfInvstgtnMaps.get("cxlDtls");
cxlDtlsMaps = (Map<String, Object>)cxlDtlsJsonArray.get(0);
}
public Map<String, Object> getTxInfAndStsMaps(){
Map<String, Object> txInfAndStsMaps = null;
JSONArray txInfAndStsJsonArray = null;
if(cxlDtlsMaps.containsKey("txInfAndSts")){
txInfAndStsJsonArray = (JSONArray) cxlDtlsMaps.get("txInfAndSts");
if (txInfAndStsJsonArray.size()>0) {
txInfAndStsMaps = (Map<String, Object>)txInfAndStsJsonArray.get(0);
} else {
txInfAndStsMaps = new HashMap<>();
txInfAndStsJsonArray.add(txInfAndStsMaps);
}
}else {
txInfAndStsJsonArray = new JSONArray();
txInfAndStsMaps = new HashMap<>();
cxlDtlsMaps.put("txInfAndSts",txInfAndStsJsonArray);
txInfAndStsJsonArray.add(txInfAndStsMaps);
}
return txInfAndStsMaps;
}
}
package com.brilliance.swift.mt2mx.camt029001;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.mt2mx.AbstractMt2MxCreator;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.Mt2MxParseField;
import com.brilliance.swift.mt2mx.camt029001.impl.*;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Mt2MxCamt029001Creator extends AbstractMt2MxCreator {
@Override
public void preProcess() {
super.preProcess();
jsonMaps.put("identifier", "camt.029.001.09");
Map<String, Object> appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
appHdrMaps.put("msgDefIdr", "camt.029.001.09");
AbstractMT abstractMT = context.get(AbstractMT.class);
//初始化转换和不需要BLOCK4的转换
Map<String, Object> rsltnOfInvstgtnMaps = new HashMap<>();
jsonMaps.put("rsltnOfInvstgtn", rsltnOfInvstgtnMaps);
Map<String, Object> assgnmtMaps = new HashMap<>();
rsltnOfInvstgtnMaps.put("assgnmt", assgnmtMaps);
assgnmtMaps.put("creDtTm", "9999-12-31T00:00:00+00:00");
Map<String, Object> cxlDtlsMaps = new HashMap<>();
JSONArray cxlDtlsJsonArray = new JSONArray();
cxlDtlsJsonArray.add(cxlDtlsMaps);
rsltnOfInvstgtnMaps.put("cxlDtls", cxlDtlsJsonArray);
Map<String, Object> txInfAndStsMaps = new HashMap<>();
JSONArray txInfAndStsJsonArray = new JSONArray();
txInfAndStsJsonArray.add(txInfAndStsMaps);
cxlDtlsMaps.put("txInfAndSts",txInfAndStsJsonArray);
String orgnlUETR = abstractMT.getSwiftMessage().getUETR();
if (StringUtil.isNotEmpty(orgnlUETR)) {
txInfAndStsMaps.put("orgnlUETR", orgnlUETR);
}
String sendBic = (String) context.get(Mt2MxContextIdentifier.MT_SEND_BIC, true);
if (StringUtil.isNotEmpty(sendBic)) {
Map<String, Object> assgnrMaps = new HashMap<>();
assgnmtMaps.put("assgnr",assgnrMaps);
Map<String, Object> agtMaps = new HashMap<>();
assgnrMaps.put("agt",agtMaps);
mt_to_mxBICFI(sendBic, agtMaps);
}
String receiverBic = (String) context.get(Mt2MxContextIdentifier.MT_RECEIVE_BIC, true);
if (StringUtil.isNotEmpty(receiverBic)) {
Map<String, Object> assgneMaps = new HashMap<>();
assgnmtMaps.put("assgnr",assgneMaps);
Map<String, Object> agtMaps = new HashMap<>();
assgneMaps.put("agt",agtMaps);
mt_to_mxBICFI(sendBic, agtMaps);
}
}
@Override
public List<Mt2MxParseField> getParseFieldList() {
List<Mt2MxParseField> list = new ArrayList<>();
list.add(new Camt029001Parse20Field());
list.add(new Camt029001Parse21Field());
list.add(new Camt029001Parse11RField());
list.add(new Camt029001Parse76Field());
list.add(new Camt029001Parse77AField());
list.add(new Camt029001Parse79Field());
return list;
}
}
package com.brilliance.swift.mt2mx.camt029001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.AbstractMt2MxCamt029001ParseField;
import com.brilliance.swift.util.DateUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field11R;
import com.prowidesoftware.swift.model.field.Field32A;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Camt029001Parse11RField extends AbstractMt2MxCamt029001ParseField {
private static final String NAME = "11R";
@Override
public void parseField() throws SwiftException {
try {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag != null) {
Field11R field11R = (Field11R)tag.asField();
Date date = DateUtil.parseDate("20"+field11R.getDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
Map<String, Object> txInfAndStsMaps = getTxInfAndStsMaps();
Map<String, Object> orgnlGrpInfMaps = null;
if(txInfAndStsMaps.containsKey("orgnlGrpInf")){
orgnlGrpInfMaps = (Map<String, Object>)txInfAndStsMaps.get("orgnlGrpInf");
}else {
orgnlGrpInfMaps = new HashMap<>();
txInfAndStsMaps.put("orgnlGrpInf",orgnlGrpInfMaps);
}
String mtType = field11R.getMT();
String mxType = getMxType(mtType);
orgnlGrpInfMaps.put("orgnlMsgNmId",mxType);
orgnlGrpInfMaps.put("orgnlCreDtTm",dateStr+"T00:00:00+00:00");
}
} catch (ParseException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
package com.brilliance.swift.mt2mx.camt029001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.AbstractMt2MxCamt029001ParseField;
import com.brilliance.swift.mt2mx.pacs008001.AbstractMt2MxPacs008001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Camt029001Parse20Field extends AbstractMt2MxCamt029001ParseField {
private static final String NAME = "20";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag20 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag20 != null) {
appHdrMaps.put("bizMsgIdr", tag20.getValue());
assgnmtMaps.put("id",tag20.getValue());
Map<String, Object> txInfAndStsMaps = getTxInfAndStsMaps();
txInfAndStsMaps.put("cxlStsId",tag20.getValue());
}
}
}
package com.brilliance.swift.mt2mx.camt029001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.AbstractMt2MxCamt029001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Camt029001Parse21Field extends AbstractMt2MxCamt029001ParseField {
private static final String NAME = "21";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag21 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag21 != null) {
Map<String, Object> txInfAndStsMaps = getTxInfAndStsMaps();
Map<String, Object> rslvdCaseMaps = null;
if(txInfAndStsMaps.containsKey("rslvdCase")){
rslvdCaseMaps = (Map<String, Object>) txInfAndStsMaps.get("rslvdCase");
}else {
rslvdCaseMaps = new HashMap<>();
txInfAndStsMaps.put("rslvdCase",rslvdCaseMaps);
}
rslvdCaseMaps.put("id",tag21.getValue());
}
}
}
package com.brilliance.swift.mt2mx.camt029001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.AbstractMt2MxCamt029001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field11R;
import com.prowidesoftware.swift.model.field.Field76;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.Map;
public class Camt029001Parse76Field extends AbstractMt2MxCamt029001ParseField {
private static final String NAME = "76";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag76 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag76 != null) {
Field76 field76 = (Field76)tag76.asField();
Map<String, Object> txInfAndStsMaps = getTxInfAndStsMaps();
mt_To_mxField76(field76.getValue(),txInfAndStsMaps);
}
}
}
package com.brilliance.swift.mt2mx.camt029001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.AbstractMt2MxCamt029001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field76;
import com.prowidesoftware.swift.model.field.Field77A;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.Map;
public class Camt029001Parse77AField extends AbstractMt2MxCamt029001ParseField {
private static final String NAME = "77A";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag77A = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag77A != null) {
Map<String, Object> txInfAndStsMaps = getTxInfAndStsMaps();
Field77A field77A = (Field77A)tag77A.asField();
String String77A = field77A.getValue().replace("\r\n//", "").replace("\r\n","");
int index = String77A.indexOf("/UETR/");
String uetr = String77A.substring(index+6);
txInfAndStsMaps.put("orgnlUETR",uetr);
}
}
}
package com.brilliance.swift.mt2mx.camt029001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.AbstractMt2MxCamt029001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.Map;
public class Camt029001Parse79Field extends AbstractMt2MxCamt029001ParseField {
private static final String NAME = "79";
@Override
public void parseField() throws SwiftException {
}
}
{1:F01NDEAFIHHXXXX0000000000}{2:O1960000991231HELSFIHHXXXX00000000009912310000N}{3:{121:8a562c67-ca16-48ba-b074-65581be6f001}}{4:
:20:CNCL-ID001
:21:CSE-001
:76:/CNCL/AGNT
:77A:/UETR/8a562c67-ca16-48ba-b074-65581
//be6f001
:11R:103
210217
-}
\ No newline at end of file
{1:F01NDEAFIHHXXXX0000000000}{2:O2960000991231HELSFIHHXXXX00000000009912310000N}{3:{121:8a562c67-ca16-48ba-b074-65581be6f001}}{4:
:20:CNCL-ID001
:21:CSE-001
:76:/CNCL/AGNT/HELLO,WORLD.HELLO,WORLD.
//HELLO,WORLD.HELLO,WORLD.HELLO,WOR
//LD.HELLO,WORLD.HELLO,WORLD.HELLO,
//WORLD.HELLO,WORLD.HELLO,WORLD.HEL
//LO,WORLD.HELLO,WORLD.HELLO,WORLD.
//HELLO,WORLD.HELLO,WORLD.HELLO,WOR
:77A:
//LD.HELLO,WORLD.HELLO,WORLD.HELLO,
//WORLD.HELLO,WORLD.HELLO,WORLD.NIC
//E TO MEET YOU
/UETR/8a562c67-ca16-48ba-b074-65581
//be6f001
:11R:202
210217
-}
package com.brilliance.mt2mx.camt029001;
import com.brilliance.swift.mt2mx.Mt2MxCreatorManager;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class Test196 {
public static void main(String[] args) throws IOException {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt196.txt");
String mtStr = FileUtils.readFileToString(file);
String mxXml = new Mt2MxCreatorManager().mt2mx(mtStr, null, null);
System.out.println(mxXml);
/*AbstractMT abstractMT = AbstractMT.parse(mtStr);
MT103 mt103 = (MT103)abstractMT;
Field53A field53A = mt103.getField53A();
System.out.println(field53A.getComponent(1) + field53A.getComponent2());
System.out.println(field53A.getBIC());*/
}
}
package com.brilliance.mt2mx.camt029001;
import com.brilliance.swift.mt2mx.Mt2MxCreatorManager;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class Test296 {
public static void main(String[] args) throws IOException {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt296.txt");
String mtStr = FileUtils.readFileToString(file);
String mxXml = new Mt2MxCreatorManager().mt2mx(mtStr, null, null);
System.out.println(mxXml);
/*AbstractMT abstractMT = AbstractMT.parse(mtStr);
MT103 mt103 = (MT103)abstractMT;
Field53A field53A = mt103.getField53A();
System.out.println(field53A.getComponent(1) + field53A.getComponent2());
System.out.println(field53A.getBIC());*/
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment