package com.zhongzheng.controller.grade;

import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.core.page.TableDataInfo;
import com.zhongzheng.common.enums.BusinessType;
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.IClassGradeService;
import com.zhongzheng.modules.grade.service.IClassGradeSysService;
import com.zhongzheng.modules.grade.service.IClassGradeUserService;
import com.zhongzheng.modules.grade.vo.*;
import com.zhongzheng.modules.user.bo.*;
import com.zhongzheng.modules.user.service.IUserService;
import com.zhongzheng.modules.user.service.IUserStudyRecordService;
import com.zhongzheng.modules.user.service.IUserUpdateService;
import com.zhongzheng.modules.user.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

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

    private final IClassGradeService iClassGradeService;

    private final IClassGradeInterfaceService iClassGradeInterfaceService;

    private final IClassGradeSysService iClassGradeSysService;

    private final IClassGradeUserService iClassGradeUserService;

    private final IUserStudyRecordService iUserStudyRecordService;

    private final IUserService iUserService;
    private final IUserUpdateService iUserUpdateService;


    /**
     * 查询學員用户列表
     */
    @ApiOperation("查询學員用户列表")
    @PreAuthorize("@ss.hasPermi('app:user:list')")
    @GetMapping("/listStudent")
    public TableDataInfo<UserVo> listStudent(UserQueryBo bo) {
        startPage();
        List<UserVo> list = iUserService.selectList(bo);
        return getDataTable(list);
    }


    /**
     * 修改客户端用户
     */
    @ApiOperation("修改學員用户")
    @PreAuthorize("@ss.hasPermi('app:user:edit')")
    @Log(title = "修改學員用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody UserEditBo bo) throws IllegalAccessException {
        return toAjax(iUserService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 查询学员商品学习记录
     */
    @ApiOperation("查询学员商品学习记录")
    @PreAuthorize("@ss.hasPermi('grade:student:list')")
    @GetMapping("/list")
    public TableDataInfo<GoodsStudyRecordVo> list(UserQueryBo bo) {
        startPage();
        List<GoodsStudyRecordVo> list = iUserStudyRecordService.queryGoods(bo);

        return getDataTable(list);
    }


    /**
     * 查询学员课程科目学习记录
     */
    @ApiOperation("查询学员课程科目学习记录")
    @PreAuthorize("@ss.hasPermi('grade:student:listSubject')")
    @GetMapping("/listSubject")
    public TableDataInfo<SubjectStudyRecordVo> listSubject(SubjectStudyRecordQueryBo bo) {
        startPage();
        List<SubjectStudyRecordVo> list = iUserStudyRecordService.listSubject(bo);
        return getDataTable(list);
    }

    /**
     * 查询学员课程节学习记录
     */
    @ApiOperation("查询学员课程节学习记录")
    @PreAuthorize("@ss.hasPermi('grade:student:listSection')")
    @GetMapping("/listSection")
    public TableDataInfo<SectionStudyRecordVo> listSection(SubjectStudyRecordQueryBo bo) {
        startPage();
        List<SectionStudyRecordVo> list = iUserStudyRecordService.listSection(bo);
        return getDataTable(list);
    }



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

    /**
     * 查询学员商品题库学习记录
     */
    @ApiOperation("查询学员商品题库学习记录")
    @PreAuthorize("@ss.hasPermi('grade:student:list')")
    @GetMapping("/listExam")
    public TableDataInfo<ExamStudyRecordVo> listExam(UserQueryBo bo) {
        startPage();
        List<ExamStudyRecordVo> list = iUserStudyRecordService.querExamStudy(bo);
        return getDataTable(list);
    }

    /**
     * 查询学员商品学习记录
     */
    @ApiOperation("查询学员商品卷学习记录")
    @PreAuthorize("@ss.hasPermi('grade:student:list')")
    @GetMapping("/listExamSon")
    public TableDataInfo<ExamSonStudyRecordVo> listExamSon(SubjectStudyRecordQueryBo bo) {
        startPage();
        List<ExamSonStudyRecordVo> list = iUserStudyRecordService.listExamSon(bo);
        return getDataTable(list);
    }

    /**
     * 查询用户修改记录列表
     */
    @ApiOperation("查询用户修改记录列表")
    @PreAuthorize("@ss.hasPermi('system:update:list')")
    @GetMapping("/userUpdateList")
    public TableDataInfo<UserUpdateVo> list(UserUpdateQueryBo bo) {
        startPage();
        List<UserUpdateVo> list = iUserUpdateService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 修改用户修改记录
     */
    @ApiOperation("修改用户修改记录")
    @PreAuthorize("@ss.hasPermi('system:update:edit')")
    @Log(title = "用户修改记录", businessType = BusinessType.UPDATE)
    @PostMapping("userUpdate")
    public AjaxResult<Void> edit(@RequestBody UserUpdateEditBo bo) {
        return toAjax(iUserUpdateService.updateByEditBo(bo) ? 1 : 0);
    }
}
