Commit f3d17e8a by chengzhuoshen

封装报文转换详细报告方法

parent 961ca0f0
......@@ -50,7 +50,7 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
errorInfo.setOriginalValue(originalValue);
str.addErrorInfo(errorInfo);
if ("FAILURE".equalsIgnoreCase(errorInfo.getErrorType())) {
throw new SwiftException(location + Mx2MtConstants.NEW_LINE + "-" + errorInfo.getErrorType() + ":" + errorInfo.getDescription());
throw new SwiftException(location + "-" + errorInfo.getErrorType() + ":" + errorInfo.getDescription());
}
}
......
package com.brilliance.swift.mx2mt;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.util.*;
......@@ -66,13 +67,26 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
protected void buildSTErrorInfo(String errorCode, String location, String originalValue) {
SwiftTranslationReport str = context.get(SwiftTranslationReport.class);
SwiftTranslationErrorInfo errorInfo = SwiftTransferUtil.getSwiftTranslationErrorInfoByErrorCode(errorCode);
if (StringUtil.isEmpty(location)) {
location = (String) context.get(Mx2MtContextIdentifier.MX_TO_MT_ERROR_LOCATION,true);
}
errorInfo.setLocation(location);
errorInfo.setOriginalValue(originalValue);
List<SwiftTranslationErrorInfo> errorInfos = str.getErrorInfos();
boolean existFlag = false;
for (int i=0; i<errorInfos.size(); i++) {
if (SwiftTransferUtil.compareStErrorInfo(errorInfo, errorInfos.get(i))) {
existFlag = true;
break;
}
}
if (!existFlag) {
str.addErrorInfo(errorInfo);
if ("FAILURE".equalsIgnoreCase(errorInfo.getErrorType())) {
throw new SwiftException(location + Mx2MtConstants.NEW_LINE + "-" + errorInfo.getErrorType() + ":" + errorInfo.getDescription());
}
}
}
//转换函数方法区开始
/**
......@@ -345,10 +359,12 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
if (StringUtil.isNotEmpty(bicCode)) {
if (mtClearingSystem.indexOf("FW") > -1) {
mtClearingSystem = "//FW";
buildSTErrorInfo(ERROR.T20075, null, null);
} else if (mtClearingSystem.indexOf("CP") > -1
|| mtClearingSystem.indexOf("RU") > -1
|| mtClearingSystem.indexOf("SW") > -1) {
mtClearingSystem = "";
buildSTErrorInfo(ERROR.T20076, null, null);
}
}
return mtClearingSystem;
......@@ -427,9 +443,15 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
}
int addressLineCount = XmlUtil.getChildrenCount(document, nameAddressPrefixPath + ".PstlAdr.AdrLine", null);
if (addressLineCount >= 3) {
if (mxName.length() > 35) mxName = mxName.substring(0, 34) + "+";
if (mxName.length() > 35) {
buildSTErrorInfo(ERROR.T0000T, null, mxName);
mxName = mxName.substring(0, 34) + "+";
}
} else {
if (mxName.length() > 70) mxName = mxName.substring(0, 69) + "+";
if (mxName.length() > 70) {
buildSTErrorInfo(ERROR.T0000T, null, mxName);
mxName = mxName.substring(0, 69) + "+";
}
}
int addressRemainLine = 3;//address剩余的行数
if (mxName.length() > 35) addressRemainLine = 2;
......@@ -494,6 +516,7 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
addressRemainLine = 2;
} else {
if (mxName.length() > 66) {
buildSTErrorInfo(ERROR.T0000T, null, mxName);
mtNameAddress = "1/" + mxName.substring(0, 33)
+ Mx2MtConstants.NEW_LINE
+ "1/" + mxName.substring(33, 65) + "+";
......@@ -570,13 +593,15 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
//根据剩余行数来拼接mxAddress2和mxAddress3
String mtAddress2 = "";
String mtAddress3 = "";
if (addressRemainLine == 3) {//表示name只占1行
if (addressRemainLine == 3) { //表示name只占1行
if (mxAddress2.length() > 0) { //mxAddress2存在,优先计算mxAddress3长度
if (mxAddress3.length() > 66) { //mxAddress3最多占2行 mxaddress2最多占1行
buildSTErrorInfo(ERROR.T0000T, null, mxAddress3);
mtAddress3 = "3/" + mxAddress3.substring(0, 33)
+ Mx2MtConstants.NEW_LINE
+ "3/" + mxAddress3.substring(33, 65) + "+";
if (mxAddress2.length() > 33) {
buildSTErrorInfo(ERROR.T0000T, null, mtAddress2);
mtAddress2 = "2/" + mxAddress2.substring(0, 32) + "+";
}
} else if (mxAddress3.length() > 33) { //mxAddress3占2行 mxaddress2最多占1行
......@@ -584,11 +609,13 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
+ Mx2MtConstants.NEW_LINE
+ "3/" + mxAddress3.substring(33);
if (mxAddress2.length() > 33) {
buildSTErrorInfo(ERROR.T0000T, null, mtAddress2);
mtAddress2 = "2/" + mxAddress2.substring(0, 32) + "+";
}
} else {//mxAddress3占1行 mxaddress2最多占2行
mtAddress3 = "3/" + mxAddress3;
if (mxAddress2.length() > 66) {
buildSTErrorInfo(ERROR.T0000T, null, mxAddress2);
mtAddress2 = "2/" + mxAddress2.substring(0, 33)
+ Mx2MtConstants.NEW_LINE
+ "2/" + mxAddress2.substring(33, 65) + "+";
......@@ -602,6 +629,7 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
}
} else { //mxAddress2不存在,只读取mxAddress3
if (mxAddress3.length() > 99) {
buildSTErrorInfo(ERROR.T0000T, null, mxAddress3);
mtAddress3 = "3/" + mxAddress3.substring(0, 33)
+ Mx2MtConstants.NEW_LINE
+ "3/" + mxAddress3.substring(33, 66)
......@@ -624,11 +652,13 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
} else { //表示name占了2行
if (mxAddress2.length() > 0) { //mxAddress2存在,mxaddress2和mxaddress3算一行
if (mxAddress2.length() > 33) {
buildSTErrorInfo(ERROR.T0000T, null, mxAddress2);
mtAddress2 = "2/" + mxAddress2.substring(0, 32) + "+";
} else {
mtAddress2 = "2/" + mxAddress2;
}
if (mxAddress3.length() > 33) {
buildSTErrorInfo(ERROR.T0000T, null, mxAddress3);
mtAddress3 = "3/" + mxAddress3.substring(0, 32) + "+";
} else {
mtAddress3 = "3/" + mxAddress3;
......@@ -1552,7 +1582,8 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
break;
}
}
} else if (SwiftTransferUtil.getOrganisationIdentificationCodeByCode(mxCode) != null
}
if (SwiftTransferUtil.getOrganisationIdentificationCodeByCode(mxCode) != null
&& !OrganisationIdentificationCode.CUST.value().equals(mxCode)
&& !OrganisationIdentificationCode.EMPL.value().equals(mxCode)
&& !OrganisationIdentificationCode.TXID.value().equals(mxCode)) {
......@@ -1580,19 +1611,20 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
} else if (OrganisationIdentificationCode.TXID.value().equals(mxCode)) {
mtSchemeCode = mxCode;
mtIssuer = "";
if (StringUtil.isNotEmpty(mtCountryCode)) {
if (Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE.equals(mtIdentifier)) {
if (StringUtil.isNotEmpty(countryCode)) {
mtCountryCode = countryCode;
if (StringUtil.isNotEmpty(mtCountryCode) && !Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE.equals(mtIdentifier)) {
successfulFATF = true;
break;
}
} else {
successfulFATF = true;
break;
}
}
if (SwiftTransferUtil.getOrganisationIdentificationCodeByCode(mxCode) != null) {
if (StringUtil.isNotEmpty(countryCode)) {
mtCountryCode = countryCode;
successfulFATF = true;
buildSTErrorInfo(ERROR.T20058, null, null);
}
} else {
buildSTErrorInfo(ERROR.T20217, null, null);
}
} else {
int privateIdenOtherCount = XmlUtil.getChildrenCount(document, identificationPath + ".PrvtId.Othr", null);
......@@ -1620,14 +1652,20 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
}
}
}
}
}
if (SwiftTransferUtil.getPersonIdentificationCodeByCode(mtSchemeCode) != null) {
if (StringUtil.isNotEmpty(countryCode)) {
mtCountryCode = countryCode;
successfulFATF = true;
buildSTErrorInfo(ERROR.T20058, null, null);
} else if (StringUtil.isNotEmpty(countryOfResidence)) {
mtCountryCode = countryOfResidence;
successfulFATF = true;
buildSTErrorInfo(ERROR.T20059, null, null);
}
}
} else {
buildSTErrorInfo(ERROR.T20060, null, null);
}
if (PersonIdentificationCode.ARNU.value().equals(mtSchemeCode)
|| PersonIdentificationCode.CCPT.value().equals(mtSchemeCode)
......@@ -1664,12 +1702,15 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
|| "CUST".equals(mtSchemeCode)
|| "DRLC".equals(mtSchemeCode)) {
if (mtFATFId.length() > 68) {
buildSTErrorInfo(ERROR.T0000T, null, mtFATFId);
int issuerLength = 59 - mtIdentifier.length();
mtIssuer = mtIssuer.substring(0, issuerLength-1) + "+";
mtFATFId = mtSchemeCode + "/" + mtCountryCode + "/" + mtIssuer + "/" + mtIdentifier;
}
}
return mtFATFId;
} else {
buildSTErrorInfo(ERROR.T20026, null, null);
}
return null;
}
......@@ -1693,6 +1734,7 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
}
if (StringUtil.isNotEmpty(mxBirthPlace)) {
if (mxBirthPlace.length() > 30) {
buildSTErrorInfo(ERROR.T0000T, null, mxBirthPlace);
mxBirthPlace = mxBirthPlace.substring(0, 29) + "+";
}
}
......@@ -1761,8 +1803,13 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
}
if (successfulFATF) {
mtCode6 = "6/" + mtCountryCode + "/" + mtIssuer + "/" + mxIdentifier;
if (mtCode6.length() > 35) mtCode6 = mtCode6.substring(0, 34) + "+";
if (mtCode6.length() > 35) {
buildSTErrorInfo(ERROR.T0000T, null, mtCode6);
mtCode6 = mtCode6.substring(0, 34) + "+";
}
maps.put("MTCODE6", mtCode6);
} else {
buildSTErrorInfo(ERROR.T20037, null, null);
}
}
}
......@@ -1791,8 +1838,13 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
}
if (successfulFATF) {
mtCode7 = "7/" + mtCountryCode + "/" + mxIdentifier;
if (mtCode7.length() > 35) mtCode7 = mtCode7.substring(0, 34) + "+";
if (mtCode7.length() > 35) {
buildSTErrorInfo(ERROR.T0000T, null, mtCode7);
mtCode7 = mtCode7.substring(0, 34) + "+";
}
maps.put("MTCODE7", mtCode7);
} else {
buildSTErrorInfo(ERROR.T20037, null, null);
}
}
}
......
......@@ -22,4 +22,6 @@ public class Mx2MtContextIdentifier {
public static final String MT_TYPE_210_50_FLAG = "mt.type.210.50.flag";
public static final String MX_TO_MT_ERROR_LOCATION = "mx.to.mt.error.location";
}
package com.brilliance.swift.mx2mt.mt103;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtCreator;
......@@ -29,6 +30,11 @@ public class Mx2Mt103Creator extends AbstractMx2MtCreator {
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("CdtTrfTxInf"));
String bodyParentPath = parentElementMaps.get("CdtTrfTxInf");
int counts = getXmlNodeCounts(bodyParentPath, document, "CdtTrfTxInf");
if (counts > 1) {
buildSTErrorInfo(ERROR.T20053, bodyParentPath+".CdtTrfTxInf", null);
}
}
@Override
......
......@@ -4,9 +4,6 @@ import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.brilliance.swift.vo.SwiftTranslationErrorInfo;
import com.brilliance.swift.vo.SwiftTranslationReport;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
......@@ -34,7 +31,7 @@ public class Field20Generate extends AbstractMx2MtTagsGenerate {
}
if (StringUtil.isNotEmpty(messageId)) {
if (messageId.length() > 16) {
buildSTErrorInfo(ERROR.T0000T, "MT103/BLOCK4/:20:", messageId);
buildSTErrorInfo(ERROR.T0000T, "Block4/:20:", messageId);
messageId = messageId.substring(0, 15) + "+";
}
tags.add(new Tag(name, messageId));
......
package com.brilliance.swift.mx2mt.mt103.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.DateUtil;
......@@ -33,6 +34,10 @@ public class Field32AGenerate extends AbstractMx2MtTagsGenerate {
}
String amt = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.IntrBkSttlmAmt");
String ccy = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.IntrBkSttlmAmt@Ccy");
if ("XAU".equalsIgnoreCase(ccy) || "XAG".equalsIgnoreCase(ccy)
|| "XPD".equalsIgnoreCase(ccy) || "XPT".equalsIgnoreCase(ccy)) {
buildSTErrorInfo(ERROR.T20054, bodyHdrParentElementName+".CdtTrfTxInf.IntrBkSttlmAmt", null);
}
if (StringUtil.isNotEmpty(amt) && StringUtil.isNotEmpty(ccy)) {
intrBkSttlmAmt = NumberUtil.formatAmt(new BigDecimal(amt), ccy);
intrBkSttlmccy = ccy;
......
package com.brilliance.swift.mx2mt.mt103.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
......@@ -32,6 +33,7 @@ public class Field33BGenerate extends AbstractMx2MtTagsGenerate {
amt = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.IntrBkSttlmAmt");
ccy = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.IntrBkSttlmAmt@Ccy");
if (StringUtil.isNotEmpty(amt) && StringUtil.isNotEmpty(ccy)) {
buildSTErrorInfo(ERROR.T20025, "Block4/:"+name+":", null);
tags.add(new Tag(name, ccy+NumberUtil.formatAmt(new BigDecimal(amt), ccy)));
}
}
......
......@@ -3,6 +3,7 @@ package com.brilliance.swift.mx2mt.mt103.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
......@@ -22,6 +23,7 @@ public class Field50AGenerate extends AbstractMx2MtTagsGenerate {
@Override
public void tagGenerate() throws SwiftException {
context.set(Mx2MtContextIdentifier.MX_TO_MT_ERROR_LOCATION, "Block4/50a");
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String partyPath = bodyHdrParentElementName + ".CdtTrfTxInf.Dbtr";
......
......@@ -3,6 +3,7 @@ package com.brilliance.swift.mx2mt.mt103.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
......@@ -20,6 +21,7 @@ public class Field52AGenerate extends AbstractMx2MtTagsGenerate {
@Override
public void tagGenerate() throws SwiftException {
context.set(Mx2MtContextIdentifier.MX_TO_MT_ERROR_LOCATION, "Block4/52a");
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String bicCode = mx_to_mtBICFI(bodyHdrParentElementName + ".CdtTrfTxInf.DbtrAgt");
......
......@@ -3,6 +3,7 @@ package com.brilliance.swift.mx2mt.mt103.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.common.SettlementMethodCode;
import com.prowidesoftware.swift.model.SwiftMessage;
......@@ -24,6 +25,7 @@ public class Field53AGenerate extends AbstractMx2MtTagsGenerate {
@Override
public void tagGenerate() throws SwiftException {
context.set(Mx2MtContextIdentifier.MX_TO_MT_ERROR_LOCATION, "Block4/53a");
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String settlementMethod = getXmlNodeValue(grpHdrParentElementName, document, "GrpHdr.SttlmInf.SttlmMtd");
......
......@@ -2,6 +2,7 @@ package com.brilliance.swift.util;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.vo.MxMtReasonCodeInfo;
import com.brilliance.swift.vo.SwiftTranslationErrorInfo;
......@@ -761,21 +762,24 @@ public class SwiftTransferUtil {
}
}
}
SwiftTranslationErrorInfo errorInfo = null;
SwiftTranslationErrorInfo tmpErrorInfo = null;
if (stErrorInfos != null && stErrorInfos.size() > 0) {
for (int i=0; i<stErrorInfos.size(); i++) {
SwiftTranslationErrorInfo tmpErrorInfo = stErrorInfos.get(i);
if (key.equalsIgnoreCase(tmpErrorInfo.getErrorCode())) {
errorInfo = tmpErrorInfo;
if (key.equalsIgnoreCase(stErrorInfos.get(i).getErrorCode())) {
tmpErrorInfo = stErrorInfos.get(i);
break;
}
}
}
if (errorInfo == null) { //在errorcode list里面找不到,生成默认值
errorInfo = new SwiftTranslationErrorInfo();
SwiftTranslationErrorInfo errorInfo = new SwiftTranslationErrorInfo();
if (tmpErrorInfo == null) { //在errorcode list里面找不到,生成默认值
errorInfo.setErrorCode(key);
errorInfo.setDescription(key);
errorInfo.setErrorType("WARNING");
} else {
errorInfo.setErrorCode(tmpErrorInfo.getErrorCode());
errorInfo.setDescription(tmpErrorInfo.getDescription());
errorInfo.setErrorType(tmpErrorInfo.getErrorType());
}
return errorInfo;
}
......@@ -809,4 +813,21 @@ public class SwiftTransferUtil {
throw new SwiftException("Validate " + xsdName + ".xsd Error;" + e.getMessage());
}
}
public static boolean compareStErrorInfo(SwiftTranslationErrorInfo target, SwiftTranslationErrorInfo source) {
boolean flag = false;
if (target != null && source != null) {
if (target.getErrorCode().equals(source.getErrorCode())
&& target.getLocation().equals(source.getLocation())) {
if (ERROR.T0000T.equals(target.getErrorCode()) || ERROR.T0000R.equals(target.getErrorCode())) {
if (target.getOriginalValue().equals(source.getOriginalValue())) {
flag = true;
}
} else {
flag = true;
}
}
}
return flag;
}
}
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