1,【list转map】
1.1
Map<String, OrganizationVO> groupMap = new HashMap<>();
if(CollectionUtils.isNotEmpty(groupList)){
groupMap = groupList.stream().collect(MapCollectors.toMap(v->v.getPurchaseOrgCode(), v->v));
}
1.2
return products.stream().collect(Collectors.toMap(k -> k.getProductCode(), v -> v, (a, b) -> b));
2,【map获取value】
List<SelectionProductShop> productShopSupplier = productShopHashMap.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList());
3,【list转list】
3.1
List<ReqSupplierOrderCycleVO> queryExpectedTime = productShopSupplier.stream().map(v -> {
ReqSupplierOrderCycleVO supplierOrderCycleVO = new ReqSupplierOrderCycleVO();
supplierOrderCycleVO.setSupplierCode(v.getProductCode());
supplierOrderCycleVO.setBigCategoryCode(v.getShopCode());
supplierOrderCycleVO.setLocationCode(v.getShopCode());
return supplierOrderCycleVO;
}).collect(Collectors.toList());
3.2
List<ResFreshSmallAreaConfigVO> resultList = new ArrayList<>();
List<FreshSmallAreaConfig> freshSmallAreaConfigs = freshSmallAreaConfigMapper.selectSearchSmallArea(smallArea);
freshSmallAreaConfigs.forEach(freshSmallAreaConfig -> {
resultList.add(new ResFreshSmallAreaConfigVO(freshSmallAreaConfig.getId(), freshSmallAreaConfig.getSmallArea()));
});
return R.success(resultList);
4,【list转map<String,List<Object>>】
获取商品门店对应供应商列表
4.1 key多属性
private Map<String, List<String>> getSupplierCodeList(List<LocationProductKeyVO> params) {
Map<String, List<String>> supplierCodeMap = new HashMap<>();
params.forEach(keyVo -> {
String key = StringUtil.contact(BizConstant.UNDERLINE, keyVo.getLocationCode(), keyVo.getProductCode());
List<String> supplierCodeList = supplierCodeMap.containsKey(key) ? supplierCodeMap.get(key) : new ArrayList<>();
supplierCodeList.add(keyVo.getSupplierCode());
supplierCodeMap.put(key, supplierCodeList);
});
return supplierCodeMap;
}
4.2 key单属性
Map<String, List<SelectionProductShop>> shopMap = Maps.newHashMap();
shopMap = list.stream().collect(Collectors.groupingBy(SelectionProductShop::getShopCode,LinkedHashMap::new, Collectors.toList()));
4.3 key多属性
Map<String, List<SelectionProductShop>> result = selectionProductShopList.stream().collect(Collectors.groupingBy(e -> e.getShopCode() + e.getProductCode()));
4.4
Map<String, List<ShopRepCartVO>> queryResult = Maps.newHashMap();
shopRepCartVOS.stream().forEach(result -> {
String key = StringUtil.contact(BizConstant.UNDERLINE, result.getShopCode(), result.getProductCode());
List<ShopRepCartVO> vos = queryResult.containsKey(key) ? queryResult.get(key) : new ArrayList<>();
vos.add(result);
queryResult.put(key, vos);
});
5,循环赋值
List<ShopProductDetailVO> detailVOS = baseProductShopClient.getByProductCodeMult(vos).getResult();
Map<String, ShopProductDetailVO> supplierMap = detailVOS.stream().collect(MapCollectors.toMap(v -> StringUtil.contact(BizConstant.UNDERLINE, v.getShopCode(), v.getProductCode()), v -> v));
list.stream().forEach(v -> {
ShopProductDetailVO detailVO = supplierMap.get(StringUtil.contact(BizConstant.UNDERLINE, v.getShopCode(), v.getProductCode()));
v.setSupplierCode(detailVO.getSupplierCode());
v.setSupplierName(detailVO.getSupplierName());
});
6,获取List<Object>属性组合
List<String> shopProducts = listEs.stream().map(v -> v.getLocationCode() + StringUtilBuilder.UNDER_LINE + v.getProductCode()).collect(Collectors.toList());
7,字符串拼接
StringUtil.contact(BizConstant.UNDERLINE, v.getShopCode(), v.getProductCode())