Search in sources :

Example 1 with QueryException

use of com.moxi.mougblog.base.exception.exceptionType.QueryException in project mogu_blog_v2 by moxi624.

the class SysParamsServiceImpl method getSysParamsValueByKey.

@Override
public String getSysParamsValueByKey(String paramsKey) {
    // 判断Redis中是否包含该key的数据
    String redisKey = RedisConf.SYSTEM_PARAMS + RedisConf.SEGMENTATION + paramsKey;
    String paramsValue = redisUtil.get(redisKey);
    // 如果Redis中不存在,那么从数据库中获取
    if (StringUtils.isEmpty(paramsValue)) {
        SysParams sysParams = sysParamsService.getSysParamsByKey(paramsKey);
        // 如果数据库也不存在,将抛出异常【需要到找到 doc/数据库脚本 更新数据库中的 t_sys_params表】
        if (sysParams == null || StringUtils.isEmpty(sysParams.getParamsValue())) {
            throw new QueryException(ErrorCode.PLEASE_CONFIGURE_SYSTEM_PARAMS, MessageConf.PLEASE_CONFIGURE_SYSTEM_PARAMS);
        }
        paramsValue = sysParams.getParamsValue();
        redisUtil.set(redisKey, paramsValue);
    }
    return paramsValue;
}
Also used : QueryException(com.moxi.mougblog.base.exception.exceptionType.QueryException) SysParams(com.moxi.mogublog.commons.entity.SysParams)

Example 2 with QueryException

use of com.moxi.mougblog.base.exception.exceptionType.QueryException in project mogu_blog_v2 by moxi624.

the class SystemConfigServiceImpl method getConfig.

