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.WxPhysiqueTestDto;
import org.dromara.ygpassport.domain.dto.WxStudentDto;
import org.dromara.ygpassport.domain.vo.PhysiqueTestVo;
import org.dromara.ygpassport.domain.vo.StudentListVo;
import org.dromara.ygpassport.service.IPhysiqueTestService;
import org.dromara.ygpassport.service.IStudentListService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 移动端-第二课堂- 体质情况
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/ygpassport/wxPhysiqueTest")
public class WxPhysiqueTestController extends BaseController {

    private final IStudentListService studentListService;

    private final IPhysiqueTestService physiqueTestService;

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


        StudentListVo studentListVo = studentListService.queryByStuNo(stuNo);
        List<PhysiqueTestVo> physiqueTestVoList = physiqueTestService.queryListByStuNo(stuNo);

        // 封装信息
        WxPhysiqueTestDto wxPhysiqueTestDto = new WxPhysiqueTestDto();
        wxPhysiqueTestDto.setStudentDto(new WxStudentDto(studentListVo));
        wxPhysiqueTestDto.setPhysiqueTestListVo(physiqueTestVoList);

        return R.ok(wxPhysiqueTestDto);
    }
}
