use of com.moxi.mogublog.commons.entity.SystemConfig 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.mogublog.commons.entity.SystemConfig in project mogu_blog_v2 by moxi624.
the class LoginRestApi method register.
@ApiOperation(value = "用户注册", notes = "用户注册")
@PostMapping("/register")
public String register(@Validated({ Insert.class }) @RequestBody UserVO userVO, BindingResult result) {
ThrowableUtils.checkParamArgument(result);
// 判断是否开启登录方式
Boolean isOpenLoginType = webConfigService.isOpenLoginType(RedisConf.PASSWORD);
if (!isOpenLoginType) {
return ResultUtil.result(SysConf.ERROR, "后台未开启注册功能!");
}
if (userVO.getUserName().length() < Constants.NUM_FIVE || userVO.getUserName().length() >= Constants.NUM_TWENTY || userVO.getPassWord().length() < Constants.NUM_FIVE || userVO.getPassWord().length() >= Constants.NUM_TWENTY) {
return ResultUtil.result(SysConf.ERROR, MessageConf.PARAM_INCORRECT);
}
HttpServletRequest request = RequestHolder.getRequest();
String ip = IpUtils.getIpAddr(request);
Map<String, String> map = IpUtils.getOsAndBrowserInfo(request);
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.and(wrapper -> wrapper.eq(SQLConf.USER_NAME, userVO.getUserName()).or().eq(SQLConf.EMAIL, userVO.getEmail()));
queryWrapper.eq(SysConf.STATUS, EStatus.ENABLE);
queryWrapper.last(SysConf.LIMIT_ONE);
User user = userService.getOne(queryWrapper);
if (user != null) {
return ResultUtil.result(SysConf.ERROR, MessageConf.USER_OR_EMAIL_EXIST);
}
user = new User();
user.setUserName(userVO.getUserName());
user.setNickName(userVO.getNickName());
user.setPassWord(MD5Utils.string2MD5(userVO.getPassWord()));
user.setEmail(userVO.getEmail());
// 设置账号来源,蘑菇博客
user.setSource(SysConf.MOGU);
user.setLastLoginIp(ip);
user.setBrowser(map.get(SysConf.BROWSER));
user.setOs(map.get(SysConf.OS));
// 判断是否开启用户邮件激活状态
SystemConfig systemConfig = systemConfigService.getConfig();
String openEmailActivate = systemConfig.getOpenEmailActivate();
String resultMessage = "注册成功";
if (EOpenStatus.OPEN.equals(openEmailActivate)) {
user.setStatus(EStatus.FREEZE);
} else {
// 未开启注册用户邮件激活,直接设置成激活状态
user.setStatus(EStatus.ENABLE);
}
user.insert();
// 判断是否需要发送邮件通知
if (EOpenStatus.OPEN.equals(openEmailActivate)) {
// 生成随机激活的token
String token = StringUtils.getUUID();
// 过滤密码
user.setPassWord("");
// 将从数据库查询的数据缓存到redis中,用于用户邮箱激活,1小时后过期
redisUtil.setEx(RedisConf.ACTIVATE_USER + RedisConf.SEGMENTATION + token, JsonUtils.objectToJson(user), 1, TimeUnit.HOURS);
// 发送邮件,进行账号激活
rabbitMqUtil.sendActivateEmail(user, token);
resultMessage = "注册成功,请登录邮箱进行账号激活";
}
return ResultUtil.result(SysConf.SUCCESS, resultMessage);
}
use of com.moxi.mogublog.commons.entity.SystemConfig in project mogu_blog_v2 by moxi624.
the class WechatRestApi method updateUserPhoto.
/**
* 更新用户头像
*
* @param data
* @param user
*/
private void updateUserPhoto(Map<String, Object> data, User user) {
QueryWrapper<SystemConfig> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
queryWrapper.last(SysConf.LIMIT_ONE);
SystemConfig systemConfig = systemConfigService.getOne(queryWrapper);
// 获取到头像,然后上传到自己服务器
FileVO fileVO = new FileVO();
fileVO.setAdminUid(SysConf.DEFAULT_UID);
fileVO.setUserUid(SysConf.DEFAULT_UID);
fileVO.setProjectName(SysConf.BLOG);
fileVO.setSortName(SysConf.ADMIN);
fileVO.setSystemConfig(JsonUtils.object2Map(systemConfig));
List<String> urlList = new ArrayList<>();
if (data.get("headimgurl") != null) {
urlList.add(data.get("headimgurl").toString());
}
fileVO.setUrlList(urlList);
String res = this.pictureFeignClient.uploadPicsByUrl(fileVO);
Map<String, Object> resultMap = JsonUtils.jsonToMap(res);
if (resultMap.get(SysConf.CODE) != null && SysConf.SUCCESS.equals(resultMap.get(SysConf.CODE).toString())) {
if (resultMap.get(SysConf.DATA) != null) {
List<Map<String, Object>> listMap = (List<Map<String, Object>>) resultMap.get(SysConf.DATA);
if (listMap != null && listMap.size() > 0) {
Map<String, Object> pictureMap = listMap.get(0);
String localPictureBaseUrl = systemConfig.getLocalPictureBaseUrl();
String qiNiuPictureBaseUrl = systemConfig.getQiNiuPictureBaseUrl();
String picturePriority = systemConfig.getPicturePriority();
user.setAvatar(pictureMap.get(SysConf.UID).toString());
// 判断图片优先展示
if (EOpenStatus.OPEN.equals(picturePriority)) {
// 使用七牛云
if (pictureMap.get(SysConf.QI_NIU_URL) != null && pictureMap.get(SysConf.UID) != null) {
user.setPhotoUrl(qiNiuPictureBaseUrl + pictureMap.get(SysConf.QI_NIU_URL).toString());
}
} else {
// 使用自建图片服务器
if (pictureMap.get(SysConf.PIC_URL) != null && pictureMap.get(SysConf.UID) != null) {
user.setPhotoUrl(localPictureBaseUrl + pictureMap.get(SysConf.PIC_URL).toString());
}
}
}
}
}
}
use of com.moxi.mogublog.commons.entity.SystemConfig in project mogu_blog_v2 by moxi624.
the class FreemarkerController method index.
@RequestMapping("/info/{uid}")
public String index(Map<String, Object> map, @PathVariable("uid") String uid) {
// fc98d2ae7756d2587390ae441b82f52d
List<Blog> sameBlog = blogService.getSameBlogByBlogUid(uid);
sameBlog = setBlog(sameBlog);
List<Blog> thirdBlog = blogService.getBlogListByLevel(ELevel.THIRD);
thirdBlog = setBlog(thirdBlog);
List<Blog> fourthBlog = blogService.getBlogListByLevel(ELevel.FOURTH);
fourthBlog = setBlog(fourthBlog);
SystemConfig systemConfig = systemConfigService.getConfig();
if (systemConfig == null) {
return ResultUtil.result(SysConf.ERROR, "系统配置为空");
}
map.put("vueWebBasePath", webSiteUrl);
map.put("webBasePath", webUrl);
map.put("staticBasePath", systemConfig.getLocalPictureBaseUrl());
map.put("webConfig", webConfigService.getWebConfig());
map.put("blog", blogService.getBlogByUid(uid));
map.put("sameBlog", sameBlog);
map.put("thirdBlogList", thirdBlog);
map.put("fourthBlogList", fourthBlog);
map.put("fourthBlogList", fourthBlog);
map.put("hotBlogList", blogService.getBlogListByTop(SysConf.FIVE));
return "info";
}
use of com.moxi.mogublog.commons.entity.SystemConfig in project mogu_blog_v2 by moxi624.
the class AuthRestApi method updateUserPhoto.
/**
* 更新用户头像
*
* @param data
* @param user
*/
private void updateUserPhoto(Map<String, Object> data, User user) {
QueryWrapper<SystemConfig> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
queryWrapper.last(SysConf.LIMIT_ONE);
SystemConfig systemConfig = systemConfigService.getOne(queryWrapper);
// 获取到头像,然后上传到自己服务器
FileVO fileVO = new FileVO();
fileVO.setAdminUid(SysConf.DEFAULT_UID);
fileVO.setUserUid(SysConf.DEFAULT_UID);
fileVO.setProjectName(SysConf.BLOG);
fileVO.setSortName(SysConf.ADMIN);
fileVO.setSystemConfig(JsonUtils.object2Map(systemConfig));
List<String> urlList = new ArrayList<>();
if (data.get(SysConf.AVATAR) != null) {
urlList.add(data.get(SysConf.AVATAR).toString());
} else if (data.get(SysConf.AVATAR_URL) != null) {
urlList.add(data.get(SysConf.AVATAR_URL).toString());
}
fileVO.setUrlList(urlList);
String res = this.pictureFeignClient.uploadPicsByUrl(fileVO);
Map<String, Object> resultMap = JsonUtils.jsonToMap(res);
if (resultMap.get(SysConf.CODE) != null && SysConf.SUCCESS.equals(resultMap.get(SysConf.CODE).toString())) {
if (resultMap.get(SysConf.DATA) != null) {
List<Map<String, Object>> listMap = (List<Map<String, Object>>) resultMap.get(SysConf.DATA);
if (listMap != null && listMap.size() > 0) {
Map<String, Object> pictureMap = listMap.get(0);
String localPictureBaseUrl = systemConfig.getLocalPictureBaseUrl();
String qiNiuPictureBaseUrl = systemConfig.getQiNiuPictureBaseUrl();
String picturePriority = systemConfig.getPicturePriority();
user.setAvatar(pictureMap.get(SysConf.UID).toString());
// 判断图片优先展示
if (EOpenStatus.OPEN.equals(picturePriority)) {
// 使用七牛云
if (pictureMap.get(SysConf.QI_NIU_URL) != null && pictureMap.get(SysConf.UID) != null) {
user.setPhotoUrl(qiNiuPictureBaseUrl + pictureMap.get(SysConf.QI_NIU_URL).toString());
}
} else {
// 使用自建图片服务器
if (pictureMap.get(SysConf.PIC_URL) != null && pictureMap.get(SysConf.UID) != null) {
user.setPhotoUrl(localPictureBaseUrl + pictureMap.get(SysConf.PIC_URL).toString());
}
}
}
}
}
}
Aggregations