package com.muyu.fault.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.fault.common.FaultLog;
import com.muyu.fault.common.SysCarFault;
import com.muyu.fault.mapper.FaultLogMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

@Service
public class FaultLogServiceImpl extends ServiceImpl<FaultLogMapper, FaultLog> implements FaultLogService{
    @Override
    public List<FaultLog> faultLogList(FaultLog faultLog) {
        LambdaQueryWrapper<FaultLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(faultLog.getFaultLogVin()),
                FaultLog::getFaultLogVin, faultLog.getFaultLogVin());
        queryWrapper.like(StringUtils.isNotEmpty(faultLog.getFaultLogCodes()),
                FaultLog::getFaultLogCodes, faultLog.getFaultLogCodes());
        return this.list(queryWrapper);
    }

    @Override
    public FaultLog byidId(Long faultLogId) {
        LambdaQueryWrapper<FaultLog> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(faultLogId, "日志ID不可为空");
        queryWrapper.eq(FaultLog::getFaultLogId, faultLogId);
        return this.getOne(queryWrapper);
    }
}