@Override
public SystemConfig getConfig() {
    // 从Redis中获取系统配置
    String systemConfigJson = redisUtil.get(RedisConf.SYSTEM_CONFIG);
    if (StringUtils.isEmpty(systemConfigJson)) {
        QueryWrapper<SystemConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
        queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        queryWrapper.last(SysConf.LIMIT_ONE);
        SystemConfig systemConfig = systemConfigService.getOne(queryWrapper);
        if (systemConfig == null) {
            throw new QueryException(MessageConf.SYSTEM_CONFIG_IS_NOT_EXIST);
        } else {
            // 将系统配置存入Redis中【设置过期时间24小时】
            redisUtil.setEx(RedisConf.SYSTEM_CONFIG, JsonUtils.objectToJson(systemConfig), 24, TimeUnit.HOURS);
        }
        return systemConfig;
    } else {
        SystemConfig systemConfig = JsonUtils.jsonToPojo(systemConfigJson, SystemConfig.class);
        if (systemConfig == null) {
            throw new QueryException(ErrorCode.QUERY_DEFAULT_ERROR, "系统配置转换错误,请检查系统配置,或者清空Redis后重试!");
        }
        return systemConfig;
    }
}
Also used : SystemConfig(com.moxi.mogublog.commons.entity.SystemConfig) QueryException(com.moxi.mougblog.base.exception.exceptionType.QueryException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Example 3 with QueryException

use of com.moxi.mougblog.base.exception.exceptionType.QueryException in project mogu_blog_v2 by moxi624.

the class WebConfigServiceImpl method isOpenLoginType.

@Override
public Boolean isOpenLoginType(String loginType) {
    String loginTypeJson = redisUtil.get(RedisConf.LOGIN_TYPE + Constants.SYMBOL_COLON + loginType);
    // 判断redis中是否包含该登录记录
    if (StringUtils.isNotEmpty(loginTypeJson)) {
        // 如果Redis中有内容,表示开启该登录方式
        return true;
    } else if (loginTypeJson != null && loginTypeJson.length() == 0) {
        // 如果内容为空串,表示没有开启该登录方式
        return false;
    }
    QueryWrapper<WebConfig> queryWrapper = new QueryWrapper<>();
    queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
    WebConfig webConfig = webConfigService.getOne(queryWrapper);
    if (webConfig == null) {
        throw new QueryException(ErrorCode.SYSTEM_CONFIG_IS_NOT_EXIST, MessageConf.SYSTEM_CONFIG_IS_NOT_EXIST);
    }
    // 过滤一些不需要显示的用户账号信息
    String loginTypeListJson = webConfig.getLoginTypeList();
    // 判断哪些联系方式需要显示出来
    List<String> loginTypeList = JsonUtils.jsonToList(loginTypeListJson, String.class);
    for (String item : loginTypeList) {
        if (ELoginType.PASSWORD.getCode().equals(item)) {
            redisUtil.set(RedisConf.LOGIN_TYPE + Constants.SYMBOL_COLON + RedisConf.PASSWORD, ELoginType.PASSWORD.getName());
        }
        if (ELoginType.GITEE.getCode().equals(item)) {
            redisUtil.set(RedisConf.LOGIN_TYPE + Constants.SYMBOL_COLON + RedisConf.GITEE, ELoginType.GITEE.getName());
        }
        if (ELoginType.GITHUB.getCode().equals(item)) {
            redisUtil.set(RedisConf.LOGIN_TYPE + Constants.SYMBOL_COLON + RedisConf.GITHUB, ELoginType.GITHUB.getName());
        }
        if (ELoginType.QQ.getCode().equals(item)) {
            redisUtil.set(RedisConf.LOGIN_TYPE + Constants.SYMBOL_COLON + RedisConf.QQ, ELoginType.QQ.getName());
        }
        if (ELoginType.WECHAT.getCode().equals(item)) {
            redisUtil.set(RedisConf.LOGIN_TYPE + Constants.SYMBOL_COLON + RedisConf.WECHAT, ELoginType.WECHAT.getName());
        }
    }
    // 再次判断该登录方式是否开启
    loginTypeJson = redisUtil.get(RedisConf.LOGIN_TYPE + Constants.SYMBOL_COLON + loginType);
    if (StringUtils.isNotEmpty(loginTypeJson)) {
        return true;
    } else {
        // 设置一个为空的字符串【防止缓存穿透】
        redisUtil.set(RedisConf.LOGIN_TYPE + Constants.SYMBOL_COLON + loginType, "");
        return false;
    }
}
Also used : QueryException(com.moxi.mougblog.base.exception.exceptionType.QueryException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) WebConfig(com.moxi.mogublog.commons.entity.WebConfig)

Example 4 with QueryException

use of com.moxi.mougblog.base.exception.exceptionType.QueryException in project mogu_blog_v2 by moxi624.

the class WebUtil method getPicture.

/**
 * 格式化数据获取图片列表
 *
 * @param result
 * @return
 */
public List<String> getPicture(String result) {
    String picturePriority = "";
    String localPictureBaseUrl = "";
    String qiNiuPictureBaseUrl = "";
    String minioPictureBaseUrl = "";
    // 从Redis中获取系统配置
    String systemConfigJson = redisUtil.get(RedisConf.SYSTEM_CONFIG);
    if (StringUtils.isEmpty(systemConfigJson)) {
        QueryWrapper<SystemConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        SystemConfig systemConfig = systemConfigService.getOne(queryWrapper);
        if (systemConfig == null) {
            throw new QueryException(MessageConf.SYSTEM_CONFIG_IS_NOT_EXIST);
        } else {
            // 将系统配置存入Redis中【设置过期时间24小时】
            redisUtil.setEx(RedisConf.SYSTEM_CONFIG, JsonUtils.objectToJson(systemConfig), 24, TimeUnit.HOURS);
        }
        picturePriority = systemConfig.getPicturePriority();
        localPictureBaseUrl = systemConfig.getLocalPictureBaseUrl();
        qiNiuPictureBaseUrl = systemConfig.getQiNiuPictureBaseUrl();
        minioPictureBaseUrl = systemConfig.getMinioPictureBaseUrl();
    } else {
        SystemConfig systemConfig = JsonUtils.jsonToPojo(systemConfigJson, SystemConfig.class);
        if (systemConfig == null) {
            throw new QueryException(ErrorCode.QUERY_DEFAULT_ERROR, "系统配置转换错误,请检查系统配置,或者清空Redis后重试!");
        }
        picturePriority = systemConfig.getPicturePriority();
        localPictureBaseUrl = systemConfig.getLocalPictureBaseUrl();
        qiNiuPictureBaseUrl = systemConfig.getQiNiuPictureBaseUrl();
        minioPictureBaseUrl = systemConfig.getMinioPictureBaseUrl();
    }
    List<String> picUrls = new ArrayList<>();
    try {
        Map<String, Object> picMap = (Map<String, Object>) JsonUtils.jsonToObject(result, Map.class);
        if (SysConf.SUCCESS.equals(picMap.get(SysConf.CODE))) {
            List<Map<String, Object>> picData = (List<Map<String, Object>>) picMap.get(SysConf.DATA);
            if (picData.size() > 0) {
                for (int i = 0; i < picData.size(); i++) {
                    // 判断文件显示优先级【需要显示存储在哪里的图片】
                    if (EFilePriority.QI_NIU.equals(picturePriority)) {
                        picUrls.add(qiNiuPictureBaseUrl + picData.get(i).get(SysConf.QI_NIU_URL));
                    } else if (EFilePriority.MINIO.equals(picturePriority)) {
                        picUrls.add(minioPictureBaseUrl + picData.get(i).get(SysConf.MINIO_URL));
                    } else {
                        picUrls.add(localPictureBaseUrl + picData.get(i).get(SysConf.URL));
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("从Json中获取图片列表失败");
        log.error(e.getMessage());
        return picUrls;
    }
    return picUrls;
}
Also used : SystemConfig(com.moxi.mogublog.commons.entity.SystemConfig) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList) QueryException(com.moxi.mougblog.base.exception.exceptionType.QueryException) QueryException(com.moxi.mougblog.base.exception.exceptionType.QueryException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with QueryException

use of com.moxi.mougblog.base.exception.exceptionType.QueryException in project mogu_blog_v2 by moxi624.

the class WebUtil method getPictureMap.

/**
 * 获取图片,返回Map
 *
 * @param result
 * @return
 */
public List<Map<String, Object>> getPictureMap(String result) {
    String picturePriority = "";
    String localPictureBaseUrl = "";
    String qiNiuPictureBaseUrl = "";
    String minioPictureBaseUrl = "";
    // 从Redis中获取系统配置
    String systemConfigJson = redisUtil.get(RedisConf.SYSTEM_CONFIG);
    if (StringUtils.isEmpty(systemConfigJson)) {
        QueryWrapper<SystemConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        SystemConfig systemConfig = systemConfigService.getOne(queryWrapper);
        if (systemConfig == null) {
            throw new QueryException(MessageConf.SYSTEM_CONFIG_IS_NOT_EXIST);
        } else {
            // 将系统配置存入Redis中【设置过期时间24小时】
            redisUtil.setEx(RedisConf.SYSTEM_CONFIG, JsonUtils.objectToJson(systemConfig), 24, TimeUnit.HOURS);
        }
        picturePriority = systemConfig.getPicturePriority();
        localPictureBaseUrl = systemConfig.getLocalPictureBaseUrl();
        qiNiuPictureBaseUrl = systemConfig.getQiNiuPictureBaseUrl();
        minioPictureBaseUrl = systemConfig.getMinioPictureBaseUrl();
    } else {
        SystemConfig systemConfig = JsonUtils.jsonToPojo(systemConfigJson, SystemConfig.class);
        picturePriority = systemConfig.getPicturePriority();
        localPictureBaseUrl = systemConfig.getLocalPictureBaseUrl();
        qiNiuPictureBaseUrl = systemConfig.getQiNiuPictureBaseUrl();
        minioPictureBaseUrl = systemConfig.getMinioPictureBaseUrl();
    }
    List<Map<String, Object>> resultList = new ArrayList<>();
    Map<String, Object> picMap = (Map<String, Object>) JsonUtils.jsonToObject(result, Map.class);
    if (SysConf.SUCCESS.equals(picMap.get(SysConf.CODE))) {
        List<Map<String, Object>> picData = (List<Map<String, Object>>) picMap.get(SysConf.DATA);
        if (picData.size() > 0) {
            for (int i = 0; i < picData.size(); i++) {
                Map<String, Object> map = new HashMap<>();
                if (StringUtils.isEmpty(picData.get(i).get(SysConf.UID))) {
                    continue;
                }
                // 判断文件显示优先级【需要显示存储在哪里的图片】
                if (EFilePriority.QI_NIU.equals(picturePriority)) {
                    map.put(SysConf.URL, qiNiuPictureBaseUrl + picData.get(i).get(SysConf.QI_NIU_URL));
                } else if (EFilePriority.MINIO.equals(picturePriority)) {
                    map.put(SysConf.URL, minioPictureBaseUrl + picData.get(i).get(SysConf.MINIO_URL));
                } else {
                    map.put(SysConf.URL, localPictureBaseUrl + picData.get(i).get(SysConf.URL));
                }
                map.put(SysConf.UID, picData.get(i).get(SysConf.UID));
                resultList.add(map);
            }
        }
    } else if (SysConf.ERROR.equals(picMap.get(SysConf.CODE))) {
        log.error("获取图片失败,图片服务出现异常:{}", picMap.get(SysConf.MESSAGE));
    } else {
        log.error("获取图片失败");
    }
    return resultList;
}
Also used : SystemConfig(com.moxi.mogublog.commons.entity.SystemConfig) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryException(com.moxi.mougblog.base.exception.exceptionType.QueryException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

QueryException (com.moxi.mougblog.base.exception.exceptionType.QueryException)11 SystemConfig (com.moxi.mogublog.commons.entity.SystemConfig)7 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 WebConfig (com.moxi.mogublog.commons.entity.WebConfig)2 List (java.util.List)2 Map (java.util.Map)2 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)2 File (com.moxi.mogublog.commons.entity.File)1 NetworkDisk (com.moxi.mogublog.commons.entity.NetworkDisk)1 Storage (com.moxi.mogublog.commons.entity.Storage)1 SysParams (com.moxi.mogublog.commons.entity.SysParams)1 UpdateException (com.moxi.mougblog.base.exception.exceptionType.UpdateException)1 Date (java.util.Date)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1