You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.9 KiB
Java
81 lines
2.9 KiB
Java
package com.xydl.cac.service.impl;
|
|
|
|
import com.xydl.cac.entity.ModevTypePoint;
|
|
import com.xydl.cac.entity.NSensor;
|
|
import com.xydl.cac.entity.WarnRule;
|
|
import com.xydl.cac.exception.BusinessException;
|
|
import com.xydl.cac.repository.ModevTypePointRepository;
|
|
import com.xydl.cac.repository.NSensorRepository;
|
|
import com.xydl.cac.repository.WarnRuleRepository;
|
|
import com.xydl.cac.service.WarnRuleService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class WarnRuleServiceImpl implements WarnRuleService {
|
|
|
|
@Resource
|
|
WarnRuleRepository repository;
|
|
@Resource
|
|
NSensorRepository sensorRepository;
|
|
@Resource
|
|
ModevTypePointRepository typePointRepository;
|
|
|
|
@Override
|
|
public List<WarnRule> listAll() {
|
|
List<WarnRule> list = repository.findAll();
|
|
for (WarnRule item : list) {
|
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(item.getSensorId());
|
|
if (optionalNSensor.isPresent()) {
|
|
item.setNSensor(optionalNSensor.get());
|
|
}
|
|
Optional<ModevTypePoint> optionalModevTypePoint = typePointRepository.findById(item.getModevtypePointId());
|
|
if (optionalModevTypePoint.isPresent()) {
|
|
item.setTypePoint(optionalModevTypePoint.get());
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
@Override
|
|
public WarnRule add(WarnRule item) throws Exception {
|
|
item.setId(null);
|
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(item.getSensorId());
|
|
if (!optionalNSensor.isPresent()) {
|
|
throw new BusinessException("未找到该装置" + item.getSensorId());
|
|
}
|
|
NSensor sensor = optionalNSensor.get();
|
|
Optional<ModevTypePoint> optionalModevTypePoint = typePointRepository.findById(item.getModevtypePointId());
|
|
if (!optionalModevTypePoint.isPresent()) {
|
|
throw new BusinessException("未找到该监测装置属性点" + item.getModevtypePointId());
|
|
}
|
|
ModevTypePoint typePoint = optionalModevTypePoint.get();
|
|
return repository.save(item);
|
|
}
|
|
|
|
@Override
|
|
public void update(WarnRule item) throws Exception {
|
|
Optional<WarnRule> optional = repository.findById(item.getId());
|
|
if (!optional.isPresent()) {
|
|
throw new BusinessException("未找到该告警规则");
|
|
}
|
|
WarnRule rule = optional.get();
|
|
rule.setComparator(item.getComparator());
|
|
rule.setThreshold(item.getThreshold());
|
|
rule.setLevel(item.getLevel());
|
|
repository.save(rule);
|
|
}
|
|
|
|
@Override
|
|
public void delete(Integer id) throws Exception {
|
|
repository.deleteById(id);
|
|
}
|
|
}
|