package com.muyu.enterpise.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.domain.SysCarFault;
import com.muyu.enterpise.mapper.SysCarFaultMapper;
import com.muyu.enterpise.service.ISysCarFaultService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * 车辆故障Service业务层处理
 * @author Yang鹏
 * @date 2024-09-18
 */
@Service
public class SysCarFaultServiceImpl
        extends ServiceImpl<SysCarFaultMapper, SysCarFault>
        implements ISysCarFaultService {

    /**
     * 精确查询车辆故障
     *
     * @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<>();
        if (StringUtils.isNotEmpty(sysCarFault.getFaultCode())){
            queryWrapper.eq(SysCarFault::getFaultCode, sysCarFault.getFaultCode());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getFaultName())){
            queryWrapper.like(SysCarFault::getFaultName, sysCarFault.getFaultName());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getFaultType())){
            queryWrapper.eq(SysCarFault::getFaultType, sysCarFault.getFaultType());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getCarVin())){
            queryWrapper.eq(SysCarFault::getCarVin, sysCarFault.getCarVin());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getFaultLabel())){
            queryWrapper.eq(SysCarFault::getFaultLabel, sysCarFault.getFaultLabel());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getFaultBit())){
            queryWrapper.eq(SysCarFault::getFaultBit, sysCarFault.getFaultBit());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getFaultValue())){
            queryWrapper.eq(SysCarFault::getFaultValue, sysCarFault.getFaultValue());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getFaultWarn())){
            queryWrapper.eq(SysCarFault::getFaultWarn, sysCarFault.getFaultWarn());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getWarnStatus())){
            queryWrapper.eq(SysCarFault::getWarnStatus, sysCarFault.getWarnStatus());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getFaultDesc())){
            queryWrapper.eq(SysCarFault::getFaultDesc, sysCarFault.getFaultDesc());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getState())){
            queryWrapper.eq(SysCarFault::getState, sysCarFault.getState());
        }
        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;
    }


}
