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
package com.dy.sso.busi;
 
import com.dy.pipIrrGlobal.daoBa.BaUserMapper;
import com.dy.pipIrrGlobal.pojoBa.BaUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
@Slf4j
@Service
public class SsoSv {
 
    private BaUserMapper baUserMapper;
 
    @Autowired
    private void setBaUserMapper(BaUserMapper baUserMapper){
        this.baUserMapper = baUserMapper ;
    }
 
    //当未注解@Transactional时,会输出日志:SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@46727a0c] was not registered for synchronization because synchronization is not active
    //@Transactional
    @Cacheable(cacheNames=CacheConstants.cacheNames, key="'" + CacheConstants.loginUserKeyPrefix + "' + #uuid", sync=true)
    public BaUser login(String uuid, String phone, String password){
        return this.baUserMapper.login(phone, password) ;
    }
 
    @CacheEvict(cacheNames=CacheConstants.cacheNames, key="'" + CacheConstants.loginUserKeyPrefix + "' + #uuid")
    public void logout(String uuid){
    }
 
    @Cacheable(cacheNames=CacheConstants.cacheNames, key="'" + CacheConstants.loginUserKeyPrefix + "' + #uuid")
    public BaUser getByUuid(String uuid){
        //此方法目的是直接从缓存中读取,如果缓存无此值,说明数据被清楚了,返回null值,需要重新登录
        return null ;
    }
 
}