package com.jiayue.insu.incloud.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.insu.incloud.entity.Quartz;
import com.jiayue.insu.incloud.entity.Record;
import com.jiayue.insu.incloud.mapper.QuartzMapper;
import com.jiayue.insu.incloud.mapper.RecordMapper;
import com.jiayue.insu.incloud.service.QuartzService;
import com.jiayue.insu.incloud.service.RecordService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 数据记录业务实现
 *
 * @author yh
 * @version 1.0
 * @since 2022/5/22 11:29
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements RecordService {

    /**
     *  查询记录
     * @param time 时间
     * @param type 日志类型
     * @param state 状态
     * @param station 场站编码
     * @return
     */
    @Override
    public Record findTimeAndTypeAndStateAndStation(LocalDateTime time, String type, String state,String station) {
        LambdaQueryWrapper<Record> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Record::getTime,time);
        lambdaQueryWrapper.eq(Record::getType,type);
        lambdaQueryWrapper.eq(Record::getState,state);
        lambdaQueryWrapper.eq(Record::getStationCode,station);

        return this.getOne(lambdaQueryWrapper);
    }

    @Override
    public List<Record> findTypeAndStateAndStationAndCreatTime(String type, String state, String station,LocalDateTime creatTime) {
        LambdaQueryWrapper<Record> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Record::getType,type);
        lambdaQueryWrapper.eq(Record::getState,state);
        lambdaQueryWrapper.eq(Record::getStationCode,station);
        lambdaQueryWrapper.ge(Record::getCreateTime,creatTime);
        return this.list(lambdaQueryWrapper);
    }
}
