Преглед изворни кода

人脸核身图片保存 签发时间的区间

tongfeng пре 2 година
родитељ
комит
6c9d24f470

+ 6 - 1
eladmin-system/src/main/java/me/zhengjie/application/admin/controller/vo/NotaryOrderQueryReq.java

@@ -88,5 +88,10 @@ public class NotaryOrderQueryReq extends BaseRequest {
 	private String notaryUserName;
 	//当事人
 	private String name;
-	
+
+	//签发开始时间
+	private String issuedStartDate;
+	//签发结束时间
+	private String issuedEndDate;
+
 }

+ 4 - 0
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/AdminOrderServiceImpl.java

@@ -161,9 +161,13 @@ public class AdminOrderServiceImpl implements AdminOrderService {
         JSONObject json = new JSONObject();
         json.put("startDate", req.getStartDate());
         json.put("endDate", req.getEndDate());
+        json.put("issuedStartDate",req.getIssuedStartDate());
+        json.put("issuedEndDate",req.getIssuedEndDate());
         // 清楚
         order.setStartDate("");
         order.setEndDate("");
+        order.setIssuedStartDate("");
+        order.setIssuedEndDate("");
         QueryWrapper<ContractOrderEntity> qw = QueryWrapperUtil.convertQuery(order, json);
         SysUserEntity user = userDao.selectById(contextUtil.getCurrentUserId());
         String maxRole = userDomain.getUserMaxRole();

+ 11 - 2
eladmin-system/src/main/java/me/zhengjie/base/file/AbstractFileHandle.java

@@ -11,18 +11,27 @@ import me.zhengjie.base.util.FileUploadUtil;
 public abstract class AbstractFileHandle implements FileHandle, ApplicationContextAware {
 
 	//图片预览
-	@Value("${app.minio.preview}")
+	@Value("${app.minio.preview:https://fqgz.flowbb.cn}")
 	protected String appMinioPreview;
 
+	private static final String APPMINIOPREVIEW = "https://fqgz.flowbb.cn";
+
 	ApplicationContext applicationContext;
 
 	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
 		this.applicationContext = applicationContext;
 		// 设置应用
-		FileHandle fileHandle = applicationContext.getBean(FileHandle.class);
+		FileHandle fileHandle=null;
+		if (APPMINIOPREVIEW.equals(appMinioPreview)){
+			fileHandle = applicationContext.getBean(FaceMinioFileHandle.class);
+		}else {
+			fileHandle = applicationContext.getBean(MinioFileHandle.class);
+		}
+
 		FileUploadUtil.setFileHandle(fileHandle);
 	}
 	/**
+	/**
 	 * 对图片预览的统一处理
 	 * @param keyName
 	 * @return

+ 174 - 0
eladmin-system/src/main/java/me/zhengjie/base/file/FaceMinioFileHandle.java

@@ -0,0 +1,174 @@
+package me.zhengjie.base.file;
+
+import cn.hutool.core.io.IoUtil;
+import io.minio.MinioClient;
+import io.minio.ObjectStat;
+import io.minio.PutObjectOptions;
+import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.base.config.AppConfigInfo;
+import me.zhengjie.dao.mybatis.entity.FileInfoEntity;
+import me.zhengjie.dao.mybatis.mapper.FileInfoMapper;
+import org.apache.commons.io.FileUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.io.*;
+
+@Slf4j
+@Primary
+@Component
+public class FaceMinioFileHandle extends AbstractFileHandle {
+	// minio的连接bucketName
+	@Value("mytest")
+	private String bucketName;
+	// 设置连接minio的url
+	@Value("http://124.222.192.60:9000")
+	public String appMinioUrl;
+	// minio的连接accesskey
+	@Value("minioadmin")
+	public String appMinioAccesskey;
+	// minio的连接secretkey
+	@Value("minioadmin")
+	public String appMinioSecretkey;
+
+	@Autowired
+	public FileInfoMapper fileInfoMapper;
+
+	private MinioClient minioClient;
+
+	@PostConstruct
+	private void init() throws Exception {
+		try {
+			if (minioClient == null) {
+				log.info("minioClient create start");
+				minioClient = new MinioClient(appMinioUrl, appMinioAccesskey, appMinioSecretkey);
+				log.info("minioClient create end");
+				// 判断桶是否已经存在
+				log.info("开始创建minio的:");
+				createBucket();
+			}
+		} catch (Exception e) {
+			log.error("连接MinIO服务器异常:{}", e);
+			throw e;
+		}
+	}
+
+	/**
+	 * @Title: createBucket
+	 * @Description: (创建bucket)
+	 * @author humuyu [bucketName] 桶名
+	 */
+	public void createBucket() {
+		try {
+			if (!minioClient.bucketExists(bucketName)) {
+				minioClient.makeBucket(bucketName);
+			}
+		} catch (Exception e) {
+			log.error("创建桶失败:{}", e);
+		}
+	}
+
+	/**
+	 * 通过流上传文件
+	 *
+	 * @param bucketName  存储桶
+	 * @param objectName  文件对象
+	 * @param inputStream 文件流
+	 */
+	public void uploadFileStream(FileHandleVo file) throws Exception {
+		int fileSize = file.getInputStream().available();
+		PutObjectOptions options = new PutObjectOptions(fileSize, -1);
+		options.setContentType(file.getContentType());
+		minioClient.putObject(bucketName, file.getFilePath(), file.getInputStream(), options);
+	}
+
+	public void uploadfilePath(FileHandleVo file) throws Exception {
+		InputStream is = new FileInputStream(file.getFilePath());
+		long size = is.available();
+		PutObjectOptions options = new PutObjectOptions(size, -1);
+		options.setContentType(file.getContentType());
+		minioClient.putObject(bucketName, file.getSourceFilePath(), is, options);
+		if (is != null) {
+			is.close();
+		}
+//
+	}
+
+	public InputStream getObject(String objectName) throws Exception {
+		return minioClient.getObject(bucketName, objectName);
+	}
+
+	/**
+	 * @param bucketName bucket名称
+	 * @param objectName ⽂件名称
+	 * @param expires    过期时间 <=7
+	 * @return url
+	 * @Title: getObjectURL
+	 * @Description: (获取 ⽂ 件外链) [bucketName 桶名, objectName 文件名, expires 时间<=1小时]
+	 */
+	public String getObjectUrl(String keyName) throws Exception {
+		return minioClient.presignedGetObject(bucketName, keyName, 3600);
+	}
+
+	/**
+	 * 自定义url
+	 * 
+	 * @param fileKey 文件的
+	 * @return
+	 */
+	public String getCustomUrl(String fileKey, String filePath) {
+		try {
+			// return fileHandle.getPreviewUrl(fileKey);
+			InputStream input = minioClient.getObject(bucketName, fileKey);
+			byte[] b = IoUtil.readBytes(input);
+			String uploadPath = AppConfigInfo.APP_UPLOAD_PATH;
+			if (!uploadPath.endsWith("/")) {
+				uploadPath = uploadPath + "/";
+			}
+			String transferFilePath = uploadPath + filePath;
+			FileUtils.writeByteArrayToFile(new File(transferFilePath), b);
+			return appMinioPreview +"/image/"+ filePath;
+		} catch (Exception e) {
+			log.error("图片预览失败:" + e.getLocalizedMessage());
+			return null;
+		}
+	}
+
+	/**
+	 * 根据文件路径从minio获取文件
+	 * @param filePath
+	 * @return
+	 * @throws Exception
+	 */
+	public File getFileWithPath(String filePath) throws Exception {
+		InputStream inputStream = minioClient.getObject(bucketName, filePath);
+		File file = File.createTempFile("compare",".jpeg");
+		file.deleteOnExit();
+		OutputStream outputStream = new FileOutputStream(file);
+		int bytesRead = 0;
+		byte[] buffer = new byte[8192];
+		while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
+			outputStream.write(buffer, 0, bytesRead);
+		}
+		inputStream.close();
+		outputStream.close();
+		return file;
+	}
+
+	public byte[] getByte(String fileId) throws Exception {
+		FileInfoEntity fileInfo = fileInfoMapper.selectById(fileId);
+		String path = fileInfo.getPath();
+		InputStream inputStream = this.getObject(path);
+		// 这里已经关闭流,不需要手动关闭
+		return IoUtil.readBytes(inputStream);
+	}
+
+	public long getSize(String keyName) throws Exception {
+		ObjectStat stat = minioClient.statObject(bucketName, keyName);
+		long length = stat.length();
+		return length;
+	}
+}

