package com.playlet.web.controller.system;

import java.util.List;

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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.playlet.common.annotation.Log;
import com.playlet.common.enums.BusinessType;
import com.playlet.system.domain.PlayletUserTask;
import com.playlet.system.service.IPlayletUserTaskService;
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-22 12:03
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 短剧用户任务Controller
 */
@Controller
@RequestMapping("/system/user/task")
public class PlayletUserTaskController extends BaseController {
    private String prefix = "system/task";

    @Autowired
    private IPlayletUserTaskService playletUserTaskService;

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

    /**
     * 查询短剧用户任务列表
     */
    @RequiresPermissions("system:task:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletUserTask playletUserTask) {
        startPage();
        List<PlayletUserTask> list = playletUserTaskService.selectPlayletUserTaskList(playletUserTask);
        return getDataTable(list);
    }

    /**
     * 导出短剧用户任务列表
     */
    @RequiresPermissions("system:task:export")
    @Log(title = "短剧用户任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletUserTask playletUserTask) {
        List<PlayletUserTask> list = playletUserTaskService.selectPlayletUserTaskList(playletUserTask);
        ExcelUtil<PlayletUserTask> util = new ExcelUtil<PlayletUserTask>(PlayletUserTask.class);
        return util.exportExcel(list, "短剧用户任务数据");
    }

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

    /**
     * 新增保存短剧用户任务
     */
    @RequiresPermissions("system:task:add")
    @Log(title = "短剧用户任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletUserTask playletUserTask) {
        return toAjax(playletUserTaskService.insertPlayletUserTask(playletUserTask));
    }

    /**
     * 修改短剧用户任务
     */
    @RequiresPermissions("system:task:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        PlayletUserTask playletUserTask = playletUserTaskService.selectPlayletUserTaskById(id);
        mmap.put("playletUserTask", playletUserTask);
        return prefix + "/edit";
    }

    /**
     * 修改保存短剧用户任务
     */
    @RequiresPermissions("system:task:edit")
    @Log(title = "短剧用户任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletUserTask playletUserTask) {
        return toAjax(playletUserTaskService.updatePlayletUserTask(playletUserTask));
    }

    /**
     * 删除短剧用户任务
     */
    @RequiresPermissions("system:task:remove")
    @Log(title = "短剧用户任务", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(playletUserTaskService.deletePlayletUserTaskByIds(ids));
    }
}
