從兩個接口獲取到了數據Map集合, 但是要展示到同一頁面 根據了播控人為key 將兩個返回的進行遍歷 將他們存在新的map里面 只有單個key value 就存為(MAP<object,object> ,多個直接存為Map<object,Map>
將兩個接口獲取到的key作為存入set去重
后去set 根據key(person)去取到各自對應的值,存入map 返回
方法很繁瑣 ,循環太多,但遇到了 ,就這么實現的
數據example ::// {(all,xxx),(count,600)},{("張三",xxx),(count,190)}
// {(all,xxx),(count,190),(per,10%)},{("張三,xxx),(count,190),(per,10%)}
@RequestMapping("/sx_review_all") @ResponseBody public List<Map<String, Object>> getReviewData(String startDate, String endDate) { List<Map<String, Object>> list = new ArrayList<>(); //實時數據和離線數據的 List<Map<String, String>> rlData = this.auditorRt(); List<Map<String, Object>> olData = this.auditorOl(startDate, endDate); Map<String, Object> rlmap = new HashMap<>(); Map<String, Map<String,Object>> olmap = new HashMap<>(); Set<String> personSet = new HashSet<>(); ;//存實時播控人 以姓名為key,count為值 for (Map<String, String> rl : rlData) { String person = rl.get("auditor"); rlmap.put(person, rl.get("person_bc_amt")); personSet.add(person); } for (Map<String, Object> ol : olData) { String person = ol.get("bc_person").toString(); Map<String,Object> cacheMap= new HashMap(); cacheMap.put("olAmt",ol.get("count").toString()); cacheMap.put("total",olData.get(0).get("count").toString()); cacheMap.put("is_bc_re", ol.get("is_bc_re").toString()); cacheMap.put("per", ol.get("per").toString()); olmap.put(person, cacheMap); personSet.add(person); } if (olData.size()>0){ for(String person:personSet) { // String person = ol.get("bc_person").toString(); Map<String, Object> cache = new HashMap<>(); cache.put("auditor", person); cache.put("rlAmt", rlmap.get(person) == null ? 0 : rlmap.get(person));//判斷 cache.put("olAmt", olmap.get(person) != null ? olmap.get(person).get("olAmt") : 0); cache.put("total", olData.get(0).get("count").toString()); cache.put("is_bc_re", olmap.get(person) != null ? olmap.get(person).get("is_bc_re") : 0); cache.put("per", olmap.get(person) != null ? olmap.get(person).get("per") : 0); list.add(cache); } // return list; } else { for (Map<String, String> rl : rlData) { Map<String, Object> cache = new HashMap<>(); cache.put("auditor", rl.get("auditor")); cache.put("rlAmt", rl.get("person_bc_amt"));//判斷 cache.put("olAmt", 0); cache.put("total", 0); cache.put("is_bc_re", 0); cache.put("per", 0); list.add(cache); } } // }else { // if (olData.size() != 0) { // for (Map<String, String> rl : rlData) { // String person = rl.get("auditor"); // Map<String, Object> cache = new HashMap<>(); // cache.put("auditor", rl.get("auditor")); // cache.put("rlAmt", rl.get("person_bc_amt"));//判斷 // cache.put("olAmt", olmap.get(person)!=null ?olmap.get(person).get("olAmt"):0); // cache.put("total", olData.get(0).get("count").toString()); // cache.put("is_bc_re",olmap.get(person)!=null ?olmap.get(person).get("is_bc_re"):0 ); // cache.put("per", olmap.get(person)!=null ?olmap.get(person).get("per"):0); // list.add(cache); // } // // return list; // } // // } return list; }