Search in sources :

Example 6 with Blog

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

the class PictureServiceImpl method editPicture.

@Override
public String editPicture(PictureVO pictureVO) {
    Picture picture = pictureService.getById(pictureVO.getUid());
    // 这里需要更新所有的博客,将图片替换成 裁剪的图片
    QueryWrapper<Blog> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    queryWrapper.eq(SQLConf.FILE_UID, picture.getFileUid());
    List<Blog> blogList = blogService.list(queryWrapper);
    if (blogList.size() > 0) {
        blogList.forEach(item -> {
            item.setFileUid(pictureVO.getFileUid());
        });
        blogService.updateBatchById(blogList);
        Map<String, Object> map = new HashMap<>();
        map.put(SysConf.COMMAND, SysConf.EDIT_BATCH);
        // 发送到RabbitMq
        rabbitTemplate.convertAndSend(SysConf.EXCHANGE_DIRECT, SysConf.MOGU_BLOG, map);
    }
    picture.setFileUid(pictureVO.getFileUid());
    picture.setPicName(pictureVO.getPicName());
    picture.setPictureSortUid(pictureVO.getPictureSortUid());
    picture.setUpdateTime(new Date());
    picture.updateById();
    return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Picture(com.moxi.mogublog.commons.entity.Picture) Blog(com.moxi.mogublog.commons.entity.Blog)

Example 7 with Blog

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

the class SubjectItemServiceImpl method sortByCreateTime.

@Override
public String sortByCreateTime(String subjectUid, Boolean isDesc) {
    QueryWrapper<SubjectItem> queryWrapper = new QueryWrapper();
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    queryWrapper.eq(SQLConf.SUBJECT_UID, subjectUid);
    // 查询出所有的专题列表
    List<SubjectItem> subjectItemList = subjectItemService.list(queryWrapper);
    // 获取专题中的博客uid
    List<String> blogUidList = new ArrayList<>();
    subjectItemList.forEach(item -> {
        blogUidList.add(item.getBlogUid());
    });
    if (blogUidList.size() == 0) {
        return ResultUtil.errorWithMessage(MessageConf.UPDATE_FAIL);
    }
    Collection<Blog> blogList = blogService.listByIds(blogUidList);
    List<Blog> tempBlogList = new ArrayList<>();
    // 升序排列或降序排列
    if (isDesc) {
        tempBlogList = blogList.stream().sorted(Comparator.comparing(Blog::getCreateTime).reversed()).collect(Collectors.toList());
    } else {
        tempBlogList = blogList.stream().sorted(Comparator.comparing(Blog::getCreateTime)).collect(Collectors.toList());
    }
    // 设置初始化最大的sort值
    int maxSort = tempBlogList.size();
    Map<String, Integer> subjectItemSortMap = new HashMap<>();
    for (Blog item : tempBlogList) {
        subjectItemSortMap.put(item.getUid(), maxSort--);
    }
    // 设置更新后的排序值
    for (SubjectItem item : subjectItemList) {
        item.setSort(subjectItemSortMap.get(item.getBlogUid()));
    }
    subjectItemService.updateBatchById(subjectItemList);
    return ResultUtil.successWithMessage(MessageConf.OPERATION_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) SubjectItem(com.moxi.mogublog.commons.entity.SubjectItem) Blog(com.moxi.mogublog.commons.entity.Blog)

Example 8 with Blog

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

the class FreemarkerController method getAllHtml.

/**
 * 生成所有博客的静态文件
 */
@RequestMapping("/getAllHtml")
@ResponseBody
public String getAllHtml() throws IOException {
    FileOutputStream fileOutputStream = null;
    InputStream inputStream = null;
    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");
        QueryWrapper<Blog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        queryWrapper.eq(SQLConf.IS_PUBLISH, EPublish.PUBLISH);
        List<Blog> blogList = blogService.list(queryWrapper);
        blogList = setBlog(blogList);
        Map<String, List<Blog>> blogMap = new HashMap<>();
        List<Blog> thirdBlog = new ArrayList<>();
        List<Blog> fourthBlog = new ArrayList<>();
        List<Blog> hotBlogList = blogService.getBlogListByTop(SysConf.FIVE);
        blogList.forEach(item -> {
            if (item.getLevel() == ELevel.THIRD) {
                thirdBlog.add(item);
            } else if (item.getLevel() == ELevel.FOURTH) {
                fourthBlog.add(item);
            }
            List<Blog> tempList = blogMap.get(item.getBlogSortUid());
            if (tempList != null && tempList.size() > 0) {
                tempList.add(item);
                blogMap.put(item.getBlogSortUid(), tempList);
            } else {
                List<Blog> temp = new ArrayList<>();
                temp.add(item);
                blogMap.put(item.getBlogSortUid(), temp);
            }
        });
        SystemConfig systemConfig = systemConfigService.getConfig();
        if (systemConfig == null) {
            return ResultUtil.result(SysConf.ERROR, "系统配置为空");
        }
        for (int a = 0; a < blogList.size(); a++) {
            // 数据模型
            Map map = new HashMap();
            List<Blog> sameBlog = blogMap.get(blogList.get(a).getBlogSortUid());
            map.put("vueWebBasePath", webSiteUrl);
            map.put("webBasePath", webUrl);
            map.put("staticBasePath", systemConfig.getLocalPictureBaseUrl());
            map.put("webConfig", webConfigService.getWebConfig());
            map.put("blog", blogList.get(a));
            map.put("sameBlog", sameBlog);
            map.put("thirdBlogList", thirdBlog);
            map.put("fourthBlogList", fourthBlog);
            map.put("hotBlogList", hotBlogList);
            // 静态化
            String content = FreeMarkerTemplateUtils.processTemplateIntoString(template, map);
            inputStream = IOUtils.toInputStream(content);
            // 输出文件
            String savePath = fileUploadPath + "/blog/page/" + blogList.get(a).getUid() + ".html";
            fileOutputStream = new FileOutputStream(new File(savePath));
            IOUtils.copy(inputStream, fileOutputStream);
        }
        return ResultUtil.result(SysConf.SUCCESS, "生成成功");
    } catch (Exception e) {
        e.getMessage();
    } finally {
        inputStream.close();
        fileOutputStream.close();
    }
    return ResultUtil.result(SysConf.SUCCESS, "生成失败");
}
Also used : SystemConfig(com.moxi.mogublog.commons.entity.SystemConfig) Configuration(freemarker.template.Configuration) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) InputStream(java.io.InputStream) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) Template(freemarker.template.Template) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Blog(com.moxi.mogublog.commons.entity.Blog) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with Blog

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

