package com.ruoyi.web.controller.ai;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ai.domain.MapValue;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ai.domain.AiStatistics;
import com.ruoyi.ai.service.IAiStatisticsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ai-统计Controller
 *
 * @author shi
 * @date 2025-11-29
 */
@RestController
@RequestMapping("/ai/statistics")
public class AiStatisticsController extends BaseController
{
    @Autowired
    private IAiStatisticsService aiStatisticsService;

    /**
     * 查询ai-统计列表
     */
    @PreAuthorize("@ss.hasPermi('ai:statistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiStatistics aiStatistics)
    {
        startPage();
        List<AiStatistics> list = aiStatisticsService.selectAiStatisticsList(aiStatistics);
        return getDataTable(list);
    }

    /**
     *  查询首页头部统计
     */
    @PreAuthorize("@ss.hasPermi('ai:statistics:list')")
    @GetMapping("/getTitleTotal")
    public AjaxResult getTitleTotal()
    {
        AiStatistics aiStatistics = aiStatisticsService.getTitleTotal();
        return AjaxResult.success(aiStatistics);
    }

    /**
     * 获取今日新增用户统计
     * @return
     */
    @GetMapping("/getTodayHourlyAddUserWithZero")
    public AjaxResult getTodayHourlyAddUserWithZero(String source) {
        List<Long> longs = aiStatisticsService.getTodayHourlyAddUserWithZero(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取本周每日用户统计
     * @return
     */
    @GetMapping("/getWeeklyAddUserCount")
    public AjaxResult getWeeklyAddUserCount(String source) {
        List<Long> longs = aiStatisticsService.getWeeklyAddUserCount(source);
        return AjaxResult.success(longs);
    }

    /**
     * 获取本月每日用户统计
     * @return
     */
    @GetMapping("/getMonthlyAddUserCount")
    public AjaxResult getMonthlyAddUserCount(String source) {
        List<Long> longs = aiStatisticsService.getMonthlyAddUserCount(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取时间范围用户统计
     * @return
     */
    @GetMapping("/getMonthlyAddUserCountByRange")
    public AjaxResult getMonthlyAddUserCountByRange(String source, Date startDate, Date endDate) {
        List<Long> longs = aiStatisticsService.getMonthlyAddUserCountByRange(source, startDate, endDate);
        return AjaxResult.success(longs);
    }





   // ======================================================================================================


    /**
     * 获取今日充值统计
     * @return
     */
    @GetMapping("/getTodayHourlyRechargeWithZero")
    public AjaxResult getTodayHourlyRechargeWithZero(String source) {
        List<Long> longs = aiStatisticsService.getTodayHourlyRechargeWithZero(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取本周每日充值统计
     * @return
     */
    @GetMapping("/getWeeklyRecharge")
    public AjaxResult getWeeklyRecharge(String source) {
        List<Long> longs = aiStatisticsService.getWeeklyRecharge(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取本月每日充值统计
     * @return
     */
    @GetMapping("/getMonthlyRecharge")
    public AjaxResult getMonthlyRecharge(String source) {
        List<Long> longs = aiStatisticsService.getMonthlyRecharge(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取时间范围充值统计
     * @return
     */
    @GetMapping("/getMonthlyRechargeByRange")
    public AjaxResult getMonthlyRechargeByRange(String source, Date startDate, Date endDate) {
        List<Long> longs = aiStatisticsService.getMonthlyRechargeByRange(source, startDate, endDate);
        return AjaxResult.success(longs);
    }
// ======================================================================================================


    /**
     * 获取今日访客统计
     * @return
     */
    @GetMapping("/getTodayHourlyVisitorWithZero")
    public AjaxResult getTodayHourlyVisitorWithZero(String source) {
        List<Long> longs = aiStatisticsService.getTodayHourlyVisitorWithZero(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取本周每日访客统计
     * @return
     */
    @GetMapping("/getWeeklyVisitor")
    public AjaxResult getWeeklyVisitor(String source) {
        List<Long> longs = aiStatisticsService.getWeeklyVisitor(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取本月每日访客统计
     * @return
     */
    @GetMapping("/getMonthlyVisitor")
    public AjaxResult getMonthlyVisitor(String source) {
        List<Long> longs = aiStatisticsService.getMonthlyVisitor(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取时间范围访客统计
     * @return
     */
    @GetMapping("/getMonthlyVisitorByRange")
    public AjaxResult getMonthlyVisitorByRange(String source, Date startDate, Date endDate) {
        List<Long> longs = aiStatisticsService.getMonthlyVisitorByRange(source, startDate, endDate);
        return AjaxResult.success(longs);
    }


// ======================================================================================================


    /**
     * 获取今日生成统计
     * @return
     */
    @GetMapping("/getTodayHourlyGenerateWithZero")
    public AjaxResult getTodayHourlyGenerateWithZero(String source) {
        List<Long> longs = aiStatisticsService.getTodayHourlyGenerateWithZero(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取本周每日生成统计
     * @return
     */
    @GetMapping("/getWeeklyGenerate")
    public AjaxResult getWeeklyGenerate(String source) {
        List<Long> longs = aiStatisticsService.getWeeklyGenerate(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取本月每日生成统计
     * @return
     */
    @GetMapping("/getMonthlyGenerate")
    public AjaxResult getMonthlyGenerate(String source) {
        List<Long> longs = aiStatisticsService.getMonthlyGenerate(source);
        return AjaxResult.success(longs);
    }


    /**
     * 获取时间范围生成统计
     * @return
     */
    @GetMapping("/getMonthlyVisitorGenerate")
    public AjaxResult getMonthlyVisitorGenerate(String source, Date startDate, Date endDate) {
        List<Long> longs = aiStatisticsService.getMonthlyVisitorGenerate(source, startDate, endDate);
        return AjaxResult.success(longs);
    }


    @GetMapping("/getMapStatistics")
    public AjaxResult getMapStatistics() {
        List<MapValue> map = aiStatisticsService.getMapStatistics();
        return AjaxResult.success(map);
    }


    @GetMapping("/getAllSource")
    public AjaxResult getAllSource() {
        List<String> list = aiStatisticsService.getAllSource();
        return AjaxResult.success(list);
    }

    /**
     * 导出ai-统计列表
     */
    @PreAuthorize("@ss.hasPermi('ai:statistics:export')")
    @Log(title = "ai-统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiStatistics aiStatistics)
    {
        List<AiStatistics> list = aiStatisticsService.selectAiStatisticsList(aiStatistics);
        ExcelUtil<AiStatistics> util = new ExcelUtil<AiStatistics>(AiStatistics.class);
        util.exportExcel(response, list, "ai-统计数据");
    }

    /**
     * 获取ai-统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:statistics:query')")
    @GetMapping(value = "/{dateKey}")
    public AjaxResult getInfo(@PathVariable("dateKey") String dateKey)
    {
        return success(aiStatisticsService.selectAiStatisticsByDateKey(dateKey));
    }

    /**
     * 新增ai-统计
     */
    @PreAuthorize("@ss.hasPermi('ai:statistics:add')")
    @Log(title = "ai-统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiStatistics aiStatistics)
    {
        return toAjax(aiStatisticsService.insertAiStatistics(aiStatistics));
    }


    /**
     * 修改ai-统计
     */
    @PreAuthorize("@ss.hasPermi('ai:statistics:edit')")
    @Log(title = "ai-统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiStatistics aiStatistics)
    {
        return toAjax(aiStatisticsService.updateAiStatistics(aiStatistics));
    }

    /**
     * 删除ai-统计
     */
    @PreAuthorize("@ss.hasPermi('ai:statistics:remove')")
    @Log(title = "ai-统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dateKeys}")
    public AjaxResult remove(@PathVariable String[] dateKeys)
    {
        return toAjax(aiStatisticsService.deleteAiStatisticsByDateKeys(dateKeys));
    }



}
