package com.playlet.system.controller;

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.PlayletRealizationProject;
import com.playlet.system.service.IPlayletRealizationProjectService;
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;

/**
 * 变现项目Controller
 *
 * @author clunt
 * @date 2024-03-10
 */
@Controller
@RequestMapping("/system/playlet/project")
public class PlayletRealizationProjectController extends BaseController
{
    private String prefix = "system/playlet/project";

    @Autowired
    private IPlayletRealizationProjectService playletRealizationProjectService;

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

    /**
     * 查询变现项目列表
     */
    @RequiresPermissions("playlet:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletRealizationProject playletRealizationProject)
    {
        startPage();
        List<PlayletRealizationProject> list = playletRealizationProjectService.selectPlayletRealizationProjectList(playletRealizationProject);
        return getDataTable(list);
    }

    /**
     * 导出变现项目列表
     */
    @RequiresPermissions("playlet:project:export")
    @Log(title = "变现项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletRealizationProject playletRealizationProject)
    {
        List<PlayletRealizationProject> list = playletRealizationProjectService.selectPlayletRealizationProjectList(playletRealizationProject);
        ExcelUtil<PlayletRealizationProject> util = new ExcelUtil<PlayletRealizationProject>(PlayletRealizationProject.class);
        return util.exportExcel(list, "变现项目数据");
    }

    /**
     * 新增变现项目
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存变现项目
     */
    @RequiresPermissions("playlet:project:add")
    @Log(title = "变现项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletRealizationProject playletRealizationProject)
    {
        return toAjax(playletRealizationProjectService.insertPlayletRealizationProject(playletRealizationProject));
    }

    /**
     * 修改变现项目
     */
    @RequiresPermissions("playlet:project:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletRealizationProject playletRealizationProject = playletRealizationProjectService.selectPlayletRealizationProjectById(id);
        mmap.put("playletRealizationProject", playletRealizationProject);
        return prefix + "/edit";
    }

    /**
     * 修改保存变现项目
     */
    @RequiresPermissions("playlet:project:edit")
    @Log(title = "变现项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletRealizationProject playletRealizationProject)
    {
        return toAjax(playletRealizationProjectService.updatePlayletRealizationProject(playletRealizationProject));
    }

    /**
     * 删除变现项目
     */
    @RequiresPermissions("playlet:project:remove")
    @Log(title = "变现项目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletRealizationProjectService.deletePlayletRealizationProjectByIds(ids));
    }
}
