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.SBid;
import com.ruoyi.business.service.ISBidService;
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/bid")
public class SBidController extends BaseController
{
    private String prefix = "business/bid";

    @Autowired
    private ISBidService sBidService;

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

    /**
     * 查询项目列表
     */
    @RequiresPermissions("business:bid:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SBid sBid)
    {
        startPage();
        List<SBid> list = sBidService.selectSBidList(sBid);
        return getDataTable(list);
    }

    /**
     * 导出项目列表
     */
    @RequiresPermissions("business:bid:export")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SBid sBid)
    {
        List<SBid> list = sBidService.selectSBidList(sBid);
        ExcelUtil<SBid> util = new ExcelUtil<SBid>(SBid.class);
        return util.exportExcel(list, "项目数据");
    }

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

    /**
     * 新增保存项目
     */
    @RequiresPermissions("business:bid:add")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SBid sBid)
    {
        return toAjax(sBidService.insertSBid(sBid));
    }

    /**
     * 修改项目
     */
    @RequiresPermissions("business:bid:edit")
    @GetMapping("/edit/{bidId}")
    public String edit(@PathVariable("bidId") String bidId, ModelMap mmap)
    {
        SBid sBid = sBidService.selectSBidByBidId(bidId);
        mmap.put("sBid", sBid);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目
     */
    @RequiresPermissions("business:bid:edit")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SBid sBid)
    {
        return toAjax(sBidService.updateSBid(sBid));
    }

    /**
     * 删除项目
     */
    @RequiresPermissions("business:bid:remove")
    @Log(title = "项目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sBidService.deleteSBidByBidIds(ids));
    }
}
