Commit d3956a85 authored by minminyan's avatar minminyan

禁用用户的同时删除相应的缓存

parent 8aa4d2be
......@@ -2,7 +2,6 @@ package cn.quantgroup.xyqb.service.session;
import cn.quantgroup.xyqb.entity.Merchant;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.function.OneArgFunction;
import cn.quantgroup.xyqb.model.AuthBean;
import cn.quantgroup.xyqb.model.LoginProperties;
import cn.quantgroup.xyqb.model.session.SessionStruct;
......@@ -14,15 +13,19 @@ import cn.quantgroup.xyqb.model.session.SessionValue;
public interface ISessionService {
AuthBean createSession(Long channelId, Long createdFrom, String appChannel, User user, Merchant merchant);
AuthBean createSession(Long channelId, Long createdFrom, String appChannel, User user, Merchant merchant);
SessionStruct createSessionAndPersist(User user, LoginProperties loginProperties);
SessionStruct createSessionAndPersist(User user, LoginProperties loginProperties);
String findSessionIdByUserIdLoginProperties(Long userId, LoginProperties properties);
String findSessionIdByUserIdLoginProperties(Long userId, LoginProperties properties);
String findSessionValueBySessionId(String sessionId);
SessionStruct newSession(User user, LoginProperties properties);
void persistSession(String token, SessionValue sessionValue);
String findSessionValueBySessionId(String sessionId);
SessionStruct findSessionBySessionId(String sessionId);
SessionStruct newSession(User user, LoginProperties properties);
void persistSession(String token, SessionValue sessionValue);
SessionStruct findSessionBySessionId(String sessionId);
void deleteByUserId(long userId);
}
......@@ -24,120 +24,122 @@ import java.util.concurrent.TimeUnit;
@Service
public class UserServiceImpl implements IUserService {
@Autowired
RedisTemplate<String, String> stringRedisTemplate;
@Autowired
private ILkbUserService lkbUserService;
@Autowired
private IUserRepository userRepository;
@Autowired
private ISmsService smsService;
@Override
public User findByPhoneInDb(String phone) {
return userRepository.findByPhoneNo(phone);
@Autowired
RedisTemplate<String, String> stringRedisTemplate;
@Autowired
private ILkbUserService lkbUserService;
@Autowired
private IUserRepository userRepository;
@Autowired
private ISmsService smsService;
@Override
public User findByPhoneInDb(String phone) {
return userRepository.findByPhoneNo(phone);
}
@Override
public User findByUuidInDb(String uuid) {
return userRepository.findByUuid(uuid);
}
@Override
@CacheEvict(value = "usercache", key = "'xyqbuser' + #user.phoneNo", cacheManager = "cacheManager")
public User saveUser(User user) {
return userRepository.save(user);
}
@Override
public User findById(Long userId) {
return userRepository.findById(userId);
}
@Override
public User registerAndReturn(String phoneNo, String password, Long registerFrom) {
String uuid = lkbUserService.registerApp(phoneNo, password);
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
User user = new User();
user.setEnable(true);
user.setPhoneNo(phoneNo);
user.setUpdatedAt(currentTime);
user.setCreatedAt(currentTime);
user.setUuid(uuid);
user.setPassword(PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT));
user.setRegisteredFrom(registerFrom);
return userRepository.save(user);
}
@Override
@Cacheable(value = "usercache", key = "'xyqbuser' + #phone", unless = "#result == null", cacheManager = "cacheManager")
public User findByPhoneWithCache(String phone) {
return userRepository.findByPhoneNo(phone);
}
@Override
@Cacheable(value = "usercache", key = "'xyqbuser' + #uuid", unless = "#result == null", cacheManager = "cacheManager")
public User findByUuidWithCache(String uuid) {
return userRepository.findByUuid(uuid);
}
@Override
@Transactional(value = Transactional.TxType.REQUIRED)
public boolean register(String phoneNo, String password, Long registerFrom, String userIp, Long channelId) {
String uuid = lkbUserService.registerApp(phoneNo, password);
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
User user = new User();
user.setEnable(true);
user.setPhoneNo(phoneNo);
user.setUpdatedAt(currentTime);
user.setCreatedAt(currentTime);
user.setUuid(uuid);
user.setPassword(PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT));
//解决线上白条registerFrom为1的问题
if (channelId == 222L) {
user.setRegisteredFrom(channelId);
} else {
user.setRegisteredFrom(registerFrom);
}
@Override
public User findByUuidInDb(String uuid) {
return userRepository.findByUuid(uuid);
}
@Override
public User saveUser(User user) {
return userRepository.save(user);
//user.setRegisteredFrom(registerFrom);
user = userRepository.save(user);
smsService.sendAfterRegister(phoneNo);
return user != null;
}
@Override
public boolean exist(String phoneNo) {
return userRepository.findByPhoneNo(phoneNo) != null;
}
/**
* 修改用户密码
*
* @param phoneNo
* @param password
* @return
* @date 2017-02-15 修改用户修改密码时,更新updatedAt时间
*/
@Override
@CacheEvict(value = "usercache", key = "'xyqbuser' + #phone", cacheManager = "cacheManager")
public boolean resetPassword(String phoneNo, String password) {
User user = userRepository.findByPhoneNo(phoneNo);
if (user == null) {
throw new RuntimeException("用户[" + phoneNo + "]不存在");
}
user.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
user.setPassword(PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT));
user = userRepository.save(user);
stringRedisTemplate.expire("usercache:xyqbuser" + phoneNo, 1L, TimeUnit.MILLISECONDS);
return StringUtils.equals(PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT), user.getPassword());
@Override
public User findById(Long userId) {
return userRepository.findById(userId);
}
@Override
public User registerAndReturn(String phoneNo, String password, Long registerFrom) {
String uuid = lkbUserService.registerApp(phoneNo, password);
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
User user = new User();
user.setEnable(true);
user.setPhoneNo(phoneNo);
user.setUpdatedAt(currentTime);
user.setCreatedAt(currentTime);
user.setUuid(uuid);
user.setPassword(PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT));
user.setRegisteredFrom(registerFrom);
return userRepository.save(user);
}
@Override
@Cacheable(value = "usercache", key = "'xyqbuser' + #phone", unless = "#result == null", cacheManager = "cacheManager")
public User findByPhoneWithCache(String phone) {
return userRepository.findByPhoneNo(phone);
}
@Override
@Cacheable(value = "usercache", key = "'xyqbuser' + #uuid", unless = "#result == null", cacheManager = "cacheManager")
public User findByUuidWithCache(String uuid) {
return userRepository.findByUuid(uuid);
}
@Override
@Transactional(value = Transactional.TxType.REQUIRED)
public boolean register(String phoneNo, String password, Long registerFrom, String userIp, Long channelId) {
String uuid = lkbUserService.registerApp(phoneNo, password);
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
User user = new User();
user.setEnable(true);
user.setPhoneNo(phoneNo);
user.setUpdatedAt(currentTime);
user.setCreatedAt(currentTime);
user.setUuid(uuid);
user.setPassword(PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT));
//解决线上白条registerFrom为1的问题
if(channelId == 222L) {
user.setRegisteredFrom(channelId);
} else {
user.setRegisteredFrom(registerFrom);
}
//user.setRegisteredFrom(registerFrom);
user = userRepository.save(user);
smsService.sendAfterRegister(phoneNo);
return user != null;
}
@Override
public boolean exist(String phoneNo) {
return userRepository.findByPhoneNo(phoneNo) != null;
}
/**
* 修改用户密码
* @date 2017-02-15 修改用户修改密码时,更新updatedAt时间
* @param phoneNo
* @param password
* @return
*/
@Override
@CacheEvict(value = "usercache", key = "'xyqbuser' + #phone", cacheManager = "cacheManager")
public boolean resetPassword(String phoneNo, String password) {
User user = userRepository.findByPhoneNo(phoneNo);
if (user == null) {
throw new RuntimeException("用户[" + phoneNo + "]不存在");
}
user.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
user.setPassword(PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT));
user = userRepository.save(user);
stringRedisTemplate.expire("usercache:xyqbuser" + phoneNo, 1L, TimeUnit.MILLISECONDS);
return StringUtils.equals(PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT), user.getPassword());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment