|
@@ -0,0 +1,79 @@
|
|
|
+package com.sagacloud.route.processors.supplier;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Hashtable;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Xiaoyu on 2018/7/13
|
|
|
+ */
|
|
|
+public class SupplierFilter 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);
|
|
|
+ boolean valid = validate(p,targetVenderId);
|
|
|
+ if(valid){
|
|
|
+ pruneInfos(p,specMap);
|
|
|
+ }else{
|
|
|
+ propertyObjList.remove(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ exchange.getOut().setBody(VendersUtil.successJsonMsg("",propertyObjList));
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validate(PropertyObj p, String targetVenderId) {
|
|
|
+ Map<String, Object> infos = p.getInfos();
|
|
|
+ if(infos.get(Const.SUPP_ID)==null){
|
|
|
+ return false;
|
|
|
+ }else{
|
|
|
+ return targetVenderId.equals(infos.get(Const.SUPP_ID));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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("EquipLocalName", oldInfos.get("EquipLocalName"));
|
|
|
+ newInfos.put("EquipLocalId", oldInfos.get("EquipLocalID"));
|
|
|
+ newInfos.put("PurchasePrice", oldInfos.get("PurchasePrice"));
|
|
|
+ newInfos.put("Warranty", oldInfos.get("Warranty"));
|
|
|
+ newInfos.put("ProductDate", oldInfos.get("ProductDate"));
|
|
|
+ newInfos.put("SerialNum", oldInfos.get("SerialNum"));
|
|
|
+ newInfos.put("SupplierContractID", oldInfos.get("SupplierContractID"));
|
|
|
+
|
|
|
+ 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", specObj.get("productName"));
|
|
|
+ newInfos.put("Specification", specObj.get("specificationName"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|