Search in sources :

Example 31 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.

the class GenTableServiceImpl method validateEdit.

/**
 * 修改保存参数校验
 *
 * @param genTable 业务信息
 */
@Override
public void validateEdit(GenTable genTable) {
    if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
        String options = JSON.toJSONString(genTable.getParams());
        JSONObject paramsObj = JSONObject.parseObject(options);
        if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) {
            throw new ServiceException("树编码字段不能为空");
        } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) {
            throw new ServiceException("树父编码字段不能为空");
        } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
            throw new ServiceException("树名称字段不能为空");
        } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
            if (StringUtils.isEmpty(genTable.getSubTableName())) {
                throw new ServiceException("关联子表的表名不能为空");
            } else if (StringUtils.isEmpty(genTable.getSubTableFkName())) {
                throw new ServiceException("子表关联的外键名不能为空");
            }
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 32 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.

the class AuthRequestFactoryImpl method getAuthRequest.

/**
 * 获得对于AUthRequest
 *
 * @param source 登录方式
 * @return 对应AuthRequest
 */
@Override
public AuthRequestWrap getAuthRequest(String source) {
    AuthRequestWrap authRequestWrap = new AuthRequestWrap();
    AuthRequest authRequest;
    try {
        SocialPlatformType socialPlatformType = SocialPlatformType.valueOf(source.toUpperCase(Locale.ROOT));
        SocialPlatform socialPlatform = iSocialPlatformService.selectSocialPlatformByPlatform(source);
        authRequestWrap.setSocialPlatform(socialPlatform);
        AuthConfig authConfig = AuthConfig.builder().clientId(socialPlatform.getClientId()).clientSecret(socialPlatform.getSecretKey()).redirectUri(socialPlatform.getRedirectUri()).build();
        switch(socialPlatformType) {
            case QQ:
                {
                    authRequest = new AuthQqRequest(authConfig, authStateRedisCache);
                    break;
                }
            case Wechat:
                {
                    authRequest = new AuthWeChatMpRequest(authConfig, authStateRedisCache);
                    break;
                }
            default:
                {
                    throw new ServiceException("source: " + source + ",暂不支持");
                }
        }
        authRequestWrap.setAuthRequest(authRequest);
        return authRequestWrap;
    } catch (Exception e) {
        throw new ServiceException(e.getMessage());
    }
}
Also used : AuthRequest(me.zhyd.oauth.request.AuthRequest) SocialPlatform(com.ruoyi.iot.domain.SocialPlatform) AuthRequestWrap(com.ruoyi.iot.model.login.AuthRequestWrap) ServiceException(com.ruoyi.common.exception.ServiceException) SocialPlatformType(com.ruoyi.common.enums.SocialPlatformType) AuthQqRequest(me.zhyd.oauth.request.AuthQqRequest) AuthConfig(me.zhyd.oauth.config.AuthConfig) AuthWeChatMpRequest(me.zhyd.oauth.request.AuthWeChatMpRequest) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 33 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.

the class SysDictTypeServiceImpl method deleteDictTypeByIds.

/**
 * 批量删除字典类型信息
 *
 * @param dictIds 需要删除的字典ID
 * @return 结果
 */
@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.exception.ServiceException) SysDictType(com.ruoyi.common.core.domain.entity.SysDictType)

Example 34 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.

the class SysUserServiceImpl method importUser.

/**
 * 导入用户数据
 *
 * @param userList 用户数据列表
 * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
 * @param operName 操作用户
 * @return 结果
 */
@Override
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) {
    if (StringUtils.isNull(userList) || userList.size() == 0) {
        throw new ServiceException("导入用户数据不能为空!");
    }
    int successNum = 0;
    int failureNum = 0;
    StringBuilder successMsg = new StringBuilder();
    StringBuilder failureMsg = new StringBuilder();
    String password = configService.selectConfigByKey("sys.user.initPassword");
    for (SysUser user : userList) {
        try {
            // 验证是否存在这个用户
            SysUser u = userMapper.selectUserByUserName(user.getUserName());
            if (StringUtils.isNull(u)) {
                user.setPassword(SecurityUtils.encryptPassword(password));
                user.setCreateBy(operName);
                this.insertUser(user);
                successNum++;
                successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
            } else if (isUpdateSupport) {
                user.setUpdateBy(operName);
                this.updateUser(user);
                successNum++;
                successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
            } else {
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");
            }
        } catch (Exception e) {
            failureNum++;
            String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
            failureMsg.append(msg + e.getMessage());
            log.error(msg, e);
        }
    }
    if (failureNum > 0) {
        failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
        throw new ServiceException(failureMsg.toString());
    } else {
        successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
    }
    return successMsg.toString();
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysUser(com.ruoyi.common.core.domain.entity.SysUser) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 35 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.

the class SysConfigServiceImpl method deleteConfigByIds.

/**
 * 批量删除参数信息
 *
 * @param configIds 需要删除的参数ID
 * @return 结果
 */
@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()));
        }
        configMapper.deleteConfigById(configId);
        redisCache.deleteObject(getCacheKey(config.getConfigKey()));
    }
}
Also used : SysConfig(com.ruoyi.system.domain.SysConfig) ServiceException(com.ruoyi.common.exception.ServiceException)

Aggregations

ServiceException (com.ruoyi.common.exception.ServiceException)109 IOException (java.io.IOException)21 Transactional (org.springframework.transaction.annotation.Transactional)21 GenTable (com.ruoyi.generator.domain.GenTable)12 StringWriter (java.io.StringWriter)12 Template (org.apache.velocity.Template)12 VelocityContext (org.apache.velocity.VelocityContext)12 SysRole (com.ruoyi.common.core.domain.entity.SysRole)10 File (java.io.File)10 SysUser (com.ruoyi.common.core.domain.entity.SysUser)9 GenTableColumn (com.ruoyi.generator.domain.GenTableColumn)8 Before (org.aspectj.lang.annotation.Before)8 JSONObject (com.alibaba.fastjson.JSONObject)6 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)6 SysDept (com.ruoyi.common.core.domain.entity.SysDept)6 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)6 Constants (com.ruoyi.common.constant.Constants)5 GenConstants (com.ruoyi.common.constant.GenConstants)5 StringUtils (com.ruoyi.common.utils.StringUtils)5 SysOss (com.ruoyi.system.domain.SysOss)5