CsdnController.java 2.7 KB
Newer Older
1 2
package com.kwan.springbootkwan.controller;

3 4 5
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
6
import com.kwan.springbootkwan.entity.Result;
7 8 9
import com.kwan.springbootkwan.enums.CollectStatus;
import com.kwan.springbootkwan.enums.CommentStatus;
import com.kwan.springbootkwan.enums.LikeStatus;
10
import com.kwan.springbootkwan.service.CsdnCommentService;
11
import com.kwan.springbootkwan.service.CsdnService;
12
import com.kwan.springbootkwan.service.CsdnUserInfoService;
13
import lombok.extern.slf4j.Slf4j;
14
import org.apache.ibatis.annotations.Param;
15 16 17 18 19
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

20
import java.util.List;
21
import java.util.Objects;
22

23 24 25 26 27 28
@Slf4j
@RestController
@RequestMapping("/csdn")
public class CsdnController {

    @Autowired
29
    private CsdnService csdnService;
30
    @Autowired
31 32
    private CsdnCommentService csdnCommentService;
    @Autowired
33
    private CsdnUserInfoService csdnUserInfoService;
34

35 36
    @GetMapping("/singleTriplet")
    public Result singleTriplet(@Param("username") String username) {
37 38
        QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
39 40 41
        wrapper.eq("user_name", username).last("limit 1");
        final CsdnUserInfo csdnUserInfo = csdnUserInfoService.getOne(wrapper);
        if (Objects.nonNull(csdnUserInfo)) {
42 43
            csdnService.singleArticle(csdnUserInfo);
        }
44
        return Result.ok("单人三连完成");
45 46 47 48 49
    }

    @GetMapping("/multiTriplet")
    public Result multiTriplet() {
        csdnService.multiTriplet();
50 51
        return Result.ok("多人三连完成");
    }
52 53 54 55 56 57

    @GetMapping("/autoReply")
    public Result autoReply() {
        csdnCommentService.commentSelf();
        return Result.ok("自动回复完成");
    }
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

    @GetMapping("/resetCurrentStatus")
    public Result resetCurrentStatus() {
        QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        final List<CsdnUserInfo> list = csdnUserInfoService.list(wrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            for (CsdnUserInfo csdnUserInfo : list) {
                csdnUserInfo.setLikeStatus(LikeStatus.UN_PROCESSED.getCode());
                csdnUserInfo.setCollectStatus(CollectStatus.UN_PROCESSED.getCode());
                csdnUserInfo.setCommentStatus(CommentStatus.RESTRICTED_COMMENTS.getCode());
                csdnUserInfoService.updateById(csdnUserInfo);
            }
        }
        return Result.ok("重置当天状态完成");
    }
74
}