From 65437d618316f2f14725377a446a97e972f860d2 Mon Sep 17 00:00:00 2001 From: insanity Date: Tue, 14 Nov 2017 14:40:54 +0900 Subject: [PATCH] ing --- .../sensor/service/SensorItemService.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/sensor/service/SensorItemService.java b/src/main/java/com/loafle/overflow/module/sensor/service/SensorItemService.java index 07a46bc..9211142 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/service/SensorItemService.java +++ b/src/main/java/com/loafle/overflow/module/sensor/service/SensorItemService.java @@ -2,6 +2,7 @@ package com.loafle.overflow.module.sensor.service; import com.loafle.overflow.commons.model.PageParams; import com.loafle.overflow.commons.utils.PageUtil; +import com.loafle.overflow.module.sensor.dao.SensorDAO; import com.loafle.overflow.module.sensor.dao.SensorItemDAO; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.sensor.model.SensorItem; @@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; +import javax.transaction.Transactional; import java.util.List; /** @@ -19,13 +21,24 @@ public class SensorItemService { @Autowired private SensorItemDAO sensorItemDAO; + @Autowired + private SensorDAO sensorDAO; + @Transactional public SensorItem regist(SensorItem sensorItem) { + Sensor s = sensorItem.getSensor(); + s.setItemCount((short)(s.getItemCount() + 1)); + this.sensorDAO.save(s); return this.sensorItemDAO.save(sensorItem); } - public boolean registAll(List sensorItemList) {this.sensorItemDAO.save(sensorItemList); - return true; + @Transactional + public boolean registAll(List sensorItemList) { + Sensor s = sensorItemList.get(0).getSensor(); + s.setItemCount((short)(s.getItemCount() + 1)); + this.sensorDAO.save(s); + this.sensorItemDAO.save(sensorItemList); + return true; } public SensorItem read(String id) { @@ -36,7 +49,11 @@ public class SensorItemService { return this.sensorItemDAO.findAllBySensor(sensor, PageUtil.getPageRequest(pageParams)); } + @Transactional public void remove(SensorItem sensorItem) { + Sensor s = sensorItem.getSensor(); + s.setItemCount((short)(s.getItemCount() - 1)); + this.sensorDAO.save(s); this.sensorItemDAO.delete(sensorItem); } }