package com.admin.web.controller.major;

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

import com.admin.major.domain.AdjustResult;
import com.admin.major.domain.dto.ClassResultDTO;
import com.admin.major.manager.ClassResultManager;
import com.admin.major.service.EnhanceClassResultService;
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.ClassResult;
import com.admin.major.service.IClassResultService;
import com.admin.common.utils.poi.ExcelUtil;
import com.admin.common.core.page.TableDataInfo;

/**
 * 分班结果Controller
 * 
 * @author ljx
 * @date 2022-05-18
 */
@RestController
@RequestMapping("/major/classResult")
public class ClassResultController extends BaseController
{
    @Autowired
    private IClassResultService classResultService;
    @Autowired
    private EnhanceClassResultService enhanceClassResultService;
    @Autowired
    private ClassResultManager classResultManager;

    /**
     * 查询分班结果列表
     */
    @PreAuthorize("@ss.hasPermi('major:classResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassResultDTO classResultDTO)
    {
        startPage();
        List<ClassResultDTO> list = enhanceClassResultService.viewClassResult(classResultDTO);
        return getDataTable(list);
    }

    /**
     * 导出分班结果列表
     */
    @PreAuthorize("@ss.hasPermi('major:classResult:export')")
    @Log(title = "分班结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassResultDTO classResultDTO)
    {
        List<ClassResultDTO> list = enhanceClassResultService.viewClassResult(classResultDTO);
        ExcelUtil<ClassResultDTO> util = new ExcelUtil<ClassResultDTO>(ClassResultDTO.class);
        util.exportExcel(response, list, "分班结果数据");
    }

    /**
     * 获取分班结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('major:classResult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(enhanceClassResultService.selectClassResultById(id));
    }

    /**
     * 新增分班结果
     */
    @PreAuthorize("@ss.hasPermi('major:classResult:add')")
    @Log(title = "分班结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassResult classResult)
    {
        return toAjax(classResultService.insertClassResult(classResult));
    }

    /**
     * 修改分班结果
     */
    @PreAuthorize("@ss.hasPermi('major:classResult:edit')")
    @Log(title = "分班结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassResult classResult)
    {
        return toAjax(classResultService.updateClassResult(classResult));
    }

    /**
     * 删除分班结果
     */
    @PreAuthorize("@ss.hasPermi('major:classResult:remove')")
    @Log(title = "分班结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classResultService.deleteClassResultByIds(ids));
    }

    /**
     * 分班
     */
    @PreAuthorize("@ss.hasPermi('major:classResult:add')")
    @Log(title = "分流", businessType = BusinessType.OTHER)
    @PostMapping("/startClass")
    public AjaxResult startClass(@RequestBody ClassResult classResult)
    {
        classResultManager.division(classResult.getYear(),classResult.getCollegeId());
        return toAjax(true);
    }
}
