需要了解的网址:
https://blog.csdn.net/qq_28410283/article/details/80634725
https://blog.csdn.net/qq_28410283/article/details/80783505
代码:
Boolean bl=traceNodeInfos.stream().filter(node -> {
return 1 == node.getHead();
}).findFirst().isPresent();
if(bl){
return traceNodeInfos.stream().filter(node -> {
return 1 == node.getHead();
}).findFirst().get();
}
Optional optional=traceNodeInfos.stream().filter(node -> {
return 1 == node.getHead();
}).findFirst();
if(optional.isPresent()){
WfTraceNodeInfo wfTraceNodeInfo=optional.get();
}else{
}
return traceNodeInfos.stream().filter(node -> {
return 1 == node.getHead();
}).findFirst().get();
https://www.cnblogs.com/aoeiuv/p/5911692.html
java8表达式
filter的使用:
listRoles =listRoles.stream().filter(ele-> !ele.getAssignee().equals(bill.getCreator()) ).collect(Collectors.toList());
listRoles =listRoles.stream().filter(ele-> (!ele.getAssignee().equals(bill.getCreator()) )).collect(Collectors.toList());
Optional<PexContentBill> re=listRoles.stream().filter(ele-> (ele.getAssignee().equals(bill.getCreator()) )).findFirst();
.findFirst()是之查询第一条
listRoles =listRoles.stream().filter(ele-> {return !ele.getAssignee().equals(bill.getCreator());}).collect(Collectors.toList());
groupBy的用法:
Map<String, List<PexContentBill>> collect = listRoles.stream()
.collect(Collectors.groupingBy(PexContentBill::getAgyCode));
查询出来的数据格式如下
{009=[PexContentBill(billId=ae7c6020d47c11e8b9b79ff34dd60024, billNo=SQ20181020000464, billType=trainning, billTypeName=培训费申请单, billFunc=apply, creator=lvjun_zd, creatorName=吕俊, createdTime=2018-10-20 23:27:58, claimantCode=lvjun_zd, claimantName=吕俊, createdTimeStart=null, createdTimeEnd=null, modifier=lvjun_zd, modifierName=吕俊, modifiedTime=2018-10-20 23:27:58, agyCode=009, agyName=吉林市船营区财政局, departmentCode=02, departmentName=纪律部, fiscal=2018, ver=null, reason=null, quotaAmt=null, usedAmt=null, remarks=null, outChannel=null, inputAmt=1.00, checkAmt=1.00, totalAmt=null, canUsedAmt=null, isSend=0, isPay=0, isVou=0, vouId=null, sendDate=null, payDate=null, vouDate=null, transDate=2018-10-20, exeNodeId=null, settlements=null, isSettle=0, expenseTypeCodes=[], overApply=0, pageIndex=null, pageSize=null)]
map的使用方法:
1:
List<Map> records = indexEleDao.selectAgyIndexEleInfo(params);
List<Map> result = records.stream().map(row -> {
Map indexEle = new HashMap();
indexEle.put("code", row.get("code"));
indexEle.put("name", row.get("name"));
indexEle.put("atomName", row.get("atomName"));
indexEle.put("atomCode", row.get("atomCode"));
indexEle.put("codeRule", row.get("codeRule"));
return indexEle;
}).collect(Collectors.toList());
2:
List<String> listRo=listRoles.stream().map(PexContentBill::getBillTypeName).collect(Collectors.toList());
listRoles的值为:
[培训费申请单, 培训费申请单, 培训费申请单, 培训费申请单, 培训费申请单, 会议费申请单, 会议费申请单, 会议费申请单其他费用申请单, 会议费申请单]
foreach和map的区别:
List<PexApplyBillVo> list=toDoDao.apply(bill);
//foreach和map的写法的区别
list.stream().forEach(ele->{
if(ele.getUsedAmt()==null){
ele.setUsedAmt(PexConstants.ZERO);
}
});
return list;
/*return toDoDao.apply(bill).stream().map(apply->{
if(apply.getUsedAmt()==null){
apply.setUsedAmt(PexConstants.ZERO);
}
return apply;
}).collect(Collectors.toList());*/
//这是错误的写法
/*toDoDao.apply(bill).forEach(ele->{
if(ele.getUsedAmt()==null){
ele.setUsedAmt(PexConstants.ZERO);
}
});*/
/**
* 校验单位项目总体,每月是否可以上报
*/
@Override
public CheckMsg reportSchePlan(List<BipSchePlan> plans) {
BipImpPlanSetting sett = new BipImpPlanSetting();
Map<String, List<BipImpPlanSetting>> settMap = impPlanSettingService.selectBudImpPlanSetting(sett);
if (plans.size() > 0) {
BigDecimal janScheduleSum = plans.stream().map(BipSchePlan::getJanSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal febScheduleSum = plans.stream().map(BipSchePlan::getFebSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal marScheduleSum = plans.stream().map(BipSchePlan::getMarSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal aprScheduleSum = plans.stream().map(BipSchePlan::getAprSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal mayScheduleSum = plans.stream().map(BipSchePlan::getMaySchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal junScheduleSum = plans.stream().map(BipSchePlan::getJunSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal julScheduleSum = plans.stream().map(BipSchePlan::getJulSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal augScheduleSum = plans.stream().map(BipSchePlan::getAugSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal sepScheduleSum = plans.stream().map(BipSchePlan::getSepSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal octScheduleSum = plans.stream().map(BipSchePlan::getOctSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal novScheduleSum = plans.stream().map(BipSchePlan::getNovSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
BigDecimal decScheduleSum = plans.stream().map(BipSchePlan::getDecSchedule).reduce(BigDecimal.ZERO,
(sum, amt) -> {
return amt == null ? sum : sum.add(amt);
});
for (BipSchePlan bipSchePlan : plans) {
List<BipImpPlanSetting> commonList = settMap.get("commonList");
//PropertyUtil.clone(bipSchePlan, commonList);
StringBuffer comMonthStr = new StringBuffer();
comMonthStr.append(bipSchePlan.getAgyName() + "单位:");
if (janScheduleSum.compareTo(new BigDecimal(commonList.get(0).getJanSchedule() + "")) == -1) {
comMonthStr.append("1、");
}
projectCheck(bipSchePlan, settMap.get("projectList"));
}
System.out.println(janScheduleSum);
}
return CheckMsg.success();
}
list转map的用法:
List<Map<String, Object>> vars = taskDao.findCompleteVariables(processInstanceId);
Map<String, Object> nameValueMap = new HashMap<String, Object>();
for (Map<String, Object> processMap : vars) {
String name = (String) processMap.get("name");
String value = (String) processMap.get("value");
nameValueMap.put(name, value);
}
/**
* 批量插入科目
*/
@Override
@Transactional(rollbackFor = Exception.class)
public CheckMsg insertBath( List<MadAco> acos ) throws Exception {
// 批量插入会计科目
CheckMsg msg = CheckMsg.success();
if (!CollectionUtils.isEmpty(acos)){
List<MadAco> acoList = acos.stream().collect(
Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getMadCode()+","+o.getAgyCode()))),
ArrayList::new));
List<List<MadAco>> lists = Lists.partition(acoList, 200);
for (List<MadAco> subList : lists) {
acoDao.insertBatch(subList);
List<MadAcoAcitemVO> madAcoAcitems = new ArrayList<>();
subList.stream().forEach(madAco -> {
madAcoAcitems.addAll(madAco.getAcoAcitems());
});
acoAcitemService.insertBatch(madAcoAcitems);
}
}
return msg;
}
Predicate的用法
Predicate<PtyBudBalance> expTypePredicate = balance -> !ObjectUtils.isEmpty(balance.getExptypeName()) && "基本支出".equals(balance.getExptypeName());
Predicate<PtyBudBalance> bgProjectPredicate = balance -> !ObjectUtils.isEmpty(balance.getProjectName()) && Pattern.matches(pattern, balance.getProjectName());
List<PtyBudBalance> bgBalances = budBalances.stream().filter(expTypePredicate.and(bgProjectPredicate)).collect(Collectors.toList());
看不明白的话 看这个:
List<WfNodeInfo> nodes =getAllDefinition(tenantId,key);
Predicate<WfNodeInfo> lsl=balance -> !ObjectUtils.isEmpty(balance.getName()) && "基本支出".equals(balance.getName());
isPresent
if(findFirst.isPresent()){
GalMemoVouRelDO galMemoVouRelDO = findFirst.get();
A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.
一个容器对象,它可能包含也可能不包含非空值。如果存在一个值,isPresent()将返回true, get()将返回值。
Java8中争对于map类型得数据得操作
Map<String, List<PexBillTypeVo>> groups = billTypes.stream()
.collect(Collectors.groupingBy(PexBillTypeVo::getBillTypeCode));
// 获取申请单类型
List<Map> applys = groups.entrySet().stream().filter(entry -> {
return entry.getValue().stream().anyMatch(billTypeVo -> {
//过滤合同数据
return PexConstants.BILL_FUNC_APPLY.equals(billTypeVo.getBillFunc()) && billTypeVo.getNeedApply() != null
&& billTypeVo.getNeedApply() == 1 && !PexConstants.BILL_TYPE_HTZFD.equals(billTypeVo.getBillTypeCode());
});
}).map(entry -> {
Map billType = new HashMap();
PexBillTypeVo first = entry.getValue().get(0);
billType.put("seq", first.getSeq());
billType.put("billType", first.getBillTypeCode());
billType.put("billName", first.getBillTypeName());
billType.put("remark",first.getRemark());
return billType;
}).sorted(seqComparator).collect(Collectors.toList());
Java中相对于二个集合:
A集合比B集合多的,B加上
A集合比B集合少的,B减去
JSONArray jsonArray = JSONArray.fromObject(docInfo.getSearchConfig());
List<SearchField> list = (List) JSONArray.toCollection(jsonArray, SearchField.class);
List<SearchField> distinctByUniqueAddList = listValue.stream().filter(item -> !list.stream()
.map(e -> e.getCode()).collect(Collectors.toList()).contains(item.getCode()))
.collect(Collectors.toList());
list.addAll(distinctByUniqueAddList);
List<SearchField> distinctByUniqueRemoveList = list.stream().filter(item -> !listValue.stream()
.map(e -> e.getCode()).collect(Collectors.toList()).contains(item.getCode()))
.collect(Collectors.toList());
list.removeAll(distinctByUniqueRemoveList);
对于map类型得数据得操作
Map<String, List<PexRuleExpense>> collect = list.stream().collect(Collectors.groupingBy(PexRuleExpense::getValCode));
for (String key : collect.keySet()) {
Map<String, Object> data = new HashMap<>();
Map<String, String> map = collect.get(key).stream().collect(Collectors.toMap(PexRuleExpense::getExpenseTypeCode, PexRuleExpense::getCostStandard));
for (String k : map.keySet()) {
data.put(k,new BigDecimal(map.get(k)));
}
result.put(key,data);
}
Java8中的map的循环
paOptions.stream().forEach(info -> {
paOptionMap.forEach((k, v) -> {
if (info.getOptCode().equals(k)) {
Map<Object, Object> tempMap = Maps.newHashMap();
tempMap.put("optId", info.getOptId());
tempMap.put("optValue", info.getOptValue());
paOptionMap.put(k, tempMap);
}
});
});