for (Winning winning : winnings) { // 若存在物流信息 发货时间不能为空 if (winning.getPostTime() != null){ rightNow.setTime(winning.getPostTime()); //日期加1个月 rightNow.add(Calendar.MONTH,1); flg = rightNow.getTime().compareTo(new Date()); if (flg <= 0 ){ flag = true; } } if (!VtuzxUtil.isEmpty(winning.getOutState())){ // 自动收货 if(winning.getOutState().equals(String.valueOf(PrizeOutStateEnum.Sent_ENUM.value())) && flag){ // 修改发放状态为已收货 winningDao.updOutStateById(String.valueOf(winning.getId()),PrizeOutStateEnum.Receive_Goods.value()); winning.setOutState(PrizeOutStateEnum.Receive_Goods.value()); flag = false; } } dataList.add( new VtuzxMap("prizeName",winning.getPrizeName()) .append("receiptNo",winning.getReceiptNo()) .append("companyName",winning.getCompanyName()) .append("department",winning.getDepartment()) .append("prizeNum",winning.getPrizeNum()) .append("outStore",winning.getOutStore()) .append("giveOut",winning.getGiveOut()) .append("userName",winning.getUserName()) .append("activityName",winning.getActivityName()) .append("outState",winning.getOutState()) .append("mobile",winning.getMobile()) .append("activityId",winning.getAwardActivityId()) .append("prizeType",winning.getPrizeType()) .append("clearingState",winning.getClearingState()) .append("postCompany",winning.getPostCompany()) .append("storeName", winning.getStoreName()) .append("postNo",winning.getPostNo()) .append("postName",winning.getPostName()) .append("contactMobile",winning.getContactMobile()) .append("province",winning.getProvince()) .append("city",winning.getCity()) .append("area",winning.getArea()) .append("createdAt",VtuzxUtil.formatYmdHmsF(winning.getCreatedAt())) .append("addressDetail",winning.getAddressDetail()) ); }使用stream优化
时间: 2024-03-05 22:48:37 浏览: 104
Ulam’s searching game with.pdf
可以使用 Java 8 中的 stream 来优化上述代码,具体实现如下:
```
List<Map<String, Object>> dataList = winnings.stream()
.filter(winning -> winning.getPostTime() != null)
.map(winning -> {
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(winning.getPostTime());
rightNow.add(Calendar.MONTH, 1);
boolean flag = rightNow.getTime().compareTo(new Date()) <= 0;
if (!VtuzxUtil.isEmpty(winning.getOutState()) && winning.getOutState().equals(String.valueOf(PrizeOutStateEnum.Sent_ENUM.value())) && flag) {
winningDao.updOutStateById(String.valueOf(winning.getId()), PrizeOutStateEnum.Receive_Goods.value());
winning.setOutState(PrizeOutStateEnum.Receive_Goods.value());
flag = false;
}
return new VtuzxMap("prizeName", winning.getPrizeName())
.append("receiptNo", winning.getReceiptNo())
.append("companyName", winning.getCompanyName())
.append("department", winning.getDepartment())
.append("prizeNum", winning.getPrizeNum())
.append("outStore", winning.getOutStore())
.append("giveOut", winning.getGiveOut())
.append("userName", winning.getUserName())
.append("activityName", winning.getActivityName())
.append("outState", winning.getOutState())
.append("mobile", winning.getMobile())
.append("activityId", winning.getAwardActivityId())
.append("prizeType", winning.getPrizeType())
.append("clearingState", winning.getClearingState())
.append("postCompany", winning.getPostCompany())
.append("storeName", winning.getStoreName())
.append("postNo", winning.getPostNo())
.append("postName", winning.getPostName())
.append("contactMobile", winning.getContactMobile())
.append("province", winning.getProvince())
.append("city", winning.getCity())
.append("area", winning.getArea())
.append("createdAt", VtuzxUtil.formatYmdHmsF(winning.getCreatedAt()))
.append("addressDetail", winning.getAddressDetail());
})
.collect(Collectors.toList());
```
使用 stream 可以让代码更加简洁和易于理解,同时也有更好的可读性和可维护性。
阅读全文