Browse Source

生产商查询资产

FanXiaoyu 6 năm trước cách đây
mục cha
commit
b128b4e7a1

+ 1 - 0
src/main/java/com/sagacloud/route/processors/GetPropByPjProcessor.java

@@ -18,6 +18,7 @@ public class GetPropByPjProcessor implements Processor {
         String projectId = json.getString(Const.HEADER_PROJECT);
         String secret = ProPasCache.getPjSecret(projectId);
 
+//        exchange.getIn().setBody("{\"venderInfo\":true,\"criteria\":{\"family\":[]}}");
         exchange.getIn().setBody("{\"criteria\":{\"family\":[]}}");
         exchange.getIn().setHeader(Exchange.HTTP_URI, Const.dataPlatform+"/property/relation_query?method=POST");
         exchange.getIn().setHeader(Exchange.HTTP_QUERY,Const.HEADER_PROJECT + "=" + projectId + "&"+ Const.HEADER_SECRET+ "="+ secret);

+ 76 - 0
src/main/java/com/sagacloud/route/processors/Manufacturer/Filter.java

@@ -0,0 +1,76 @@
+package com.sagacloud.route.processors.Manufacturer;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.google.common.base.Strings;
+import com.sagacloud.Exceptions.InvalidPostException;
+import com.sagacloud.pojos.PropertyObj;
+import com.sagacloud.utils.Const;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by Xiaoyu on 2018/7/12
+ */
+public class Filter implements Processor {
+
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        String jsonStr = exchange.getIn().getBody(String.class);
+        JSONObject json = JSONObject.parseObject(jsonStr);
+        if (json.getString("result").equalsIgnoreCase("failure")) {
+            throw new InvalidPostException("查询厂商信息出错");
+        }
+        JSONArray content = json.getJSONArray("content");
+        Hashtable<String, JSONObject> specMap = new Hashtable<>();
+        for (int i = 0; i < content.size(); ++i) {
+            JSONObject obj = content.getJSONObject(i);
+            specMap.put(obj.getString("specificationId"), obj);
+        }
+        String targetVenderId = (String) exchange.getProperty("venderId");
+        List<PropertyObj> propertyObjList = (List<PropertyObj>) exchange.getProperty("property");
+        for (int i = propertyObjList.size() - 1; i >= 0; --i) {
+            PropertyObj p = propertyObjList.get(i);
+
+        }
+
+    }
+
+//    private boolean validate(PropertyObj p, Hashtable<String, JSONObject> specMap,String targetVenderId){
+//        Map<String, Object> infos = p.getInfos();
+//        String venderId = Strings.nullToEmpty((String) infos.get(Const.MANU_ID));
+//        String specId = Strings.nullToEmpty((String) infos.get(Const.SPEC_ID));
+//        if(infos){
+//            return true;
+//        }
+//    }
+
+    private void pruneInfos(PropertyObj p, Hashtable<String, JSONObject> specMap) {
+        Map<String, Object> oldInfos = p.getInfos();
+        Map<String, Object> newInfos = new HashMap<>();
+        p.setInfos(newInfos);
+        newInfos.put("propertyId", p.getId());
+        newInfos.put("localName", oldInfos.get("EquipLocalName"));
+        newInfos.put("localId", oldInfos.get("EquipLocalID"));
+        newInfos.put("picture", oldInfos.get("Pic"));
+        newInfos.put("platePic", oldInfos.get("Nameplate"));
+        newInfos.put("productionDate", oldInfos.get("ProductDate"));
+        newInfos.put("serialNumber", oldInfos.get("serialNum"));
+
+        if (oldInfos.containsKey(Const.SPEC_ID)) {
+            String specId = oldInfos.get(Const.SPEC_ID).toString();
+            if (specMap.containsKey(specId)) {
+                JSONObject specObj = specMap.get(specId);
+                newInfos.put("brand", specObj.get("brandName"));
+                newInfos.put("product", oldInfos.get("productName"));
+                newInfos.put("specification", oldInfos.get("specificationName"));
+            }
+        }
+    }
+}

+ 42 - 0
src/main/java/com/sagacloud/route/processors/Manufacturer/GetVenderBySpecProcessor.java

@@ -0,0 +1,42 @@
+package com.sagacloud.route.processors.Manufacturer;
+
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.sagacloud.Exceptions.InvalidPostException;
+import com.sagacloud.pojos.PropertyObj;
+import com.sagacloud.utils.Const;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by Xiaoyu on 2018/7/12
+ */
+public class GetVenderBySpecProcessor implements Processor {
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        String jsonStr = exchange.getIn().getBody(String.class);
+        JSONObject json = JSONObject.parseObject(jsonStr);
+        if(json.getString("Result").equalsIgnoreCase("failure")){
+            throw new InvalidPostException("查询数据平台资产出错");
+        }
+        List<PropertyObj> propertyObjList = JSON.parseObject(json.getJSONArray("Content").toString(),List.class);
+        List<String> specIdList = new ArrayList<>();
+        for(PropertyObj p : propertyObjList){
+            Map<String,Object> infos = p.getInfos();
+            if(infos.containsKey(Const.SPEC_ID)){
+                specIdList.add((String) infos.get(Const.SPEC_ID));
+            }
+        }
+        //查询型号id所对应的生产商id
+        JSONObject queryJson = new JSONObject();
+        queryJson.put("specificationId",specIdList);
+        exchange.setProperty("property",propertyObjList);
+        exchange.getIn().setBody(queryJson.toString());
+        exchange.getIn().setHeader(Exchange.HTTP_URI, Const.venders+"/manufacturer/specification/query_vender?method=POST");
+    }
+}

+ 7 - 0
src/main/java/com/sagacloud/utils/ManufacturerUtil.java

@@ -0,0 +1,7 @@
+package com.sagacloud.utils;
+
+/**
+ * Created by Xiaoyu on 2018/7/12
+ */
+public class ManufacturerUtil {
+}