Search in sources :

Example 1 with ReportResponse

use of com.tony.billing.response.costrecord.ReportResponse 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 2 with ReportResponse

use of com.tony.billing.response.costrecord.ReportResponse in project BillingDubbo by TonyJiangWJ.

the class CostReportController method getReport.

@RequestMapping(value = "/report/get")
public ReportResponse getReport(@ModelAttribute("request") CostReportRequest request) {
    ReportResponse response = new ReportResponse();
    try {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
        LocalDate localDate = LocalDate.now();
        List<String> monthList = new ArrayList<>();
        if (StringUtils.isEmpty(request.getStartMonth()) || StringUtils.isEmpty(request.getEndMonth())) {
            int ngm = -6;
            localDate = localDate.plusMonths(ngm);
            for (int i = 0; i < -ngm; i++) {
                localDate = localDate.plusMonths(1);
                monthList.add(localDate.format(dateTimeFormatter));
            }
        } else {
            YearMonth start = YearMonth.parse(request.getStartMonth(), dateTimeFormatter);
            YearMonth end = YearMonth.parse(request.getEndMonth(), dateTimeFormatter);
            do {
                monthList.add(start.format(dateTimeFormatter));
                start = start.plusMonths(1);
            } while (!start.isAfter(end));
        }
        return getReportResponse(monthList, request.getUserId(), response);
    } catch (Exception e) {
        logger.error("/report/get error", e);
        ResponseUtil.sysError(response);
    }
    return response;
}
Also used : ReportResponse(com.tony.billing.response.costrecord.ReportResponse) YearMonth(java.time.YearMonth) ArrayList(java.util.ArrayList) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ReportResponse (com.tony.billing.response.costrecord.ReportResponse)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ReportDTO (com.tony.billing.dto.ReportDTO)1 ReportEntity (com.tony.billing.entity.ReportEntity)1 LocalDate (java.time.LocalDate)1 YearMonth (java.time.YearMonth)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1