
package com.lideeyunji.core.framework.enhance.example.report.xtsy;

import cn.hutool.core.date.DateUtil;
import com.lideeyunji.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
import com.lideeyunji.core.framework.config.aspect.enhancereport.plugin.ReportAfterAdvicePlugin;
import com.lideeyunji.core.framework.mapper.example.ExampleReportMapper;
import com.lideeyunji.core.framework.utils.Func;
import com.lideeyunji.core.framework.utils.FuncWeb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * 系统首页-使用统计-使用最多模块
 */
@Component("exampleSytjSyzdmkReportEnhance")
public class ExampleSytjSyzdmkReportEnhance implements ReportAfterAdvicePlugin {

    @Autowired
    private ExampleReportMapper exampleReportMapper;

    @Override
    public void execute(EnhanceReportContext enhanceContext) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        Date end = DateUtil.date();
        Date begin = DateUtil.beginOfDay(end);
        List<Map<String, Object>> list = exampleReportMapper.getMaxUsedModel(begin, end);
        if (Func.isNotEmpty(list)) {
            int total = Math.min(list.size(), 5);
            resultList = list.subList(0, total);
            for (int i = 0; i < resultList.size(); i++) {
                resultList.get(i).put("pm", i + 1);
            }
        }
        FuncWeb.setReportResult(enhanceContext, resultList);
    }
}
