master
yixian 5 years ago
parent 518f36d51e
commit f49939ec86

@ -1,6 +1,5 @@
package au.com.royalpay.payment.manage.analysis.beans.ato;
import com.github.stuxuhai.jpinyin.PinyinException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.joda.time.DateTime;
@ -18,16 +17,7 @@ public interface ATOBulkLine {
default StringBuilder appendAParam(StringBuilder line, String content, int length) {
content = content == null ? "" : StringUtils.trim(content);
content = StringUtils.remove(StringUtils.remove(content, '\r'), '\n');
int contentCharacterLength = content.getBytes().length;
int contentLength = content.length();
if (contentCharacterLength != contentLength) {
try {
content = CharacterUtils.convertToAlphaBet(content);
} catch (PinyinException e) {
e.printStackTrace();
content = "";
}
}
content = CharacterUtils.convertToAlphaBet(content);
content = content.replace("?", " ");
if (content.getBytes().length != content.length()) {
content = "";

@ -1,10 +1,12 @@
package au.com.royalpay.payment.manage.analysis.beans.ato;
import com.github.stuxuhai.jpinyin.ChineseHelper;
import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
@ -12,12 +14,19 @@ import java.util.stream.Collectors;
*/
public class CharacterUtils {
public static String convertToAlphaBet(String source) throws PinyinException {
public static String convertToAlphaBet(String source) {
return convertFullWidthToHalfWidth(convertToPinYin(source));
}
public static String convertToPinYin(String source) throws PinyinException {
return PinyinHelper.convertToPinyinString(source, "", PinyinFormat.WITHOUT_TONE).toUpperCase();
public static String convertToPinYin(String source) {
try {
return PinyinHelper.convertToPinyinString(source, "", PinyinFormat.WITHOUT_TONE);
} catch (PinyinException e) {
return source.chars().filter(c -> !ChineseHelper.isChinese((char) c))
.mapToObj(c -> "" + (char) c)
.collect(Collectors.joining());
}
}
public static String convertFullWidthToHalfWidth(String source) {

@ -0,0 +1,19 @@
package au.com.royalpay.payment.manage.analysis.beans.ato;
import com.github.stuxuhai.jpinyin.PinyinException;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Create by davep at 2019-09-04 11:07
*/
public class CharacterUtilsTest {
@Test
public void convertToAlphaBet() {
String res = CharacterUtils.convertToAlphaBet("605/110 \bQueens Road Hurstville");
Assert.assertEquals("605/110 Queens Road Hurstville",res);
}
}
Loading…
Cancel
Save