CsdnUserInfoServiceImpl.java 5.0 KB
Newer Older
1 2
package com.kwan.springbootkwan.service.impl;

3 4
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 6
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
7 8 9 10
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.enums.CollectStatus;
import com.kwan.springbootkwan.enums.CommentStatus;
import com.kwan.springbootkwan.enums.LikeStatus;
11
import com.kwan.springbootkwan.mapper.CsdnUserInfoMapper;
12 13
import com.kwan.springbootkwan.service.CsdnArticleService;
import com.kwan.springbootkwan.service.CsdnCollectService;
14
import com.kwan.springbootkwan.service.CsdnUserInfoService;
15 16
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
17 18
import org.springframework.stereotype.Service;

19 20
import java.util.List;

21 22 23 24 25 26 27 28 29
/**
 * csdn用户信息(CsdnUserInfo)表服务实现类
 *
 * @author makejava
 * @since 2023-10-23 16:03:14
 */
@Service("csdnUserInfoService")
public class CsdnUserInfoServiceImpl extends ServiceImpl<CsdnUserInfoMapper, CsdnUserInfo> implements CsdnUserInfoService {

30 31 32 33 34 35 36 37 38 39 40 41 42 43

    @Autowired
    private CsdnCollectService csdnCollectService;
    @Autowired
    private CsdnArticleService csdnArticleService;

    @Override
    public void resetCurrentStatus() {
        QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        final List<CsdnUserInfo> list = this.list(wrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            for (CsdnUserInfo csdnUserInfo : list) {
                final String userName = csdnUserInfo.getUserName();
44
                final Integer commentStatus = csdnUserInfo.getCommentStatus();
45 46 47 48 49 50 51 52
                final List<BusinessInfoResponse.ArticleData.Article> articles = csdnArticleService.getArticles(userName);
                if (CollectionUtil.isNotEmpty(articles)) {
                    final BusinessInfoResponse.ArticleData.Article article = articles.get(0);
                    final String type = article.getType();
                    if (StringUtils.equals(type, "blog")) {
                        final String urlInfo = article.getUrl();
                        String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
                        final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo);
53
                        if (!collect || CommentStatus.COMMENT_TOO_FAST.getCode().equals(commentStatus)) {
54 55 56
                            csdnUserInfo.setLikeStatus(LikeStatus.UN_PROCESSED.getCode());
                            csdnUserInfo.setCollectStatus(CollectStatus.UN_PROCESSED.getCode());
                            csdnUserInfo.setCommentStatus(CommentStatus.UN_PROCESSED.getCode());
57
                            csdnUserInfo.setArticleType(type);
58 59 60 61 62 63 64
                            this.updateById(csdnUserInfo);
                        }
                    }
                }
            }
        }
    }
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

    @Override
    public void resetUserDayStatus() {
        QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        final List<CsdnUserInfo> list = this.list(wrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            for (CsdnUserInfo csdnUserInfo : list) {
                final String userName = csdnUserInfo.getUserName();
                final List<BusinessInfoResponse.ArticleData.Article> articles = csdnArticleService.getArticles(userName);
                if (CollectionUtil.isNotEmpty(articles)) {
                    final BusinessInfoResponse.ArticleData.Article article = articles.get(0);
                    final String type = article.getType();
                    if (StringUtils.equals(type, "blog")) {
                        //看看之前的状态
                        final Integer likeStatus = csdnUserInfo.getLikeStatus();
                        if (!LikeStatus.HAVE_ALREADY_LIKED.getCode().equals(likeStatus) && !LikeStatus.LIKE_SUCCESSFUL.getCode().equals(likeStatus)) {
                            csdnUserInfo.setLikeStatus(LikeStatus.UN_PROCESSED.getCode());
                        }
                        final Integer collectStatus = csdnUserInfo.getCollectStatus();
                        if (!CollectStatus.COLLECT_SUCCESSFUL.getCode().equals(collectStatus) && !CollectStatus.HAVE_ALREADY_COLLECT.getCode().equals(collectStatus)) {
                            csdnUserInfo.setCollectStatus(CollectStatus.UN_PROCESSED.getCode());
                        }
                        final Integer commentStatus = csdnUserInfo.getCommentStatus();
                        if (!CommentStatus.COMMENT_SUCCESSFUL.getCode().equals(commentStatus) && !CommentStatus.HAVE_ALREADY_COMMENT.getCode().equals(commentStatus)) {
                            csdnUserInfo.setCommentStatus(CommentStatus.UN_PROCESSED.getCode());
                        }
                        this.updateById(csdnUserInfo);
                    }
                }
            }
        }
    }
98 99
}

100