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;
}
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;
}
}
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;
}
}
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;
}
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;
}
Aggregations