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.BuyerPolicy;
import com.ruoyi.buyerapi.service.IBuyerPolicyService;
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/policy")
public class BuyerPolicyController extends BaseController
{
    @Autowired
    private IBuyerPolicyService buyerPolicyService;

    /**
     * 查询加计扣除相关政策列表
     */
    @ApiOperation(value = "查询加计扣除相关政策列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "title", value = "政策标题", required = true, paramType = "query"),
            @ApiImplicitParam(name = "description", value = "政策描述", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createBy", value = "创建人", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", required = true, paramType = "query"),
            @ApiImplicitParam(name = "updateBy", value = "最后操作人", required = true, paramType = "query")
    })
    @PreAuthorize("@ss.hasPermi('system:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerPolicy buyerPolicy)
    {
        startPage();
        List<BuyerPolicy> list = buyerPolicyService.selectBuyerPolicyList(buyerPolicy);
        return getDataTable(list);
    }

    /**
     * 导出加计扣除相关政策列表
     */
    @ApiOperation(value = "导出加计扣除相关政策列表")
    @PreAuthorize("@ss.hasPermi('system:policy:export')")
    @Log(title = "加计扣除相关政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerPolicy buyerPolicy)
    {
        List<BuyerPolicy> list = buyerPolicyService.selectBuyerPolicyList(buyerPolicy);
        ExcelUtil<BuyerPolicy> util = new ExcelUtil<BuyerPolicy>(BuyerPolicy.class);
        util.exportExcel(response, list, "加计扣除相关政策数据");
    }

    /**
     * 获取加计扣除相关政策详细信息
     */
    @ApiOperation(value = "获取加计扣除相关政策详细信息")
    @PreAuthorize("@ss.hasPermi('system:policy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(buyerPolicyService.selectBuyerPolicyById(id));
    }

    /**
     * 新增加计扣除相关政策
     */
    @ApiOperation(value = "新增加计扣除相关政策")
    @PreAuthorize("@ss.hasPermi('system:policy:add')")
    @Log(title = "加计扣除相关政策", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerPolicy buyerPolicy)
    {
        buyerPolicy.setId(IdUtil.simpleUUID());
        buyerPolicy.setCreateBy(getUsername());
        return toAjax(buyerPolicyService.insertBuyerPolicy(buyerPolicy));
    }

    /**
     * 修改加计扣除相关政策
     */
    @ApiOperation(value = "修改加计扣除相关政策")
    @PreAuthorize("@ss.hasPermi('system:policy:edit')")
    @Log(title = "加计扣除相关政策", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerPolicy buyerPolicy)
    {
        buyerPolicy.setUpdateBy(getUsername());
        return toAjax(buyerPolicyService.updateBuyerPolicy(buyerPolicy));
    }

    /**
     * 删除加计扣除相关政策
     */
    @ApiOperation(value = "删除加计扣除相关政策")
    @PreAuthorize("@ss.hasPermi('system:policy:remove')")
    @Log(title = "加计扣除相关政策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(buyerPolicyService.deleteBuyerPolicyByIds(ids));
    }
}
