package com.zhongzheng.controller.bank;

import cn.hutool.core.lang.Validator;
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.domain.model.LoginUser;
import com.zhongzheng.common.core.page.TableDataInfo;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.framework.web.service.TokenService;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.bank.bo.QuestionAddBo;
import com.zhongzheng.modules.bank.bo.QuestionBusinessQueryBo;
import com.zhongzheng.modules.bank.bo.QuestionEditBo;
import com.zhongzheng.modules.bank.bo.QuestionQueryBo;
import com.zhongzheng.modules.bank.domain.QuestionBusiness;
import com.zhongzheng.modules.bank.service.IQuestionBusinessService;
import com.zhongzheng.modules.bank.service.IQuestionService;
import com.zhongzheng.modules.bank.vo.QuestionImport;
import com.zhongzheng.modules.bank.vo.QuestionVo;
import com.zhongzheng.modules.course.bo.CourseQueryBo;
import com.zhongzheng.modules.goods.bo.GoodsQueryBo;
import com.zhongzheng.modules.goods.service.IGoodsService;
import com.zhongzheng.modules.goods.vo.GoodsUserQuestionVo;
import com.zhongzheng.modules.goods.vo.GoodsUserVo;
import com.zhongzheng.modules.goods.vo.GoodsVo;
import com.zhongzheng.modules.order.vo.OrderGoodsVo;
import com.zhongzheng.modules.user.bo.UserExamRecordQueryBo;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import com.zhongzheng.modules.user.service.IUserExamRecordService;
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 org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 题库题目Controller
 *
 * @author hjl
 * @date 2021-10-21
 */
@Api(value = "题库题目控制器", tags = {"题库题目管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/bank/question")
public class QuestionController extends BaseController {

    private final IQuestionService iQuestionService;

    private final IQuestionBusinessService iQuestionBusinessService;

    private final WxTokenService wxTokenService;

    private final IGoodsService iGoodsService;

    private final IUserExamRecordService iUserExamRecordService;


    /**
     * 查询商品列表
     */
    @ApiOperation("查询用户拥有题库商品")
    @GetMapping("/listGoodsUserQuestion")
    public TableDataInfo<GoodsUserQuestionVo> listGoodsUserQuestionVo(GoodsQueryBo bo) {
        startPage();
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<GoodsUserQuestionVo> list = iQuestionService.listGoodsUserQuestionVo(bo);
        for (GoodsUserQuestionVo g : list) {
            UserExamRecordQueryBo userExamRecordQueryBo = new UserExamRecordQueryBo();
            userExamRecordQueryBo.setGoodsId(g.getGoodsId());
            userExamRecordQueryBo.setUserId(loginUser.getUser().getUserId());
            Long doNum = iUserExamRecordService.selectDoNum(userExamRecordQueryBo);
            Long totalNum = iGoodsService.getQuestionNum(g.getGoodsId());
            g.setDoNum(doNum);
            g.setTotalNum(totalNum);

        }
        return getDataTable(list);
    }
}
