【8.1.7】【system】更新一个简化添加用户的方法

dev-8.1.9
stylefeng 2024-05-24 00:04:54 +08:00
parent 27c5a02fc7
commit 3dbcb13501
4 changed files with 135 additions and 0 deletions

View File

@ -179,4 +179,15 @@ public interface SysUserServiceApi {
*/
List<SimpleUserDTO> batchGetUserSimpleInfoList(Set<Long> userIdList);
/**
*
*
* @param addUserDTO
* @param orgId id
* @param positionId id
* @author fengshuonan
* @since 2024/5/23 23:48
*/
void simpleAddUser(AddUserDTO addUserDTO, Long orgId, Long positionId);
}

View File

@ -0,0 +1,45 @@
package cn.stylefeng.roses.kernel.sys.api.pojo.user;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import lombok.Data;
/**
*
*
* @author fengshuonan
* @since 2024/5/23 23:47
*/
@Data
public class AddUserDTO {
/**
*
*/
@ChineseDescription("账号")
private String account;
/**
*
*/
@ChineseDescription("昵称")
private String nickName;
/**
*
*/
@ChineseDescription("邮箱")
private String email;
/**
* MD5
*/
@ChineseDescription("密码加密方式为MD5")
private String password;
/**
*
*/
@ChineseDescription("密码盐")
private String passwordSalt;
}

View File

@ -2,8 +2,13 @@ package cn.stylefeng.roses.kernel.sys.modular.user.factory;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.AddUserDTO;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUser;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserOrg;
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserRequest;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
/**
*
@ -46,4 +51,50 @@ public class SysUserCreateFactory {
}
}
/**
* dto
*
* @author fengshuonan
* @since 2024/5/23 23:51
*/
public static SysUser createSimpleAddUser(AddUserDTO addUserDTO) {
SysUser sysUser = new SysUser();
// 设置主键
sysUser.setUserId(IdWorker.getId());
// 设置账号
sysUser.setAccount(addUserDTO.getAccount());
// 设置昵称
sysUser.setNickName(addUserDTO.getNickName());
// 设置邮箱
sysUser.setEmail(addUserDTO.getEmail());
// 设置密码
sysUser.setPassword(addUserDTO.getPassword());
// 设置密码盐
sysUser.setPasswordSalt(addUserDTO.getPasswordSalt());
return sysUser;
}
/**
*
*
* @author fengshuonan
* @since 2024/5/24 0:02
*/
public static SysUserOrg createOneUserOrg(Long userId, Long orgId, Long positionId) {
SysUserOrg sysUserOrg = new SysUserOrg();
sysUserOrg.setUserId(userId);
sysUserOrg.setOrgId(orgId);
sysUserOrg.setPositionId(positionId);
sysUserOrg.setMainFlag(YesOrNotEnum.Y.getCode());
sysUserOrg.setStatusFlag(StatusEnum.ENABLE.getCode());
return sysUserOrg;
}
}

View File

@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.sys.modular.user.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.roses.kernel.auth.api.TenantCodeGetApi;
@ -794,6 +795,33 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return simpleUserDTOS;
}
@Override
public void simpleAddUser(AddUserDTO addUserDTO, Long orgId, Long positionId) {
SysUser simpleUser = SysUserCreateFactory.createSimpleAddUser(addUserDTO);
// 设置用户默认头像
simpleUser.setAvatar(FileConstants.DEFAULT_AVATAR_FILE_ID);
this.save(simpleUser);
// 记录一个密码修改记录
securityConfigService.recordPasswordEditLog(simpleUser.getUserId(), simpleUser.getPassword(), simpleUser.getPasswordSalt());
// 更新用户的任职信息,用户有且只有一个所属机构
sysUserOrgService.updateUserOrg(simpleUser.getUserId(),
ListUtil.of(
SysUserCreateFactory.createOneUserOrg(simpleUser.getUserId(), orgId, positionId)));
// 添加用户一个默认角色
sysUserRoleService.bindUserDefaultRole(simpleUser.getUserId());
// 记录日志
BusinessLogUtil.setLogTitle("新增用户,用户账号:" + simpleUser.getAccount());
BusinessLogUtil.addContent("新增用户账号信息:", simpleUser.getAccount());
BusinessLogUtil.addContent("用户详细信息如下:\n", simpleUser);
}
/**
*
*