فهرست منبع

新建查询中增加目录查询功能

zhuoning 4 سال پیش
والد
کامیت
87c3c6d50b

+ 30 - 0
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/controller/ImageCatalogController.java

@@ -0,0 +1,30 @@
+package com.huimv.manager.controller;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.manager.service.IImageCatalogSerivce;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@RestController
+@RequestMapping("/catalog")
+public class ImageCatalogController {
+    @Autowired
+    private IImageCatalogSerivce imageCatalogSerivce;
+
+    @RequestMapping(value = "/list",method = RequestMethod.GET)
+    public JSONArray getCatalog(){
+        //
+        return imageCatalogSerivce.getImageCatalog();
+    }
+}

+ 5 - 2
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/controller/ImageManagerController.java

@@ -90,13 +90,16 @@ public class ImageManagerController {
      */
     @Deprecated
     @RequestMapping(value = "/listImage", method = RequestMethod.GET)
-    public JSONObject listImage(@RequestParam(value = "startDate", required = true) String startDate, @RequestParam(value = "endDate", required = true) String endDate, @RequestParam(value = "pageNo", required = true) int pageNo, @RequestParam(value = "pageSize", required = true) int pageSize) {
+    public JSONObject listImage(@RequestParam(value = "startDate", required = true) String startDate, @RequestParam(value = "endDate", required = true) String endDate, @RequestParam(value = "catalog", required = false) String catalog, @RequestParam(value = "pageNo", required = true) int pageNo, @RequestParam(value = "pageSize", required = true) int pageSize) {
         log.info("startDate>>" + startDate);
         log.info("endDate>>" + endDate);
+        log.info("catalog>>"+catalog);
         log.info("pageNo>>" + pageNo);
         log.info("pageSize>>" + pageSize);
+        // 搜索记录时,catalog是非必要字段;
+        // 导出图片时,catalog是必要字段;
         //
-        List<ImagePathEntity> imageList = imageService.getImageList(startDate, endDate, pageNo, pageSize);
+        List<ImagePathEntity> imageList = imageService.getImageList(startDate, endDate, pageNo, pageSize,catalog);
         JSONArray imageJa = new JSONArray();
         for (ImagePathEntity imageEntity : imageList) {
 //            JSONObject dataJo = (JSONObject) JSONObject.toJSON(imageEntity);

+ 5 - 0
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/dao/repo/ImageCatalogEntityRepository.java

@@ -3,7 +3,12 @@ package com.huimv.manager.dao.repo;
 import com.huimv.manager.dao.entity.ImageCatalogEntity;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.List;
 
 public interface ImageCatalogEntityRepository extends JpaRepository<ImageCatalogEntity, Integer>, JpaSpecificationExecutor<ImageCatalogEntity> {
 
+    @Query(nativeQuery = true, value = "SELECT * FROM image_catalog")
+    List<ImageCatalogEntity> getImageCatalog();
 }

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

@@ -38,6 +38,10 @@ public interface ImagePathRepo extends JpaRepository<ImagePathEntity, Integer>,
     @Query(nativeQuery = true, value = "SELECT id,name,img_path,relative_path,file_name,effective,ai_result,ai_time_used,ai_data,create_date,pig_quantity FROM image_path WHERE DATE_FORMAT(create_date,'%Y-%m-%d')>=DATE_FORMAT(:startDate,'%Y-%m-%d') AND DATE_FORMAT(create_date,'%Y-%m-%d')<=DATE_FORMAT(:endDate,'%Y-%m-%d') ORDER BY create_date DESC LIMIT :pageNo,:pageSize")
     List<ImagePathEntity> listImage(String startDate, String endDate,int pageNo,int pageSize);
 
+    @Query(nativeQuery = true, value = "SELECT id,name,img_path,relative_path,file_name,effective,ai_result,ai_time_used,ai_data,create_date,pig_quantity FROM image_path WHERE DATE_FORMAT(create_date,'%Y-%m-%d')>=DATE_FORMAT(:startDate,'%Y-%m-%d') AND DATE_FORMAT(create_date,'%Y-%m-%d')<=DATE_FORMAT(:endDate,'%Y-%m-%d') AND name=:catalog ORDER BY create_date DESC LIMIT :pageNo,:pageSize")
+    List<ImagePathEntity> listImage(String startDate, String endDate,int pageNo,int pageSize,String catalog);
+
+
     @Query(nativeQuery = true, value = "SELECT id,name,img_path,relative_path,file_name,effective,ai_result,ai_time_used,ai_data,create_date,pig_quantity FROM image_path WHERE DATE_FORMAT(create_date,'%Y-%m-%d')>=DATE_FORMAT(:startDate,'%Y-%m-%d') AND DATE_FORMAT(create_date,'%Y-%m-%d')<=DATE_FORMAT(:endDate,'%Y-%m-%d') ORDER BY create_date DESC LIMIT :pageNo,:pageSize")
     List<ImagePathEntity> listImage2(String startDate, String endDate,int pageNo,int pageSize);
 

+ 19 - 0
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/service/IImageCatalogSerivce.java

@@ -0,0 +1,19 @@
+package com.huimv.manager.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+public interface IImageCatalogSerivce {
+
+    /**
+     * @Method      : getImageCatalog
+     * @Description : 
+     * @Params      : []
+     * @Return      : com.alibaba.fastjson.JSONObject
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/1/26       
+     * @Time        : 11:24
+     */
+    JSONArray getImageCatalog();
+}

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

@@ -40,7 +40,7 @@ public interface IImageService {
      * @Date        : 2021/1/22       
      * @Time        : 16:04
      */
-    List<ImagePathEntity> getImageList(String startDate, String endDate,int pageNo,int pageSize);
+    List<ImagePathEntity> getImageList(String startDate, String endDate,int pageNo,int pageSize,String catalog);
 
     /**
      * @Method      : getTotal

+ 54 - 0
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/service/impl/ImageCatalogServiceImpl.java

@@ -0,0 +1,54 @@
+package com.huimv.manager.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.manager.dao.entity.ImageCatalogEntity;
+import com.huimv.manager.dao.repo.ImageCatalogEntityRepository;
+import com.huimv.manager.service.IImageCatalogSerivce;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Service
+public class ImageCatalogServiceImpl implements IImageCatalogSerivce {
+    @Autowired
+    private ImageCatalogEntityRepository imageCatalogRepo;
+
+    @Override
+    public JSONArray getImageCatalog() {
+        //
+        List<ImageCatalogEntity> imageCatalogEntityList = imageCatalogRepo.getImageCatalog();
+        if(imageCatalogEntityList.size()>0){
+//            JSONArray dataJa = (JSONArray) JSONObject.toJSON(imageCatalogEntityList);
+//            System.out.println("dataJa>>"+dataJa);
+            JSONArray newJa = new JSONArray();
+            JSONObject emptyJo = new JSONObject();
+            emptyJo.put("catalogName","全部");
+            emptyJo.put("catalogPath","");
+            newJa.add(emptyJo);
+            for(ImageCatalogEntity imageCatalogEntity:imageCatalogEntityList){
+                JSONObject dataJo = new JSONObject();
+                dataJo.put("catalogName",imageCatalogEntity.getCatalogName());
+                dataJo.put("catalogPath",imageCatalogEntity.getCatalogPath());
+                newJa.add(dataJo);
+            }
+            return newJa;
+        }else{
+            JSONObject emptyJo = new JSONObject();
+            emptyJo.put("catalogName","全部");
+            emptyJo.put("catalogPath","");
+            JSONArray newJa = new JSONArray();
+            newJa.add(emptyJo);
+            return newJa;
+        }
+    }
+}

+ 49 - 48
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/service/impl/ImageServiceImpl.java

@@ -24,14 +24,13 @@ public class ImageServiceImpl implements IImageService {
     private ImagePathRepo imagePathRepo;
 
     /**
-     * @Method      : getLastImage
+     * @Method : getLastImage
      * @Description : 读取最后一幅图像
-     * @Params      : []
-     * @Return      : java.lang.String
-     *
-     * @Author      : ZhuoNing
-     * @Date        : 2021/1/21
-     * @Time        : 20:49
+     * @Params : []
+     * @Return : java.lang.String
+     * @Author : ZhuoNing
+     * @Date : 2021/1/21
+     * @Time : 20:49
      */
     @Override
     public ImagePathEntity getLastImage() {
@@ -41,76 +40,78 @@ public class ImageServiceImpl implements IImageService {
     }
 
     /**
-     * @Method      : getNextImage
+     * @Method : getNextImage
      * @Description : 读取下一副图像
-     * @Params      : []
-     * @Return      : java.lang.String
-     *
-     * @Author      : ZhuoNing
-     * @Date        : 2021/1/21
-     * @Time        : 20:49
+     * @Params : []
+     * @Return : java.lang.String
+     * @Author : ZhuoNing
+     * @Date : 2021/1/21
+     * @Time : 20:49
      */
     @Override
     public ImagePathEntity getNextImage() {
         // 读取下一副图像
         ImagePathEntity imagePathEntity = imagePathRepo.getNextImage();
-        if(imagePathEntity!=null){
+        if (imagePathEntity != null) {
             // 更改记录
             imagePathEntity.setEffective(0);
             imagePathRepo.saveAndFlush(imagePathEntity);
             return imagePathEntity;
-        }else{
+        } else {
             return imagePathRepo.getLastImage();
         }
     }
 
     /**
-     * @Method      : getImageList
-     * @Description : 
-     * @Params      : [startDate, endDate, pageNo, pageSize]
-     * @Return      : java.util.List<com.huimv.manager.dao.entity.ImagePathEntity>
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2021/1/22       
-     * @Time        : 16:50
+     * @Method : getImageList
+     * @Description :
+     * @Params : [startDate, endDate, pageNo, pageSize]
+     * @Return : java.util.List<com.huimv.manager.dao.entity.ImagePathEntity>
+     * @Author : ZhuoNing
+     * @Date : 2021/1/22
+     * @Time : 16:50
      */
     @Override
-    public List<ImagePathEntity> getImageList(String startDate, String endDate,int pageNo,int pageSize) {
-        System.out.println("pageNo>>"+pageNo);
-        System.out.println("pageSize>>"+pageSize);
-        int start = (pageNo-1)*pageSize;
-        System.out.println("start>>"+start);
-        // 按照日期区间,读取图片列表
-        return imagePathRepo.listImage(startDate,endDate,start,pageSize);
+    public List<ImagePathEntity> getImageList(String startDate, String endDate, int pageNo, int pageSize, String catalog) {
+        System.out.println("pageNo>>" + pageNo);
+        System.out.println("pageSize>>" + pageSize);
+        int start = (pageNo - 1) * pageSize;
+        System.out.println("start>>" + start);
+        if (catalog != null && !catalog.isEmpty()) {
+            // 按照日期区间,读取图片列表
+            return imagePathRepo.listImage(startDate, endDate, start, pageSize,catalog);
+        } else {
+            // 按照日期区间,读取图片列表
+            return imagePathRepo.listImage(startDate, endDate, start, pageSize);
+        }
     }
 
     /**
-     * @Method      : getTotal
-     * @Description : 
-     * @Params      : [startDate, endDate]
-     * @Return      : int
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2021/1/22       
-     * @Time        : 16:50
+     * @Method : getTotal
+     * @Description :
+     * @Params : [startDate, endDate]
+     * @Return : int
+     * @Author : ZhuoNing
+     * @Date : 2021/1/22
+     * @Time : 16:50
      */
     @Override
     public int getTotal(String startDate, String endDate) {
         // 根据条件读取总记录数
-        return imagePathRepo.getTotal(startDate,endDate);
+        return imagePathRepo.getTotal(startDate, endDate);
     }
 
     @Override
     public List<ImagePathEntity> getExportImageList(String startDate, String endDate, String imageIds) {
         // 以指定图片导出优先条件
-        if(imageIds == null || imageIds.trim().isEmpty()){
+        if (imageIds == null || imageIds.trim().isEmpty()) {
             // 用startDate,endDate读取需要导出的图片
-            return imagePathRepo.getExportImageListByStartAndEndDate(startDate,endDate);
-        }else{
+            return imagePathRepo.getExportImageListByStartAndEndDate(startDate, endDate);
+        } else {
             // 指定需要导出的图片
             String[] idArray = imageIds.split(",");
             List imageIdList = new ArrayList();
-            for(String id:idArray){
+            for (String id : idArray) {
                 imageIdList.add(id);
             }
             // 读取导出图片
@@ -120,12 +121,12 @@ public class ImageServiceImpl implements IImageService {
 
     @Override
     public ImagePathEntity getOneImage(String type, int imageId) {
-        if(type.trim().equalsIgnoreCase("next")){
+        if (type.trim().equalsIgnoreCase("next")) {
             // 读取下一张照片
-            return  imagePathRepo.getNextImageById(imageId);
-        }else{
+            return imagePathRepo.getNextImageById(imageId);
+        } else {
             // 读取上一张照片
-            return  imagePathRepo.getPreviousImageById(imageId);
+            return imagePathRepo.getPreviousImageById(imageId);
         }
     }
 

+ 10 - 7
huimv-video/huimv-video-process/src/main/java/com/huimv/process/service/impl/ImageServiceImpl.java

@@ -53,28 +53,31 @@ public class ImageServiceImpl implements IImageService {
      * @Time : 17:31
      */
     @Override
-    public JSONObject saveImage(String imageBase64, String name) {
+    public JSONObject saveImage(String imageBase64, String cameraName) {
         String uploadPath = "uploadImages";
         //
         String os = System.getProperty("os.name");
         String userDir = System.getProperty("user.dir");
+        String createPath = "";
         if (os.toLowerCase().indexOf("windows") != -1) {
             // Windows
-            uploadPath = "\\" + uploadPath + "\\"+name+"\\";
+            uploadPath = "\\" + uploadPath + "\\"+cameraName+"\\";
+            createPath = userDir + uploadPath;
         } else {
             // Linux
-            uploadPath = "/" + uploadPath + "/"+name+"/";
+            uploadPath = "/" + uploadPath + "/"+cameraName+"/";
+            createPath = userDir + uploadPath;
         }
         // 时间戳
         long timeMillis = System.currentTimeMillis();
         //判断文件目录是否存在
-        File dir = new File(uploadPath);
+        File dir = new File(createPath);
         if (!dir.exists()) { // && dir.isDirectory()
             dir.mkdirs();
             // 目录入库
             ImageCatalogEntity imageCatalogEntity = new ImageCatalogEntity();
-            imageCatalogEntity.setCatalogName(name);
-            imageCatalogEntity.setCatalogPath(name);
+            imageCatalogEntity.setCatalogName(cameraName);
+            imageCatalogEntity.setCatalogPath(cameraName);
             imageCatalogRepo.saveAndFlush(imageCatalogEntity);
         }
         // type1
@@ -84,7 +87,7 @@ public class ImageServiceImpl implements IImageService {
 //        String imgPath = imgBuild.append(uploadPath).append(name).append("_").append(timeMillis).append(".jpg").toString();
         // type 3
         StringBuilder fileNameBuild = new StringBuilder();
-        String fileName = fileNameBuild.append(name).append("_").append(timeMillis).append(".jpg").toString();
+        String fileName = fileNameBuild.append(cameraName).append("_").append(timeMillis).append(".jpg").toString();
         String relativePath = uploadPath + fileName;
         String imgPath = userDir + relativePath;
         JSONObject resultJo = new JSONObject();

+ 44 - 0
huimv-video/huimv-video-process/src/test/java/com/huimv/process/service/UtilsTest.java

@@ -0,0 +1,44 @@
+package com.huimv.process.service;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.security.RunAs;
+import java.io.File;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class UtilsTest {
+
+    @Test
+    public void testCatalog(){
+        String userDir = System.getProperty("user.dir");
+        System.out.println("userDir>>"+userDir);
+
+        String datpTemp = "uploadFiles\\abc";
+        String dirPath = userDir+"\\"+datpTemp;
+        File file = new File(dirPath);
+        if (!file.exists()) {
+            System.out.println("目录不存在");
+            file.mkdirs();
+        }else{
+            System.out.println("目录存在");
+        }
+
+//        System.out.println();
+//        File file = new File(dirPath);
+//        if (!file.exists()) {
+//            file.mkdirs();
+//        }
+    }
+}