package com.microservices.dms.achievementLibrary.service;

import com.microservices.dms.achievementLibrary.domain.AchQueryVo;
import com.microservices.dms.achievementLibrary.domain.KeyValueVo;
import com.microservices.dms.achievementLibrary.domain.MemoTotalVo;
import com.microservices.dms.resourceLibrary.domain.vo.KeyValVo;
import com.microservices.dms.resourceLibrary.mapper.ExpertResourceLibraryMapper;
import com.microservices.dms.utils.DateUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class MemoDashboardService {
    @Autowired
    private ExpertResourceLibraryMapper memoResourceLibraryMapper;
    /**
     * 审核通过率
     * @return
     */
    public List<KeyValueVo> getMemoAduit() {
        return memoResourceLibraryMapper.getMemoAduit();
    }

    /**
     * 原创、非原创
     * @return
     */
    public List<KeyValueVo> getIsOriginalStatistic() {
        return memoResourceLibraryMapper.getIsOriginalStatistic();
    }

    /**
     * 年度动态数据统计
     * @return
     */
    public List<KeyValueVo> getMemoTotalByYear() {
        return memoResourceLibraryMapper.getMemoTotalByYear();
    }

    /**
     * 根据帖子类型汇总
     * @return
     */
    public List<KeyValueVo> getForumSectionStatistic() {
        return memoResourceLibraryMapper.getForumSectionStatistic();
    }

    /**
     * 近一年新增帖子数
     * @return
     */
    public List<KeyValueVo> getAddMemoStatistic() {
        return memoResourceLibraryMapper.getAddMemoStatistic();
    }

    /**
     * 本年帖子热度top5（论坛评论、点击、点赞）
     * @return
     */
    public List<MemoTotalVo> getTop5Memos() {
        return memoResourceLibraryMapper.getTop5Memos();
    }

    /**
     * 近7日帖子点赞数
     * @return
     */
    public List<KeyValVo<String, Long>> get7DayPaise() {
        Date[] days = DateUtil.getDays(1, 7);
        Map<String, Long> w = memoResourceLibraryMapper.get7DayPaise(days[0], days[1])
                .stream().collect(Collectors.toMap(KeyValVo::getK, KeyValVo::getV));

        List<String> dateStr = DateUtil.getDateStrMMDD(days[0], days[1]);
        List<KeyValVo<String, Long>> res = new ArrayList<>();

        for (String s : dateStr) {
            Long a = w.getOrDefault(s, 0L);
            KeyValVo<String, Long> k1 = new KeyValVo<>();
            k1.setK(s);
            k1.setV(a);
            res.add(k1);
        }
        return res;
    }




}
