AccessTokenServiceImpl.java 3.11 KB
package com.meishu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meishu.common.exception.HttpException;
import com.meishu.dto.token.GetAllStudentsDTO;
import com.meishu.dto.token.GetAllTeachersDTO;
import com.meishu.mapper.AdministerMapper;
import com.meishu.mapper.UuidHistoryMapper;
import com.meishu.model.AccessTokenDO;
import com.meishu.mapper.AccessTokenMapper;
import com.meishu.model.AdministerDO;
import com.meishu.model.UserRoleDO;
import com.meishu.model.UuidHistoryDO;
import com.meishu.service.AccessTokenService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.SecretUtils;
import com.meishu.vo.accesstoken.GetAllStudentsVO;
import com.meishu.vo.accesstoken.GetAllTeachersVO;
import com.meishu.vo.administer.GetTeacherSubjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2021-05-10
 */
@Service
public class AccessTokenServiceImpl extends ServiceImpl<AccessTokenMapper, AccessTokenDO> implements AccessTokenService {

    @Autowired
    private AdministerMapper administerMapper;

    @Autowired
    private UuidHistoryMapper uuidHistoryMapper;

    public List<GetAllTeachersVO> getAllTeachers(GetAllTeachersDTO getAllTeachersDTO){

        int count = uuidHistoryMapper.selectCount(new QueryWrapper<UuidHistoryDO>()
        .lambda()
        .eq(UuidHistoryDO::getUuid,getAllTeachersDTO.getUuid()));

        if (count>0){
            throw new HttpException(80001);
        }

        String uuidSec = SecretUtils.hash(getAllTeachersDTO.getUuid()+"ixihs");
        if (!uuidSec.equals(getAllTeachersDTO.getUuidSecret())){
            throw new HttpException(80002);
        }

        //查找所有老师
        List<GetAllTeachersVO> administerDOS = this.baseMapper.getAllTeachers(getAllTeachersDTO);
        administerDOS.stream().forEach(x->{
            List<GetTeacherSubjectVO> getTeacherSubjectVOS = administerMapper.getTeacherSubject(x.getId());
            x.setSubjectDictDOS(getTeacherSubjectVOS);
        });
        UuidHistoryDO uuidHistoryDO = new UuidHistoryDO();
        uuidHistoryDO.setUuid(getAllTeachersDTO.getUuid());
        uuidHistoryMapper.insert(uuidHistoryDO);
        return administerDOS;
    }

    public List<GetAllStudentsVO> getAllStudents(GetAllStudentsDTO getAllStudentsDTO){
        int count = uuidHistoryMapper.selectCount(new QueryWrapper<UuidHistoryDO>()
                .lambda()
                .eq(UuidHistoryDO::getUuid,getAllStudentsDTO.getUuid()));

        if (count>0){
            throw new HttpException(80001);
        }

        String uuidSec = SecretUtils.hash(getAllStudentsDTO.getUuid()+"ixihs");
        if (!uuidSec.equals(getAllStudentsDTO.getUuidSecret())){
            throw new HttpException(80002);
        }
        UuidHistoryDO uuidHistoryDO = new UuidHistoryDO();
        uuidHistoryDO.setUuid(getAllStudentsDTO.getUuid());
        uuidHistoryMapper.insert(uuidHistoryDO);
        return this.baseMapper.getAllStudents(getAllStudentsDTO);
    }


}