import java.util.concurrent.CompletableFuture;
public List<?> getStuTaxDeduction(Long stuEmployeeId, Integer type, Integer year) {
Long taxDeductionId = jsGsStuTaxDeductionMapper.getDeductionByEmployeeIdAndYear(stuEmployeeId, year);
if (taxDeductionId == null) {
return Collections.emptyList();
}
//根据type判断哪个要执行,哪个不执行,并且异步查询
List<CompletableFuture<List<?>>> completableFutureList = new ArrayList<>();
completableFutureList.add(CompletableFuture.supplyAsync(() -> getChildrenByTaxDeductionId(type, taxDeductionId)));
completableFutureList.add(CompletableFuture.supplyAsync(() -> getInfantCareCostsByTaxDeductionId(type, taxDeductionId)));
completableFutureList.add(CompletableFuture.supplyAsync(() -> getContinueByTaxDeductionId(type, taxDeductionId)));
completableFutureList.add(CompletableFuture.supplyAsync(() -> getMedicalCareByTaxDeductionId(type, taxDeductionId)));
completableFutureList.add(CompletableFuture.supplyAsync(() -> getLoanByTaxDeductionId(type, taxDeductionId)));
completableFutureList.add(CompletableFuture.supplyAsync(() -> getRentByTaxDeductionId(type, taxDeductionId)));
completableFutureList.add(CompletableFuture.supplyAsync(() -> getSupportOldTaxDeductionId(type, taxDeductionId)));
return completableFutureList.stream().map(CompletableFuture::join).flatMap(List::stream)
.filter(Objects::nonNull).map(obj -> {
JSONObject object = JSONObject.parseObject(JSONObject.toJSON(obj).toString());
object.put("year", year);
return object;
})
.sorted(Comparator.comparingInt((JSONObject obj) -> obj.getInteger("del")).reversed().thenComparing(obj -> obj.getString("modifyTime")).reversed()).collect(Collectors.toList());
}