package com.jjt.calc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jjt.calc.domain.TwinRecordStop;
import com.jjt.calc.mapper.TwinRecordStopMapper;
import com.jjt.calc.service.ITwinRecordStopService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 停机数据记录Service业务层处理
 *
 * @author wukai
 * @date 2025-01-18
 */
@Service
public class TwinRecordStopServiceImpl implements ITwinRecordStopService {
    @Resource
    private TwinRecordStopMapper twinRecordStopMapper;

    /**
     * 查询停机数据记录
     *
     * @param id 停机数据记录主键
     * @return 停机数据记录
     */
    @Override
    public TwinRecordStop selectTwinRecordStopById(Long id) {
        return twinRecordStopMapper.selectTwinRecordStopById(id);
    }

    /**
     * 查询停机数据记录列表
     *
     * @param twinRecordStop 停机数据记录
     * @return 停机数据记录
     */
    @Override
    public List<TwinRecordStop> selectTwinRecordStopList(TwinRecordStop twinRecordStop) {
        return twinRecordStopMapper.selectTwinRecordStopList(twinRecordStop);
    }

    /**
     * 新增停机数据记录
     *
     * @param twinRecordStop 停机数据记录
     * @return 结果
     */
    @Override
    public int insertTwinRecordStop(TwinRecordStop twinRecordStop) {
        return twinRecordStopMapper.insertTwinRecordStop(twinRecordStop);
    }

    /**
     * 修改停机数据记录
     *
     * @param twinRecordStop 停机数据记录
     * @return 结果
     */
    @Override
    public int updateTwinRecordStop(TwinRecordStop twinRecordStop) {
        return twinRecordStopMapper.updateTwinRecordStop(twinRecordStop);
    }

    /**
     * 批量删除停机数据记录
     *
     * @param ids 需要删除的停机数据记录主键
     * @return 结果
     */
    @Override
    public int deleteTwinRecordStopByIds(Long[] ids) {
        return twinRecordStopMapper.deleteTwinRecordStopByIds(ids);
    }

    /**
     * 删除停机数据记录信息
     *
     * @param id 停机数据记录主键
     * @return 结果
     */
    @Override
    public int deleteTwinRecordStopById(Long id) {
        return twinRecordStopMapper.deleteTwinRecordStopById(id);
    }

    /**
     * 按时间删除记录
     *
     * @param date 日期
     * @param hour 小时
     */
    @Override
    public void deleteTwinRecordStop(Date date, int hour) {
        QueryWrapper<TwinRecordStop> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("DATA_DATE", date);
        queryWrapper.eq("hour", hour);
        twinRecordStopMapper.delete(queryWrapper);
    }
}
