CsdnArticleInfoController.java 7.4 KB
Newer Older
1 2
package com.kwan.springbootkwan.controller;

3
import cn.hutool.core.collection.CollectionUtil;
4 5 6
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kwan.springbootkwan.entity.CsdnArticleInfo;
7
import com.kwan.springbootkwan.entity.CsdnUserInfo;
8 9 10
import com.kwan.springbootkwan.entity.Result;
import com.kwan.springbootkwan.entity.dto.CsdnArticleInfoDTO;
import com.kwan.springbootkwan.entity.query.CsdnArticleInfoQuery;
11 12
import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
13
import com.kwan.springbootkwan.service.CsdnArticleInfoService;
14 15
import com.kwan.springbootkwan.service.CsdnService;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
16 17
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
18
import lombok.extern.slf4j.Slf4j;
19 20 21 22 23 24 25 26 27
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
28
import java.util.List;
29 30
import java.util.Objects;

31
@Slf4j
32 33 34 35 36
@Api(tags = "csdn文章管理")
@RestController
@RequestMapping("/csdnArticleInfo")
public class CsdnArticleInfoController {

37 38 39 40
    @Resource
    private CsdnService csdnService;
    @Resource
    private CsdnUserInfoService csdnUserInfoService;
41 42 43 44 45 46
    @Resource
    private CsdnArticleInfoService csdnArticleInfoService;

    @ApiOperation(value = "分页查询所有数据", nickname = "分页查询所有数据")
    @PostMapping("/page")
    public Result selectAll(@RequestBody CsdnArticleInfoQuery query) {
47
        final String articleId = query.getArticleId();
48 49 50 51 52 53 54 55 56 57
        final String nickName = query.getNickName();
        final String userName = query.getUserName();
        final Integer likeStatus = query.getLikeStatus();
        final Integer collectStatus = query.getCollectStatus();
        final Integer commentStatus = query.getCommentStatus();
        Page<CsdnArticleInfo> pageParm = new Page<>();
        pageParm.setCurrent(query.getPage());
        pageParm.setSize(query.getPageSize());
        QueryWrapper<CsdnArticleInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
58 59 60
        if (StringUtils.isNotEmpty(articleId)) {
            wrapper.eq("article_id", articleId);
        }
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        if (StringUtils.isNotEmpty(userName)) {
            wrapper.eq("user_name", userName);
        }
        if (Objects.nonNull(likeStatus)) {
            wrapper.eq("like_status", likeStatus);
        }
        if (Objects.nonNull(collectStatus)) {
            wrapper.eq("collect_status", collectStatus);
        }
        if (Objects.nonNull(commentStatus)) {
            wrapper.eq("comment_status", commentStatus);
        }
        if (StringUtils.isNotEmpty(nickName)) {
            wrapper.like("nick_name", nickName);
        }
        wrapper.orderByDesc("update_time");
        return Result.ok(CsdnArticleInfoDTO.Converter.INSTANCE.from(this.csdnArticleInfoService.page(pageParm, wrapper)));
    }

80
    @ApiOperation(value = "新增文章", nickname = "新增文章")
81 82 83 84
    @PostMapping("/add")
    public Result add(@RequestBody CsdnArticleInfoQuery addInfo) {
        final String userName = addInfo.getUserName();
        final String articleId = addInfo.getArticleId();
85 86 87 88 89 90 91 92 93
        if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(articleId)) {
            final List<BusinessInfoResponse.ArticleData.Article> articles = this.csdnArticleInfoService.getBlogs(userName);
            for (BusinessInfoResponse.ArticleData.Article article : articles) {
                if (articleId.equals(article.getArticleId().toString())) {
                    //首先查询用户
                    CsdnUserInfoQuery addUserInfo = new CsdnUserInfoQuery();
                    addUserInfo.setUserName(userName);
                    addUserInfo.setAddType(0);
                    csdnUserInfoService.add(addUserInfo);
94 95 96
                    CsdnArticleInfo csdnArticleInfo = this.csdnArticleInfoService.getArticleByArticleId(articleId);
                    if (csdnArticleInfo == null) {
                        csdnArticleInfo = new CsdnArticleInfo();
97 98 99 100 101 102
                        csdnArticleInfo.setArticleId(articleId);
                        csdnArticleInfo.setUserName(userName);
                        csdnArticleInfo.setArticleTitle(article.getTitle());
                        csdnArticleInfo.setArticleDescription(article.getDescription());
                        csdnArticleInfo.setArticleUrl(article.getUrl());
                        csdnArticleInfo.setNickName(addUserInfo.getNickName());
103
                        this.csdnArticleInfoService.saveArticle(csdnArticleInfo);
104
                    }
105
                    break;
106 107 108 109 110 111 112 113 114 115 116 117 118
                }
            }
        }
        return Result.ok();
    }

    @ApiOperation(value = "更新用户", nickname = "更新用户")
    @PostMapping("/update")
    public Result update(@RequestBody CsdnArticleInfoQuery query) {
        CsdnArticleInfo csdnUserInfo = new CsdnArticleInfo();
        csdnUserInfo.setId(query.getId());
        csdnUserInfo.setUserName(query.getUserName());
        csdnUserInfo.setNickName(query.getNickName());
119 120
        csdnUserInfo.setArticleUrl(query.getArticleUrl());
        csdnUserInfo.setArticleId(query.getArticleId());
121 122 123 124 125 126 127 128 129 130 131 132 133
        return Result.ok(this.csdnArticleInfoService.updateById(csdnUserInfo));
    }

    @ApiOperation(value = "删除用户", nickname = "删除用户")
    @GetMapping("/delete")
    public Result delete(@RequestParam("id") Integer id) {
        CsdnArticleInfo csdnArticleInfo = new CsdnArticleInfo();
        csdnArticleInfo.setIsDelete(1);
        QueryWrapper<CsdnArticleInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        return Result.ok(this.csdnArticleInfoService.update(csdnArticleInfo, wrapper));
    }

134 135 136
    @ApiOperation(value = "单篇文章三连", nickname = "单篇文章三连")
    @GetMapping("/triplet")
    public Result triplet(@RequestParam("articleId") Integer articleId) {
137 138 139 140
        final CsdnArticleInfo csdnArticleInfo = this.csdnArticleInfoService.getArticleByArticleId(articleId.toString());
        if (csdnArticleInfo != null) {
            final String userName = csdnArticleInfo.getUserName();
            CsdnUserInfo csdnUserInfo = csdnUserInfoService.getUserByUserName(userName);
141
            BusinessInfoResponse.ArticleData.Article article = new BusinessInfoResponse.ArticleData.Article();
142 143 144 145
            article.setDescription(csdnArticleInfo.getArticleDescription());
            article.setTitle(csdnArticleInfo.getArticleTitle());
            article.setUrl(csdnArticleInfo.getArticleUrl());
            csdnService.tripletByArticle(csdnUserInfo, article, csdnArticleInfo);
146 147 148
        }
        return Result.ok("单篇文章三连完成");
    }
149 150 151 152 153 154 155 156 157 158 159

    @ApiOperation(value = "多条blog三连", nickname = "多条blog三连")
    @PostMapping("/multiTriplet")
    public Result multiTriplet(@RequestBody List<String> articleIds) {
        if (CollectionUtil.isNotEmpty(articleIds)) {
            for (String articleId : articleIds) {
                triplet(Integer.valueOf(articleId));
            }
        }
        return Result.ok("重置多个人员新博客状态完成");
    }
160
}