From 7a81ff5c057b7b85e0ab1607c84a8769209253c7 Mon Sep 17 00:00:00 2001 From: guocjsh <627680635@qq.com> Date: Mon, 18 Aug 2025 21:44:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bullshit-code=E4=B9=8B=E7=8E=8B=EF=BC=8C?= =?UTF-8?q?=E7=9C=8B=E5=88=B0=E8=A1=80=E5=8E=8B=E9=A3=99=E5=8D=87280?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Java/TypeChangeUtil.java | 298 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 Java/TypeChangeUtil.java diff --git a/Java/TypeChangeUtil.java b/Java/TypeChangeUtil.java new file mode 100644 index 0000000..50e7954 --- /dev/null +++ b/Java/TypeChangeUtil.java @@ -0,0 +1,298 @@ +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/*** + * 此处省略N行代码,当我看到这些代码时 + * 瞬间!!血压280 把这尊大佛调去了别的组,别来嚯嚯我了!!! + */ +public class TypeChangeUtil { + + private static final Pattern AMOUNT_PATTERN = Pattern.compile("^(0|[1-9]\\d{0,11})\\.(\\d\\d)$"); + private static final char[] RMB_NUMS = "零壹贰叁肆伍陆柒捌玖".toCharArray(); + private static final String[] UNITS = {"元", "角", "分", "整"}; + private static final String[] U1 = {"", "拾", "佰", "仟"}; + private static final String[] U2 = {"", "万", "亿"}; + + + public static String getIdType2(String bankIdType, String nationalityCode) + { + String idtype = null; + if("4".equals(bankIdType)){ + if("446".equals(nationalityCode)){ + idtype = "516"; + } else if ("344".equals(nationalityCode)) { + idtype = "516"; + } else if ("158".equals(nationalityCode)) { + idtype = "511"; + } + }else if("31".equals(bankIdType)){ + if("446".equals(nationalityCode)){ + idtype = "563"; + } else if ("344".equals(nationalityCode)) { + idtype = "563"; + } else if ("158".equals(nationalityCode)) { + idtype = "564"; + } + } + return idtype; + } + + + public static String tranPayDateCHN(String payDate, String payInterval) + { + if ("12".equals(payInterval)) + { + payDate = "每年" + payDate.substring(5, 7) + "月" + payDate.substring(8, 10) + "日"; + } else + { + payDate = ""; + } + return payDate; + } + + /** + * 缴费方式 + */ + public static String transferPayMethodCHN(String payMethod) + { + String temp = trimStr(payMethod); + switch (temp) + { + case "12": + return "年缴"; + case "1": + return "月缴"; + case "0": + return "趸缴"; + default: + return ""; + } + } + + public static String trimStr(String str) + { + if (str == null) + { + str = ""; + } else + { + str = str.trim(); + } + return str; + } + + /** + * 将金额(整数部分等于或少于 12 位,小数部分 2 位)转换为中文大写形式. + * + * @param amount 金额数字分 + * @return 中文大写 + */ + public static String convertToChinese(String amount) throws IllegalArgumentException + { + // 去掉分隔符 + amount = amount.replace(",", ""); + DecimalFormat decimalFormat = new DecimalFormat("0.00"); + amount = decimalFormat.format(new BigDecimal(amount)); + if (amount.equals("0.00")) + { + return "零"; + } + Matcher matcher = AMOUNT_PATTERN.matcher(amount); + if (!matcher.find()) + { + throw new IllegalArgumentException("输入金额有误."); + } + /*整数部分*/ + String integer = matcher.group(1); + /*小数部分*/ + String fraction = matcher.group(2); + String result = ""; + if (!integer.equals("0")) + { + result += integer2rmb(integer) + UNITS[0]; + } + if (fraction.equals("00")) + { + result += UNITS[3]; + } else if (fraction.startsWith("0") && integer.equals("0")) + { + result += fraction2rmb(fraction).substring(1); + } else + { + result += fraction2rmb(fraction); + } + return "人民币" + result; + } + /** + * 小数部分处理成中文 + */ + public static String fraction2rmb(String fraction) + { + // 角 + char jiao = fraction.charAt(0); + // 分 + char fen = fraction.charAt(1); + return (RMB_NUMS[jiao - '0'] + (jiao > '0' ? UNITS[1] : "")) + + (fen > '0' ? RMB_NUMS[fen - '0'] + UNITS[2] : ""); + } + + /** + * 整数部分处理成中文 + */ + public static String integer2rmb(String integer) + { + StringBuilder buffer = new StringBuilder(); + int i, j; + for (i = integer.length() - 1, j = 0; i >= 0; i--, j++) + { + char n = integer.charAt(i); + if (n == '0') + { + // 当 n 是 0 且 n 的右边一位不是 0 时,插入[零] + if (i < integer.length() - 1 && integer.charAt(i + 1) != '0') + { + buffer.append(RMB_NUMS[0]); + } + // 插入[万]或者[亿] + if (j % 4 == 0) + { + if (i > 0 && integer.charAt(i - 1) != '0' || i > 1 && integer.charAt(i - 2) != '0' + || i > 2 && integer.charAt(i - 3) != '0') + { + buffer.append(U2[j / 4]); + } + } + } else + { + if (j % 4 == 0) + { + // 插入[万]或者[亿] + buffer.append(U2[j / 4]); + } + // 插入[拾]、[佰]或[仟] + buffer.append(U1[j % 4]); + // 插入数字 + buffer.append(RMB_NUMS[n - '0']); + } + } + return buffer.reverse().toString(); + } + + public static String getAddressResolution(String address,String detailed,String SaleType) + { + if("5".equals(SaleType)){ + // 工行手机银行 + address = address.replace("(市辖区)", ""); + if (address.startsWith("北京市") || address.startsWith("天津市") || address.startsWith("上海市") || address.startsWith("重庆市")) { + address = address.substring(3); + } + }else if("1".equals(SaleType)){ + // 工行网银 北京市省(市、区)北京市(市辖区)市东城区县(区)东城区王府井大街137号 河北省(市、区)保定市东城区县(区)东城区王府井大街137号 + // 江老师后期会再测试, 现在适配银行对北京地址的测试 + if (address.startsWith("北京市") || address.startsWith("天津市") || address.startsWith("上海市") || address.startsWith("重庆市")) { + address = address.replace("省(市、区)", ""); + address = address.substring(3); + }else { + address = address.replace("(市、区)", ""); + } + address = address.replace("(市辖区)市", ""); + address = address.replace("县(区)", ""); + } else { + // 工行柜面自助终端加 + address = address.replace("(市辖区)", ""); + } + if (address.startsWith("北京市") || address.startsWith("天津市") || address.startsWith("上海市") || address.startsWith("重庆市")) { + address = address.substring(0, 3) + "市辖区" + address.substring(3); + } + String regex = "(?[^省]+自治区|.*?省|.*?行政区|.*?市)(?[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)(?.*)"; + Matcher m = Pattern.compile(regex).matcher(address); + String province = null, city = null, county = null; + while(m.find()){ + province = m.group("province"); + if (province.equals("北京市") || province.equals("天津市") || province.equals("上海市") || province.equals("重庆市")) { + city = province; + county = m.group("city"); + if (county.split("区").length > 1) { + county = county.substring(0, county.indexOf("区") + 1); + } else { + county = m.group("county"); + if (county != null && county.split("区").length > 1) { + county = county.substring(0, county.indexOf("区") + 1); + } + } + } else { + city = m.group("city"); + + county = m.group("county"); + if (county != null && !"".equals(county)) { + if (county.split("市").length > 1 && county.indexOf("市") < 5) { + county = county.substring(0, county.indexOf("市") + 1); + } + if (county.split("旗").length > 1) { + county = county.substring(0, county.indexOf("旗") + 1); + } + if (county.split("海域").length > 1) { + county = county.substring(0, county.indexOf("海域") + 2); + } + if (county.split("区").length > 1) { + county = county.substring(0, county.indexOf("区") + 1); + } + } + } + } + if("province".equals(detailed)){ + //省 + // return codeMappingMapperStaticPack.getInsuCode(province); + }else if ("city".equals(detailed)){ + //市 + // return codeMappingMapperStaticPack.getCityInsuCode(city); + }else if ("county".equals(detailed)){ + //区 + // return codeMappingMapperStaticPack.getCountyInsuCode(city,county); + } + return "地址填写有误"; + } + + + + /** + * + * @param Line1 全部地址 + * @return 详细地址 + */ + public static String getDetailAddress(String Line1) { + if(StringUtils.isEmpty(Line1)){ + return ""; + }else if(Line1.contains("区")){ + String[] address = Line1.split("区"); + String lastaddress = address.length>1?address[address.length-1]:""; + return lastaddress.replaceAll(")",""); + }else if(Line1.contains("市")){ + String[] address = Line1.split("市"); + String lastaddress = address.length>1?address[address.length-1]:""; + return lastaddress.replaceAll(")",""); + } else { + return ""; + } + } + + public static void main(String[] args) { + String Line1 = "浙江省绍兴市嵊州区三江街道xxxx5幢一单元"; + if(StringUtils.isEmpty(Line1)){ + System.out.println(1); + }else if(Line1.contains("区")){ + String[] address = Line1.split("区"); + String lastaddress = address.length>1?address[address.length-1]:""; + System.out.println(lastaddress.replaceAll(")","")); + }else if(Line1.contains("市")){ + String[] address = Line1.split("市"); + String lastaddress = address.length>1?address[address.length-1]:""; + System.out.println("111"+lastaddress.replaceAll(")","")); + } else { + System.out.println(2); + } + + } + } -- Gitee From 5dfec2ca34d689f94843cdfbc8a50cb24140d291 Mon Sep 17 00:00:00 2001 From: guocjsh <627680635@qq.com> Date: Mon, 18 Aug 2025 21:46:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bullshit-code=E4=B9=8B=E7=8E=8B=EF=BC=8C?= =?UTF-8?q?=E7=9C=8B=E5=88=B0=E8=A1=80=E5=8E=8B=E9=A3=99=E5=8D=87280?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Java/TypeChangeUtil.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Java/TypeChangeUtil.java b/Java/TypeChangeUtil.java index 50e7954..cba954f 100644 --- a/Java/TypeChangeUtil.java +++ b/Java/TypeChangeUtil.java @@ -189,8 +189,6 @@ public class TypeChangeUtil { address = address.substring(3); } }else if("1".equals(SaleType)){ - // 工行网银 北京市省(市、区)北京市(市辖区)市东城区县(区)东城区王府井大街137号 河北省(市、区)保定市东城区县(区)东城区王府井大街137号 - // 江老师后期会再测试, 现在适配银行对北京地址的测试 if (address.startsWith("北京市") || address.startsWith("天津市") || address.startsWith("上海市") || address.startsWith("重庆市")) { address = address.replace("省(市、区)", ""); address = address.substring(3); @@ -200,7 +198,6 @@ public class TypeChangeUtil { address = address.replace("(市辖区)市", ""); address = address.replace("县(区)", ""); } else { - // 工行柜面自助终端加 address = address.replace("(市辖区)", ""); } if (address.startsWith("北京市") || address.startsWith("天津市") || address.startsWith("上海市") || address.startsWith("重庆市")) { -- Gitee