package com.gunshi.project.hsz.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gunshi.project.hsz.mapper.WarningConditionMapper; import com.gunshi.project.hsz.mapper.WarningRuleMapper; import com.gunshi.project.hsz.model.WarningCondition; import com.gunshi.project.hsz.model.WarningRule; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.Serializable; import java.util.List; @Service @Slf4j @Transactional(rollbackFor = Exception.class) public class WarningConditionService extends ServiceImpl { public List getListByRuleId(Serializable id){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(WarningCondition::getRuleId,id); queryWrapper.orderByAsc(WarningCondition::getOrder); return this.list(queryWrapper); } public WarningCondition checkConditionExists(WarningCondition dto) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if(dto.getId() != null){ queryWrapper.ne(WarningCondition::getId, dto.getId()); } if(dto.getIndicatorType() != null){ //预警指标类型 queryWrapper.eq(WarningCondition::getIndicatorType,dto.getIndicatorType()); } if(dto.getWarningLevel() != null){ //预警等级 queryWrapper.eq(WarningCondition::getWarningLevel,dto.getWarningLevel()); } if(dto.getWarningType() != null){ //预警类型 queryWrapper.eq(WarningCondition::getWarningType,dto.getWarningType()); } if(dto.getOperator() != null){ //比较符 queryWrapper.eq(WarningCondition::getOperator,dto.getOperator()); } if(dto.getThresholdValue() != null){ //阈值 queryWrapper.eq(WarningCondition::getThresholdValue,dto.getThresholdValue()); } if(dto.getDurationHours() != null){ //时长/时段(小时) queryWrapper.eq(WarningCondition::getDurationHours,dto.getDurationHours()); } WarningCondition warningCondition = this.baseMapper.selectOne(queryWrapper); return warningCondition; } public boolean removeByRuleId(Long ruleId){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(WarningCondition::getRuleId,ruleId); return this.remove(queryWrapper); } public boolean deleteData(Long ruleId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(WarningCondition::getRuleId,ruleId); boolean remove = this.remove(queryWrapper); return remove; } }