Search in sources :

Example 1 with Blog

use of com.moxi.mogublog.commons.entity.Blog in project mogu_blog_v2 by moxi624.

the class ElasticSearchRestApi method addElasticSearchIndexByUid.

@ApiOperation(value = "ElasticSearch通过博客Uid添加索引", notes = "添加博客", response = String.class)
@PostMapping("/addElasticSearchIndexByUid")
public String addElasticSearchIndexByUid(@RequestParam(required = true) String uid) {
    String result = webFeignClient.getBlogByUid(uid);
    Blog eblog = WebUtils.getData(result, Blog.class);
    if (eblog == null) {
        return ResultUtil.result(SysConf.ERROR, MessageConf.INSERT_FAIL);
    }
    ESBlogIndex blog = searchService.buidBlog(eblog);
    blogRepository.save(blog);
    return ResultUtil.result(SysConf.SUCCESS, MessageConf.INSERT_SUCCESS);
}
Also used : ESBlogIndex(com.moxi.mogublog.search.pojo.ESBlogIndex) Blog(com.moxi.mogublog.commons.entity.Blog) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with Blog

use of com.moxi.mogublog.commons.entity.Blog in project mogu_blog_v2 by moxi624.

the class CommentServiceImpl method getPageList.

@Override
public IPage<Comment> getPageList(CommentVO commentVO) {
    QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
    if (StringUtils.isNotEmpty(commentVO.getKeyword()) && !StringUtils.isEmpty(commentVO.getKeyword().trim())) {
        queryWrapper.like(SQLConf.CONTENT, commentVO.getKeyword().trim());
    }
    if (commentVO.getType() != null) {
        queryWrapper.eq(SQLConf.TYPE, commentVO.getType());
    }
    if (StringUtils.isNotEmpty(commentVO.getSource()) && !SysConf.ALL.equals(commentVO.getSource())) {
        queryWrapper.eq(SQLConf.SOURCE, commentVO.getSource());
    }
    if (StringUtils.isNotEmpty(commentVO.getUserName())) {
        String userName = commentVO.getUserName();
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.like(SQLConf.NICK_NAME, userName);
        userQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        List<User> list = userService.list(userQueryWrapper);
        if (list.size() > 0) {
            List<String> userUid = new ArrayList<>();
            list.forEach(item -> {
                userUid.add(item.getUid());
            });
            queryWrapper.in(SQLConf.USER_UID, userUid);
        } else {
            // 当没有查询到用户时,默认UID
            queryWrapper.in(SQLConf.USER_UID, SysConf.DEFAULT_UID);
        }
    }
    Page<Comment> page = new Page<>();
    page.setCurrent(commentVO.getCurrentPage());
    page.setSize(commentVO.getPageSize());
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
    IPage<Comment> pageList = commentService.page(page, queryWrapper);
    List<Comment> commentList = pageList.getRecords();
    Set<String> userUidSet = new HashSet<>();
    Set<String> blogUidSet = new HashSet<>();
    commentList.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getUserUid())) {
            userUidSet.add(item.getUserUid());
        }
        if (StringUtils.isNotEmpty(item.getToUserUid())) {
            userUidSet.add(item.getToUserUid());
        }
        if (StringUtils.isNotEmpty(item.getBlogUid())) {
            blogUidSet.add(item.getBlogUid());
        }
    });
    // 获取博客
    Collection<Blog> blogList = new ArrayList<>();
    if (blogUidSet.size() > 0) {
        blogList = blogService.listByIds(blogUidSet);
    }
    Map<String, Blog> blogMap = new HashMap<>();
    blogList.forEach(item -> {
        // 评论管理并不需要查看博客内容,因此将其排除
        item.setContent("");
        blogMap.put(item.getUid(), item);
    });
    // 获取头像
    Collection<User> userCollection = new ArrayList<>();
    if (userUidSet.size() > 0) {
        userCollection = userService.listByIds(userUidSet);
    }
    final StringBuffer fileUids = new StringBuffer();
    userCollection.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getAvatar())) {
            fileUids.append(item.getAvatar() + SysConf.FILE_SEGMENTATION);
        }
    });
    String pictureList = null;
    if (fileUids != null) {
        pictureList = this.pictureFeignClient.getPicture(fileUids.toString(), SysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureList);
    Map<String, String> pictureMap = new HashMap<>();
    picList.forEach(item -> {
        pictureMap.put(item.get(SQLConf.UID).toString(), item.get(SQLConf.URL).toString());
    });
    Map<String, User> userMap = new HashMap<>();
    userCollection.forEach(item -> {
        // 判断头像是否为空
        if (pictureMap.get(item.getAvatar()) != null) {
            item.setPhotoUrl(pictureMap.get(item.getAvatar()));
        }
        userMap.put(item.getUid(), item);
    });
    for (Comment item : commentList) {
        try {
            ECommentSource commentSource = ECommentSource.valueOf(item.getSource());
            item.setSourceName(commentSource.getName());
        } catch (Exception e) {
            log.error("ECommentSource 转换异常");
        }
        if (StringUtils.isNotEmpty(item.getUserUid())) {
            item.setUser(userMap.get(item.getUserUid()));
        }
        if (StringUtils.isNotEmpty(item.getToUserUid())) {
            item.setToUser(userMap.get(item.getToUserUid()));
        }
        if (StringUtils.isNotEmpty(item.getBlogUid())) {
            item.setBlog(blogMap.get(item.getBlogUid()));
        }
    }
    pageList.setRecords(commentList);
    return pageList;
}
Also used : User(com.moxi.mogublog.commons.entity.User) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) ECommentSource(com.moxi.mougblog.base.enums.ECommentSource) Blog(com.moxi.mogublog.commons.entity.Blog) Comment(com.moxi.mogublog.commons.entity.Comment) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) DeleteException(com.moxi.mougblog.base.exception.exceptionType.DeleteException)

