|
@@ -0,0 +1,63 @@
|
|
|
+package com.winhc.bigdata.udf.company;
|
|
|
+
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
+
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: XuJiakai
|
|
|
+ * 2023/5/19 16:23
|
|
|
+ * 注册资本按汇率转化为amount
|
|
|
+ * <p>
|
|
|
+ * 函数名:reg_capital_amount_format
|
|
|
+ */
|
|
|
+public class RegCapitalAmountFormat extends UDF {
|
|
|
+ public static final Map<String, Double> unit_w = new HashMap<String, Double>() {{
|
|
|
+ put("欧元", 7.9145);
|
|
|
+ put("英镑", 8.7751);
|
|
|
+ put("美元", 6.5301);
|
|
|
+ put("港元", 0.8425);
|
|
|
+ put("港币", 0.8425);
|
|
|
+ put("台币", 0.2316);
|
|
|
+ put("日元", 0.06270);
|
|
|
+ put("加拿大元", 5.1096);
|
|
|
+ put("新加坡元", 4.8907);
|
|
|
+ put("澳元", 4.846);
|
|
|
+ put("卢布", 0.08825);
|
|
|
+ put("泰铢", 0.2162);
|
|
|
+ put("韩元", 0.006025);
|
|
|
+ put("澳门元", 0.8178);
|
|
|
+ }};
|
|
|
+
|
|
|
+ public Double evaluate(String val) {
|
|
|
+ return getAmount(val);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Double getAmount(String regCapital) {
|
|
|
+ DecimalFormat df = new DecimalFormat("00.00");
|
|
|
+ if (StringUtils.isEmpty(regCapital))
|
|
|
+ return null;
|
|
|
+ double unit = unit_w.entrySet().stream()
|
|
|
+ .filter(e -> regCapital.contains(e.getKey()))
|
|
|
+ .mapToDouble(Map.Entry::getValue)
|
|
|
+ .findFirst().orElse(1d);
|
|
|
+
|
|
|
+ if (regCapital.contains("亿")) {
|
|
|
+ unit *= 100000000.0d;
|
|
|
+ } else if (regCapital.contains("百万")) {
|
|
|
+ unit *= 1000000.0d;
|
|
|
+ } else if (regCapital.contains("万")) {
|
|
|
+ unit *= 10000.0d;
|
|
|
+ }
|
|
|
+ unit *= 100.0d;
|
|
|
+ try {
|
|
|
+ double amount = Double.parseDouble(regCapital.replaceAll("[^0-9.]", " ").split("\\s+")[0]);
|
|
|
+ return Double.valueOf(df.format(amount * unit));
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|