package com.ruoyi.system.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.system.domain.DIpcType;
import com.ruoyi.system.service.IDIpcTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ipc分类Controller
 *
 * @author ruoyi
 * @date 2023-04-05
 */
@RestController
@RequestMapping("/system/dIpcType")
public class DIpcTypeController extends BaseController {
    private final IDIpcTypeService dIpcTypeService;

    public DIpcTypeController(IDIpcTypeService dIpcTypeService) {
        this.dIpcTypeService = dIpcTypeService;
    }


    /**
     * 查询ipc分类列表
     *
     * @param dIpcType ipc分类
     * @return ipc分类集合
     * @date 2023-04-05
     */
    @PreAuthorize("@ss.hasPermi('system:dIpcType:list')")
    @GetMapping("/list")
    public TableDataInfo list(DIpcType dIpcType) {
        startPage();
        List<DIpcType> list = dIpcTypeService.queryList(dIpcType);
        return getDataTable(list);
    }


    /**
     * 导出ipc分类列表
     *
     * @param dIpcType ipc分类
     * @date 2023-04-05
     */
    @PreAuthorize("@ss.hasPermi('system:dIpcType:export')")
    @Log(title = "ipc分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DIpcType dIpcType) {
        List<DIpcType> list = dIpcTypeService.list(new QueryWrapper<>());
        ExcelUtil<DIpcType> util = new ExcelUtil<>(DIpcType. class);
        util.exportExcel(response, list, "ipc分类数据");
    }

    /**
     * 获取ipc分类详细信息
     *
     * @param id 主键id
     * @return 结果
     * @date 2023-04-05
     */
    @PreAuthorize("@ss.hasPermi('system:dIpcType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(dIpcTypeService.getById(id));
    }


    /**
     * 新增ipc分类信息
     *
     * @param dIpcType ipc分类
     * @return 结果
     * @date 2023-04-05
     */
    @PreAuthorize("@ss.hasPermi('system:dIpcType:add')")
    @Log(title = "ipc分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DIpcType dIpcType) {
        return toAjax(dIpcTypeService.save(dIpcType));
    }


    /**
     * 修改ipc分类信息
     *
     * @param dIpcType ipc分类
     * @return 结果
     * @date 2023-04-05
     */
    @PreAuthorize("@ss.hasPermi('system:dIpcType:edit')")
    @Log(title = "ipc分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DIpcType dIpcType) {
        return toAjax(dIpcTypeService.updateById(dIpcType));
    }


    /**
     * 删除ipc分类信息
     *
     * @param ids 主键ids
     * @return 结果
     * @date 2023-04-05
     */
    @PreAuthorize("@ss.hasPermi('system:dIpcType:remove')")
    @Log(title = "ipc分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dIpcTypeService.removeByIds(Arrays.asList(ids)));
    }


}