Example 3 with Blog

use of com.moxi.mogublog.commons.entity.Blog in project mogu_blog_v2 by moxi624.

the class FreemarkerController method setBlog.

/**
 * 设置博客的分类标签和内容
 *
 * @param list
 * @return
 */
private List<Blog> setBlog(List<Blog> list) {
    final StringBuffer fileUids = new StringBuffer();
    List<String> sortUids = new ArrayList<>();
    List<String> tagUids = new ArrayList<>();
    list.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            fileUids.append(item.getFileUid() + SysConf.FILE_SEGMENTATION);
        }
        if (StringUtils.isNotEmpty(item.getBlogSortUid())) {
            sortUids.add(item.getBlogSortUid());
        }
        if (StringUtils.isNotEmpty(item.getTagUid())) {
            tagUids.add(item.getTagUid());
        }
    });
    String pictureList = null;
    if (fileUids != null) {
        pictureList = this.pictureFeignClient.getPicture(fileUids.toString(), SysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureList);
    Collection<BlogSort> sortList = new ArrayList<>();
    Collection<Tag> tagList = new ArrayList<>();
    if (sortUids.size() > 0) {
        sortList = blogSortService.listByIds(sortUids);
    }
    if (tagUids.size() > 0) {
        tagList = tagService.listByIds(tagUids);
    }
    Map<String, BlogSort> sortMap = new HashMap<>();
    Map<String, Tag> tagMap = new HashMap<>();
    Map<String, String> pictureMap = new HashMap<>();
    sortList.forEach(item -> {
        sortMap.put(item.getUid(), item);
    });
    tagList.forEach(item -> {
        tagMap.put(item.getUid(), item);
    });
    picList.forEach(item -> {
        pictureMap.put(item.get(SQLConf.UID).toString(), item.get(SQLConf.URL).toString());
    });
    for (Blog item : list) {
        // 设置分类
        if (StringUtils.isNotEmpty(item.getBlogSortUid())) {
            item.setBlogSort(sortMap.get(item.getBlogSortUid()));
        }
        // 获取标签
        if (StringUtils.isNotEmpty(item.getTagUid())) {
            List<String> tagUidsTemp = StringUtils.changeStringToString(item.getTagUid(), SysConf.FILE_SEGMENTATION);
            List<Tag> tagListTemp = new ArrayList<Tag>();
            tagUidsTemp.forEach(tag -> {
                tagListTemp.add(tagMap.get(tag));
            });
            item.setTagList(tagListTemp);
        }
        // 获取图片
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            List<String> pictureUidsTemp = StringUtils.changeStringToString(item.getFileUid(), SysConf.FILE_SEGMENTATION);
            List<String> pictureListTemp = new ArrayList<>();
            pictureUidsTemp.forEach(picture -> {
                pictureListTemp.add(pictureMap.get(picture));
            });
            item.setPhotoList(pictureListTemp);
        }
    }
    return list;
}
Also used : BlogSort(com.moxi.mogublog.commons.entity.BlogSort) Tag(com.moxi.mogublog.commons.entity.Tag) Blog(com.moxi.mogublog.commons.entity.Blog)

