package com.muyu.enterprise.service.impl;

import java.util.List;

import com.muyu.enterprise.domain.SysCarFault;
import com.muyu.enterprise.service.SysCarFaultService;
import org.springframework.stereotype.Service;
import com.muyu.enterprise.mapper.SysCarFaultMapper;
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;


/**
 * 故障管理业务实现层
 * @Author: chenruijia
 * @Date 2024/9/28 12.19
 * @Description SysCarFaultServiceImpl:故障管理业务实现层
 */
@Service
public class SysCarFaultServiceImpl
        extends ServiceImpl<SysCarFaultMapper, SysCarFault>
        implements SysCarFaultService {

    /**
     * 精确查询车辆故障
     *
     * @param id 车辆故障主键
     * @return 车辆故障
     */
    @Override
    public SysCarFault selectSysCarFaultById(Long id)
    {
        LambdaQueryWrapper<SysCarFault> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(id, "id不可为空");
        queryWrapper.eq(SysCarFault::getId, id);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询车辆故障列表
     *
     * @param sysCarFault 车辆故障
     * @return 车辆故障
     */
    @Override
    public List<SysCarFault> selectSysCarFaultList(SysCarFault sysCarFault)
    {
        LambdaQueryWrapper<SysCarFault> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(String.valueOf(sysCarFault.getFaultTypeId())),
                SysCarFault::getFaultTypeId, sysCarFault.getFaultTypeId());
        queryWrapper.eq(StringUtils.isNotEmpty(sysCarFault.getState()),
                SysCarFault::getState, sysCarFault.getState());
        queryWrapper.like(StringUtils.isNotEmpty(sysCarFault.getCarVin()),
                SysCarFault::getCarVin, sysCarFault.getCarVin());
        queryWrapper.eq(StringUtils.isNotEmpty(sysCarFault.getFaultWarn()),
                SysCarFault::getFaultWarn, sysCarFault.getFaultWarn());
        return this.list(queryWrapper);
    }

    /**
    * 唯一 判断
    * @param sysCarFault 车辆故障
     * @return 车辆故障
    */
    @Override
    public Boolean checkIdUnique(SysCarFault sysCarFault) {
        LambdaQueryWrapper<SysCarFault> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysCarFault::getId, sysCarFault.getId());
        return this.count(queryWrapper) > 0;
    }

}
