added sensor from infra
This commit is contained in:
parent
c9e595797d
commit
f1725b6f46
|
@ -15,10 +15,12 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Repository
|
@Repository
|
||||||
public interface SensorDAO extends JpaRepository<Sensor, Long> {
|
public interface SensorDAO extends JpaRepository<Sensor, Long> {
|
||||||
|
|
||||||
|
|
||||||
List<Sensor> findAllByTarget(Target target);
|
List<Sensor> findAllByTarget(Target target);
|
||||||
|
|
||||||
@Query("SELECT s from Sensor s WHERE s.target in (:targetList)")
|
@Query("SELECT s from Sensor s WHERE s.target in (:targetList)")
|
||||||
List<Sensor> findAllByTarget(@Param("targetList") List<Target> targetList);
|
List<Sensor> findAllByTargetList(@Param("targetList") List<Target> targetList);
|
||||||
// List<Sensor> findAllByTargetList(List<Target> targets);
|
// List<Sensor> findAllByTargetList(List<Target> targets);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,9 @@ import com.loafle.overflow.module.probe.service.ProbeService;
|
||||||
import com.loafle.overflow.module.sensor.dao.SensorDAO;
|
import com.loafle.overflow.module.sensor.dao.SensorDAO;
|
||||||
import com.loafle.overflow.module.sensor.model.Sensor;
|
import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
import com.loafle.overflow.module.target.model.Target;
|
import com.loafle.overflow.module.target.model.Target;
|
||||||
import com.loafle.overflow.module.target.service.TargetService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,8 +43,18 @@ public class SensorService {
|
||||||
|
|
||||||
List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList);
|
List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList);
|
||||||
|
|
||||||
return this.sensorDAO.findAllByTarget(targetList);
|
return this.sensorDAO.findAllByTargetList(targetList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Sensor> readAllByInfra(Infra infra) {
|
||||||
|
Infra dbInfra = this.infraService.read(infra.getId());
|
||||||
|
|
||||||
|
if(dbInfra == null || dbInfra.getTarget() == null) return null;
|
||||||
|
|
||||||
|
return this.sensorDAO.findAllByTarget(dbInfra.getTarget());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public Sensor read(String id) {
|
public Sensor read(String id) {
|
||||||
return this.sensorDAO.findOne(Long.valueOf(id));
|
return this.sensorDAO.findOne(Long.valueOf(id));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package com.loafle.overflow.module.sensor.service;
|
package com.loafle.overflow.module.sensor.service;
|
||||||
|
|
||||||
import com.loafle.overflow.module.domain.model.Domain;
|
import com.loafle.overflow.module.domain.model.Domain;
|
||||||
import com.loafle.overflow.module.infra.service.InfraService;
|
import com.loafle.overflow.module.infra.model.Infra;
|
||||||
|
import com.loafle.overflow.module.infra.model.InfraMachine;
|
||||||
import com.loafle.overflow.module.meta.model.MetaCrawler;
|
import com.loafle.overflow.module.meta.model.MetaCrawler;
|
||||||
import com.loafle.overflow.module.meta.model.MetaSensorStatus;
|
import com.loafle.overflow.module.meta.model.MetaSensorStatus;
|
||||||
import com.loafle.overflow.module.probe.model.Probe;
|
|
||||||
import com.loafle.overflow.module.probe.service.ProbeService;
|
|
||||||
import com.loafle.overflow.module.sensor.model.Sensor;
|
import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
import com.loafle.overflow.module.target.model.Target;
|
import com.loafle.overflow.module.target.model.Target;
|
||||||
import com.loafle.overflow.spring.AppConfigTest;
|
import com.loafle.overflow.spring.AppConfigTest;
|
||||||
|
@ -87,4 +86,16 @@ public class SensorServiceTest {
|
||||||
Assert.assertNotEquals(sl.size(), 0);
|
Assert.assertNotEquals(sl.size(), 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readAllByInfra() {
|
||||||
|
|
||||||
|
Infra infra = new InfraMachine();
|
||||||
|
infra.setId(1);
|
||||||
|
|
||||||
|
List<Sensor> sl = this.sensorService.readAllByInfra(infra);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(sl.size(), 0);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user