package com.muyu.car.service.impl;

import java.util.List;

import com.muyu.car.domain.SysMessageType;
import com.muyu.car.mapper.SysMessageTypeMapper;
import com.muyu.car.service.ISysMessageTypeService;
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 SysMessageTypeServiceImpl
        extends ServiceImpl<SysMessageTypeMapper, SysMessageType>
        implements ISysMessageTypeService {

    /**
     * 精确查询车辆报文类型
     *
     * @param id 车辆报文类型主键
     * @return 车辆报文类型
     */
    @Override
    public SysMessageType selectSysMessageTypeByMessageCode(String messageCode)
    {
        LambdaQueryWrapper<SysMessageType> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(messageCode, "messageCode不可为空");
        queryWrapper.eq(SysMessageType::getMessageCode, messageCode);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询车辆报文类型列表
     *
     * @param sysMessageType 车辆报文类型
     * @return 车辆报文类型
     */
    @Override
    public List<SysMessageType> selectSysMessageTypeList(SysMessageType sysMessageType)
    {
        LambdaQueryWrapper<SysMessageType> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(sysMessageType.getMessageName())){
            queryWrapper.like(SysMessageType::getMessageName, sysMessageType.getMessageName());
        }
        if (StringUtils.isNotEmpty(sysMessageType.getMessageType())){
            queryWrapper.eq(SysMessageType::getMessageType, sysMessageType.getMessageType());
        }
        return this.list(queryWrapper);
    }

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

}
