package com.muyu.enterpise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.domain.WarnRule;
import com.muyu.enterpise.mapper.WarnRuleMapper;
import com.muyu.enterpise.service.IWarnRuleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 预警规则Service业务层处理
 * @author muyu
 * @date 2024-09-20
 */
@Service
public class WarnRuleServiceImpl
        extends ServiceImpl<WarnRuleMapper, WarnRule>
        implements IWarnRuleService {

    /**
     * 精确查询预警规则
     *
     * @param id 预警规则主键
     * @return 预警规则
     */
    @Override
    public WarnRule selectWarnRuleById(Long id)
    {
        LambdaQueryWrapper<WarnRule> queryWrapper = new LambdaQueryWrapper<>();
        if(null != id){
            queryWrapper.eq(WarnRule::getId, id);
        }
        return this.getOne(queryWrapper);
    }


    /**
     * 查询预警规则列表
     *
     * @param warnRule 预警规则
     * @return 预警规则
     */
    @Override
    public List<WarnRule> selectWarnRuleList(WarnRule warnRule)
    {
        LambdaQueryWrapper<WarnRule> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(warnRule.getRuleName())){
            queryWrapper.like(WarnRule::getRuleName, warnRule.getRuleName());
        }
        if(null !=warnRule.getStrategyId()){
            queryWrapper.eq(WarnRule::getStrategyId, warnRule.getStrategyId());
        }
        if(null != warnRule.getSlideTime()){
            queryWrapper.eq(WarnRule::getSlideTime, warnRule.getSlideTime());
        }
        if(StringUtils.isNotEmpty(warnRule.getSlideFrequency())){
            queryWrapper.eq(WarnRule::getSlideFrequency, warnRule.getSlideFrequency());
        }
        if(StringUtils.isNotEmpty(warnRule.getSlideData())){
            queryWrapper.eq(WarnRule::getSlideData, warnRule.getSlideData());
        }
        return this.list(queryWrapper);
    }
    /**
    * 唯一 判断
    * @param warnRule 预警规则
     * @return 预警规则
    */
    @Override
    public Boolean checkIdUnique(WarnRule warnRule) {
        LambdaQueryWrapper<WarnRule> queryWrapper = new LambdaQueryWrapper<>();
        if(null != warnRule.getId()){
            queryWrapper.eq(WarnRule::getId, warnRule.getId());
        }
        return this.count(queryWrapper) > 0;
    }

}
