This commit is contained in:
insanity 2017-06-28 15:03:21 +09:00
parent 7428634bf0
commit 313157683a
3 changed files with 49 additions and 30 deletions

View File

@ -1,21 +0,0 @@
package com.loafle.overflow.module.commons;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Created by insanity on 17. 6. 28.
*/
public class OFService {
@Autowired
private ObjectMapper mapper;
public String toString(Object o) {
try {
return mapper.writeValueAsString(o);
}catch(Exception e) {
return e.getMessage();
}
}
}

View File

@ -0,0 +1,33 @@
package com.loafle.overflow.module.sensor.service;
import com.loafle.overflow.module.sensor.dao.SensorDAO;
import com.loafle.overflow.module.sensor.model.Sensor;
import com.loafle.overflow.module.target.model.Target;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
* Created by insanity on 17. 6. 28.
*/
public class SensorService {
@Autowired
SensorDAO sensorDAO;
public Sensor regist(Sensor sensor) {
return this.sensorDAO.save(sensor);
}
public List<Sensor> readAllByTarget(Target target) {
return this.sensorDAO.findAllByTarget(target);
}
public Sensor read(String id) {
return this.sensorDAO.findOne(Long.valueOf(id));
}
public void remove(Sensor sensor) {
this.sensorDAO.delete(sensor);
}
}

View File

@ -1,27 +1,34 @@
package com.loafle.overflow.module.target.service;
import com.loafle.overflow.module.commons.OFService;
import com.loafle.overflow.module.probe.model.Probe;
import com.loafle.overflow.module.target.dao.TargetDAO;
import com.loafle.overflow.module.target.model.Target;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
* Created by insanity on 17. 6. 28.
*/
public class TargetService extends OFService {
public class TargetService {
@Autowired
private TargetDAO targetDAO;
public String regist(Target target) {
Target t = this.targetDAO.save(target);
return toString(t);
public Target regist(Target target) {
return this.targetDAO.save(target);
}
public String read(String id) {
Target t = this.targetDAO.findOne(Long.valueOf(id));
return toString(t);
public Target read(String id) {
return this.targetDAO.findOne(Long.valueOf(id));
}
public List<Target> readAllByProbe(Probe probe) {
return this.targetDAO.findAllByProbe(probe);
}
public void remove(Target target) {
this.targetDAO.delete(target);
}
}