|
|
@ -5,15 +5,18 @@ import com.xydl.cac.entity.NSensor;
|
|
|
|
import com.xydl.cac.entity.WarnRule;
|
|
|
|
import com.xydl.cac.entity.WarnRule;
|
|
|
|
import com.xydl.cac.exception.BusinessException;
|
|
|
|
import com.xydl.cac.exception.BusinessException;
|
|
|
|
import com.xydl.cac.repository.ModevTypePointRepository;
|
|
|
|
import com.xydl.cac.repository.ModevTypePointRepository;
|
|
|
|
import com.xydl.cac.repository.NSensorRepository;
|
|
|
|
|
|
|
|
import com.xydl.cac.repository.WarnRuleRepository;
|
|
|
|
import com.xydl.cac.repository.WarnRuleRepository;
|
|
|
|
|
|
|
|
import com.xydl.cac.service.DataService;
|
|
|
|
|
|
|
|
import com.xydl.cac.service.NSensorService;
|
|
|
|
import com.xydl.cac.service.WarnRuleService;
|
|
|
|
import com.xydl.cac.service.WarnRuleService;
|
|
|
|
|
|
|
|
import com.xydl.cac.util.DateUtil;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
@ -24,22 +27,23 @@ public class WarnRuleServiceImpl implements WarnRuleService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
WarnRuleRepository repository;
|
|
|
|
WarnRuleRepository repository;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
NSensorRepository sensorRepository;
|
|
|
|
NSensorService sensorService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
ModevTypePointRepository typePointRepository;
|
|
|
|
ModevTypePointRepository typePointRepository;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
DataService dataService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<WarnRule> listAll() {
|
|
|
|
public List<WarnRule> listAll() throws Exception {
|
|
|
|
List<WarnRule> list = repository.findAll();
|
|
|
|
List<WarnRule> list = repository.findAll();
|
|
|
|
for (WarnRule item : list) {
|
|
|
|
for (WarnRule item : list) {
|
|
|
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(item.getSensorId());
|
|
|
|
NSensor sensor = sensorService.detail(item.getSensorId());
|
|
|
|
if (optionalNSensor.isPresent()) {
|
|
|
|
item.setNSensor(sensor);
|
|
|
|
item.setNSensor(optionalNSensor.get());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<ModevTypePoint> optionalModevTypePoint = typePointRepository.findById(item.getModevtypePointId());
|
|
|
|
Optional<ModevTypePoint> optionalModevTypePoint = typePointRepository.findById(item.getModevtypePointId());
|
|
|
|
if (optionalModevTypePoint.isPresent()) {
|
|
|
|
if (!optionalModevTypePoint.isPresent()) {
|
|
|
|
item.setTypePoint(optionalModevTypePoint.get());
|
|
|
|
throw new BusinessException("未找到该监测装置属性点" + item.getModevtypePointId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
item.setTypePoint(optionalModevTypePoint.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -47,16 +51,17 @@ public class WarnRuleServiceImpl implements WarnRuleService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public WarnRule add(WarnRule item) throws Exception {
|
|
|
|
public WarnRule add(WarnRule item) throws Exception {
|
|
|
|
item.setId(null);
|
|
|
|
item.setId(null);
|
|
|
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(item.getSensorId());
|
|
|
|
NSensor sensor = sensorService.detail(item.getSensorId());
|
|
|
|
if (!optionalNSensor.isPresent()) {
|
|
|
|
|
|
|
|
throw new BusinessException("未找到该装置" + item.getSensorId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NSensor sensor = optionalNSensor.get();
|
|
|
|
|
|
|
|
Optional<ModevTypePoint> optionalModevTypePoint = typePointRepository.findById(item.getModevtypePointId());
|
|
|
|
Optional<ModevTypePoint> optionalModevTypePoint = typePointRepository.findById(item.getModevtypePointId());
|
|
|
|
if (!optionalModevTypePoint.isPresent()) {
|
|
|
|
if (!optionalModevTypePoint.isPresent()) {
|
|
|
|
throw new BusinessException("未找到该监测装置属性点" + item.getModevtypePointId());
|
|
|
|
throw new BusinessException("未找到该监测装置属性点" + item.getModevtypePointId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ModevTypePoint typePoint = optionalModevTypePoint.get();
|
|
|
|
ModevTypePoint typePoint = optionalModevTypePoint.get();
|
|
|
|
|
|
|
|
Map<String, Object> map = dataService.getLastOneData(sensor, typePoint);
|
|
|
|
|
|
|
|
if (map != null) {
|
|
|
|
|
|
|
|
String str = (String) map.get("acquisitionTime");
|
|
|
|
|
|
|
|
item.setLastDTime(DateUtil.parse(str));
|
|
|
|
|
|
|
|
}
|
|
|
|
return repository.save(item);
|
|
|
|
return repository.save(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|