Example 4 with Blog

use of com.moxi.mogublog.commons.entity.Blog in project mogu_blog_v2 by moxi624.

the class FreemarkerController method generateHtml.

/**
 * 生成静态文件
 *
 * @throws IOException
 * @throws TemplateException
 */
public void generateHtml(String uid) {
    try {
        // 创建配置类
        Configuration configuration = new Configuration(Configuration.getVersion());
        String classpath = this.getClass().getResource("/").getPath();
        // 设置模板路径
        configuration.setDirectoryForTemplateLoading(new File(classpath + "/templates/"));
        // 设置字符集
        configuration.setDefaultEncoding("utf-8");
        // 加载模板
        Template template = configuration.getTemplate("info.ftl");
        // 数据模型
        Map map = new HashMap();
        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);
        map.put("vueWebBasePath", "http://localhost:9527/#/");
        map.put("webBasePath", "http://localhost:8603");
        map.put("staticBasePath", "http://localhost:8600");
        map.put("webConfig", webConfigService.getWebConfig());
        map.put("blog", blogService.getBlogByUid(uid));
        map.put("sameBlog", sameBlog);
        map.put("hotBlogList", blogService.getBlogListByTop(SysConf.FIVE));
        // 静态化
        String content = FreeMarkerTemplateUtils.processTemplateIntoString(template, map);
        InputStream inputStream = IOUtils.toInputStream(content);
        // 输出文件
        String savePath = fileUploadPath + "/blog/page/" + uid + ".html";
        FileOutputStream fileOutputStream = new FileOutputStream(new File(savePath));
        int copy = IOUtils.copy(inputStream, fileOutputStream);
    } catch (Exception e) {
        e.getMessage();
    }
}
Also used : Configuration(freemarker.template.Configuration) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Blog(com.moxi.mogublog.commons.entity.Blog) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) Template(freemarker.template.Template)

Example 5 with Blog

use of com.moxi.mogublog.commons.entity.Blog 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";
}
Also used : SystemConfig(com.moxi.mogublog.commons.entity.SystemConfig) Blog(com.moxi.mogublog.commons.entity.Blog) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Blog (com.moxi.mogublog.commons.entity.Blog)9 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)5 SystemConfig (com.moxi.mogublog.commons.entity.SystemConfig)2 Configuration (freemarker.template.Configuration)2 Template (freemarker.template.Template)2 TemplateException (freemarker.template.TemplateException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 BlogSort (com.moxi.mogublog.commons.entity.BlogSort)1 Comment (com.moxi.mogublog.commons.entity.Comment)1 Picture (com.moxi.mogublog.commons.entity.Picture)1 SubjectItem (com.moxi.mogublog.commons.entity.SubjectItem)1 Tag (com.moxi.mogublog.commons.entity.Tag)1 User (com.moxi.mogublog.commons.entity.User)1