package com.ruoyi.hezhi.api.kaoshi;


import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RateLimiter;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.Kd100StateEnum;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.kd100.Kd100Util;
import com.ruoyi.hezhi.domain.TbExpressKdCode;
import com.ruoyi.hezhi.domain.TbMemberAddress;
import com.ruoyi.hezhi.domain.TbStudent;
import com.ruoyi.hezhi.domain.dto.*;
import com.ruoyi.hezhi.service.*;
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @Author: LCL
 * @Date: 2024/10/08
 * @Description:通用API
 */
@Api("用户")
@RestController
@RequestMapping("/api/memberUser")
public class ApiMemberUserController extends BaseController {

    @Resource
    private RedisCache redisCache;
    @Resource
    private ITbStudentService studentService;
    @Resource
    private ITbMemberAddressService memberAddressService;
    @Resource
    private ITbMemberSignService memberSignService;
    @Resource
    private ITbMemberScoreService memberScoreService;
    @Resource
    private ITbMemberSubjectCollectService memberSubjectCollectService;
    @Resource
    private ITbExamRegistrationService examRegistrationService;
    @Resource
    private ITbSmsCodeService smsCodeService;
    @Resource
    private ITbMemberOrderService memberOrderService;
    @Resource
    private ITbExpressKdCodeService expressKdCodeService;
    @Resource
    private ITbMemberMajorService memberMajorService;
    @Resource
    private ITbTeacherAuthenticationService tbTeacherAuthenticationService;
    @Resource
    private Kd100Util kd100Util;


    /**
     * 用户详情
     *
     * @param params memberUserId 用户ID
     * @return success
     */
    @GetMapping("/getStudentUserInfo")
    public AjaxResult getStudentUserInfo(@RequestParam Map<String, Object> params) {
        // if (!params.containsKey("memberUserId") || StringUtils.isBlank(params.get("memberUserId").toString())) {
        //     return AjaxResult.error("缺少 memberUserId 用户ID");
        // }
        try {
            if (!params.containsKey("memberUserId") || StringUtils.isBlank(params.get("memberUserId").toString())) {
                return AjaxResult.success().put("data", null);
            }
            return AjaxResult.success().put("data", studentService.selectTbStudentByStudentId(Long.valueOf(params.get("memberUserId").toString())));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("用户详情异常");
        }
    }

    /**
     * 用户修改个人资料
     *
     * @param studentDTO 参数
     * @return 结果
     */
    @RepeatSubmit
    @RateLimiter(key = "API_updateMemberInfo", time = 5, count = 50)
    @PostMapping("/updateMemberInfo")
    public AjaxResult updateMemberInfo(@RequestBody @Validated({StudentDTO.updateMemberInfo.class}) StudentDTO studentDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return studentService.updateMemberInfo(studentDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("用户修改个人资料异常");
        }
    }

    /**
     * 地址管理列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   memberUserId 用户ID
     * @return success
     */
    @GetMapping("/getMemberAddressList")
    public AjaxResult getMemberAddressList(@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 = memberAddressService.getMemberAddressList(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return AjaxResult.success().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("地址管理列表异常");
        }
    }

    /**
     * 新增地址
     *
     * @param memberAddressDTO 参数
     * @return 结果
     */
    @RepeatSubmit
    @RateLimiter(key = "API_addMemberAddress", time = 5, count = 50)
    @PostMapping("/addMemberAddress")
    public AjaxResult addMemberAddress(@RequestBody @Validated({MemberAddressDTO.addMemberAddress.class}) MemberAddressDTO memberAddressDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return memberAddressService.userRetrievePassword(memberAddressDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("新增地址异常");
        }
    }

    /**
     * 查询地址列表
     *
     * @param tbMemberAddress 参数
     * @return 结果
     */
    @GetMapping("/addressList")
    public TableDataInfo addressList(TbMemberAddress tbMemberAddress)
    {
        startPage();
        List<TbMemberAddress> list = memberAddressService.selectTbMemberAddressList(tbMemberAddress);
        return getDataTable(list);
    }



