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.ReReward;
import com.ruoyi.business.service.IReRewardService;
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/reward")
public class ReRewardController extends BaseController
{
    private String prefix = "business/reward";

    @Autowired
    private IReRewardService reRewardService;

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

    /**
     * 查询我的悬赏列表
     */
    @RequiresPermissions("business:reward:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReReward reReward)
    {
        startPage();
        List<ReReward> list = reRewardService.selectReRewardList(reReward);
        return getDataTable(list);
    }

    /**
     * 导出我的悬赏列表
     */
    @RequiresPermissions("business:reward:export")
    @Log(title = "我的悬赏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReReward reReward)
    {
        List<ReReward> list = reRewardService.selectReRewardList(reReward);
        ExcelUtil<ReReward> util = new ExcelUtil<ReReward>(ReReward.class);
        return util.exportExcel(list, "我的悬赏数据");
    }

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

    /**
     * 新增保存我的悬赏
     */
    @RequiresPermissions("business:reward:add")
    @Log(title = "我的悬赏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReReward reReward)
    {
        return toAjax(reRewardService.insertReReward(reReward));
    }

    /**
     * 修改我的悬赏
     */
    @RequiresPermissions("business:reward:edit")
    @GetMapping("/edit/{rewardId}")
    public String edit(@PathVariable("rewardId") Long rewardId, ModelMap mmap)
    {
        ReReward reReward = reRewardService.selectReRewardByRewardId(rewardId);
        mmap.put("reReward", reReward);
        return prefix + "/edit";
    }

    /**
     * 修改保存我的悬赏
     */
    @RequiresPermissions("business:reward:edit")
    @Log(title = "我的悬赏", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReReward reReward)
    {
        return toAjax(reRewardService.updateReReward(reReward));
    }

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