从两个接口获取到了数据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;
}
 

需求中碰到的简单Map集合 key相同合并 value的思路的更多相关文章

  1. ES6中的Set和Map集合

    前面的话 在ES6标准制定以前,由于可选的集合类型有限,数组使用的又是数值型索引,因而经常被用于创建队列和栈.如果需要使用非数值型索引,就会用非数组对象创建所需的数据结构,而这就是Set集合与Map集 ...

  2. java.util.Map按照key值合并的value的Collection 集合中。

    用java实现把多个map的内容合并的一个resultMap中 代码大致如下 /**  * @author Shalf  */ public class MapUtil { /** * 把partMa ...

  3. 定义一个Map集合,key和value不规定类型,任意放入数据,用keySet()和 entrySet()两种方式遍历出Map集合的数据

    package com.lanxi.demo1_1_1; import java.util.HashMap; import java.util.Iterator; import java.util.M ...

  4. map集合修改其中元素 去除Map集合中所有具有相同值的元素 Properties长久保存的流操作 两种用map记录单词或字母个数的方法

    package com.swift.lianxi; import java.util.HashMap; import java.util.Iterator; import java.util.Map; ...

  5. 【读书笔记】【深入理解ES6】#7-Set集合和Map集合

    ES6新标准中将Set集合和Map集合添加到JS中. ES5中Set集合和Map集合 在ES5中,开发者们用对象属性来模拟这两种集合. var set = Object.create(null); s ...

  6. 编程坑太多,Map 集合怎么也有这么多坑?一不小心又踩了好几个!

    点赞再看,养成习惯,微信搜索『程序通事』,关注就完事了! 点击查看更多历史文章 上一篇 List 踩坑文章中,我们提到几个比较容易踩坑的点.作为 List 集合好兄弟 Map,我们也是天天都在使用,一 ...

  7. List和Map集合详细分析

    1.Java集合主要三种类型(两部分): 第一部分:Collection(存单个数据,只能存取引用类型) (1).List :是一个有序集合,可以放重复的数据:(存顺序和取顺序相同) (2).Set ...

  8. Java集合的实现细节—Set集合和Map集合

    Set:代表无序.不可重复的集合 Map:代表key-value对集合,也称为关联数组 从表面上看,Set和Map相似性很少,但实际上可以说Map集合时Set集合的扩展. 1.Set集合和Map集合的 ...

  9. java学习笔记—集合之Map集合

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: center; font: 12.0px Times } p.p2 { margin: 0.0p ...

随机推荐

  1. what's the python之可迭代对象、迭代器与生成器(附面试题)

    可迭代对象 字符串.列表.元祖.集合.字典都是可迭代的,数字是不可迭代的.(可以用for循环遍历取出内部元素的就是可迭代的) 如何查看一个变量是否为可迭代: from collections impo ...

  2. MySQL 5.7 新特性大全和未来展望

    引用 美图公司数据库高级 DBA,负责美图后端数据存储平台建设和架构设计.前新浪高级数据库工程师,负责新浪微博核心数据库架构改造优化,以及数据库相关的服务器存储选型设计.之前在「高可用架构」发表的&l ...

  3. Delphi窗体置顶及失去焦点后取得焦点

    unit u_FrmTopMostActive; interface uses Winapi.Windows; implementation // 窗体置顶 procedure SetXwForegr ...

  4. redis.conf密码设置的问题

    requirepass是终端客户端登录需要的密码,配置在服务端 masterauth是从服务器端登录master端需要的密码,配置在从服务端

  5. ppt 调整 页面 白色区域 大小

    1:  点击设计>大小 2:点击确保适合 3:成功

  6. Python的Matplotlib库简述

    Matplotlib 库是 python 的数据可视化库import matplotlib.pyplot as plt 1.字符串转化为日期 unrate = pd.read_csv("un ...

  7. jmeter 发送加密请求 beanshell断言 线程组间传递参数

    原文地址https://www.cnblogs.com/wnfindbug/p/5817038.html 最近在做http加密接口,请求头的uid参数及body的请求json参数都经过加密再发送请求, ...

  8. cocos2d JS 艺术字特殊符号的显示

    this.setSocreAtion(score, this.tfMoneyList[index],mun); //传入分数与对象,调用下面的函数 setSocreAtion : function ( ...

  9. python进阶(六) 虚拟环境git clone报错解决办法

    在虚拟环境目录,进行git clone xxxxx.git  项目,报如下图错误 解决办法:env GIT_SSL_NO_VERIFY=true git clone xxxx.git

  10. Spring @Value注解 and Spring Boot @ConfigurationProperties注解

    一.Spring的@Value Spring EL表达式语言,支持在XML和注解中表达式,类是于JSP的EL表达式语言. 在Spring开发中经常涉及调用各种资源的情况,包含普通文件.网址.配置文件. ...