java8的groupingBy实战
程序员文章站
2022-03-20 11:25:18
...
groupingBy是归类的意思,我代码就是每个公司相同的进行分类,相同公司的数据进行处理
代码如下:
List<SaleOrderItemInfoDTO> saleOrderItemInfoDTOS = this.saleOrderItemMapper.saleOrderItemInfos(param);
if (CollectionUtils.isNotEmpty(saleOrderItemInfoDTOS)) {
Map<Long, List<SaleOrderItemInfoDTO>> saleOrderItemInfoListGroup = saleOrderItemInfoDTOS.stream().collect(Collectors.groupingBy(SaleOrderItemInfoDTO::getEnterpriseId));
if (saleOrderItemInfoListGroup.size() > 1) {
throw new ResultException("");
}
saleOrderItemInfoListGroup.forEach( (k,v)-> {
Long enterpriseId = k;
List<SaleOrderItemInfoDTO> saleOrderItemInfoDTOList = v;
// 然后进行逻辑处理
}
SaleOrderItemInfoDTO不包含以下字段:
public class SaleOrderItemInfoDTO{
/**
* 公司id
*/
private Long enterpriseId;
private Long a;
private Long b;
private String c;
}
下一篇: Shell的后台运行(&)与nohup