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.MallMajorRanking;
import com.ruoyi.mall.mapper.MallMemberUserMapper;
import com.ruoyi.mall.service.*;
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.util.List;
import java.util.Map;

/**
 * @ClassName 专业榜单接口
 * @Description 专业榜单接口
 * @Author LCL
 * @Date 2023/10/18
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/majorRanking")
public class ApiMajorRankingController {
    @Resource
    private IMallMajorRankingService mallMajorRankingService;


    /**
     * 专业榜单-列表
     *
     * @param pageNum  页码
     * @param pageSize 每页个数
     * @param type     类型：0-排行榜，1-专业强校，2-省份强校，3-非正常研究
     * @return
     */
    @GetMapping("/getMajorRankingList")
    public AjaxResult getMajorRankingList(@RequestParam(defaultValue = "1") Integer pageNum,
                                          @RequestParam(defaultValue = "10") Integer pageSize,
                                          @RequestParam String type) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> mapList = mallMajorRankingService.selectMajorRankingList(type);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(mapList);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业榜单-列表异常");
        }
    }

    /**
     * 专业榜单-榜单院校列表
     *
     * @param pageNum   页码
     * @param pageSize  每页个数
     * @param rankingId 榜单ID
     * @return
     */
    @GetMapping("/getMajorRankingSchoolList")
    public AjaxResult getMajorRankingSchoolList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                @RequestParam(defaultValue = "10") Integer pageSize,
                                                @RequestParam Long rankingId) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> mapList = mallMajorRankingService.selectMajorRankingSchoolList(rankingId);
            mallMajorRankingService.updateMallMajorRankingViewNumByRankingId(rankingId);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(mapList);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业榜单-榜单院校列表异常");
        }
    }

}
