package com.huimv.env.admin.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huimv.env.admin.common.utils.Result;
import com.huimv.env.admin.common.utils.ResultCode;
import com.huimv.env.admin.entity.PortWarningInfo;
import com.huimv.env.admin.entity.vo.WarningPageParam;
import com.huimv.env.admin.service.IPortWarningInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author newspaper
 * @since 2024-05-09
 */
@RestController
@CrossOrigin
@RequestMapping("/port-warning-info")
public class PortWarningInfoController {

    @Autowired
    private IPortWarningInfoService portWarningInfoService;

    @PostMapping("/page")
    public Result page(@RequestBody WarningPageParam warningPageParam){
        String startTime = warningPageParam.getStartTime();
        String endTime = warningPageParam.getEndTime();
        if (ObjectUtil.isNotEmpty(startTime)){
            startTime = startTime + " 00:00:00";
            endTime = endTime + " 23:59:59";
        }
        Page<PortWarningInfo> page = new Page<>(warningPageParam.getPageNum(),warningPageParam.getPageSize());
        Page<PortWarningInfo> warningInfoPage = portWarningInfoService.page(page, new QueryWrapper<PortWarningInfo>().lambda()
                .eq(ObjectUtil.isNotEmpty(warningPageParam.getWarningType()), PortWarningInfo::getWarningType, warningPageParam.getWarningType())
                .between(ObjectUtil.isNotEmpty(startTime),PortWarningInfo::getCreateTime,startTime,endTime));
        return new Result(ResultCode.SUCCESS,warningInfoPage);
    }

}
