package com.fs.company.controller.live;

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.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.SecurityUtils;
import com.fs.live.domain.LiveRewardRecord;
import com.fs.live.service.ILiveRewardRecordService;
import com.fs.live.vo.LiveRewardRecordStatisticsVo;
import com.fs.live.vo.LiveRewardRecordVo;
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-08-27
 */
@RestController
@RequestMapping("/live/record")
public class LiveRewardRecordController extends BaseController
{
    @Autowired
    private ILiveRewardRecordService liveRewardRecordService;

    /**
     * 查询用户直播间奖励记录列表
     */
//    @PreAuthorize("@ss.hasPermi('live:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(LiveRewardRecord liveRewardRecord)
    {
        startPage();
        List<LiveRewardRecord> list = liveRewardRecordService.selectLiveRewardRecordList(liveRewardRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户直播间奖励记录列表
     */
//    @PreAuthorize("@ss.hasPermi('live:record:export')")
    @Log(title = "用户直播间奖励记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveRewardRecord liveRewardRecord)
    {
        List<LiveRewardRecord> list = liveRewardRecordService.selectLiveRewardRecordList(liveRewardRecord);
        ExcelUtil<LiveRewardRecord> util = new ExcelUtil<LiveRewardRecord>(LiveRewardRecord.class);
        return util.exportExcel(list, "用户直播间奖励记录数据");
    }

    /**
     * 获取用户直播间奖励记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('live:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(liveRewardRecordService.selectLiveRewardRecordById(id));
    }

    /**
     * 新增用户直播间奖励记录
     */
//    @PreAuthorize("@ss.hasPermi('live:record:add')")
    @Log(title = "用户直播间奖励记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveRewardRecord liveRewardRecord)
    {
        return toAjax(liveRewardRecordService.insertLiveRewardRecord(liveRewardRecord));
    }

    /**
     * 修改用户直播间奖励记录
     */
//    @PreAuthorize("@ss.hasPermi('live:record:edit')")
    @Log(title = "用户直播间奖励记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveRewardRecord liveRewardRecord)
    {
        return toAjax(liveRewardRecordService.updateLiveRewardRecord(liveRewardRecord));
    }

    /**
     * 删除用户直播间奖励记录
     */
//    @PreAuthorize("@ss.hasPermi('live:record:remove')")
    @Log(title = "用户直播间奖励记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(liveRewardRecordService.deleteLiveRewardRecordByIds(ids));
    }


    @PreAuthorize("@ss.hasPermi('live:record:query')")
    @PostMapping("/statistics")
    public R statistics(@RequestBody LiveRewardRecordVo param)
    {
        Long companyId = SecurityUtils.getLoginUser().getUser().getCompanyId();
        param.setCompanyId(companyId);
        return liveRewardRecordService.statistics(param);
    }

    @PreAuthorize("@ss.hasPermi('live:record:export')")
    @PostMapping("/export")
    public AjaxResult export(@RequestBody LiveRewardRecordVo param)
    {
        Long companyId = SecurityUtils.getLoginUser().getUser().getCompanyId();
        param.setCompanyId(companyId);
        List<LiveRewardRecordStatisticsVo> list = liveRewardRecordService.selectRewardSummary(param);

        ExcelUtil<LiveRewardRecordStatisticsVo> util = new ExcelUtil<LiveRewardRecordStatisticsVo>(LiveRewardRecordStatisticsVo.class);
        return util.exportExcel(list, "liveIntegralLogs");

//        return liveRewardRecordService.export(param);
//        return R.ok();
    }
}
