曾经写过一个感觉比较复杂的业务,大家看看是否能直接SQL解决呢?
作者:互联网
public static List excelSortLoanNo(List list) {
Predicate<list> singleOrNot = equalsList -> equalsList.size() > 1;
//可针对三种情况导出列表,对导出的借据号重复的放在一起(并提示与哪一行重复),为null的排除
List listVisiable = list.stream()
.filter(exl -> {
try {
Field field = exl.getClass().getDeclaredField(LOAN_NUMBER);
field.setAccessible(true);
return field.get(exl) != null;
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false;
})
.sorted((in1, in2) -> {
Field field1 = null;
Field field2 = null;
try {
field1 = in1.getClass().getDeclaredField(LOAN_NUMBER);
field2 = in2.getClass().getDeclaredField(LOAN_NUMBER);
field1.setAccessible(true);
field2.setAccessible(true);
} catch (NoSuchFieldException e) {
log.error("excelSortLoanNo字段不存在");
}
return field1.hashCode() - field2.hashCode();
})
.collect(Collectors.groupingBy(exl -> {
try {
Field declaredField = exl.getClass().getDeclaredField(LOAN_NUMBER);
declaredField.setAccessible(true);
return declaredField.get(exl);
} catch (IllegalAccessException e) {
log.error("checkOutListCondition非法访问");
throw new RuntimeException("提取数据异常");
} catch (NoSuchFieldException e) {
log.error("checkOutListCondition字段不存在");
throw new RuntimeException("提取数据异常");
}
}))
.values().stream()
.filter(loanNoDuplicateList -> singleOrNot.test(loanNoDuplicateList))
.map(oneGroup -> {
List
标签:getDeclaredField,return,setAccessible,写过,借据,比较复杂,SQL,catch,getClass 来源: https://www.cnblogs.com/ukzq/p/16321603.html