package org.dromara.ygpassport.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.json.JSONObject;
import com.github.yulichang.toolkit.MPJWrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.dromara.ygpassport.domain.CombatProject;
import org.dromara.ygpassport.domain.ExactiveItems;
import org.dromara.ygpassport.domain.dto.WxExtracActivitiesDto;
import org.dromara.ygpassport.domain.dto.WxStudentDto;
import org.dromara.ygpassport.domain.vo.ExactiveItemsVo;
import org.dromara.ygpassport.domain.vo.StudentListVo;
import org.dromara.ygpassport.service.IExactiveItemsService;
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/wxExtracActivities")
public class WxExtracActivitiesController extends BaseController {

    private final IStudentListService studentListService;

    private final IExactiveItemsService exactiveItemsService;

    /**
     * 查询第二课堂信息列表
     *
     * @param jsonObject json中包含一个参数：stuNo（学号）
     *
     * @return R<WxExtracActivitiesDto>
     */
    @SaIgnore
    @PostMapping("/getInfo")
    public R<WxExtracActivitiesDto> getInfo(@RequestBody JSONObject jsonObject){
        String stuNo = jsonObject.getStr("stuNo"); // 获取学号

        // 查询该学生的相关信息
        StudentListVo studentListVo = studentListService.queryByStuNo(stuNo);
        List<ExactiveItemsVo> exactiveItemsVoList = exactiveItemsService.selectJoinList(ExactiveItemsVo.class,
            MPJWrappers.<ExactiveItems>lambdaJoin()
                .selectAll(ExactiveItems.class)
                .eq(CombatProject::getStuNo, stuNo));

        // 封装信息
        WxExtracActivitiesDto wxExtracActivitiesDto = new WxExtracActivitiesDto();
        wxExtracActivitiesDto.setStudentDto(new WxStudentDto(studentListVo));
        wxExtracActivitiesDto.setExactiveItemsVoList(exactiveItemsVoList);
        wxExtracActivitiesDto.setQrCode("");

        return R.ok(wxExtracActivitiesDto);
    }
}
