use of com.tony.billing.entity.CostRecord in project BillingDubbo by TonyJiangWJ.
the class CostReportServiceImpl method getReportInfoBetween.
@Override
public List<ReportEntity> getReportInfoBetween(String startDate, String endDate, Long userId) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
endDate = LocalDate.parse(endDate, dateTimeFormatter).plusDays(1).format(dateTimeFormatter);
List<CostRecord> costRecords = costReportMapper.getAllCostInfoBetween(startDate, endDate, userId);
return costRecords.parallelStream().collect(Collectors.groupingByConcurrent(record -> record.getCostCreateTime().substring(0, 10))).entrySet().parallelStream().map(entry -> {
String date = entry.getKey();
ReportEntity reportEntity = new ReportEntity(date, new RawReportEntity());
List<CostRecord> records = entry.getValue();
if (CollectionUtils.isNotEmpty(records)) {
long totalCost = 0L;
long totalCostExceptDeleted = 0L;
long totalCostExceptHidden = 0L;
long totalCostExceptDeletedAndHidden = 0L;
long totalIncomeExceptDeleted = 0L;
long totalIncomeExceptHidden = 0L;
long totalIncomeExceptDeletedAndHidden = 0L;
long totalIncome = 0L;
for (CostRecord record : records) {
if (InOutType.COST.equals(record.getInOutType())) {
totalCost += record.getMoney();
int flag = 1;
if (!EnumHidden.HIDDEN.val().equals(record.getIsHidden())) {
totalCostExceptHidden += record.getMoney();
flag = flag << 1;
}
if (!EnumDeleted.DELETED.val().equals(record.getIsDeleted())) {
totalCostExceptDeleted += record.getMoney();
flag = flag << 1;
}
if (flag == 4) {
totalCostExceptDeletedAndHidden += record.getMoney();
}
} else if (InOutType.INCOME.equals(record.getInOutType())) {
totalIncome += record.getMoney();
int flag = 1;
if (!EnumHidden.HIDDEN.val().equals(record.getIsHidden())) {
totalIncomeExceptHidden += record.getMoney();
flag = flag << 1;
}
if (!EnumDeleted.DELETED.val().equals(record.getIsDeleted())) {
totalIncomeExceptDeleted += record.getMoney();
flag = flag << 1;
}
if (flag == 4) {
totalIncomeExceptDeletedAndHidden += record.getMoney();
}
}
}
RawReportEntity rawReportEntity = new RawReportEntity();
rawReportEntity.setTotalCost(totalCost);
rawReportEntity.setTotalCostExceptDeletedAndHidden(totalCostExceptDeletedAndHidden);
rawReportEntity.setTotalCostExceptDeleted(totalCostExceptDeleted);
rawReportEntity.setTotalCostExceptHidden(totalCostExceptHidden);
rawReportEntity.setTotalIncome(totalIncome);
rawReportEntity.setTotalIncomeExceptDeletedAndHidden(totalIncomeExceptDeletedAndHidden);
rawReportEntity.setTotalIncomeExceptDeleted(totalIncomeExceptDeleted);
rawReportEntity.setTotalIncomeExceptHidden(totalIncomeExceptHidden);
rawReportEntity.calculateAdditional();
reportEntity = new ReportEntity(date, rawReportEntity);
}
return reportEntity;
}).sorted((a, b) -> StringUtils.compare(a.getMonth(), b.getMonth())).collect(Collectors.toList());
}
Aggregations