优化这段代码:Map<String, List<DeepAnalysisSmsRecordResultVo>> smsListMap = smsList.stream().collect(Collectors.groupingBy(DeepAnalysisSmsRecordResultVo::getCollectTargetId)); for (Map.Entry<String, List<DeepAnalysisSmsRecordResultVo>> entry : smsListMap.entrySet()) { String key = entry.getKey(); List<DeepAnalysisSmsRecordResultVo> value = entry.getValue(); if (key.contains(iNode.getCollectTargetId())) { Integer z = null; for (DeepAnalysisSmsRecordResultVo sms : value) { String phone = sms.getOtherNumber(); List<MobilePhonePersonIdentityNumberVo> persons = getCasePerson("3", phone); Long personId = persons.get(0).getPersonId(); for (int j = 0; j < nodeList.size(); j++) { MobilePhoneModelPersonDiagramNodeVo jNode = nodeList.get(j); if (jNode.getPersonId().equals(personId)) { z = j; break; } } } MobilePhoneModelPersonDiagramLinkVo linkVo = new MobilePhoneModelPersonDiagramLinkVo(); linkVo.setSource(i); linkVo.setTarget(z); linkVo.setName("短信记录"); linkVo.setNumber(value.size()); linkList.add(linkVo); } }
时间: 2024-02-14 20:31:51 浏览: 75
一段关于短信收发的代码
优化后的代码如下:
Map<String, List<DeepAnalysisSmsRecordResultVo>> smsListMap = smsList.stream()
.filter(sms -> sms.getCollectTargetId().contains(iNode.getCollectTargetId()))
.collect(Collectors.groupingBy(DeepAnalysisSmsRecordResultVo::getCollectTargetId));
for (Map.Entry<String, List<DeepAnalysisSmsRecordResultVo>> entry : smsListMap.entrySet()) {
String key = entry.getKey();
List<DeepAnalysisSmsRecordResultVo> value = entry.getValue();
Integer z = null;
for (DeepAnalysisSmsRecordResultVo sms : value) {
String phone = sms.getOtherNumber();
List<MobilePhonePersonIdentityNumberVo> persons = getCasePerson("3", phone);
Long personId = persons.get(0).getPersonId();
for (int j = 0; j < nodeList.size(); j++) {
MobilePhoneModelPersonDiagramNodeVo jNode = nodeList.get(j);
if (jNode.getPersonId().equals(personId)) {
z = j;
break;
}
}
}
MobilePhoneModelPersonDiagramLinkVo linkVo = new MobilePhoneModelPersonDiagramLinkVo();
linkVo.setSource(i);
linkVo.setTarget(z);
linkVo.setName("短信记录");
linkVo.setNumber(value.size());
linkList.add(linkVo);
}
阅读全文