package org.jk.rag.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.jk.common.core.domain.R;
import org.jk.common.excel.utils.ExcelUtil;
import org.jk.common.idempotent.annotation.RepeatSubmit;
import org.jk.common.log.annotation.Log;
import org.jk.common.log.enums.BusinessType;
import org.jk.common.mybatis.core.page.PageQuery;
import org.jk.common.mybatis.core.page.TableDataInfo;
import org.jk.common.web.core.BaseController;
import org.jk.rag.domain.Dataset;
import org.jk.rag.domain.dto.*;
import org.jk.rag.domain.vo.SysTokenLogVo;
import org.jk.rag.domain.vo.SysUserOnlineLogVo;
import org.jk.rag.service.IDialogLogService;
import org.jk.rag.service.IJkDatasetService;
import org.jk.rag.service.ISysTokenLogService;
import org.jk.rag.service.ISysUserOnlineLogService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 【概览】Controller
 *
 * @author takai
 * @date 2025-05-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/deepseek/overview")
public class JkOverviewController extends BaseController
{
    private final IDialogLogService dialogLogService;

    private final ISysUserOnlineLogService sysUserOnlineLogService;

    private final ISysTokenLogService sysTokenLogService;

    @GetMapping("/topData")
    public R<OverviewTopDTO> list()
    {
        OverviewTopDTO dto = dialogLogService.queryByTime();
        return R.ok(dto);
    }

    @GetMapping("/onlineUserData")
    public R<List<SysUserOnlineLogVo>> onlineUserData(String monthDay)
    {
        List<SysUserOnlineLogVo> list = new ArrayList<>();
        if(monthDay.equals("month")) {
            list = sysUserOnlineLogService.queryTwelveMonthData();
        } else {
            list = sysUserOnlineLogService.queryThirtyDayData();
        }

        return R.ok(list);
    }

    @GetMapping("/conversationData")
    public R<List<ConversationReqDTO>> conversationData(String monthDay)
    {
        List<ConversationReqDTO> list = new ArrayList<>();
        if(monthDay.equals("month")) {
            list = sysUserOnlineLogService.queryTwelveMonthConversationData();
        } else {
            list = sysUserOnlineLogService.queryThirtyDayConversationData();
        }

        return R.ok(list);
    }

    @GetMapping("/conversationDetailData")
    public R<List<ConversationReqDTO>> conversationDetailData(String monthDay)
    {
        List<ConversationReqDTO> list = new ArrayList<>();
        if(monthDay.equals("month")) {
            list = sysUserOnlineLogService.queryTwelveMonthConversationDetailData();
        } else {
            list = sysUserOnlineLogService.queryThirtyDayConversationDetailData();
        }

        return R.ok(list);
    }

    @GetMapping("/overviewTokenData")
    public R<List<SysTokenLogVo>> overviewTokenData(String monthDay)
    {
        List<SysTokenLogVo> list = new ArrayList<>();
        if(monthDay.equals("month")) {
            list = sysTokenLogService.queryTwelveMonthData();
        } else {
            list = sysTokenLogService.queryThirtyDayData();
        }
        return R.ok(list);
    }

    @GetMapping("/overviewAppData")
    public R<List<OverviewAppDTO>> overviewAppDTOData()
    {
        List<OverviewAppDTO> list = sysUserOnlineLogService.queryOverviewAppData();
        return R.ok(list);
    }



    @GetMapping("/overviewAppDetailData")
    public TableDataInfo<OverviewAppDetailDTO> overviewAppDetailData(PageQuery pageQuery)
    {
        TableDataInfo<OverviewAppDetailDTO> list = sysUserOnlineLogService.queryOverviewAppDetailData(pageQuery);
        return list;
    }

    @GetMapping("/overviewKnowledgeData")
    public TableDataInfo<OverviewKnowledgeDTO> overviewKnowledgeData(PageQuery pageQuery)
    {
        TableDataInfo<OverviewKnowledgeDTO> list = sysUserOnlineLogService.queryOverviewKnowledgeData(pageQuery);
        return list;
    }


}
