package com.hzs.member.statis.provider;

import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.domain.R;
import com.hzs.member.statis.ICuBonusVertexStatisServiceApi;
import com.hzs.member.statis.service.ICuBonusVertexStatisService;
import com.hzs.member.statis.vo.CuBonusVertexStatisVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 顶点奖金拨比统计Dubbo 服务
 **/
@Slf4j
@DubboService
public class ICuBonusVertexStatisServiceProvider implements ICuBonusVertexStatisServiceApi {

    @Autowired
    private ICuBonusVertexStatisService iCuBonusVertexStatisService;

    /**
     * @description: 7天重算顶点奖金拨比统计
     **/
    @Override
    public R<Boolean> anewStatsHistoryBonus(String startDate, String endDate) {
        return R.ok(iCuBonusVertexStatisService.anewStatisHistoryBonus(startDate, endDate));
    }

    /**
     * @description: 删除奖金拨比统计数据
     **/
    @Override
    public R<?> delStats(String startDate, String endDate) {
        List<CuBonusVertexStatisVO> vertexList = iCuBonusVertexStatisService.vertexList(null);
        if (CollectionUtil.isNotEmpty(vertexList)) {
            List<Integer> pkVertexList = vertexList.stream().map(CuBonusVertexStatisVO::getPkVertex).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(pkVertexList)) {
                iCuBonusVertexStatisService.delStatis(startDate, endDate, pkVertexList);
            }
        }
        return R.ok();
    }

}
