Search in sources :

Example 41 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysOssConfigServiceImpl method deleteWithValidByIds.

@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
    if (isValid) {
        if (CollUtil.containsAny(ids, OssConstant.SYSTEM_DATA_IDS)) {
            throw new ServiceException("系统内置, 不可删除!");
        }
    }
    List<SysOssConfig> list = Lists.newArrayList();
    for (Long configId : ids) {
        SysOssConfig config = baseMapper.selectById(configId);
        list.add(config);
    }
    boolean flag = baseMapper.deleteBatchIds(ids) > 0;
    if (flag) {
        list.stream().forEach(sysOssConfig -> {
            RedisUtils.deleteObject(getCacheKey(sysOssConfig.getConfigKey()));
        });
    }
    return flag;
}
Also used : SysOssConfig(com.ruoyi.resource.domain.SysOssConfig) ServiceException(com.ruoyi.common.core.exception.ServiceException)

Example 42 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysOssServiceImpl method upload.

@Override
public SysOss upload(MultipartFile file) {
    String originalfileName = file.getOriginalFilename();
    String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
    OssClient storage = OssFactory.instance();
    UploadResult uploadResult;
    try {
        uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
    } catch (IOException e) {
        throw new ServiceException(e.getMessage());
    }
    // 保存文件信息
    SysOss oss = new SysOss();
    oss.setUrl(uploadResult.getUrl());
    oss.setFileSuffix(suffix);
    oss.setFileName(uploadResult.getFilename());
    oss.setOriginalName(originalfileName);
    oss.setService(storage.getConfigKey());
    baseMapper.insert(oss);
    return oss;
}
Also used : SysOss(com.ruoyi.resource.domain.SysOss) OssClient(com.ruoyi.common.oss.core.OssClient) ServiceException(com.ruoyi.common.core.exception.ServiceException) UploadResult(com.ruoyi.common.oss.entity.UploadResult) IOException(java.io.IOException)

Example 43 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysConfigServiceImpl method deleteConfigByIds.

/**
 * 批量删除参数信息
 *
 * @param configIds 需要删除的参数ID
 */
@Override
public void deleteConfigByIds(Long[] configIds) {
    for (Long configId : configIds) {
        SysConfig config = selectConfigById(configId);
        if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
            throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
        }
        RedisUtils.deleteObject(getCacheKey(config.getConfigKey()));
    }
    baseMapper.deleteBatchIds(Arrays.asList(configIds));
}
Also used : SysConfig(com.ruoyi.system.domain.SysConfig) ServiceException(com.ruoyi.common.core.exception.ServiceException)

Example 44 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysDeptServiceImpl method insertDept.

/**
 * 新增保存部门信息
 *
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int insertDept(SysDept dept) {
    SysDept info = baseMapper.selectById(dept.getParentId());
    // 如果父节点不为正常状态,则不允许新增子节点
    if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
        throw new ServiceException("部门停用,不允许新增");
    }
    dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
    return baseMapper.insert(dept);
}
Also used : ServiceException(com.ruoyi.common.core.exception.ServiceException) SysDept(com.ruoyi.system.api.domain.SysDept)

Example 45 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysDeptServiceImpl method checkDeptDataScope.

/**
 * 校验部门是否有数据权限
 *
 * @param deptId 部门id
 */
@Override
public void checkDeptDataScope(Long deptId) {
    if (!LoginHelper.isAdmin()) {
        SysDept dept = new SysDept();
        dept.setDeptId(deptId);
        List<SysDept> depts = this.selectDeptList(dept);
        if (CollUtil.isEmpty(depts)) {
            throw new ServiceException("没有权限访问部门数据!");
        }
    }
}
Also used : ServiceException(com.ruoyi.common.core.exception.ServiceException) SysDept(com.ruoyi.system.api.domain.SysDept)

Aggregations

ServiceException (com.ruoyi.common.core.exception.ServiceException)49 IOException (java.io.IOException)10 GenTable (com.ruoyi.gen.domain.GenTable)9 SysUser (com.ruoyi.system.api.domain.SysUser)9 Transactional (org.springframework.transaction.annotation.Transactional)7 GenTableColumn (com.ruoyi.gen.domain.GenTableColumn)6 SysDept (com.ruoyi.system.api.domain.SysDept)6 SysRole (com.ruoyi.system.api.domain.SysRole)6 StringWriter (java.io.StringWriter)6 Template (org.apache.velocity.Template)6 VelocityContext (org.apache.velocity.VelocityContext)6 File (java.io.File)5 JSONObject (com.alibaba.fastjson.JSONObject)4 SysOss (com.ruoyi.resource.domain.SysOss)4 LoginUser (com.ruoyi.system.api.model.LoginUser)4 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 Constants (com.ruoyi.common.core.constant.Constants)3 GenConstants (com.ruoyi.common.core.constant.GenConstants)3 StringUtils (com.ruoyi.common.core.utils.StringUtils)3 GenTableColumnMapper (com.ruoyi.gen.mapper.GenTableColumnMapper)3