package com.ruoyi.dimp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dimp.domain.DPatentEffectiveInfo;
import com.ruoyi.dimp.service.IDPatentEffectiveInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 专利有效导入Controller
 *
 * @author ruoyi
 * @date 2023-03-19
 */
@RestController
@RequestMapping("/dimp/dPatentEffectiveInfo")
public class DPatentEffectiveInfoController extends BaseController {
    private final IDPatentEffectiveInfoService dPatentEffectiveInfoService;

    public DPatentEffectiveInfoController(IDPatentEffectiveInfoService dPatentEffectiveInfoService) {
        this.dPatentEffectiveInfoService = dPatentEffectiveInfoService;
    }


    /**
     * 查询专利有效导入列表
     *
     * @param dPatentEffectiveInfo 专利有效导入
     * @return 专利有效导入集合
     * @date 2023-03-19
     */
    @PreAuthorize("@ss.hasPermi('dimp:dPatentEffectiveInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(DPatentEffectiveInfo dPatentEffectiveInfo) {
        startPage();
        List<DPatentEffectiveInfo> list = dPatentEffectiveInfoService.queryList(dPatentEffectiveInfo);
        return getDataTable(list);
    }


    /**
     * 导出专利有效导入列表
     *
     * @param dPatentEffectiveInfo 专利有效导入
     * @date 2023-03-19
     */
    @PreAuthorize("@ss.hasPermi('dimp:dPatentEffectiveInfo:export')")
    @Log(title = "专利有效导入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DPatentEffectiveInfo dPatentEffectiveInfo) {
        List<DPatentEffectiveInfo> list = dPatentEffectiveInfoService.list(new QueryWrapper<>());
        ExcelUtil<DPatentEffectiveInfo> util = new ExcelUtil<>(DPatentEffectiveInfo.class);
        util.exportExcel(response, list, "专利有效导入数据");
    }

    /**
     * 获取专利有效导入详细信息
     *
     * @param id 主键id
     * @return 结果
     * @date 2023-03-19
     */
    @PreAuthorize("@ss.hasPermi('dimp:dPatentEffectiveInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(dPatentEffectiveInfoService.getById(id));
    }


    /**
     * 新增专利有效导入信息
     *
     * @param dPatentEffectiveInfo 专利有效导入
     * @return 结果
     * @date 2023-03-19
     */
    @PreAuthorize("@ss.hasPermi('dimp:dPatentEffectiveInfo:add')")
    @Log(title = "专利有效导入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DPatentEffectiveInfo dPatentEffectiveInfo) {
        return toAjax(dPatentEffectiveInfoService.save(dPatentEffectiveInfo));
    }


    /**
     * 修改专利有效导入信息
     *
     * @param dPatentEffectiveInfo 专利有效导入
     * @return 结果
     * @date 2023-03-19
     */
    @PreAuthorize("@ss.hasPermi('dimp:dPatentEffectiveInfo:edit')")
    @Log(title = "专利有效导入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DPatentEffectiveInfo dPatentEffectiveInfo) {
        return toAjax(dPatentEffectiveInfoService.updateById(dPatentEffectiveInfo));
    }


    /**
     * 删除专利有效导入信息
     *
     * @param ids 主键ids
     * @return 结果
     * @date 2023-03-19
     */
    @PreAuthorize("@ss.hasPermi('dimp:dPatentEffectiveInfo:remove')")
    @Log(title = "专利有效导入", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dPatentEffectiveInfoService.removeByIds(Arrays.asList(ids)));
    }


}
