package com.admin.web.controller.major;

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

import com.admin.major.domain.dto.ClassInfoDTO;
import com.admin.major.service.EnhanceClassInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
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.admin.common.annotation.Log;
import com.admin.common.core.controller.BaseController;
import com.admin.common.core.domain.AjaxResult;
import com.admin.common.enums.BusinessType;
import com.admin.major.domain.ClassInfo;
import com.admin.major.service.IClassInfoService;
import com.admin.common.utils.poi.ExcelUtil;
import com.admin.common.core.page.TableDataInfo;

/**
 * 班级管理Controller
 * 
 * @author ljx
 * @date 2022-05-18
 */
@RestController
@RequestMapping("/major/classInfo")
public class ClassInfoController extends BaseController
{
    @Autowired
    private IClassInfoService classInfoService;
    @Autowired
    private EnhanceClassInfoService enhanceClassInfoService;

    /**
     * 查询班级管理列表
     */
    @PreAuthorize("@ss.hasPermi('major:classInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassInfo classInfo)
    {
        startPage();
        List<ClassInfoDTO> list = enhanceClassInfoService.viewClassInfo(classInfo);
        return getDataTable(list);
    }

    /**
     * 查询空余班级管理列表
     */
    @PreAuthorize("@ss.hasPermi('major:classInfo:list')")
    @GetMapping("/spareList")
    public TableDataInfo spareList()
    {
        startPage();
        List<ClassInfoDTO> list = enhanceClassInfoService.viewSpareClassInfo();
        return getDataTable(list);
    }

    /**
     * 导出班级管理列表
     */
    @PreAuthorize("@ss.hasPermi('major:classInfo:export')")
    @Log(title = "班级管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassInfo classInfo)
    {
        List<ClassInfoDTO> list = enhanceClassInfoService.viewClassInfo(classInfo);
        ExcelUtil<ClassInfoDTO> util = new ExcelUtil<ClassInfoDTO>(ClassInfoDTO.class);
        util.exportExcel(response, list, "班级管理数据");
    }

    /**
     * 获取班级管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('major:classInfo:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId)
    {
        return AjaxResult.success(enhanceClassInfoService.selectClassInfoById(classId));
    }

    /**
     * 新增班级管理
     */
    @PreAuthorize("@ss.hasPermi('major:classInfo:add')")
    @Log(title = "班级管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassInfo classInfo)
    {
        return toAjax(classInfoService.insertClassInfo(classInfo));
    }

    /**
     * 修改班级管理
     */
    @PreAuthorize("@ss.hasPermi('major:classInfo:edit')")
    @Log(title = "班级管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassInfo classInfo)
    {
        return toAjax(classInfoService.updateClassInfo(classInfo));
    }

    /**
     * 删除班级管理
     */
    @PreAuthorize("@ss.hasPermi('major:classInfo:remove')")
    @Log(title = "班级管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds)
    {
        return toAjax(classInfoService.deleteClassInfoByClassIds(classIds));
    }
}