    /**
     * 地址管理详情
     *
     * @param params memberAddressId 用户地址ID
     * @return success
     */
    @GetMapping("/getMemberAddressInfo")
    public AjaxResult getMemberAddressInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("memberAddressId") || StringUtils.isBlank(params.get("memberAddressId").toString())) {
            return AjaxResult.error("缺少 memberAddressId 地址ID");
        }
        try {
            return AjaxResult.success().put("data", memberAddressService.getMemberAddressInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("地址管理详情异常");
        }
    }

    /**
     * 修改地址
     *
     * @param memberAddressDTO 参数
     * @return 结果
     */
    @RepeatSubmit
    @RateLimiter(key = "API_updateMemberAddress", time = 5, count = 50)
        @PostMapping("/updateMemberAddress")
    public AjaxResult updateMemberAddress(@RequestBody @Validated({MemberAddressDTO.updateMemberAddress.class}) MemberAddressDTO memberAddressDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return memberAddressService.updateMemberAddress(memberAddressDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("修改地址异常");
        }
    }

    /**
     * 删除地址
     *
     * @param memberAddressDTO 参数
     * @return 结果
     */
    @RepeatSubmit
    @RateLimiter(key = "API_deleteMemberAddress", time = 5, count = 50)
    @PostMapping("/deleteMemberAddress")
    public AjaxResult deleteMemberAddress(@RequestBody @Validated({MemberAddressDTO.deleteMemberAddress.class}) MemberAddressDTO memberAddressDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return memberAddressService.deleteMemberAddress(memberAddressDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("删除地址异常");
        }
    }

    /**
     * 用户签到弹窗
     *
     * @param params memberUserId 用户ID
     * @return success
     */
    @GetMapping("/getMemberSignPopup")
    public AjaxResult getMemberSignPopup(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", memberSignService.getMemberSignPopup(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("用户签到弹窗异常");
        }
    }

    /**
     * 用户签到
     *
     * @param memberSignDTO 参数
     * @return 结果
     */
    @RepeatSubmit
    @RateLimiter(key = "API_memberSignDay", time = 5, count = 50)
    @PostMapping("/memberSignDay")
    public AjaxResult memberSignDay(@RequestBody @Validated({MemberSignDTO.memberSignDay.class}) MemberSignDTO memberSignDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return memberSignService.memberSignDay(memberSignDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("用户签到异常");
        }
    }

    /**
     * 我的积分列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   memberUserId 用户ID
     *                 incomeExpenses 收入支出（0或空-全部，1-收入，2-支出）
     * @return success
     */
    @GetMapping("/getMemberScoreList")
    public AjaxResult getMemberScoreList(@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 = memberScoreService.getMemberScoreList(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 memberUserId 用户ID
     * @return success
     */
    @GetMapping("/getMemberSign")
    public AjaxResult getMemberSign(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", memberScoreService.getMemberScore(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("用户积分异常");
        }
    }

    /**
     * 题目收藏列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   memberUserId 用户ID
     *                 subjectWarehouseClassId 题库分类ID
     *                 searchValue 搜索词
     * @return success
     */
    @GetMapping("/getMemberSubjectCollectList")
    public AjaxResult getMemberSubjectCollectList(@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 = memberSubjectCollectService.getMemberSubjectCollectList(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   memberUserId 用户ID
     *                 examStatus（1-已报名，2-待开考，3-开考中，4-已结束，5-领取证书）
     * @return success
     */
    @GetMapping("/getMemberExamList")
    public AjaxResult getMemberExamList(@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 = examRegistrationService.getMemberExamList(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   memberUserId 用户ID
     *                 examStatus（1-已报名，2-待开考，3-开考中，4-已结束，5-领取证书）
     * @return success
     */
    @GetMapping("/getMemberExamListNum")
    public AjaxResult getMemberExamListNum(@RequestParam Map<String, Object> params) {
        try {
            int numOne = 0;
            int numTwo = 0;
            int numThree = 0;
            int numFour = 0;
            int numFive = 0;

            if (params.containsKey("memberUserId") && StringUtils.isNotBlank(params.get("memberUserId").toString())) {
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("memberUserId", params.get("memberUserId").toString());

                hashMap.put("examStatus", 1);
                numOne = examRegistrationService.getMemberExamList(hashMap).size();

                hashMap.put("examStatus", 2);
                numTwo = examRegistrationService.getMemberExamList(hashMap).size();

                hashMap.put("examStatus", 3);
                numThree = examRegistrationService.getMemberExamList(hashMap).size();

                hashMap.put("examStatus", 4);
                numFour = examRegistrationService.getMemberExamList(hashMap).size();

                hashMap.put("examStatus", 5);
                numFive = examRegistrationService.getMemberExamList(hashMap).size();
            }

            HashMap<String, Object> map = new HashMap<>();
            map.put("numOne", numOne);
            map.put("numTwo", numTwo);
            map.put("numThree", numThree);
            map.put("numFour", numFour);
            map.put("numFive", numFive);

            return AjaxResult.success().put("data", map);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("我的考试列表数量异常");
        }
    }

    /**
     * 我的考试详情
     *
     * @param params examRegistrationId 报名ID
     * @return success
     */
    @GetMapping("/getMemberExamInfo")
    public AjaxResult getMemberExamInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("examRegistrationId") || StringUtils.isBlank(params.get("examRegistrationId").toString())) {
            return AjaxResult.error("缺少 examRegistrationId 报名ID");
        }
        try {
            return AjaxResult.success().put("data", examRegistrationService.getMemberExamInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("我的考试详情异常");
        }
    }

    /**
     * 短信验证码验证
     *
     * @param params phone 手机号
     *               smsCode 验证码
     *               type 类型（0-默认，1-手机号登录，2-修改个人资料，3-考试报名）
     * @return success
     */
    @GetMapping("/checkPhoneSmsCode")
    public AjaxResult checkPhoneSmsCode(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("phone") || StringUtils.isBlank(params.get("phone").toString())) {
            return AjaxResult.error("缺少 phone 手机号");
        }
        if (!params.containsKey("smsCode") || StringUtils.isBlank(params.get("smsCode").toString())) {
            return AjaxResult.error("缺少 smsCode 验证码");
        }
        if (!params.containsKey("type") || StringUtils.isBlank(params.get("type").toString())) {
            return AjaxResult.error("缺少 type 类型");
        }
        try {
            String phone = params.get("phone").toString();
            String smsCode = params.get("smsCode").toString();
            int type = Integer.parseInt(params.get("type").toString());
            return smsCodeService.checkPhoneSmsCode(phone, smsCode, type);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("短信验证码验证异常");
        }
    }

    /**
     * 我的订单列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   memberUserId 用户ID
     *                 orderType 订单类型（1-会员费，2-考试）
     * @return success
     */
    @GetMapping("/getMemberOrderList")
    public AjaxResult getMemberOrderList(@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 = memberOrderService.getMemberOrderList(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   memberUserId 用户ID
     *                 searchValue 搜索词
     * @return success
     */
    @GetMapping("/getMemberCoursewareList")
    public AjaxResult getMemberCoursewareList(@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 = examRegistrationService.getMemberCoursewareList(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   memberUserId 用户ID
     * @return success
     */
    @GetMapping("/getMemberCertificateMore")
    public AjaxResult getMemberCertificateMore(@RequestParam Map<String, Object> params) {
        try {
            return AjaxResult.success().put("data", examRegistrationService.getMemberCertificateMore(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("我的报名表、准考证、证书异常");
        }
    }

    /**
     * 填写证书收货信息
     *
     * @param postAddressDTO 参数
     * @return 结果
     */
    @RepeatSubmit
    @RateLimiter(key = "API_submitCertificateGoodsInfo", time = 5, count = 50)
    @PostMapping("/submitCertificateGoodsInfo")
    public AjaxResult submitCertificateGoodsInfo(@RequestBody @Validated({PostAddressDTO.submitCertificateGoodsInfo.class}) PostAddressDTO postAddressDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return examRegistrationService.submitCertificateGoodsInfo(postAddressDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("填写证书收货信息异常");
        }
    }

    /**
     * 查看快递信息
     *
     * @param params   memberUserId 用户ID
     *                 examRegistrationId 报名ID
     *
     * @return success
     */
    @GetMapping("/getExpressInfo")
    public AjaxResult getExpressInfo(@RequestParam Map<String, Object> params) {
        try {
            Map<String, Object> certificateMore = examRegistrationService.getMemberCertificateMore(params);
            if (certificateMore != null) {
                String shippingLogo = "https://www.ems.com.cn/img/logo-38.caaf481a.svg";
                List<Map<String, Object>> expressList = new ArrayList<>();
                String state = "";
                int certificateStatus = Integer.parseInt(certificateMore.get("certificateStatus").toString());
                if (certificateStatus == 2) {
                    // 已发货
                    // 查询快递
                    TbExpressKdCode expressKdCode = expressKdCodeService.selectTbExpressKdCodeByCode(certificateMore.get("shippingMark").toString());
                    shippingLogo = expressKdCode.getLogo();

                    String shippingMark = certificateMore.get("shippingMark").toString();
                    String shippingCode = certificateMore.get("shippingCode").toString();
                    String contactPhone = certificateMore.get("contactPhone").toString();
                    String shippingPollToken = certificateMore.get("shippingPollToken").toString();
                    // 已发货,先查redis,1个小时过期时间，因为api半小时内查多了会锁单
                    JSONObject expressJsonData = null;
                    String redisKey = "kd:" + shippingMark+shippingCode+contactPhone;
                    if (redisCache.hasKey(redisKey)) {
                        //查出缓存中的数据
                        String cachedData = redisCache.getCacheObject(redisKey);
                        if (StringUtils.isNotBlank(cachedData)) {
                            expressJsonData = JSONObject.parseObject(cachedData);
                            // 可以添加日志记录
                            logger.info("从Redis缓存获取快递数据，key: {}", redisKey);
                        }
                    }else{
                        expressJsonData = kd100Util.getExpressJsonData(shippingMark, shippingCode, contactPhone, shippingPollToken);
                        // 如果接口返回数据有效，存入Redis
                        if (expressJsonData != null && !expressJsonData.isEmpty()) {
                            //先判断失败的情况直接返回
                            Boolean result = expressJsonData.getBoolean("result");
                            if (result!=null&&!result){
                                String message = expressJsonData.getString("message");
                                return AjaxResult.error(message);
                            }
                            // 没有失败则设置缓存过期时间（1小时），根据业务需求调整
                            int expireTime = 3600; // 单位：秒
                            redisCache.setCacheObject(redisKey, expressJsonData.toJSONString(), expireTime, TimeUnit.SECONDS);
                            // 可以添加日志记录
                            logger.info("将快递数据存入Redis缓存，key: {}", redisKey);
                        }
                    }
                    JSONArray data = expressJsonData.getJSONArray("data");
                    state = expressJsonData.getString("state");

                    for (int i = 0; i < data.size(); i++) {
                        JSONObject jsonObject = data.getJSONObject(i);

                        HashMap<String, Object> map = new HashMap<>();
                        map.put("time", jsonObject.getString("time"));
                        map.put("context", jsonObject.getString("context"));
                        String statusCode = jsonObject.getString("statusCode");
                        map.put("status", Kd100StateEnum.getKd100StateEnum(statusCode).getInfo());
                        map.put("statusCode", statusCode);
                        expressList.add(map);
                    }
                }

                certificateMore.put("shippingLogo", shippingLogo);
                certificateMore.put("expressList", expressList);
                certificateMore.put("state", state);

            }
            return AjaxResult.success().put("data", certificateMore);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("我的报名表、准考证、证书异常");
        }
    }

    /**
     * 用户新增题库专业
     *
     * @param memberMajorDTO 参数
     * @return 结果
     */
    @PostMapping("/insertMemberMajor")
    public AjaxResult insertMemberMajor(@RequestBody @Validated({MemberMajorDTO.insertMemberMajor.class}) MemberMajorDTO memberMajorDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }
        try {
            return memberMajorService.insertMemberMajor(memberMajorDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("用户新增题库专业异常");
        }
    }

    /**
     * 用户新增题库专业列表
     *
     * @param params memberUserId 用户ID
     * @return success
     */
    @GetMapping("/getMemberMajorList")
    public AjaxResult getMemberMajorList(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("memberUserId") || StringUtils.isBlank(params.get("memberUserId").toString())) {
            return AjaxResult.error("请先登录");
        }
        try {
            return AjaxResult.success().put("data", memberMajorService.getMemberMajorList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("用户新增题库专业列表异常");
        }
    }

    /**
     * 提交名师认证
     * @param teacherAuthenticationDTO 参数
     * @return 结果
     */
    @RepeatSubmit
    @PostMapping("/submitTeacherAuthentication")
    public AjaxResult submitTeacherAuthentication(@RequestBody @Validated TeacherAuthenticationDTO teacherAuthenticationDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return AjaxResult.allParameterErrors(bindingResult);
        }

        int i = tbTeacherAuthenticationService.submitTeacherAuthentication(teacherAuthenticationDTO);
        return AjaxResult.toAjax(i);
    }

    //修改密码
    @Log(title = "学员", businessType = BusinessType.UPDATE)
    @PostMapping("/editPassword")
    public AjaxResult editPassword(@RequestBody TbStudent tbStudent)
    {
        if (ObjectUtil.isNull(tbStudent)||tbStudent.getStudentId()==null){
            return AjaxResult.error("请求参数异常");
        }
//        if (StringUtils.isBlank(tbStudent.getOldPassword())){
//            return AjaxResult.error("旧密码不能为空");
//        }
        if (org.apache.commons.lang3.StringUtils.isBlank(tbStudent.getPassword())){
            return AjaxResult.error("新密码不能为空");
        }
        return AjaxResult.toAjax(studentService.editPassword(tbStudent));
    }

    /**
     * 获取教师详细信息
     */
    @GetMapping(value = "/getTeacherInfo/{phone}")
    public AjaxResult getTeacherInfo(@PathVariable("phone") String phone)
    {
        return AjaxResult.success(tbTeacherAuthenticationService.selectTbTeacherAuthenticationByPhone(phone));
    }


    //查询用户是否有订单待支付
    @GetMapping("/havaOrderToPay")
    public AjaxResult havaOrderToPay(Long memberUserId){
        return examRegistrationService.havaOrderToPay(memberUserId);
    }




}
