package com.fs.company.controller.course;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.course.domain.FsUserWatchStatistics;
import com.fs.course.service.IFsUserWatchStatisticsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员看课统计-按营期统计Controller
 *
 * @author fs
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/course/userWatchStatistics")
public class FsUserWatchStatisticsController extends BaseController
{
    @Autowired
    private IFsUserWatchStatisticsService fsUserWatchStatisticsService;

    /**
     * 查询会员看课统计-按营期统计列表
     */
    @PreAuthorize("@ss.hasPermi('course:userWatchStatistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserWatchStatistics fsUserWatchStatistics)
    {
        startPage();
        List<FsUserWatchStatistics> list = fsUserWatchStatisticsService.selectFsUserWatchStatisticsList(fsUserWatchStatistics);
        return getDataTable(list);
    }

    /**
     * 导出会员看课统计-按营期统计列表
     */
    @PreAuthorize("@ss.hasPermi('course:userWatchStatistics:export')")
    @Log(title = "会员看课统计-按营期统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserWatchStatistics fsUserWatchStatistics)
    {
        List<FsUserWatchStatistics> list = fsUserWatchStatisticsService.selectFsUserWatchStatisticsList(fsUserWatchStatistics);
        ExcelUtil<FsUserWatchStatistics> util = new ExcelUtil<FsUserWatchStatistics>(FsUserWatchStatistics.class);
        return util.exportExcel(list, "会员看课统计-按营期统计数据");
    }

    /**
     * 获取会员看课统计-按营期统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userWatchStatistics:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsUserWatchStatisticsService.selectFsUserWatchStatisticsById(id));
    }

    /**
     * 新增会员看课统计-按营期统计
     */
    @PreAuthorize("@ss.hasPermi('course:userWatchStatistics:add')")
    @Log(title = "会员看课统计-按营期统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserWatchStatistics fsUserWatchStatistics)
    {
        return toAjax(fsUserWatchStatisticsService.insertFsUserWatchStatistics(fsUserWatchStatistics));
    }

    /**
     * 修改会员看课统计-按营期统计
     */
    @PreAuthorize("@ss.hasPermi('course:userWatchStatistics:edit')")
    @Log(title = "会员看课统计-按营期统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserWatchStatistics fsUserWatchStatistics)
    {
        return toAjax(fsUserWatchStatisticsService.updateFsUserWatchStatistics(fsUserWatchStatistics));
    }

    /**
     * 删除会员看课统计-按营期统计
     */
    @PreAuthorize("@ss.hasPermi('course:userWatchStatistics:remove')")
    @Log(title = "会员看课统计-按营期统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsUserWatchStatisticsService.deleteFsUserWatchStatisticsByIds(ids));
    }


    @PostMapping("/test")
    @ApiOperation("测试营期看课统计定时任务")
    public void userCourseCountTask() {
        fsUserWatchStatisticsService.insertStatistics();
    }

}
