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

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.model.JsDisinfect;
import com.ruoyi.web.v2.mapper.JsDisinfectMapper;
import com.ruoyi.web.v2.service.IJsDisinfectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * v2.0消毒登记 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-05-22
 */
@Service
public class JsDisinfectServiceImpl extends ServiceImpl<JsDisinfectMapper, JsDisinfect> implements IJsDisinfectService {

    @Autowired
    private JsDisinfectMapper disinfectMapper;

    @Override
    public AjaxResult add(JsDisinfect disinfect) {
        disinfectMapper.insert(disinfect);
        return success();
    }

    @Override
    public AjaxResult edit(JsDisinfect disinfect) {
        disinfectMapper.updateById(disinfect);
        return success();
    }

    @Override
    public AjaxResult delete(String ids) {
        String[] split = ids.split(",");
        for (String s : split) {
            disinfectMapper.deleteById(s);
        }
        return success();
    }

    @Override
    public AjaxResult page(Integer pageNum, Integer pageSize, String startTime, String endTime, String disinfectLocation) {
        Page<JsDisinfect> page = new Page<>(pageNum, pageSize);
        QueryWrapper<JsDisinfect> queryWrapper = new QueryWrapper<>();
        if ("".equals(startTime) || null == startTime) {

        } else {
            queryWrapper.between("disinfect_time", startTime+" 00:00:00", endTime+" 23:59:59");
        }
        queryWrapper.orderByDesc("disinfect_time").orderByDesc("id");
        queryWrapper.like(StringUtils.isNotEmpty(disinfectLocation),"disinfect_location", disinfectLocation);
        return success(disinfectMapper.selectPage(page, queryWrapper));
    }

    @Override
    public AjaxResult listAll() {
        return null;
    }
}
