Kaynağa Gözat

生产商查询资产完成,待测试

FanXiaoyu 6 yıl önce
ebeveyn
işleme
57ad248b50

+ 2 - 7
src/main/java/com/sagacloud/route/Route.java

@@ -1,19 +1,14 @@
 package com.sagacloud.route;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.github.rjeschke.txtmark.Processor;
-import com.sagacloud.Exceptions.InvalidPostException;
 import com.sagacloud.route.processors.Insurance.GetInsuranceNoListProcessor;
 import com.sagacloud.route.processors.GetPropByPjProcessor;
 import com.sagacloud.route.processors.Insurance.GetPropertyUnderWarrantyProcessor;
 import com.sagacloud.route.processors.Insurance.HandleWarrantyFromVenderProcessor;
+import com.sagacloud.route.processors.Manufacturer.MaunfacturerFilter;
 import com.sagacloud.route.processors.Manufacturer.GetVenderBySpecProcessor;
 import com.sagacloud.utils.Const;
-import com.sagacloud.utils.VendersUtil;
-import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.http.common.HttpOperationFailedException;
 import org.apache.commons.io.IOUtils;
 
 import javax.ws.rs.core.MediaType;
@@ -49,7 +44,7 @@ public class Route extends ExceptionHandlerBaseRoute {
                 .to("direct:getPropertiesByPj")
                 .process(new GetVenderBySpecProcessor())
                 .to(Const.venders+"/manufacturer/specification/query_vender")
-                .process();
+                .process(new MaunfacturerFilter());
 
         // 查询项目下的资产
         rest("/supplier/property/").post("query")

+ 23 - 10
src/main/java/com/sagacloud/route/processors/Manufacturer/Filter.java

@@ -6,6 +6,7 @@ import com.google.common.base.Strings;
 import com.sagacloud.Exceptions.InvalidPostException;
 import com.sagacloud.pojos.PropertyObj;
 import com.sagacloud.utils.Const;
+import com.sagacloud.utils.VendersUtil;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 
@@ -17,7 +18,7 @@ import java.util.Map;
 /**
  * Created by Xiaoyu on 2018/7/12
  */
-public class Filter implements Processor {
+public class MaunfacturerFilter implements Processor {
 
 
     @Override
@@ -37,19 +38,31 @@ public class Filter implements Processor {
         List<PropertyObj> propertyObjList = (List<PropertyObj>) exchange.getProperty("property");
         for (int i = propertyObjList.size() - 1; i >= 0; --i) {
             PropertyObj p = propertyObjList.get(i);
-
+            boolean valid = validate(p,specMap,targetVenderId);
+            if(valid){
+                pruneInfos(p,specMap);
+            }else{
+                propertyObjList.remove(i);
+            }
         }
+        exchange.getOut().setBody(VendersUtil.successJsonMsg("",propertyObjList));
 
     }
 
-//    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 boolean validate(PropertyObj p, Hashtable<String, JSONObject> specMap,String targetVenderId){
+        Map<String, Object> infos = p.getInfos();
+        if(infos.get(Const.MANU_ID)!=null){
+            String venderId = Strings.nullToEmpty((String) infos.get(Const.MANU_ID));
+            return venderId.equals(targetVenderId);
+        }else{
+            String specId = Strings.nullToEmpty((String) infos.get(Const.SPEC_ID));
+            if(specMap.containsKey(specId)){
+                String venderId = specMap.get(specId).getString("venderId");
+                return venderId.equals(targetVenderId);
+            }
+        }
+        return false;
+    }
 
     private void pruneInfos(PropertyObj p, Hashtable<String, JSONObject> specMap) {
         Map<String, Object> oldInfos = p.getInfos();