|
@@ -0,0 +1,83 @@
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
+
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: π
|
|
|
+ * 2021/8/30 16:57
|
|
|
+ * 案件金额判断
|
|
|
+ * judge_info [{"amt":30.492,"case_stage":"恢复执行"},{"amt":30.0,"case_stage":"民事一审"}]
|
|
|
+ * exec_info [{"date":"2022-06-14 00:00:00","exec_money":6.18,"litigant_id":"a87cd9b6bc6e11be1681fe5ab0166dae","name":"云南尚多购商贸有限公司"},{"date":"2022-06-14 00:00:00","exec_money":6.18,"litigant_id":"b5570cbb03c2ce1cec47a95a5e281c99","name":"通海尚多购商贸有限公司"}]
|
|
|
+ */
|
|
|
+public class get_case_amt extends UDF {
|
|
|
+
|
|
|
+ public Double evaluate(String exec_info, String judge_info) {
|
|
|
+ if (StringUtils.isBlank(exec_info) && StringUtils.isBlank(judge_info)) return null;
|
|
|
+ try {
|
|
|
+ double exec_amt = JSON.parseArray(Optional.ofNullable(exec_info)
|
|
|
+ .orElse("[]"))
|
|
|
+ .toJavaList(JSONObject.class)
|
|
|
+ .stream()
|
|
|
+ .sorted(Comparator.comparing(x -> {
|
|
|
+ JSONObject j = (JSONObject)x;
|
|
|
+ return j.getString("date");
|
|
|
+ }).reversed())
|
|
|
+ .mapToDouble(y -> y.getDouble("exec_money"))
|
|
|
+ .findFirst().orElse(0);
|
|
|
+
|
|
|
+ double judge_amt = JSON.parseArray(Optional.ofNullable(judge_info)
|
|
|
+ .orElse("[]"))
|
|
|
+ .toJavaList(JSONObject.class)
|
|
|
+ .stream()
|
|
|
+ .sorted(Comparator.comparing(x -> {
|
|
|
+ JSONObject j = (JSONObject)x;
|
|
|
+ return stageWeight(j.getString("case_stage"));
|
|
|
+ }).reversed())
|
|
|
+ .mapToDouble(y -> y.getDouble("amt"))
|
|
|
+ .findFirst().orElse(0);
|
|
|
+
|
|
|
+ return exec_amt > 0 ? exec_amt : judge_amt > 0 ? judge_amt : null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer stageWeight(String stage_name) {
|
|
|
+ if (StringUtils.isBlank(stage_name)) return 0;
|
|
|
+ if (StrUtil.containsAny(stage_name, "执")) {
|
|
|
+ return 5;
|
|
|
+ }
|
|
|
+ if (StrUtil.containsAny(stage_name, "再")) {
|
|
|
+ return 4;
|
|
|
+ }
|
|
|
+ if (StrUtil.containsAny(stage_name, "二")) {
|
|
|
+ return 3;
|
|
|
+ }
|
|
|
+ if (StrUtil.containsAny(stage_name, "一")) {
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ get_case_amt j = new get_case_amt();
|
|
|
+ //String exec_info = "[{\"date\":\"2022-07-15 00:00:00\",\"exec_money\":8.88,\"litigant_id\":\"11\",\"name\":\"云南尚多购商贸有限公司\"},{\"date\":\"2022-06-14 00:00:00\",\"exec_money\":9.99,\"litigant_id\":\"22\",\"name\":\"通海尚多购商贸有限公司\"}]";
|
|
|
+ String exec_info = null;
|
|
|
+ String judge_info = "[{\"amt\":30.492,\"case_stage\":\"恢复执行\"},{\"amt\":30.0,\"case_stage\":\"民事一审\"}]";
|
|
|
+ Double e = j.evaluate(exec_info, judge_info);
|
|
|
+ System.out.println(e);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|