CsdnUserController.java 4.2 KB
Newer Older
1 2 3 4 5 6 7 8 9
package com.kwan.springbootkwan.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.Result;
import com.kwan.springbootkwan.entity.dto.CsdnUserInfoDTO;
import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
10 11
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
12 13 14 15 16 17 18 19 20 21
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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;

22 23
import java.util.Objects;

24
@Slf4j
25
@Api(tags = "csdn每日三连监控")
26 27 28
@RestController
@RequestMapping("/csdn/user")
public class CsdnUserController {
29

30 31 32
    @Autowired
    private CsdnUserInfoService csdnUserInfoService;

33
    @ApiOperation(value = "分页查询所有数据", nickname = "分页查询所有数据")
34 35 36 37 38
    @PostMapping("/page")
    public Result selectAll(@RequestBody CsdnUserInfoQuery query) {
        final Integer userWeight = query.getUserWeight();
        final String nickName = query.getNickName();
        final String userName = query.getUserName();
39 40 41 42
        final String articleType = query.getArticleType();
        final Integer likeStatus = query.getLikeStatus();
        final Integer collectStatus = query.getCollectStatus();
        final Integer commentStatus = query.getCommentStatus();
43
        Page<CsdnUserInfo> pageParm = new Page<>();
44 45
        pageParm.setCurrent(query.getPage());
        pageParm.setSize(query.getPageSize());
46 47 48 49 50
        QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        if (StringUtils.isNotEmpty(userName)) {
            wrapper.eq("user_name", userName);
        }
51 52 53
        if (StringUtils.isNotEmpty(articleType)) {
            wrapper.eq("article_type", articleType);
        }
54 55 56
        if (Objects.nonNull(userWeight)) {
            wrapper.eq("user_weight", userWeight);
        }
57 58 59 60 61 62 63 64 65
        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);
        }
66 67 68
        if (StringUtils.isNotEmpty(nickName)) {
            wrapper.like("nick_name", nickName);
        }
69
        wrapper.orderByDesc("user_weight").orderByDesc("update_time");
70 71 72
        return Result.ok(CsdnUserInfoDTO.Converter.INSTANCE.from(this.csdnUserInfoService.page(pageParm, wrapper)));
    }

73
    @ApiOperation(value = "新增用户", nickname = "新增用户")
74 75
    @PostMapping("/add")
    public Result add(@RequestBody CsdnUserInfoQuery addInfo) {
76
        csdnUserInfoService.add(addInfo);
77 78 79
        return Result.ok();
    }

80
    @ApiOperation(value = "更新用户", nickname = "更新用户")
81 82 83
    @PostMapping("/update")
    public Result update(@RequestBody CsdnUserInfoQuery query) {
        CsdnUserInfo csdnUserInfo = new CsdnUserInfo();
84 85 86 87
        csdnUserInfo.setId(query.getId());
        csdnUserInfo.setUserName(query.getUserName());
        csdnUserInfo.setNickName(query.getNickName());
        csdnUserInfo.setUserWeight(query.getUserWeight());
88
        csdnUserInfo.setUserHomeUrl(query.getUserHomeUrl());
89 90 91
        return Result.ok(this.csdnUserInfoService.updateById(csdnUserInfo));
    }

92
    @ApiOperation(value = "删除用户", nickname = "删除用户")
93 94 95 96 97 98 99 100
    @GetMapping("/delete")
    public Result delete(@RequestParam("id") Integer id) {
        CsdnUserInfo csdnUserInfo = new CsdnUserInfo();
        csdnUserInfo.setIsDelete(1);
        QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        return Result.ok(this.csdnUserInfoService.update(csdnUserInfo, wrapper));
    }
101
}