Search in sources :

Example 1 with ServiceException

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

the class GenTableServiceImpl method generatorCode.

/**
 * 生成代码(自定义路径)
 *
 * @param tableName 表名称
 */
@Override
public void generatorCode(String tableName) {
    // 查询表信息
    GenTable table = genTableMapper.selectGenTableByName(tableName);
    // 设置主子表信息
    setSubTable(table);
    // 设置主键列信息
    setPkColumn(table);
    VelocityInitializer.initVelocity();
    VelocityContext context = VelocityUtils.prepareContext(table);
    // 获取模板列表
    List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
    for (String template : templates) {
        if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
            // 渲染模板
            StringWriter sw = new StringWriter();
            Template tpl = Velocity.getTemplate(template, Constants.UTF8);
            tpl.merge(context, sw);
            try {
                String path = getGenPath(table, template);
                FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
            } catch (IOException e) {
                throw new ServiceException("渲染模板失败,表名:" + table.getTableName());
            }
        }
    }
}
Also used : StringWriter(java.io.StringWriter) ServiceException(com.ruoyi.common.core.exception.ServiceException) GenTable(com.ruoyi.gen.domain.GenTable) VelocityContext(org.apache.velocity.VelocityContext) IOException(java.io.IOException) File(java.io.File) Template(org.apache.velocity.Template)

Example 2 with ServiceException

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

the class SysDictTypeServiceImpl method deleteDictTypeByIds.

/**
 * 批量删除字典类型信息
 *
 * @param dictIds 需要删除的字典ID
 */
@Override
public void deleteDictTypeByIds(Long[] dictIds) {
    for (Long dictId : dictIds) {
        SysDictType dictType = selectDictTypeById(dictId);
        if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) {
            throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
        }
        dictTypeMapper.deleteDictTypeById(dictId);
        DictUtils.removeDictCache(dictType.getDictType());
    }
}
Also used : ServiceException(com.ruoyi.common.core.exception.ServiceException) SysDictType(com.ruoyi.system.api.domain.SysDictType)

Example 3 with ServiceException

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

the class SysDeptServiceImpl method checkDeptDataScope.

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

Example 4 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class SysLoginService method register.

/**
 * 注册
 */
public void register(String username, String password) {
    // 用户名或密码为空 错误
    if (StringUtils.isAnyBlank(username, password)) {
        throw new ServiceException("用户/密码必须填写");
    }
    if (username.length() < UserConstants.USERNAME_MIN_LENGTH || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
        throw new ServiceException("账户长度必须在2到20个字符之间");
    }
    if (password.length() < UserConstants.PASSWORD_MIN_LENGTH || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
        throw new ServiceException("密码长度必须在5到20个字符之间");
    }
    // 注册用户信息
    SysUser sysUser = new SysUser();
    sysUser.setUserName(username);
    sysUser.setNickName(username);
    sysUser.setPassword(SecurityUtils.encryptPassword(password));
    R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
    if (R.FAIL == registerResult.getCode()) {
        throw new ServiceException(registerResult.getMsg());
    }
    recordLogininfor(username, Constants.REGISTER, "注册成功");
}
Also used : ServiceException(com.ruoyi.common.core.exception.ServiceException) SysUser(com.ruoyi.system.api.domain.SysUser)

Example 5 with ServiceException

use of com.ruoyi.common.core.exception.ServiceException in project RuoYi-Cloud-Oracle by yangzongzhuan.

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.core.exception.ServiceException) SysRole(com.ruoyi.system.api.domain.SysRole)

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