package com.bonus.sgzb.base.controller;

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

import com.bonus.sgzb.base.api.domain.SysDic;
import com.bonus.sgzb.base.service.ISysDicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;

/**
 * 数据字典Controller
 *
 * @author bonus
 * @date 2023-12-11
 */
@Api(tags = "数据字典Controller")
@RestController
@RequestMapping("/dic")
public class SysDicController extends BaseController
{
    @Autowired
    private ISysDicService sysDicService;

    /**
     * 查询数据字典列表
     */
    @ApiOperation(value = "查询数据字典列表")
    @GetMapping("/list")
    public TableDataInfo list(SysDic sysDic)
    {
        startPage();
        List<SysDic> list = sysDicService.selectSysDicList(sysDic);
        return getDataTable(list);
    }

    /**
     * 导出数据字典列表
     */
    @ApiOperation(value = "导出数据字典列表")
    @Log(title = "数据字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDic sysDic)
    {
        List<SysDic> list = sysDicService.selectSysDicList(sysDic);
        ExcelUtil<SysDic> util = new ExcelUtil<SysDic>(SysDic.class);
        util.exportExcel(response, list, "数据字典数据");
    }

    /**
     * 获取数据字典详细信息
     */
    @ApiOperation(value = "获取数据字典详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysDicService.selectSysDicById(id));
    }

    /**
     * 新增数据字典
     */
    @ApiOperation(value = "新增数据字典")
    @Log(title = "数据字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDic sysDic)
    {
        return toAjax(sysDicService.insertSysDic(sysDic));
    }

    /**
     * 修改数据字典
     */
    @ApiOperation(value = "修改数据字典")
    @Log(title = "数据字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDic sysDic)
    {
        return toAjax(sysDicService.updateSysDic(sysDic));
    }

    /**
     * 删除数据字典
     */
    @ApiOperation(value = "删除数据字典")
    @Log(title = "数据字典", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysDicService.deleteSysDicByIds(ids));
    }
}
