Search in sources :

Example 1 with Comment

use of com.dimple.project.blog.domain.Comment in project DimpleBlog by martin-chips.

the class CommentServiceImpl method selectCommentListByPageId.

@Override
public List<Comment> selectCommentListByPageId(Long id) {
    // 查询获取所有的comment
    List<Comment> commentList = commentMapper.selectCommentListByPageId(id);
    List<Comment> result = commentList.stream().filter(e -> e.getParentId() == null).collect(Collectors.toList());
    // CommentId和NickName的映射Map
    Map<Long, String> commentIdAndNickNameMap = commentList.stream().collect(Collectors.toMap(Comment::getId, Comment::getNickName));
    for (Comment comment : result) {
        Long commentId = comment.getId();
        comment.setSubCommentList(commentList.stream().filter(e -> commentId.equals(e.getParentId())).collect(Collectors.toList()));
        // 设置replyNickName
        if (ObjectUtils.isNotEmpty(comment.getSubCommentList())) {
            for (Comment temp : comment.getSubCommentList()) {
                if (temp.getReplyId() != null) {
                    temp.setReplyNickName(commentIdAndNickNameMap.get(temp.getReplyId()));
                }
            }
        }
    }
    return result;
}
Also used : Comment(com.dimple.project.blog.domain.Comment) StringUtils(com.dimple.common.utils.StringUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) CommentService(com.dimple.project.blog.service.CommentService) Collectors(java.util.stream.Collectors) AddressUtils(com.dimple.common.utils.ip.AddressUtils) UserAgent(eu.bitwalker.useragentutils.UserAgent) List(java.util.List) ConvertUtils(com.dimple.common.utils.ConvertUtils) Service(org.springframework.stereotype.Service) SecurityUtils(com.dimple.common.utils.SecurityUtils) Map(java.util.Map) IpUtils(com.dimple.common.utils.ip.IpUtils) ObjectUtils(com.dimple.common.utils.ObjectUtils) CommentMapper(com.dimple.project.blog.mapper.CommentMapper) ServletUtils(com.dimple.common.utils.ServletUtils) Comment(com.dimple.project.blog.domain.Comment)

Example 2 with Comment

use of com.dimple.project.blog.domain.Comment in project DimpleBlog by martin-chips.

the class AddressUpdateTask method updateCommentAddress.

private String updateCommentAddress() {
    List<Comment> commentList = commentMapper.selectCommentList(new Comment());
    Integer count = 0;
    for (Comment comment : commentList) {
        String ip = comment.getIp();
        if (StringUtils.isNotEmpty(ip)) {
            count++;
            String cityInfoByIp = AddressUtils.getCityInfoByIp(ip);
            comment.setLocation(cityInfoByIp);
            commentMapper.updateComment(comment);
        }
    }
    return "Comment总数:" + commentList.size() + ";更新总数:" + count;
}
Also used : Comment(com.dimple.project.blog.domain.Comment)

Example 3 with Comment

use of com.dimple.project.blog.domain.Comment in project DimpleBlog by martin-chips.

the class FrontServiceImpl method selectCommentListByPageId.

@Override
public List<Comment> selectCommentListByPageId(Long id) {
    // 查询获取所有的comment
    List<Comment> commentList = frontMapper.selectCommentListByPageId(id);
    List<Comment> result = commentList.stream().filter(e -> e.getParentId() == null).collect(Collectors.toList());
    // CommentId和NickName的映射Map
    Map<Long, String> commentIdAndNickNameMap = commentList.stream().collect(Collectors.toMap(Comment::getId, Comment::getNickName));
    for (Comment comment : result) {
        Long commentId = comment.getId();
        comment.setSubCommentList(commentList.stream().filter(e -> commentId.equals(e.getParentId())).collect(Collectors.toList()));
        // 设置replyNickName
        if (ObjectUtils.isNotEmpty(comment.getSubCommentList())) {
            for (Comment temp : comment.getSubCommentList()) {
                if (temp.getReplyId() != null) {
                    temp.setReplyNickName(commentIdAndNickNameMap.get(temp.getReplyId()));
                }
            }
        }
    }
    return result;
}
Also used : Notice(com.dimple.project.system.domain.Notice) AsyncManager(com.dimple.framework.manager.AsyncManager) Cacheable(org.springframework.cache.annotation.Cacheable) Autowired(org.springframework.beans.factory.annotation.Autowired) Tag(com.dimple.project.blog.domain.Tag) CacheConstants(com.dimple.common.enums.CacheConstants) Config(com.dimple.project.system.domain.Config) AddressUtils(com.dimple.common.utils.ip.AddressUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) Blog(com.dimple.project.blog.domain.Blog) EmailService(com.dimple.project.common.service.EmailService) ObjectUtils(com.dimple.common.utils.ObjectUtils) TimeType(com.dimple.framework.config.redis.TimeType) ServletUtils(com.dimple.common.utils.ServletUtils) Comment(com.dimple.project.blog.domain.Comment) Link(com.dimple.project.system.domain.Link) AsyncFactory(com.dimple.framework.manager.factory.AsyncFactory) Collectors(java.util.stream.Collectors) CacheExpire(com.dimple.framework.config.redis.CacheExpire) UserAgent(eu.bitwalker.useragentutils.UserAgent) List(java.util.List) SecurityUtils(com.dimple.common.utils.SecurityUtils) FrontService(com.dimple.project.front.service.FrontService) IpUtils(com.dimple.common.utils.ip.IpUtils) FrontMapper(com.dimple.project.front.mapper.FrontMapper) Category(com.dimple.project.common.domain.Category) BlogQuery(com.dimple.project.front.domain.BlogQuery) Carousel(com.dimple.project.system.domain.Carousel) ReplayEmail(com.dimple.project.common.domain.ReplayEmail) Comment(com.dimple.project.blog.domain.Comment)

