package com.zd.system.controller;

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

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.web.domain.ResultData;
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.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.system.domain.SysClass;
import com.zd.system.service.ISysClassService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.zd.common.swagger.config.Knife4jConfiguration;
import com.zd.common.core.web.page.TableDataInfo;

/**
 * 班级字典Controller
 *
 * @author zd
 * @date 2022-04-08
 */
@RestController
@Api(tags = "【班级字典】")
//作者手动加入 ，在接口上加作者@ApiOperationSupport(author = "XXX")
@ApiSupport(author = Knife4jConfiguration.Author.CYL)
@RequestMapping("/class")
public class SysClassController extends BaseController
{
    @Autowired
    private ISysClassService sysClassService;

    /**
     * 查询班级字典列表
     */
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_CLASS+ PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询班级字典列表")
    public TableDataInfo<SysClass> list(SysClass sysClass)
    {
        startPage();
        List<SysClass> list = sysClassService.selectSysClassList(sysClass);
        return getDataTable(list);
    }

    /**
     * 查询班级字典列表
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询班级字典列表")
    public ResultData<List<SysClass>> listAll(SysClass sysClass)
    {
        List<SysClass> list = sysClassService.selectSysClassList(sysClass);
        return ResultData.success(list);
    }

    /**
     * 导出班级字典列表
     */
    @ApiOperation(value = "导出班级字典列表")
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_CLASS+ PerFun.EXPORT)
    @Log(title = "班级字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysClass sysClass) throws IOException
    {
        List<SysClass> list = sysClassService.selectSysClassList(sysClass);
        ExcelUtil<SysClass> util = new ExcelUtil<SysClass>(SysClass.class);
        util.exportExcel(response, list, "班级字典数据");
    }

    /**
     * 获取班级字典详细信息
     */
    @ApiOperation(value = "获取班级字典详细信息")
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_CLASS+ PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<SysClass> getInfo(@PathVariable("id") Long id)
    {
        return ResultData.success(sysClassService.selectSysClassById(id));
    }

    /**
     * 新增班级字典
     */
    @ApiOperation(value = "新增班级字典")
//    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_CLASS+ PerFun.ADD)
    @Log(title = "班级字典", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody SysClass sysClass)
    {
        return ResultData.success(sysClassService.insertSysClass(sysClass));
    }

    /**
     * 修改班级字典
     */
    @ApiOperation(value = "修改班级字典")
//    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_CLASS+ PerFun.EDIT)
    @Log(title = "班级字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody SysClass sysClass)
    {
        return  ResultData.result(sysClassService.updateSysClass(sysClass));
    }

    /**
     * 删除班级字典
     */
    @ApiOperation(value = "删除班级字典")
    @PreAuthorize(hasPermi = PerPrefix.SYSTEM_CLASS+ PerFun.REMOVE)
    @Log(title = "班级字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids)
    {
        return ResultData.result(sysClassService.deleteSysClassByIds(ids));
    }
}
