package com.playlet.web.controller.system;

import java.util.List;

import com.playlet.common.core.domain.Result;
import com.playlet.system.pojo.vo.RevenueRecordStatisticsVO;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.playlet.common.annotation.Log;
import com.playlet.common.enums.BusinessType;
import com.playlet.system.domain.PlayletRevenueRecord;
import com.playlet.system.service.IPlayletRevenueRecordService;
import com.playlet.common.core.controller.BaseController;
import com.playlet.common.core.domain.AjaxResult;
import com.playlet.common.utils.poi.ExcelUtil;
import com.playlet.common.core.page.TableDataInfo;

/**
 * @Date: 2024-03-17
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 短剧任务收益Controller
 */
@Controller
@RequestMapping("/system/record")
public class PlayletRevenueRecordController extends BaseController {

    private String prefix = "system/record";

    @Autowired
    private IPlayletRevenueRecordService playletRevenueRecordService;

    @RequiresPermissions("system:record:view")
    @GetMapping()
    public String record() {
        return prefix + "/record";
    }

    /**
     * 查询短剧任务收益列表
     */
    @RequiresPermissions("system:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletRevenueRecord playletRevenueRecord) {
        startPage();
        List<PlayletRevenueRecord> list = playletRevenueRecordService.selectPlayletRevenueRecordList(playletRevenueRecord);
        return getDataTable(list);
    }

    /**
     * 导出短剧任务收益列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "短剧任务收益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletRevenueRecord playletRevenueRecord) {
        List<PlayletRevenueRecord> list = playletRevenueRecordService.selectPlayletRevenueRecordList(playletRevenueRecord);
        ExcelUtil<PlayletRevenueRecord> util = new ExcelUtil<PlayletRevenueRecord>(PlayletRevenueRecord.class);
        return util.exportExcel(list, "短剧任务收益数据");
    }

    /**
     * 新增短剧任务收益
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存短剧任务收益
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "短剧任务收益", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletRevenueRecord playletRevenueRecord) {
        return toAjax(playletRevenueRecordService.insertPlayletRevenueRecord(playletRevenueRecord));
    }

    /**
     * 修改短剧任务收益
     */
    @RequiresPermissions("system:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        PlayletRevenueRecord playletRevenueRecord = playletRevenueRecordService.selectPlayletRevenueRecordById(id);
        mmap.put("playletRevenueRecord", playletRevenueRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存短剧任务收益
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "短剧任务收益", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletRevenueRecord playletRevenueRecord) {
        return toAjax(playletRevenueRecordService.updatePlayletRevenueRecord(playletRevenueRecord));
    }

    /**
     * 删除短剧任务收益
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "短剧任务收益", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(playletRevenueRecordService.deletePlayletRevenueRecordByIds(ids));
    }

    @ResponseBody
    @PostMapping("/statistics/time")
    public Result<PlayletRevenueRecord> statisticsTime(@RequestBody PlayletRevenueRecord playletRevenueRecord) {
        return Result.success(playletRevenueRecordService.statisticsTime(playletRevenueRecord));
    }

    @ResponseBody
    @PostMapping("/statistics")
    public Result<RevenueRecordStatisticsVO> statistics(@RequestBody PlayletRevenueRecord playletRevenueRecord) {
        return Result.success(playletRevenueRecordService.statistics(playletRevenueRecord));
    }

    @ResponseBody
    @PostMapping("/statistics/time/type")
    public Result<List<PlayletRevenueRecord>> statisticsTimeType(@RequestBody PlayletRevenueRecord playletRevenueRecord) {
        return Result.success(playletRevenueRecordService.statisticsTimeType(playletRevenueRecord));
    }
}
