package com.ruoyi.web.controller.api;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mall.domain.MallExamSection;
import com.ruoyi.mall.domain.MallMemberUser;
import com.ruoyi.mall.mapper.MallMemberUserMapper;
import com.ruoyi.mall.service.*;
import com.ruoyi.web.controller.spi.CheckSensitiveWordSpi;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @ClassName 成绩分析接口
 * @Description 成绩分析接口
 * @Author LCL
 * @Date 2023/10/18
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/achievementAnalysis")
public class ApiAchievementAnalysisController {

    @Resource
    private MallMemberUserMapper memberUserMapper;

    @Resource
    private IMallMajorClassService mallMajorClassService;

    @Resource
    private IMallCareerService mallCareerService;

    @Resource
    private IMallCareerSalaryService mallCareerSalaryService;

    @Resource
    private IMallExamSectionService mallExamSectionService;

    @Resource
    private IMallConfigService mallConfigService;

    @Resource
    private IMallSchoolAcceptRecordService mallSchoolAcceptRecordService;


    /**
     * 成绩分析-联考一分一段
     *
     * @param pageNum  页码
     * @param pageSize 每页个数
     * @param years    年份
     * @return
     */
    @GetMapping("/getMajorProspect")
    public AjaxResult getMajorProspect(@RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam String years) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            MallExamSection mallExamSection = new MallExamSection();
            mallExamSection.setYears(years);
            List<MallExamSection> list = mallExamSectionService.selectMallExamSectionList(mallExamSection);
            PageInfo<MallExamSection> pageInfo = new PageInfo<>(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("成绩分析-联考一分一段异常");
        }
    }

    /**
     * 成绩分析-联考成绩分析-分数排名
     *
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/getScoreRanking")
    public AjaxResult getScoreRanking(@RequestParam Long userId) {
        try {
            return AjaxResult.success().put("data", mallExamSectionService.selectUserScoreRanking(userId));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("成绩分析-联考一分一段-分数排名异常");
        }
    }

    /**
     * 成绩分析-联考一分一段-历年同位分
     *
     * @param pageNum  页码
     * @param pageSize 每页个数
     * @param userId   用户ID
     * @return
     */
    @GetMapping("/getCalendarYeaAppositionr")
    public AjaxResult getCalendarYeaAppositionr(@RequestParam(defaultValue = "1") Integer pageNum,
                                                @RequestParam(defaultValue = "10") Integer pageSize,
                                                @RequestParam Long userId) {
        try {
            MallMemberUser memberUser = memberUserMapper.selectMallMemberUserById(userId);
            if (memberUser != null) {
                PageHelper.startPage(pageNum, pageSize);
                List<MallExamSection> list = mallExamSectionService.selectMallExamSectionClosestListBy(null, memberUser.getMajorScore());
                PageInfo<MallExamSection> pageInfo = new PageInfo<>(list);
                return AjaxResult.success().put("data", pageInfo);
            } else {
                return AjaxResult.error("用户信息异常");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("成绩分析-联考一分一段-历年同位分异常");
        }
    }

    /**
     * 成绩分析-文化成绩分析与说明
     *
     * @param mark achievement：文化成绩分析，illustrate：说明
     * @return
     */
    @GetMapping("/getAnalysisDetails")
    public AjaxResult getAnalysisDetails(@RequestParam String mark) {
        try {
            return AjaxResult.success().put("data", mallConfigService.selectMallConfigByMarK(mark));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("成绩分析-文化成绩分析与说明异常");
        }
    }

    /**
     * 成绩分析-各层次院校录取分析
     *
     * @param pageNum  页码
     * @param pageSize 每页个数
     * @param batchId  批次ID：1-艺术本科提前批，2-艺术本科A段，3-艺术本科B段，4-艺术专科
     * @return
     */
    @GetMapping("/getAllLevelsSchoolAcceptRecordList")
    public AjaxResult getAllLevelsSchoolAcceptRecordList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                         @RequestParam(defaultValue = "10") Integer pageSize,
                                                         @RequestParam Long batchId) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> mapList = mallSchoolAcceptRecordService.selectAllLevelsMallSchoolAcceptRecordList(batchId, LocalDate.now().getYear()+"");
            PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(mapList);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("成绩分析-各层次院校录取分析异常");
        }
    }

}
