Ver código fonte

修复前一张和后一张的增加查询摄像机功能

zhuoning 4 anos atrás
pai
commit
dd042ced9a

+ 10 - 12
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/controller/ImageManagerController.java

@@ -22,7 +22,6 @@ import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
 
 import javax.imageio.ImageIO;
-import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.awt.image.BufferedImage;
@@ -120,10 +119,10 @@ public class ImageManagerController {
         }
         // 读取记录数
         int total = 0;
-        if(catalog != null && !catalog.trim().isEmpty()){
-            total= imageService.getTotal(startDate, endDate,catalog);
-        }else{
-            total= imageService.getTotal(startDate, endDate);
+        if (catalog != null && !catalog.trim().isEmpty()) {
+            total = imageService.getTotal(startDate, endDate, catalog);
+        } else {
+            total = imageService.getTotal(startDate, endDate);
         }
 
 
@@ -143,9 +142,9 @@ public class ImageManagerController {
      * @Time : 19:09
      */
     @RequestMapping(value = "/getPreviousImage", method = RequestMethod.GET)
-    public Result getPreviousImage(@RequestParam(value = "imageId", required = true) int imageId) {
+    public Result getPreviousImage(@RequestParam(value = "imageId", required = true) int imageId, @RequestParam(value = "catalog", required = false) String catalog) {
         //
-        ImagePathEntity imagePathEntity = imageService.getOneImage("previous", imageId);
+        ImagePathEntity imagePathEntity = imageService.getOneImage("previous", imageId,catalog);
         if (imagePathEntity == null) {
             return new Result(10001, "未查询到任何记录.", false);
         } else {
@@ -163,9 +162,9 @@ public class ImageManagerController {
      * @Time : 19:09
      */
     @RequestMapping(value = "/getNextImage", method = RequestMethod.GET)
-    public Result getNextImage(@RequestParam(value = "imageId", required = true) int imageId) {
+    public Result getNextImage(@RequestParam(value = "imageId", required = true) int imageId, @RequestParam(value = "catalog", required = false) String catalog) {
         //
-        ImagePathEntity imagePathEntity = imageService.getOneImage("next", imageId);
+        ImagePathEntity imagePathEntity = imageService.getOneImage("next", imageId, catalog);
         if (imagePathEntity == null) {
             return new Result(10001, "未查询到任何记录.", false);
         } else {
@@ -337,7 +336,7 @@ public class ImageManagerController {
         List<ImagePathEntity> imageList = new ArrayList<>();
         if (catalog != null && !catalog.trim().isEmpty()) {
             // 读取图片文件
-            imageList = imageService.getExportImageList(startDate, endDate, imageIds,catalog);
+            imageList = imageService.getExportImageList(startDate, endDate, imageIds, catalog);
         } else {
             // 读取图片文件
             imageList = imageService.getExportImageList(startDate, endDate, imageIds);
@@ -367,7 +366,7 @@ public class ImageManagerController {
         if (catalog != null && !catalog.trim().isEmpty()) {
             name = camera;
         }
-        String fileName = name +"_"+ dateUtil.formatLongTimeForTime(new Date().getTime());
+        String fileName = name + "_" + dateUtil.formatLongTimeForTime(new Date().getTime());
         String zipFileName = fileName + ".zip";
         File zipFile = null;
         String path = rootPath + "temp_download";
@@ -571,7 +570,6 @@ public class ImageManagerController {
         if (imagePathEntity == null) {
             log.error("imagePathEntity[" + imagePathEntity.toString() + "]==null");
         }
-
         // 拼接完整图片路径。这里填写图片链接
 //        String urlPath = "";
         // 获取图片文件后缀名

+ 26 - 0
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/dao/repo/ImagePathRepo.java

@@ -128,4 +128,30 @@ public interface ImagePathRepo extends JpaRepository<ImagePathEntity, Integer>,
      */
     @Query(nativeQuery = true, value = "SELECT * FROM image_path WHERE id=:imageId")
     ImagePathEntity getOneImageById(String imageId);
+
+    /**
+     * @Method      : getNextImageById
+     * @Description : 带有目录的下一张图片
+     * @Params      : [imageId, catalog]
+     * @Return      : com.huimv.manager.dao.entity.ImagePathEntity
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/1/28       
+     * @Time        : 9:18
+     */
+    @Query(nativeQuery = true, value = "SELECT * FROM image_path WHERE name=:catalog AND id>:imageId ORDER BY id ASC LIMIT 1")
+    ImagePathEntity getNextImageById(int imageId, String catalog);
+
+    /**
+     * @Method      : getPreviousImageById
+     * @Description : 带有目录的前一张图片
+     * @Params      : [imageId, catalog]
+     * @Return      : com.huimv.manager.dao.entity.ImagePathEntity
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/1/28       
+     * @Time        : 9:19
+     */
+    @Query(nativeQuery = true, value = "SELECT * FROM image_path WHERE name=:catalog AND id<:imageId ORDER BY id DESC LIMIT 1")
+    ImagePathEntity getPreviousImageById(int imageId, String catalog);
 }

+ 1 - 2
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/service/IImageService.java

@@ -1,6 +1,5 @@
 package com.huimv.manager.service;
 
-import com.alibaba.fastjson.JSONObject;
 import com.huimv.manager.dao.entity.ImagePathEntity;
 
 import java.util.List;
@@ -76,7 +75,7 @@ public interface IImageService {
      * @Date        : 2021/1/23       
      * @Time        : 19:25
      */
-    ImagePathEntity getOneImage(String type, int imageId);
+    ImagePathEntity getOneImage(String type, int imageId, String catalog);
 
     /**
      * @Method      : getOneImageDetail

+ 21 - 12
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/service/impl/ImageServiceImpl.java

@@ -1,6 +1,5 @@
 package com.huimv.manager.service.impl;
 
-import com.alibaba.fastjson.JSONObject;
 import com.huimv.manager.dao.entity.ImagePathEntity;
 import com.huimv.manager.dao.repo.ImagePathRepo;
 import com.huimv.manager.service.IImageService;
@@ -76,7 +75,7 @@ public class ImageServiceImpl implements IImageService {
         int start = (pageNo - 1) * pageSize;
         if (catalog != null && !catalog.isEmpty()) {
             // 按照日期区间,读取图片列表
-            return imagePathRepo.listImage(startDate, endDate, start, pageSize,catalog);
+            return imagePathRepo.listImage(startDate, endDate, start, pageSize, catalog);
         } else {
             // 按照日期区间,读取图片列表
             return imagePathRepo.listImage(startDate, endDate, start, pageSize);
@@ -93,9 +92,9 @@ public class ImageServiceImpl implements IImageService {
      * @Time : 16:50
      */
     @Override
-    public int getTotal(String startDate, String endDate,String catalog) {
+    public int getTotal(String startDate, String endDate, String catalog) {
         // 根据条件读取总记录数
-        return imagePathRepo.getTotal(startDate, endDate,catalog);
+        return imagePathRepo.getTotal(startDate, endDate, catalog);
     }
 
     @Override
@@ -123,11 +122,11 @@ public class ImageServiceImpl implements IImageService {
     }
 
     @Override
-    public List<ImagePathEntity> getExportImageList(String startDate, String endDate, String imageIds,String catalog) {
+    public List<ImagePathEntity> getExportImageList(String startDate, String endDate, String imageIds, String catalog) {
         // 以指定图片导出优先条件
         if (imageIds == null || imageIds.trim().isEmpty()) {
             // 用startDate,endDate读取需要导出的图片
-            return imagePathRepo.getExportImageListByStartAndEndDate(startDate, endDate,catalog);
+            return imagePathRepo.getExportImageListByStartAndEndDate(startDate, endDate, catalog);
         } else {
             // 指定需要导出的图片
             String[] idArray = imageIds.split(",");
@@ -141,13 +140,23 @@ public class ImageServiceImpl implements IImageService {
     }
 
     @Override
-    public ImagePathEntity getOneImage(String type, int imageId) {
-        if (type.trim().equalsIgnoreCase("next")) {
-            // 读取下一张照片
-            return imagePathRepo.getNextImageById(imageId);
+    public ImagePathEntity getOneImage(String type, int imageId, String catalog) {
+        if (catalog == null || catalog.trim().isEmpty()) {
+            if (type.trim().equalsIgnoreCase("next")) {
+                // 读取下一张照片
+                return imagePathRepo.getNextImageById(imageId);
+            } else {
+                // 读取上一张照片
+                return imagePathRepo.getPreviousImageById(imageId);
+            }
         } else {
-            // 读取上一张照片
-            return imagePathRepo.getPreviousImageById(imageId);
+            if (type.trim().equalsIgnoreCase("next")) {
+                // 读取下一张照片
+                return imagePathRepo.getNextImageById(imageId,catalog);
+            } else {
+                // 读取上一张照片
+                return imagePathRepo.getPreviousImageById(imageId,catalog);
+            }
         }
     }