package com.muyu.car.service.impl;

import java.util.List;

import com.muyu.car.domain.SysCarMessage;
import com.muyu.car.domain.VO.SysMessageVO;
import com.muyu.car.mapper.SysCarMessageMapper;
import com.muyu.car.service.ISysCarMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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-18
 */
@Service
public class SysCarMessageServiceImpl
        extends ServiceImpl<SysCarMessageMapper, SysCarMessage>
        implements ISysCarMessageService {
    @Autowired
    private SysCarMessageMapper mapper;

    @Override
    public List<SysMessageVO> dobList(SysMessageVO sysMessageVO) {
        return mapper.dobList(sysMessageVO);
    }

    /**
     * 精确查询车辆报文记录
     *
     * @param id 车辆报文记录主键
     * @return 车辆报文记录
     */
    @Override
    public SysCarMessage selectSysCarMessageById(Long id)
    {
        LambdaQueryWrapper<SysCarMessage> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(id, "id不可为空");
        queryWrapper.eq(SysCarMessage::getId, id);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询车辆报文记录列表
     *
     * @param sysCarMessage 车辆报文记录
     * @return 车辆报文记录
     */
    @Override
    public List<SysCarMessage> selectSysCarMessageList(SysCarMessage sysCarMessage)
    {
        LambdaQueryWrapper<SysCarMessage> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(sysCarMessage.getModelCode())){
            queryWrapper.eq(SysCarMessage::getModelCode, sysCarMessage.getModelCode());
        }
        if (StringUtils.isNotEmpty(sysCarMessage.getMessageType())){
            queryWrapper.eq(SysCarMessage::getMessageType, sysCarMessage.getMessageType());
        }
        return this.list(queryWrapper);
    }

    /**
    * 唯一 判断
    * @param sysCarMessage 车辆报文记录
     * @return 车辆报文记录
    */
    @Override
    public Boolean checkIdUnique(SysCarMessage sysCarMessage) {
        LambdaQueryWrapper<SysCarMessage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysCarMessage::getId, sysCarMessage.getId());
        return this.count(queryWrapper) > 0;
    }

}
