Search in sources :

Example 1 with UserOrganizationChangeEvent

use of com.hccake.ballcat.system.event.UserOrganizationChangeEvent 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)

Aggregations

UserOrganizationChangeEvent (com.hccake.ballcat.system.event.UserOrganizationChangeEvent)1 SysUser (com.hccake.ballcat.system.model.entity.SysUser)1 Transactional (org.springframework.transaction.annotation.Transactional)1