package com.ruoyi.web.v2.v1.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.v2.v1.model.JsMaintenanceWarning;
import com.ruoyi.web.v2.v1.service.IJsMaintenanceWarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * <p>
 * v2.0设备维护提示 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-06-19
 */
@RestController
@RequestMapping("/js-maintenance-warning")
@Api("2.0设备维护提示")
public class JsMaintenanceWarningController {

    @Autowired
    private IJsMaintenanceWarningService maintenanceWarningService;

    @ApiOperation("设备维护提示分页")
    @GetMapping("/page")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
            , @RequestParam(value = "startTime", required = false) String startTime
            , @RequestParam(value = "endTime", required = false) String endTime
            , @RequestParam(value = "deviceNum", required = false) String deviceNum
            , @RequestParam(value = "deviceName", required = false) String deviceName) {
        Page<JsMaintenanceWarning> page = new Page<>(pageNum, pageSize);
        QueryWrapper<JsMaintenanceWarning> queryWrapper = new QueryWrapper<>();
        if ("".equals(startTime) || null == startTime) {

        } else {
            queryWrapper.between("maintenance_time", startTime, endTime);
        }
        queryWrapper.like(StringUtils.isNotEmpty(deviceNum), "device_num", deviceNum);
        queryWrapper.like(StringUtils.isNotEmpty(deviceName), "device_name", deviceName);
        queryWrapper.orderByDesc("maintenance_time");
        return success(maintenanceWarningService.page(page,queryWrapper));
    }
}
