package com.xunwang.education.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xunwang.commonutils.JwtUtils;
import com.xunwang.education.entity.TeacherCertifications;
import com.xunwang.education.feign.ImageFeign;

import com.xunwang.education.mapper.TeacherCertificationsMapper;
import com.xunwang.education.service.TeacherCertificationsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

import java.util.List;

/**
 * <p>
 * 老师认证 服务实现类
 * </p>
 *
 * @author Long
 * @since 2022-11-24
 */
@Service
public class TeacherCertificationsServiceImpl extends ServiceImpl<TeacherCertificationsMapper, TeacherCertifications> implements TeacherCertificationsService {

    /**
     * 判断老师类型：在校大学生，专职老师
     * @param uid
     * @return
     */
    @Override
    public String getTeacherType(String uid) {
        TeacherCertifications one = baseMapper.selectOne(new QueryWrapper<TeacherCertifications>().eq("uid", uid));
        String education = one.getEducation();
        if (education.contains("在读")) {
            return "学生教员";
        } else {
            return "专职教员";
        }
    }

    /**
     * 根据用户id查询姓名，学历，头像
     * @param request
     * @return
     */
    @Override
    public Map getInfos(HttpServletRequest request) {
        String uid = JwtUtils.getUIdByJwtToken(request);
        TeacherCertifications one = baseMapper.selectOne(new QueryWrapper<TeacherCertifications>().eq("uid", uid));
        String img = one.getProfilePhoto();
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("imgUrl", img);
        hashMap.put("name", one.getName());
        hashMap.put("education", one.getEducation());
        hashMap.put("sex", one.getSex());
        return hashMap;
    }

    @Override
    public List<TeacherCertifications> getTeacherDetail(String[] array) {
        return baseMapper.getTeacherDetail(array);
    }

}
