package com.muyu.car.service.impl;

import java.util.List;
import com.muyu.common.core.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.muyu.car.mapper.SysCarMapper;
import com.muyu.car.domain.SysCar;
import com.muyu.car.service.ISysCarService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.util.Assert;

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

    /**
     * 精确查询车辆基础信息
     *
     * @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<SysCar> selectSysCarList(SysCar sysCar)
    {
        LambdaQueryWrapper<SysCar> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(sysCar.getCarVin())){
            queryWrapper.eq(SysCar::getCarVin, sysCar.getCarVin());
        }
        if (StringUtils.isNotEmpty(sysCar.getCarPlate())){
            queryWrapper.eq(SysCar::getCarPlate, sysCar.getCarPlate());
        }
        if (StringUtils.isNotEmpty(sysCar.getCarBrand())){
            queryWrapper.eq(SysCar::getCarBrand, sysCar.getCarBrand());
        }
        if (StringUtils.isNotEmpty(sysCar.getCarModel())){
            queryWrapper.eq(SysCar::getCarModel, sysCar.getCarModel());
        }
        if (StringUtils.isNotEmpty(sysCar.getCarType())){
            queryWrapper.eq(SysCar::getCarType, sysCar.getCarType());
        }
        if (sysCar.getCarLastJoinTime()!= null){
            queryWrapper.eq(SysCar::getCarLastJoinTime, sysCar.getCarLastJoinTime());
        }
        if (sysCar.getCarLastOfflineTime()!= null){
            queryWrapper.eq(SysCar::getCarLastOfflineTime, sysCar.getCarLastOfflineTime());
        }
        if (StringUtils.isNotEmpty(sysCar.getState())){
            queryWrapper.eq(SysCar::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;
    }

}