Example 4 with Comment

use of com.dimple.project.blog.domain.Comment in project DimpleBlog by martin-chips.

the class FrontServiceImpl method insertComment.

@Override
public int insertComment(Comment comment) {
    comment.setAdminReply(SecurityUtils.isAdmin());
    final UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
    comment.setOs(userAgent.getOperatingSystem().getName());
    comment.setBrowser(userAgent.getBrowser().getName());
    comment.setDisplay(true);
    comment.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
    comment.setLocation(AddressUtils.getCityInfoByIp(comment.getIp()));
    if (comment.getParentId() != null) {
        Comment tempComment = frontMapper.selectCommentById(comment.getParentId());
        String title = frontMapper.selectBlogTitleById(comment.getPageId());
        if (tempComment.getReply()) {
            ReplayEmail replayEmail = new ReplayEmail();
            replayEmail.setCreateTime(tempComment.getCreateTime());
            replayEmail.setOriginContent(tempComment.getHtmlContent());
            replayEmail.setReplyContent(comment.getHtmlContent());
            replayEmail.setUrl(comment.getUrl());
            replayEmail.setTitle(title);
            AsyncManager.me().execute(AsyncFactory.sendReplyEmail(comment.getUrl(), comment.getHtmlContent(), comment.getNickName(), tempComment.getEmail(), replayEmail));
        }
    }
    return frontMapper.insertComment(comment);
}
Also used : Comment(com.dimple.project.blog.domain.Comment) ReplayEmail(com.dimple.project.common.domain.ReplayEmail) UserAgent(eu.bitwalker.useragentutils.UserAgent)

Example 5 with Comment

use of com.dimple.project.blog.domain.Comment in project DimpleBlog by martin-chips.

the class CommentController method edit.

@PreAuthorize("@permissionService.hasPermission('blog:comment:edit')")
@Log(title = "评论管理", businessType = BusinessType.UPDATE)
@PutMapping("/{id}/display/{display}")
public AjaxResult edit(@PathVariable Long id, @PathVariable Boolean display) {
    Comment comment = new Comment();
    comment.setDisplay(display);
    comment.setId(id);
    comment.setUpdateBy(SecurityUtils.getUsername());
    return toAjax(commentService.updateComment(comment));
}
Also used : Comment(com.dimple.project.blog.domain.Comment) Log(com.dimple.framework.aspectj.lang.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Comment (com.dimple.project.blog.domain.Comment)5 UserAgent (eu.bitwalker.useragentutils.UserAgent)3 ObjectUtils (com.dimple.common.utils.ObjectUtils)2 SecurityUtils (com.dimple.common.utils.SecurityUtils)2 ServletUtils (com.dimple.common.utils.ServletUtils)2 AddressUtils (com.dimple.common.utils.ip.AddressUtils)2 IpUtils (com.dimple.common.utils.ip.IpUtils)2 ReplayEmail (com.dimple.project.common.domain.ReplayEmail)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 CacheConstants (com.dimple.common.enums.CacheConstants)1 ConvertUtils (com.dimple.common.utils.ConvertUtils)1 StringUtils (com.dimple.common.utils.StringUtils)1 Log (com.dimple.framework.aspectj.lang.annotation.Log)1 CacheExpire (com.dimple.framework.config.redis.CacheExpire)1 TimeType (com.dimple.framework.config.redis.TimeType)1 AsyncManager (com.dimple.framework.manager.AsyncManager)1