the class BlogContentRestApi method getBlogByUid.

@BussinessLog(value = "点击博客", behavior = EBehavior.BLOG_CONTNET)
@ApiOperation(value = "通过Uid获取博客内容", notes = "通过Uid获取博客内容")
@GetMapping("/getBlogByUid")
public String getBlogByUid(@ApiParam(name = "uid", value = "博客UID", required = false) @RequestParam(name = "uid", required = false) String uid, @ApiParam(name = "oid", value = "博客OID", required = false) @RequestParam(name = "oid", required = false, defaultValue = "0") Integer oid) {
    HttpServletRequest request = RequestHolder.getRequest();
    String ip = IpUtils.getIpAddr(request);
    if (StringUtils.isEmpty(uid) && oid == 0) {
        return ResultUtil.result(SysConf.ERROR, MessageConf.PARAM_INCORRECT);
    }
    Blog blog = null;
    if (StringUtils.isNotEmpty(uid)) {
        blog = blogService.getById(uid);
    } else {
        QueryWrapper<Blog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SysConf.OID, oid);
        queryWrapper.last(SysConf.LIMIT_ONE);
        blog = blogService.getOne(queryWrapper);
    }
    if (blog == null || blog.getStatus() == EStatus.DISABLED || EPublish.NO_PUBLISH.equals(blog.getIsPublish())) {
        return ResultUtil.result(ECode.ERROR, MessageConf.BLOG_IS_DELETE);
    }
    // 设置文章版权申明
    setBlogCopyright(blog);
    // 设置博客标签
    blogService.setTagByBlog(blog);
    // 获取分类
    blogService.setSortByBlog(blog);
    // 设置博客标题图
    setPhotoListByBlog(blog);
    // 从Redis取出数据,判断该用户是否点击过
    String jsonResult = stringRedisTemplate.opsForValue().get("BLOG_CLICK:" + ip + "#" + blog.getUid());
    if (StringUtils.isEmpty(jsonResult)) {
        // 给博客点击数增加
        Integer clickCount = blog.getClickCount() + 1;
        blog.setClickCount(clickCount);
        blog.updateById();
        // 将该用户点击记录存储到redis中, 24小时后过期
        stringRedisTemplate.opsForValue().set(RedisConf.BLOG_CLICK + Constants.SYMBOL_COLON + ip + Constants.SYMBOL_WELL + blog.getUid(), blog.getClickCount().toString(), 24, TimeUnit.HOURS);
    }
    return ResultUtil.result(SysConf.SUCCESS, blog);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Blog(com.moxi.mogublog.commons.entity.Blog) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation) BussinessLog(com.moxi.mogublog.web.annotion.log.BussinessLog)

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