|
|
|
@ -9,6 +9,7 @@ import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -25,7 +26,7 @@ import util.IdWorker;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
|
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
|
import com.luoo.user.pojo.Admin;
|
|
|
|
|
import com.luoo.user.dto.UserQueryReq;
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
import com.luoo.user.util.NickNameUtil;
|
|
|
|
|
|
|
|
|
@ -82,31 +83,6 @@ public class UserInfoService {
|
|
|
|
|
return userInfoDao.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 条件查询+分页
|
|
|
|
|
*
|
|
|
|
|
* @param whereMap
|
|
|
|
|
* @param page
|
|
|
|
|
* @param size
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Page<UserInfo> findSearch(Map whereMap, int page, int size) {
|
|
|
|
|
Specification<UserInfo> specification = createSpecification(whereMap);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
return userInfoDao.findAll(specification, pageRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 条件查询
|
|
|
|
|
*
|
|
|
|
|
* @param whereMap
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<UserInfo> findSearch(Map whereMap) {
|
|
|
|
|
Specification<UserInfo> specification = createSpecification(whereMap);
|
|
|
|
|
return userInfoDao.findAll(specification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询实体
|
|
|
|
|
*
|
|
|
|
@ -141,76 +117,6 @@ public class UserInfoService {
|
|
|
|
|
userInfoDao.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 动态条件构建
|
|
|
|
|
*
|
|
|
|
|
* @param searchMap
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Specification<UserInfo> createSpecification(Map searchMap) {
|
|
|
|
|
|
|
|
|
|
return new Specification<UserInfo>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Predicate toPredicate(Root<UserInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
|
// ID
|
|
|
|
|
if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) {
|
|
|
|
|
predicateList
|
|
|
|
|
.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 手机号码
|
|
|
|
|
if (searchMap.get("mobile") != null && !"".equals(searchMap.get("mobile"))) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
cb.like(root.get("mobile").as(String.class), "%" + (String) searchMap.get("mobile") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 用户名
|
|
|
|
|
if (searchMap.get("loginname") != null && !"".equals(searchMap.get("loginname"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("loginname").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("loginname") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 密码
|
|
|
|
|
if (searchMap.get("password") != null && !"".equals(searchMap.get("password"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("password").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("password") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 昵称
|
|
|
|
|
if (searchMap.get("nickname") != null && !"".equals(searchMap.get("nickname"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("nickname").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("nickname") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 性别
|
|
|
|
|
if (searchMap.get("sex") != null && !"".equals(searchMap.get("sex"))) {
|
|
|
|
|
predicateList
|
|
|
|
|
.add(cb.like(root.get("sex").as(String.class), "%" + (String) searchMap.get("sex") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 头像
|
|
|
|
|
if (searchMap.get("avatar") != null && !"".equals(searchMap.get("avatar"))) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
cb.like(root.get("avatar").as(String.class), "%" + (String) searchMap.get("avatar") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// E-Mail
|
|
|
|
|
if (searchMap.get("email") != null && !"".equals(searchMap.get("email"))) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
cb.like(root.get("email").as(String.class), "%" + (String) searchMap.get("email") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 兴趣
|
|
|
|
|
if (searchMap.get("interest") != null && !"".equals(searchMap.get("interest"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("interest").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("interest") + "%"));
|
|
|
|
|
}
|
|
|
|
|
// 个性
|
|
|
|
|
if (searchMap.get("personality") != null && !"".equals(searchMap.get("personality"))) {
|
|
|
|
|
predicateList.add(cb.like(root.get("personality").as(String.class),
|
|
|
|
|
"%" + (String) searchMap.get("personality") + "%"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void sendSms(String deviceId, String mobile) {
|
|
|
|
|
// 生成6位数字随机数
|
|
|
|
@ -315,4 +221,61 @@ public class UserInfoService {
|
|
|
|
|
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());
|
|
|
|
|
Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest);
|
|
|
|
|
return userInfoPage.map(this::updateAvatarPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserInfo updateAvatarPath(UserInfo userInfo) {
|
|
|
|
|
if (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())){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
|
|
|
|
|
}
|
|
|
|
|
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.getBadge())){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge()));
|
|
|
|
|
}
|
|
|
|
|
if(Objects.nonNull(queryReq.getStatus())){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus()));
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* if(Objects.nonNull(queryReq.getOnlineStatus())){
|
|
|
|
|
* predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer.
|
|
|
|
|
* class), queryReq.getOnlineStatus())); }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if(Objects.nonNull(queryReq.getCreateDateStart())){
|
|
|
|
|
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
|
queryReq.getCreateDateStart()));
|
|
|
|
|
}
|
|
|
|
|
if(Objects.nonNull(queryReq.getCreateDateEnd())){
|
|
|
|
|
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
|
queryReq.getCreateDateEnd()));
|
|
|
|
|
}
|
|
|
|
|
Predicate[] predicates = new Predicate[predicateList.size()];
|
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(predicates));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|