|  |  |  | 
|---|
|  |  |  | package com.dy.sso.busi; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoBa.BaPrivilegeMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoBa.BaCaptchaMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoBa.BaUserMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaUser; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class SsoSv { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private BaUserMapper baUserMapper; | 
|---|
|  |  |  | private BaPrivilegeMapper baPrivilegeMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setBaUserMapper(BaUserMapper baUserMapper){ | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setBaPrivilegeMapper(BaPrivilegeMapper baPrivilegeMapper){ | 
|---|
|  |  |  | this.baPrivilegeMapper = baPrivilegeMapper ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private BaCaptchaMapper baCaptchaMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 需要BaUserMapper.xml | 
|---|
|  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | @Cacheable(cacheNames=CacheConstants.cacheNames, key="'" + CacheConstants.loginUserKeyPrefix + "' + #uuid", sync=true) | 
|---|
|  |  |  | public BaUser loginWithMapperXml(String uuid, String phone, String password){ | 
|---|
|  |  |  | BaUser baUser = this.baUserMapper.login(phone, password) ; | 
|---|
|  |  |  | if(baUser !=  null  && baUser.id != null){ | 
|---|
|  |  |  | baUser.privileges = this.baPrivilegeMapper.selectPrivilegeByUserId(baUser.id) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return baUser; | 
|---|
|  |  |  | return this.baUserMapper.login(phone, password) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq("deleted", 0) | 
|---|
|  |  |  | .eq("phone", phone) | 
|---|
|  |  |  | .eq("password", password); | 
|---|
|  |  |  | BaUser baUser = this.baUserMapper.selectOne(qw) ; | 
|---|
|  |  |  | if(baUser !=  null  && baUser.id != null){ | 
|---|
|  |  |  | baUser.privileges = this.baPrivilegeMapper.selectPrivilegeByUserId(baUser.id) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return baUser; | 
|---|
|  |  |  | return this.baUserMapper.selectOne(qw) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @CacheEvict(cacheNames=CacheConstants.cacheNames, key="'" + CacheConstants.loginUserKeyPrefix + "' + #uuid") | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Cacheable(cacheNames=CacheConstants.cacheNames, key="'" + CacheConstants.loginUserKeyPrefix + "' + #uuid") | 
|---|
|  |  |  | public BaUser getByUuid(String uuid){ | 
|---|
|  |  |  | //此方法目的是直接从缓存中读取,如果缓存无此值,说明数据被清楚了,返回null值,需要重新登录 | 
|---|
|  |  |  | //此方法目的是直接从缓存中读取,如果缓存无此值,说明数据被清除了,返回null值,需要重新登录 | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 判断手机号是否存在 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public boolean existPhone(String phone){ | 
|---|
|  |  |  | Long count = baUserMapper.countPhone(phone) ; | 
|---|
|  |  |  | if(count == null || count == 0){ | 
|---|
|  |  |  | return false ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到所有用户手机号 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<String> getPhones(){ | 
|---|
|  |  |  | return baUserMapper.getPhones() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 依据验证码token获取验证字符 | 
|---|
|  |  |  | * @param token | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Map getCodeByToken(String token) { | 
|---|
|  |  |  | return baCaptchaMapper.getCodeByToken(token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|