package com.muyu.server.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.common.domain.SysCarFault;
import com.muyu.server.mapper.SysCarFaultMapper;
import com.muyu.server.service.SysCarFaultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * 车辆故障码 业务层
 * @author 袁子龙
 * @package: com.muyu.breakdown.service.impl
 * @name: SysCarFaultServiceImpl
 * @date: 2024/9/20 10:58
 */
@Service
public class SysCarFaultServiceImpl
        extends ServiceImpl<SysCarFaultMapper, SysCarFault>
        implements SysCarFaultService {

    @Autowired
    private SysCarFaultMapper mapper;

    /**
     * 精确查询车辆故障管理
     *
     * @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());
        }
        //车辆类型查询
        if (sysCarFault.getCarTypeId()!=null){
            queryWrapper.eq(SysCarFault::getCarTypeId,sysCarFault.getTypeId());
        }
        return this.list(queryWrapper);
    }



    /**
     * 唯一 判断
     * @param faultCode 车辆故障管理
     * @return 车辆故障管理
     */

    @Override
    public SysCarFault selectFaultByFaultCode(String faultCode) {
        return mapper.selectFaultByFaultCode(faultCode);
    }


}
