package com.muyu.enterprise.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.enterprise.domain.FaultLog;
import com.muyu.enterprise.mapper.FaultLogMapper;
import com.muyu.enterprise.service.FaultLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
/**
 * 故障日志业务实现层
 * @Author: chenruijia
 * @Date 2024/9/28 12.19
 * @Description FaultLogServiceImpl:故障日志业务实现层
 */
@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);
    }
}
