| 
					
				 | 
			
			
				@@ -1,37 +1,27 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.iden.bms.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.bean.BeanUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import cn.hutool.core.collection.CollUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import cn.hutool.core.util.StrUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.entity.IdenCrowd; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.entity.IdenPerson; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.entity.IdenPersonCrowdRef; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.enums.PersonTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.enums.PopulationTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.face.monitor.FaceMonitor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.face.monitor.model.FaceModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.iden.bms.face.FaceIdenTool; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.iden.common.entity.IdenFaceImage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.iden.common.exception.BDException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.service.IdenCrowdService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.service.IdenPersonCrowdRefService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.service.IdenPersonService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.iden.common.util.DateUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.iden.common.util.ImgUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.util.MyBeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.vo.PageReqVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.iden.common.vo.PersonVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.iden.common.vo.TraceVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.iden.common.vo.UserLogindConvertVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.beans.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.lang3.ArrayUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.File; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.io.FileOutputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.UUID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -44,12 +34,7 @@ import java.util.UUID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class TraceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private IdenPersonService idenPersonService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private IdenPersonCrowdRefService idenPersonCrowdRefService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private IdenCrowdService idenCrowdService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private FaceImageService faceImageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Value("${iden.root:#{null}}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private String idenRoot; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -62,7 +47,7 @@ public class TraceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return  访问URL 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public String uploadImage(MultipartFile file) throws BDException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String logo = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String image = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (file != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //获取文件名 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -75,10 +60,10 @@ public class TraceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     throw new BDException("图像文件必须是图片格式!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 String saveFileName = DateUtils.getCurrYyyyMMddHHmmssDate() + "_" + UUID.randomUUID().toString()  + fileName.substring(fileName.lastIndexOf("."), fileName.length()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                String picFullFileName = idenRoot + "data/final/image/person/" + saveFileName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String picFullFileName = idenRoot + "data/trace/" + saveFileName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 FileOutputStream fos = new FileOutputStream(picFullFileName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 fos.write(file.getBytes()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                logo = fileUrl + "person/" + saveFileName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                image = saveFileName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 throw new BDException("上传失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -86,18 +71,63 @@ public class TraceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new BDException("上传失败",e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return logo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return image; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 查询轨迹列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 图像识别,使用特征码查询图像库,得到图库表中对应的数据列表,同时缓存到表里 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     *  上传图像查询轨迹列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 图像识别,使用特征码查询图像库,得到图库表中对应的数据列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public List<TraceVO> listTrace(String imageCodes, String beginTime, String endTime, UserLogindConvertVO loginUser) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<TraceVO> listUploadImagesTrace(String images, String beginTime, String endTime, UserLogindConvertVO loginUser) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(images.endsWith(",")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            images = images.substring(0, images.length() - 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String[] imageArr = images.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        File[] imgFiles = new File[imageArr.length]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < imageArr.length; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isNotEmpty(imageArr[i])){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                imgFiles[i] = new File(idenRoot + "data/trace/" + imageArr[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //上传的图像的特征码结构体数组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FaceModel[] faceModels = FaceIdenTool.extractFeature(idenRoot,imgFiles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //初始化引擎,加载摄像头上传的图像人脸特征库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        File cameraImageDirFile = new File(idenRoot + "data/final/camera/image"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        File[] cameraImageFiles = getCameraImageFiles(cameraImageDirFile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FaceMonitor faceMonitorCamera = FaceIdenTool.initFaceMonitor(idenRoot,cameraImageFiles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<TraceVO> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for(FaceModel faceModel : faceModels) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+           int hitIndex = FaceIdenTool.getHitIndex(faceMonitorCamera,faceModel); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+           if (hitIndex != -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               IdenFaceImage idenFaceImage = faceImageService.getIdenFaceImageByImageFileName(cameraImageFiles[hitIndex].getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               if(idenFaceImage != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   TraceVO vo = new TraceVO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   BeanUtil.copyProperties(idenFaceImage,vo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                   result.add(vo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+           } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private File[] getCameraImageFiles(File cameraImageDirFile) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        File[] resuit = new File[]{}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        File[] cameraCodeDirFiles = cameraImageDirFile.listFiles(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cameraCodeDirFiles != null && cameraCodeDirFiles.length > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (File cameraCodeDirFile : cameraCodeDirFiles) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                File[] cameraImageFiles = cameraCodeDirFile.listFiles(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (cameraImageFiles != null && cameraImageFiles.length > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    resuit =  ArrayUtils.addAll(resuit,cameraImageFiles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return resuit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |