package com.muyu.breakdown.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.breakdown.domain.SysCarFault;
import com.muyu.breakdown.mapper.SysCarFaultMapper;
import com.muyu.breakdown.service.SysCarFaultService;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @ClassDescription: 车辆故障管理Service业务层处理
 * @JdkVersion: 1.8
 * @Author: YZL
 * @Created: 2024/9/20 10:58
 */
@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<>();
        if (StringUtils.isNotEmpty(sysCarFault.getFaultCode())){
            queryWrapper.eq(SysCarFault::getFaultCode, sysCarFault.getFaultCode());
        }
        if (StringUtils.isNotEmpty(sysCarFault.getFaultBit())){
            queryWrapper.eq(SysCarFault::getFaultBit, sysCarFault.getFaultBit());
        }
        if (sysCarFault.getFaultRank()!=null){
            queryWrapper.eq(SysCarFault::getFaultRank, sysCarFault.getFaultRank());
        }
        if (sysCarFault.getTypeId()!=null){
            queryWrapper.eq(SysCarFault::getTypeId,sysCarFault.getTypeId());
        }
        return this.list(queryWrapper);
    }

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



}
