package com.ruoyi.hezhi.api.kaoshi;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.RateLimiter;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.hezhi.domain.TbConferenceNotice;
import com.ruoyi.hezhi.domain.TbContinuingEducationClass;
import com.ruoyi.hezhi.domain.dto.DelHistoricalRecordsDTO;
import com.ruoyi.hezhi.domain.dto.MemberDiscussDTO;
import com.ruoyi.hezhi.domain.dto.MemberJoinDTO;
import com.ruoyi.hezhi.domain.vo.CareerExamListVO;
import com.ruoyi.hezhi.domain.vo.CourseListVO;
import com.ruoyi.hezhi.domain.vo.NoticeVO;
import com.ruoyi.hezhi.domain.vo.StudyCenterVO;
import com.ruoyi.hezhi.service.*;
import com.ruoyi.hezhi.service.impl.TbCourseServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author: LCL
 * @Date: 2024/10/08
 * @Description:通用API
 */
@Api("PC")
@RestController
@RequestMapping("/api/pc")
public class ApiPCController {

    @Resource
    private ITbNoticeService noticeService;
    @Resource
    private ITbTeacherService teacherService;
    @Resource
    private ITbExamNoticeService examNoticeService;
    @Resource
    private ITbCooperatePartnerService cooperatePartnerService;
    @Resource
    private ITbAuthorizeHonorService authorizeHonorService;
    @Resource
    private ITbMajorClassService majorClassService;
    @Resource
    private ITbLiveBroadcastService liveBroadcastService;
    @Resource
    private ITbStudyCenterService studyCenterService;
    @Resource
    private ITbEvaluateAgencyService evaluateAgencyService;
    @Resource
    private ITbContinuingEducationClassService continuingEducationClassService;
    @Resource
    private ITbConferenceNoticeService conferenceNoticeService;
    @Resource
    private ITbConferencePeopleService conferencePeopleService;
    @Resource
    private ITbConferenceRegistrationService conferenceRegistrationService;
    @Resource
    private ITbExamService examService;
    @Resource
    private ITbMemberJoinService memberJoinService;
    @Resource
    private ITbMemberDiscussService memberDiscussService;
    @Resource
    private ITbContinuingEducationClassService tbContinuingEducationClassService;
    @Resource
    private TbCourseServiceImpl tbCourseService;


    /**
     * 查询公告列表
     *
     * @return 结果
     */
    @GetMapping("/selectNoticeList")
    public AjaxResult selectNoticeList() {
        List<NoticeVO> list = noticeService.getNoticeList();
        return AjaxResult.success(list);
    }

