package com.muyu.warning.service.impl;

import java.util.List;
import org.springframework.stereotype.Service;
import com.muyu.warning.mapper.WarnLogsMapper;
import com.muyu.warning.domain.WarnLogs;
import com.muyu.warning.service.IWarnLogsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.util.Assert;

/**
 * 预警日志Service业务层处理
 *
 * @author muyu
 * @date 2024-09-20
 */
@Service
public class WarnLogsServiceImpl
        extends ServiceImpl<WarnLogsMapper, WarnLogs>
        implements IWarnLogsService {

    /**
     * 精确查询预警日志
     *
     * @param id 预警日志主键
     * @return 预警日志
     */
    @Override
    public WarnLogs selectWarnLogsById(Long id)
    {
        LambdaQueryWrapper<WarnLogs> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(id, "id不可为空");
        queryWrapper.eq(WarnLogs::getId, id);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询预警日志列表
     *
     * @param warnLogs 预警日志
     * @return 预警日志
     */
    @Override
    public List<WarnLogs> selectWarnLogsList(WarnLogs warnLogs)
    {
        LambdaQueryWrapper<WarnLogs> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(warnLogs.getVin())){
            queryWrapper.eq(WarnLogs::getVin, warnLogs.getVin());
        }
        if (StringUtils.isNotNull(warnLogs.getWarnRuleId())){
            queryWrapper.eq(WarnLogs::getWarnRuleId, warnLogs.getWarnRuleId());
        }
        if (StringUtils.isNotNull(warnLogs.getStartTime())){
            queryWrapper.eq(WarnLogs::getStartTime, warnLogs.getStartTime());
        }
        if (StringUtils.isNotNull(warnLogs.getEndTime())){
            queryWrapper.eq(WarnLogs::getEndTime, warnLogs.getEndTime());
        }
        if (StringUtils.isNotNull(warnLogs.getMaxValue())){
            queryWrapper.eq(WarnLogs::getMaxValue, warnLogs.getMaxValue());
        }
        if (StringUtils.isNotNull(warnLogs.getMinValue())){
            queryWrapper.eq(WarnLogs::getMinValue, warnLogs.getMinValue());
        }
        if (StringUtils.isNotNull(warnLogs.getAvgValue())){
            queryWrapper.eq(WarnLogs::getAvgValue, warnLogs.getAvgValue());
        }
        if (StringUtils.isNotNull(warnLogs.getMedianValue())){
            queryWrapper.eq(WarnLogs::getMedianValue, warnLogs.getMedianValue());
        }
        if (StringUtils.isNotNull(warnLogs.getStatus())){
            queryWrapper.eq(WarnLogs::getStatus, warnLogs.getStatus());
        }
        return this.list(queryWrapper);
    }

    /**
    * 唯一 判断
    * @param warnLogs 预警日志
     * @return 预警日志
    */
    @Override
    public Boolean checkIdUnique(WarnLogs warnLogs) {
        LambdaQueryWrapper<WarnLogs> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WarnLogs::getId, warnLogs.getId());
        return this.count(queryWrapper) > 0;
    }

}
