package com.ruoyi.adjust.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.adjust.domain.DPatentDataCollationLog;
import com.ruoyi.adjust.service.IDPatentDataCollationLogService;
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 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-04-19
 */
@RestController
@RequestMapping("/adjust/dPatentDataCollationLog")
public class DPatentDataCollationLogController extends BaseController {
    private final IDPatentDataCollationLogService dPatentDataCollationLogService;

    public DPatentDataCollationLogController(IDPatentDataCollationLogService dPatentDataCollationLogService) {
        this.dPatentDataCollationLogService = dPatentDataCollationLogService;
    }


    /**
     * 查询专利数据整理历史列表
     *
     * @param dPatentDataCollationLog 专利数据整理历史
     * @return 专利数据整理历史集合
     * @date 2023-04-19
     */
    @PreAuthorize("@ss.hasPermi('adjust:dPatentDataCollationLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(DPatentDataCollationLog dPatentDataCollationLog) {
        startPage();
        List<DPatentDataCollationLog> list = dPatentDataCollationLogService.queryList(dPatentDataCollationLog);
        return getDataTable(list);
    }


    /**
     * 导出专利数据整理历史列表
     *
     * @param dPatentDataCollationLog 专利数据整理历史
     * @date 2023-04-19
     */
    @PreAuthorize("@ss.hasPermi('adjust:dPatentDataCollationLog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DPatentDataCollationLog dPatentDataCollationLog) {
        List<DPatentDataCollationLog> list = dPatentDataCollationLogService.list(new QueryWrapper<>());
        ExcelUtil<DPatentDataCollationLog> util = new ExcelUtil<>(DPatentDataCollationLog.class);
        util.exportExcel(response, list, "专利数据整理历史数据");
    }

    /**
     * 获取专利数据整理历史详细信息
     *
     * @param id 主键id
     * @return 结果
     * @date 2023-04-19
     */
    @PreAuthorize("@ss.hasPermi('adjust:dPatentDataCollationLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(dPatentDataCollationLogService.getById(id));
    }


    /**
     * 新增专利数据整理历史信息
     *
     * @param dPatentDataCollationLog 专利数据整理历史
     * @return 结果
     * @date 2023-04-19
     */
    @PreAuthorize("@ss.hasPermi('adjust:dPatentDataCollationLog:add')")
    @Log(title = "专利数据整理历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DPatentDataCollationLog dPatentDataCollationLog) {
        return toAjax(dPatentDataCollationLogService.save(dPatentDataCollationLog));
    }


    /**
     * 修改专利数据整理历史信息
     *
     * @param dPatentDataCollationLog 专利数据整理历史
     * @return 结果
     * @date 2023-04-19
     */
    @PreAuthorize("@ss.hasPermi('adjust:dPatentDataCollationLog:edit')")
    @Log(title = "专利数据整理历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DPatentDataCollationLog dPatentDataCollationLog) {
        return toAjax(dPatentDataCollationLogService.updateById(dPatentDataCollationLog));
    }


    /**
     * 删除专利数据整理历史信息
     *
     * @param ids 主键ids
     * @return 结果
     * @date 2023-04-19
     */
    @PreAuthorize("@ss.hasPermi('adjust:dPatentDataCollationLog:remove')")
    @Log(title = "专利数据整理历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dPatentDataCollationLogService.removeByIds(Arrays.asList(ids)));
    }


}
