package com.muyu.warning.service.impl;

import java.util.List;
import org.springframework.stereotype.Service;
import com.muyu.warning.mapper.WarnStrategyMapper;
import com.muyu.warning.domain.WarnStrategy;
import com.muyu.warning.service.IWarnStrategyService;
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-20
 */
@Service
public class WarnStrategyServiceImpl
        extends ServiceImpl<WarnStrategyMapper, WarnStrategy>
        implements IWarnStrategyService {

    /**
     * 精确查询预警策略
     *
     * @param id 预警策略主键
     * @return 预警策略
     */
    @Override
    public WarnStrategy selectWarnStrategyById(Long id)
    {
        LambdaQueryWrapper<WarnStrategy> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(id, "id不可为空");
        queryWrapper.eq(WarnStrategy::getId, id);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询预警策略列表
     *
     * @param warnStrategy 预警策略
     * @return 预警策略
     */
    @Override
    public List<WarnStrategy> selectWarnStrategyList(WarnStrategy warnStrategy)
    {
        LambdaQueryWrapper<WarnStrategy> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotNull(warnStrategy.getCarTypeId())){
            queryWrapper.eq(WarnStrategy::getCarTypeId, warnStrategy.getCarTypeId());
        }
        if (StringUtils.isNotNull(warnStrategy.getStrategyName())){
            queryWrapper.like(WarnStrategy::getStrategyName, warnStrategy.getStrategyName());
        }
        if (StringUtils.isNotNull(warnStrategy.getMsgId())){
            queryWrapper.eq(WarnStrategy::getMsgId, warnStrategy.getMsgId());
        }
        return this.list(queryWrapper);
    }

    /**
    * 唯一 判断
    * @param warnStrategy 预警策略
     * @return 预警策略
    */
    @Override
    public Boolean checkIdUnique(WarnStrategy warnStrategy) {
        LambdaQueryWrapper<WarnStrategy> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WarnStrategy::getId, warnStrategy.getId());
        return this.count(queryWrapper) > 0;
    }

}
