package com.ruoyi.web.controller.buyerapi;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.IdUtil;
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.BuyerAgreement;
import com.ruoyi.buyerapi.service.IBuyerAgreementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统协议Controller
 *
 * @author ruoyi
 * @date 2022-09-19
 */
@Api(tags = "系统协议")
@RestController
@RequestMapping("/buyer/agreement")
public class BuyerAgreementController extends BaseController
{
    @Autowired
    private IBuyerAgreementService buyerAgreementService;

    /**
     * 查询系统协议列表
     */
    @ApiOperation(value = "查询系统协议列表")
    @GetMapping("/list")
    public TableDataInfo list(BuyerAgreement buyerAgreement)
    {
        startPage();
        List<BuyerAgreement> list = buyerAgreementService.selectBuyerAgreementList(buyerAgreement);
        return getDataTable(list);
    }

    /**
     * 导出系统协议列表
     */
    @ApiOperation(value = "导出系统协议列表")
    @PreAuthorize("@ss.hasPermi('system:agreement:export')")
    @Log(title = "系统协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerAgreement buyerAgreement)
    {
        List<BuyerAgreement> list = buyerAgreementService.selectBuyerAgreementList(buyerAgreement);
        ExcelUtil<BuyerAgreement> util = new ExcelUtil<BuyerAgreement>(BuyerAgreement.class);
        util.exportExcel(response, list, "系统协议数据");
    }

    /**
     * 获取系统协议详细信息
     */
    @ApiOperation(value = "获取系统协议详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(buyerAgreementService.selectBuyerAgreementById(id));
    }

    /**
     * 新增系统协议
     */
    @ApiOperation(value = "新增系统协议")
    @Log(title = "系统协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerAgreement buyerAgreement)
    {
        buyerAgreement.setId(IdUtil.simpleUUID());
        buyerAgreement.setCreateBy(getUsername());
        return toAjax(buyerAgreementService.insertBuyerAgreement(buyerAgreement));
    }

    /**
     * 修改系统协议
     */
    @ApiOperation(value = "修改系统协议")
    @PreAuthorize("@ss.hasPermi('system:agreement:edit')")
    @Log(title = "系统协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerAgreement buyerAgreement)
    {
        buyerAgreement.setUpdateBy(getUsername());
        return toAjax(buyerAgreementService.updateBuyerAgreement(buyerAgreement));
    }

    /**
     * 删除系统协议
     */
    @ApiOperation(value = "删除系统协议")
    @PreAuthorize("@ss.hasPermi('system:agreement:remove')")
    @Log(title = "系统协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(buyerAgreementService.deleteBuyerAgreementByIds(ids));
    }
}
