package com.zhongzheng.controller.grade;

import java.util.ArrayList;
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.*;
import com.zhongzheng.modules.grade.vo.*;
import io.swagger.models.auth.In;
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.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;

    private final IUserPeriodService iUserPeriodService;

    private final IUserPeriodStatusService userPeriodStatusService;

    /**
     * 查询班级列表
     */
    @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("是否出现官方按钮选择 1官方信息推送 2官方学时推送 3账号开通    1,2,3 班级出现全部  学时审核出现学时推送 ")
    @PreAuthorize("@ss.hasPermi('grade:grade:select')")
    @GetMapping("/selectButton")
    public AjaxResult<Integer[]> selectButton(ClassGradeQueryBo bo) {
        ClassGradeVo classGradeVo = iClassGradeService.queryList(bo).get(0);
        List<Integer> integers = new ArrayList<>();
        Integer status =1;
        if (classGradeVo.getInterfacePushId() != null ){
            integers.add(1);
        }
        if (classGradeVo.getInterfacePeriodId()!=null){
            integers.add(2);
        }
        if (classGradeVo.getInterfaceAccountId() != null ){
            integers.add(3);
        }
        //初始化需要得到的数组
        Integer[] array = new Integer[integers.size()];

        //使用for循环得到数组
        for(int i = 0; i < integers.size();i++){
            array[i] = integers.get(i);
        }
        return AjaxResult.success(array);
    }


    /**
     * 查询班级列表
     */
    @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:grade:edit')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping("/addUserGrade")
    public AjaxResult<Void> editUserGrade(@RequestBody ClassGradeUserAddQueryBo bo) {
        return toAjax(iClassGradeService.editUserGrade(bo) ? 1 : 0);
    }



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

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

    /**
     * 学时审核
     */
    @ApiOperation("学时审核")
    @PreAuthorize("@ss.hasPermi('grade:user:list')")
    @GetMapping("/listPeriodAudit")
    public TableDataInfo<ClassPeriodVo> listPeriodAudit(ClassGradeUserQueryBo bo) {
        startPage();
        List<ClassPeriodVo> list = iClassGradeUserService.listPeriodAudit(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("/listPeriodStatus")
    public TableDataInfo<UserPeriodStatusVo> list(UserPeriodQueryBo bo) {
        startPage();
        List<UserPeriodStatusVo> list = userPeriodStatusService.selectPeriodStatus(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('grade:grade:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/editPeriod")
    public AjaxResult<Void> edit(@RequestBody UserPeriodEditBo bo) {
        return toAjax(iUserPeriodService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("更改全部待审核状态")
    @PreAuthorize("@ss.hasPermi('grade:grade:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/editPeriodAll")
    public AjaxResult<Void> editPeriodAll(@RequestBody UserPeriodEditBo bo) {
        return toAjax(iUserPeriodService.editPeriodAll(bo) ? 1 : 0);
    }

    /**
     * 修改学员记录
     */
    @ApiOperation("修改学员记录")
    @PreAuthorize("@ss.hasPermi('system:user:edit')")
    @Log(title = "学员记录", businessType = BusinessType.UPDATE)
    @PostMapping("/editGradeUser")
    public AjaxResult<Void> edit(@RequestBody ClassGradeUserEditBo bo) {
        return toAjax(iClassGradeUserService.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);
    }*/


    /**
     * 学时审核
     */
    @ApiOperation("学时审核第一次請求獲得商品的章節")
    @PreAuthorize("@ss.hasPermi('grade:user:list')")
    @GetMapping("/listPeriodAuditOne")
    public TableDataInfo<ClassPeriodVo> listPeriodAuditOne(ClassGradeUserQueryBo bo) {
        startPage();
        List<ClassPeriodVo> list = iClassGradeUserService.listPeriodAuditOne(bo);
        return getDataTable(list);
    }

    /**
     * 学时审核
     */
    @ApiOperation("学时审核獲得商品模塊下的章")
    @PreAuthorize("@ss.hasPermi('grade:user:list')")
    @GetMapping("/listPeriodAuditChapter")
    public TableDataInfo<ClassPeriodChapterVo> listPeriodAuditChapter(ClassGradeUserQueryBo bo) {
        startPage();
        List<ClassPeriodChapterVo> list = iClassGradeUserService.listPeriodAuditChapter(bo);
        return getDataTable(list);
    }

    /**
     * 学时审核
     */
    @ApiOperation("学时审核獲得商品章下面的節")
    @PreAuthorize("@ss.hasPermi('grade:user:list')")
    @GetMapping("/listPeriodAuditSection")
    public TableDataInfo<ClassPeriodSectionVo> listPeriodAuditSection(ClassGradeUserQueryBo bo) {
        startPage();
        List<ClassPeriodSectionVo> list = iClassGradeUserService.listPeriodAuditSection(bo);
        return getDataTable(list);
    }

    /**
     * 学时审核
     */
    @ApiOperation("学时审核獲得商品節下面的審核記錄")
    @PreAuthorize("@ss.hasPermi('grade:user:list')")
    @GetMapping("/listPeriodAuditStatus")
    public AjaxResult<ClassPeriodSectionVo> listPeriodAuditStatus(UserPeriodQueryBo bo) {
        startPage();
        ClassPeriodSectionVo list = iClassGradeUserService.listPeriodAuditStatus(bo);
        return AjaxResult.success(list);
    }
}
