From 3c641d4133e8aaacd456dfc0e1bd534dc50dfd13 Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 23 Aug 2017 15:52:13 +0900 Subject: [PATCH] History ing --- .../module/history/dao/HistoryDAO.java | 10 + .../history/service/HistoryService.java | 20 ++ src/main/resources/init.sql | 230 ++++++++++++++++++ .../history/service/HistoryServiceTest.java | 27 +- 4 files changed, 285 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java b/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java index 832cbfc..763f5c5 100644 --- a/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java +++ b/src/main/java/com/loafle/overflow/module/history/dao/HistoryDAO.java @@ -1,13 +1,23 @@ package com.loafle.overflow.module.history.dao; import com.loafle.overflow.module.history.model.History; +import com.loafle.overflow.module.meta.model.MetaHistoryType; +import com.loafle.overflow.module.probe.model.Probe; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; + /** * Created by insanity on 17. 8. 23. */ @Repository public interface HistoryDAO extends JpaRepository { + List findAllByProbeOrderByIdDesc(Probe probe); + + @Query("SELECT h FROM History h WHERE h.probe.id = :#{#probe.id} and h.type.id = :#{#type.id}") + List findAllByProbeAndType(@Param("probe") Probe probe, @Param("type") MetaHistoryType type); } diff --git a/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java b/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java index e8cb783..e9dc35e 100644 --- a/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java +++ b/src/main/java/com/loafle/overflow/module/history/service/HistoryService.java @@ -1,9 +1,29 @@ package com.loafle.overflow.module.history.service; +import com.loafle.overflow.module.history.dao.HistoryDAO; +import com.loafle.overflow.module.history.model.History; +import com.loafle.overflow.module.meta.model.MetaHistoryType; +import com.loafle.overflow.module.probe.model.Probe; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Service("HistoryService") public class HistoryService { + @Autowired + private HistoryDAO historyDAO; + public History regist(History history) { + return this.historyDAO.save(history); + } + + public List readAllByProbe(Probe probe) { + return this.historyDAO.findAllByProbeOrderByIdDesc(probe); + } + + public List readAllByProbeAndType(Probe probe, MetaHistoryType type) { + return this.historyDAO.findAllByProbeAndType(probe, type); + } } diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 9bc55b0..33fa460 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -486,3 +486,233 @@ INSERT INTO public.noauth_probe (api_key,create_date,host_name,ip_address,mac_ad INSERT INTO public.noauth_probe (api_key,create_date,host_name,ip_address,mac_address,temp_probe_key,domain_id,probe_id,status) VALUES ( '52abd6fd57e511e7ac52080027658d15','2017-08-11 12:43:46.877','insanity',3232235980,8796753988883,'1cf2555c57d511e79714080027658d15',1,NULL,3); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +1,'2017-08-23 15:22:39.851','Test History 0',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +2,'2017-08-23 15:22:39.881','Test History 1',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +3,'2017-08-23 15:22:39.899','Test History 2',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +4,'2017-08-23 15:22:39.915','Test History 3',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +5,'2017-08-23 15:22:39.929','Test History 4',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +6,'2017-08-23 15:22:39.944','Test History 5',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +7,'2017-08-23 15:22:39.959','Test History 6',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +8,'2017-08-23 15:22:39.974','Test History 7',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +9,'2017-08-23 15:22:39.987','Test History 8',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +10,'2017-08-23 15:22:40.001','Test History 9',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +11,'2017-08-23 15:22:40.014','Test History 10',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +12,'2017-08-23 15:22:40.028','Test History 11',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +13,'2017-08-23 15:22:40.041','Test History 12',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +14,'2017-08-23 15:22:40.056','Test History 13',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +15,'2017-08-23 15:22:40.069','Test History 14',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +16,'2017-08-23 15:22:40.083','Test History 15',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +17,'2017-08-23 15:22:40.096','Test History 16',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +18,'2017-08-23 15:22:40.108','Test History 17',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +19,'2017-08-23 15:22:40.120','Test History 18',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +20,'2017-08-23 15:22:40.133','Test History 19',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +21,'2017-08-23 15:22:40.146','Test History 20',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +22,'2017-08-23 15:22:40.159','Test History 21',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +23,'2017-08-23 15:22:40.172','Test History 22',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +24,'2017-08-23 15:22:40.186','Test History 23',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +25,'2017-08-23 15:22:40.198','Test History 24',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +26,'2017-08-23 15:22:40.212','Test History 25',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +27,'2017-08-23 15:22:40.224','Test History 26',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +28,'2017-08-23 15:22:40.235','Test History 27',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +29,'2017-08-23 15:22:40.245','Test History 28',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +30,'2017-08-23 15:22:40.258','Test History 29',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +31,'2017-08-23 15:22:40.269','Test History 30',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +32,'2017-08-23 15:22:40.284','Test History 31',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +33,'2017-08-23 15:22:40.297','Test History 32',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +34,'2017-08-23 15:22:40.308','Test History 33',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +35,'2017-08-23 15:22:40.319','Test History 34',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +36,'2017-08-23 15:22:40.333','Test History 35',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +37,'2017-08-23 15:22:40.344','Test History 36',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +38,'2017-08-23 15:22:40.357','Test History 37',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +39,'2017-08-23 15:22:40.369','Test History 38',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +40,'2017-08-23 15:22:40.380','Test History 39',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +41,'2017-08-23 15:22:40.390','Test History 40',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +42,'2017-08-23 15:22:40.400','Test History 41',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +43,'2017-08-23 15:22:40.412','Test History 42',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +44,'2017-08-23 15:22:40.423','Test History 43',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +45,'2017-08-23 15:22:40.434','Test History 44',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +46,'2017-08-23 15:22:40.448','Test History 45',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +47,'2017-08-23 15:22:40.461','Test History 46',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +48,'2017-08-23 15:22:40.472','Test History 47',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +49,'2017-08-23 15:22:40.483','Test History 48',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +50,'2017-08-23 15:22:40.494','Test History 49',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +51,'2017-08-23 15:22:40.504','Test History 50',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +52,'2017-08-23 15:22:40.515','Test History 51',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +53,'2017-08-23 15:22:40.529','Test History 52',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +54,'2017-08-23 15:22:40.541','Test History 53',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +55,'2017-08-23 15:22:40.553','Test History 54',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +56,'2017-08-23 15:22:40.567','Test History 55',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +57,'2017-08-23 15:22:40.578','Test History 56',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +58,'2017-08-23 15:22:40.590','Test History 57',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +59,'2017-08-23 15:22:40.602','Test History 58',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +60,'2017-08-23 15:22:40.616','Test History 59',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +61,'2017-08-23 15:22:40.627','Test History 60',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +62,'2017-08-23 15:22:40.638','Test History 61',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +63,'2017-08-23 15:22:40.651','Test History 62',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +64,'2017-08-23 15:22:40.663','Test History 63',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +65,'2017-08-23 15:22:40.674','Test History 64',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +66,'2017-08-23 15:22:40.686','Test History 65',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +67,'2017-08-23 15:22:40.696','Test History 66',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +68,'2017-08-23 15:22:40.708','Test History 67',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +69,'2017-08-23 15:22:40.719','Test History 68',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +70,'2017-08-23 15:22:40.729','Test History 69',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +71,'2017-08-23 15:22:40.742','Test History 70',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +72,'2017-08-23 15:22:40.755','Test History 71',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +73,'2017-08-23 15:22:40.769','Test History 72',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +74,'2017-08-23 15:22:40.785','Test History 73',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +75,'2017-08-23 15:22:40.796','Test History 74',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +76,'2017-08-23 15:22:40.808','Test History 75',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +77,'2017-08-23 15:22:40.820','Test History 76',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +78,'2017-08-23 15:22:40.835','Test History 77',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +79,'2017-08-23 15:22:40.849','Test History 78',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +80,'2017-08-23 15:22:40.861','Test History 79',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +81,'2017-08-23 15:22:40.873','Test History 80',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +82,'2017-08-23 15:22:40.884','Test History 81',1,1,6); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +83,'2017-08-23 15:22:40.896','Test History 82',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +84,'2017-08-23 15:22:40.907','Test History 83',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +85,'2017-08-23 15:22:40.921','Test History 84',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +86,'2017-08-23 15:22:40.932','Test History 85',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +87,'2017-08-23 15:22:40.945','Test History 86',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +88,'2017-08-23 15:22:40.956','Test History 87',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +89,'2017-08-23 15:22:40.968','Test History 88',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +90,'2017-08-23 15:22:40.979','Test History 89',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +91,'2017-08-23 15:22:40.992','Test History 90',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +92,'2017-08-23 15:22:41.005','Test History 91',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +93,'2017-08-23 15:22:41.028','Test History 92',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +94,'2017-08-23 15:22:41.064','Test History 93',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +95,'2017-08-23 15:22:41.095','Test History 94',1,1,2); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +96,'2017-08-23 15:22:41.118','Test History 95',1,1,1); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +97,'2017-08-23 15:22:41.138','Test History 96',1,1,4); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +98,'2017-08-23 15:22:41.148','Test History 97',1,1,3); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +99,'2017-08-23 15:22:41.158','Test History 98',1,1,5); +INSERT INTO public.history (id,create_date,message,member_id,probe_id,type_id) VALUES ( +100,'2017-08-23 15:22:41.168','Test History 99',1,1,4); \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java b/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java index 611876c..4e1afcf 100644 --- a/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/history/service/HistoryServiceTest.java @@ -2,8 +2,10 @@ package com.loafle.overflow.module.history.service; import com.loafle.overflow.module.history.model.History; import com.loafle.overflow.module.member.model.Member; +import com.loafle.overflow.module.meta.model.MetaHistoryType; import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.spring.AppConfigTest; +import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -11,6 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.util.List; +import java.util.Random; + /** * Created by insanity on 17. 8. 23. */ @@ -24,11 +29,29 @@ public class HistoryServiceTest { @Test @Ignore public void registHistories() { - for (int i=0;i<600;i++) { + for (int i=0;i<100;i++) { History h = new History(); h.setMember(new Member(1)); h.setProbe(new Probe(1)); - //h.setType(new MetaHistoryType(typeId)); + Random rand = new Random(); + int randomNum = rand.nextInt((6 - 1) + 1) + 1; + h.setType(new MetaHistoryType(randomNum)); + h.setMessage("Test History " + i); + this.historyService.regist(h); } } + + @Test + @Ignore + public void readAllHistoryByProbe() { + List result = this.historyService.readAllByProbe(new Probe(1)); + Assert.assertNotNull(result); + } + + @Test + @Ignore + public void readAllByProbeAndType() { + List result = this.historyService.readAllByProbeAndType(new Probe(1), new MetaHistoryType(1)); + Assert.assertNotNull(result); + } }