package com.ruoyi.web.controller.buyerapi;

import java.util.List;
import cn.hutool.core.util.IdUtil;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.buyerapi.domain.BuyerProject;
import com.ruoyi.buyerapi.service.IBuyerProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 立项管理Controller
 *
 * @author ruoyi
 * @date 2022-09-22
 */
@Api(tags = "立项管理")
@RestController
@RequestMapping("/buyer/project")
public class BuyerProjectController extends BaseController
{
    @Autowired
    private IBuyerProjectService buyerProjectService;

    /**
     * 查询立项管理列表
     */
    @ApiOperation(value = "查询立项管理列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "项目名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "budget", value = "项目预算", required = true, paramType = "query"),
            @ApiImplicitParam(name = "employeeName", value = "项目负责人", required = true, paramType = "query")
    })
    @PreAuthorize("@ss.hasPermi('buyer:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerProject buyerProject)
    {
        startPage();
        List<BuyerProject> list = buyerProjectService.selectBuyerProjectList(buyerProject);
        return getDataTable(list);
    }

    /**
     * 辅助帐查询立项管理列表
     */
    @ApiOperation(value = "查询立项管理列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "项目名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "year", value = "年度", required = true, paramType = "query"),
    })
    @PreAuthorize("@ss.hasPermi('buyer:project:list')")
    @GetMapping("/listForVoucher")
    public TableDataInfo listForVoucher(BuyerProject buyerProject)
    {
        startPage();
        List<BuyerProject> list = buyerProjectService.listForVoucher(buyerProject);
        return getDataTable(list);
    }

    /**
     * 导出立项管理列表
     */
    @ApiOperation(value = "导出立项管理列表")
    @PreAuthorize("@ss.hasPermi('buyer:project:export')")
    @Log(title = "立项管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerProject buyerProject)
    {
        List<BuyerProject> list = buyerProjectService.selectBuyerProjectList(buyerProject);
        ExcelUtil<BuyerProject> util = new ExcelUtil<BuyerProject>(BuyerProject.class);
        util.exportExcel(response, list, "立项管理数据");
    }

    /**
     * 获取立项管理详细信息
     */
    @ApiOperation(value = "获取立项管理详细信息")
    @PreAuthorize("@ss.hasPermi('buyer:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(buyerProjectService.selectBuyerProjectById(id));
    }

    /**
     * 新增立项管理
     */
    @ApiOperation(value = "新增立项管理")
    @PreAuthorize("@ss.hasPermi('buyer:project:add')")
    @Log(title = "立项管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerProject buyerProject)
    {
        buyerProject.setId(IdUtil.simpleUUID());
        buyerProject.setCreateBy(getUsername());
        buyerProject.setUpdateBy(getUsername());
        return toAjax(buyerProjectService.insertBuyerProject(buyerProject));
    }

    /**
     * 修改立项管理
     */
    @ApiOperation(value = "修改立项管理")
    @PreAuthorize("@ss.hasPermi('buyer:project:edit')")
    @Log(title = "立项管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerProject buyerProject)
    {
        buyerProject.setUpdateBy(getUsername());
        return toAjax(buyerProjectService.updateBuyerProject(buyerProject));
    }

    /**
     * 删除立项管理
     */
    @ApiOperation(value = "删除立项管理")
    @PreAuthorize("@ss.hasPermi('buyer:project:remove')")
    @Log(title = "立项管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(buyerProjectService.deleteBuyerProjectByIds(ids));
    }
}
