Blame view

UserRoleServiceImpl.java 5.57 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
package com.meishu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meishu.common.exception.HttpException;
import com.meishu.dto.sms.VerifyCodeDTO;
import com.meishu.dto.userrole.AccountLoginDTO;
import com.meishu.dto.userrole.AddStudentsDTO;
import com.meishu.dto.userrole.QueryStudentsDTO;
import com.meishu.mapper.UserRoleCopy1Mapper;
import com.meishu.model.*;
import com.meishu.mapper.UserRoleMapper;
import com.meishu.service.ClassesDictService;
import com.meishu.service.ClassesUserMappingService;
import com.meishu.service.SmsCodeService;
import com.meishu.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.util.excel.ExcelUtil;
import com.meishu.vo.userrole.QueryStudentsVO;
import com.meishu.vo.userrole.UserInfoVO;
import com.meishu.vo.userrole.UserRoleVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 学生表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2021-08-16
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRoleDO> implements UserRoleService {

    @Autowired
    private SmsCodeService smsCodeService;

    @Autowired
    private ClassesDictService classesDictService;

    @Autowired
    private UserRoleCopy1Mapper userRoleCopy1Mapper;

    public IPage<QueryStudentsVO> queryStudents(QueryStudentsDTO queryStudentsDTO){
        Page pager = new Page(queryStudentsDTO.getPageNum(), queryStudentsDTO.getPageSize());
        return this.baseMapper.queryStudents(pager,queryStudentsDTO.getUserName(),queryStudentsDTO.getGrade(),queryStudentsDTO.getSession(),queryStudentsDTO.getUserStatus());
    }

    public String addStudents(UserRoleDO userRoleDO){
        userRoleDO.setUserStatus("在读");
        userRoleDO.setRoleType("学生");
        this.baseMapper.insert(userRoleDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    public String updateStudent(UserRoleDO userRoleDO){
        this.baseMapper.updateById(userRoleDO);
        return ConstantUtils.SUCCESS_UPDATE;
    }

    public List<QueryStudentsVO> exportStudents(QueryStudentsDTO queryStudentsDTO){
        return this.baseMapper.exportStudents(queryStudentsDTO.getUserName(),queryStudentsDTO.getGrade(),queryStudentsDTO.getSession(),queryStudentsDTO.getUserStatus());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public UserRoleVO login(VerifyCodeDTO verifyCodeDTO) {
        UserRoleVO userRoleVO = new UserRoleVO();
        UserRoleDO userRoleDO = this.baseMapper.selectOne(new QueryWrapper<UserRoleDO>()
                .lambda()
                .eq(UserRoleDO::getPhone, verifyCodeDTO.getPhone()));
        if(userRoleDO == null) {
            throw new HttpException(10010);
        }
        BeanUtils.copyProperties(userRoleDO, userRoleVO);

        SmsCodeDO smsCodeDO = smsCodeService.getOne(new QueryWrapper<SmsCodeDO>()
                .lambda()
                .eq(SmsCodeDO::getTelephone, verifyCodeDTO.getPhone())
                .eq(SmsCodeDO::getCode, verifyCodeDTO.getVerifyCode()));
        if(smsCodeDO == null) {
            throw new HttpException(70010);
        }

        smsCodeService.removeById(smsCodeDO.getId());
        return userRoleVO;
    }

    @Override
    public UserInfoVO userInfo(Integer id) {
        UserInfoVO userInfoVO = new UserInfoVO();
        UserRoleDO userRoleDO = this.baseMapper.selectById(id);
        if(userRoleDO != null) {
            BeanUtils.copyProperties(userRoleDO, userInfoVO);
            ClassesDictDO classesDictDO = classesDictService.getClassesById((long)id);
            if(classesDictDO != null) {
                userInfoVO.setClasses(classesDictDO.getClassName());
            }
        }
        return userInfoVO;
    }

    @Override
    public UserRoleVO accountLogin(AccountLoginDTO accountLoginDTO) {
        UserRoleVO userRoleVO = new UserRoleVO();
        UserRoleDO userRoleDO = this.baseMapper.selectOne(new QueryWrapper<UserRoleDO>()
                .lambda()
                .eq(UserRoleDO::getPassword, accountLoginDTO.getPassword())
                .eq(UserRoleDO::getIdCard, accountLoginDTO.getIdCard()));
        if(userRoleDO == null) {
            throw new HttpException(10004);
        }

        BeanUtils.copyProperties(userRoleDO, userRoleVO);
        return userRoleVO;
    }

    public void studycode(){

        List<UserRoleDO> userRoleDOS = this.baseMapper.selectList(null);

        for (UserRoleDO userRoleDO : userRoleDOS){

            try {

                List<UserRoleCopy1DO> userRoleCopy1DO = userRoleCopy1Mapper.selectList(new QueryWrapper<UserRoleCopy1DO>()
                .lambda()
                .eq(UserRoleCopy1DO::getUserName,userRoleDO.getUserName())
                .eq(UserRoleCopy1DO::getGender,userRoleDO.getGender())
                .eq(UserRoleCopy1DO::getSession,userRoleDO.getSession()));

                if (userRoleCopy1DO.size()>0){
                    userRoleDO.setStudyCode(userRoleCopy1DO.get(0).getStudyCode());
                    this.baseMapper.updateById(userRoleDO);
                }
            }catch (Exception e){
                System.out.println("==========="+userRoleDO.getId()+"==="+userRoleDO.getUserName());
            }


        }


    }

}