package org.dromara.ygpassport.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.json.JSONObject;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.dromara.ygpassport.domain.dto.WxScoreDto;
import org.dromara.ygpassport.domain.dto.WxStudentDto;
import org.dromara.ygpassport.domain.vo.ScoreListVo;
import org.dromara.ygpassport.domain.vo.StudentListVo;
import org.dromara.ygpassport.service.IScoreListService;
import org.dromara.ygpassport.service.IStudentListService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 移动端-第一课堂-学生成绩
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/ygpassport/wxScore")
public class WxScoreController extends BaseController {

    private final IStudentListService studentListService;

    private final IScoreListService scoreListService;

    /**
     * 查询学生成绩
     *
     * @param jsonObject json中包含一个参数：stuNo（学号）
     *
     * @return R<WxScoreDto>
     */
    @SaIgnore
    @PostMapping("/getInfo")
    public R<WxScoreDto> getInfo(@RequestBody JSONObject jsonObject){
        String stuNo = jsonObject.getStr("stuNo"); // 获取学号

        // 查询该学生的相关信息
        StudentListVo studentListVo = studentListService.queryByStuNoPro(stuNo);
        // 查询该学生的成绩列表
        List<ScoreListVo> scoreList = scoreListService.queryListByStuNo(stuNo);

        // 封装学生信息
        WxScoreDto wxScore = new WxScoreDto();
        wxScore.setStudentDto(new WxStudentDto(studentListVo));
        wxScore.setScoreListVos(scoreList);
        wxScore.setQrCode("");

        return R.ok(wxScore);
    }
}