+ 0 - 2
eladmin-system/src/main/java/me/zhengjie/base/plus/QueryWrapperUtil.java

@@ -145,7 +145,6 @@ public class QueryWrapperUtil {
 //							Field startRange = clazz.getDeclaredField(attribute[0]);
 //							startRange.setAccessible(true);
 //							Object val = startRange.get(obj);
-
 							// 结束的属性值,通过反射设置属性值
 							String endRange = attribute[1];
 							getMethod = getMethod(endRange);
@@ -164,7 +163,6 @@ public class QueryWrapperUtil {
 							if (!ObjectUtils.isEmpty(val)) {
 								queryWrapper.ge(fieldName, val);
 							}
-
 							// 然后通过参数查询
 							val = param.get(attribute[1]);
 							if (!ObjectUtils.isEmpty(val)) {

+ 8 - 0
eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/ContractOrderEntity.java

@@ -168,6 +168,7 @@ public class ContractOrderEntity implements Serializable {
 
     @TableField("creator")
     private String creator;
+
     @QueryWapper(value = {QueryKeyword.RANGE,QueryKeyword.DESC}, attribute = { "startDate", "endDate" })
     @TableField(value="create_time", fill = FieldFill.INSERT)
     private Date createTime;
@@ -184,6 +185,13 @@ public class ContractOrderEntity implements Serializable {
     @TableField("contract_term")
     private String contractTerm;
 
+    @TableField("issued_start_date")
+    private String issuedStartDate;
+
+    @TableField("issued_end_date")
+    private String issuedEndDate;
+
+    @QueryWapper(value = {QueryKeyword.RANGE,QueryKeyword.DESC},attribute = {"issuedStartDate","issuedEndDate"})
     @TableField(value = "issued_time", fill = FieldFill.UPDATE)
     private Date issuedTime;
 

+ 9 - 31
eladmin-system/src/main/java/me/zhengjie/domain/notary/impl/NotaryDomainImpl.java

@@ -8,6 +8,7 @@ import com.arcsoft.face.toolkit.ImageInfo;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.RequiredArgsConstructor;
 import me.zhengjie.base.ResultCode;
+import me.zhengjie.base.file.FaceMinioFileHandle;
 import me.zhengjie.base.file.FileHandleVo;
 import me.zhengjie.base.file.MinioFileHandle;
 import me.zhengjie.base.util.JuheServiceUtil;
@@ -18,22 +19,16 @@ import me.zhengjie.dao.mybatis.entity.UserAXQInfoEntity;
 import me.zhengjie.dao.mybatis.mapper.FileInfoMapper;
 import me.zhengjie.dao.mybatis.mapper.SysUserMapper;
 import me.zhengjie.dao.mybatis.mapper.UserAXQInfoMapper;
-import me.zhengjie.domain.Jvhe.JuheDomain;
-import me.zhengjie.domain.Jvhe.ResultDomain;
 import me.zhengjie.domain.img.CompareImageDomain;
 import me.zhengjie.domain.notary.NotaryDomain;
-import me.zhengjie.sign.converter.JsonObjectMapper;
 import me.zhengjie.utils.RedisUtils;
 import org.springframework.stereotype.Component;
 import org.springframework.util.ObjectUtils;
 
 import java.io.File;
 import java.io.IOException;
-import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
@@ -44,7 +39,7 @@ public class NotaryDomainImpl implements NotaryDomain {
 
     private final SysUserMapper userMapper;
     private final UserAXQInfoMapper userAXQInfoMapper;
-    private final MinioFileHandle minioFileHandle;
+    private final FaceMinioFileHandle minioFileHandle;
     private final FileInfoMapper fileInfoMapper;
     private final RedisUtils redis;
     private static final String APPID = "6F5JVsCCeSEbBSLSXWVwPki71yK5Y4Jf7oUjA4Y3mLtu";
@@ -157,25 +152,10 @@ public class NotaryDomainImpl implements NotaryDomain {
         if (!ObjectUtils.isEmpty(userAXQInfoEntity)) {
             id = userAXQInfoEntity.getCompareImgId();
         }
-        Integer fileId = compareImage(base, id,redisCount,count);
-        if (fileId == null) {
+        if (! compareImage(base, id,redisCount,count)) {
             System.err.println("人脸比对失败");
             return ResultCode.LIVE_VIDEO_INVALID;
         }
-        if (!ObjectUtils.isEmpty(sysUserEntity)) {
-            SysUserEntity user = new SysUserEntity();
-            user.setUserId(sysUserEntity.getUserId());
-            user.setCompareImgId(fileId);
-            userMapper.updateById(user);
-            System.err.println("客户经理认证成功");
-        }
-        if (!ObjectUtils.isEmpty(userAXQInfoEntity)) {
-            UserAXQInfoEntity user = new UserAXQInfoEntity();
-            user.setId(userAXQInfoEntity.getId());
-            user.setCompareImgId(fileId);
-            userAXQInfoMapper.updateById(user);
-            System.err.println("当事人认证成功");
-        }
         if (count != null) {
             redis.del(redisCount);
         }
@@ -190,7 +170,7 @@ public class NotaryDomainImpl implements NotaryDomain {
      * @param count redis当中的次数
      * @return
      */
-    public Integer compareImage(File base, Integer id,String redisCount,Integer count) {
+    public boolean compareImage(File base, Integer id,String redisCount,Integer count) {
         //从官网获取
         FaceEngine faceEngine = new FaceEngine(LIBPATH);
         //激活引擎
@@ -243,7 +223,7 @@ public class NotaryDomainImpl implements NotaryDomain {
         if (pitch > 10 || yaw > 10) {
             //照片不符合标准
             System.err.println("图片不符合标准");
-            return null;
+            return false;
         }
         //特征提取
         FaceFeature faceFeature = new FaceFeature();
@@ -277,9 +257,7 @@ public class NotaryDomainImpl implements NotaryDomain {
         if (faceSimilar.getScore() > 0.8) {
             FileInfoEntity fileInfo = saveCompareImage(base);
             fileInfoMapper.insert(fileInfo);
-            return fileInfo.getId();
-        }else {
-            System.out.println("特征值不符合");
+            return true;
         }
         if (count == null) {
             redis.set(redisCount, 1, 30, TimeUnit.MINUTES);
@@ -287,13 +265,13 @@ public class NotaryDomainImpl implements NotaryDomain {
             redis.set(redisCount, count + 1, 30, TimeUnit.MINUTES);
         }
         System.err.println("人脸照片比对未通过");
-        return null;
+        return false;
     }
 
     private FileInfoEntity saveCompareImage(File base) {
         FileHandleVo fileHandleVo = new FileHandleVo();
         fileHandleVo.setFilePath(base.getPath());
-        fileHandleVo.setSourceFilePath("/compareImage/" + base.getName());
+        fileHandleVo.setSourceFilePath("/face/" + base.getName());
         fileHandleVo.setContentType("JPEG");
         try {
             minioFileHandle.uploadfilePath(fileHandleVo);
@@ -301,7 +279,7 @@ public class NotaryDomainImpl implements NotaryDomain {
             throw new RuntimeException("照片保存到minio异常");
         }
         FileInfoEntity fileInfo = new FileInfoEntity();
-        fileInfo.setLoanNo("compareImage");
+        fileInfo.setLoanNo("face");
         fileInfo.setFileName(base.getName());
         fileInfo.setPath(fileInfo.getLoanNo() + "/" + base.getName());
         return fileInfo;