|
@@ -25,6 +25,7 @@ import com.webchat.user.repository.dao.IGroupUserDAO;
|
|
import com.webchat.user.repository.dao.IUserDAO;
|
|
import com.webchat.user.repository.dao.IUserDAO;
|
|
import com.webchat.user.repository.entity.GroupUserEntity;
|
|
import com.webchat.user.repository.entity.GroupUserEntity;
|
|
import com.webchat.user.repository.entity.UserEntity;
|
|
import com.webchat.user.repository.entity.UserEntity;
|
|
|
|
+import jakarta.persistence.criteria.Predicate;
|
|
import jakarta.servlet.http.Cookie;
|
|
import jakarta.servlet.http.Cookie;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
@@ -35,6 +36,7 @@ import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.data.redis.core.DefaultTypedTuple;
|
|
import org.springframework.data.redis.core.DefaultTypedTuple;
|
|
import org.springframework.data.redis.core.ZSetOperations;
|
|
import org.springframework.data.redis.core.ZSetOperations;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -86,6 +88,41 @@ public class UserService {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public APIPageResponseBean<UserBaseResponseInfoVO> page(String userId, Integer roleCode, String userName, String mobile,
|
|
|
|
+ int pageNo, int pageSize) {
|
|
|
|
+
|
|
|
|
+ Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.by(Sort.Direction.DESC, "id"));
|
|
|
|
+ Specification<UserEntity> specification = createAccountQuerySpecification(userId, roleCode, userName, mobile);
|
|
|
|
+ Page<UserEntity> userEntityPage = userDAO.findAll(specification, pageable);
|
|
|
|
+ List<UserEntity> userEntities = userEntityPage.getContent();
|
|
|
|
+ List<UserBaseResponseInfoVO> userBaseVoList = new ArrayList<>();
|
|
|
|
+ if (CollectionUtils.isNotEmpty(userEntities)) {
|
|
|
|
+ userBaseVoList = userEntities.stream().map(UserService::convertBaseVo).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ return APIPageResponseBean.success(pageNo, pageSize, userEntityPage.getTotalElements(), userBaseVoList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Specification createAccountQuerySpecification(String userId, Integer roleCode, String userName, String mobile) {
|
|
|
|
+ return ((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+ if (roleCode != null) {
|
|
|
|
+ predicates.add(criteriaBuilder.equal(root.get("roleCode").as(Integer.class), roleCode));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(userId)) {
|
|
|
|
+ predicates.add(criteriaBuilder.equal(root.get("userId").as(String.class), userId));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(userName)) {
|
|
|
|
+ predicates.add(criteriaBuilder.like(root.get("userName").as(String.class), "%" + userName + "%"));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(mobile)) {
|
|
|
|
+ predicates.add(criteriaBuilder.equal(root.get("mobile").as(String.class), mobile));
|
|
|
|
+ }
|
|
|
|
+ Predicate[] pre = new Predicate[predicates.size()];
|
|
|
|
+ criteriaQuery.where(predicates.toArray(pre));
|
|
|
|
+ return criteriaQuery.getRestriction();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 用户登录 - 登录成功返回用户基本信息
|
|
* 用户登录 - 登录成功返回用户基本信息
|
|
@@ -412,7 +449,7 @@ public class UserService {
|
|
// 清理登录Session
|
|
// 清理登录Session
|
|
Cookie[] cookies = request.getCookies();
|
|
Cookie[] cookies = request.getCookies();
|
|
for(Cookie cookie : cookies) {
|
|
for(Cookie cookie : cookies) {
|
|
- if (CookieConstants.C_U_USER_COOKIE_KEY.equals(cookie.getName())) {
|
|
|
|
|
|
+ if (CookieConstants.WEB_CHAT_USER_COOKIE_KEY.equals(cookie.getName())) {
|
|
cookie.setValue(null);
|
|
cookie.setValue(null);
|
|
cookie.setMaxAge(0);
|
|
cookie.setMaxAge(0);
|
|
cookie.setPath("/");
|
|
cookie.setPath("/");
|
|
@@ -445,6 +482,7 @@ public class UserService {
|
|
userEntity.setPassword(md5Pwd(password));
|
|
userEntity.setPassword(md5Pwd(password));
|
|
userEntity.setRoleCode(RoleCodeEnum.USER.getCode());
|
|
userEntity.setRoleCode(RoleCodeEnum.USER.getCode());
|
|
userEntity.setCreateBy(userId);
|
|
userEntity.setCreateBy(userId);
|
|
|
|
+ userEntity.setSignature("暂无签名~");
|
|
// 注册用户
|
|
// 注册用户
|
|
return userDAO.save(userEntity).getUserId();
|
|
return userDAO.save(userEntity).getUserId();
|
|
}
|
|
}
|
|
@@ -712,7 +750,7 @@ public class UserService {
|
|
String sessionKey = RedisKeyEnum.USER_SESSION_PREFIX.getKey(sessionId);
|
|
String sessionKey = RedisKeyEnum.USER_SESSION_PREFIX.getKey(sessionId);
|
|
redisService.set(sessionKey, userId, RedisKeyEnum.USER_SESSION_PREFIX.getExpireTime());
|
|
redisService.set(sessionKey, userId, RedisKeyEnum.USER_SESSION_PREFIX.getExpireTime());
|
|
// 种浏览器Cookie
|
|
// 种浏览器Cookie
|
|
- Cookie cookie = new Cookie(CookieConstants.C_U_USER_COOKIE_KEY, sessionId);
|
|
|
|
|
|
+ Cookie cookie = new Cookie(CookieConstants.WEB_CHAT_USER_COOKIE_KEY, sessionId);
|
|
cookie.setPath("/");
|
|
cookie.setPath("/");
|
|
cookie.setMaxAge(CookieConstants.COOKIE_OUT_TIME);
|
|
cookie.setMaxAge(CookieConstants.COOKIE_OUT_TIME);
|
|
response.addCookie(cookie);
|
|
response.addCookie(cookie);
|
|
@@ -789,7 +827,7 @@ public class UserService {
|
|
|
|
|
|
public String getUserLoginCookie(String userId) {
|
|
public String getUserLoginCookie(String userId) {
|
|
String sessionId = MD5Utils.md5(userId);
|
|
String sessionId = MD5Utils.md5(userId);
|
|
- return CookieConstants.C_U_USER_COOKIE_KEY.concat("=").concat(sessionId);
|
|
|
|
|
|
+ return CookieConstants.WEB_CHAT_USER_COOKIE_KEY.concat("=").concat(sessionId);
|
|
}
|
|
}
|
|
|
|
|
|
public static UserBaseResponseInfoVO convertBaseVo(UserEntity entity) {
|
|
public static UserBaseResponseInfoVO convertBaseVo(UserEntity entity) {
|