Commit 040ff4dd by zhanghou

完成940950转camt05300108

parent 5a8c5996
......@@ -2,6 +2,7 @@ package com.brilliance.swift.mt2mx;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.Mt2MxCamt029001Creator;
import com.brilliance.swift.mt2mx.camt053001.Mt2MxCamt053001Creator;
import com.brilliance.swift.mt2mx.camt054001.Mt2MxCamt054001Creator;
import com.brilliance.swift.mt2mx.camt056001.Mt2MxCamt056001Creator;
import com.brilliance.swift.mt2mx.pacs002001.Mt2MxPacs002001Creator;
......@@ -64,7 +65,9 @@ public class Mt2MxCreatorManager {
return new Mt2MxCamt056001Creator();
} else if("900".equals(messageType)||"910".equals(messageType)) {
return new Mt2MxCamt054001Creator();
} else {
} else if("940".equals(messageType)||"950".equals(messageType)) {
return new Mt2MxCamt053001Creator();
}else {
throw new SwiftException("Invalid message type");
}
}
......
package com.brilliance.swift.mt2mx.camt053001;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.mt2mx.AbstractMt2MxParseField;
import java.util.HashMap;
import java.util.Map;
public abstract class AbstractMt2MxCamt053001ParseField extends AbstractMt2MxParseField {
protected Map<String, Object> appHdrMaps = null;
protected Map<String, Object> grpHdrMaps = null;
protected Map<String, Object> stmtMaps = null;
@Override
public void initJsonMaps() {
super.initJsonMaps();
appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
Map<String, Object> bkToCstmrStmtMaps = (Map<String, Object>)jsonMaps.get("bkToCstmrStmt");
grpHdrMaps = (Map<String, Object>)bkToCstmrStmtMaps.get("grpHdr");
JSONArray stmtJsonArray = (JSONArray) bkToCstmrStmtMaps.get("stmt");
stmtMaps = (Map<String, Object>)stmtJsonArray.get(0);
}
}
package com.brilliance.swift.mt2mx.camt053001;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.mt2mx.AbstractMt2MxCreator;
import com.brilliance.swift.mt2mx.Mt2MxParseField;
import com.brilliance.swift.mt2mx.camt053001.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 Mt2MxCamt053001Creator extends AbstractMt2MxCreator {
@Override
public void preProcess() {
super.preProcess();
jsonMaps.put("identifier", "camt.053.001.08");
Map<String, Object> appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
appHdrMaps.put("msgDefIdr", "camt.053.001.08");
AbstractMT abstractMT = context.get(AbstractMT.class);
//初始化转换和不需要BLOCK4的转换
Map<String, Object> bkToCstmrStmtMaps = new HashMap<>();
jsonMaps.put("bkToCstmrStmt", bkToCstmrStmtMaps);
Map<String, Object> grpHdrMaps = new HashMap<>();
bkToCstmrStmtMaps.put("grpHdr", grpHdrMaps);
grpHdrMaps.put("creDtTm", getCreateDateStr());
grpHdrMaps.put("nbOfTxs", "1");
Map<String, Object> stmtMaps = new HashMap<>();
JSONArray stmtJsonArray = new JSONArray();
stmtJsonArray.add(stmtMaps);
bkToCstmrStmtMaps.put("stmt", stmtJsonArray);
Map<String, Object> ntryMaps = new HashMap<>();
JSONArray ntryJsonArray = new JSONArray();
Map<String, Object> ntryDtlsMaps = new HashMap<>();
JSONArray ntryDtlsJsonArray = new JSONArray();
Map<String, Object> txDtlsMaps = new HashMap<>();
JSONArray txDtlsJsonArray = new JSONArray();
String uetr = abstractMT.getSwiftMessage().getUETR();
if (StringUtil.isNotEmpty(uetr)) {
ntryJsonArray.add(ntryMaps);
stmtMaps.put("ntry", ntryJsonArray);
ntryDtlsJsonArray.add(ntryDtlsMaps);
ntryMaps.put("ntryDtls", ntryDtlsJsonArray);
txDtlsJsonArray.add(txDtlsMaps);
ntryDtlsMaps.put("txDtls", txDtlsJsonArray);
Map<String, Object> refsMaps = new HashMap<>();
txDtlsMaps.put("refs",refsMaps);
refsMaps.put("uetr",uetr);
}
}
@Override
public List<Mt2MxParseField> getParseFieldList() {
List<Mt2MxParseField> list = new ArrayList<>();
list.add(new Camt053001Parse20Field());
list.add(new Camt053001Parse25Field());
list.add(new Camt053001Parse28CField());
list.add(new Camt053001Parse60Field());
list.add(new Camt053001Parse61Field());
list.add(new Camt053001Parse62Field());
list.add(new Camt053001Parse64Field());
list.add(new Camt053001Parse65Field());
list.add(new Camt053001Parse86Field());
return list;
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.brilliance.swift.mt2mx.camt054001.AbstractMt2MxCamt054001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
public class Camt053001Parse20Field extends AbstractMt2MxCamt053001ParseField {
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());
grpHdrMaps.put("msgId", tag20.getValue());
stmtMaps.put("id",tag20.getValue());
}
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field25;
import com.prowidesoftware.swift.model.field.Field25P;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Camt053001Parse25Field extends AbstractMt2MxCamt053001ParseField {
private static final String NAME_25 = "25";
private static final String NAME_25P = "25P";
@Override
public void parseField() throws SwiftException {
Field25 field25 = null;
Field25P field25P = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag25 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_25);
Tag tag25P = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_25P);
Map<String, Object> acctMaps = null;
if (stmtMaps.containsKey("acct")) {
acctMaps = (Map<String, Object>) stmtMaps.get("acct");
} else {
acctMaps = new HashMap<>();
stmtMaps.put("acct",acctMaps);
}
if(tag25!=null){
field25 = (Field25) tag25.asField();
mt_to_mxAccount35(field25.getValue(),acctMaps,"Ntfctn/Acct/Id/Othr/Id");
}
if(tag25P!=null){
field25P = (Field25P) tag25P.asField();
mt_to_mxAccount35(field25P.getValue(),acctMaps,"Ntfctn/Acct/Id/Othr/Id");
}
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field28C;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Camt053001Parse28CField extends AbstractMt2MxCamt053001ParseField {
private static final String NAME = "28C";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag28 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag28 != null) {
Field28C field28C = (Field28C) tag28.asField();
stmtMaps.put("lglSeqNb",field28C.getStatementNumber());
Map<String, Object> stmtPgntnMaps = null;
if (stmtMaps.containsKey("stmtPgntn")) {
stmtPgntnMaps = (Map<String, Object>) stmtMaps.get("stmtPgntn");
} else {
stmtPgntnMaps = new HashMap<>();
stmtMaps.put("stmtPgntn",stmtPgntnMaps);
}
stmtPgntnMaps.put("pgNb",field28C.getSequenceNumber());
}
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.vo.common.BalanceSubTypeCode;
import com.brilliance.swift.vo.common.BalanceTypeCode;
import com.brilliance.swift.vo.common.CdtDbtCode;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field60F;
import com.prowidesoftware.swift.model.field.Field60M;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import org.sss.common.model.IFactory;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Camt053001Parse60Field extends AbstractMt2MxCamt053001ParseField {
private static final String NAME_F = "60F";
private static final String NAME_M = "60M";
@Override
public void parseField() throws SwiftException {
try {
Field60F field60F = null;
Field60M field60M = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag60 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_F);
if (tag60 != null) {
field60F = (Field60F) tag60.asField();
}
tag60 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_M);
if (tag60 != null) {
field60M = (Field60M) tag60.asField();
}
Map<String, Object> balMaps = null;
JSONArray balJsonArray = null;
if(stmtMaps.containsKey("bal")){
balJsonArray = (JSONArray) stmtMaps.get("bal");
balMaps = new HashMap<>();
balJsonArray.add(balMaps);
}else {
balJsonArray = new JSONArray();
balMaps = new HashMap<>();
stmtMaps.put("bal",balJsonArray);
balJsonArray.add(balMaps);
}
Map<String, Object> tpMaps = new HashMap<>();
balMaps.put("tp",tpMaps);
Map<String, Object> cdOrPrtryMaps = new HashMap<>();
tpMaps.put("cdOrPrtry",cdOrPrtryMaps);
Map<String, Object> subTpMaps = new HashMap<>();
tpMaps.put("subTp",subTpMaps);
subTpMaps.put("cd", BalanceSubTypeCode.INTM);
cdOrPrtryMaps.put("cd", BalanceTypeCode.OPBD);
Map<String, Object> dtMaps = null;
if(balMaps.containsKey("dt")){
dtMaps = (Map<String, Object>)balMaps.get("dt");
}else {
dtMaps = new HashMap<>();
balMaps.put("dt",dtMaps);
}
Map<String, Object> amtMaps = null;
if(balMaps.containsKey("amt")){
amtMaps = (Map<String, Object>)balMaps.get("amt");
}else {
amtMaps = new HashMap<>();
balMaps.put("amt",amtMaps);
}
if (field60F != null) {
if ("D".equals(field60F.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.DBIT);
} else if ("C".equals(field60F.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.CRDT);
}
Date date = DateUtil.parseDate("20" + field60F.getDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
dtMaps.put("dt",dateStr);
amtMaps.put("value",field60F.amount());
amtMaps.put("ccy",field60F.getCurrency());
}
if (field60M != null) {
if ("D".equals(field60M.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.DBIT);
} else if ("C".equals(field60M.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.CRDT);
}
Date date = DateUtil.parseDate("20" + field60M.getDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
dtMaps.put("dt",dateStr);
amtMaps.put("value",field60M.amount());
amtMaps.put("ccy",field60M.getCurrency());
}
} catch (ParseException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.common.CdtDbtCode;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field60F;
import com.prowidesoftware.swift.model.field.Field60M;
import com.prowidesoftware.swift.model.field.Field61;
import com.prowidesoftware.swift.model.field.Field86;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Camt053001Parse61Field extends AbstractMt2MxCamt053001ParseField {
private static final String NAME = "61";
private static final String NAME_86 = "86";
private static final String NAME_60F = "60F";
private static final String NAME_60M = "60M";
@Override
public void parseField() throws SwiftException {
try {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag[] tag61 = abstractMT.getSwiftMessage().getBlock4().getTagsByName(NAME);
List<Tag> tags = abstractMT.getSwiftMessage().getBlock4().getTags();
Tag tag60M = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_60M);
Tag tag60F = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_60F);
if (tag61 != null) {
int index = 0;
int count = 0;
for (int i = 0; i < tag61.length; i++) {
Field61 field61 = (Field61) tag61[i].asField();
Map<String, Object> ntryMaps = null;
JSONArray ntryJsonArray = null;
if(stmtMaps.containsKey("ntry")){
ntryJsonArray = (JSONArray) stmtMaps.get("ntry");
if(i==0){
ntryMaps = (Map<String, Object>)ntryJsonArray.get(0);
}else {
ntryMaps = new HashMap<>();
ntryJsonArray.add(ntryMaps);
}
}else {
ntryJsonArray = new JSONArray();
ntryMaps = new HashMap<>();
stmtMaps.put("ntry",ntryJsonArray);
ntryJsonArray.add(ntryMaps);
}
if(field61.getValueDate()!=null){
Map<String, Object> valDtMaps = new HashMap<>();
ntryMaps.put("valDt",valDtMaps);
Date date = DateUtil.parseDate("20"+field61.getValueDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
valDtMaps.put("dt",dateStr);
}
if(field61.getEntryDate()!=null){
Map<String, Object> bookgDtMaps = new HashMap<>();
ntryMaps.put("bookgDt",bookgDtMaps);
Date date = DateUtil.parseDate("2022"+field61.getEntryDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
bookgDtMaps.put("dt",dateStr);
}
if(field61.getDCMark()!=null){
if("RC".equals(field61.getDCMark())||"D".equals(field61.getDCMark())){
if("RC".equals(field61.getDCMark())){
ntryMaps.put("rvslInd",Boolean.TRUE);
}
ntryMaps.put("cdtDbtInd", CdtDbtCode.DBIT);
}else {
if("RD".equals(field61.getDCMark())){
ntryMaps.put("rvslInd",Boolean.TRUE);
}
ntryMaps.put("cdtDbtInd", CdtDbtCode.CRDT);
}
}
if(field61.getAmount()!=null){
Map<String, Object> amtMaps = new HashMap<>();
ntryMaps.put("amt",amtMaps);
amtMaps.put("value",field61.amount());
if(tag60F!=null){
Field60F field60F = (Field60F)tag60F.asField();
amtMaps.put("ccy",field60F.getCurrency());
}
if(tag60M!=null){
Field60M field60M = (Field60M)tag60M.asField();
amtMaps.put("ccy",field60M.getCurrency());
}
}
JSONArray ntryDtlsJsonArray = null;
Map<String, Object> ntryDtlsMaps = null;
if(ntryMaps.containsKey("ntryDtls")){
ntryDtlsJsonArray = (JSONArray)ntryMaps.get("ntryDtls");
ntryDtlsMaps = (Map<String, Object>)ntryDtlsJsonArray.get(0);
}else {
ntryDtlsJsonArray = new JSONArray();
ntryDtlsMaps = new HashMap<>();
ntryDtlsJsonArray.add(ntryDtlsMaps);
ntryMaps.put("ntryDtls",ntryDtlsJsonArray);
}
JSONArray txDtlsJsonArray = null;
Map<String, Object> txDtlsMaps = null;
if(ntryDtlsMaps.containsKey("txDtls")){
txDtlsJsonArray = (JSONArray)ntryDtlsMaps.get("txDtls");
txDtlsMaps = (Map<String, Object>)txDtlsJsonArray.get(0);
}else {
txDtlsJsonArray = new JSONArray();
txDtlsMaps = new HashMap<>();
ntryDtlsMaps.put("txDtls",txDtlsJsonArray);
txDtlsJsonArray.add(txDtlsMaps);
}
if(field61.getReferenceForTheAccountOwner()!=null){
Map<String, Object> refsMaps = null;
if(txDtlsMaps.containsKey("refs")){
refsMaps = (Map<String, Object>)txDtlsMaps.get("refs");
}else {
refsMaps = new HashMap<>();
txDtlsMaps.put("refs",refsMaps);
}
refsMaps.put("endToEndId",field61.getReferenceForTheAccountOwner());
}
if(field61.getReferenceOfTheAccountServicingInstitution()!=null){
ntryMaps.put("acctSvcrRef",field61.getReferenceOfTheAccountServicingInstitution());
}
if(field61.getSupplementaryDetails()!=null){
txDtlsMaps.put("addtlTxInf",field61.getSupplementaryDetails());
}
if("940".equals(abstractMT.getMessageType())){
Tag[] tag86 = abstractMT.getSwiftMessage().getBlock4().getTagsByName(NAME_86);
if(tag86!=null){
if(tags!=null){
for (;index < tags.size()-1; index++) {
if(tags.get(index).getName().equals("61")&&tags.get(index+1).getName().equals("86")){
Field86 field86 = (Field86) tag86[count].asField();
ntryMaps.put("addtlNtryInf",field86.getValue().replace("\r\n",""));
count++;
}
}
}
}
}
}
}
}catch (ParseException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.vo.common.BalanceSubTypeCode;
import com.brilliance.swift.vo.common.BalanceTypeCode;
import com.brilliance.swift.vo.common.CdtDbtCode;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field60F;
import com.prowidesoftware.swift.model.field.Field60M;
import com.prowidesoftware.swift.model.field.Field62F;
import com.prowidesoftware.swift.model.field.Field62M;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Camt053001Parse62Field extends AbstractMt2MxCamt053001ParseField {
private static final String NAME_F = "62F";
private static final String NAME_M = "62M";
@Override
public void parseField() throws SwiftException {
try {
Field62F field62F = null;
Field62M field62M = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag60 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_F);
if (tag60 != null) {
field62F = (Field62F) tag60.asField();
}
tag60 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_M);
if (tag60 != null) {
field62M = (Field62M) tag60.asField();
}
Map<String, Object> balMaps = null;
JSONArray balJsonArray = null;
if(stmtMaps.containsKey("bal")){
balJsonArray = (JSONArray) stmtMaps.get("bal");
balMaps = new HashMap<>();
balJsonArray.add(balMaps);
}else {
balJsonArray = new JSONArray();
balMaps = new HashMap<>();
stmtMaps.put("bal",balJsonArray);
balJsonArray.add(balMaps);
}
Map<String, Object> tpMaps = new HashMap<>();
balMaps.put("tp",tpMaps);
Map<String, Object> cdOrPrtryMaps = new HashMap<>();
tpMaps.put("cdOrPrtry",cdOrPrtryMaps);
Map<String, Object> subTpMaps = new HashMap<>();
tpMaps.put("subTp",subTpMaps);
subTpMaps.put("cd", BalanceSubTypeCode.INTM);
cdOrPrtryMaps.put("cd", BalanceTypeCode.CLBD);
Map<String, Object> dtMaps = null;
if(balMaps.containsKey("dt")){
dtMaps = (Map<String, Object>)balMaps.get("dt");
}else {
dtMaps = new HashMap<>();
balMaps.put("dt",dtMaps);
}
Map<String, Object> amtMaps = null;
if(balMaps.containsKey("amt")){
amtMaps = (Map<String, Object>)balMaps.get("amt");
}else {
amtMaps = new HashMap<>();
balMaps.put("amt",amtMaps);
}
if (field62F != null) {
if ("D".equals(field62F.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.DBIT);
} else if ("C".equals(field62F.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.CRDT);
}
Date date = DateUtil.parseDate("20" + field62F.getDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
dtMaps.put("dt",dateStr);
amtMaps.put("value",field62F.amount());
amtMaps.put("ccy",field62F.getCurrency());
}
if (field62M != null) {
if ("D".equals(field62M.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.DBIT);
} else if ("C".equals(field62M.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.CRDT);
}
Date date = DateUtil.parseDate("20" + field62M.getDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
dtMaps.put("dt",dateStr);
amtMaps.put("value",field62M.amount());
amtMaps.put("ccy",field62M.getCurrency());
}
} catch (ParseException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.vo.common.BalanceTypeCode;
import com.brilliance.swift.vo.common.CdtDbtCode;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field60F;
import com.prowidesoftware.swift.model.field.Field60M;
import com.prowidesoftware.swift.model.field.Field64;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Camt053001Parse64Field extends AbstractMt2MxCamt053001ParseField {
private static final String NAME_F = "64";
@Override
public void parseField() throws SwiftException {
try {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag60 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_F);
if (tag60 != null) {
Field64 field64 = (Field64) tag60.asField();
Map<String, Object> balMaps = null;
JSONArray balJsonArray = null;
if(stmtMaps.containsKey("bal")){
balJsonArray = (JSONArray) stmtMaps.get("bal");
balMaps = new HashMap<>();
balJsonArray.add(balMaps);
}else {
balJsonArray = new JSONArray();
balMaps = new HashMap<>();
stmtMaps.put("bal",balJsonArray);
balJsonArray.add(balMaps);
}
Map<String, Object> tpMaps = new HashMap<>();
balMaps.put("tp",tpMaps);
Map<String, Object> cdOrPrtryMaps = new HashMap<>();
tpMaps.put("cdOrPrtry",cdOrPrtryMaps);
cdOrPrtryMaps.put("cd", BalanceTypeCode.CLAV);
Map<String, Object> dtMaps = null;
if(balMaps.containsKey("dt")){
dtMaps = (Map<String, Object>)balMaps.get("dt");
}else {
dtMaps = new HashMap<>();
balMaps.put("dt",dtMaps);
}
Map<String, Object> amtMaps = null;
if(balMaps.containsKey("amt")){
amtMaps = (Map<String, Object>)balMaps.get("amt");
}else {
amtMaps = new HashMap<>();
balMaps.put("amt",amtMaps);
}
if ("D".equals(field64.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.DBIT);
} else if ("C".equals(field64.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.CRDT);
}
Date date = DateUtil.parseDate("20" + field64.getDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
dtMaps.put("dt",dateStr);
amtMaps.put("value",field64.amount());
amtMaps.put("ccy",field64.getCurrency());
}
} catch (ParseException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.vo.common.BalanceTypeCode;
import com.brilliance.swift.vo.common.CdtDbtCode;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field64;
import com.prowidesoftware.swift.model.field.Field65;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Camt053001Parse65Field extends AbstractMt2MxCamt053001ParseField {
private static final String NAME_F = "65";
@Override
public void parseField() throws SwiftException {
try {
AbstractMT abstractMT = context.get(AbstractMT.class);
if("950".equals(abstractMT.getMessageType())){
return;
}
Tag tag60 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_F);
if (tag60 != null) {
Field65 field65 = (Field65) tag60.asField();
Map<String, Object> balMaps = null;
JSONArray balJsonArray = null;
if(stmtMaps.containsKey("bal")){
balJsonArray = (JSONArray) stmtMaps.get("bal");
balMaps = new HashMap<>();
balJsonArray.add(balMaps);
}else {
balJsonArray = new JSONArray();
balMaps = new HashMap<>();
stmtMaps.put("bal",balJsonArray);
balJsonArray.add(balMaps);
}
Map<String, Object> tpMaps = new HashMap<>();
balMaps.put("tp",tpMaps);
Map<String, Object> cdOrPrtryMaps = new HashMap<>();
tpMaps.put("cdOrPrtry",cdOrPrtryMaps);
cdOrPrtryMaps.put("cd", BalanceTypeCode.FWAV);
Map<String, Object> dtMaps = null;
if(balMaps.containsKey("dt")){
dtMaps = (Map<String, Object>)balMaps.get("dt");
}else {
dtMaps = new HashMap<>();
balMaps.put("dt",dtMaps);
}
Map<String, Object> amtMaps = null;
if(balMaps.containsKey("amt")){
amtMaps = (Map<String, Object>)balMaps.get("amt");
}else {
amtMaps = new HashMap<>();
balMaps.put("amt",amtMaps);
}
if ("D".equals(field65.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.DBIT);
} else if ("C".equals(field65.getDCMark())) {
balMaps.put("CdtDbtInd", CdtDbtCode.CRDT);
}
Date date = DateUtil.parseDate("20" + field65.getDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
dtMaps.put("dt",dateStr);
amtMaps.put("value",field65.amount());
amtMaps.put("ccy",field65.getCurrency());
}
} catch (ParseException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
package com.brilliance.swift.mt2mx.camt053001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt053001.AbstractMt2MxCamt053001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field86;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.List;
public class Camt053001Parse86Field extends AbstractMt2MxCamt053001ParseField {
private static final String NAME = "86";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
if("950".equals(abstractMT.getMessageType())){
return;
}
Tag[] tag86 = abstractMT.getSwiftMessage().getBlock4().getTagsByName(NAME);
List<Tag> tags = abstractMT.getSwiftMessage().getBlock4().getTags();
if (tags != null) {
for (int i = 1;i < tags.size(); i++) {
if(!tags.get(i-1).getName().equals("61")&&tags.get(i).getName().equals("86")){
Field86 field86 = (Field86) tag86[tag86.length-1].asField();
stmtMaps.put("addtlStmtInf",field86.getValue().replace("\r\n",""));
}
}
}
}
}
......@@ -18,9 +18,9 @@ public abstract class AbstractMt2MxCamt054001ParseField extends AbstractMt2MxPar
public void initJsonMaps() {
super.initJsonMaps();
appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
Map<String, Object> BkToCstmrDbtCdtNtfctnMaps = (Map<String, Object>)jsonMaps.get("bkToCstmrDbtCdtNtfctn");
grpHdrMaps = (Map<String, Object>)BkToCstmrDbtCdtNtfctnMaps.get("grpHdr");
JSONArray ntfctnJsonArray = (JSONArray) BkToCstmrDbtCdtNtfctnMaps.get("ntfctn");
Map<String, Object> bkToCstmrDbtCdtNtfctnMaps = (Map<String, Object>)jsonMaps.get("bkToCstmrDbtCdtNtfctn");
grpHdrMaps = (Map<String, Object>)bkToCstmrDbtCdtNtfctnMaps.get("grpHdr");
JSONArray ntfctnJsonArray = (JSONArray) bkToCstmrDbtCdtNtfctnMaps.get("ntfctn");
ntfctnMaps = (Map<String, Object>)ntfctnJsonArray.get(0);
}
......
......@@ -50,7 +50,7 @@ public class Mt2MxCamt056001Creator extends AbstractMt2MxCreator {
if (StringUtil.isNotEmpty(orgnlUETR)) {
txInfMaps.put("orgnlUETR", orgnlUETR);
}
txInfMaps.put("orgnlEndToEndId",Mx2MtConstants.MT_TO_MX_DEFAULT_VALUE);
String sendBic = (String) context.get(Mt2MxContextIdentifier.MT_SEND_BIC, true);
if (StringUtil.isNotEmpty(sendBic)) {
Map<String, Object> assgnrMaps = new HashMap<>();
......@@ -68,11 +68,11 @@ public class Mt2MxCamt056001Creator extends AbstractMt2MxCreator {
mt_to_mxBICFI(receiverBic, agtMaps);
}
Map<String, Object> caseMaps = null;
if(txInfMaps.containsKey("case")){
caseMaps = (Map<String, Object>) txInfMaps.get("case");
if(txInfMaps.containsKey("_case")){
caseMaps = (Map<String, Object>) txInfMaps.get("_case");
}else {
caseMaps = new HashMap<>();
txInfMaps.put("case",caseMaps);
txInfMaps.put("_case",caseMaps);
}
Map<String, Object> cretrMaps = new HashMap<>();
Map<String, Object> agtMaps = new HashMap<>();
......
......@@ -22,11 +22,11 @@ public class Camt056001Parse20Field extends AbstractMt2MxCamt056001ParseField {
assgnmtMaps.put("id",tag20.getValue());
Map<String, Object> txInfMaps = getTxInfMaps();
Map<String, Object> caseMaps = null;
if(txInfMaps.containsKey("case")){
caseMaps = (Map<String, Object>) txInfMaps.get("case");
if(txInfMaps.containsKey("_case")){
caseMaps = (Map<String, Object>) txInfMaps.get("_case");
}else {
caseMaps = new HashMap<>();
txInfMaps.put("case",caseMaps);
txInfMaps.put("_case",caseMaps);
}
caseMaps.put("id",tag20.getValue());
}
......
......@@ -18,7 +18,7 @@ public class Camt056001Parse21Field extends AbstractMt2MxCamt056001ParseField {
Tag tag21 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag21 != null) {
Map<String, Object> txInfMaps = getTxInfMaps();
txInfMaps.put("OrgnlInstrId",tag21.getValue());
txInfMaps.put("orgnlInstrId",tag21.getValue());
Map<String, Object> orgnlGrpInfMaps = null;
if(txInfMaps.containsKey("orgnlGrpInf")){
orgnlGrpInfMaps = (Map<String, Object>)txInfMaps.get("orgnlGrpInf");
......
package com.brilliance.mx2mt.mt940;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mx2mt.Mx2MtCreatorManager;
import com.brilliance.swift.vo.SwiftTranslationErrorInfo;
import com.brilliance.swift.vo.SwiftTranslationReport;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.net.URL;
import java.util.List;
public class Mx2Mt940 {
public static void main(String[] args) {
public static void main(String[] args) throws Exception{
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\camt05300108_950.xml");
String xmlStr = FileUtils.readFileToString(file);
SwiftTranslationReport str = SwiftTransfer.mx2MtPlus(xmlStr, null, null);
if (str != null) {
List<SwiftTranslationErrorInfo> errorInfos = str.getErrorInfos();
if (errorInfos != null && errorInfos.size() > 0) {
for (int i=0; i<errorInfos.size(); i++) {
SwiftTranslationErrorInfo errorInfo = errorInfos.get(i);
String location = errorInfo.getLocation();
String errorType = errorInfo.getErrorType();
String description = errorInfo.getDescription();
System.out.println(location + Mx2MtConstants.NEW_LINE + "-" + errorType + ":" + description);
}
}
System.out.println(str.getMessage());
}
}
}
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