|
@@ -1,35 +1,29 @@
|
|
|
package com.jtzx.crm.module.sys.service;
|
|
package com.jtzx.crm.module.sys.service;
|
|
|
|
|
|
|
|
-import cc.uncarbon.framework.core.context.TenantContext;
|
|
|
|
|
-import cc.uncarbon.framework.core.context.TenantContextHolder;
|
|
|
|
|
import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
-import cc.uncarbon.framework.core.enums.EnabledStatusEnum;
|
|
|
|
|
import cc.uncarbon.framework.core.exception.BusinessException;
|
|
import cc.uncarbon.framework.core.exception.BusinessException;
|
|
|
-import cc.uncarbon.framework.core.page.PageParam;
|
|
|
|
|
import cc.uncarbon.framework.core.page.PageResult;
|
|
import cc.uncarbon.framework.core.page.PageResult;
|
|
|
-import cc.uncarbon.framework.core.props.HelioProperties;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+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.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.jtzx.crm.module.sys.constant.SysConstant;
|
|
|
|
|
import com.jtzx.crm.module.sys.entity.SysUserEntity;
|
|
import com.jtzx.crm.module.sys.entity.SysUserEntity;
|
|
|
import com.jtzx.crm.module.sys.enums.SysErrorEnum;
|
|
import com.jtzx.crm.module.sys.enums.SysErrorEnum;
|
|
|
-import com.jtzx.crm.module.sys.enums.SysUserStatusEnum;
|
|
|
|
|
import com.jtzx.crm.module.sys.mapper.SysUserMapper;
|
|
import com.jtzx.crm.module.sys.mapper.SysUserMapper;
|
|
|
-import com.jtzx.crm.module.sys.model.interior.UserRoleContainer;
|
|
|
|
|
-import com.jtzx.crm.module.sys.model.request.*;
|
|
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.request.AdminListSysUserDTO;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.request.InsertOrUpdateSysUserDTO;
|
|
|
|
|
+import com.jtzx.crm.module.sys.model.request.UpdateSysUserPasswordDTO;
|
|
|
import com.jtzx.crm.module.sys.model.response.SysUserBO;
|
|
import com.jtzx.crm.module.sys.model.response.SysUserBO;
|
|
|
import com.jtzx.crm.module.sys.model.response.SysUserLoginBO;
|
|
import com.jtzx.crm.module.sys.model.response.SysUserLoginBO;
|
|
|
import com.jtzx.crm.module.sys.model.response.VbenAdminUserInfoVO;
|
|
import com.jtzx.crm.module.sys.model.response.VbenAdminUserInfoVO;
|
|
|
import com.jtzx.crm.module.sys.util.PwdUtil;
|
|
import com.jtzx.crm.module.sys.util.PwdUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.lang.Nullable;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
@@ -47,58 +41,43 @@ public class SysUserService {
|
|
|
|
|
|
|
|
private final SysUserMapper sysUserMapper;
|
|
private final SysUserMapper sysUserMapper;
|
|
|
private final SysRoleService sysRoleService;
|
|
private final SysRoleService sysRoleService;
|
|
|
- private final SysMenuService sysMenuService;
|
|
|
|
|
- private final SysUserRoleRelationService sysUserRoleRelationService;
|
|
|
|
|
- private final SysRoleMenuRelationService sysRoleMenuRelationService;
|
|
|
|
|
- private final HelioProperties helioProperties;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 后台管理-分页列表
|
|
* 后台管理-分页列表
|
|
|
*/
|
|
*/
|
|
|
- public PageResult<SysUserBO> adminList(PageParam pageParam, AdminListSysUserDTO dto) {
|
|
|
|
|
- // 预处理:根据【手动选择的部门】筛选用户
|
|
|
|
|
- Set<Long> deptUserIds = Collections.emptySet();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public PageResult<SysUserBO> adminList(AdminListSysUserDTO dto) {
|
|
|
|
|
+ if (dto.getStatus() == null) {
|
|
|
|
|
+ dto.setStatus(1);
|
|
|
|
|
+ }
|
|
|
Page<SysUserEntity> entityPage = sysUserMapper.selectPage(
|
|
Page<SysUserEntity> entityPage = sysUserMapper.selectPage(
|
|
|
- new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
|
|
|
|
|
|
|
+ new Page<>(dto.getPageNum(), dto.getPageSize()),
|
|
|
new QueryWrapper<SysUserEntity>()
|
|
new QueryWrapper<SysUserEntity>()
|
|
|
.lambda()
|
|
.lambda()
|
|
|
- // 手机号
|
|
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getPhoneNo()), SysUserEntity::getPhoneNo, CharSequenceUtil.cleanBlank(dto.getPhoneNo()))
|
|
|
|
|
- // 根据【手动选择的部门ID】筛选用户
|
|
|
|
|
- .in(CollUtil.isNotEmpty(deptUserIds), SysUserEntity::getId, deptUserIds)
|
|
|
|
|
|
|
+ .eq(SysUserEntity::getStatus, dto.getStatus())
|
|
|
|
|
+ .and(
|
|
|
|
|
+ CharSequenceUtil.isNotBlank(dto.getQueryStr()),
|
|
|
|
|
+ z -> z.like(SysUserEntity::getPhoneNo, CharSequenceUtil.cleanBlank(dto.getQueryStr()))
|
|
|
|
|
+ .or(x -> x.like(SysUserEntity::getUserName, dto.getQueryStr()))
|
|
|
|
|
+ )
|
|
|
// 排序
|
|
// 排序
|
|
|
.orderByDesc(SysUserEntity::getCreatedAt)
|
|
.orderByDesc(SysUserEntity::getCreatedAt)
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
return this.entityPage2BOPage(entityPage);
|
|
return this.entityPage2BOPage(entityPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据 ID 取详情
|
|
|
|
|
- *
|
|
|
|
|
- * @param id 主键ID
|
|
|
|
|
- * @return null or BO
|
|
|
|
|
- */
|
|
|
|
|
- public SysUserBO getOneById(Long id) {
|
|
|
|
|
- return this.getOneById(id, false);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据 ID 取详情
|
|
* 根据 ID 取详情
|
|
|
*
|
|
*
|
|
|
* @param id 主键ID
|
|
* @param id 主键ID
|
|
|
- * @param throwIfInvalidId 是否在 ID 无效时抛出异常
|
|
|
|
|
* @return null or BO
|
|
* @return null or BO
|
|
|
*/
|
|
*/
|
|
|
- public SysUserBO getOneById(Long id, boolean throwIfInvalidId) throws BusinessException {
|
|
|
|
|
|
|
+ public SysUserBO getOneById(Long id) throws BusinessException {
|
|
|
|
|
|
|
|
SysUserEntity entity = sysUserMapper.selectById(id);
|
|
SysUserEntity entity = sysUserMapper.selectById(id);
|
|
|
- if (throwIfInvalidId) {
|
|
|
|
|
- SysErrorEnum.INVALID_ID.assertNotNull(entity);
|
|
|
|
|
|
|
+ if (entity == null) {
|
|
|
|
|
+ throw new BusinessException(400, "用户不存在");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- return this.entity2BO(entity, true);
|
|
|
|
|
|
|
+ return this.entity2BO(entity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -107,18 +86,18 @@ public class SysUserService {
|
|
|
* @return 主键ID
|
|
* @return 主键ID
|
|
|
*/
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void adminInsert(AdminInsertOrUpdateSysUserDTO dto) {
|
|
|
|
|
|
|
+ public void adminInsert(InsertOrUpdateSysUserDTO dto) {
|
|
|
log.info("[后台管理-新增后台用户] >> 入参={}", dto);
|
|
log.info("[后台管理-新增后台用户] >> 入参={}", dto);
|
|
|
this.checkExistence(dto);
|
|
this.checkExistence(dto);
|
|
|
dto.setId(null);
|
|
dto.setId(null);
|
|
|
SysUserEntity entity = new SysUserEntity();
|
|
SysUserEntity entity = new SysUserEntity();
|
|
|
BeanUtil.copyProperties(dto, entity);
|
|
BeanUtil.copyProperties(dto, entity);
|
|
|
-
|
|
|
|
|
|
|
+ entity.setStatus(1);
|
|
|
String salt = IdUtil.randomUUID();
|
|
String salt = IdUtil.randomUUID();
|
|
|
entity
|
|
entity
|
|
|
.setSalt(salt)
|
|
.setSalt(salt)
|
|
|
- .setPin(dto.getUsername())
|
|
|
|
|
- .setPwd(PwdUtil.encrypt(dto.getPasswordOfNewUser(), salt));
|
|
|
|
|
|
|
+ .setPin(dto.getAccount())
|
|
|
|
|
+ .setPwd(PwdUtil.encrypt(dto.getAccount(), salt));
|
|
|
|
|
|
|
|
sysUserMapper.insert(entity);
|
|
sysUserMapper.insert(entity);
|
|
|
}
|
|
}
|
|
@@ -127,15 +106,13 @@ public class SysUserService {
|
|
|
* 后台管理-编辑
|
|
* 后台管理-编辑
|
|
|
*/
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void adminUpdate(AdminInsertOrUpdateSysUserDTO dto) {
|
|
|
|
|
|
|
+ public void adminUpdate(InsertOrUpdateSysUserDTO dto) {
|
|
|
log.info("[后台管理-编辑后台用户] >> 入参={}", dto);
|
|
log.info("[后台管理-编辑后台用户] >> 入参={}", dto);
|
|
|
- preUpdateCheck(dto.getId(), dto.getStatus());
|
|
|
|
|
this.checkExistence(dto);
|
|
this.checkExistence(dto);
|
|
|
-
|
|
|
|
|
SysUserEntity entity = new SysUserEntity();
|
|
SysUserEntity entity = new SysUserEntity();
|
|
|
BeanUtil.copyProperties(dto, entity);
|
|
BeanUtil.copyProperties(dto, entity);
|
|
|
// 手动处理异名字段
|
|
// 手动处理异名字段
|
|
|
- entity.setPin(dto.getUsername());
|
|
|
|
|
|
|
+ entity.setPin(dto.getAccount());
|
|
|
sysUserMapper.updateById(entity);
|
|
sysUserMapper.updateById(entity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -163,7 +140,7 @@ public class SysUserService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (SysUserStatusEnum.BANNED == sysUserEntity.getStatus()) {
|
|
|
|
|
|
|
+ if (sysUserEntity.getStatus() == 0) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -174,23 +151,16 @@ public class SysUserService {
|
|
|
this.updateLastLoginAt(sysUserEntity.getId(), LocalDateTimeUtil.now());
|
|
this.updateLastLoginAt(sysUserEntity.getId(), LocalDateTimeUtil.now());
|
|
|
|
|
|
|
|
// 取账号完整信息
|
|
// 取账号完整信息
|
|
|
- SysUserBO sysUserBO = this.entity2BO(sysUserEntity, false);
|
|
|
|
|
|
|
+ SysUserBO sysUserBO = this.entity2BO(sysUserEntity);
|
|
|
|
|
|
|
|
Map<Long, String> roleMap = sysRoleService.getRoleMapByUserId(sysUserBO.getId());
|
|
Map<Long, String> roleMap = sysRoleService.getRoleMapByUserId(sysUserBO.getId());
|
|
|
|
|
|
|
|
-// Map<Long, Set<String>> roleIdPermissionMap = sysMenuService.getRoleIdPermissionMap(roleMap.keySet());
|
|
|
|
|
-
|
|
|
|
|
// 包装返回体;有的字段类型不一致, 单独转换
|
|
// 包装返回体;有的字段类型不一致, 单独转换
|
|
|
SysUserLoginBO ret = new SysUserLoginBO();
|
|
SysUserLoginBO ret = new SysUserLoginBO();
|
|
|
BeanUtil.copyProperties(sysUserBO, ret);
|
|
BeanUtil.copyProperties(sysUserBO, ret);
|
|
|
-
|
|
|
|
|
-// Set<String> permissions = roleIdPermissionMap.values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
|
|
|
|
|
-
|
|
|
|
|
ret
|
|
ret
|
|
|
.setRoleIds(new HashSet<>(roleMap.keySet()))
|
|
.setRoleIds(new HashSet<>(roleMap.keySet()))
|
|
|
.setRoles(new ArrayList<>(roleMap.values()));
|
|
.setRoles(new ArrayList<>(roleMap.values()));
|
|
|
-// .setPermissions(permissions)
|
|
|
|
|
-// .setRoleIdPermissionMap(roleIdPermissionMap);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
@@ -198,121 +168,98 @@ public class SysUserService {
|
|
|
/**
|
|
/**
|
|
|
* 后台管理-取当前用户信息
|
|
* 后台管理-取当前用户信息
|
|
|
*/
|
|
*/
|
|
|
- public VbenAdminUserInfoVO adminGetCurrentUserInfo() {
|
|
|
|
|
- SysUserBO sysUserBO = this.getOneById(UserContextHolder.getUserId(), true);
|
|
|
|
|
|
|
+ public VbenAdminUserInfoVO getCurrentUserInfo() {
|
|
|
|
|
+ SysUserBO sysUserBO = this.getOneById(UserContextHolder.getUserId());
|
|
|
|
|
+ if (sysUserBO == null) {
|
|
|
|
|
+ throw new BusinessException(400, "用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, String> roleMap = sysRoleService.getRoleMapByUserId(sysUserBO.getId());
|
|
|
return VbenAdminUserInfoVO.builder()
|
|
return VbenAdminUserInfoVO.builder()
|
|
|
.username(sysUserBO.getUsername())
|
|
.username(sysUserBO.getUsername())
|
|
|
- .nickname(sysUserBO.getNickname())
|
|
|
|
|
|
|
+ .account(sysUserBO.getAccount())
|
|
|
.lastLoginAt(sysUserBO.getLastLoginAt())
|
|
.lastLoginAt(sysUserBO.getLastLoginAt())
|
|
|
.gender(sysUserBO.getGender())
|
|
.gender(sysUserBO.getGender())
|
|
|
- .email(sysUserBO.getEmail())
|
|
|
|
|
.phoneNo(sysUserBO.getPhoneNo())
|
|
.phoneNo(sysUserBO.getPhoneNo())
|
|
|
.avatar(sysUserBO.getAvatarUrl())
|
|
.avatar(sysUserBO.getAvatarUrl())
|
|
|
|
|
+ .roles(new ArrayList<>(roleMap.values()))
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 后台管理-重置某用户密码
|
|
|
|
|
- */
|
|
|
|
|
- public void adminResetUserPassword(AdminResetSysUserPasswordDTO dto) {
|
|
|
|
|
- preUpdateCheck(dto.getUserId(), null);
|
|
|
|
|
- SysUserEntity sysUserEntity = sysUserMapper.selectById(dto.getUserId());
|
|
|
|
|
-
|
|
|
|
|
- SysUserEntity templateEntity = new SysUserEntity();
|
|
|
|
|
- templateEntity
|
|
|
|
|
- .setPwd(PwdUtil.encrypt(dto.getRandomPassword(), sysUserEntity.getSalt()))
|
|
|
|
|
- .setId(dto.getUserId());
|
|
|
|
|
-
|
|
|
|
|
- sysUserMapper.updateById(templateEntity);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 后台管理-修改当前用户密码
|
|
|
|
|
|
|
+ * 后台管理-修改用户密码
|
|
|
*/
|
|
*/
|
|
|
- public void adminUpdateCurrentUserPassword(AdminUpdateCurrentSysUserPasswordDTO dto) {
|
|
|
|
|
- SysUserEntity sysUserEntity = sysUserMapper.selectById(UserContextHolder.getUserId());
|
|
|
|
|
- if (sysUserEntity == null || !sysUserEntity.getPwd().equals(PwdUtil.encrypt(dto.getOldPassword(), sysUserEntity.getSalt()))) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.INCORRECT_OLD_PASSWORD);
|
|
|
|
|
|
|
+ public void UpdateUserPassword(UpdateSysUserPasswordDTO dto) {
|
|
|
|
|
+ if (StrUtil.isEmpty(dto.getNewPassword())) {
|
|
|
|
|
+ throw new BusinessException(400, "密码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ SysUserEntity sysUserEntity = sysUserMapper.selectById(dto.getUserId());
|
|
|
|
|
+ if (sysUserEntity == null) {
|
|
|
|
|
+ throw new BusinessException(400, "用户不存在");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
sysUserEntity
|
|
sysUserEntity
|
|
|
- .setPwd(PwdUtil.encrypt(dto.getConfirmNewPassword(), sysUserEntity.getSalt()))
|
|
|
|
|
- .setId(UserContextHolder.getUserId());
|
|
|
|
|
-
|
|
|
|
|
|
|
+ .setPwd(PwdUtil.encrypt(dto.getNewPassword(), sysUserEntity.getSalt()))
|
|
|
|
|
+ .setId(dto.getUserId());
|
|
|
sysUserMapper.updateById(sysUserEntity);
|
|
sysUserMapper.updateById(sysUserEntity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 后台管理-绑定用户与角色关联关系
|
|
|
|
|
|
|
+ * 启用或禁用用户状态
|
|
|
|
|
+ * @param userId
|
|
|
*/
|
|
*/
|
|
|
- public void adminBindRoles(AdminBindUserRoleRelationDTO dto) {
|
|
|
|
|
- preBindUserRoleRelationCheck(dto);
|
|
|
|
|
- sysUserRoleRelationService.cleanAndBind(dto.getUserId(), dto.getRoleIds());
|
|
|
|
|
|
|
+ public Integer updateUserStatus(Long userId) {
|
|
|
|
|
+ SysUserEntity sysUserEntity = sysUserMapper.selectById(userId);
|
|
|
|
|
+ if (sysUserEntity == null) {
|
|
|
|
|
+ throw new BusinessException(400, "用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sysUserEntity.getStatus().equals(1)) {
|
|
|
|
|
+ sysUserEntity.setStatus(0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sysUserEntity.setStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ return sysUserEntity.getStatus();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 根据用户账号查询
|
|
|
|
|
- */
|
|
|
|
|
- public SysUserEntity getUserByPin(String pin) {
|
|
|
|
|
- return sysUserMapper.getUserByPin(pin);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 后台管理 - 取指定用户关联角色ID
|
|
|
|
|
- *
|
|
|
|
|
- * @param userId 用户ID
|
|
|
|
|
- * @return 角色Ids
|
|
|
|
|
|
|
+ * 启用或禁用用户跟进状态
|
|
|
|
|
+ * @param userId
|
|
|
|
|
+ * @param followType 开关的跟进类型,公海跟进-publicFollow,历史跟进 -historyFollow
|
|
|
*/
|
|
*/
|
|
|
- public Set<Long> listRelatedRoleIds(Long userId) {
|
|
|
|
|
- if (ObjectUtil.isNull(userId)) {
|
|
|
|
|
- return Collections.emptySet();
|
|
|
|
|
|
|
+ public Integer updateUserFollow(Long userId,String followType) {
|
|
|
|
|
+ SysUserEntity sysUserEntity = sysUserMapper.selectById(userId);
|
|
|
|
|
+ if (sysUserEntity == null) {
|
|
|
|
|
+ throw new BusinessException(400, "用户不存在");
|
|
|
}
|
|
}
|
|
|
- return sysRoleService.getRoleMapByUserId(userId).keySet();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 后台管理 - 取租户用户IDs
|
|
|
|
|
- *
|
|
|
|
|
- * @param tenantId 租户ID,非主键ID
|
|
|
|
|
- * @param statusEnums 仅保留符合指定状态的,可以为null
|
|
|
|
|
- */
|
|
|
|
|
- public List<Long> listUserIdsByTenantId(Long tenantId, Collection<EnabledStatusEnum> statusEnums) {
|
|
|
|
|
- if (Objects.isNull(tenantId)) {
|
|
|
|
|
- return Collections.emptyList();
|
|
|
|
|
|
|
+ if(followType.equals("publicFollow")){
|
|
|
|
|
+ if(sysUserEntity.getPublicFollowStatus().equals(1)) {
|
|
|
|
|
+ sysUserEntity.setPublicFollowStatus(0);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ sysUserEntity.setPublicFollowStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ return sysUserEntity.getPublicFollowStatus();
|
|
|
}
|
|
}
|
|
|
- // 备份原始租户上下文;以下查询方式可同时兼容行级、数据源级多租户
|
|
|
|
|
- TenantContext originContext = TenantContextHolder.getTenantContext();
|
|
|
|
|
- try {
|
|
|
|
|
- // 临时切换租户
|
|
|
|
|
- TenantContextHolder.setTenantContext(new TenantContext(tenantId, CharSequenceUtil.EMPTY));
|
|
|
|
|
- return sysUserMapper.selectIds(statusEnums);
|
|
|
|
|
- } finally {
|
|
|
|
|
- TenantContextHolder.setTenantContext(originContext);
|
|
|
|
|
|
|
+ if(followType.equals("historyFollow")){
|
|
|
|
|
+ if(sysUserEntity.getHistoryFollowStatus().equals(1)) {
|
|
|
|
|
+ sysUserEntity.setHistoryFollowStatus(0);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ sysUserEntity.setHistoryFollowStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ return sysUserEntity.getHistoryFollowStatus();
|
|
|
}
|
|
}
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 后台管理-更新当前用户信息资料
|
|
|
|
|
- */
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public void adminUpdateCurrentUserInfo(AdminUpdateCurrentSysUserInfoDTO dto) {
|
|
|
|
|
- SysUserEntity update = SysUserEntity.of(dto);
|
|
|
|
|
- update.setId(UserContextHolder.getUserId());
|
|
|
|
|
- sysUserMapper.updateById(update);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 后台管理-更新当前用户头像
|
|
|
|
|
|
|
+ * 根据用户账号查询
|
|
|
*/
|
|
*/
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public void adminUpdateCurrentUserAvatar(AdminUpdateCurrentSysUserAvatarDTO dto) {
|
|
|
|
|
- dto.securityCheck();
|
|
|
|
|
-
|
|
|
|
|
- SysUserEntity update = SysUserEntity.of(dto);
|
|
|
|
|
- update.setId(UserContextHolder.getUserId());
|
|
|
|
|
- sysUserMapper.updateById(update);
|
|
|
|
|
|
|
+ public SysUserEntity getUserByPin(String pin) {
|
|
|
|
|
+ return sysUserMapper.getUserByPin(pin);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
----------------------------------------------------------------
|
|
----------------------------------------------------------------
|
|
|
私有方法 private methods
|
|
私有方法 private methods
|
|
@@ -323,19 +270,18 @@ public class SysUserService {
|
|
|
* 实体转 BO
|
|
* 实体转 BO
|
|
|
*
|
|
*
|
|
|
* @param entity 实体
|
|
* @param entity 实体
|
|
|
- * @param fillDeptInfo 是否根据实体部门ID,查询关联部门信息并填充到BO
|
|
|
|
|
* @return BO
|
|
* @return BO
|
|
|
*/
|
|
*/
|
|
|
- private SysUserBO entity2BO(SysUserEntity entity, boolean fillDeptInfo) {
|
|
|
|
|
|
|
+ private SysUserBO entity2BO(SysUserEntity entity) {
|
|
|
if (entity == null) {
|
|
if (entity == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
SysUserBO bo = new SysUserBO();
|
|
SysUserBO bo = new SysUserBO();
|
|
|
BeanUtil.copyProperties(entity, bo);
|
|
BeanUtil.copyProperties(entity, bo);
|
|
|
|
|
|
|
|
// 可以在此处为BO填充字段
|
|
// 可以在此处为BO填充字段
|
|
|
- bo.setUsername(entity.getPin());
|
|
|
|
|
|
|
+ bo.setUsername(entity.getUserName());
|
|
|
|
|
+ bo.setAccount(entity.getPin());
|
|
|
return bo;
|
|
return bo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -353,7 +299,7 @@ public class SysUserService {
|
|
|
// 深拷贝
|
|
// 深拷贝
|
|
|
List<SysUserBO> ret = new ArrayList<>(entityList.size());
|
|
List<SysUserBO> ret = new ArrayList<>(entityList.size());
|
|
|
entityList.forEach(
|
|
entityList.forEach(
|
|
|
- entity -> ret.add(this.entity2BO(entity, true))
|
|
|
|
|
|
|
+ entity -> ret.add(this.entity2BO(entity))
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
@@ -378,15 +324,22 @@ public class SysUserService {
|
|
|
*
|
|
*
|
|
|
* @param dto DTO
|
|
* @param dto DTO
|
|
|
*/
|
|
*/
|
|
|
- private void checkExistence(AdminInsertOrUpdateSysUserDTO dto) {
|
|
|
|
|
- SysUserEntity existingEntity = this.getUserByPin(dto.getUsername());
|
|
|
|
|
|
|
+ private void checkExistence(InsertOrUpdateSysUserDTO dto) {
|
|
|
|
|
+ SysUserEntity existingEntity = this.getUserByPin(dto.getAccount());
|
|
|
|
|
|
|
|
if (existingEntity != null && !existingEntity.getId().equals(dto.getId())) {
|
|
if (existingEntity != null && !existingEntity.getId().equals(dto.getId())) {
|
|
|
throw new BusinessException(400, "已存在相同账号,请重新输入");
|
|
throw new BusinessException(400, "已存在相同账号,请重新输入");
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ SysUserEntity entity =
|
|
|
|
|
+ sysUserMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<>(SysUserEntity.class)
|
|
|
|
|
+ .eq(SysUserEntity::getPhoneNo, dto.getPhoneNo())
|
|
|
|
|
+ );
|
|
|
|
|
+ if (entity != null && !entity.getId().equals(dto.getId())) {
|
|
|
|
|
+ throw new BusinessException(400, "已存在相同手机号,请重新输入");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateLastLoginAt(Long userId, LocalDateTime lastLoginAt) {
|
|
private void updateLastLoginAt(Long userId, LocalDateTime lastLoginAt) {
|
|
@@ -397,37 +350,6 @@ public class SysUserService {
|
|
|
sysUserMapper.updateById(entity);
|
|
sysUserMapper.updateById(entity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 编辑后台用户信息前检查
|
|
|
|
|
- *
|
|
|
|
|
- * @param specifiedUserId 被操作用户ID
|
|
|
|
|
- * @param statusEnum 用户状态枚举,可以为null
|
|
|
|
|
- */
|
|
|
|
|
- private void preUpdateCheck(Long specifiedUserId, @Nullable SysUserStatusEnum statusEnum) {
|
|
|
|
|
- UserRoleContainer currentUser = sysRoleService.getCurrentUserRoleContainer();
|
|
|
|
|
- if (currentUser.isAdmin()) {
|
|
|
|
|
- // 超级管理员除禁用自己外为所欲为
|
|
|
|
|
- if (statusEnum == SysUserStatusEnum.BANNED && Objects.equals(specifiedUserId, UserContextHolder.getUserId())) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_SELF_USER);
|
|
|
|
|
- }
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (Objects.equals(specifiedUserId, UserContextHolder.getUserId())) {
|
|
|
|
|
- // 不能动自身用户
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_SELF_USER);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 目标是超级管理员or租户管理员时,均不能编辑
|
|
|
|
|
- UserRoleContainer specifiedUser = sysRoleService.getSpecifiedUserRoleContainer(specifiedUserId);
|
|
|
|
|
- if (specifiedUser.isGroupManager()) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_THIS_USER);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-// dataScopeCheck(Collections.singleton(specifiedUserId));
|
|
|
|
|
- // 暂未实现角色层级,一律平级
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 删除后台用户前检查
|
|
* 删除后台用户前检查
|
|
|
*/
|
|
*/
|
|
@@ -437,81 +359,12 @@ public class SysUserService {
|
|
|
throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_SELF_USER);
|
|
throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_SELF_USER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 目标是超级管理员时,不能删除
|
|
|
|
|
- List<UserRoleContainer> specifiedUsers = ids.stream().map(sysRoleService::getSpecifiedUserRoleContainer).toList();
|
|
|
|
|
- if (specifiedUsers.stream().anyMatch(UserRoleContainer::isAdmin)) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_THIS_USER);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 只有超级管理员可以删租户管理员用户
|
|
|
|
|
- UserRoleContainer currentUser = sysRoleService.getCurrentUserRoleContainer();
|
|
|
|
|
- if (!currentUser.isGroupManager()) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_THIS_USER);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 绑定后台用户与角色关联关系前检查
|
|
|
|
|
- * 防止越权访问漏洞
|
|
|
|
|
- */
|
|
|
|
|
- private void preBindUserRoleRelationCheck(AdminBindUserRoleRelationDTO dto) {
|
|
|
|
|
- UserRoleContainer currentUser = sysRoleService.getCurrentUserRoleContainer();
|
|
|
|
|
- // 是否对自己操作
|
|
|
|
|
- boolean selfFlag = Objects.equals(dto.getUserId(), UserContextHolder.getUserId());
|
|
|
|
|
- if (currentUser.isAdmin()) {
|
|
|
|
|
- // 超级管理员不能去掉自己的超级管理员角色
|
|
|
|
|
- if (selfFlag && !CollUtil.contains(dto.getRoleIds(), SysConstant.SUPER_ADMIN_ROLE_ID)) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_SELF_USER);
|
|
|
|
|
- }
|
|
|
|
|
- // 也不能赋予其他人超级管理员角色
|
|
|
|
|
- if (!selfFlag && CollUtil.contains(dto.getRoleIds(), SysConstant.SUPER_ADMIN_ROLE_ID)) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_THIS_USER);
|
|
|
|
|
- }
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (selfFlag) {
|
|
|
|
|
- // 不能动自身用户
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_SELF_USER);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 目标已经是超级管理员or租户管理员时,均不能绑定
|
|
|
|
|
- UserRoleContainer specifiedUser = sysRoleService.getSpecifiedUserRoleContainer(dto.getUserId());
|
|
|
|
|
- if (specifiedUser.isAdmin()) {
|
|
|
|
|
|
|
+ if (CollUtil.contains(ids, 1)) {
|
|
|
|
|
+ // 不能删除默认的管理员数据
|
|
|
throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_THIS_USER);
|
|
throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_THIS_USER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 超级管理员之外的用户,都需要校验自身角色范围是否满足输入值
|
|
|
|
|
- currentUserNotSuperAdmin(dto, currentUser);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 绑定后台用户与角色关联关系前检查
|
|
|
|
|
- * 超级管理员之外的用户,都需要校验自身角色范围是否满足输入值
|
|
|
|
|
- * 拆分子方法以降低Cognitive Complexity
|
|
|
|
|
- */
|
|
|
|
|
- private void currentUserNotSuperAdmin(AdminBindUserRoleRelationDTO dto, UserRoleContainer currentUser) {
|
|
|
|
|
- if (CollUtil.isNotEmpty(dto.getRoleIds()) && !currentUser.isAdmin()) {
|
|
|
|
|
- boolean overRoles = !CollUtil.containsAll(currentUser.getRelatedRoleIds(), dto.getRoleIds());
|
|
|
|
|
- if (overRoles && currentUser.isGroupManager()) {
|
|
|
|
|
- // 普通用户超自身角色授予了;如果当前用户拥有新角色的所有菜单,那么也放行
|
|
|
|
|
- Set<Long> grantedMenuIds = sysRoleMenuRelationService.listMenuIdsByRoleIds(currentUser.getRelatedRoleIds());
|
|
|
|
|
- Set<Long> needMenuIds = sysRoleMenuRelationService.listMenuIdsByRoleIds(dto.getRoleIds());
|
|
|
|
|
- if (!CollUtil.containsAll(grantedMenuIds, needMenuIds)) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.BEYOND_AUTHORITY_BIND_ROLES);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-// if (currentUser.isTenantAdmin()) {
|
|
|
|
|
-// // 超自身权限,但作为租户管理员有额外情况
|
|
|
|
|
-// Set<Long> invisibleRoleIds = sysRoleService.determineInvisibleRoleIds();
|
|
|
|
|
-// // 除非超越了可见角色IDs授予 or 想要授予用户租户管理员角色,否则不管
|
|
|
|
|
-// invisibleRoleIds.addAll(currentUser.getRelatedRoleIds());
|
|
|
|
|
-// if (CollUtil.containsAny(invisibleRoleIds, dto.getRoleIds())) {
|
|
|
|
|
-// throw new BusinessException(SysErrorEnum.BEYOND_AUTHORITY_BIND_ROLES);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|