Search in sources :

Example 11 with CostRecord

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());
}
Also used : ReportEntity(com.tony.billing.entity.ReportEntity) ReportEntityQuery(com.tony.billing.entity.query.ReportEntityQuery) Resource(javax.annotation.Resource) EnumHidden(com.tony.billing.constants.enums.EnumHidden) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) CostRecord(com.tony.billing.entity.CostRecord) CostReportService(com.tony.billing.service.api.CostReportService) Objects(java.util.Objects) EnumDeleted(com.tony.billing.constants.enums.EnumDeleted) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) InOutType(com.tony.billing.constants.InOutType) CollectionUtils(org.apache.commons.collections.CollectionUtils) CostReportMapper(com.tony.billing.dao.mapper.CostReportMapper) RawReportEntity(com.tony.billing.entity.RawReportEntity) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Service(org.apache.dubbo.config.annotation.Service) CostRecord(com.tony.billing.entity.CostRecord) RawReportEntity(com.tony.billing.entity.RawReportEntity) DateTimeFormatter(java.time.format.DateTimeFormatter) ReportEntity(com.tony.billing.entity.ReportEntity) RawReportEntity(com.tony.billing.entity.RawReportEntity)

Aggregations

CostRecord (com.tony.billing.entity.CostRecord)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 TagInfo (com.tony.billing.entity.TagInfo)4 BaseResponse (com.tony.billing.response.BaseResponse)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ParseException (java.text.ParseException)2 InOutType (com.tony.billing.constants.InOutType)1 EnumDeleted (com.tony.billing.constants.enums.EnumDeleted)1 EnumHidden (com.tony.billing.constants.enums.EnumHidden)1 CostReportMapper (com.tony.billing.dao.mapper.CostReportMapper)1 BudgetReportItemDTO (com.tony.billing.dto.BudgetReportItemDTO)1 CostRecordDTO (com.tony.billing.dto.CostRecordDTO)1 TagCostInfoDTO (com.tony.billing.dto.TagCostInfoDTO)1 Budget (com.tony.billing.entity.Budget)1 RawReportEntity (com.tony.billing.entity.RawReportEntity)1 ReportEntity (com.tony.billing.entity.ReportEntity)1 TagCostRef (com.tony.billing.entity.TagCostRef)1 ReportEntityQuery (com.tony.billing.entity.query.ReportEntityQuery)1 BudgetReportModel (com.tony.billing.model.BudgetReportModel)1