|
@@ -1,9 +1,14 @@
|
|
|
package org.dromara.service.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.secure.BCrypt;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.common.core.config.BoManConfig;
|
|
|
+import org.dromara.common.core.enums.UserType;
|
|
|
+import org.dromara.common.core.exception.user.UserException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
@@ -15,20 +20,22 @@ import org.dromara.domain.staffManage.vo.StaffManageVo;
|
|
|
import org.dromara.mapper.StaffManageMapper;
|
|
|
import org.dromara.service.IStaffManageService;
|
|
|
import org.dromara.system.domain.SysRole;
|
|
|
+import org.dromara.system.domain.SysUser;
|
|
|
import org.dromara.system.domain.SysUserTenant;
|
|
|
import org.dromara.system.domain.bo.SysUserBo;
|
|
|
import org.dromara.system.domain.vo.SysRoleVo;
|
|
|
import org.dromara.system.mapper.SysRoleMapper;
|
|
|
+import org.dromara.system.mapper.SysUserMapper;
|
|
|
import org.dromara.system.mapper.SysUserTenantMapper;
|
|
|
import org.dromara.system.service.ISysUserService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-import static org.dromara.common.core.constant.Constants.TWO;
|
|
|
-import static org.dromara.common.core.constant.Constants.Y;
|
|
|
+import static org.dromara.common.core.constant.Constants.*;
|
|
|
|
|
|
/**
|
|
|
* 员工管理Service业务层处理
|
|
@@ -43,7 +50,9 @@ public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
private final StaffManageMapper baseMapper;
|
|
|
private final SysUserTenantMapper sysUserTenantMapper;
|
|
|
private final SysRoleMapper sysRoleMapper;
|
|
|
- private final ISysUserService sysUserService;
|
|
|
+ private final ISysUserService userService;
|
|
|
+ private final SysUserMapper userMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询员工管理
|
|
|
*
|
|
@@ -51,10 +60,21 @@ public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
* @return 员工管理
|
|
|
*/
|
|
|
@Override
|
|
|
- public StaffManageVo queryById(Long staffId){
|
|
|
+ public StaffManageVo queryById(Long staffId) {
|
|
|
return baseMapper.selectVoById(staffId);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取员工管理详细信息
|
|
|
+ *
|
|
|
+ * @param userId 用户id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public StaffManageVo getInfoByUserId(Long userId) {
|
|
|
+ return baseMapper.selectVoOne(new LambdaQueryWrapper<StaffManage>().eq(StaffManage::getUserId, userId));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 分页查询员工管理列表
|
|
|
*
|
|
@@ -117,6 +137,66 @@ public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 管理员新增员工信息默认认证
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean insertAuthenticationByBo(StaffManageBo bo) {
|
|
|
+ StaffManage staffManage = MapstructUtils.convert(bo, StaffManage.class);
|
|
|
+ SysUserBo sysUser = new SysUserBo();
|
|
|
+ String tenantId = "";
|
|
|
+ //手机号、手机验证码注册
|
|
|
+ if (TenantHelper.isEnable()) {
|
|
|
+ tenantId = staffManage.getTenantId();
|
|
|
+ }
|
|
|
+ String username = staffManage.getPhoneNumber();
|
|
|
+ String password = BoManConfig.getPasswordDeft();
|
|
|
+ // 校验用户类型是否存在
|
|
|
+ String userType = UserType.getUserType(staffManage.getUserType()).getUserType();
|
|
|
+
|
|
|
+ sysUser.setUserName(username);
|
|
|
+ sysUser.setNickName(username);
|
|
|
+ sysUser.setPassword(BCrypt.hashpw(password));
|
|
|
+ sysUser.setUserType(userType);
|
|
|
+ sysUser.setPhonenumber(username);
|
|
|
+ sysUser.setIsAuthentication(Y);
|
|
|
+ boolean exist = TenantHelper.dynamic(tenantId, () -> {
|
|
|
+ return userMapper.exists(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getUserName, sysUser.getUserName()));
|
|
|
+ });
|
|
|
+ if (exist) {
|
|
|
+ throw new UserException("user.register.save.error", username);
|
|
|
+ }
|
|
|
+ boolean regFlag = userService.registerUser(sysUser, tenantId);
|
|
|
+ if (!regFlag) {
|
|
|
+ throw new UserException("user.register.error");
|
|
|
+ }
|
|
|
+ staffManage.setExamine(TWO);
|
|
|
+ staffManage.setUserId(sysUser.getUserId());
|
|
|
+ boolean flag = baseMapper.insert(staffManage) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setStaffId(staffManage.getStaffId());
|
|
|
+ }
|
|
|
+ //sys_user_tenant表中
|
|
|
+ SysUserTenant sysUserTenant = new SysUserTenant();
|
|
|
+ sysUserTenant.setUserId(staffManage.getUserId());
|
|
|
+ sysUserTenant.setTenantId(staffManage.getTenantId());
|
|
|
+ sysUserTenantMapper.insert(sysUserTenant);
|
|
|
+
|
|
|
+ //给该userId赋予角色
|
|
|
+ // 新增用户与角色管理
|
|
|
+ //根据权限字符去查询角色id
|
|
|
+ Long[] roles;
|
|
|
+ SysRoleVo sysRoleVo = sysRoleMapper.selectVoOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getRoleKey, staffManage.getStaffCategory()));
|
|
|
+ if (sysRoleVo != null) {
|
|
|
+ roles = new Long[]{sysRoleVo.getRoleId()};
|
|
|
+ sysUser.setRoleIds(roles);
|
|
|
+ }
|
|
|
+ userService.insertUserRole(sysUser, false);
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改员工管理
|
|
|
*
|
|
@@ -130,10 +210,54 @@ public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
return baseMapper.updateById(update) > 0;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 管理员修改员工管理
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean editAuthentication(StaffManageBo bo) {
|
|
|
+ StaffManage examineStaffManage = MapstructUtils.convert(bo, StaffManage.class);
|
|
|
+ StaffManageVo staffManageVo = baseMapper.selectVoById(bo.getStaffId());
|
|
|
+ //原始的tenantId
|
|
|
+ String tenantIdOld = staffManageVo.getTenantId();
|
|
|
+ Long userId = examineStaffManage.getUserId();
|
|
|
+ SysUserBo sysUser = new SysUserBo();
|
|
|
+ if (TenantHelper.isEnable()) {
|
|
|
+ //把租户id更新到sys_user表/sys_user_tenant表中
|
|
|
+ String tenantIdNew = examineStaffManage.getTenantId();
|
|
|
+ sysUser.setTenantId(tenantIdNew);
|
|
|
+ //如过两个租户id不一致,更新sys_user_tenant表
|
|
|
+ if (!tenantIdOld.equals(tenantIdNew)) {
|
|
|
+ SysUserTenant sysUserTenant = new SysUserTenant();
|
|
|
+ sysUserTenant.setUserId(userId);
|
|
|
+ sysUserTenant.setTenantId(examineStaffManage.getTenantId());
|
|
|
+ sysUserTenantMapper.update(new LambdaUpdateWrapper<SysUserTenant>()
|
|
|
+ .set(SysUserTenant::getTenantId, tenantIdNew)
|
|
|
+ .eq(SysUserTenant::getUserId, userId).eq(SysUserTenant::getTenantId, tenantIdOld));
|
|
|
+
|
|
|
+ //组装sysUser
|
|
|
+ //给该userId赋予角色
|
|
|
+ // 新增用户与角色管理
|
|
|
+ sysUser.setUserId(bo.getUserId());
|
|
|
+ //根据权限字符去查询角色id
|
|
|
+ Long[] roles;
|
|
|
+ SysRoleVo sysRoleVo = sysRoleMapper.selectVoOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getRoleKey, examineStaffManage.getStaffCategory()));
|
|
|
+ if (sysRoleVo != null) {
|
|
|
+ roles = new Long[]{sysRoleVo.getRoleId()};
|
|
|
+ sysUser.setRoleIds(roles);
|
|
|
+ }
|
|
|
+ userService.insertUserRole(sysUser, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sysUser.setUserId(examineStaffManage.getUserId());
|
|
|
+ sysUser.setPhonenumber(examineStaffManage.getPhoneNumber());
|
|
|
+ return userService.updateUserById(sysUser) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(StaffManage entity){
|
|
|
+ private void validEntityBeforeSave(StaffManage entity) {
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
}
|
|
|
|
|
@@ -146,7 +270,7 @@ public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
+ if (isValid) {
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
@@ -166,11 +290,12 @@ public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
//判断是否审核通过
|
|
|
if (TWO.equals(examineStaffManage.getExamine())) {
|
|
|
SysUserBo sysUser = new SysUserBo();
|
|
|
+ sysUser.setUserId(bo.getUserId());
|
|
|
if (TenantHelper.isEnable()) {
|
|
|
//把租户id更新到sys_user表/sys_user_tenant表中
|
|
|
sysUser.setTenantId(examineStaffManage.getTenantId());
|
|
|
sysUser.setIsAuthentication(Y);
|
|
|
- sysUserService.updateUserById(sysUser);
|
|
|
+ userService.updateUserById(sysUser);
|
|
|
SysUserTenant sysUserTenant = new SysUserTenant();
|
|
|
sysUserTenant.setUserId(examineStaffManage.getUserId());
|
|
|
sysUserTenant.setTenantId(examineStaffManage.getTenantId());
|
|
@@ -179,7 +304,6 @@ public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
//组装sysUser
|
|
|
//给该userId赋予角色
|
|
|
// 新增用户与角色管理
|
|
|
- sysUser.setUserId(bo.getUserId());
|
|
|
//根据权限字符去查询角色id
|
|
|
Long[] roles;
|
|
|
SysRoleVo sysRoleVo = sysRoleMapper.selectVoOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getRoleKey, examineStaffManage.getStaffCategory()));
|
|
@@ -187,7 +311,7 @@ public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
roles = new Long[]{sysRoleVo.getRoleId()};
|
|
|
sysUser.setRoleIds(roles);
|
|
|
}
|
|
|
- sysUserService.insertUserRole(sysUser, false);
|
|
|
+ userService.insertUserRole(sysUser, false);
|
|
|
} else {
|
|
|
return baseMapper.updateById(examineStaffManage) > 0;
|
|
|
}
|