    /**
     * 公告列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   type 通知类型（0-通知公告，1-专题专栏，2-政策解读，3-媒体聚焦，4-教育评论）
     *                 typeTwo 根据type二级类型（type=1：1-专题专栏1,2-专题专栏2,3-专题专栏3）
     *                 publisherType 0-总部学习中心通知，1-地方学习中心通知
     *                 searchValue 搜索词
     * @return success
     */
    @GetMapping("/getNoticeList")
    public AjaxResult getNoticeList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                    @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                    @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = noticeService.getPCNoticeList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("公告列表异常");
        }
    }

    /**
     * 公告详情
     *
     * @param params noticeId 公告ID
     * @return ok
     */
    @GetMapping("/getNoticeInfo")
    public AjaxResult getNoticeInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("noticeId") || StringUtils.isBlank(params.get("noticeId").toString())) {
            return AjaxResult.error("缺少 noticeId 公告ID");
        }
        try {
            // 浏览量+1
            noticeService.addViewsNum(Long.parseLong(params.get("noticeId").toString()));
            return AjaxResult.success().put("data", noticeService.getNoticeInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("公告详情异常");
        }
    }

    /**
     * 考试通知列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @return success
     */
    @GetMapping("/getExamNoticeList")
    public AjaxResult getExamNoticeList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                        @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                        @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = examNoticeService.getExamNoticeList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("考试通知列表异常");
        }
    }

    /**
     * 考试通知详情
     *
     * @param params examNoticeId 考试通知ID
     * @return ok
     */
    @GetMapping("/getExamNoticeInfo")
    public AjaxResult getExamNoticeInfo(@RequestParam Map<String, Object> params) {
        //判断非空非null
        if (StringUtils.isNull(params.get("examNoticeId"))&&StringUtils.isNull(params.get("examId"))){
            return AjaxResult.error("缺少 examNoticeId 考试通知ID 或者 examId 考试id");
        }
      /*  if (!params.containsKey("examNoticeId") || StringUtils.isBlank(params.get("examNoticeId").toString())) {
            return AjaxResult.error("缺少 examNoticeId 考试通知ID");
        }*/
        try {
            return AjaxResult.success().put("data", examNoticeService.getExamNoticeInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 合作伙伴列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @return success
     */
    @GetMapping("/getCooperatePartnerList")
    public AjaxResult getCooperatePartnerList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                              @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                              @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = cooperatePartnerService.getCooperatePartnerList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("合作伙伴列表异常");
        }
    }

    /**
     * 授权及荣誉列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @return success
     */
    @GetMapping("/getAuthorizeHonorList")
    public AjaxResult getAuthorizeHonorList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                            @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                            @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = authorizeHonorService.getAuthorizeHonorList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("授权及荣誉列表异常");
        }
    }

    /**
     * 获取直播机构列表
     * @return 结果
     */
    @GetMapping("/getLiveBroadcastEvaluateAgencyList")
    public AjaxResult getLiveBroadcastEvaluateAgencyList(){
        List<Map<String, Object>> liveBroadcastEvaluateAgencyList = liveBroadcastService.getLiveBroadcastEvaluateAgencyList();
        return AjaxResult.success(liveBroadcastEvaluateAgencyList);
    }

    /**
     * 直播预告列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   majorId 专业ID（0或不传查全部）
     *                 teacherId 老师ID（0或不传查全部）
     *                 type 1-首页，2-更多
     *                 searchValue 搜索词
     * @return success
     */
    @GetMapping("/getLiveBroadcastList")
    public AjaxResult getLiveBroadcastList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                           @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                           @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = liveBroadcastService.getLiveBroadcastList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("直播预告列表异常");
        }
    }

    /**
     * 直播预告详情
     *
     * @param params liveBroadcastId 直播ID
     * @return ok
     */
    @GetMapping("/getLiveBroadcastInfo")
    public AjaxResult getLiveBroadcastInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("liveBroadcastId") || StringUtils.isBlank(params.get("liveBroadcastId").toString())) {
            return AjaxResult.error("缺少 liveBroadcastId 直播ID");
        }
        try {
            return AjaxResult.success().put("data", liveBroadcastService.getLiveBroadcastInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("直播预告详情异常");
        }
    }

    /**
     * 师资团队列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   searchValue 搜索词
     *                 majorId 专业ID
     * @return success
     */
    @GetMapping("/getTeacherList")
    public AjaxResult getTeacherList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                     @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = teacherService.getTeacherList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("师资团队列表异常");
        }
    }

    /**
     * 学习中心列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   searchValue 搜索词
     *                 isRecommend 推荐（0或不传-正常，1-推荐）
     *                 studyCenterClassId 学习中心分类ID（0或不传查全部）
     * @return success
     */
    @GetMapping("/getStudyCenterList")
    public AjaxResult getStudyCenterList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                         @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = studyCenterService.getStudyCenterList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("学习中心列表异常");
        }
    }

    /**
     * 学习中心详情
     *
     * @param params studyCenterId 学习中心ID
     * @return success
     */
    @GetMapping("/getStudyCenterInfo")
    public AjaxResult getStudyCenterInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("studyCenterId") || StringUtils.isBlank(params.get("studyCenterId").toString())) {
            return AjaxResult.error("缺少 studyCenterId 学习中心ID");
        }
        try {
            return AjaxResult.success().put("data", studyCenterService.getStudyCenterInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("学习中心详情异常");
        }
    }

    /**
     * 获取有推荐课程的评价机构列表
     *
     * @return 结果
     */
    @GetMapping("/getEvaluateAgencyListHasCourse")
    public AjaxResult getEvaluateAgencyListHasCourse(@RequestParam Map<String, Object> params) {
        List<Map<String, Object>> evaluateAgencyListHasCourse = evaluateAgencyService.getEvaluateAgencyListHasCourse(params);
        return AjaxResult.success(evaluateAgencyListHasCourse);
    }

    /**
     * 获取学习中心 机构列表
     *
     * @return 结果
     */
    @GetMapping("/getContinuingEducationClassList")
    public AjaxResult getContinuingEducationClassList() {
        List<TbContinuingEducationClass> allContinuingEducationClassList = tbContinuingEducationClassService.getAllContinuingEducationClassList();
        return AjaxResult.success(allContinuingEducationClassList);
    }

    /**
     * 获取学习中心 继续教育分类
     *
     * @param studyCenterId 学习中心ID
     * @return 结果
     */
    @GetMapping("/getStudyCenterEvaluateAgencyList")
    public AjaxResult getStudyCenterEvaluateAgencyList(Long studyCenterId) {
        List<Map<String, Object>> studyCenterEvaluateAgencyList = studyCenterService.getStudyCenterEvaluateAgencyList(studyCenterId);
        return AjaxResult.success(studyCenterEvaluateAgencyList);
    }

    /**
     * 获取学习中心 课程列表
     *
     * @param studyCenterId 学习中心ID
     * @return 结果
     */
    @GetMapping("/getStudyCenterCourseList")
    public AjaxResult getStudyCenterCourseList(@RequestParam(defaultValue = "1") Integer pageNum,
                                               @RequestParam(defaultValue = "10") Integer pageSize,
                                               Long studyCenterId,
                                               Long evaluateAgencyId) {
        PageInfo<Map<String, Object>> studyCenterEvaluateAgencyList = studyCenterService.getStudyCenterCourseList(pageNum, pageSize, studyCenterId, evaluateAgencyId);
        return AjaxResult.success(studyCenterEvaluateAgencyList);
    }

    /**
     * 评价机构列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   searchValue 搜索词
     *                 evaluateAgencyClassId 评价机构分类ID（0或不传查全部）
     * @return success
     */
    @GetMapping("/getEvaluateAgencyList")
    public AjaxResult getEvaluateAgencyList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                            @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                            @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = evaluateAgencyService.getEvaluateAgencyList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("评价机构列表异常");
        }
    }

    /**
     * 评价机构详情
     *
     * @param params evaluateAgencyId 评价机构ID
     * @return ok
     */
    @GetMapping("/getEvaluateAgencyInfo")
    public AjaxResult getEvaluateAgencyInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("evaluateAgencyId") || StringUtils.isBlank(params.get("evaluateAgencyId").toString())) {
            return AjaxResult.error("缺少 evaluateAgencyId 评价机构ID");
        }
        try {
            return AjaxResult.success().put("data", evaluateAgencyService.getEvaluateAgencyInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("评价机构详情异常");
        }
    }

    /**
     * 专业课程列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   searchValue 搜索词
     *                 majorId 专业分类ID（0或不传查全部）
     *                 careerId 职业分类ID（0或不传查全部）
     *                 isRecommend 推荐（0或不传查全部，1-推荐）
     * @return success
     */
    @GetMapping("/getMajorCourseList")
    public AjaxResult getMajorCourseList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                         @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = majorClassService.getMajorCourseList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业课程列表异常");
        }
    }

    /**
     * 获取机构专业分类
     *
     * @param evaluateAgencyId 机构ID
     * @return 结果
     */
    @GetMapping("/getEvaluateAgencyMajorClass")
    public AjaxResult getEvaluateAgencyMajorClass(Long evaluateAgencyId) {
        List<Map<String, Object>> evaluateAgencyMajorClass = majorClassService.getEvaluateAgencyMajorClass(evaluateAgencyId);
        return AjaxResult.success(evaluateAgencyMajorClass);
    }

    /**
     * 专业课程详情
     *
     * @param params courseId 课程ID
     * @return ok
     */
    @GetMapping("/getMajorCourseInfo")
    public AjaxResult getMajorCourseInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("courseId") || StringUtils.isBlank(params.get("courseId").toString())) {
            return AjaxResult.error("缺少 courseId 课程ID");
        }
        try {
            return AjaxResult.success().put("data", majorClassService.getMajorCourseInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业课程详情异常");
        }
    }

    /**
     * 专业课程视频列表
     *
     * @param params courseId 课程ID
     * @return ok
     */
    @GetMapping("/getMajorCourseVideoList")
    public AjaxResult getMajorCourseVideoList(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("courseId") || StringUtils.isBlank(params.get("courseId").toString())) {
            return AjaxResult.error("缺少 courseId 课程ID");
        }
        try {
            return AjaxResult.success().put("data", majorClassService.getMajorCourseVideoList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("专业课程视频列表异常");
        }
    }

    /**
     * 继续教育列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   searchValue 搜索词
     *                 continuingEducationClassId 继续教育分类ID（0或不传查全部）
     *                 isRecommend 推荐（0或不传查全部，1-推荐）
     * @return success
     */
    @GetMapping("/getContinuingEducationList")
    public AjaxResult getContinuingEducationList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                                 @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                                 @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = continuingEducationClassService.getContinuingEducationList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("继续教育列表异常");
        }
    }

    /**
     * 课程师资列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   searchValue 搜索词
     *                 majorId 专业分类ID（0或不传查全部）
     *                 teacherId 老师ID（0或不传查全部）
     * @return success
     */
    @GetMapping("/getCourseTeacherList")
    public AjaxResult getCourseTeacherList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                           @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                           @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = majorClassService.getCourseTeacherList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("课程师资列表异常");
        }
    }

    /**
     * 老师详情
     *
     * @param params teacherId 老师ID
     * @return ok
     */
    @GetMapping("/getTeacherInfo")
    public AjaxResult getTeacherInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("teacherId") || StringUtils.isBlank(params.get("teacherId").toString())) {
            return AjaxResult.error("缺少 teacherId 老师ID");
        }
        try {
            return AjaxResult.success().put("data", teacherService.getTeacherInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("老师详情异常");
        }
    }

    /**
     * 数字教育大会通知列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   searchValue 搜索词
     *                 type 类型（0或不传查全部，1-公告，2-新媒体报道，3-会议，-3-往期会议）
     * @return success
     */
    @GetMapping("/getConferenceNoticeList")
    public AjaxResult getConferenceNoticeList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                              @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                              @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = conferenceNoticeService.getCourseTeacherList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("数字教育大会通知列表异常");
        }
    }

    /**
     * 数字教育大会通知详情
     *
     * @param params conferenceNoticeId 数字教育大会通知ID
     * @return ok
     */
    @GetMapping("/getConferenceNoticeInfo")
    public AjaxResult getConferenceNoticeInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("conferenceNoticeId") || StringUtils.isBlank(params.get("conferenceNoticeId").toString())) {
            return AjaxResult.error("缺少 conferenceNoticeId 数字教育大会通知ID");
        }
        try {
            return AjaxResult.success().put("data", conferenceNoticeService.getConferenceNoticeInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("数字教育大会通知详情异常");
        }
    }

    /**
     * 参会嘉宾列表
     *
     * @param params
     * @return success
     */
    @GetMapping("/getConferencePeopleList")
    public AjaxResult getConferencePeopleList(@RequestParam Map<String, Object> params) {
        try {
            TbConferenceNotice conferenceNotice = conferenceNoticeService.selectTbConferenceNoticeByNew();
            if (conferenceNotice != null) {
                params.put("conferenceNoticeId", conferenceNotice.getConferenceNoticeId());
            } else {
                params.put("conferenceNoticeId", 0);
            }
            List<Map<String, Object>> list = conferencePeopleService.getConferencePeopleList(params);
            return AjaxResult.success().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("参会嘉宾列表异常");
        }
    }

    /**
     * 参会报名详情
     *
     * @param params memberUserId 用户ID
     * @return ok
     */
    @GetMapping("/getConferenceRegistrationInfo")
    public AjaxResult getConferenceRegistrationInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("memberUserId") || StringUtils.isBlank(params.get("memberUserId").toString())) {
            return AjaxResult.error("请先登录");
        }
        try {
            return AjaxResult.success().put("data", conferenceRegistrationService.getConferenceRegistrationInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("参会报名详情异常");
        }
    }

    /**
     * 职业考试列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   careerId 职业ID
     *                 majorId 专业ID
     *                 searchValue 搜索词
     * @return success
     */
    @GetMapping("/getCareerExamList")
    public AjaxResult getCareerExamList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                        @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                        @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<CareerExamListVO> list = examService.getCareerExamList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("职业考试列表异常");
        }
    }

    /**
     * 根据机构id查询课程列表
     *
     * @param evaluateAgencyId 机构id
     * @return success
     */
    @GetMapping("/getCourseListByEvaluateAgency")
        public AjaxResult getCourseListByEvaluateAgency(@RequestParam(required = false) Long evaluateAgencyId) {
        if (null == evaluateAgencyId){
            return AjaxResult.success().put("data", new ArrayList<>());
        }
        List<CourseListVO> list = examService.getCourseListByEvaluateAgency(evaluateAgencyId);
        return AjaxResult.success().put("data", list);
    }

    /**
     * 根据课程id查询学习中心
     *
     * @param courseId 课程id
     * @return success
     */
    @GetMapping("/getStudyListByCourse")
    public AjaxResult getStudyListByCourse(@RequestParam(required = false) Long courseId) {
        if (null == courseId){
            return AjaxResult.success().put("data", new ArrayList<>());
        }
        List<StudyCenterVO> list = examService.getStudyListByCourse(courseId);
        return AjaxResult.success().put("data", list);
    }


    /**
     * 职业考试详情
     *
     * @param params examId 考试ID
     * @return ok
     */
    @GetMapping("/getCareerExamInfo")
    public AjaxResult getCareerExamInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("examId") || StringUtils.isBlank(params.get("examId").toString())) {
            return AjaxResult.error("缺少 examId 考试ID");
        }
        try {
            return AjaxResult.success().put("data", examService.getCareerExamInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("职业考试详情异常");
        }
    }

    /**
     * 立即参加
     *
     * @param memberJoinDTO
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_joinNow", time = 5, count = 50)
    @PostMapping("/joinNow")
    public AjaxResult joinNow(@RequestBody @Validated({MemberJoinDTO.joinNow.class}) MemberJoinDTO memberJoinDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return memberJoinService.joinNow(memberJoinDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("立即参加异常");
        }
    }

    /**
     * 用户讨论列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   liveBroadcastId 直播ID
     *                 sort (0-从新到老，1-从老到新)
     *                 searchValue 搜索词
     * @return success
     */
    @GetMapping("/getMemberDiscussList")
    public AjaxResult getMemberDiscussList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                           @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                           @RequestParam Map<String, Object> params) {
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> list = memberDiscussService.getMemberDiscussList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("用户讨论列表异常");
        }
    }

    /**
     * 发布讨论信息
     *
     * @param memberDiscussDTO
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_releaseMemberDiscuss", time = 5, count = 50)
    @PostMapping("/releaseMemberDiscuss")
    public AjaxResult releaseMemberDiscuss(@RequestBody @Validated({MemberDiscussDTO.releaseMemberDiscuss.class}) MemberDiscussDTO memberDiscussDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return memberDiscussService.releaseMemberDiscuss(memberDiscussDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发布讨论信息异常");
        }
    }

    /**
     * 根据课程类型获取机构列表
     *
     * @param classType 1-职业考试，2-职业技能
     * @return 结果
     */
    @GetMapping("/getEvaluateAgencyListByClassType")
    public AjaxResult getEvaluateAgencyListByClassType(Integer classType) {
        List<Map<String, Object>> evaluateAgencyListByClassType = evaluateAgencyService.getEvaluateAgencyListByClassType(classType);
        return AjaxResult.success(evaluateAgencyListByClassType);
    }

    /**
     * 获取课程名称列表
     * @param pageNum 页码
     * @param pageSize 每页展示数量
     * @param searchValue 搜索值
     * @return 结果
     */
    @GetMapping("/getCourseNameListForInput")
    public AjaxResult getCourseNameListForInput(@RequestParam(defaultValue = "1") Integer pageNum,
                                                @RequestParam(defaultValue = "10") Integer pageSize,
                                                @RequestParam(required = false) String searchValue,
                                                @RequestParam(required = false) Long memberUserId) {
        PageInfo<Map<String, Object>> courseNameListForInput = tbCourseService.getCourseNameListForInput(pageNum, pageSize, searchValue,memberUserId);
        return AjaxResult.success(courseNameListForInput);
    }


    /**
     * 热搜
     * @return 结果
     */
    @GetMapping("/getHotSearch")
    public AjaxResult getHotSearch(@RequestParam(required = false) Integer size) {
        List<String> hotSearch = tbCourseService.getHotSearch(size);
        return AjaxResult.success(hotSearch);
    }


    /**
     * 搜索历史记录
     * @param memberUserId 用户id
     * @param size 数量
     * @return 结果
     */
    @GetMapping("/getHistoricalRecords")
    public AjaxResult getHistoricalRecords(@RequestParam Long memberUserId,@RequestParam(required = false) Integer size) {
        List<String> historicalRecords = tbCourseService.getHistoricalRecords(memberUserId,size);
        return AjaxResult.success(historicalRecords);
    }


    /**
     * 删除历史记录
     * @return 结果
     */
    @PostMapping("/delHistoricalRecords")
    public AjaxResult delHistoricalRecords(@RequestBody DelHistoricalRecordsDTO dto) {
        return AjaxResult.toAjax(tbCourseService.delHistoricalRecords(dto));
    }

    //根据经纬度搜索最近的学习中心
    @GetMapping("/getNearbyStudyCenter")
    public AjaxResult getNearbyStudyCenter(@RequestParam(required = false) String latitude,
                                           @RequestParam(required = false) String longitude) {
        StudyCenterVO nearbyStudyCenter = studyCenterService.getNearbyStudyCenter(latitude, longitude);

        return AjaxResult.success(nearbyStudyCenter);
    }

}
