ReportPrepareTask.java 1.7 KB
package cn.fw.valhalla.controller.task;

import cn.fw.valhalla.common.utils.DateUtil;
import cn.fw.valhalla.rpc.oop.OopService;
import cn.fw.valhalla.rpc.oop.dto.GroupDTO;
import cn.fw.valhalla.service.report.CustomerRetentionRatioBizService;
import cn.fw.valhalla.service.report.PublicReportBizService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * @author : kurisu
 * @className : ReportPrepareTask
 * @description : 报表准备任务
 * @date: 2020-11-24 15:52
 */
@RequiredArgsConstructor
@Component
@Slf4j
public class ReportPrepareTask {
    private final OopService oopService;
    private final CustomerRetentionRatioBizService retentionRatioBizService;
    private final PublicReportBizService publicReportBizService;

    /**
     * 保持率进站率报表数据准备
     */
    @Scheduled(cron = "30 0 0 ? * * ")
    public void extractingData() {
        retentionRatioBizService.extracting(DateUtil.startDate(new Date()));
    }

    /**
     * 公共池报表数据准备,0点30分抽取
     */
    @Scheduled(cron = "0 30 0 ? * * ")
    public void extractingPublicData() {
        final List<GroupDTO> groupList = oopService.allGroup();
        final LocalDate now = LocalDate.now().minusDays(1);
        for (GroupDTO group : groupList) {
            try {
                publicReportBizService.extracting(now, group.getId());
            } catch (Exception e) {
                log.warn("准备公共池报表数据失败[groupId: {} data: {}]", group.getId(), now, e);
            }
        }
    }
}