package com.muyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.domain.SysCar;
import com.muyu.domain.resp.SysCarResp;
import com.muyu.mapper.SysCarMapper;
import com.muyu.service.SysCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * 车辆基础信息Service业务层处理
 * @author LiHD
 * @date 2024-09-18
 */
@Service
public class SysCarServiceImpl
        extends ServiceImpl<SysCarMapper, SysCar>
        implements SysCarService {

    @Autowired
    private SysCarMapper sysCarMapper;

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


    /**
     * 查询车辆基础信息列表
     *
     * @param sysCar 车辆基础信息
     * @return 车辆基础信息
     */
    @Override
    public List<SysCarResp> selectSysCarList(SysCar sysCar)
    {
        return sysCarMapper.selectSysCarList(sysCar);
//        LambdaQueryWrapper<SysCarResp> queryWrapper = new LambdaQueryWrapper<>();
//        if (StringUtils.isNotEmpty(sysCar.getCarVin())){
//            queryWrapper.like(SysCarResp::getCarVin, sysCar.getCarVin());
//        }
//        if (StringUtils.isNotEmpty(sysCar.getCarPlate())){
//            queryWrapper.like(SysCarResp::getCarPlate, sysCar.getCarPlate());
//        }
//        if (StringUtils.isNotEmpty(sysCar.getCarBrand())){
//            queryWrapper.eq(SysCarResp::getCarBrand, sysCar.getCarBrand());
//        }
//        if (StringUtils.isNotEmpty(sysCar.getCarModel())){
//            queryWrapper.eq(SysCarResp::getCarModel, sysCar.getCarModel());
//        }
//        if (StringUtils.isNotEmpty(String.valueOf(sysCar.getCarType()))){
//            queryWrapper.eq(SysCarResp::getCarType, sysCar.getCarType());
//        }
//        if (StringUtils.isNotEmpty(String.valueOf(sysCar.getState()))){
//            queryWrapper.eq(SysCarResp::getState, sysCar.getState());
//        }
//        return this.list(queryWrapper);
    }

    /**
    * 唯一 判断
    * @param sysCar 车辆基础信息
     * @return 车辆基础信息
    */
    @Override
    public Boolean checkIdUnique(SysCar sysCar) {
        LambdaQueryWrapper<SysCar> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysCar::getId, sysCar.getId());
        return this.count(queryWrapper) > 0;
    }

}
