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 11 12
import com.kwan.springbootkwan.service.CsdnTripletDayInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
13 14
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
15 16 17
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

18 19 20 21
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/**
 * 每日三连监控(CsdnTripletDayInfo)表控制层
 *
 * @author makejava
 * @since 2023-10-26 20:55:30
 */
@RestController
@RequestMapping("/dayInfo")
public class CsdnTripletDayInfoController {
    @Autowired
    private CsdnTripletDayInfoService csdnTripletDayInfoService;

    @GetMapping("/add")
    public Result autoReply() {
        return Result.ok(csdnTripletDayInfoService.todayInfo());
    }
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @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)));
    }
66 67
}