| | |
| | | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserSyncReqDTO; |
| | | import cn.iocoder.yudao.module.system.api.user.event.AdminUserDeletedEvent; |
| | | import cn.iocoder.yudao.module.system.api.user.event.AdminUserUpdatedEvent; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| | |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.validation.ConstraintViolationException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.security.crypto.password.PasswordEncoder; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | @Resource |
| | | private AdminUserProducer adminUserProducer; |
| | | |
| | | @Resource |
| | | private ApplicationEventPublisher eventPublisher; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | // 3. 记录操作日志上下文 |
| | | LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldUser, UserSaveReqVO.class)); |
| | | LogRecordContext.putVariable("user", oldUser); |
| | | |
| | | // 4. 通知 hrm 模块同步员工档案(没有员工档案的账号会被监听器直接跳过) |
| | | eventPublisher.publishEvent(new AdminUserUpdatedEvent(updateReqVO.getId(), |
| | | updateReqVO.getNickname(), updateReqVO.getMobile(), updateReqVO.getDeptId(), |
| | | updateReqVO.getSex(), updateReqVO.getEmail())); |
| | | } |
| | | |
| | | private void updateUserPost(UserSaveReqVO reqVO, AdminUserDO updateObj) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateUserProfile(Long id, UserProfileUpdateReqVO reqVO) { |
| | | // 1. 校验正确性 |
| | | AdminUserDO oldUser = validateUserExists(id); |
| | |
| | | |
| | | // 3. 昵称 / 头像变化时,发送消息供下游订阅(如 IM 模块推 FRIEND_INFO_UPDATED) |
| | | publishUserProfileUpdatedIfChanged(oldUser, reqVO.getNickname(), reqVO.getAvatar()); |
| | | |
| | | // 4. 通知 hrm 模块同步员工档案(没有员工档案的账号会被监听器直接跳过) |
| | | eventPublisher.publishEvent(new AdminUserUpdatedEvent(id, |
| | | reqVO.getNickname(), reqVO.getMobile(), null, reqVO.getSex(), reqVO.getEmail())); |
| | | } |
| | | |
| | | /** |
| | |
| | | @LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_DELETE_SUB_TYPE, bizNo = "{{#id}}", |
| | | success = SYSTEM_USER_DELETE_SUCCESS) |
| | | public void deleteUser(Long id) { |
| | | doDeleteUser(id); |
| | | // 通知 hrm 模块联动删除员工档案(没有员工档案的账号会被监听器直接跳过) |
| | | eventPublisher.publishEvent(new AdminUserDeletedEvent(id)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteUserSilently(Long id) { |
| | | doDeleteUser(id); |
| | | } |
| | | |
| | | private void doDeleteUser(Long id) { |
| | | // 1. 校验用户存在 |
| | | AdminUserDO user = validateUserExists(id); |
| | | |
| | |
| | | permissionService.processUserDeleted(id); |
| | | userPostMapper.deleteByUserId(id); |
| | | }); |
| | | |
| | | // 3. 通知 hrm 模块联动删除员工档案 |
| | | ids.forEach(id -> eventPublisher.publishEvent(new AdminUserDeletedEvent(id))); |
| | | } |
| | | |
| | | @Override |
| | | public void updateUserForEmployee(AdminUserSyncReqDTO reqDTO) { |
| | | if (reqDTO == null || reqDTO.getUserId() == null) { |
| | | return; |
| | | } |
| | | // 1. 校验用户存在 |
| | | AdminUserDO user = validateUserExists(reqDTO.getUserId()); |
| | | // 2. 校验手机号 / 邮箱唯一(与旧值不同时才校验) |
| | | if (StrUtil.isNotBlank(reqDTO.getMobile()) && !ObjUtil.equal(user.getMobile(), reqDTO.getMobile())) { |
| | | validateMobileUnique(reqDTO.getUserId(), reqDTO.getMobile()); |
| | | } |
| | | if (StrUtil.isNotBlank(reqDTO.getEmail()) && !ObjUtil.equal(user.getEmail(), reqDTO.getEmail())) { |
| | | validateEmailUnique(reqDTO.getUserId(), reqDTO.getEmail()); |
| | | } |
| | | // 3. 只更新非空字段 |
| | | AdminUserDO updateObj = new AdminUserDO(); |
| | | updateObj.setId(reqDTO.getUserId()); |
| | | if (StrUtil.isNotBlank(reqDTO.getNickname())) { |
| | | updateObj.setNickname(reqDTO.getNickname()); |
| | | } |
| | | if (StrUtil.isNotBlank(reqDTO.getMobile())) { |
| | | updateObj.setMobile(reqDTO.getMobile()); |
| | | } |
| | | if (reqDTO.getDeptId() != null) { |
| | | updateObj.setDeptId(reqDTO.getDeptId()); |
| | | } |
| | | if (reqDTO.getSex() != null) { |
| | | updateObj.setSex(reqDTO.getSex()); |
| | | } |
| | | if (StrUtil.isNotBlank(reqDTO.getEmail())) { |
| | | updateObj.setEmail(reqDTO.getEmail()); |
| | | } |
| | | userMapper.updateById(updateObj); |
| | | } |
| | | |
| | | @Override |