com.didiglobal.logi.security.dao.impl.UserDaoImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of logi-security-spring-boot-starter Show documentation
Show all versions of logi-security-spring-boot-starter Show documentation
logi-security 提供项目大多都需要的一些基础功能(用户、角色、权限、登录、注册、操作记录)
package com.didiglobal.logi.security.dao.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.didiglobal.logi.security.common.dto.user.UserBriefQueryDTO;
import com.didiglobal.logi.security.common.dto.user.UserQueryDTO;
import com.didiglobal.logi.security.common.entity.user.User;
import com.didiglobal.logi.security.common.entity.user.UserBrief;
import com.didiglobal.logi.security.common.po.UserPO;
import com.didiglobal.logi.security.dao.UserDao;
import com.didiglobal.logi.security.dao.mapper.UserMapper;
import com.didiglobal.logi.security.util.CopyBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author cjm
*/
@Component
public class UserDaoImpl extends BaseDaoImpl implements UserDao {
@Autowired
private UserMapper userMapper;
@Override
public IPage selectPageByDeptIdListAndUserIdList(UserQueryDTO queryDTO, List deptIdList,
List userIdList) {
IPage page = new Page<>(queryDTO.getPage(), queryDTO.getSize());
if(deptIdList != null && deptIdList.isEmpty()) {
return CopyBeanUtil.copyPage(page, User.class);
}
if(userIdList != null && userIdList.isEmpty()) {
return CopyBeanUtil.copyPage(page, User.class);
}
QueryWrapper queryWrapper = getQueryWrapper();
queryWrapper
.like(queryDTO.getUsername() != null, FieldConstant.USERNAME, queryDTO.getUsername())
.like(queryDTO.getRealName() != null, FieldConstant.REAL_NAME, queryDTO.getRealName())
.in(deptIdList != null, FieldConstant.DEPT_ID, deptIdList)
.in(userIdList != null, FieldConstant.ID, userIdList);
userMapper.selectPage(page, queryWrapper);
return CopyBeanUtil.copyPage(page, User.class);
}
@Override
public IPage selectBriefPageByDeptIdList(UserBriefQueryDTO queryDTO, List deptIdList) {
IPage page = new Page<>(queryDTO.getPage(), queryDTO.getSize());
if(deptIdList != null && deptIdList.isEmpty()) {
return CopyBeanUtil.copyPage(page, UserBrief.class);
}
QueryWrapper queryWrapper = wrapBriefQuery();
queryWrapper
.like(!StringUtils.isEmpty(queryDTO.getUsername()), FieldConstant.USERNAME, queryDTO.getUsername())
.like(!StringUtils.isEmpty(queryDTO.getRealName()), FieldConstant.REAL_NAME, queryDTO.getRealName())
.in(deptIdList != null, FieldConstant.DEPT_ID, deptIdList);
userMapper.selectPage(page, queryWrapper);
return CopyBeanUtil.copyPage(page, UserBrief.class);
}
@Override
public User selectByUserId(Integer userId) {
if(userId == null) {
return null;
}
QueryWrapper queryWrapper = getQueryWrapper();
queryWrapper.eq("id", userId);
return CopyBeanUtil.copy(userMapper.selectOne(queryWrapper), User.class);
}
@Override
public List selectBriefListByUserIdList(List userIdList) {
if(CollectionUtils.isEmpty(userIdList)) {
return new ArrayList<>();
}
QueryWrapper queryWrapper = wrapBriefQuery();
queryWrapper.in("id", userIdList);
return CopyBeanUtil.copyList(userMapper.selectList(queryWrapper), UserBrief.class);
}
@Override
public List selectBriefListByNameAndDescOrderByCreateTime(String name) {
QueryWrapper queryWrapper = wrapBriefQuery();
queryWrapper
.like(!StringUtils.isEmpty(name), FieldConstant.USERNAME, name)
.or()
.like(!StringUtils.isEmpty(name), FieldConstant.REAL_NAME, name)
.orderByDesc(FieldConstant.CREATE_TIME);
return CopyBeanUtil.copyList(userMapper.selectList(queryWrapper), UserBrief.class);
}
@Override
public List selectBriefListByDeptIdList(List deptIdList) {
if(deptIdList != null && deptIdList.isEmpty()) {
return new ArrayList<>();
}
QueryWrapper queryWrapper = wrapBriefQuery();
queryWrapper.in(deptIdList != null, FieldConstant.DEPT_ID, deptIdList);
return CopyBeanUtil.copyList(userMapper.selectList(queryWrapper), UserBrief.class);
}
@Override
public List selectBriefListOrderByCreateTime(boolean isAsc) {
QueryWrapper queryWrapper = wrapBriefQuery();
if(isAsc) {
queryWrapper.orderByAsc(FieldConstant.CREATE_TIME);
} else {
queryWrapper.orderByDesc(FieldConstant.CREATE_TIME);
}
userMapper.selectList(queryWrapper);
return CopyBeanUtil.copyList(userMapper.selectList(queryWrapper), UserBrief.class);
}
@Override
public List selectAllBriefList() {
QueryWrapper queryWrapper = wrapBriefQuery();
return CopyBeanUtil.copyList(userMapper.selectList(queryWrapper), UserBrief.class);
}
@Override
public List selectUserIdListByUsernameOrRealName(String name) {
QueryWrapper queryWrapper = getQueryWrapper();
queryWrapper.select(FieldConstant.ID)
.like(!StringUtils.isEmpty(name), FieldConstant.USERNAME, name)
.or()
.like(!StringUtils.isEmpty(name), FieldConstant.REAL_NAME, name);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy