Jelajahi Sumber

点播记录搜索时增加时间起始点的判断

yaobo 7 tahun lalu
induk
melakukan
320dc803c1

+ 23 - 8
src/main/java/cn/efunbox/audio/controller/RecordController.java

@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.sql.Timestamp;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -35,6 +36,8 @@ public class RecordController {
         String idChannel = request.getParameter("idChannel");
         String idDevice = request.getParameter("idDevice");
         String idAudio = request.getParameter("idAudio");
+        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)
@@ -50,14 +53,26 @@ public class RecordController {
         List<Record> list = null;
         if(idRecord!=null && idRecord.length()>0)
             list = recordService.SearchById(Long.valueOf(idRecord));
-        else if(idChannel!=null && idChannel.length()>0)
-            pageRes = recordService.SearchByIdChannel(Long.valueOf(idChannel), Integer.valueOf(page), Integer.valueOf(size));
-        else if(idDevice!=null && idDevice.length()>0)
-            pageRes = recordService.SearchByIdDevice(Long.valueOf(idDevice), Integer.valueOf(page), Integer.valueOf(size));
-        else if(idAudio!=null && idAudio.length()>0)
-            pageRes = recordService.SearchByIdAudio(Long.valueOf(idAudio), Integer.valueOf(page), Integer.valueOf(size));
-        else
-            pageRes = recordService.SearchAll(Integer.valueOf(page), Integer.valueOf(size));
+        else if((start==null || start.length()==0) && (end==null || end.length()==0)){
+            if(idChannel!=null && idChannel.length()>0)
+                pageRes = recordService.SearchByIdChannel(Long.valueOf(idChannel), Integer.valueOf(page), Integer.valueOf(size));
+            else if(idDevice!=null && idDevice.length()>0)
+                pageRes = recordService.SearchByIdDevice(Long.valueOf(idDevice), Integer.valueOf(page), Integer.valueOf(size));
+            else if(idAudio!=null && idAudio.length()>0)
+                pageRes = recordService.SearchByIdAudio(Long.valueOf(idAudio), Integer.valueOf(page), Integer.valueOf(size));
+            else
+                pageRes = recordService.SearchAll(Integer.valueOf(page), Integer.valueOf(size));
+        }else{
+            if(idChannel!=null && idChannel.length()>0)
+                pageRes = recordService.SearchByIdChannelAndCreatedBetween(Long.valueOf(idChannel), Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
+            else if(idDevice!=null && idDevice.length()>0)
+                pageRes = recordService.SearchByIdDeviceAndCreatedBetween(Long.valueOf(idDevice), Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
+            else if(idAudio!=null && idAudio.length()>0)
+                pageRes = recordService.SearchByIdAudioAndCreatedBetween(Long.valueOf(idAudio), Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
+            else
+                pageRes = recordService.SearchCreatedBetween(Integer.valueOf(page), Integer.valueOf(size), Timestamp.valueOf(start), Timestamp.valueOf(end));
+        }
+
 
 //        if(list==null || list.size()<1){
 //            HttpUtil.responseApiCode(request, response, ApiCode.NOT_FOUND);

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

@@ -13,6 +13,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.ArrayList;
 import java.util.List;
 
@@ -68,6 +69,42 @@ public class RecordServiceImpl implements RecordService {
     }
 
     @Override
+    public Page<Record> SearchCreatedBetween(int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Record> list = recordRepo.findByCreatedBetween(start, end, pageable);
+        return list;
+    }
+
+    @Override
+    public Page<Record> SearchByIdChannelAndCreatedBetween(Long id, int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Record> list = recordRepo.findByIdChannelAndCreatedBetween(id, start, end, pageable);
+        return list;
+    }
+
+    @Override
+    public Page<Record> SearchByIdDeviceAndCreatedBetween(Long id, int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Record> list = recordRepo.findByIdDeviceAndCreatedBetween(id, start, end, pageable);
+        return list;
+    }
+
+    @Override
+    public Page<Record> SearchByIdAudioAndCreatedBetween(Long id, int page, int size, Timestamp start, Timestamp end){
+        if(size<=0)
+            size = 50;
+        Pageable pageable = new PageRequest(page, size);
+        Page<Record> list = recordRepo.findByIdAudioAndCreatedBetween(id, start, end, pageable);
+        return list;
+    }
+
+    @Override
     public Record Insert(Record r){
         r = recordRepo.save(r);
         return r;

+ 9 - 0
src/main/java/cn/efunbox/audio/repository/RecordRepo.java

@@ -9,6 +9,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;
 
 /**
@@ -25,4 +26,12 @@ public interface RecordRepo extends JpaRepository<Record, Long> {
 
     Page<Record> findByIdAudio(Long id, Pageable pageable);
 
+    Page<Record> findByCreatedBetween(Timestamp start, Timestamp end, Pageable pageable);
+
+    Page<Record> findByIdChannelAndCreatedBetween(Long id, Timestamp start, Timestamp end, Pageable pageable);
+
+    Page<Record> findByIdDeviceAndCreatedBetween(Long id, Timestamp start, Timestamp end, Pageable pageable);
+
+    Page<Record> findByIdAudioAndCreatedBetween(Long id, Timestamp start, Timestamp end, Pageable pageable);
+
 }

+ 10 - 0
src/main/java/cn/efunbox/audio/service/RecordService.java

@@ -4,6 +4,8 @@ import cn.efunbox.audio.entity.Audio;
 import cn.efunbox.audio.entity.Record;
 import org.springframework.data.domain.Page;
 
+import java.sql.Date;
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -21,6 +23,14 @@ public interface RecordService {
 
     public Page<Record> SearchByIdAudio(Long id, int page, int size);
 
+    public Page<Record> SearchCreatedBetween(int page, int size, Timestamp start, Timestamp end);
+
+    public Page<Record> SearchByIdChannelAndCreatedBetween(Long id, int page, int size, Timestamp start, Timestamp end);
+
+    public Page<Record> SearchByIdDeviceAndCreatedBetween(Long id, int page, int size, Timestamp start, Timestamp end);
+
+    public Page<Record> SearchByIdAudioAndCreatedBetween(Long id, int page, int size, Timestamp start, Timestamp end);
+
     public Record Insert(Record record);
 
     public void Delete(Long id);