|
@@ -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"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|