package com.zhongzheng.controller.course;

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.framework.web.service.*;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.course.bo.CourseEducationTypeQueryBo;
import com.zhongzheng.modules.course.service.ICourseEducationTypeService;
import com.zhongzheng.modules.course.service.ICourseService;
import com.zhongzheng.modules.course.vo.CourseEducationTypeVo;
import com.zhongzheng.modules.goods.vo.GoodsPeriodStatusVo;
import com.zhongzheng.modules.goods.vo.GoodsPeriodVo;
import com.zhongzheng.modules.goods.vo.GoodsVo;
import com.zhongzheng.modules.grade.bo.ClassGradeUserQueryBo;
import com.zhongzheng.modules.user.bo.UserPlanQueryBo;
import com.zhongzheng.modules.user.bo.UserSubscribeCertificateEditBo;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
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-10-08
 */
@Api(value = "我的学时", tags = {"我的学时"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/period")
public class CoursePeriodController extends BaseController {

    private final ICourseService courseService;

    private final WxTokenService wxTokenService;

    /**
     * 查询用户拥有商品的学时记录
     */
    @ApiOperation("查询用户拥有商品的学时记录")
    @GetMapping("/listGoods")
    public TableDataInfo<GoodsPeriodVo> listGoods(UserPlanQueryBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<GoodsPeriodVo> list = courseService.listGoodsPeriodVo(bo);
        return getDataTable(list);
    }

    /**
     * 查询学习计划列表
     */
    @ApiOperation("查看班级作弊重学详细情况")
    @GetMapping("/cheat")
    public TableDataInfo<GoodsPeriodStatusVo> listSection(ClassGradeUserQueryBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<GoodsPeriodStatusVo> list = courseService.listSection(bo);
        return getDataTable(list);
    }

    /**
     * 修改用户预约考试
     */
    @ApiOperation("确认重学")
    @Log(title = "确认重学", businessType = BusinessType.UPDATE)
    @PostMapping("rebuild")
    public AjaxResult<Void> editRebuild(@RequestBody ClassGradeUserQueryBo bo) {
        return toAjax(courseService.editRebuild(bo) ? 1 : 0);
    }


}
