//去掉重复的key
for (MaterielLoss oldMaterielLoss : materielLosses) {
String temp = oldMaterielLoss.getMaterielCode();
//containsKey(Object key)该方法判断Map集合中是否包含指定的键名,如果包含返回true,不包含返回false
//containsValue(Object value)该方法判断Map集合中是否包含指定的键值,如果包含返回true,不包含返回false
if (tempMap.containsKey(temp)) {
MaterielLoss newMaterielLoss = new MaterielLoss();
BeanUtils.copyProperties(oldMaterielLoss, newMaterielLoss);
//合并相同key的value
newMaterielLoss.setLossCount(tempMap.get(temp).getLossCount() + oldMaterielLoss.getLossCount());
//HashMap不允许key重复,当有key重复时,前面key对应的value值会被覆盖
tempMap.put(temp, newMaterielLoss);
} else {
tempMap.put(temp, oldMaterielLoss);
}
}