package cn.com.ctop.kuaishou.modules.report.service.impl;

import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
import cn.com.ctop.kuaishou.modules.report.entity.EtlKuaiShouAccountMaterialOverview;
import cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaiShouAccountMaterialOverviewMapper;
import cn.com.ctop.kuaishou.modules.report.service.IEtlKuaiShouAccountMaterialOverviewService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 清洗数据账户素材概览数据
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2021-03-10
 */
@Service
public class EtlKuaiShouAccountMaterialOverviewServiceImpl extends ServiceImpl<EtlKuaiShouAccountMaterialOverviewMapper, EtlKuaiShouAccountMaterialOverview> implements IEtlKuaiShouAccountMaterialOverviewService {
    @Autowired
    private IKuaiShouVideoGetService videoGetService;
    @Autowired
    private EtlKuaiShouAccountMaterialOverviewMapper accountMaterialOverviewMapper;

    @Override
    public void cleanAccountMaterialOverview(Long accountId, String statDate) {
        Integer totalCount = videoGetService.getTotalCountByAccount(accountId);
        Integer newlyCount = videoGetService.getTotalCountByAccountAndStatDate(accountId, statDate);
        Integer effectiveCount = videoGetService.getEffectiveCountByAccountId(accountId);
        Integer hotMoneyCount = videoGetService.getHotMoneyCountByAccountId(accountId);
        EtlKuaiShouAccountMaterialOverview etlKuaiShouAccountMaterialOverview = new EtlKuaiShouAccountMaterialOverview();
        etlKuaiShouAccountMaterialOverview.setAccountId(accountId);
        etlKuaiShouAccountMaterialOverview.setStateDate(DateUtils.parseDate(statDate, "yyyy-MM-dd"));
        etlKuaiShouAccountMaterialOverview.setTotalCount(totalCount);
        etlKuaiShouAccountMaterialOverview.setNewlyCount(newlyCount);
        etlKuaiShouAccountMaterialOverview.setEffectiveCount(effectiveCount);
        etlKuaiShouAccountMaterialOverview.setHotMoneyCount(hotMoneyCount);
        accountMaterialOverviewMapper.replaceInsert(etlKuaiShouAccountMaterialOverview);
    }

    @Override
    public JSONObject getMaterialOverview(Long accountId, String statDate) {
        return accountMaterialOverviewMapper.getMaterialOverview(accountId, statDate);
    }
}
