Pārlūkot izejas kodu

device/trail的都是都增加时间起始点的判断

yaobo 7 gadi atpakaļ
vecāks
revīzija
08e1583fa2

+ 12 - 2
src/main/java/cn/efunbox/audio/controller/DeviceController.java

@@ -223,6 +223,8 @@ public class DeviceController {
     public void Search(HttpServletRequest request, HttpServletResponse response){
         String idDevice = request.getParameter("idDevice");
         String idChannel = request.getParameter("idChannel");
+        String start = request.getParameter("start");
+        String end = request.getParameter("end");
         String page = request.getParameter("page");
         String size = request.getParameter("size");
         if(page==null || page.length()<1)
@@ -232,7 +234,11 @@ public class DeviceController {
         Map<String,Object> map = new HashMap<>();
 
         if((idDevice==null || idDevice.length()==0) && (idChannel==null || idChannel.length()==0)){
-            Page<Device> pageRes = deviceService.SearchAll(Integer.valueOf(page), Integer.valueOf(size));
+            Page<Device> pageRes = null;
+            if((start==null || start.length()==0) || (end==null || end.length()==0))
+                pageRes = deviceService.SearchAll(Integer.valueOf(page), Integer.valueOf(size));
+            else
+                pageRes = deviceService.SearchAll(Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
             for(int i=0; i<pageRes.getNumberOfElements(); i++){
                 pageRes.getContent().get(i).setTokenNew("");
                 pageRes.getContent().get(i).setTokenOld("");
@@ -245,7 +251,11 @@ public class DeviceController {
                 idDevice = "0";
             if(idChannel==null || idChannel.length()==0)
                 idChannel = "0";
-            Page<Device> pageRes = deviceService.Search(Long.valueOf(idChannel), Long.valueOf(idDevice), Integer.valueOf(page), Integer.valueOf(size));
+            Page<Device> pageRes = null;
+            if((start==null || start.length()==0) || (end==null || end.length()==0))
+                pageRes = deviceService.Search(Long.valueOf(idChannel), Long.valueOf(idDevice), Integer.valueOf(page), Integer.valueOf(size));
+            else
+                pageRes = deviceService.Search(Long.valueOf(idChannel), Long.valueOf(idDevice), Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
             for(int i=0; i<pageRes.getNumberOfElements(); i++){
                 System.out.println("i:"+i);
                 pageRes.getContent().get(i).setTokenNew("");

+ 23 - 9
src/main/java/cn/efunbox/audio/controller/TrailController.java

@@ -47,6 +47,8 @@ public class TrailController {
         String idAdmin = request.getParameter("idAdmin");
         String target = request.getParameter("target");
         String idTarget = request.getParameter("idTarget");
+        String start = request.getParameter("start");
+        String end = request.getParameter("end");
         String page = request.getParameter("page");
         String size = request.getParameter("size");
         if(page==null || page.length()<1)
@@ -55,16 +57,28 @@ public class TrailController {
             size = "0";
         Map<String,Object> map = new HashMap<>();
         Page<Trail> pageRes = null;
-        if(idAdmin!=null && idAdmin.length()>0)
-            pageRes = trailService.SearchByIdAdmin(Long.valueOf(idAdmin), Integer.valueOf(page), Integer.valueOf(size));
-        else if(target!=null && target.length()>0 && idTarget!=null && idTarget.length()>0)
+        if(target!=null && target.length()>0 && idTarget!=null && idTarget.length()>0)
             pageRes = trailService.SearchByTargetAndIdTarget(target, Long.valueOf(idTarget), Integer.valueOf(page), Integer.valueOf(size));
-        else if(target!=null && target.length()>0)
-            pageRes = trailService.SearchByTarget(target, Integer.valueOf(page), Integer.valueOf(size));
-        else if(idTarget!=null && idTarget.length()>0)
-            pageRes = trailService.SearchByIdTarget(Long.valueOf(idTarget), Integer.valueOf(page), Integer.valueOf(size));
-        else
-            pageRes = trailService.SearchAll(Integer.valueOf(page), Integer.valueOf(size));
+        else if((start==null || start.length()==0) || (end==null || end.length()==0)){
+            if(idAdmin!=null && idAdmin.length()>0)
+                pageRes = trailService.SearchByIdAdmin(Long.valueOf(idAdmin), Integer.valueOf(page), Integer.valueOf(size));
+            else if(target!=null && target.length()>0)
+                pageRes = trailService.SearchByTarget(target, Integer.valueOf(page), Integer.valueOf(size));
+            else if(idTarget!=null && idTarget.length()>0)
+                pageRes = trailService.SearchByIdTarget(Long.valueOf(idTarget), Integer.valueOf(page), Integer.valueOf(size));
+            else
+                pageRes = trailService.SearchAll(Integer.valueOf(page), Integer.valueOf(size));
+        }else {
+            if(idAdmin!=null && idAdmin.length()>0)
+                pageRes = trailService.SearchByIdAdminAndCreatedBetween(Long.valueOf(idAdmin), Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
+            else if(target!=null && target.length()>0)
+                pageRes = trailService.SearchByTargetAndCreatedBetween(target, Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
+            else if(idTarget!=null && idTarget.length()>0)
+                pageRes = trailService.SearchByIdTargetAndCreatedBetween(Long.valueOf(idTarget), Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
+            else
+                pageRes = trailService.SearchByCreatedBetween(Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
+        }
+
 
         if(pageRes!=null){
             map.put("data", pageRes.getContent());

+ 26 - 0
src/main/java/cn/efunbox/audio/impl/DeviceServiceImpl.java

@@ -96,12 +96,38 @@ public class DeviceServiceImpl implements DeviceService {
 
     @Override
     public Page<Device> SearchAll(int page, int size){
+        if(size<=0)
+            size = 50;
         Pageable pageable = new PageRequest(page, size);
         Page<Device> list = deviceRepo.findAll(pageable);
         return list;
     }
 
     @Override
+    public Page<Device> Search(Long idChannel, Long idDevice, int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Device> list = null;
+        if(idChannel>0)
+            list = deviceRepo.findByIdChannelAndCreatedBetween(idChannel, start, end, pageable);
+        else if(idDevice>0)
+            list = deviceRepo.findByIdDeviceAndCreatedBetween(idDevice, start, end, pageable);
+        else
+            list = deviceRepo.findByCreatedBetween(start, end, pageable);
+        return list;
+    }
+
+    @Override
+    public Page<Device> SearchAll(int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Device> list = deviceRepo.findByCreatedBetween(start, end, pageable);
+        return list;
+    }
+
+    @Override
     public Device Update(Device device){
         device = deviceRepo.save(device);
         return device;

+ 37 - 0
src/main/java/cn/efunbox/audio/impl/TrailServiceImpl.java

@@ -12,6 +12,7 @@ import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -75,6 +76,42 @@ public class TrailServiceImpl implements TrailService {
     }
 
     @Override
+    public Page<Trail> SearchByCreatedBetween(int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Trail> list = trailRepo.findByCreatedBetween(start, end, pageable);
+        return list;
+    }
+
+    @Override
+    public Page<Trail> SearchByIdAdminAndCreatedBetween(Long idAdmin, int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Trail> list = trailRepo.findByIdAdminAndCreatedBetween(idAdmin, start, end, pageable);
+        return list;
+    }
+
+    @Override
+    public Page<Trail> SearchByTargetAndCreatedBetween(String target, int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Trail> list = trailRepo.findByTargetAndCreatedBetween(target, start, end, pageable);
+        return list;
+    }
+
+    @Override
+    public Page<Trail> SearchByIdTargetAndCreatedBetween(Long idTarget, int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Trail> list = trailRepo.findByIdTargetAndCreatedBetween(idTarget, start, end, pageable);
+        return list;
+    }
+
+    @Override
     public Trail Insert(Trail trail){
         Trail t = trailRepo.save(trail);
         return t;

+ 4 - 0
src/main/java/cn/efunbox/audio/repository/DeviceRepo.java

@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -19,6 +20,9 @@ public interface DeviceRepo extends JpaRepository<Device, Long> {
     Device findById(Long id);
     Page<Device> findByIdDevice(Long idDevice, Pageable pageable);
     Page<Device> findByIdChannel(Long idChannel, Pageable pageable);
+    Page<Device> findByIdDeviceAndCreatedBetween(Long idDevice, Timestamp start, Timestamp end, Pageable pageable);
+    Page<Device> findByIdChannelAndCreatedBetween(Long idChannel, Timestamp start, Timestamp end, Pageable pageable);
+    Page<Device> findByCreatedBetween(Timestamp start, Timestamp end, Pageable pageable);
 
     @Query("from Device d where d.idDevice=:idDevice")
     List<Device> findByDevice(@Param("idDevice")String idDevice);

+ 5 - 0
src/main/java/cn/efunbox/audio/repository/TrailRepo.java

@@ -7,6 +7,7 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -22,4 +23,8 @@ public interface TrailRepo extends JpaRepository<Trail, Long> {
     public Page<Trail> findByIdTarget(Long idTarget, Pageable pageable);
     public Page<Trail> findByTargetAndIdTarget(String target, Long idTarget, Pageable pageable);
 
+    public Page<Trail> findByCreatedBetween(Timestamp start, Timestamp end, Pageable pageable);
+    public Page<Trail> findByIdAdminAndCreatedBetween(Long idAdmin, Timestamp start, Timestamp end, Pageable pageable);
+    public Page<Trail> findByTargetAndCreatedBetween(String target, Timestamp start, Timestamp end, Pageable pageable);
+    public Page<Trail> findByIdTargetAndCreatedBetween(Long idTarget, Timestamp start, Timestamp end, Pageable pageable);
 }

+ 5 - 0
src/main/java/cn/efunbox/audio/service/DeviceService.java

@@ -3,6 +3,7 @@ package cn.efunbox.audio.service;
 import cn.efunbox.audio.entity.Device;
 import org.springframework.data.domain.Page;
 
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -22,6 +23,10 @@ public interface DeviceService {
 
     public Page<Device> SearchAll(int page, int size);
 
+    public Page<Device> Search(Long idChannel, Long idDevice, int page, int size, Timestamp start, Timestamp end);
+
+    public Page<Device> SearchAll(int page, int size, Timestamp start, Timestamp end);
+
     public Device Update(Device device);
 
     public void Delete(Long id);

+ 9 - 0
src/main/java/cn/efunbox/audio/service/TrailService.java

@@ -4,6 +4,7 @@ import cn.efunbox.audio.entity.Channel;
 import cn.efunbox.audio.entity.Trail;
 import org.springframework.data.domain.Page;
 
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -23,5 +24,13 @@ public interface TrailService {
 
     public Page<Trail> SearchByTargetAndIdTarget(String target, Long idTarget, int page, int size);
 
+    public Page<Trail> SearchByCreatedBetween(int page, int size, Timestamp start, Timestamp end);
+
+    public Page<Trail> SearchByIdAdminAndCreatedBetween(Long idAdmin, int page, int size, Timestamp start, Timestamp end);
+
+    public Page<Trail> SearchByTargetAndCreatedBetween(String target, int page, int size, Timestamp start, Timestamp end);
+
+    public Page<Trail> SearchByIdTargetAndCreatedBetween(Long idTarget, int page, int size, Timestamp start, Timestamp end);
+
     public Trail Insert(Trail trail);
 }