|
|
|
@@ -2,7 +2,6 @@ package com.gxwebsoft.common.system.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.DesensitizedUtil;
|
|
|
|
import cn.hutool.core.util.DesensitizedUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
@@ -12,10 +11,7 @@ import com.gxwebsoft.common.core.utils.CommonUtil;
|
|
|
|
import com.gxwebsoft.common.core.utils.RedisUtil;
|
|
|
|
import com.gxwebsoft.common.core.utils.RedisUtil;
|
|
|
|
import com.gxwebsoft.common.core.web.PageParam;
|
|
|
|
import com.gxwebsoft.common.core.web.PageParam;
|
|
|
|
import com.gxwebsoft.common.core.web.PageResult;
|
|
|
|
import com.gxwebsoft.common.core.web.PageResult;
|
|
|
|
import com.gxwebsoft.common.system.entity.Company;
|
|
|
|
import com.gxwebsoft.common.system.entity.*;
|
|
|
|
import com.gxwebsoft.common.system.entity.Role;
|
|
|
|
|
|
|
|
import com.gxwebsoft.common.system.entity.User;
|
|
|
|
|
|
|
|
import com.gxwebsoft.common.system.entity.UserRole;
|
|
|
|
|
|
|
|
import com.gxwebsoft.common.system.mapper.UserMapper;
|
|
|
|
import com.gxwebsoft.common.system.mapper.UserMapper;
|
|
|
|
import com.gxwebsoft.common.system.param.UserParam;
|
|
|
|
import com.gxwebsoft.common.system.param.UserParam;
|
|
|
|
import com.gxwebsoft.common.system.service.*;
|
|
|
|
import com.gxwebsoft.common.system.service.*;
|
|
|
|
@@ -27,12 +23,9 @@ import org.springframework.transaction.annotation.Isolation;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import static com.gxwebsoft.common.core.constants.PlatformConstants.MP_WEIXIN;
|
|
|
|
|
|
|
|
import static com.gxwebsoft.common.core.constants.PlatformConstants.WEB;
|
|
|
|
import static com.gxwebsoft.common.core.constants.PlatformConstants.WEB;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@@ -43,51 +36,53 @@ import static com.gxwebsoft.common.core.constants.PlatformConstants.WEB;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private UserRoleService userRoleService;
|
|
|
|
private UserRoleService userRoleService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private RoleService roleService;
|
|
|
|
private RoleService roleService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private RoleMenuService roleMenuService;
|
|
|
|
private RoleMenuService roleMenuService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private BCryptPasswordEncoder bCryptPasswordEncoder;
|
|
|
|
private BCryptPasswordEncoder bCryptPasswordEncoder;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private UserService userService;
|
|
|
|
private UserService userService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private CompanyService companyService;
|
|
|
|
private CompanyService companyService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private RedisUtil redisUtil;
|
|
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private OrganizationService organizationService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public PageResult<User> pageRel(UserParam param) {
|
|
|
|
public PageResult<User> pageRel(UserParam param) {
|
|
|
|
PageParam<User, UserParam> page = new PageParam<>(param);
|
|
|
|
PageParam<User, UserParam> page = new PageParam<>(param);
|
|
|
|
page.setDefaultOrder("create_time desc");
|
|
|
|
page.setDefaultOrder("create_time desc");
|
|
|
|
List<User> list = baseMapper.selectPageRel(page, param);
|
|
|
|
List<User> list = baseMapper.selectPageRel(page, param);
|
|
|
|
// 查询用户的角色
|
|
|
|
// 查询用户的角色
|
|
|
|
selectUserRoles(list);
|
|
|
|
selectUserRoles(list);
|
|
|
|
return new PageResult<>(list, page.getTotal());
|
|
|
|
return new PageResult<>(list, page.getTotal());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<User> listRel(UserParam param) {
|
|
|
|
public List<User> listRel(UserParam param) {
|
|
|
|
List<User> list = baseMapper.selectListRel(param);
|
|
|
|
List<User> list = baseMapper.selectListRel(param);
|
|
|
|
// 查询用户的角色
|
|
|
|
// 查询用户的角色
|
|
|
|
selectUserRoles(list);
|
|
|
|
selectUserRoles(list);
|
|
|
|
// 排序
|
|
|
|
// 排序
|
|
|
|
PageParam<User, UserParam> page = new PageParam<>(param);
|
|
|
|
PageParam<User, UserParam> page = new PageParam<>(param);
|
|
|
|
page.setDefaultOrder("create_time desc");
|
|
|
|
page.setDefaultOrder("create_time desc");
|
|
|
|
return page.sortRecords(list);
|
|
|
|
return page.sortRecords(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public User getByIdRel(Integer userId) {
|
|
|
|
public User getByIdRel(Integer userId) {
|
|
|
|
UserParam param = new UserParam();
|
|
|
|
UserParam param = new UserParam();
|
|
|
|
param.setUserId(userId);
|
|
|
|
param.setUserId(userId);
|
|
|
|
User user = param.getOne(baseMapper.selectListRel(param));
|
|
|
|
User user = param.getOne(baseMapper.selectListRel(param));
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
user.setPassword(null);
|
|
|
|
user.setPassword(null);
|
|
|
|
user.setRoles(userRoleService.listByUserId(user.getUserId()));
|
|
|
|
user.setRoles(userRoleService.listByUserId(user.getUserId()));
|
|
|
|
user.setAuthorities(roleMenuService.listMenuByUserId(user.getUserId(), null));
|
|
|
|
user.setAuthorities(roleMenuService.listMenuByUserId(user.getUserId(), null));
|
|
|
|
// // 系统配置信息
|
|
|
|
// // 系统配置信息
|
|
|
|
// Map<String, Object> map = new HashMap<>();
|
|
|
|
// Map<String, Object> map = new HashMap<>();
|
|
|
|
// // 1)云存储
|
|
|
|
// // 1)云存储
|
|
|
|
@@ -100,196 +95,219 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
// map.put("fileUrl",object.getString("fileUrl") + "/");
|
|
|
|
// map.put("fileUrl",object.getString("fileUrl") + "/");
|
|
|
|
// user.setSystem(map);
|
|
|
|
// user.setSystem(map);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// 企业信息
|
|
|
|
// 企业信息
|
|
|
|
// final Company company = companyService.getByTenantIdRel(user.getTenantId());
|
|
|
|
// final Company company = companyService.getByTenantIdRel(user.getTenantId());
|
|
|
|
// if (company != null) {
|
|
|
|
// if (company != null) {
|
|
|
|
// user.setCompanyId(company.getCompanyId());
|
|
|
|
// user.setCompanyId(company.getCompanyId());
|
|
|
|
// user.setCompanyInfo(company);
|
|
|
|
// user.setCompanyInfo(company);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return user;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public User getByUsername(String username) {
|
|
|
|
public User getByUsername(String username) {
|
|
|
|
return getByUsername(username, null);
|
|
|
|
return getByUsername(username, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public User getByUsername(String username, Integer tenantId) {
|
|
|
|
|
|
|
|
if (StrUtil.isBlank(username)) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
User user = baseMapper.selectByUsername(username, tenantId);
|
|
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
|
|
|
user.setRoles(userRoleService.listByUserId(user.getUserId()));
|
|
|
|
|
|
|
|
user.setAuthorities(roleMenuService.listMenuByUserId(user.getUserId(), null));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return user;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
|
|
|
public User getByUsername(String username, Integer tenantId) {
|
|
|
|
return getByUsername(username);
|
|
|
|
if (StrUtil.isBlank(username)) {
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
|
|
|
User user = baseMapper.selectByUsername(username, tenantId);
|
|
|
|
@Override
|
|
|
|
if (user != null) {
|
|
|
|
public boolean saveUser(User user) {
|
|
|
|
user.setRoles(userRoleService.listByUserId(user.getUserId()));
|
|
|
|
if (StrUtil.isNotEmpty(user.getUsername()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
user.setAuthorities(roleMenuService.listMenuByUserId(user.getUserId(), null));
|
|
|
|
.eq(User::getUsername, user.getUsername())) > 0) {
|
|
|
|
}
|
|
|
|
throw new BusinessException("账号已存在");
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StrUtil.isNotEmpty(user.getPhone()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getPhone, user.getPhone())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("手机号已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(user.getEmail()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getEmail, user.getEmail())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("邮箱已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean result = baseMapper.insert(user) > 0;
|
|
|
|
|
|
|
|
if (result && user.getRoles() != null && user.getRoles().size() > 0) {
|
|
|
|
|
|
|
|
List<Integer> roleIds = user.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (userRoleService.saveBatch(user.getUserId(), roleIds) < roleIds.size()) {
|
|
|
|
|
|
|
|
throw new BusinessException("用户角色添加失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
|
|
|
public boolean updateUser(User user) {
|
|
|
|
return getByUsername(username);
|
|
|
|
if (StrUtil.isNotEmpty(user.getUsername()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getUsername, user.getUsername())
|
|
|
|
|
|
|
|
.ne(User::getUserId, user.getUserId())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("账号已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StrUtil.isNotEmpty(user.getPhone()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getPhone, user.getPhone())
|
|
|
|
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
|
|
|
.ne(User::getUserId, user.getUserId())) > 0) {
|
|
|
|
@Override
|
|
|
|
throw new BusinessException("手机号已存在");
|
|
|
|
public boolean saveUser(User user) {
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(user.getUsername()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getUsername, user.getUsername())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("账号已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(user.getPhone()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getPhone, user.getPhone())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("手机号已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(user.getEmail()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getEmail, user.getEmail())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("邮箱已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean result = baseMapper.insert(user) > 0;
|
|
|
|
|
|
|
|
if (result && user.getRoles() != null && user.getRoles().size() > 0) {
|
|
|
|
|
|
|
|
List<Integer> roleIds = user.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (userRoleService.saveBatch(user.getUserId(), roleIds) < roleIds.size()) {
|
|
|
|
|
|
|
|
throw new BusinessException("用户角色添加失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StrUtil.isNotEmpty(user.getEmail()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getEmail, user.getEmail())
|
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
|
.ne(User::getUserId, user.getUserId())) > 0) {
|
|
|
|
@Override
|
|
|
|
throw new BusinessException("邮箱已存在");
|
|
|
|
public boolean updateUser(User user) {
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(user.getUsername()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getUsername, user.getUsername())
|
|
|
|
|
|
|
|
.ne(User::getUserId, user.getUserId())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("账号已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(user.getPhone()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getPhone, user.getPhone())
|
|
|
|
|
|
|
|
.ne(User::getUserId, user.getUserId())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("手机号已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(user.getEmail()) && baseMapper.selectCount(new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getEmail, user.getEmail())
|
|
|
|
|
|
|
|
.ne(User::getUserId, user.getUserId())) > 0) {
|
|
|
|
|
|
|
|
throw new BusinessException("邮箱已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新用户等级
|
|
|
|
|
|
|
|
if (user.getGradeId() != null && !user.getGradeId().equals(0)) {
|
|
|
|
|
|
|
|
userService.updateById(user);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean result = baseMapper.updateById(user) > 0;
|
|
|
|
|
|
|
|
if (result && user.getRoles() != null && user.getRoles().size() > 0) {
|
|
|
|
|
|
|
|
userRoleService.remove(new LambdaUpdateWrapper<UserRole>().eq(UserRole::getUserId, user.getUserId()));
|
|
|
|
|
|
|
|
List<Integer> roleIds = user.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (userRoleService.saveBatch(user.getUserId(), roleIds) < roleIds.size()) {
|
|
|
|
|
|
|
|
throw new BusinessException("用户角色添加失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 更新用户等级
|
|
|
|
|
|
|
|
if (user.getGradeId() != null && !user.getGradeId().equals(0)){
|
|
|
|
@Override
|
|
|
|
userService.updateById(user);
|
|
|
|
public boolean comparePassword(String dbPassword, String inputPassword) {
|
|
|
|
|
|
|
|
return bCryptPasswordEncoder.matches(inputPassword, dbPassword);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean result = baseMapper.updateById(user) > 0;
|
|
|
|
|
|
|
|
if (result && user.getRoles() != null && user.getRoles().size() > 0) {
|
|
|
|
@Override
|
|
|
|
userRoleService.remove(new LambdaUpdateWrapper<UserRole>().eq(UserRole::getUserId, user.getUserId()));
|
|
|
|
public String encodePassword(String password) {
|
|
|
|
List<Integer> roleIds = user.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList());
|
|
|
|
return password == null ? null : bCryptPasswordEncoder.encode(password);
|
|
|
|
if (userRoleService.saveBatch(user.getUserId(), roleIds) < roleIds.size()) {
|
|
|
|
|
|
|
|
throw new BusinessException("用户角色添加失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean comparePassword(String dbPassword, String inputPassword) {
|
|
|
|
public User getByPhone(String phone) {
|
|
|
|
return bCryptPasswordEncoder.matches(inputPassword, dbPassword);
|
|
|
|
return getOne(
|
|
|
|
}
|
|
|
|
new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.eq(User::getPhone, phone)
|
|
|
|
|
|
|
|
.orderByDesc(User::getUserId).last("limit 1")
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String encodePassword(String password) {
|
|
|
|
public User getByUnionId(UserParam param) {
|
|
|
|
return password == null ? null : bCryptPasswordEncoder.encode(password);
|
|
|
|
return param.getOne(baseMapper.getOne(param));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public User getByPhone(String phone) {
|
|
|
|
public User getByOauthId(UserParam userParam) {
|
|
|
|
return getOne(
|
|
|
|
return userParam.getOne(baseMapper.getOne(userParam));
|
|
|
|
new LambdaQueryWrapper<User>()
|
|
|
|
}
|
|
|
|
.eq(User::getPhone, phone)
|
|
|
|
|
|
|
|
.orderByDesc(User::getUserId).last("limit 1")
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public User getByUnionId(UserParam param) {
|
|
|
|
public List<User> listStatisticsRel(UserParam param) {
|
|
|
|
return param.getOne(baseMapper.getOne(param));
|
|
|
|
List<User> list = baseMapper.selectListStatisticsRel(param);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
/**
|
|
|
|
public User getByOauthId(UserParam userParam) {
|
|
|
|
* 更新用户信息(跨租户)
|
|
|
|
return userParam.getOne(baseMapper.getOne(userParam));
|
|
|
|
*
|
|
|
|
}
|
|
|
|
* @param user 用户信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<User> listStatisticsRel(UserParam param) {
|
|
|
|
public void updateByUserId(User user) {
|
|
|
|
List<User> list = baseMapper.selectListStatisticsRel(param);
|
|
|
|
baseMapper.updateByUserId(user);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 更新用户信息(跨租户)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param user 用户信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void updateByUserId(User user) {
|
|
|
|
|
|
|
|
baseMapper.updateByUserId(user);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public User addUser(UserParam userParam) {
|
|
|
|
public User addUser(UserParam userParam) {
|
|
|
|
User addUser = new User();
|
|
|
|
User addUser = new User();
|
|
|
|
// 注册用户
|
|
|
|
// 注册用户
|
|
|
|
addUser.setStatus(0);
|
|
|
|
addUser.setStatus(0);
|
|
|
|
addUser.setUsername(userParam.getPhone());
|
|
|
|
addUser.setUsername(userParam.getPhone());
|
|
|
|
addUser.setNickname(DesensitizedUtil.mobilePhone(userParam.getPhone()));
|
|
|
|
addUser.setNickname(DesensitizedUtil.mobilePhone(userParam.getPhone()));
|
|
|
|
addUser.setPlatform(WEB);
|
|
|
|
addUser.setPlatform(WEB);
|
|
|
|
addUser.setGradeId(2);
|
|
|
|
addUser.setGradeId(2);
|
|
|
|
if(userParam.getGradeId() != null){
|
|
|
|
if (userParam.getGradeId() != null) {
|
|
|
|
addUser.setGradeId(userParam.getGradeId());
|
|
|
|
addUser.setGradeId(userParam.getGradeId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(userParam.getPhone() != null){
|
|
|
|
if (userParam.getPhone() != null) {
|
|
|
|
addUser.setPhone(userParam.getPhone());
|
|
|
|
addUser.setPhone(userParam.getPhone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(userParam.getPassword() != null){
|
|
|
|
if (userParam.getPassword() != null) {
|
|
|
|
addUser.setPassword(encodePassword(userParam.getPassword()));
|
|
|
|
addUser.setPassword(encodePassword(userParam.getPassword()));
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
addUser.setPassword(encodePassword(CommonUtil.randomUUID16()));
|
|
|
|
addUser.setPassword(encodePassword(CommonUtil.randomUUID16()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addUser.setTenantId(userParam.getTenantId());
|
|
|
|
addUser.setTenantId(userParam.getTenantId());
|
|
|
|
addUser.setRecommend(0);
|
|
|
|
addUser.setRecommend(0);
|
|
|
|
Role role = roleService.getOne(new QueryWrapper<Role>().eq("role_code", "user"), false);
|
|
|
|
Role role = roleService.getOne(new QueryWrapper<Role>().eq("role_code", "user"), false);
|
|
|
|
addUser.setRoleId(role.getRoleId());
|
|
|
|
addUser.setRoleId(role.getRoleId());
|
|
|
|
if (saveUser(addUser)) {
|
|
|
|
if (saveUser(addUser)) {
|
|
|
|
// 添加用户角色
|
|
|
|
// 添加用户角色
|
|
|
|
final UserRole userRole = new UserRole();
|
|
|
|
final UserRole userRole = new UserRole();
|
|
|
|
userRole.setUserId(addUser.getUserId());
|
|
|
|
userRole.setUserId(addUser.getUserId());
|
|
|
|
userRole.setTenantId(addUser.getTenantId());
|
|
|
|
userRole.setTenantId(addUser.getTenantId());
|
|
|
|
userRole.setRoleId(addUser.getRoleId());
|
|
|
|
userRole.setRoleId(addUser.getRoleId());
|
|
|
|
userRoleService.save(userRole);
|
|
|
|
userRoleService.save(userRole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return addUser;
|
|
|
|
return addUser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public User getAdminByPhone(String phone) {
|
|
|
|
public User getAdminByPhone(String phone) {
|
|
|
|
return baseMapper.selectAdminByPhone(phone);
|
|
|
|
return baseMapper.selectAdminByPhone(phone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 批量查询用户的角色
|
|
|
|
* 批量查询用户的角色
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param users 用户集合
|
|
|
|
* @param users 用户集合
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void selectUserRoles(List<User> users) {
|
|
|
|
private void selectUserRoles(List<User> users) {
|
|
|
|
if (users != null && users.size() > 0) {
|
|
|
|
if (users != null && users.size() > 0) {
|
|
|
|
List<Integer> userIds = users.stream().map(User::getUserId).collect(Collectors.toList());
|
|
|
|
List<Integer> userIds = users.stream().map(User::getUserId).collect(Collectors.toList());
|
|
|
|
List<Role> userRoles = userRoleService.listByUserIds(userIds);
|
|
|
|
List<Role> userRoles = userRoleService.listByUserIds(userIds);
|
|
|
|
for (User user : users) {
|
|
|
|
for (User user : users) {
|
|
|
|
List<Role> roles = userRoles.stream().filter(d -> user.getUserId().equals(d.getUserId()))
|
|
|
|
List<Role> roles = userRoles.stream().filter(d -> user.getUserId().equals(d.getUserId()))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
user.setRoles(roles);
|
|
|
|
user.setRoles(roles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Integer userNumInPark(UserParam param) {
|
|
|
|
|
|
|
|
List<Organization> organizationList = organizationService.list(
|
|
|
|
|
|
|
|
new LambdaQueryWrapper<Organization>()
|
|
|
|
|
|
|
|
.eq(Organization::getPark, param.getPark())
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (organizationList != null && !organizationList.isEmpty()) {
|
|
|
|
|
|
|
|
return count(
|
|
|
|
|
|
|
|
new LambdaQueryWrapper<User>()
|
|
|
|
|
|
|
|
.in(User::getOrganizationId, organizationList.stream().map(Organization::getOrganizationId).collect(Collectors.toList()))
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Integer orgNumInPark(UserParam param) {
|
|
|
|
|
|
|
|
return organizationService.count(
|
|
|
|
|
|
|
|
new LambdaQueryWrapper<Organization>()
|
|
|
|
|
|
|
|
.eq(Organization::getPark, param.getPark())
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|