package com.muyu.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.domain.SysCar;
import com.muyu.common.domain.req.SysCarReq;
import com.muyu.common.domain.resp.SysCarFaultLogVo;
import com.muyu.common.domain.resp.SysCarVo;
import com.muyu.server.mapper.SysCarMapper;
import com.muyu.server.service.SysCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysCarServiceImpl extends ServiceImpl<SysCarMapper, SysCar> implements SysCarService {
    @Autowired
    private SysCarMapper sysCarMapper;
    @Override
    public List<SysCarVo> selectSysCarVoList(SysCarReq sysCarReq) {
        return sysCarMapper.selectSysCarVoList(sysCarReq);
    }

    @Override
    public SysCarVo selectSysCarVoById(Long id) {
        return sysCarMapper.selectSysCarVoById(id);
    }

    @Override
    public int addSysCar(SysCar sysCar) {
        return sysCarMapper.insert(sysCar);
    }

    @Override
    public int deleteSysCarById(Long id) {
        return sysCarMapper.deleteById(id);
    }

    @Override
    public int updateSysCar(SysCar sysCar) {
        return sysCarMapper.updateById(sysCar);
    }

    @Override
    public List<SysCarFaultLogVo> findFenceByCarVin(String carVin) {
        return sysCarMapper.findFenceByCarVin(carVin);
    }

    @Override
    public SysCar findCarByVin(String carVin) {
        QueryWrapper<SysCar> sysCarQueryWrapper = new QueryWrapper<>();
        sysCarQueryWrapper.eq("car_vin", carVin);
        SysCar sysCar = sysCarMapper.selectOne(sysCarQueryWrapper);
        return sysCar;
    }
}
