package com.ruoyi.award.controller;

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

import org.springframework.security.access.prepost.PreAuthorize;
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 java.util.Arrays;

import com.ruoyi.common.core.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.award.domain.CPatentAward;
import com.ruoyi.award.service.ICPatentAwardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中国专利奖Controller
 *
 * @author ruoyi
 * @date 2023-04-28
 */
@RestController
@RequestMapping("/award/cPatentAward")
public class CPatentAwardController extends BaseController {
    private final ICPatentAwardService cPatentAwardService;

    public CPatentAwardController(ICPatentAwardService cPatentAwardService) {
        this.cPatentAwardService = cPatentAwardService;
    }


    /**
     * 查询中国专利奖列表
     *
     * @param cPatentAward 中国专利奖
     * @return 中国专利奖集合
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('award:cPatentAward:list')")
    @GetMapping("/list")
    public TableDataInfo list(CPatentAward cPatentAward) {
        startPage();
        List<CPatentAward> list = cPatentAwardService.queryList(cPatentAward);
        return getDataTable(list);
    }


    /**
     * 导出中国专利奖列表
     *
     * @param cPatentAward 中国专利奖
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('award:cPatentAward:export')")
    @Log(title = "中国专利奖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CPatentAward cPatentAward) {
        List<CPatentAward> list = cPatentAwardService.list(new QueryWrapper<>());
        ExcelUtil<CPatentAward> util = new ExcelUtil<>(CPatentAward. class);
        util.exportExcel(response, list, "中国专利奖数据");
    }

    /**
     * 获取中国专利奖详细信息
     *
     * @param id 主键id
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('award:cPatentAward:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cPatentAwardService.getById(id));
    }


    /**
     * 新增中国专利奖信息
     *
     * @param cPatentAward 中国专利奖
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('award:cPatentAward:add')")
    @Log(title = "中国专利奖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CPatentAward cPatentAward) {
        return toAjax(cPatentAwardService.save(cPatentAward));
    }


    /**
     * 修改中国专利奖信息
     *
     * @param cPatentAward 中国专利奖
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('award:cPatentAward:edit')")
    @Log(title = "中国专利奖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CPatentAward cPatentAward) {
        return toAjax(cPatentAwardService.updateById(cPatentAward));
    }


    /**
     * 删除中国专利奖信息
     *
     * @param ids 主键ids
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('award:cPatentAward:remove')")
    @Log(title = "中国专利奖", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cPatentAwardService.removeByIds(Arrays.asList(ids)));
    }


}
