Search in sources :

Example 1 with SysUser

use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.

the class NotifyWebsocketEventListener method onAnnouncementPublishEvent.

/**
 * 站内通知推送事件
 * @param event the StationNotifyPushEvent
 */
@Async
@EventListener(StationNotifyPushEvent.class)
public void onAnnouncementPublishEvent(StationNotifyPushEvent event) {
    NotifyInfo notifyInfo = event.getNotifyInfo();
    List<SysUser> userList = event.getUserList();
    notifyInfoDelegateHandler.handle(userList, notifyInfo);
}
Also used : SysUser(com.hccake.ballcat.system.model.entity.SysUser) NotifyInfo(com.hccake.ballcat.notify.model.domain.NotifyInfo) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Example 2 with SysUser

use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.

the class AnnouncementNotifyInfoHandler method persistMessage.

@Override
protected void persistMessage(List<SysUser> userList, AnnouncementNotifyInfo announcementNotifyInfo) {
    List<UserAnnouncement> userAnnouncements = new ArrayList<>(userList.size());
    // 向指定用户推送
    for (SysUser sysUser : userList) {
        Integer userId = sysUser.getUserId();
        UserAnnouncement userAnnouncement = userAnnouncementService.prodUserAnnouncement(userId, announcementNotifyInfo.getId());
        userAnnouncements.add(userAnnouncement);
    }
    userAnnouncementService.saveBatch(userAnnouncements);
}
Also used : SysUser(com.hccake.ballcat.system.model.entity.SysUser) ArrayList(java.util.ArrayList) UserAnnouncement(com.hccake.ballcat.notify.model.entity.UserAnnouncement)

Example 3 with SysUser

use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.

the class AnnouncementLoginEventListener method getSysUser.

private SysUser getSysUser(User user) {
    SysUser sysUser = new SysUser();
    sysUser.setUserId(user.getUserId());
    sysUser.setUsername(user.getUsername());
    sysUser.setNickname(user.getNickname());
    sysUser.setAvatar(user.getAvatar());
    sysUser.setOrganizationId(user.getOrganizationId());
    sysUser.setType(user.getType());
    return sysUser;
}
Also used : SysUser(com.hccake.ballcat.system.model.entity.SysUser)

Example 4 with SysUser

use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.

the class SysUserServiceImpl method updateSysUser.

/**
 * 更新系统用户信息
 * @param sysUserDTO 系统用户DTO
 * @return 更新成功 true: 更新失败 false
 */
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateSysUser(SysUserDTO sysUserDTO) {
    SysUser entity = SysUserConverter.INSTANCE.dtoToPo(sysUserDTO);
    Assert.isTrue(adminUserChecker.hasModifyPermission(entity), "当前用户不允许修改!");
    // 如果不更新组织,直接执行
    Integer currentOrganizationId = entity.getOrganizationId();
    if (currentOrganizationId == null) {
        return SqlHelper.retBool(baseMapper.updateById(entity));
    }
    // 查询出当前库中用户
    Integer userId = entity.getUserId();
    SysUser oldUser = baseMapper.selectById(userId);
    Assert.notNull(oldUser, "修改用户失败,当前用户不存在:{}", userId);
    // 是否修改了组织
    Integer originOrganizationId = oldUser.getOrganizationId();
    boolean organizationIdModified = !currentOrganizationId.equals(originOrganizationId);
    // 是否更改成功
    boolean isUpdateSuccess = SqlHelper.retBool(baseMapper.updateById(entity));
    // 如果修改了组织且修改成功,则发送用户组织更新事件
    if (isUpdateSuccess && organizationIdModified) {
        publisher.publishEvent(new UserOrganizationChangeEvent(userId, originOrganizationId, currentOrganizationId));
    }
    return isUpdateSuccess;
}
Also used : UserOrganizationChangeEvent(com.hccake.ballcat.system.event.UserOrganizationChangeEvent) SysUser(com.hccake.ballcat.system.model.entity.SysUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SysUser

use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.

the class SysUserServiceImpl method addSysUser.

/**
 * 新增系统用户
 * @param sysUserDto 系统用户DTO
 * @return 添加成功:true , 失败:false
 */
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addSysUser(SysUserDTO sysUserDto) {
    SysUser sysUser = SysUserConverter.INSTANCE.dtoToPo(sysUserDto);
    sysUser.setStatus(SysUserConst.Status.NORMAL.getValue());
    sysUser.setType(SysUserConst.Type.SYSTEM.getValue());
    // 对密码进行加密
    String rawPassword = sysUserDto.getPassword();
    String encodedPassword = PasswordUtils.encode(rawPassword);
    sysUser.setPassword(encodedPassword);
    // 保存用户
    boolean insertSuccess = SqlHelper.retBool(baseMapper.insert(sysUser));
    Assert.isTrue(insertSuccess, () -> {
        log.error("[addSysUser] 数据插入系统用户表失败,user:{}", sysUserDto);
        return new BusinessException(BaseResultCode.UPDATE_DATABASE_ERROR.getCode(), "数据插入系统用户表失败");
    });
    // 新增用户角色关联
    List<String> roleCodes = sysUserDto.getRoleCodes();
    if (CollectionUtil.isNotEmpty(roleCodes)) {
        boolean addUserRoleSuccess = sysUserRoleService.addUserRoles(sysUser.getUserId(), roleCodes);
        Assert.isTrue(addUserRoleSuccess, () -> {
            log.error("[addSysUser] 更新用户角色信息失败,user:{}, roleCodes: {}", sysUserDto, roleCodes);
            return new BusinessException(BaseResultCode.UPDATE_DATABASE_ERROR.getCode(), "更新用户角色信息失败");
        });
    }
    // 发布用户创建事件
    publisher.publishEvent(new UserCreatedEvent(sysUser, sysUserDto.getRoleCodes()));
    return true;
}
Also used : UserCreatedEvent(com.hccake.ballcat.system.event.UserCreatedEvent) BusinessException(com.hccake.ballcat.common.core.exception.BusinessException) SysUser(com.hccake.ballcat.system.model.entity.SysUser) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SysUser (com.hccake.ballcat.system.model.entity.SysUser)12 Transactional (org.springframework.transaction.annotation.Transactional)3 User (com.hccake.ballcat.common.security.userdetails.User)2 UserAnnouncement (com.hccake.ballcat.notify.model.entity.UserAnnouncement)2 Operation (io.swagger.v3.oas.annotations.Operation)2 HashMap (java.util.HashMap)2 EventListener (org.springframework.context.event.EventListener)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 BusinessException (com.hccake.ballcat.common.core.exception.BusinessException)1 CreateOperationLogging (com.hccake.ballcat.common.log.operation.annotation.CreateOperationLogging)1 MailDetails (com.hccake.ballcat.common.mail.model.MailDetails)1 NotifyChannelEnum (com.hccake.ballcat.notify.enums.NotifyChannelEnum)1 NotifyInfo (com.hccake.ballcat.notify.model.domain.NotifyInfo)1 Announcement (com.hccake.ballcat.notify.model.entity.Announcement)1 RecipientHandler (com.hccake.ballcat.notify.recipient.RecipientHandler)1 AnnouncementService (com.hccake.ballcat.notify.service.AnnouncementService)1 UserAnnouncementService (com.hccake.ballcat.notify.service.UserAnnouncementService)1 UserCreatedEvent (com.hccake.ballcat.system.event.UserCreatedEvent)1 UserOrganizationChangeEvent (com.hccake.ballcat.system.event.UserOrganizationChangeEvent)1 UserInfoDTO (com.hccake.ballcat.system.model.dto.UserInfoDTO)1