|
@@ -0,0 +1,284 @@
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: π
|
|
|
+ * @Date: 2023/7/27 16:26
|
|
|
+ * 招投标转换
|
|
|
+ * <p>
|
|
|
+ * [{"company_id":"2c9d7aec5ac48c1f505b7cc74123b8f1","name":"西安市公路工程管理处"},{"company_id":"cec3be99b8395225c4c7519f2416f4ee","name":"正衡工程项目管理有限公司"}]
|
|
|
+ * 3297737385;3097206773
|
|
|
+ * [{"gid":"3097206773","name":"西安市公路工程管理处"}]
|
|
|
+ * 招标公告
|
|
|
+ */
|
|
|
+public class CompanyBidTrans extends UDF {
|
|
|
+
|
|
|
+ public String evaluate(String wtbamtInfo) {
|
|
|
+ if (StringUtils.isBlank(wtbamtInfo)) return null;
|
|
|
+
|
|
|
+ List<JSONObject> re = JSON.parseArray(wtbamtInfo)
|
|
|
+ .toJavaList(JSONObject.class)
|
|
|
+ .stream()
|
|
|
+ .peek(j -> j.fluentPut("project_bid_money", ""))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return JSONObject.toJSONString(re);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> evaluate(String purchaser, String proxy) {
|
|
|
+ Set<String> set = new HashSet<>();
|
|
|
+ if (StringUtils.isNotBlank(purchaser)) {
|
|
|
+ if (purchaser.startsWith("[{")) {
|
|
|
+ JSONArray ja = new JSONArray();
|
|
|
+ try {
|
|
|
+ ja = JSON.parseArray(purchaser);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ List<String> re = ja.toJavaList(JSONObject.class)
|
|
|
+ .stream()
|
|
|
+ .map(s -> s.getString("name"))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ set.addAll(re);
|
|
|
+ } else if (purchaser.startsWith("[[{")) {
|
|
|
+ JSONArray ja = new JSONArray();
|
|
|
+ try {
|
|
|
+ ja = JSON.parseArray(purchaser);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ List<String> re = ja.toJavaList(JSONArray.class).stream()
|
|
|
+ .flatMap(jj1 -> jj1.toJavaList(JSONObject.class).stream()
|
|
|
+ .map(s -> s.getString("name"))
|
|
|
+ .filter(Objects::nonNull).
|
|
|
+ distinct()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ set.addAll(re);
|
|
|
+ } else {
|
|
|
+ List<String> re2 = Arrays.stream(purchaser.split("、"))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ set.addAll(re2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(proxy)) {
|
|
|
+ List<String> re3 = Arrays.stream(proxy.split("、"))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ set.addAll(re3);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new ArrayList<>(set);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String evaluate(String datas, String purchaser, String proxy, String type, String title) {
|
|
|
+
|
|
|
+ JSONArray ej = new JSONArray();
|
|
|
+
|
|
|
+ Map<String, JSONObject> names = Optional.ofNullable(JSON.parseArray(datas))
|
|
|
+ .orElse(new JSONArray())
|
|
|
+ .toJavaList(JSONObject.class).stream()
|
|
|
+ .filter(Objects::nonNull).collect(Collectors.toMap(t -> t.getString("name"), t -> t, (n, o) -> o));
|
|
|
+
|
|
|
+ List<String> nameList = new ArrayList<>();
|
|
|
+ AtomicReference<Integer> companyNumber = new AtomicReference<>(0);
|
|
|
+ List<JSONObject> purchaserList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(purchaser)) {
|
|
|
+ if (purchaser.startsWith("[{")) {
|
|
|
+ JSONArray ja = new JSONArray();
|
|
|
+ try {
|
|
|
+ ja = JSON.parseArray(purchaser);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ ja.toJavaList(JSONObject.class)
|
|
|
+ .stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .forEach(d -> {
|
|
|
+ String name = d.getString("name");
|
|
|
+ String keyno = "";
|
|
|
+ if (names.containsKey(name)) {
|
|
|
+ keyno = names.get(name).getString("company_id");
|
|
|
+ }
|
|
|
+ JSONObject re = new JSONObject()
|
|
|
+ .fluentPut("name", name)
|
|
|
+ .fluentPut("keyno", keyno)
|
|
|
+ .fluentPut("contacts", ej)
|
|
|
+ .fluentPut("phones", ej)
|
|
|
+ .fluentPut("address", ej)
|
|
|
+ .fluentPut("email", ej);
|
|
|
+ purchaserList.add(re);
|
|
|
+ nameList.add(name);
|
|
|
+ companyNumber.updateAndGet(v -> v + 1);
|
|
|
+ });
|
|
|
+ } else if (purchaser.startsWith("[[{")) {
|
|
|
+ JSONArray ja = new JSONArray();
|
|
|
+ try {
|
|
|
+ ja = JSON.parseArray(purchaser);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ ja.toJavaList(JSONArray.class).stream()
|
|
|
+ .flatMap(jj1 -> jj1.toJavaList(JSONObject.class).stream()
|
|
|
+ .filter(Objects::nonNull).
|
|
|
+ distinct()).forEach(d -> {
|
|
|
+ String name = d.getString("name");
|
|
|
+ String keyno = "";
|
|
|
+ if (names.containsKey(name)) {
|
|
|
+ keyno = names.get(name).getString("company_id");
|
|
|
+ }
|
|
|
+ JSONObject re = new JSONObject()
|
|
|
+ .fluentPut("name", name)
|
|
|
+ .fluentPut("keyno", keyno)
|
|
|
+ .fluentPut("contacts", ej)
|
|
|
+ .fluentPut("phones", ej)
|
|
|
+ .fluentPut("address", ej)
|
|
|
+ .fluentPut("email", ej);
|
|
|
+ purchaserList.add(re);
|
|
|
+ nameList.add(name);
|
|
|
+ companyNumber.updateAndGet(v -> v + 1);
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Arrays.stream(purchaser.split("、"))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .forEach(d1 -> {
|
|
|
+ String keyno = "";
|
|
|
+ if (names.containsKey(d1)) {
|
|
|
+ keyno = names.get(d1).getString("company_id");
|
|
|
+ }
|
|
|
+ JSONObject re = new JSONObject()
|
|
|
+ .fluentPut("name", d1)
|
|
|
+ .fluentPut("keyno", keyno)
|
|
|
+ .fluentPut("contacts", ej)
|
|
|
+ .fluentPut("phones", ej)
|
|
|
+ .fluentPut("address", ej)
|
|
|
+ .fluentPut("email", ej);
|
|
|
+ purchaserList.add(re);
|
|
|
+ nameList.add(d1);
|
|
|
+ companyNumber.updateAndGet(v -> v + 1);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //代理机构
|
|
|
+ List<JSONObject> proxyList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(proxy)) {
|
|
|
+ Arrays.stream(proxy.split("、"))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .forEach(d1 -> {
|
|
|
+ String keyno = "";
|
|
|
+ if (names.containsKey(d1)) {
|
|
|
+ keyno = names.get(d1).getString("company_id");
|
|
|
+ }
|
|
|
+ JSONObject re = new JSONObject()
|
|
|
+ .fluentPut("name", d1)
|
|
|
+ .fluentPut("keyno", keyno)
|
|
|
+ .fluentPut("contacts", ej)
|
|
|
+ .fluentPut("phones", ej)
|
|
|
+ .fluentPut("address", ej)
|
|
|
+ .fluentPut("email", ej);
|
|
|
+ proxyList.add(re);
|
|
|
+ nameList.add(d1);
|
|
|
+ companyNumber.updateAndGet(v -> v + 1);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //类型
|
|
|
+ String main_type = "";
|
|
|
+ if (StringUtils.isNotBlank(type)) {
|
|
|
+ if (type.contains("招标") || type.contains("采购") || type.contains("更正公告") || type.contains("交易公告")) {
|
|
|
+ main_type = "20";
|
|
|
+ } else if (type.contains("中标") || type.contains("结果公示") || type.contains("成交")) {
|
|
|
+ main_type = "30";
|
|
|
+ } else {
|
|
|
+ main_type = "0";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //投标单位,中标单位
|
|
|
+ List<JSONObject> supplierInfoList = new ArrayList<>();
|
|
|
+ List<JSONObject> wtbamtInfoList = new ArrayList<>();
|
|
|
+ List<JSONObject> winnerCandidateList = new ArrayList<>();
|
|
|
+
|
|
|
+ AtomicReference<Integer> identity_code = new AtomicReference<>(0); // 默认为投标单位
|
|
|
+ if (main_type.equalsIgnoreCase("30")) {
|
|
|
+ if (names.size() - companyNumber.get() == 1) {
|
|
|
+ identity_code.set(1); // 中标单位
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (title.contains("候选")) {
|
|
|
+ identity_code.set(2); // 候选单位
|
|
|
+ }
|
|
|
+ names.forEach((key, data) -> {
|
|
|
+ if (!nameList.contains(key)) {
|
|
|
+ if (identity_code.get() == 0) {
|
|
|
+ JSONObject re = new JSONObject()
|
|
|
+ .fluentPut("name", key)
|
|
|
+ .fluentPut("keyno", data.getString("company_id"))
|
|
|
+ .fluentPut("contacts", ej)
|
|
|
+ .fluentPut("phones", ej)
|
|
|
+ .fluentPut("address", ej)
|
|
|
+ .fluentPut("email", ej);
|
|
|
+ supplierInfoList.add(re);
|
|
|
+ } else if (identity_code.get() == 2) {
|
|
|
+ JSONObject re = new JSONObject()
|
|
|
+ .fluentPut("name", key)
|
|
|
+ .fluentPut("keyno", data.getString("company_id"))
|
|
|
+ .fluentPut("contacts", ej)
|
|
|
+ .fluentPut("phones", ej)
|
|
|
+ .fluentPut("address", ej)
|
|
|
+ .fluentPut("email", ej);
|
|
|
+ winnerCandidateList.add(re);
|
|
|
+ } else {
|
|
|
+ JSONObject re = new JSONObject()
|
|
|
+ .fluentPut("name", key)
|
|
|
+ .fluentPut("keyno", data.getString("company_id"))
|
|
|
+ .fluentPut("contacts", ej)
|
|
|
+ .fluentPut("phones", ej)
|
|
|
+ .fluentPut("address", ej)
|
|
|
+ .fluentPut("project_bid_money", "")
|
|
|
+ .fluentPut("email", ej);
|
|
|
+ wtbamtInfoList.add(re);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ String purchaser_keyno = null;
|
|
|
+ if (purchaserList.size() > 0) {
|
|
|
+ purchaser_keyno = purchaserList.get(0).getString("keyno");
|
|
|
+ }
|
|
|
+ JSONObject j = new JSONObject()
|
|
|
+ .fluentPut("purchaser_keyno", purchaser_keyno)
|
|
|
+ .fluentPut("main_type", main_type)
|
|
|
+ .fluentPut("purchaser_info", purchaserList)
|
|
|
+ .fluentPut("proxy", proxyList)
|
|
|
+ .fluentPut("wtbamt_info", wtbamtInfoList)
|
|
|
+ .fluentPut("winner_candidate", winnerCandidateList)
|
|
|
+ .fluentPut("supplier_info", supplierInfoList);
|
|
|
+
|
|
|
+ return JSONObject.toJSONString(j, SerializerFeature.WriteMapNullValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String datas = "[{\"company_id\":\"123456\",\"name\":\"亳州学院\"},{\"company_id\":\"6e5d52d7bf1cbbac6c3b820dfc8cf0eb\",\"name\":\"亳州市诚信文化体育用品销售有限公司\"},{\"company_id\":\"efaa5ad30ec4e21ed19aae202eeeda29\",\"name\":\"亳州市谯城区信诚商贸有限公司\"}]";
|
|
|
+ String purchaser = "[[{\"gid\":\"2358397210\",\"name\":\"亳州学院\"},{\"gid\":\"2358397210\",\"name\":\"亳州学院\"}]]";
|
|
|
+ String proxy = "";
|
|
|
+ String type = "中标结果";
|
|
|
+ String title = "亳州学院于2018年12月03日成功交易2笔新订单";
|
|
|
+ CompanyBidTrans j = new CompanyBidTrans();
|
|
|
+ String re = j.evaluate(datas, purchaser, proxy, type, title);
|
|
|
+ System.out.println(re);
|
|
|
+ System.out.println(j.evaluate("[{\"address\":[],\"contacts\":[],\"email\":[],\"keyno\":\"852f69e1c4cd443ca6d7347b9c503db4\",\"name\":\"包头市仁武汽修有限责任公司\",\"phones\":[],\"project_bid_money\":[]}]"));
|
|
|
+ System.out.println(j.evaluate(purchaser, proxy));
|
|
|
+ }
|
|
|
+}
|