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

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

import java.time.LocalDateTime;

/**
 * 数据记录业务实现
 *
 * @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 状态

     * @return
     */
    @Override
    public Record findTimeAndTypeAndState(LocalDateTime time, String type, String state) {
        LambdaQueryWrapper<Record> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Record::getTime,time);
        lambdaQueryWrapper.eq(Record::getType,type);
        lambdaQueryWrapper.eq(Record::getState,state);
        return this.getOne(lambdaQueryWrapper);
    }

    @Override
    public Record findTimeAndTypeAndContentAndState(LocalDateTime time, String type, String content, String state) {
        LambdaQueryWrapper<Record> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Record::getTime,time);
        lambdaQueryWrapper.eq(Record::getType,type);
        lambdaQueryWrapper.eq(Record::getState,state);
        lambdaQueryWrapper.eq(Record::getContent,content);
        return this.getOne(lambdaQueryWrapper);
    }

    @Override
    public Record findTimeAndTypeAndStateAndStationCode(LocalDateTime time, String type, String state, String StationCode) {
        LambdaQueryWrapper<Record> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Record::getTime,time);
        lambdaQueryWrapper.eq(Record::getType,type);
        lambdaQueryWrapper.eq(Record::getState,state);
        lambdaQueryWrapper.eq(Record::getStationCode,StationCode);
        return this.getOne(lambdaQueryWrapper);
    }

    @Override
    public Record findTimeAndTypeAndContentAndStateAndStationCode(LocalDateTime time, String type, String content, String state, String StationCode) {
        LambdaQueryWrapper<Record> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Record::getTime,time);
        lambdaQueryWrapper.eq(Record::getType,type);
        lambdaQueryWrapper.eq(Record::getState,state);
        lambdaQueryWrapper.eq(Record::getContent,content);
        lambdaQueryWrapper.eq(Record::getStationCode,StationCode);
        return this.getOne(lambdaQueryWrapper);
    }
}
