package com.ruoyi.web.controller.business;

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.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TbUserRewardStore;
import com.ruoyi.business.service.ITbUserRewardStoreService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我收藏的悬赏Controller
 * 
 * @author xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/rewardStore")
public class TbUserRewardStoreController extends BaseController
{
    private String prefix = "business/rewardStore";

    @Autowired
    private ITbUserRewardStoreService tbUserRewardStoreService;

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

    /**
     * 查询我收藏的悬赏列表
     */
    @RequiresPermissions("business:rewardStore:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbUserRewardStore tbUserRewardStore)
    {
        startPage();
        List<TbUserRewardStore> list = tbUserRewardStoreService.selectTbUserRewardStoreList(tbUserRewardStore);
        return getDataTable(list);
    }

    /**
     * 导出我收藏的悬赏列表
     */
    @RequiresPermissions("business:rewardStore:export")
    @Log(title = "我收藏的悬赏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbUserRewardStore tbUserRewardStore)
    {
        List<TbUserRewardStore> list = tbUserRewardStoreService.selectTbUserRewardStoreList(tbUserRewardStore);
        ExcelUtil<TbUserRewardStore> util = new ExcelUtil<TbUserRewardStore>(TbUserRewardStore.class);
        return util.exportExcel(list, "我收藏的悬赏数据");
    }

    /**
     * 新增我收藏的悬赏
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存我收藏的悬赏
     */
    @RequiresPermissions("business:rewardStore:add")
    @Log(title = "我收藏的悬赏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbUserRewardStore tbUserRewardStore)
    {
        return toAjax(tbUserRewardStoreService.insertTbUserRewardStore(tbUserRewardStore));
    }

    /**
     * 修改我收藏的悬赏
     */
    @RequiresPermissions("business:rewardStore:edit")
    @GetMapping("/edit/{userRewardId}")
    public String edit(@PathVariable("userRewardId") Long userRewardId, ModelMap mmap)
    {
        TbUserRewardStore tbUserRewardStore = tbUserRewardStoreService.selectTbUserRewardStoreByUserRewardId(userRewardId);
        mmap.put("tbUserRewardStore", tbUserRewardStore);
        return prefix + "/edit";
    }

    /**
     * 修改保存我收藏的悬赏
     */
    @RequiresPermissions("business:rewardStore:edit")
    @Log(title = "我收藏的悬赏", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbUserRewardStore tbUserRewardStore)
    {
        return toAjax(tbUserRewardStoreService.updateTbUserRewardStore(tbUserRewardStore));
    }

    /**
     * 删除我收藏的悬赏
     */
    @RequiresPermissions("business:rewardStore:remove")
    @Log(title = "我收藏的悬赏", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbUserRewardStoreService.deleteTbUserRewardStoreByUserRewardIds(ids));
    }
}
