package com.ruoyi.web.v2.v1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.v2.v1.mapper.JsDrugCheckMapper;
import com.ruoyi.web.v2.v1.mapper.JsDrugMapper;
import com.ruoyi.web.v2.v1.mapper.JsEnvCheckMapper;
import com.ruoyi.web.v2.v1.model.JsDrug;
import com.ruoyi.web.v2.v1.model.JsDrugCheck;
import com.ruoyi.web.v2.v1.model.JsEnvCheck;
import com.ruoyi.web.v2.v1.service.IJsDrugService;
import com.ruoyi.web.v2.v1.service.IJsEnvCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Objects;

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

/**
 * <p>
 * v2.0环境拭子检测 服务实现类
 * </p>
 *
 * @author coede
 * @since 2025-09-28
 */
@Service
public class JsEnvCheckServiceImpl extends ServiceImpl<JsEnvCheckMapper, JsEnvCheck> implements IJsEnvCheckService {
    @Autowired
    private JsEnvCheckMapper envCheckMapper;

    @Override
    public AjaxResult page(Integer pageNum, Integer pageSize, String startTime, String endTime, String checkProject) {
        Page<JsEnvCheck> page = new Page<>(pageNum, pageSize);
        QueryWrapper<JsEnvCheck> queryWrapper = new QueryWrapper<>();
        if (!Objects.equals(startTime, "") && !Objects.equals(endTime, "") && startTime != null && endTime != null ) {
            queryWrapper.between("check_time", startTime + " 00:00:00", endTime + " 23:59:59");
        }
        queryWrapper.orderByDesc("check_time");
        queryWrapper.like(StringUtils.isNotEmpty(checkProject), "check_project", checkProject);
        return success(envCheckMapper.selectPage(page, queryWrapper));
    }
}
