package com.muyu.enterprise.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.enterprise.domain.FaultrRule;
import com.muyu.enterprise.mapper.FaultrRuleMapper;
import com.muyu.enterprise.service.FaultrRuleService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
/**
 * 故障规则业务实现层
 * @Author: chenruijia
 * @Date 2024/9/28 12.19
 * @Description FaultrRuleServiceImpl:故障规则业务实现层
 */
@Service
public class FaultrRuleServiceImpl extends ServiceImpl<FaultrRuleMapper, FaultrRule> implements FaultrRuleService {

    @Override
    public List<FaultrRule> faultRuleList(FaultrRule faultrRule) {
        LambdaQueryWrapper<FaultrRule> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(faultrRule.getFaultRuleName())) {
            queryWrapper.eq(FaultrRule::getFaultRuleName,faultrRule.getFaultRuleName());
        }
        if (StringUtils.isNotEmpty(faultrRule.getFaultRuleParameter())) {
            queryWrapper.eq(FaultrRule::getFaultRuleParameter,faultrRule.getFaultRuleParameter());
        }
        return this.list(queryWrapper);
    }

    @Override
    public FaultrRule byidRuleId(Long faultRuleId) {
        LambdaQueryWrapper<FaultrRule> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(faultRuleId, "规则ID不可为空");
        queryWrapper.eq(FaultrRule::getFaultRuleId, faultRuleId);
        return this.getOne(queryWrapper);
    }
}
