package com.zhongzheng.controller.grade;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.modules.grade.bo.*;
import com.zhongzheng.modules.grade.service.IClassGradeInterfaceService;
import com.zhongzheng.modules.grade.service.IClassGradeSysService;
import com.zhongzheng.modules.grade.service.IClassGradeUserService;
import com.zhongzheng.modules.grade.vo.*;
import lombok.RequiredArgsConstructor;
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.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.modules.grade.service.IClassGradeService;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 班级Controller
 *
 * @author ruoyi
 * @date 2021-11-10
 */
@Api(value = "班级控制器", tags = {"班级管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/grade/grade")
public class ClassGradeController extends BaseController {

    private final IClassGradeService iClassGradeService;

    private final IClassGradeInterfaceService iClassGradeInterfaceService;

    private final IClassGradeSysService iClassGradeSysService;

    private final IClassGradeUserService iClassGradeUserService;

    /**
     * 查询班级列表
     */
    @ApiOperation("查询班级列表")
    @PreAuthorize("@ss.hasPermi('grade:grade:list')")
    @GetMapping("/list")
    public TableDataInfo<ClassGradeVo> list(ClassGradeQueryBo bo) {
        startPage();
        List<ClassGradeVo> list = iClassGradeService.queryList(bo);
        return getDataTable(list);
    }


    /**
     * 查询班级列表
     */
    @ApiOperation("查询班级学员列表")
    @PreAuthorize("@ss.hasPermi('grade:grade:list')")
    @GetMapping("/listGrade")
    public TableDataInfo<ClassGradeStudentVo> listGrade(ClassGradeUserQueryBo bo) {
        startPage();
        List<ClassGradeStudentVo> list = iClassGradeService.listGrade(bo);
        return getDataTable(list);
    }

    /**
     * 查询学员记录列表
     */
    @ApiOperation("查询学员记录列表")
    @PreAuthorize("@ss.hasPermi('grade:user:list')")
    @GetMapping("/listUser")
    public TableDataInfo<ClassGradeUserVo> list(ClassGradeUserQueryBo bo) {
        startPage();
        List<ClassGradeUserVo> list = iClassGradeUserService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 查询学时学员记录列表
     */
    @ApiOperation("查询学员记录列表")
    @PreAuthorize("@ss.hasPermi('grade:user:list')")
    @GetMapping("/listUserPeriod")
    public TableDataInfo<ClassGradeUserVo> listUserPeriod(ClassGradeUserQueryBo bo) {
        startPage();
        List<ClassGradeUserVo> list = iClassGradeUserService.listUserPeriod(bo);
        return getDataTable(list);
    }



    /**
     * 查询班主任记录列表
     */
    @ApiOperation("查询班主任记录列表")
    @PreAuthorize("@ss.hasPermi('grade:sys:list')")
    @GetMapping("/listSys")
    public TableDataInfo<ClassGradeSysVo> list(ClassGradeSysQueryBo bo) {
        startPage();
        List<ClassGradeSysVo> list = iClassGradeSysService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 查询班级列表
     */
    @ApiOperation("是否出现官方接口选择")
    @PreAuthorize("@ss.hasPermi('grade:grade:select')")
    @GetMapping("/select")
    public AjaxResult<Integer> select(ClassGradeAddBo bo) {
        boolean tenantId = ServletUtils.getRequest().getHeader("TenantId").equals("867735392558919680");
        return AjaxResult.success(tenantId ? 1 : 0);
    }

    /**
     * 查询官方接口
     */
    @ApiOperation("查询官方接口")
    @PreAuthorize("@ss.hasPermi('grade:grade:list')")
    @GetMapping("/listInterfaceVo")
    public TableDataInfo<ClassGradeInterfaceVo> list(ClassGradeInterfaceQueryBo bo) {
        startPage();
        List<ClassGradeInterfaceVo> list = iClassGradeInterfaceService.queryList(bo);
        return getDataTable(list);
    }

    /*    *//**
     * 导出班级列表
     *//*
    @ApiOperation("导出班级列表")
    @PreAuthorize("@ss.hasPermi('modules.grade:grade:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ClassGradeVo> export(ClassGradeQueryBo bo) {
        List<ClassGradeVo> list = iClassGradeService.queryList(bo);
        ExcelUtil<ClassGradeVo> util = new ExcelUtil<ClassGradeVo>(ClassGradeVo.class);
        return util.exportExcel(list, "班级");
    }*/

    /**
     * 获取班级详细信息
     */
    @ApiOperation("获取班级详细信息")
    @PreAuthorize("@ss.hasPermi('grade:grade:query')")
    @GetMapping("/{classId}")
    public AjaxResult<ClassGradeVo> getInfo(@PathVariable("classId") Long classId) {
        return AjaxResult.success(iClassGradeService.queryById(classId));
    }

    /**
     * 新增班级
     */
    @ApiOperation("新增班级")
    @PreAuthorize("@ss.hasPermi('grade:grade:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody ClassGradeAddBo bo) {
        return toAjax(iClassGradeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改班级
     */
    @ApiOperation("修改班级")
    @PreAuthorize("@ss.hasPermi('grade:grade:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody ClassGradeEditBo bo) {
        return toAjax(iClassGradeService.updateByEditBo(bo) ? 1 : 0);
    }

    /*    *//**
     * 删除班级
     *//*
    @ApiOperation("删除班级")
    @PreAuthorize("@ss.hasPermi('modules.grade:grade:remove')")
    @Log(title = "班级" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{classIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] classIds) {
        return toAjax(iClassGradeService.deleteWithValidByIds(Arrays.asList(classIds), true) ? 1 : 0);
    }*/
}
