mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-22 18:29:51 +08:00
优化用户列表过滤
This commit is contained in:
@@ -15,6 +15,7 @@ import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserPaginateFilter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -38,37 +39,45 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
public PaginationResult<User> paginate(int page, int size, UserPaginateFilter filter) {
|
||||
QueryWrapper<User> wrapper = query().getWrapper().eq("1", "1");
|
||||
|
||||
if (filter != null) {
|
||||
if (filter.getEmail() != null) {
|
||||
wrapper.eq("email", filter.getEmail());
|
||||
}
|
||||
if (filter.getName() != null) {
|
||||
wrapper.eq("name", filter.getName());
|
||||
}
|
||||
if (filter.getNickname() != null) {
|
||||
wrapper.eq("nickname", filter.getNickname());
|
||||
}
|
||||
if (filter.getIdCard() != null) {
|
||||
wrapper.eq("id_card", filter.getIdCard());
|
||||
}
|
||||
if (filter.getIsActive() != null) {
|
||||
wrapper.eq("is_active", filter.getIsActive());
|
||||
}
|
||||
if (filter.getIsLock() != null) {
|
||||
wrapper.eq("is_lock", filter.getIsLock());
|
||||
}
|
||||
if (filter.getIsVerify() != null) {
|
||||
wrapper.eq("is_verify", filter.getIsVerify());
|
||||
}
|
||||
if (filter.getIsSetPassword() != null) {
|
||||
wrapper.eq("is_set_password", filter.getIsSetPassword());
|
||||
}
|
||||
if (filter.getCreatedAt() != null && filter.getCreatedAt().length == 2) {
|
||||
wrapper.between("created_at", filter.getCreatedAt()[0], filter.getCreatedAt()[1]);
|
||||
}
|
||||
if (filter.getSortField() != null && filter.getSortAlgo() != null) {
|
||||
wrapper.orderBy(true, filter.getSortAlgo().toUpperCase() == "ASC", filter.getSortField());
|
||||
if (filter.getEmail() != null) {
|
||||
wrapper.eq("email", filter.getEmail());
|
||||
}
|
||||
if (filter.getName() != null) {
|
||||
wrapper.eq("name", filter.getName());
|
||||
}
|
||||
if (filter.getNickname() != null) {
|
||||
wrapper.eq("nickname", filter.getNickname());
|
||||
}
|
||||
if (filter.getIdCard() != null) {
|
||||
wrapper.eq("id_card", filter.getIdCard());
|
||||
}
|
||||
if (filter.getIsActive() != null) {
|
||||
wrapper.eq("is_active", filter.getIsActive());
|
||||
}
|
||||
if (filter.getIsLock() != null) {
|
||||
wrapper.eq("is_lock", filter.getIsLock());
|
||||
}
|
||||
if (filter.getIsVerify() != null) {
|
||||
wrapper.eq("is_verify", filter.getIsVerify());
|
||||
}
|
||||
if (filter.getIsSetPassword() != null) {
|
||||
wrapper.eq("is_set_password", filter.getIsSetPassword());
|
||||
}
|
||||
if (filter.getCreatedAt() != null && filter.getCreatedAt().length == 2) {
|
||||
wrapper.between("created_at", filter.getCreatedAt()[0], filter.getCreatedAt()[1]);
|
||||
}
|
||||
if (filter.getDepIds() != null && filter.getDepIds().length > 0) {
|
||||
List<Integer> userIds = userDepartmentService.getUserIdsByDepIds(filter.getDepIds());
|
||||
if (userIds.size() == 0) {
|
||||
userIds.add(0);
|
||||
}
|
||||
wrapper.in("id", userIds);
|
||||
}
|
||||
|
||||
if (filter.getSortAlgo().equals("desc")) {
|
||||
wrapper.orderByDesc(filter.getSortField());
|
||||
} else {
|
||||
wrapper.orderByAsc(filter.getSortField());
|
||||
}
|
||||
|
||||
IPage<User> userPage = new Page<>(page, size);
|
||||
|
||||
@@ -6,6 +6,10 @@ import xyz.playedu.api.service.internal.UserDepartmentService;
|
||||
import xyz.playedu.api.mapper.UserDepartmentMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_department】的数据库操作Service实现
|
||||
@@ -14,6 +18,18 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class UserDepartmentServiceImpl extends ServiceImpl<UserDepartmentMapper, UserDepartment>
|
||||
implements UserDepartmentService {
|
||||
|
||||
@Override
|
||||
public List<Integer> getUserIdsByDepIds(Integer[] depIds) {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
List<UserDepartment> userDepartments = list(query().getWrapper().in("dep_id", Arrays.asList(depIds)));
|
||||
if (userDepartments.size() > 0) {
|
||||
for (UserDepartment userDepartment : userDepartments) {
|
||||
ids.add(userDepartment.getUserId());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,10 +3,13 @@ package xyz.playedu.api.service.internal;
|
||||
import xyz.playedu.api.domain.UserDepartment;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_department】的数据库操作Service
|
||||
* @createDate 2023-02-23 15:08:38
|
||||
*/
|
||||
public interface UserDepartmentService extends IService<UserDepartment> {
|
||||
List<Integer> getUserIdsByDepIds(Integer[] depIds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user