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.BuyerSubjectContent;
import com.ruoyi.buyerapi.service.IBuyerSubjectContentService;
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/content")
public class BuyerSubjectContentController extends BaseController
{
    @Autowired
    private IBuyerSubjectContentService buyerSubjectContentService;

    /**
     * 查询科密对应关系列表
     */
    @ApiOperation(value = "查询科密对应关系列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "subject", value = "会计科目", required = true, paramType = "query"),
            @ApiImplicitParam(name = "content", 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:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerSubjectContent buyerSubjectContent)
    {
        startPage();
        List<BuyerSubjectContent> list = buyerSubjectContentService.selectBuyerSubjectContentList(buyerSubjectContent);
        return getDataTable(list);
    }

    /**
     * 导出科密对应关系列表
     */
    @ApiOperation(value = "导出科密对应关系列表")
    @PreAuthorize("@ss.hasPermi('system:content:export')")
    @Log(title = "科密对应关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerSubjectContent buyerSubjectContent)
    {
        List<BuyerSubjectContent> list = buyerSubjectContentService.selectBuyerSubjectContentList(buyerSubjectContent);
        ExcelUtil<BuyerSubjectContent> util = new ExcelUtil<BuyerSubjectContent>(BuyerSubjectContent.class);
        util.exportExcel(response, list, "科密对应关系数据");
    }

    /**
     * 获取科密对应关系详细信息
     */
    @ApiOperation(value = "获取科密对应关系详细信息")
    @PreAuthorize("@ss.hasPermi('system:content:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(buyerSubjectContentService.selectBuyerSubjectContentById(id));
    }

    /**
     * 新增科密对应关系
     */
    @ApiOperation(value = "新增科密对应关系")
    @PreAuthorize("@ss.hasPermi('system:content:add')")
    @Log(title = "科密对应关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerSubjectContent buyerSubjectContent)
    {
        buyerSubjectContent.setId(IdUtil.simpleUUID());
        buyerSubjectContent.setCreateBy(getUsername());
        return toAjax(buyerSubjectContentService.insertBuyerSubjectContent(buyerSubjectContent));
    }

    /**
     * 修改科密对应关系
     */
    @ApiOperation(value = "修改科密对应关系")
    @PreAuthorize("@ss.hasPermi('system:content:edit')")
    @Log(title = "科密对应关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerSubjectContent buyerSubjectContent)
    {
        buyerSubjectContent.setUpdateBy(getUsername());
        return toAjax(buyerSubjectContentService.updateBuyerSubjectContent(buyerSubjectContent));
    }

    /**
     * 删除科密对应关系
     */
    @ApiOperation(value = "删除科密对应关系")
    @PreAuthorize("@ss.hasPermi('system:content:remove')")
    @Log(title = "科密对应关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(buyerSubjectContentService.deleteBuyerSubjectContentByIds(ids));
    }
}
