Commit e246d27b by zhanghou

开发camt05800108

parent f99f1114
...@@ -28,6 +28,8 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate { ...@@ -28,6 +28,8 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
protected String bodyHdrParentElementName; protected String bodyHdrParentElementName;
protected String bodyHdrParentElementName2;
public Mx2MtContext getContext() { public Mx2MtContext getContext() {
return context; return context;
} }
...@@ -38,6 +40,7 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate { ...@@ -38,6 +40,7 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
appHdrParentElementName = (String) context.get(Mx2MtContextIdentifier.APPHDR_PARENT_ELEMENT_NAME, true); appHdrParentElementName = (String) context.get(Mx2MtContextIdentifier.APPHDR_PARENT_ELEMENT_NAME, true);
grpHdrParentElementName = (String) context.get(Mx2MtContextIdentifier.GRPHDR_PARENT_ELEMENT_NAME, true); grpHdrParentElementName = (String) context.get(Mx2MtContextIdentifier.GRPHDR_PARENT_ELEMENT_NAME, true);
bodyHdrParentElementName = (String) context.get(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, true); bodyHdrParentElementName = (String) context.get(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, true);
bodyHdrParentElementName2 = (String) context.get(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME2, true);
return this; return this;
} }
......
...@@ -16,6 +16,8 @@ public class Mx2MtContextIdentifier { ...@@ -16,6 +16,8 @@ public class Mx2MtContextIdentifier {
public static final String BODY_PARENT_ELEMENT_NAME = "body.parent.element.name"; public static final String BODY_PARENT_ELEMENT_NAME = "body.parent.element.name";
public static final String BODY_PARENT_ELEMENT_NAME2 = "body.parent.element.name2";
public static final String MX_SENDER_BIC = "mx.sender.bic"; public static final String MX_SENDER_BIC = "mx.sender.bic";
public static final String MX_RECEIVER_BIC = "mx.receiver.bic"; public static final String MX_RECEIVER_BIC = "mx.receiver.bic";
......
...@@ -11,6 +11,7 @@ import com.brilliance.swift.mx2mt.mt202Retn.Mx2Mt202RetnCreator; ...@@ -11,6 +11,7 @@ import com.brilliance.swift.mx2mt.mt202Retn.Mx2Mt202RetnCreator;
import com.brilliance.swift.mx2mt.mt202Retn.Mx2Mt205RetnCreator; import com.brilliance.swift.mx2mt.mt202Retn.Mx2Mt205RetnCreator;
import com.brilliance.swift.mx2mt.mt202cov202.Mx2Mt202Creator; import com.brilliance.swift.mx2mt.mt202cov202.Mx2Mt202Creator;
import com.brilliance.swift.mx2mt.mt210.Mx2Mt210Creator; import com.brilliance.swift.mx2mt.mt210.Mx2Mt210Creator;
import com.brilliance.swift.mx2mt.mt292.Mx2Mt292Creator;
import com.brilliance.swift.mx2mt.mt900910.Mx2Mt900910Creator; import com.brilliance.swift.mx2mt.mt900910.Mx2Mt900910Creator;
import com.brilliance.swift.mx2mt.mt920.Mx2Mt920Creator; import com.brilliance.swift.mx2mt.mt920.Mx2Mt920Creator;
import com.brilliance.swift.mx2mt.mt940950.Mx2Mt940950Creator; import com.brilliance.swift.mx2mt.mt940950.Mx2Mt940950Creator;
...@@ -119,7 +120,10 @@ public class Mx2MtCreatorManager { ...@@ -119,7 +120,10 @@ public class Mx2MtCreatorManager {
return new Mx2MtN99Creator(); return new Mx2MtN99Creator();
} else if("camt060001".equals(messageType)){ } else if("camt060001".equals(messageType)){
return new Mx2Mt920Creator(); return new Mx2Mt920Creator();
} else { } else if("camt058001".equals(messageType)){
return new Mx2Mt292Creator();
}
else {
throw new SwiftException("Invalid message type"); throw new SwiftException("Invalid message type");
} }
} }
......
package com.brilliance.swift.mx2mt.mt292;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtCreator;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
import com.brilliance.swift.mx2mt.Mx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.mt292.impl.Field11SGenerate;
import com.brilliance.swift.mx2mt.mt292.impl.Field20Generate;
import com.brilliance.swift.mx2mt.mt292.impl.Field21Generate;
import com.brilliance.swift.mx2mt.mt292.impl.Field79Generate;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import com.prowidesoftware.swift.model.SwiftBlock3;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.field.Field121;
import org.dom4j.Document;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Mx2Mt292Creator extends AbstractMx2MtCreator {
@Override
public void preProcess() {
super.preProcess();
Document document = (Document)context.get(Mx2MtContextIdentifier.MX_XMl_DOCUMENT, true);
Map<String, String> parentElementMaps = XmlUtil.getParentElementMaps(document);
context.set(Mx2MtContextIdentifier.APPHDR_PARENT_ELEMENT_NAME, parentElementMaps.get("AppHdr"));
context.set(Mx2MtContextIdentifier.GRPHDR_PARENT_ELEMENT_NAME, parentElementMaps.get("GrpHdr"));
context.set(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, parentElementMaps.get("OrgnlNtfctn"));
context.set(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME2, parentElementMaps.get("CxlRsn"));
}
@Override
public void withBlock3() throws SwiftException {
super.withBlock3();
SwiftBlock3 block3 = context.get(SwiftMessage.class).getBlock3();
Document document = (Document)context.get(Mx2MtContextIdentifier.MX_XMl_DOCUMENT, true);
String bodyParentPath = (String)context.get(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, true);
int orgnlItmCount = getXmlNodeCounts(bodyParentPath, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm");
if(orgnlItmCount>0){
String uetr = getXmlNodeValue(bodyParentPath, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm(0).UETR");
if (StringUtil.isNotEmpty(uetr)) {
Field121 field121 = new Field121(uetr);
block3.builder().setField121(field121);
}
}
}
@Override
public List<Mx2MtTagsGenerate> getGenerateTagList() {
List<Mx2MtTagsGenerate> fieldsGenerateList = new ArrayList<>();
fieldsGenerateList.add(new Field20Generate());
fieldsGenerateList.add(new Field21Generate());
fieldsGenerateList.add(new Field11SGenerate());
fieldsGenerateList.add(new Field79Generate());
return fieldsGenerateList;
}
@Override
protected String getMtType() {
return Mx2MtConstants.MT_TYPE_292;
}
}
package com.brilliance.swift.mx2mt.mt292.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.List;
/**
*
*/
public class Field11SGenerate extends AbstractMx2MtTagsGenerate {
private static String name = "11S";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String field11S = "210";
String mtDate = "991231";
String dateStr = getXmlNodeValue(bodyHdrParentElementName, document, "OrgnlNtfctn.OrgnlCreDtTm");
if (StringUtil.isNotEmpty(dateStr)) {
try {
XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(dateStr);
mtDate = DateUtil.format(date, "yyMMdd");
} catch (DatatypeConfigurationException e) {
throw new SwiftException(e.getMessage());
}
}
if("991231".equals(mtDate)){
buildSTErrorInfo(119,"Block4/:11S:",mtDate);
}
tags.add(new Tag(name, field11S + Mx2MtConstants.NEW_LINE + mtDate));
}
}
package com.brilliance.swift.mx2mt.mt292.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.List;
/**
* GrpHdr.MsgId
* AppHdr.BizMsgIdr
*/
public class Field20Generate extends AbstractMx2MtTagsGenerate {
private static String name = "20";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String messageId = getXmlNodeValue(grpHdrParentElementName, document, "GrpHdr.MsgId");
if (StringUtil.isEmpty(messageId)) {
messageId = getXmlNodeValue(appHdrParentElementName, document, "AppHdr.BizMsgIdr");
}
if (StringUtil.isNotEmpty(messageId)) {
if (messageId.length() > 16) {
buildSTErrorInfo(13, "Block4/:20:", messageId);
messageId = messageId.substring(0, 15) + "+";
}
tags.add(new Tag(name, messageId));
}
}
}
package com.brilliance.swift.mx2mt.mt292.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.List;
/**
* 取值逻辑:
* field21 = OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm.OrgnlItmId,如果长度大于16,field21 = field21截取15位 + 最后一位用+代替
* 如果filed21 以/开始或者以/结束或者包含//,field21=NONREF
* 否则保持原值不变
*/
public class Field21Generate extends AbstractMx2MtTagsGenerate {
private static String name = "21";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
int orgnlItmCount = getXmlNodeCounts(bodyHdrParentElementName, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm");
if(orgnlItmCount>0){
String orgnlItmId = getXmlNodeValue(bodyHdrParentElementName, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm(0).OrgnlItmId");
if (StringUtil.isNotEmpty(orgnlItmId)) {
if (orgnlItmId.length() > 16) {
buildSTErrorInfo(13, "Block4/:21:", orgnlItmId);
orgnlItmId = orgnlItmId.substring(0, 15) + "+";
}
tags.add(new Tag(name, orgnlItmId));
}
}
}
}
package com.brilliance.swift.mx2mt.mt292.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.NumberUtil;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field121;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*/
public class Field79Generate extends AbstractMx2MtTagsGenerate {
private static String name_79 = "79";
private static String name_30 = "30";
private static String name_32 = "32B";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
boolean flag30 = false;
boolean flag32B = false;
String mtValDtStr = "";
String amtStr = "";
String ccyStr = "";
int orgnlItmCount = getXmlNodeCounts(bodyHdrParentElementName, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm");
if(orgnlItmCount>0){
String valDtStr = getXmlNodeValue(bodyHdrParentElementName, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm(0).XpctdValDt");
if (StringUtil.isNotEmpty(valDtStr)) {
try {
XMLGregorianCalendar valDt = DatatypeFactory.newInstance().newXMLGregorianCalendar(valDtStr);
mtValDtStr = DateUtil.format(valDt, "yyMMdd");
flag30 = true;
} catch (DatatypeConfigurationException e) {
throw new SwiftException(e.getMessage());
}
}
amtStr = getXmlNodeValue(bodyHdrParentElementName, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm(0).Amt");
ccyStr = getXmlNodeValue(bodyHdrParentElementName, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm(0).Amt@Ccy");
if (StringUtil.isNotEmpty(amtStr) && StringUtil.isNotEmpty(ccyStr)) {
if (NumberUtil.judgeAmtStrExceedLength(amtStr, 14)) {
buildSTErrorInfo(36, "Block4/:"+name_32+":", amtStr);
}
flag32B = true;
}
String uetr = getXmlNodeValue(bodyHdrParentElementName2, document, "OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm(0).UETR");
String mxReasonCode = getXmlNodeValue(bodyHdrParentElementName2, document, "CxlRsn.Rsn.Cd");
int addtlInfCount = getXmlNodeCounts(bodyHdrParentElementName2, document, "CxlRsn.AddtlInf");
String mxAddtlInf = "";
if (addtlInfCount > 0) {
for (int i=0; i<addtlInfCount; i++) {
if (i == 2) break;
String addtlInf = getXmlNodeValue(bodyHdrParentElementName2, document, "CxlRsn.AddtlInf("+i+")");
if (i == 0) {
mxAddtlInf += addtlInf;
} else {
if (getXmlNodeValue(bodyHdrParentElementName2, document, "CxlRsn.AddtlInf("+(i-1)+")").length() > 104) {
mxAddtlInf += addtlInf;
} else {
mxAddtlInf += " " + addtlInf;
}
}
}
}
String mt79 = "";
if(StringUtil.isNotEmpty(mxReasonCode)){
if(StringUtil.isNotEmpty(mxAddtlInf)&&mxAddtlInf.length()>=6){
Pattern r = Pattern.compile("/[0-9,A-Z]{4}/");
Matcher m = r.matcher(mxAddtlInf.substring(0,6));
if("NARR".equals(mxReasonCode)&&m.matches()){
mt79 += mxAddtlInf;
}else {
mt79 += "/" + mxReasonCode + "/" + mxAddtlInf;
}
}
}
List<String> list = new ArrayList<>();
if (StringUtil.isNotEmpty(mt79)) {
list.addAll(StringUtil.outStringList(mt79, 50, "//"));
}
if(StringUtil.isNotEmpty(uetr)){
list.add("/UETR/" + uetr);
}
String value = "";
for (int i=0; i<list.size(); i++) {
if (i == 35) break;
if (i == 0) {
value = list.get(i);
} else {
value += Mx2MtConstants.NEW_LINE + list.get(i);
}
}
value = mx_to_mtStartingLineCharacter(value, "Block4/:79:");
tags.add(new Tag(name_79, value));
if(StringUtil.isNotEmpty(value)){
if(flag30){
tags.add(new Tag(name_30, mtValDtStr));
}
if(flag32B){
tags.add(new Tag(name_32, ccyStr + NumberUtil.formatAmt(new BigDecimal(amtStr), ccyStr)));
}
}
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<RequestPayload>
<AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001.02">
<Fr>
<FIId>
<FinInstnId>
<BICFI>HELSFIHHXXX</BICFI>
</FinInstnId>
</FIId>
</Fr>
<To>
<FIId>
<FinInstnId>
<BICFI>NDEAFIHHXXX</BICFI>
</FinInstnId>
</FIId>
</To>
<BizMsgIdr>CNCL-ID001</BizMsgIdr>
<MsgDefIdr>camt.058.001.08</MsgDefIdr>
<BizSvc>swift.cbprplus.02</BizSvc>
<CreDt>2022-07-22T10:17:51.619+08:00</CreDt>
<PssblDplct>false</PssblDplct>
<Prty>NORM</Prty>
</AppHdr>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.058.001.08">
<NtfctnToRcvCxlAdvc>
<GrpHdr>
<MsgId>CSE-001</MsgId>
<CreDtTm>2022-07-22T10:17:51.619+08:00</CreDtTm>
</GrpHdr>
<OrgnlNtfctn>
<OrgnlMsgId>CNCL-ID001</OrgnlMsgId>
<OrgnlCreDtTm>2022-07-22T10:17:51.619+08:00</OrgnlCreDtTm>
<OrgnlNtfctnId>ZZZZZZ</OrgnlNtfctnId>
<OrgnlNtfctnRef>
<OrgnlItm>
<OrgnlItmId>pacs2bizmsgidr01</OrgnlItmId>
<UETR>8a562c67-ca16-48ba-b074-65581be6f001</UETR>
<Amt Ccy="USD">111</Amt>
<XpctdValDt>2022-10-11</XpctdValDt>
</OrgnlItm>
</OrgnlNtfctnRef>
</OrgnlNtfctn>
<CxlRsn>
<Rsn>
<Cd>DUPL</Cd>
</Rsn>
<AddtlInf>11111111111111</AddtlInf>
</CxlRsn>
</NtfctnToRcvCxlAdvc>
</Document>
</RequestPayload>
\ No newline at end of file
...@@ -139,6 +139,11 @@ public class Mx2MtTest { ...@@ -139,6 +139,11 @@ public class Mx2MtTest {
} }
@Test @Test
public void test292_2() {
test("/swiftXml/camt05800108.xml", null);
}
@Test
public void testXmlFilePath() { public void testXmlFilePath() {
SwiftTranslationReport str = SwiftTransfer.mx2MtPlus("d:/test/MxPacs00800108.xml", true, null, null); SwiftTranslationReport str = SwiftTransfer.mx2MtPlus("d:/test/MxPacs00800108.xml", true, null, null);
System.out.println(str.getMessage()); 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