Search in sources :

Example 1 with ReportEntity

use of com.tony.billing.entity.ReportEntity in project BillingDubbo by TonyJiangWJ.

the class CostReportServiceImpl method getReportInfo.

private ReportEntity getReportInfo(String datePrefix, Long userId) {
    ReportEntityQuery query = new ReportEntityQuery();
    query.setDatePrefix(datePrefix);
    query.setUserId(userId);
    RawReportEntity reportEntity = costReportMapper.getReportTypeAmountByCondition(query);
    if (reportEntity != null) {
        return new ReportEntity(datePrefix, reportEntity);
    } else {
        return null;
    }
}
Also used : ReportEntityQuery(com.tony.billing.entity.query.ReportEntityQuery) RawReportEntity(com.tony.billing.entity.RawReportEntity) ReportEntity(com.tony.billing.entity.ReportEntity) RawReportEntity(com.tony.billing.entity.RawReportEntity)

Example 2 with ReportEntity

use of com.tony.billing.entity.ReportEntity in project BillingDubbo by TonyJiangWJ.

the class CostReportController method getDailyCostReport.

@RequestMapping("/daily/report/get")
public ReportResponse getDailyCostReport(@ModelAttribute("request") @Validated DailyCostReportRequest reportRequest) {
    ReportResponse response = new ReportResponse();
    try {
        List<ReportEntity> result = costReportService.getReportInfoBetween(reportRequest.getStartDate(), reportRequest.getEndDate(), reportRequest.getUserId());
        if (CollectionUtils.isEmpty(result)) {
            ResponseUtil.dataNotExisting(response);
        } else {
            response.setReportList(BeanCopyUtil.copy(result, ReportDTO.class));
            ResponseUtil.success(response);
        }
        return response;
    } catch (Exception e) {
        logger.error("/daily/report/get error", e);
        return ResponseUtil.sysError(response);
    }
}
Also used : ReportResponse(com.tony.billing.response.costrecord.ReportResponse) ReportDTO(com.tony.billing.dto.ReportDTO) ReportEntity(com.tony.billing.entity.ReportEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ReportEntity

use of com.tony.billing.entity.ReportEntity 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

ReportEntity (com.tony.billing.entity.ReportEntity)3 RawReportEntity (com.tony.billing.entity.RawReportEntity)2 ReportEntityQuery (com.tony.billing.entity.query.ReportEntityQuery)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 ReportDTO (com.tony.billing.dto.ReportDTO)1 CostRecord (com.tony.billing.entity.CostRecord)1 ReportResponse (com.tony.billing.response.costrecord.ReportResponse)1 CostReportService (com.tony.billing.service.api.CostReportService)1 LocalDate (java.time.LocalDate)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1