CsdnTripletDayInfoController.java 2.5 KB
Newer Older
1 2 3
package com.kwan.springbootkwan.controller;


4 5 6
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
7
import com.kwan.springbootkwan.entity.Result;
8 9
import com.kwan.springbootkwan.entity.dto.CsdnTripletDayInfoDTO;
import com.kwan.springbootkwan.entity.query.CsdnTripletDayInfoQuery;
10
import com.kwan.springbootkwan.service.CsdnTripletDayInfoService;
11 12
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
13 14
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
15 16
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
17 18 19
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

20 21 22 23
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

24 25

@Api(tags = "csdn每日三连监控")
26 27 28
@RestController
@RequestMapping("/dayInfo")
public class CsdnTripletDayInfoController {
29

30 31 32 33 34 35 36
    @Autowired
    private CsdnTripletDayInfoService csdnTripletDayInfoService;

    @GetMapping("/add")
    public Result autoReply() {
        return Result.ok(csdnTripletDayInfoService.todayInfo());
    }
37

38
    @ApiOperation(value = "分页查询所有数据", nickname = "分页查询所有数据")
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    @PostMapping("/page")
    public Result selectAll(@RequestBody CsdnTripletDayInfoQuery query) {
        final Date startDate = query.getStartDate();
        final Date endDate = query.getEndDate();
        Page<CsdnTripletDayInfo> pageParm = new Page<>();
        pageParm.setCurrent(query.getPage());
        pageParm.setSize(query.getPageSize());
        QueryWrapper<CsdnTripletDayInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        if (Objects.nonNull(startDate)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String startFormattedDate = sdf.format(startDate);
            wrapper.ge("triplet_date", startFormattedDate);
        }
        if (Objects.nonNull(endDate)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String endFormattedDate = sdf.format(endDate);
            wrapper.le("triplet_date", endFormattedDate);
        }
        wrapper.orderByDesc("create_time");
        return Result.ok(CsdnTripletDayInfoDTO.Converter.INSTANCE.from(this.csdnTripletDayInfoService.page(pageParm, wrapper)));
    }
61 62
}