Forráskód Böngészése

修改推荐资产/设备的规则

Jxing 6 éve
szülő
commit
f1a83cbe4d

+ 5 - 2
src/main/java/com/sagacloud/route/processors/Insurance/GetPropertyCountInAllWarrantyProcessor.java

@@ -47,9 +47,12 @@ public class GetPropertyCountInAllWarrantyProcessor implements Processor {
 
         for(int i = propertyList.size() - 1; i > -1; --i){
             Map<String, Object> property = propertyList.get(i);
+            if(property.get("id").toString().contains("9da01128f85d11e8b9fc6f0dab7b6935")){
+                System.out.println("found!");
+            }
             Map<String, Object> infos = (Map<String, Object>) property.get("infos");
-            if(infos.get(Const.INSUR_ID) != null && allWarranty.containsKey(infos.get(Const.INSUR_ID).toString().trim())){
-                Warranty w = allWarranty.get(infos.get(Const.INSUR_ID).toString().trim());
+            if(infos.get(Const.INFO_INSURANCENUM) != null && allWarranty.containsKey(infos.get(Const.INFO_INSURANCENUM).toString().trim())){
+                Warranty w = allWarranty.get(infos.get(Const.INFO_INSURANCENUM).toString().trim());
                 w.setPropertyCount(w.getPropertyCount() + 1);
             }
         }

+ 157 - 14
src/main/java/com/sagacloud/route/processors/RecommendProcessor.java

@@ -10,10 +10,10 @@ import com.sagacloud.Exceptions.InvalidPostException;
 import com.sagacloud.pojos.RecommendObject;
 import com.sagacloud.utils.ExternalUrlUtil;
 import com.sagacloud.utils.HttpRequests;
+import com.sagacloud.utils.PropUtil;
 import com.sagacloud.utils.VendersUtil;
 import org.apache.camel.Exchange;
 
-import java.math.BigDecimal;
 import java.util.*;
 
 public class RecommendProcessor {
@@ -30,18 +30,24 @@ public class RecommendProcessor {
         JSONObject limit = null;
         String venderType = null;
         String venderName = null;
+        String venderId = null;
         String pjId = null;
+        JSONObject filter = null;
         try {
             JSONObject json = JSONObject.parseObject(jsonStr);
             limit = json.getJSONObject("limit");
+            filter = json.getJSONObject("filter");
             JSONObject criteria = json.getJSONObject("criteria");
             venderType = criteria.getString("venderType");
+            venderId = criteria.getString("venderId");
             venderName = criteria.getString("venderName");
-            pjId = criteria.getString("projectId");
+            pjId = (String) exchange.getIn().getHeaders().get("projectId");
             if(venderType == null || !(venderType.equals("supplier") || venderType.equals("insurer") || venderType.equals("maintainer")))
                 throw new Exception();
             if(venderName == null || venderName.length() == 0)
                 throw new Exception();
+            if(venderId == null || venderId.length() == 0)
+                throw new Exception();
             if(pjId == null || !pjId.startsWith("Pj"))
                 throw new Exception();
         }catch (Exception ex){
@@ -49,21 +55,101 @@ public class RecommendProcessor {
         }
         // map<厂商名, 对象JSONObject>
         // 获取有厂商名, 并且没有绑定厂商id的对象
+        // key --> id, value 对象Object
         Map<String, JSONObject> map = getAllObjectMap(pjId, venderType);
         if(map.size() == 0){
             exchange.getOut().setBody(VendersUtil.successJsonMsg(""));
             return;
         }
-        ArrayList<JSONObject> arr = recommendObject(map, venderName);
+        // 获取该厂商的维护名录, venders/product/directory/query
+        JSONObject bodyObj = new JSONObject();
+        bodyObj.put("venderId", venderId);
+        String result = HttpRequests.sendPost(ExternalUrlUtil.getVenderSpecDirectoryUrl(), bodyObj.toString());
+        Set<String> brandNameSet = new HashSet<>();
+        Set<String> specIdSet = new HashSet<>();
+        Set<String> specNameSet = new HashSet<>();
+        Set<String> familySet = new HashSet<>();
+        // 填充厂商维护型号清单的各个Map
+        composeVenderSpecDirMap(result, brandNameSet, specIdSet, specNameSet, familySet);
+        // 根据厂商维护的产品目录来推荐资产
+        Map<String, JSONObject> recommendMap = recommendObjectByVenderSpecDir(map, brandNameSet, specIdSet, specNameSet, familySet);
+        for(String id : recommendMap.keySet()){
+            map.remove(id);
+        }
+        // 根据维护名录中的品牌, 产品, 型号[id|name]匹配
+        ArrayList<JSONObject> arr = recommendObject(map, venderName, venderType);
+        if(recommendMap.size() > 0)
+            arr.addAll(0, recommendMap.values());
         if(arr.size() == 0){
-            exchange.getOut().setBody(VendersUtil.successJsonMsg(""));
+            exchange.getOut().setBody(VendersUtil.successJsonMsg("", new JSONArray()));
             return;
         }
-        List<Object> finalArr = paging(arr, limit);
+        List<Object> finalArr = paging(arr, limit, filter);
         exchange.getOut().setBody(VendersUtil.returnJSONArray(new JSONArray(finalArr), (long)arr.size()));
     }
 
-    public static List<Object> paging(ArrayList<JSONObject> arr, JSONObject limit) {
+    private static Map<String, JSONObject> recommendObjectByVenderSpecDir(Map<String, JSONObject> map, Set<String> brandNameSet, Set<String> specIdSet, Set<String> specNameSet, Set<String> familySet) {
+        Map<String, JSONObject> recommendMap = new HashMap<>();
+        if(brandNameSet.size() == 0 && specIdSet.size() == 0 && specNameSet.size() == 0)
+            return recommendMap;
+        for(String id : map.keySet()){
+            JSONObject single = map.get(id);
+            String family = single.getString("family");
+            if(familySet.contains(family)){
+                recommendMap.putIfAbsent(id, single);
+                continue;
+            }
+            JSONObject infos = single.getJSONObject("infos");
+            String brandName = infos.getString("Brand") ;
+            String specName = infos.getString("Specification");
+            String specId = infos.getString("DPSpecificationID");
+            if(brandNameSet.contains(brandName == null ? "" : brandName.trim()) || specNameSet.contains(specName == null? "" : specName.trim()) ||
+                    specIdSet.contains(specId == null ? "" : specId.trim())){
+                recommendMap.putIfAbsent(id, single);
+            }
+        }
+        return recommendMap;
+    }
+
+    private static void composeVenderSpecDirMap(String result, Set<String> brandNameSet, Set<String> specIdSet, Set<String> specNameSet, Set<String> familySet) {
+        JSONObject resultObj = JSONObject.parseObject(result);
+        if(resultObj == null)
+            return;
+        if(!"success".equals(resultObj.getString("result"))){
+            return;
+        }
+        JSONArray content = resultObj.getJSONArray("content");
+//        {
+//            "specificationId":"",
+//            "specificationName":"",
+//            "venderId":"",
+//            "venderName":"",
+//            "brandId":"",
+//            "brandName":"",
+//            "productId":"",
+//            "productName":"",
+//            "eqFamily":"ABC"
+//        }
+        for(int i = 0; i < content.size(); ++i){
+            JSONObject single = content.getJSONObject(i);
+            String specName = single.getString("specificationName");
+            String specid = single.getString("specificationId");
+            String brandName = single.getString("brandName");
+            String family = single.getString("eqFamily");
+            if(specName != null && specName.trim().length() != 0 && !specNameSet.contains(specName.trim()))
+                specNameSet.add(specName.trim());
+            if(specid != null && specid.trim().length() != 0 && !specIdSet.contains(specid.trim()))
+                specIdSet.add(specid.trim());
+            if(brandName != null && brandName.trim().length() != 0 && !brandNameSet.contains(brandName.trim()))
+                brandNameSet.add(brandName.trim());
+            if(family != null && family.trim().length() != 0 && !familySet.contains(family.trim()))
+                familySet.add(family.trim());
+        }
+    }
+
+    public static List<Object> paging(ArrayList<JSONObject> arr, JSONObject limit, JSONObject filter) {
+        // 先过滤, 再分页
+        filter(arr, filter);
         List<Object> retArr = new ArrayList<>();
         Long from = 0L;
         int count = arr.size();
@@ -79,6 +165,42 @@ public class RecommendProcessor {
         return retArr;
     }
 
+    private static void filter(ArrayList<JSONObject> arr, JSONObject filter) {
+        if(filter == null || filter.size() != 1)
+            return;
+        String infoCode = null;
+        Object value = null;
+        for(String key : filter.keySet()){
+            infoCode = key;
+            value = filter.get(key);
+            break;
+        }
+        for(int i = arr.size() - 1; i > -1; --i){
+            JSONObject single = arr.get(i);
+            JSONObject infos = single.getJSONObject("infos");
+            Object objValue = infos.get(infoCode);
+            if(value == null){
+                if(objValue == null)
+                    continue;
+                arr.remove(i);
+                continue;
+            }
+            if(objValue == null)
+            {
+                arr.remove(i);
+                continue;
+            }
+            if(value.equals(objValue))
+                continue;
+            if(value instanceof String && objValue instanceof String){
+                if(((String) objValue).contains((String) value))
+                    continue;
+            }
+            arr.remove(i);
+            continue;
+        }
+    }
+
     public static List<Object> paging(JSONArray arr, JSONObject limit) {
         List<Object> retArr = new ArrayList<>();
         Long from = 0L;
@@ -95,11 +217,16 @@ public class RecommendProcessor {
         return retArr;
     }
 
-    private static ArrayList<JSONObject> recommendObject(Map<String, JSONObject> map, String venderName) {
+    private static ArrayList<JSONObject> recommendObject(Map<String, JSONObject> map, String venderName, String venderType) {
         venderName = preprocessing(venderName);
         PriorityQueue<RecommendObject> queue = new PriorityQueue<>();
-        for(String name : map.keySet()){
-            JSONObject single = map.get(name);
+        String infoCode = dpVenderNameInfoCodeMap.get(venderType);
+        for(String id : map.keySet()){
+            JSONObject single = map.get(id);
+            JSONObject infos = single.getJSONObject("infos");
+            String name = infos.getString(infoCode);
+            if(name == null)
+                continue;
             if(venderName.contains(name) || name.contains(venderName)){
                 RecommendObject obj = new RecommendObject(0.99d, single);
                 queue.add(obj);
@@ -111,6 +238,19 @@ public class RecommendProcessor {
                 }
             }
         }
+//        for(String name : map.keySet()){
+//            JSONObject single = map.get(name);
+//            if(venderName.contains(name) || name.contains(venderName)){
+//                RecommendObject obj = new RecommendObject(0.99d, single);
+//                queue.add(obj);
+//            }else {
+//                double similarity = VendersUtil.levenshtein(venderName, name);
+//                if(similarity > threshold){
+//                    RecommendObject obj = new RecommendObject(similarity, single);
+//                    queue.add(obj);
+//                }
+//            }
+//        }
         ArrayList<JSONObject> arrayList = new ArrayList<>();
         while(!queue.isEmpty()){
             arrayList.add(queue.poll().getObj());
@@ -161,14 +301,17 @@ public class RecommendProcessor {
             JSONObject single = content.getJSONObject(i);
             if(single == null)
                 continue;
+            String id = single.getString("id");
             JSONObject infos = single.getJSONObject("infos");
             if(infos == null)
                 continue;
-            String nameValue = infos.getString(infoCode);
-            if(nameValue == null || nameValue.length() == 0)
-                continue;
-            if(!nameMap.containsKey(nameValue))
-                nameMap.put(nameValue, single);
+            if(!nameMap.containsKey(id))
+                nameMap.put(id, single);
+//            String nameValue = infos.getString(infoCode);
+//            if(nameValue == null || nameValue.length() == 0)
+//                continue;
+//            if(!nameMap.containsKey(nameValue))
+//                nameMap.put(nameValue, single);
         }
         return nameMap;
     }

+ 5 - 0
src/main/java/com/sagacloud/utils/ExternalUrlUtil.java

@@ -17,4 +17,9 @@ public class ExternalUrlUtil {
         return String.join("", PropUtil.getProperty("dataPlatform.baseUrl"), "/fast/object/in_query"
                 , getDpSuffix(pjId));
     }
+
+    public static String getVenderSpecDirectoryUrl()
+    {
+        return String.join("", PropUtil.getProperty("venders.baseUrl"), "/product/directory/query");
+    }
 }

+ 4 - 1
src/main/resources/documentation.md

@@ -371,10 +371,13 @@ post体:
             "skip":300,  // 跳过多少数据
             "count":50   // 查询跳过300条数据之后的50条 (按照关联性相似度排名)
         },
+        "filter":{             // 选填, 模糊匹配信息点的值, 目前只支持一个信息点的查询
+            "infoCode":"value" // 信息点编码:模糊匹配的值, 字符串模糊匹配, 其他类型直接匹配
+        },
         "criteria":{
-            "projectId":"",                                 // 必填, 项目编号
             "venderType":"supplier|insurer|maintainer",     // 必填, 当前推荐的厂商类型, 维修商结果是设备, 其他为资产
             "venderName":"***",                             // 必填, 当前推荐的厂商的名称
+            "venderId":""                                   // 必填, 当前厂商id
         }
     }
 

+ 2 - 2
src/main/resources/test/config.properties

@@ -1,5 +1,5 @@
-dataPlatform.baseUrl=http4://192.168.100.225:8080/data-platform-3
-venders.baseUrl=http4://192.168.100.225:8080/venders
+dataPlatform.baseUrl=http4://192.168.20.225:8080/data-platform-3
+venders.baseUrl=http4://192.168.20.225:8080/venders
 
 
 #venders.baseUrl=http4://localhost:8080/venders