Search in sources :

Example 31 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project wumei-smart by kerwincui.

the class ThingsModelTemplateServiceImpl method insertThingsModelTemplate.

/**
 * 新增通用物模型
 *
 * @param thingsModelTemplate 通用物模型
 * @return 结果
 */
@Override
public int insertThingsModelTemplate(ThingsModelTemplate thingsModelTemplate) {
    SysUser user = getLoginUser().getUser();
    List<SysRole> roles = user.getRoles();
    if (roles == null || roles.size() == 0) {
        return 0;
    }
    // 系统管理员
    if (roles.stream().anyMatch(a -> a.getRoleKey().equals("admin"))) {
        thingsModelTemplate.setIsSys(1);
    }
    thingsModelTemplate.setTenantId(user.getUserId());
    thingsModelTemplate.setTenantName(user.getUserName());
    thingsModelTemplate.setCreateTime(DateUtils.getNowDate());
    return thingsModelTemplateMapper.insertThingsModelTemplate(thingsModelTemplate);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) SysRole(com.ruoyi.common.core.domain.entity.SysRole)

Example 32 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project wumei-smart by kerwincui.

the class ProductServiceImpl method insertProduct.

/**
 * 新增产品
 *
 * @param product 产品
 * @return 结果
 */
@Override
public Product insertProduct(Product product) {
    SysUser user = getLoginUser().getUser();
    List<SysRole> roles = user.getRoles();
    if (roles == null || roles.size() == 0) {
        return null;
    }
    // 系统管理员
    if (roles.stream().anyMatch(a -> a.getRoleKey().equals("admin"))) {
        product.setIsSys(1);
    }
    // mqtt账号密码
    product.setMqttAccount("wumei-smart");
    product.setMqttPassword("P" + toolService.getStringRandom(15));
    product.setMqttSecret("K" + toolService.getStringRandom(15));
    product.setStatus(product.getStatus() == null ? 1 : product.getStatus());
    product.setTenantId(user.getUserId());
    product.setTenantName(user.getUserName());
    product.setCreateTime(DateUtils.getNowDate());
    productMapper.insertProduct(product);
    return product;
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) SysRole(com.ruoyi.common.core.domain.entity.SysRole)

Example 33 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project wumei-smart by kerwincui.

the class SysRoleServiceImpl method deleteRoleByIds.

/**
 * 批量删除角色信息
 *
 * @param roleIds 需要删除的角色ID
 * @return 结果
 */
@Override
@Transactional
public int deleteRoleByIds(Long[] roleIds) {
    for (Long roleId : roleIds) {
        checkRoleAllowed(new SysRole(roleId));
        SysRole role = selectRoleById(roleId);
        if (countUserRoleByRoleId(roleId) > 0) {
            throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
        }
    }
    // 删除角色与菜单关联
    roleMenuMapper.deleteRoleMenu(roleIds);
    // 删除角色与部门关联
    roleDeptMapper.deleteRoleDept(roleIds);
    return roleMapper.deleteRoleByIds(roleIds);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysRole(com.ruoyi.common.core.domain.entity.SysRole) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project wumei-smart by kerwincui.

the class SysRoleServiceImpl method checkRoleDataScope.

/**
 * 校验角色是否有数据权限
 *
 * @param roleId 角色id
 */
@Override
public void checkRoleDataScope(Long roleId) {
    if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
        SysRole role = new SysRole();
        role.setRoleId(roleId);
        List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
        if (StringUtils.isEmpty(roles)) {
            throw new ServiceException("没有权限访问角色数据!");
        }
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysRole(com.ruoyi.common.core.domain.entity.SysRole)

Example 35 with SysRole

use of com.ruoyi.common.core.domain.entity.SysRole in project RuoYi-Vue by yangzongzhuan.

the class SysRoleServiceImpl method checkRoleNameUnique.

/**
 * 校验角色名称是否唯一
 *
 * @param role 角色信息
 * @return 结果
 */
@Override
public String checkRoleNameUnique(SysRole role) {
    Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
    SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
    if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
        return UserConstants.NOT_UNIQUE;
    }
    return UserConstants.UNIQUE;
}
Also used : SysRole(com.ruoyi.common.core.domain.entity.SysRole)

Aggregations

SysRole (com.ruoyi.common.core.domain.entity.SysRole)44 SysUser (com.ruoyi.common.core.domain.entity.SysUser)15 Log (com.ruoyi.common.annotation.Log)9 UserConstants (com.ruoyi.common.constant.UserConstants)9 BaseController (com.ruoyi.common.core.controller.BaseController)9 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)9 BusinessType (com.ruoyi.common.enums.BusinessType)9 ServiceException (com.ruoyi.common.exception.ServiceException)9 StringUtils (com.ruoyi.common.utils.StringUtils)9 ExcelUtil (com.ruoyi.common.utils.poi.ExcelUtil)9 ISysPostService (com.ruoyi.system.service.ISysPostService)9 ISysRoleService (com.ruoyi.system.service.ISysRoleService)9 ISysUserService (com.ruoyi.system.service.ISysUserService)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Validated (org.springframework.validation.annotation.Validated)9 MultipartFile (org.springframework.web.multipart.MultipartFile)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)4 BCrypt (cn.dev33.satoken.secure.BCrypt)4