Blame view

StudentServiceImpl.java 5.84 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
package com.meishu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meishu.common.exception.HttpException;
import com.meishu.dto.course.GetExercisesByTreeDTO;
import com.meishu.dto.student.*;
import com.meishu.dto.subject.BatchStatusOprDTO;
import com.meishu.mapper.*;
import com.meishu.model.*;
import com.meishu.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.util.MathUtil;
import com.meishu.util.RandomUtil;
import com.meishu.util.SMSUtils;
import com.meishu.vo.course.*;
import com.meishu.vo.grade.DimensionStarVO;
import com.meishu.vo.grade.QueryOneGradeVO;
import com.meishu.vo.rule.GetOneExaminationDetailVO;
import com.meishu.vo.rule.GetStudentRulesVO;
import com.meishu.vo.rule.StudentStarVO;
import com.meishu.vo.student.*;
import com.meishu.vo.voddict.GetCourseTreesVodsVO;
import net.sf.json.JSONArray;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 白名单 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2021-04-25
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, StudentDO> implements StudentService {

    @Autowired
    private SmsCodeMapper smsCodeMapper;


    public String sendMsg(StudentDO studentDO) {

        //验证是否是白名单用户
        Integer count = this.baseMapper.selectCount(new QueryWrapper<StudentDO>()
                .lambda()
                .eq(StudentDO::getTelephone, studentDO.getTelephone()));

        StudentDO studentDO1 = this.baseMapper.getStudentInfo(studentDO.getTelephone());

        if (count == 0 && null == studentDO1) {
            throw new HttpException(10010);
        }

        String verifyCode = RandomUtil.getRandomCode(6);
        String param = "{ \"code\":\"" + verifyCode + "\"}";

        //插入短信验证码
        smsCodeMapper.delete(new QueryWrapper<SmsCodeDO>()
                .lambda()
                .eq(SmsCodeDO::getTelephone, studentDO.getTelephone()));

        SmsCodeDO smsCodeDO = new SmsCodeDO();
        smsCodeDO.setTelephone(studentDO.getTelephone());
        smsCodeDO.setCode(verifyCode);
        smsCodeMapper.insert(smsCodeDO);
        return SMSUtils.sendVerifySMS(ConstantUtils.TEMPLATE_CODE, smsCodeDO.getTelephone(), param);
    }

    public LoginVO login(SmsCodeDO smsCodeDO) {

        LoginVO loginVO = new LoginVO();

        Integer count = smsCodeMapper.selectCount(new QueryWrapper<SmsCodeDO>()
                .lambda()
                .eq(SmsCodeDO::getTelephone, smsCodeDO.getTelephone())
                .eq(SmsCodeDO::getCode, smsCodeDO.getCode())
                .gt(SmsCodeDO::getCreateDate, LocalDateTime.now().minusMinutes(10L))
        );

        //提交小程序,验证专用
        if ("15666666666".equals(smsCodeDO.getTelephone())) {
            count = 1;
        }

        if (count > 0) {
            StudentDO studentDO = this.baseMapper.selectOne(new QueryWrapper<StudentDO>()
                    .lambda()
                    .eq(StudentDO::getTelephone, smsCodeDO.getTelephone()));
            if (smsCodeDO == null) {
                throw new HttpException(10013);
            }
            //该手机号是学生账号
            if (null != studentDO) {
                BeanUtils.copyProperties(studentDO, loginVO);

                loginVO.setIsStudent("1");
            } else {
                StudentDO studentDO2 = this.baseMapper.getStudentInfo(smsCodeDO.getTelephone());
                loginVO.setUsername(studentDO2.getUsername());
                List<SubjectReportVO> subjectReportVOS = this.baseMapper.getSubjectReport(studentDO2.getId());
                loginVO.setSubjectReportVOS(subjectReportVOS);
                loginVO.setId(studentDO2.getId());
                loginVO.setIsStudent("0");
            }
            return loginVO;
        } else {
            throw new HttpException(10003);
        }
    }

    public String addStudent(StudentDO studentDO) {

        Integer count = this.baseMapper.selectCount(new QueryWrapper<StudentDO>()
        .lambda()
        .eq(StudentDO::getTelephone,studentDO.getTelephone()));

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

        studentDO.setStatus("1");
        this.baseMapper.insert(studentDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    public String updateStudent(StudentDO studentDO) {
        this.baseMapper.updateById(studentDO);
        return ConstantUtils.SUCCESS_UPDATE;
    }

    @Transactional(rollbackFor = Exception.class)
    public String batchUpdateStudent(BatchStatusOprDTO batchStatusOprDTO) {
        List<Long> longs = batchStatusOprDTO.getIds();
        for (Long lg : longs) {
            StudentDO studentDO = new StudentDO();
            studentDO.setStatus(batchStatusOprDTO.getStatus());
            studentDO.setId(lg);
            this.baseMapper.updateById(studentDO);
        }
        return ConstantUtils.SUCCESS_UPDATE;
    }

    public String deleteStudent(DeleteStudentDTO deleteStudentDTO) {

        List<Long> ids = deleteStudentDTO.getIds();
        for (Long id : ids) {
            this.baseMapper.deleteById(id);
        }
        return ConstantUtils.DELETE_SUCCESS;
    }

    public QueryStudentVO queryStudent(StudentDO studentDO) {
        QueryStudentVO queryStudentVO = new QueryStudentVO();
        StudentDO studentDO1 = this.baseMapper.selectById(studentDO.getId());
        BeanUtils.copyProperties(studentDO1, queryStudentVO);
        return queryStudentVO;
    }


}