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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations