Commit a61b6569 by chengzhuoshen

增加MT920转CAMT06000105.xml的代码

parent 0889c5e3
......@@ -7,6 +7,7 @@ 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.camt057001.Mt2MxCamt057001Creator;
import com.brilliance.swift.mt2mx.camt060001.Mt2MxCamt060001Creator;
import com.brilliance.swift.mt2mx.pacs002001.Mt2MxPacs002001Creator;
import com.brilliance.swift.mt2mx.pacs004001.Mt2MxPacs004001Creator;
import com.brilliance.swift.mt2mx.pacs008001.Mt2MxPacs008001Creator;
......@@ -70,12 +71,13 @@ public class Mt2MxCreatorManager {
return new Mt2MxCamt054001Creator();
} else if("940".equals(messageType)||"950".equals(messageType)) {
return new Mt2MxCamt053001Creator();
}else if("942".equals(messageType)){
} else if("942".equals(messageType)){
return new Mt2MxCamt052001Creator();
}else if("210".equals(messageType)){
} else if("210".equals(messageType)){
return new Mt2MxCamt057001Creator();
}
else {
} else if ("920".equals(messageType)) {
return new Mt2MxCamt060001Creator();
} else {
throw new SwiftException("Invalid message type");
}
}
......
package com.brilliance.swift.mt2mx.camt060001;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.mt2mx.AbstractMt2MxParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public abstract class AbstractMt2MxCamt060001ParseField extends AbstractMt2MxParseField {
protected Map<String, Object> appHdrMaps = null;
protected Map<String, Object> grpHdrMaps = null;
protected JSONArray rptgReqJsonArray = null;
protected List<List<Tag>> list = new ArrayList<>();
@Override
public void initJsonMaps() {
super.initJsonMaps();
appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
Map<String, Object> acctRptgReqMaps = (Map<String, Object>)jsonMaps.get("acctRptgReq");
grpHdrMaps = (Map<String, Object>)acctRptgReqMaps.get("grpHdr");
rptgReqJsonArray = (JSONArray) acctRptgReqMaps.get("rptgReq");
List<Tag> tags = null;
List<Tag> tagList = context.get(AbstractMT.class).getSwiftMessage().getBlock4().getTags();
for (int i=0; i<tagList.size(); i++) {
Tag tag = tagList.get(i);
if ("12".equals(tag.getName())) {
tags = new ArrayList<>();
tags.add(tag);
list.add(tags);
} else if (tags != null){
tags.add(tag);
}
}
}
}
package com.brilliance.swift.mt2mx.camt060001;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.mt2mx.AbstractMt2MxCreator;
import com.brilliance.swift.mt2mx.Mt2MxParseField;
import com.brilliance.swift.mt2mx.camt060001.impl.*;
import com.prowidesoftware.swift.model.Tag;
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 Mt2MxCamt060001Creator extends AbstractMt2MxCreator {
@Override
public void preProcess() {
super.preProcess();
jsonMaps.put("identifier", "camt.060.001.05");
Map<String, Object> appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
appHdrMaps.put("msgDefIdr", "camt.060.001.05");
appHdrMaps.put("bizSvc", "swift.cbprplus.02");
Map<String, Object> acctRptgReqMaps = new HashMap<>();
jsonMaps.put("acctRptgReq", acctRptgReqMaps);
Map<String, Object> grpHdrMaps = new HashMap<>();
acctRptgReqMaps.put("grpHdr", grpHdrMaps);
grpHdrMaps.put("creDtTm", getCreateDateStr());
JSONArray rptgReqJsonArray = new JSONArray();
acctRptgReqMaps.put("rptgReq", rptgReqJsonArray);
}
@Override
public List<Mt2MxParseField> getParseFieldList() {
List<Mt2MxParseField> list = new ArrayList<>();
list.add(new Camt060001Parse20Field());
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag[] tags = abstractMT.getSwiftMessage().getBlock4().getTagsByName("12");
if (tags != null && tags.length > 0) {
for (int i=0; i<tags.length; i++) {
list.add(new Camt060001Parse12Field(i));
list.add(new Camt060001Parse25Field(i));
list.add(new Camt060001Parse34FField(i));
}
}
return list;
}
}
package com.brilliance.swift.mt2mx.camt060001.impl;
import com.brilliance.swift.mt2mx.camt060001.AbstractMt2MxCamt060001ParseField;
import com.prowidesoftware.swift.model.Tag;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Camt060001Parse12Field extends AbstractMt2MxCamt060001ParseField {
private static final String NAME = "12";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
public Camt060001Parse12Field(int index) {
this.index = index;
}
@Override
public void parseField() {
List<Tag> tags = list.get(index);
if (tags != null && tags.size() > 0) {
Tag tag = null;
for (int i=0; i<tags.size(); i++) {
if (NAME.equals(tags.get(i).getName())) {
tag = tags.get(i);
break;
}
}
if (tag != null) {
Map<String, Object> rptgReqMaps = null;
if (rptgReqJsonArray.size() == (index+1)) {
rptgReqMaps = (Map<String, Object>)rptgReqJsonArray.get(index);
} else {
rptgReqMaps = new HashMap<>();
rptgReqJsonArray.add(rptgReqMaps);
}
rptgReqMaps.put("reqdMsgNmId", "MT"+tag.getValue());
}
}
}
}
package com.brilliance.swift.mt2mx.camt060001.impl;
import com.brilliance.swift.mt2mx.camt060001.AbstractMt2MxCamt060001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
public class Camt060001Parse20Field extends AbstractMt2MxCamt060001ParseField {
private static final String NAME = "20";
@Override
public void parseField() {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag20 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag20 != null) {
grpHdrMaps.put("msgId", tag20.getValue());
appHdrMaps.put("bizMsgIdr", tag20.getValue());
}
}
}
package com.brilliance.swift.mt2mx.camt060001.impl;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.camt060001.AbstractMt2MxCamt060001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.Tag;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Camt060001Parse25Field extends AbstractMt2MxCamt060001ParseField {
private static final String NAME = "25";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
public Camt060001Parse25Field(int index) {
this.index = index;
}
@Override
public void parseField() {
List<Tag> tags = list.get(index);
if (tags != null && tags.size() > 0) {
Tag tag = null;
for (int i=0; i<tags.size(); i++) {
if (NAME.equals(tags.get(i).getName())) {
tag = tags.get(i);
break;
}
}
if (tag != null) {
Map<String, Object> rptgReqMaps = null;
if (rptgReqJsonArray.size() == (index+1)) {
rptgReqMaps = (Map<String, Object>)rptgReqJsonArray.get(index);
} else {
rptgReqMaps = new HashMap<>();
rptgReqJsonArray.add(rptgReqMaps);
}
Map<String, Object> acctMaps = null;
if (rptgReqMaps.containsKey("acct")) {
acctMaps = (Map<String, Object>)rptgReqMaps.get("acct");
} else {
acctMaps = new HashMap<>();
rptgReqMaps.put("acct", acctMaps);
}
mt_to_mxAccount35(tag.getValue(), acctMaps,"AcctRptgReq/RptgReq/Acct/Id/Othr/Id");
String sendBic = (String) context.get(Mt2MxContextIdentifier.MT_SEND_BIC, true);
if (StringUtil.isNotEmpty(sendBic)) {
Map<String, Object> acctOwnrMaps = new HashMap<>();
rptgReqMaps.put("acctOwnr", acctOwnrMaps);
Map<String, Object> agtMaps = new HashMap<>();
acctOwnrMaps.put("agt", agtMaps);
mt_to_mxBICFI(sendBic, agtMaps);
}
}
}
}
}
package com.brilliance.swift.mt2mx.camt060001.impl;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.mt2mx.camt060001.AbstractMt2MxCamt060001ParseField;
import com.brilliance.swift.vo.common.CdtDbtCode;
import com.brilliance.swift.vo.common.EntryStatusCode;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field34F;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Camt060001Parse34FField extends AbstractMt2MxCamt060001ParseField {
private static final String NAME = "34F";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
public Camt060001Parse34FField(int index) {
this.index = index;
}
@Override
public void parseField() {
List<Tag> tags = list.get(index);
if (tags != null && tags.size() > 0) {
List<Tag> tag34List = new ArrayList<>();
for (int i=0; i<tags.size(); i++) {
if (NAME.equals(tags.get(i).getName())) {
tag34List.add(tags.get(i));
}
}
if (tag34List.size() > 0) {
Map<String, Object> rptgReqMaps = null;
if (rptgReqJsonArray.size() == (index+1)) {
rptgReqMaps = (Map<String, Object>)rptgReqJsonArray.get(index);
} else {
rptgReqMaps = new HashMap<>();
rptgReqJsonArray.add(rptgReqMaps);
}
Map<String, Object> reqdTxTpMaps = null;
if (rptgReqMaps.containsKey("reqdTxTp")) {
reqdTxTpMaps = (Map<String, Object>)rptgReqMaps.get("reqdTxTp");
} else {
reqdTxTpMaps = new HashMap<>();
rptgReqMaps.put("reqdTxTp", reqdTxTpMaps);
}
//设置 Status节点
Map<String, Object> stsMaps = null;
if (reqdTxTpMaps.containsKey("sts")) {
stsMaps = (Map<String, Object>)reqdTxTpMaps.get("sts");
} else {
stsMaps = new HashMap<>();
reqdTxTpMaps.put("sts", stsMaps);
}
stsMaps.put("cd", EntryStatusCode.INFO.value());
BigDecimal crAmt = BigDecimal.ZERO;
BigDecimal drAmt = BigDecimal.ZERO;
JSONArray flrLmtJsonArray = null;
if (reqdTxTpMaps.containsKey("flrLmt")) {
flrLmtJsonArray = (JSONArray)reqdTxTpMaps.get("flrLmt");
} else {
flrLmtJsonArray = new JSONArray();
reqdTxTpMaps.put("flrLmt", flrLmtJsonArray);
}
for (Tag tag : tag34List) {
Map<String, Object> flrLmtMaps = new HashMap<>();
Field34F field34 = (Field34F)tag.asField();
if ("C".equals(field34.getDCMark())) {
crAmt = crAmt.add(field34.amount());
flrLmtMaps.put("cdtDbtInd", "CRED");
} else {
drAmt = drAmt.add(field34.amount());
flrLmtMaps.put("cdtDbtInd", "DEBT");
}
Map<String, Object> amtMaps = new HashMap<>();
amtMaps.put("ccy", field34.getCurrency());
amtMaps.put("value", field34.amount());
flrLmtMaps.put("amt", amtMaps);
flrLmtJsonArray.add(flrLmtMaps);
}
if (crAmt.compareTo(drAmt) > -1) {
reqdTxTpMaps.put("cdtDbtInd", CdtDbtCode.CRDT.value());
} else {
reqdTxTpMaps.put("cdtDbtInd", CdtDbtCode.DBIT.value());
}
}
}
}
}
......@@ -11,7 +11,7 @@ import java.util.List;
public class Field34CGenerate extends AbstractMx2MtTagsGenerate {
private static String NAME = "34";
private static String NAME = "34F";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
......
......@@ -11,7 +11,7 @@ import java.util.List;
public class Field34DGenerate extends AbstractMx2MtTagsGenerate {
private static String NAME = "34";
private static String NAME = "34F";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
......
......@@ -56,23 +56,30 @@ Change Log
</Othr>
</Id>
</Acct>
<AcctOwnr>
<Agt>
<FinInstnId>
<BICFI>ABNANL2A</BICFI>
</FinInstnId>
</Agt>
</AcctOwnr>
<ReqdTxTp>
<Sts>
<Cd>PDNG</Cd>
<Cd>INFO</Cd>
</Sts>
<CdtDbtInd>CRDT</CdtDbtInd>
<FlrLmt>
<Amt Ccy="KWR">123.45</Amt>
<Amt Ccy="USD">123.45</Amt>
<CdtDbtInd>DEBT</CdtDbtInd>
</FlrLmt>
<FlrLmt>
<Amt Ccy="KWR">3456.50</Amt>
<Amt Ccy="USD">3456.50</Amt>
<CdtDbtInd>CRED</CdtDbtInd>
</FlrLmt>
</ReqdTxTp>
</RptgReq>
<RptgReq>
<Id>cmt060bizmsgidr-001</Id>
<Id>cmt060bizmsgidr-002</Id>
<ReqdMsgNmId>camt.052.001.08</ReqdMsgNmId>
<Acct>
<Id>
......@@ -90,15 +97,15 @@ Change Log
</AcctOwnr>
<ReqdTxTp>
<Sts>
<Cd>PDNG</Cd>
<Cd>INFO</Cd>
</Sts>
<CdtDbtInd>CRDT</CdtDbtInd>
<CdtDbtInd>DBIT</CdtDbtInd>
<FlrLmt>
<Amt Ccy="KWD">7878.5687</Amt>
<Amt Ccy="USD">7878.56</Amt>
<CdtDbtInd>DEBT</CdtDbtInd>
</FlrLmt>
<FlrLmt>
<Amt Ccy="KWD">1234.4563</Amt>
<Amt Ccy="USD">1234.46</Amt>
<CdtDbtInd>CRED</CdtDbtInd>
</FlrLmt>
</ReqdTxTp>
......
package com.brilliance.mt2mx.camt060001;
import com.brilliance.swift.SwiftTransfer;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
File file = new File("D:/test/MT920.txt");
String mtStr = FileUtils.readFileToString(file);
String xmlStr = SwiftTransfer.mt2Mx(mtStr, null, null);
System.out.println(xmlStr);
}
}
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