package com.ruoyi.operations.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.operations.domain.CPatentOperations;
import com.ruoyi.operations.service.ICPatentOperationsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中国专利运营Controller
 *
 * @author ruoyi
 * @date 2023-04-28
 */
@RestController
@RequestMapping("/operations/cPatentOperations")
public class CPatentOperationsController extends BaseController {
    private final ICPatentOperationsService cPatentOperationsService;

    public CPatentOperationsController(ICPatentOperationsService cPatentOperationsService) {
        this.cPatentOperationsService = cPatentOperationsService;
    }


    /**
     * 查询中国专利运营列表
     *
     * @param cPatentOperations 中国专利运营
     * @return 中国专利运营集合
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('operations:cPatentOperations:list')")
    @GetMapping("/list")
    public TableDataInfo list(CPatentOperations cPatentOperations) {
        startPage();
        List<CPatentOperations> list = cPatentOperationsService.queryList(cPatentOperations);
        return getDataTable(list);
    }


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

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


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


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


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


}
