lambda表达式分组,多字段求和
1.
public class PayDetailToBabModel implements Serializable {
private static final long serialVersionUID = -5197016274254913057L;
private String productCode;
private String productName;
private Long money;
private BigDecimal amount;
private BigDecimal price;
private Integer cityId;
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public Long getMoney() {
return money;
}
public void setMoney(Long money) {
< = money;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public Integer getCityId() {
return cityId;
}
public void setCityId(Integer cityId) {
this.cityId = cityId;
}
public String getCodeAndCityId() {
if (money >= 0) {
return  productCode+"_"+cityId;
} else {
return  "2"+productCode+"_"+cityId;
return  "2"+productCode+"_"+cityId;
}
}
}
bigdecimal转换为integer2.
public List<PayDetailToBabModel> getPayDetail(PayDetailToBabQuery model) {
List<PayDetailToBabModel> payDetail = PayDetail(model);
// 分组
Map<String, List<PayDetailToBabModel>> collect = payDetail.stream().upingBy(PayDetailToBabModel::getCodeAndCityId));
List<PayDetailToBabModel> results = collect.values().stream().map((List<PayDetailToBabModel> details) ->{
Long totalMoney = 0L;
BigDecimal totalAmount = new BigDecimal(0);
for (PayDetailToBabModel detail : details) {
totalMoney += Money();
totalAmount = totalAmount.Amount());
}
BigDecimal price = null;
if (totalAmount.equals(new BigDecimal(0))) {
price = new BigDecimal(totalMoney);
totalAmount = new BigDecimal(1);
} else {
price = new BigDecimal(totalMoney).divide(new BigDecimal(100),6).divide(totalAmount,6);
}
PayDetailToBabModel babModel = new PayDetailToBabModel();
babModel.setMoney(totalMoney);
babModel.setAmount(totalAmount);
babModel.setPrice(price);
babModel.(0).getProductName());
babModel.(0).getProductCode());
return babModel;
}).List());
return  results;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。