|
|
|
@ -2,6 +2,7 @@ package com.luoo.user.service;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
@ -93,7 +94,6 @@ public class UserInfoService {
|
|
|
|
|
return userInfoDao.getById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
*
|
|
|
|
@ -117,7 +117,6 @@ public class UserInfoService {
|
|
|
|
|
userInfoDao.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void sendSms(String deviceId, String mobile) {
|
|
|
|
|
// 生成6位数字随机数
|
|
|
|
|
String checkcode = RandomStringUtils.randomNumeric(6);
|
|
|
|
@ -129,7 +128,7 @@ public class UserInfoService {
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
map.put("mobile", mobile);
|
|
|
|
|
map.put("checkcode", checkcode);
|
|
|
|
|
rabbitTemplate.convertAndSend("sms",map);
|
|
|
|
|
rabbitTemplate.convertAndSend("sms", map);
|
|
|
|
|
|
|
|
|
|
// 在控制台放一份(方便测试)
|
|
|
|
|
|
|
|
|
@ -173,20 +172,21 @@ public class UserInfoService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String autoLogin(String authorization, String deviceId, String deviceBrand, String ip) {
|
|
|
|
|
UserLoginDto userLoginDto=jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
if (null==userLoginDto) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfo.setLastLoginIp(ip);
|
|
|
|
|
userInfo.setLastUseDeviceId(deviceId);
|
|
|
|
|
userInfo.setLastUseDeviceBrand(deviceBrand);
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX+jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(), userLoginDto.getRoles(),userLoginDto.getAvatar());
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfo.setLastLoginIp(ip);
|
|
|
|
|
userInfo.setLastUseDeviceId(deviceId);
|
|
|
|
|
userInfo.setLastUseDeviceBrand(deviceBrand);
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(),
|
|
|
|
|
userLoginDto.getRoles(), userLoginDto.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long countByNickName(String nickName) {
|
|
|
|
@ -199,11 +199,11 @@ public class UserInfoService {
|
|
|
|
|
user = userInfo;
|
|
|
|
|
user.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
user.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
|
Date curDate = new Date();
|
|
|
|
|
user.setJoinTime(curDate);
|
|
|
|
|
user.setLastLoginTime(curDate);
|
|
|
|
|
user.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
|
user.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
|
Date curDate = new Date();
|
|
|
|
|
user.setJoinTime(curDate);
|
|
|
|
|
user.setLastLoginTime(curDate);
|
|
|
|
|
user.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
|
user.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
|
} else {
|
|
|
|
|
user.setLastUseDeviceId(userInfo.getLastUseDeviceId());
|
|
|
|
|
user.setLastUseDeviceBrand(userInfo.getLastUseDeviceBrand());
|
|
|
|
@ -211,51 +211,58 @@ public class UserInfoService {
|
|
|
|
|
}
|
|
|
|
|
user.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(user);
|
|
|
|
|
return Constants.TOKEN_PREFIX+jwtUtil.createJWT(user.getId(),user.getNickName(),Constants.TOKEN_ROLE_APP_USER,user.getAvatar());
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(user.getId(), user.getNickName(), Constants.TOKEN_ROLE_APP_USER, user.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> orderByField(List<String> idList) {
|
|
|
|
|
return userInfoDao.orderByField(idList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> cmsOrderByField(List<String> idList) {
|
|
|
|
|
return orderByField(idList).stream().map(this::updateAvatarPath).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) {
|
|
|
|
|
return userInfoDao.getSimpleUserOrderByField(idList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq) {
|
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize());
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum() - 1, queryReq.getPageSize());
|
|
|
|
|
Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest);
|
|
|
|
|
return userInfoPage.map(this::updateAvatarPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private UserInfo updateAvatarPath(UserInfo userInfo) {
|
|
|
|
|
if (null != userInfo.getAvatar()) {
|
|
|
|
|
if (null != userInfo && null != userInfo.getAvatar()) {
|
|
|
|
|
userInfo.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq, int page, int size) {
|
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
return userInfoDao.findAll(specification, pageRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Specification<UserInfo> createUserInfoSpecification(UserQueryReq queryReq) {
|
|
|
|
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getId())){
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getId())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getMobile())){
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getMobile())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile()));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getNickName())){
|
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%'+queryReq.getNickName()+'%'));
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getNickName())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%' + queryReq.getNickName() + '%'));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getBadge())){
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getBadge())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge()));
|
|
|
|
|
}
|
|
|
|
|
if(Objects.nonNull(queryReq.getStatus())){
|
|
|
|
|
if (Objects.nonNull(queryReq.getStatus())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus()));
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
@ -263,12 +270,12 @@ public class UserInfoService {
|
|
|
|
|
* predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer.
|
|
|
|
|
* class), queryReq.getOnlineStatus())); }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if(Objects.nonNull(queryReq.getCreateDateStart())){
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateStart())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
|
queryReq.getCreateDateStart()));
|
|
|
|
|
}
|
|
|
|
|
if(Objects.nonNull(queryReq.getCreateDateEnd())){
|
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateEnd())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
|
queryReq.getCreateDateEnd()));
|
|
|
|
|
}
|
|
|
|
@ -277,5 +284,8 @@ public class UserInfoService {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserInfo cmsFindById(String id) {
|
|
|
|
|
return updateAvatarPath(userInfoDao.getById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|