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.constant.FieldConstant;
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 com.didiglobal.logi.security.util.PWEncryptUtil;
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 int addUser(UserPO userPO) throws Exception {
userPO.setPw(PWEncryptUtil.encode(userPO.getPw()));
userPO.setAppName(logiSecurityProper.getAppName());
return userMapper.insert(userPO);
}
@Override
public int editUser(UserPO userPO) throws Exception {
userPO.setPw(PWEncryptUtil.encode(userPO.getPw()));
return userMapper.updateById(userPO);
}
@Override
public IPage selectPageByUserIdList(UserQueryDTO queryDTO,
List userIdList) {
IPage page = new Page<>(queryDTO.getPage(), queryDTO.getSize());
QueryWrapper queryWrapper = getQueryWrapperWithAppName();
queryWrapper
.eq( queryDTO.getId() != null, FieldConstant.ID, queryDTO.getId())
.like(queryDTO.getUserName() != null, FieldConstant.USER_NAME, queryDTO.getUserName())
.like(queryDTO.getRealName() != null, FieldConstant.REAL_NAME, queryDTO.getRealName())
.in(!CollectionUtils.isEmpty(userIdList), FieldConstant.ID, userIdList)
.orderByDesc(FieldConstant.CREATE_TIME);
userMapper.selectPage(page, queryWrapper);
page.setTotal(userMapper.selectCount(queryWrapper));
page.setRecords(decodePW(page.getRecords()));
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.USER_NAME, queryDTO.getUserName())
.like(!StringUtils.isEmpty(queryDTO.getRealName()), FieldConstant.REAL_NAME, queryDTO.getRealName())
.in(deptIdList != null, FieldConstant.DEPT_ID, deptIdList);
userMapper.selectPage(page, queryWrapper);
page.setRecords(decodePW(page.getRecords()));
return CopyBeanUtil.copyPage(page, UserBrief.class);
}
@Override
public User selectByUserId(Integer userId) {
if(userId == null) {return null;}
QueryWrapper queryWrapper = getQueryWrapperWithAppName();
queryWrapper.eq(FieldConstant.ID, userId);
return CopyBeanUtil.copy(decodePW(userMapper.selectOne(queryWrapper)), User.class);
}
@Override
public boolean deleteByUserId(Integer userId) {
if(userId == null) {return false;}
QueryWrapper queryWrapper = getQueryWrapperWithAppName();
queryWrapper.eq(FieldConstant.ID, userId);
return userMapper.delete(queryWrapper) > 0;
}
@Override
public List selectBriefListByUserIdList(List userIdList) {
if(CollectionUtils.isEmpty(userIdList)) {
return new ArrayList<>();
}
QueryWrapper queryWrapper = wrapBriefQuery();
queryWrapper.in("id", userIdList);
return CopyBeanUtil.copyList(decodePW(userMapper.selectList(queryWrapper)), UserBrief.class);
}
@Override
public List selectBriefListByNameAndDescOrderByCreateTime(String name) {
QueryWrapper queryWrapper = wrapBriefQuery();
queryWrapper
.like(!StringUtils.isEmpty(name), FieldConstant.USER_NAME, name)
.or()
.like(!StringUtils.isEmpty(name), FieldConstant.REAL_NAME, name)
.orderByDesc(FieldConstant.CREATE_TIME);
return CopyBeanUtil.copyList(decodePW(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(decodePW(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(decodePW(userMapper.selectList(queryWrapper)), UserBrief.class);
}
@Override
public List selectAllBriefList() {
QueryWrapper queryWrapper = wrapBriefQuery();
return CopyBeanUtil.copyList(decodePW(userMapper.selectList(queryWrapper)), UserBrief.class);
}
@Override
public List selectUserIdListByUsernameOrRealName(String name) {
QueryWrapper queryWrapper = getQueryWrapperWithAppName();
queryWrapper.select(FieldConstant.ID)
.like(!StringUtils.isEmpty(name), FieldConstant.USER_NAME, name)
.or()
.like(!StringUtils.isEmpty(name), FieldConstant.REAL_NAME, name);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy