package com.ruoyi.project.service.impl;


import com.ruoyi.project.mapper.TrsSiteconfigMapper;
import com.ruoyi.project.mapper.TrsTechnicalResultsMapper;
import com.ruoyi.project.service.ITrsStatisticsService;
import com.ruoyi.project.service.ITrsTechnicalResultsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TrsStatisticsServiceImpl implements ITrsStatisticsService {


    @Autowired
    private TrsSiteconfigMapper trsSiteconfigMapper;

    @Override
    public int getTotalTexts(String siteId, Date startDate, Date endDate) {
        Integer totalTexts = trsSiteconfigMapper.getTotalTexts(siteId, startDate, endDate);
        return totalTexts;
    }

    @Override
    public int getProblemTexts(String siteId, Date startDate, Date endDate) {
        Integer totalTexts = trsSiteconfigMapper.getProblemTexts(siteId, startDate, endDate);
        return totalTexts;
    }

    @Override
    public List<Map<String, Object>> getHighFrequencyErrors(String siteId, Date startDate, Date endDate, int limit) {
        return trsSiteconfigMapper.getHighFrequencyErrors(siteId, startDate, endDate, limit);
    }

    @Override
    public Map<String, Object> getCommonErrors(String sitename, Date startDate, Date endDate) {
        Map<String, Object> result = new HashMap<>();

        // 1. 基础统计
        result.put("total", trsSiteconfigMapper.countByStatus("", sitename, startDate, endDate));
        result.put("fixed", trsSiteconfigMapper.countByStatus("已处理", sitename, startDate, endDate)); // 已修改
        result.put("pending", trsSiteconfigMapper.countByStatus("待处理", sitename, startDate, endDate)); // 待处理
        result.put("ignored", trsSiteconfigMapper.countByStatus("不必处理", sitename, startDate, endDate)); // 不必处理

        // 2. 按错误类型统计（6大类）
        result.put("wordCount", trsSiteconfigMapper.countByType("字词类", sitename, startDate, endDate)); // 字词类
        result.put("knowledgeCount", trsSiteconfigMapper.countByType("知识类", sitename, startDate, endDate)); // 知识类
        result.put("politicalCount", trsSiteconfigMapper.countByType("政治类", sitename, startDate, endDate)); // 政治类
        result.put("grammarCount", trsSiteconfigMapper.countByType("语法类", sitename, startDate, endDate)); // 语法类
        result.put("formatCount", trsSiteconfigMapper.countByType("格式类", sitename, startDate, endDate)); // 格式类
        result.put("customCount", trsSiteconfigMapper.countByType("自定义类", sitename, startDate, endDate)); // 自定义类
        return result;
    }

    @Override
    public Map<String, Object> getPoliticalErrors(String siteId, Date startDate, Date endDate) {
        return null;
    }
}