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.TbUserBidStore;
import com.ruoyi.business.service.ITbUserBidStoreService;
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/bidStore")
public class TbUserBidStoreController extends BaseController
{
    private String prefix = "business/bidStore";

    @Autowired
    private ITbUserBidStoreService tbUserBidStoreService;

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

    /**
     * 查询我收藏的项目列表
     */
    @RequiresPermissions("business:bidStore:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbUserBidStore tbUserBidStore)
    {
        startPage();
        List<TbUserBidStore> list = tbUserBidStoreService.selectTbUserBidStoreList(tbUserBidStore);
        return getDataTable(list);
    }

    /**
     * 导出我收藏的项目列表
     */
    @RequiresPermissions("business:bidStore:export")
    @Log(title = "我收藏的项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbUserBidStore tbUserBidStore)
    {
        List<TbUserBidStore> list = tbUserBidStoreService.selectTbUserBidStoreList(tbUserBidStore);
        ExcelUtil<TbUserBidStore> util = new ExcelUtil<TbUserBidStore>(TbUserBidStore.class);
        return util.exportExcel(list, "我收藏的项目数据");
    }

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

    /**
     * 新增保存我收藏的项目
     */
    @RequiresPermissions("business:bidStore:add")
    @Log(title = "我收藏的项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbUserBidStore tbUserBidStore)
    {
        return toAjax(tbUserBidStoreService.insertTbUserBidStore(tbUserBidStore));
    }

    /**
     * 修改我收藏的项目
     */
    @RequiresPermissions("business:bidStore:edit")
    @GetMapping("/edit/{userBidId}")
    public String edit(@PathVariable("userBidId") Long userBidId, ModelMap mmap)
    {
        TbUserBidStore tbUserBidStore = tbUserBidStoreService.selectTbUserBidStoreByUserBidId(userBidId);
        mmap.put("tbUserBidStore", tbUserBidStore);
        return prefix + "/edit";
    }

    /**
     * 修改保存我收藏的项目
     */
    @RequiresPermissions("business:bidStore:edit")
    @Log(title = "我收藏的项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbUserBidStore tbUserBidStore)
    {
        return toAjax(tbUserBidStoreService.updateTbUserBidStore(tbUserBidStore));
    }

    /**
     * 删除我收藏的项目
     */
    @RequiresPermissions("business:bidStore:remove")
    @Log(title = "我收藏的项目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbUserBidStoreService.deleteTbUserBidStoreByUserBidIds(ids));
    }
}
