Explorar el Código

虹软人脸算法

qzy hace 1 mes
padre
commit
d929f4561a
Se han modificado 21 ficheros con 561 adiciones y 414 borrados
  1. 0 7
      sp-core/sp-base/src/main/java/com/pj/current/config/SystemObject.java
  2. 0 65
      sp-core/sp-base/src/main/java/com/pj/face/config/FaceEngineConfig.java
  3. 0 136
      sp-core/sp-base/src/main/java/com/pj/face/handler/impl/ArcsoftFaceHandlerImpl.java
  4. 127 117
      sp-core/sp-base/src/main/java/com/pj/project4sp/apilog/SpApilogUtil.java
  5. 1 1
      sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderMapper.xml
  6. 12 0
      sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderService.java
  7. 4 0
      sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrders.java
  8. 3 2
      sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersService.java
  9. 18 28
      sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserApiController.java
  10. 15 18
      sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserService.java
  11. 2 2
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/brand/FaceBrand.java
  12. 60 0
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/factory/FaceEngineFactory.java
  13. 2 5
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/factory/FaceFactory.java
  14. 7 5
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/IFaceHandler.java
  15. 1 1
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/VerifyVO.java
  16. 223 0
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/impl/ArcsoftFaceHandlerImpl.java
  17. 24 9
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/impl/TencenFaceHandlerImpl.java
  18. 1 1
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/impl/TencenRespBO.java
  19. 1 1
      sp-service/sp-admin/src/main/java/com/pj/project4sp/face/properties/TencenProperties.java
  20. 2 9
      sp-service/sp-admin/src/main/java/com/pj/project4sp/startup/StartUpInit.java
  21. 58 7
      sp-service/sp-admin/src/main/java/com/pj/project4sp/utils/ImageUtils.java

+ 0 - 7
sp-core/sp-base/src/main/java/com/pj/current/config/SystemObject.java

@@ -1,7 +1,6 @@
 package com.pj.current.config;
 
 import com.pj.common.core.utils.DateUtils;
-import com.pj.face.factory.FaceFactory;
 import com.pj.sms.factory.SmsFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -59,12 +58,6 @@ public class SystemObject {
     }
 
 
-    public static FaceFactory factory;
-
-    @Autowired
-    void setConfig(FaceFactory factory) {
-        SystemObject.factory = factory;
-    }
 
     // ===================================== 生成订单号工具类 ===================================================
 

+ 0 - 65
sp-core/sp-base/src/main/java/com/pj/face/config/FaceEngineConfig.java

@@ -1,65 +0,0 @@
-package com.pj.face.config;
-
-import cn.hutool.core.io.FileUtil;
-import cn.hutool.log.StaticLog;
-import com.arcsoft.face.ActiveFileInfo;
-import com.arcsoft.face.EngineConfiguration;
-import com.arcsoft.face.FaceEngine;
-import com.arcsoft.face.FunctionConfiguration;
-import com.arcsoft.face.enums.DetectMode;
-import com.arcsoft.face.enums.DetectOrient;
-import com.arcsoft.face.enums.ErrorInfo;
-import com.pj.current.config.SystemObject;
-import lombok.extern.slf4j.Slf4j;
-
-import java.io.File;
-
-@Slf4j
-public class FaceEngineConfig {
-
-    public static FaceEngine faceEngine = null;
-
-    public static void initFaceEngine() {
-        String sdk = SystemObject.config.getFaceLibs();
-        log.info("exit:{}", FileUtil.exist(sdk + File.separator + "libarcsoft_face.dll"));
-        faceEngine = new FaceEngine(sdk);
-        //激活引擎
-        int errorCode = faceEngine.activeOnline(SystemObject.config.getArcsoftAppid(), SystemObject.config.getArcsoftSdkKey());
-        log.info("activate:{}", errorCode);
-        StaticLog.info("activate:{}", errorCode);
-
-        if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
-            StaticLog.error("引擎激活失败");
-        }
-
-
-        ActiveFileInfo activeFileInfo = new ActiveFileInfo();
-        errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
-        if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
-            StaticLog.error("获取激活文件信息失败");
-        }
-
-        //引擎配置
-        EngineConfiguration engineConfiguration = new EngineConfiguration();
-        engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);
-        engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);
-        engineConfiguration.setDetectFaceMaxNum(10);
-        engineConfiguration.setDetectFaceScaleVal(16);
-        //功能配置
-        FunctionConfiguration functionConfiguration = new FunctionConfiguration();
-        functionConfiguration.setSupportFaceDetect(true);
-        functionConfiguration.setSupportFaceRecognition(true);
-        functionConfiguration.setSupportLiveness(true);
-        engineConfiguration.setFunctionConfiguration(functionConfiguration);
-
-
-        //初始化引擎
-        errorCode = faceEngine.init(engineConfiguration);
-
-        if (errorCode != ErrorInfo.MOK.getValue()) {
-            StaticLog.error("初始化引擎失败");
-        }
-
-
-    }
-}

+ 0 - 136
sp-core/sp-base/src/main/java/com/pj/face/handler/impl/ArcsoftFaceHandlerImpl.java

@@ -1,136 +0,0 @@
-package com.pj.face.handler.impl;
-
-import cn.hutool.core.io.FileUtil;
-import com.arcsoft.face.FaceFeature;
-import com.arcsoft.face.FaceInfo;
-import com.arcsoft.face.FaceSimilar;
-import com.arcsoft.face.LivenessInfo;
-import com.arcsoft.face.toolkit.ImageInfo;
-import com.pj.current.config.SystemObject;
-import com.pj.face.brand.FaceBrand;
-import com.pj.face.config.FaceEngineConfig;
-import com.pj.face.handler.IFaceHandler;
-import com.pj.face.handler.VerifyVO;
-import com.pj.utils.sg.AjaxError;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.List;
-
-import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
-
-/**
- * 基于ArcSoft Face的人��识别
- */
-@Service
-@Slf4j
-public class ArcsoftFaceHandlerImpl implements IFaceHandler {
-    @Override
-    public boolean checkIsLive(String baseImg) {
-        List<LivenessInfo> livenessInfoList = new ArrayList<>();
-        FaceEngineConfig.faceEngine.getLiveness(livenessInfoList);
-        return livenessInfoList.get(0).getLiveness() == 1;
-    }
-
-    @Override
-    public void createPersonByBase(String faceId, String name, String imageBase) {
-        byte[] imageBytes = Base64.getDecoder().decode(imageBase);
-        String facePath = SystemObject.getFaceImgPath();
-        File outputFile = new File(facePath + File.separator + faceId + ".png");
-        FileUtil.del(outputFile);
-        // 创建输出流
-        try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
-            // 写入数据到文件
-            fileOutputStream.write(imageBytes);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-    @Override
-    public void deletePerson(String faceId) {
-        String facePath = SystemObject.getFaceImgPath();
-        File outputFile = new File(facePath + File.separator + faceId + ".png");
-        FileUtil.del(outputFile);
-    }
-
-    @Override
-    public boolean checkHasPerson(String img) {
-        byte[] imageBytes = Base64.getDecoder().decode(img);
-        ImageInfo imageInfo = getRGBData(imageBytes);
-        List<FaceInfo> faceInfoList = new ArrayList<>();
-        FaceEngineConfig.faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
-        return faceInfoList.size() == 1;
-    }
-
-    @Override
-    public VerifyVO verify(String faceId, String baseImage) {
-        VerifyVO vo = new VerifyVO();
-        String facePath = SystemObject.getFaceImgPath();
-        File file = new File(facePath + File.separator + faceId + ".png");
-        if (!file.exists()){
-            vo.setMsg("人员ID不存在");
-            return vo;
-        }
-        ImageInfo imageInfo2 = getRGBData(file);
-        byte[] imageBytes = Base64.getDecoder().decode(baseImage);
-        ImageInfo imageInfo = getRGBData(imageBytes);
-        List<FaceInfo> faceInfoList = new ArrayList<>();
-        FaceEngineConfig.faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
-        if (faceInfoList.size() == 0) {
-            vo.setMsg("No faces");
-            return vo;
-            //throw new AjaxError("请正视摄像头");
-        }
-        if (faceInfoList.size() > 1) {
-            vo.setMsg("图片中存在多个人脸");
-            return vo;
-            //throw new AjaxError("图片中存在多个人脸");
-        }
-        FaceInfo faceInfo = faceInfoList.get(0);
-        FaceFeature faceFeature = new FaceFeature();
-        FaceEngineConfig.faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfo, faceFeature);
-        System.out.println("特征值大小:" + faceFeature.getFeatureData().length);
-
-
-        //人脸检测2
-
-        List<FaceInfo> faceInfoList2 = new ArrayList<FaceInfo>();
-        FaceEngineConfig.faceEngine.detectFaces(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), imageInfo2.getImageFormat(), faceInfoList2);
-        System.out.println(faceInfoList2);
-
-        //特征提取2
-        FaceFeature faceFeature2 = new FaceFeature();
-        FaceEngineConfig.faceEngine.extractFaceFeature(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), imageInfo2.getImageFormat(), faceInfoList2.get(0), faceFeature2);
-        System.out.println("特征值大小:" + faceFeature2.getFeatureData().length);
-
-        FaceFeature targetFaceFeature = new FaceFeature();
-        targetFaceFeature.setFeatureData(faceFeature.getFeatureData());
-        FaceFeature sourceFaceFeature = new FaceFeature();
-        sourceFaceFeature.setFeatureData(faceFeature2.getFeatureData());
-        FaceSimilar faceSimilar = new FaceSimilar();
-        FaceEngineConfig.faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
-        System.out.println("相似度:" + faceSimilar.getScore());
-        boolean result = faceSimilar.getScore() > 0.75f;
-        String msg = result ? "人脸一致" : "不匹配";
-        vo.setSuccess(result);
-        vo.setMsg(msg);
-        return vo;
-    }
-
-    @Override
-    public List<String> faceSearch(String baseImg) {
-        return null;
-    }
-
-    @Override
-    public FaceBrand faceBrand() {
-        return FaceBrand.ARCSOFT;
-    }
-}

+ 127 - 117
sp-core/sp-base/src/main/java/com/pj/project4sp/apilog/SpApilogUtil.java

@@ -1,9 +1,11 @@
 package com.pj.project4sp.apilog;
 
 import java.util.Date;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
+import cn.hutool.core.util.StrUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -22,127 +24,135 @@ import cn.hutool.core.util.IdUtil;
 
 /**
  * 工具类:api请求记录表
- * @author kong 
  *
+ * @author kong
  */
 @Component
 public class SpApilogUtil {
 
-	/** 底层 Mapper 对象 */
-	static SpApilogMapper spApilogMapper;
-	@Autowired
-	public void setSpApilogMapper(SpApilogMapper spApilogMapper) {
-		SpApilogUtil.spApilogMapper = spApilogMapper;
-	}
-	
-	static final String APILOG_OBJ_SAVE_KEY = "APILOG_OBJ_SAVE_KEY";
-	static final String APILOG_OBJ_SAVE_ID_KEY = "APILOG_OBJ_SAVE_ID_KEY";
-	
-	/**
-	 * 请求开始时调用,开始计时 
-	 */
-	public static void startRequest() {
-		if(isWeb() == false)  {
-			return;
-		}
-		
-		// 1、开始时 
-    	HttpServletRequest request = SpringMVCUtil.getRequest();
-    	SpApilog a = new SpApilog();
-    	a.setId(getSnowflakeId());		
-    	a.setReqIp(WebNbUtil.getIP(request));	
-    	a.setReqApi(request.getRequestURI());;		
-    	a.setReqParame(JSON.toJSONString(WebNbUtil.getParamsMap2(request)));	
-    	a.setReqToken(StpUtil.getTokenValue());			
-    	a.setReqHeader(JSON.toJSONString(WebNbUtil.getHeaderMap(request)));		
-    	a.setReqType(request.getMethod());		
-    	a.setAdminId(StpUtil.getLoginId(0L));	
-    	a.setUserId(StpUserUtil.getLoginId(0L));		
-    	a.setStartTime(new Date());			
-    	request.setAttribute(APILOG_OBJ_SAVE_KEY, a);
-    	
-    	// 控制台日志 
-    	LogUtil.info("----------------------------------------------------------------");
-		LogUtil.info("IP: " + a.getReqIp() + "\tr-> " + a.getReqApi()+ "\tp-> " + a.getReqParame());
-	}
-	
-
-	/**
-	 * 请求结束时调用,结束计时 
-	 * @param aj
-	 */
-	public static void endRequest(AjaxJson aj) {
-		if(isWeb() == false)  {
-			return;
-		}
-		
-		// 读取本次请求的 ApiLog 对象 
-		HttpServletRequest request = SpringMVCUtil.getRequest();
-		SpApilog a = (SpApilog)request.getAttribute(APILOG_OBJ_SAVE_KEY);
-		if(a == null) {
+    /**
+     * 底层 Mapper 对象
+     */
+    static SpApilogMapper spApilogMapper;
+
+    @Autowired
+    public void setSpApilogMapper(SpApilogMapper spApilogMapper) {
+        SpApilogUtil.spApilogMapper = spApilogMapper;
+    }
+
+    static final String APILOG_OBJ_SAVE_KEY = "APILOG_OBJ_SAVE_KEY";
+    static final String APILOG_OBJ_SAVE_ID_KEY = "APILOG_OBJ_SAVE_ID_KEY";
+
+    /**
+     * 请求开始时调用,开始计时
+     */
+    public static void startRequest() {
+        if (isWeb() == false) {
+            return;
+        }
+
+        // 1、开始时
+        HttpServletRequest request = SpringMVCUtil.getRequest();
+        SpApilog a = new SpApilog();
+        a.setId(getSnowflakeId());
+        a.setReqIp(WebNbUtil.getIP(request));
+        a.setReqApi(request.getRequestURI());
+        Map<String, Object> params = WebNbUtil.getParamsMap2(request);
+        if (StrUtil.contains(request.getRequestURI(), "faceImg")) {
+            params.remove("img");
+        }
+        a.setReqParame(JSON.toJSONString(params));
+        a.setReqToken(StpUtil.getTokenValue());
+        a.setReqHeader(JSON.toJSONString(WebNbUtil.getHeaderMap(request)));
+        a.setReqType(request.getMethod());
+        a.setAdminId(StpUtil.getLoginId(0L));
+        a.setUserId(StpUserUtil.getLoginId(0L));
+        a.setStartTime(new Date());
+        request.setAttribute(APILOG_OBJ_SAVE_KEY, a);
+
+        // 控制台日志
+        LogUtil.info("----------------------------------------------------------------");
+        LogUtil.info("IP: " + a.getReqIp() + "\tr-> " + a.getReqApi() + "\tp-> " + a.getReqParame());
+    }
+
+
+    /**
+     * 请求结束时调用,结束计时
+     *
+     * @param aj
+     */
+    public static void endRequest(AjaxJson aj) {
+        if (isWeb() == false) {
+            return;
+        }
+
+        // 读取本次请求的 ApiLog 对象
+        HttpServletRequest request = SpringMVCUtil.getRequest();
+        SpApilog a = (SpApilog) request.getAttribute(APILOG_OBJ_SAVE_KEY);
+        if (a == null) {
 //	    	LogUtil.info("未找到相应ApiLog对象(可能原因:全局异常),aj=" + aj);
-	    	SpApilogUtil.startRequest();	
-	    	a = (SpApilog)request.getAttribute(APILOG_OBJ_SAVE_KEY);
-		}
-
-		// 保存数据库
-		try {
-			// 开始结束计时 
-			a.setResCode(aj.getCode()); 	
-			a.setResMsg(aj.getMsg());	
-			a.setResString(new ObjectMapper().writeValueAsString(aj));		
-			a.setEndTime(new Date());		
-			a.setCostTime((int)(a.getEndTime().getTime() - a.getStartTime().getTime()));
-			
-			// res 字符串过长时禁止写入  
-			if(a.getResString().length() > 50000) {
-				a.setResString("{\"msg\": \"数据过长,无法写入 (length=" + a.getResString().length() + ")\"}");		
-			}
-		
-        	LogUtil.info("本次请求耗时:" + ((a.getCostTime() + 0.0) / 1000) + "s, 返回:" + a.getResString());
-			a.setCreateTime(new Date());
-        	spApilogMapper.saveObj(a);
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-	}
-	
-	
-	
-	
-
-	/**
-	 * 当前是否为web环境 
-	 */
-	public static boolean isWeb() {
-		// 大善人SpringMVC提供的封装 
-		ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-		if(servletRequestAttributes != null) {
-			return true;
-		}
-		return false;
-	}
-
-
-	/** 获取当前请求的id */
-	public static String getCurrReqId() {
-		HttpServletRequest request = SpringMVCUtil.getRequest();
-		String id = (String)request.getAttribute(APILOG_OBJ_SAVE_ID_KEY);
-		if(id == null) {
-			id = IdUtil.simpleUUID();
-			request.setAttribute(APILOG_OBJ_SAVE_ID_KEY, id);
-		}
-		return id;
-	}
-
-
-	/**
-	 * 根据雪花算法,返回唯一id 
-	 * (此地方将workerId写死为1,如果你在分布式场景中应用此方法,你需要对workerId生成策略进行改造)
-	 * @return
-	 */
-	public static String getSnowflakeId() {
-		return IdUtil.getSnowflake(1, 1).nextIdStr();
-	}
-	
+            SpApilogUtil.startRequest();
+            a = (SpApilog) request.getAttribute(APILOG_OBJ_SAVE_KEY);
+        }
+
+        // 保存数据库
+        try {
+            // 开始结束计时
+            a.setResCode(aj.getCode());
+            a.setResMsg(aj.getMsg());
+            a.setResString(new ObjectMapper().writeValueAsString(aj));
+            a.setEndTime(new Date());
+            a.setCostTime((int) (a.getEndTime().getTime() - a.getStartTime().getTime()));
+
+            // res 字符串过长时禁止写入
+            if (a.getResString().length() > 50000) {
+                a.setResString("{\"msg\": \"数据过长,无法写入 (length=" + a.getResString().length() + ")\"}");
+            }
+
+            LogUtil.info("本次请求耗时:" + ((a.getCostTime() + 0.0) / 1000) + "s, 返回:" + a.getResString());
+            a.setCreateTime(new Date());
+            spApilogMapper.saveObj(a);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * 当前是否为web环境
+     */
+    public static boolean isWeb() {
+        // 大善人SpringMVC提供的封装
+        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+        if (servletRequestAttributes != null) {
+            return true;
+        }
+        return false;
+    }
+
+
+    /**
+     * 获取当前请求的id
+     */
+    public static String getCurrReqId() {
+        HttpServletRequest request = SpringMVCUtil.getRequest();
+        String id = (String) request.getAttribute(APILOG_OBJ_SAVE_ID_KEY);
+        if (id == null) {
+            id = IdUtil.simpleUUID();
+            request.setAttribute(APILOG_OBJ_SAVE_ID_KEY, id);
+        }
+        return id;
+    }
+
+
+    /**
+     * 根据雪花算法,返回唯一id
+     * (此地方将workerId写死为1,如果你在分布式场景中应用此方法,你需要对workerId生成策略进行改造)
+     *
+     * @return
+     */
+    public static String getSnowflakeId() {
+        return IdUtil.getSnowflake(1, 1).nextIdStr();
+    }
+
 }

+ 1 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderMapper.xml

@@ -71,7 +71,7 @@
 			<if test=' this.has("callCarStatus") '> and call_car_status = #{callCarStatus} </if>
 			<if test=' this.has("createBy") '> and create_by = #{createBy} </if>
 			<if test=' this.has("createName") '> and create_name = #{createName} </if>
-			<if test=' this.has("createTime") '> and create_time = #{createTime} </if>
+			<if test=' this.has("createTime") '> and  date_format(create_time,'%Y-%m-%d')= #{createTime} </if>
 			<if test=' this.has("updateBy") '> and update_by = #{updateBy} </if>
 			<if test=' this.has("updateName") '> and update_name = #{updateName} </if>
 			<if test=' this.has("updateTime") '> and update_time = #{updateTime} </if>

+ 12 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderService.java

@@ -555,6 +555,18 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
         } else if (1 == SXB010Status) {//扣款成功
             tbOrder.setSxb010Status(1)
                     .setSxb010StatusTime(new Date());
+            //如果已经过了卡三,则补发送一次通关报文给银行
+            if(tbOrder.getFinishStatus()==1){
+                HtTradeSettlement htTradeSettlement=htTradeSettlementService.getById(tbOrder.getSaleMainId());
+                //TODO: 2023/8/30 补发通关报文
+                PaymentDto paymentDto2 = new PaymentDto();
+                paymentDto2.setTradeNos(tradeNo);
+                paymentDto2.setVoyageNo(htTradeSettlement.getVoyageNo());
+                paymentDto2.setVeNo(tbOrder.getVeNo());
+                StaticLog.info("\n扣款成功,补发通关批文 sendSXB023——PaymentDto——:{}", JSONUtil.toJsonStr(paymentDto2));
+                paymentServerInterface.sendSXB023(paymentDto2);
+                //todo 补发结关信息
+            }
         }
 
         return super.updateById(tbOrder);

+ 4 - 0
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrders.java

@@ -277,4 +277,8 @@ public class TbOrders extends Model<TbOrders> implements Serializable {
 	 * 第二数量
 	 */
 	private Double buyQty2;
+	/**
+	 * 下单时间
+	 */
+	private Date orderTime;
 }

+ 3 - 2
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersService.java

@@ -196,8 +196,9 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
             }
             orderTwo.setPurchaserId(purchaser.getId());
             orderTwo.setPurchaserName(purchaser.getName());
-            orderTwo.setIsPay(3);//支付中
-            orderTwo.setPayTime(new Date());//支付时间
+            orderTwo.setIsPay(0);//支付中
+
+            orderTwo.setOrderTime(new Date());//支付时间
             boolean b = updateById(orderTwo);
             if (!b) throw new RuntimeException("购买异常,请重新登录或联系管理员!");
 

+ 18 - 28
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserApiController.java

@@ -1,43 +1,28 @@
 package com.pj.project.app_user;
 
-import cn.hutool.core.codec.Base64;
-import cn.hutool.core.thread.ThreadUtil;
-import cn.hutool.core.util.RandomUtil;
-import cn.hutool.core.util.StrUtil;
-import cn.hutool.log.StaticLog;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+
 import com.pj.api.consts.FeignFactory;
 import com.pj.api.dto.AppUserCreateDTO;
 import com.pj.api.dto.AppUserDto;
 import com.pj.api.dto.PeopleDto;
-import com.pj.api.dto.UpdateAccountDTO;
 import com.pj.current.satoken.StpAPPUserUtil;
-import com.pj.face.factory.FaceFactory;
 import com.pj.project.app_user.dto.ForgetPasswordDto;
 import com.pj.project.app_user.dto.LoginDto;
 import com.pj.project.app_user.dto.RegisterDto;
 import com.pj.project.app_user.vo.AppUserVo;
+import com.pj.project4sp.face.factory.FaceFactory;
 import com.pj.project4sp.utils.ImageUtils;
 import com.pj.utils.sg.AjaxJson;
 import com.pj.utils.so.SoMap;
-import com.tencentcloudapi.common.Credential;
-import com.tencentcloudapi.common.exception.TencentCloudSDKException;
-import com.tencentcloudapi.common.profile.ClientProfile;
-import com.tencentcloudapi.common.profile.HttpProfile;
-import com.tencentcloudapi.iai.v20200303.IaiClient;
-import com.tencentcloudapi.iai.v20200303.models.VerifyPersonRequest;
-import com.tencentcloudapi.iai.v20200303.models.VerifyPersonResponse;
+
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.InputStream;
-import java.util.Date;
+import java.io.IOException;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 
@@ -50,8 +35,7 @@ import java.util.Map;
 @RequestMapping("/app/AppUser/")
 @Slf4j
 public class AppUserApiController {
-    @Autowired
-    private FaceFactory faceFactory;
+
     /**
      * 底层 Service 对象
      */
@@ -89,7 +73,7 @@ public class AppUserApiController {
             so.put("groupId", peopleDto.getGroupId());
             so.put("groupName", peopleDto.getGroupName());
             so.put("leaderName", peopleDto.getLeaderName());
-            so.put("leaderPhone",peopleDto.getLeaderPhone());
+            so.put("leaderPhone", peopleDto.getLeaderPhone());
         }
         so.put("auth", user.getAuth());
         so.put("face", user.getFace());
@@ -103,15 +87,20 @@ public class AppUserApiController {
      * 边民首次使用APP人脸认证
      */
     @PostMapping("face")
-    public AjaxJson face(@RequestPart MultipartFile file, Integer type) {
+    public AjaxJson face(@RequestPart MultipartFile file, Integer type) throws Exception {
         appUserService.authFace(StpAPPUserUtil.getAPPLoginInfo().getLoginId(), file, type);
         return AjaxJson.getSuccess();
     }
+    @PostMapping("faceTest")
+    public AjaxJson faceTest(@RequestPart MultipartFile file, Integer type) throws Exception {
+        appUserService.authFace(1L, file, type);
+        return AjaxJson.getSuccess();
+    }
 
     @PostMapping("faceImg")
-    public AjaxJson faceImg(String img, Integer type) {
+    public AjaxJson faceImg(String img, Integer type)  throws IOException {
         if (img == null || img.isEmpty()) return AjaxJson.getError("人脸信息为空!");
-        img = ImageUtils.compressPic(img);
+
         appUserService.authFace(StpAPPUserUtil.getAPPLoginInfo().getLoginId(), img, type);
         return AjaxJson.getSuccess();
     }
@@ -210,13 +199,14 @@ public class AppUserApiController {
         return appUserService.getByPhoneAndUserType(phone, userType);
     }
 
-    /** 注销账户 */
+    /**
+     * 注销账户
+     */
     @RequestMapping("delete")
-    public AjaxJson delete(Long id){
+    public AjaxJson delete(Long id) {
         appUserService.delete(id);
         return AjaxJson.getSuccess();
     }
 
 
-
 }

+ 15 - 18
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserService.java

@@ -24,14 +24,15 @@ import com.pj.current.satoken.StpUserUtil;
 import com.pj.enummj.DeleteStatus;
 import com.pj.enummj.IsLock;
 import com.pj.enummj.UserType;
-import com.pj.face.factory.FaceFactory;
-import com.pj.face.handler.VerifyVO;
+
 import com.pj.project.app_user.dto.*;
 import com.pj.project.app_user.vo.AppUserVo;
 import com.pj.project.app_user_login_log.AppUserLoginLog;
 import com.pj.project.app_user_login_log.AppUserLoginLogService;
 import com.pj.project.re_role_menu.ReRoleMenu;
 import com.pj.project.re_role_menu.ReRoleMenuMapper;
+import com.pj.project4sp.face.factory.FaceFactory;
+import com.pj.project4sp.face.handler.VerifyVO;
 import com.pj.project4sp.utils.ImageUtils;
 import com.pj.utils.Aes;
 import com.pj.utils.cache.RedisUtil;
@@ -647,7 +648,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
     }
 
 
-    public void authFace(Long loginId, MultipartFile file, Integer type) {
+    public void authFace(Long loginId, MultipartFile file, Integer type) throws IOException{
         String img;
         try (InputStream is = file.getInputStream()) {
             img = Base64.encode(is);
@@ -655,16 +656,16 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         } catch (IOException e) {
             throw new AjaxError("识别失败");
         }
-        img = ImageUtils.compressPic(img);
+        byte[]images = ImageUtils.resizeByteImageBase64(img);
         if (type == 2) {
             AppUser db = getById(loginId);
-            VerifyVO result = faceFactory.handler().verify(db.getFaceId(), img);
+            VerifyVO result = faceFactory.handler().verify(db.getFaceId(), images);
             if (!result.isSuccess()) {
                 if (result.getMsg().contains("人员ID不存在")) {
-                    faceFactory.handler().createPersonByBase(db.getFaceId(), db.getName(), img);
+                    faceFactory.handler().createPersonByBase(db.getFaceId(), db.getName(), images);
                     return;
                 }
-                log.info("Verification:{},{}", loginId, img);
+                log.info("Verification:{},{}", loginId);
                 throw new AjaxError("人脸不匹配");
             }
             return;
@@ -674,7 +675,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         appUser.setFace(1);
         appUser.setFaceTime(new Date()).setFaceId(faceId);
         this.updateById(appUser);
-        faceFactory.handler().createPersonByBase(faceId, appUser.getName(), img);
+        faceFactory.handler().createPersonByBase(faceId, appUser.getName(), images);
     }
 
     /**
@@ -688,8 +689,9 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
      * @param img
      * @param type
      */
-    public void authFace(Long loginId, String img, Integer type) {
-        boolean hasPerson = faceFactory.handler().checkHasPerson(img);
+    public void authFace(Long loginId, String img, Integer type)throws IOException {
+        byte[]byteImageBase64 = ImageUtils.resizeByteImageBase64(img);
+        boolean hasPerson = faceFactory.handler().checkHasPerson(byteImageBase64);
         if (!hasPerson){
             throw new AjaxError("请正视摄像头");
         }
@@ -699,15 +701,10 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
             if (StrUtil.isEmpty(faceId)) {
                 throw new AjaxError("人脸未录入");
             }
-            VerifyVO result = faceFactory.handler().verify(faceId, img);
+            VerifyVO result = faceFactory.handler().verify(faceId, byteImageBase64);
             if (!result.isSuccess()) {
                 if (result.getMsg().contains("人员ID不存在")) {
-                    faceFactory.handler().createPersonByBase(faceId, db.getName(), img);
-                    return;
-                }
-                if (result.getMsg().contains("不匹配")) {
-                    faceFactory.handler().deletePerson(faceId);
-                    faceFactory.handler().createPersonByBase(faceId, db.getName(), img);
+                    faceFactory.handler().createPersonByBase(faceId, db.getName(), byteImageBase64);
                     return;
                 }
                 log.info("Verification:{},{}", loginId, img);
@@ -720,7 +717,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         appUser.setFace(1);
         appUser.setFaceTime(new Date()).setFaceId(faceId);
         this.updateById(appUser);
-        faceFactory.handler().createPersonByBase(faceId, appUser.getName(), img);
+        faceFactory.handler().createPersonByBase(faceId, appUser.getName(), byteImageBase64);
     }
 
     public AjaxJson faceLogin(MultipartFile file) {

+ 2 - 2
sp-core/sp-base/src/main/java/com/pj/face/brand/FaceBrand.java → sp-service/sp-admin/src/main/java/com/pj/project4sp/face/brand/FaceBrand.java

@@ -1,4 +1,4 @@
-package com.pj.face.brand;
+package com.pj.project4sp.face.brand;
 
 import lombok.AllArgsConstructor;
 import lombok.Getter;
@@ -21,7 +21,7 @@ public enum FaceBrand {
     /**
      * 虹软
      */
-    ARCSOFT("arcsoft"),
+    ARCSOFT(""),
     ;
 
     private String type;

+ 60 - 0
sp-service/sp-admin/src/main/java/com/pj/project4sp/face/factory/FaceEngineFactory.java

@@ -0,0 +1,60 @@
+package com.pj.project4sp.face.factory;
+
+import com.arcsoft.face.EngineConfiguration;
+import com.arcsoft.face.FaceEngine;
+import com.arcsoft.face.enums.ErrorInfo;
+import com.pj.current.config.SystemObject;
+import com.pj.utils.sg.AjaxError;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.pool2.BasePooledObjectFactory;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
+
+@Slf4j
+public class FaceEngineFactory extends BasePooledObjectFactory<FaceEngine> {
+
+    private String appId;
+    private String sdkKey;
+    private String activeKey;
+    private EngineConfiguration engineConfiguration;
+
+
+    public FaceEngineFactory(String appId, String sdkKey, String activeKey, EngineConfiguration engineConfiguration) {
+        this.appId = appId;
+        this.sdkKey = sdkKey;
+        this.activeKey = activeKey;
+        this.engineConfiguration = engineConfiguration;
+    }
+
+
+    @Override
+    public FaceEngine create() {
+
+
+        FaceEngine faceEngine = new FaceEngine(SystemObject.config.getFaceLibs());
+        int activeCode = faceEngine.activeOnline(appId, sdkKey);
+        if (activeCode != ErrorInfo.MOK.getValue() && activeCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
+            log.error("引擎激活失败" + activeCode);
+            throw new AjaxError( "引擎激活失败" + activeCode);
+        }
+        int initCode = faceEngine.init(engineConfiguration);
+        if (initCode != ErrorInfo.MOK.getValue()) {
+            log.error("引擎初始化失败" + initCode);
+            throw new AjaxError("引擎初始化失败" + initCode);
+        }
+        return faceEngine;
+    }
+
+    @Override
+    public PooledObject<FaceEngine> wrap(FaceEngine faceEngine) {
+        return new DefaultPooledObject<>(faceEngine);
+    }
+
+
+    @Override
+    public void destroyObject(PooledObject<FaceEngine> p) throws Exception {
+        FaceEngine faceEngine = p.getObject();
+        int result = faceEngine.unInit();
+        super.destroyObject(p);
+    }
+}

+ 2 - 5
sp-core/sp-base/src/main/java/com/pj/face/factory/FaceFactory.java → sp-service/sp-admin/src/main/java/com/pj/project4sp/face/factory/FaceFactory.java

@@ -1,14 +1,11 @@
-package com.pj.face.factory;
+package com.pj.project4sp.face.factory;
 
 
-import com.pj.current.config.MyConfig;
 import com.pj.current.config.SystemObject;
-import com.pj.face.handler.IFaceHandler;
-import com.pj.sms.handler.ISmsHandler;
+import com.pj.project4sp.face.handler.IFaceHandler;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.Resource;
 import java.util.List;
 
 @Service

+ 7 - 5
sp-core/sp-base/src/main/java/com/pj/face/handler/IFaceHandler.java → sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/IFaceHandler.java

@@ -1,9 +1,6 @@
-package com.pj.face.handler;
+package com.pj.project4sp.face.handler;
 
-import com.pj.common.core.utils.sign.Base64;
-import com.pj.face.brand.FaceBrand;
-import com.pj.face.handler.impl.TencenRespBO;
-import com.pj.sms.brand.SmsType;
+import com.pj.project4sp.face.brand.FaceBrand;
 
 import java.util.List;
 
@@ -28,10 +25,13 @@ public interface IFaceHandler {
      * @param imageBase 图片base64
      */
     void createPersonByBase(String faceId, String name, String imageBase);
+    void createPersonByBase(String faceId, String name, byte[] imageBase);
 
     void deletePerson(String faceId);
     boolean checkHasPerson(String img);
 
+    boolean checkHasPerson( byte[] imageBase);
+
     /**
      * 检查校验
      * @param faceId 人脸ID
@@ -40,6 +40,8 @@ public interface IFaceHandler {
      */
     VerifyVO verify(String faceId, String baseImage);
 
+    VerifyVO verify(String faceId, byte[] imageBytes);
+
     /**
      * 人脸搜索
      * @param baseImg

+ 1 - 1
sp-core/sp-base/src/main/java/com/pj/face/handler/VerifyVO.java → sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/VerifyVO.java

@@ -1,4 +1,4 @@
-package com.pj.face.handler;
+package com.pj.project4sp.face.handler;
 
 import lombok.Data;
 

+ 223 - 0
sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/impl/ArcsoftFaceHandlerImpl.java

@@ -0,0 +1,223 @@
+package com.pj.project4sp.face.handler.impl;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
+import com.arcsoft.face.*;
+import com.arcsoft.face.enums.DetectMode;
+import com.arcsoft.face.enums.DetectOrient;
+import com.arcsoft.face.toolkit.ImageFactory;
+import com.arcsoft.face.toolkit.ImageInfo;
+import com.pj.current.config.SystemObject;
+import com.pj.project4sp.face.brand.FaceBrand;
+import com.pj.project4sp.face.factory.FaceEngineFactory;
+import com.pj.project4sp.face.handler.IFaceHandler;
+import com.pj.project4sp.face.handler.VerifyVO;
+import com.pj.utils.sg.AjaxError;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.springframework.context.annotation.DependsOn;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
+
+/**
+ * 基于ArcSoft Face的人��识别
+ */
+@Service
+@Slf4j
+@DependsOn({"systemObject"})
+public class ArcsoftFaceHandlerImpl implements IFaceHandler {
+
+    //通用人脸识别引擎池
+    private GenericObjectPool<FaceEngine> faceEngineGeneralPool;
+
+
+
+    private ExecutorService compareExecutorService;
+
+    @Override
+    public boolean checkIsLive(String baseImg) {
+        List<LivenessInfo> livenessInfoList = new ArrayList<>();
+        FaceEngine faceEngine = null;
+        try {
+            faceEngine = faceEngineGeneralPool.borrowObject();
+            faceEngine.getLiveness(livenessInfoList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new AjaxError("获取识别引擎失败");
+        } finally {
+            if (faceEngine != null) {
+                faceEngineGeneralPool.returnObject(faceEngine);
+            }
+        }
+        return livenessInfoList.get(0).getLiveness() == 1;
+    }
+
+    @Override
+    public void createPersonByBase(String faceId, String name, String imageBase) {
+        byte[] imageBytes = Base64.getDecoder().decode(imageBase);
+        this.createPersonByBase(faceId, name, imageBytes);
+
+    }
+
+    @Override
+    public void createPersonByBase(String faceId, String name, byte[] imageBytes) {
+        String facePath = SystemObject.getFaceImgPath();
+        File outputFile = new File(facePath + File.separator + faceId + ".png");
+        FileUtil.del(outputFile);
+        // 创建输出流
+        try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
+            // 写入数据到文件
+            fileOutputStream.write(imageBytes);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void deletePerson(String faceId) {
+        String facePath = SystemObject.getFaceImgPath();
+        File outputFile = new File(facePath + File.separator + faceId + ".png");
+        FileUtil.del(outputFile);
+    }
+
+    @Override
+    public boolean checkHasPerson(String img) {
+        byte[] imageBytes = Base64.getDecoder().decode(img);
+        return this.checkHasPerson(imageBytes);
+    }
+
+    @Override
+    public boolean checkHasPerson(byte[] imageBase) {
+        ImageInfo imageInfo = getRGBData(imageBase);
+        List<FaceInfo> faceInfoList = new ArrayList<>();
+        FaceEngine faceEngine = null;
+        try {
+            faceEngine = faceEngineGeneralPool.borrowObject();
+            faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new AjaxError("获取识别引擎失败");
+        } finally {
+            if (faceEngine != null) {
+                faceEngineGeneralPool.returnObject(faceEngine);
+            }
+        }
+        return faceInfoList.size() == 1;
+    }
+
+    @Override
+    public VerifyVO verify(String faceId, String baseImage) {
+
+
+
+        byte[] imageBytes = Base64.getDecoder().decode(baseImage);
+       return this.verify(faceId,imageBytes);
+
+    }
+
+    @Override
+    public VerifyVO verify(String faceId, byte[] imageBytes) {
+        VerifyVO vo = new VerifyVO();
+        String facePath = SystemObject.getFaceImgPath();
+        File file = new File(facePath + File.separator + faceId + ".png");
+        if (!file.exists()) {
+            vo.setMsg("人员ID不存在");
+            return vo;
+        }
+        ImageInfo sourceImageInfo = getRGBData(imageBytes);
+        List<FaceInfo> sourceFaceInfoList = new ArrayList<>();
+        FaceEngine faceEngine = null;
+        try {
+            faceEngine = faceEngineGeneralPool.borrowObject();
+            faceEngine.detectFaces(sourceImageInfo.getImageData(), sourceImageInfo.getWidth(), sourceImageInfo.getHeight(), sourceImageInfo.getImageFormat(), sourceFaceInfoList);
+            if (sourceFaceInfoList.size() == 0) {
+                vo.setMsg("No faces");
+                return vo;
+            }
+            if (sourceFaceInfoList.size() > 1) {
+                vo.setMsg("图片中存在多个人脸");
+                return vo;
+            }
+            FaceInfo faceInfo = sourceFaceInfoList.get(0);
+            FaceFeature sourceFaceFeature = new FaceFeature();
+            faceEngine.extractFaceFeature(sourceImageInfo.getImageData(), sourceImageInfo.getWidth(), sourceImageInfo.getHeight(), sourceImageInfo.getImageFormat(), faceInfo, sourceFaceFeature);
+
+            //目标图片人脸
+            List<FaceInfo> targeFaceInfoList = new ArrayList<>();
+            ImageInfo imageInfo2 = getRGBData(file);
+            faceEngine.detectFaces(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), imageInfo2.getImageFormat(), targeFaceInfoList);
+            //特征提取
+            FaceFeature targeFaceFeature = new FaceFeature();
+            faceEngine.extractFaceFeature(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), imageInfo2.getImageFormat(), targeFaceInfoList.get(0), targeFaceFeature);
+
+
+            FaceSimilar faceSimilar = new FaceSimilar();
+            faceEngine.compareFaceFeature(new FaceFeature(targeFaceFeature.getFeatureData()), new FaceFeature(sourceFaceFeature.getFeatureData()), faceSimilar);
+            boolean result = faceSimilar.getScore() > 0.85f;
+            String msg = result ? "人脸一致" : "不匹配";
+            vo.setSuccess(result);
+            vo.setMsg(msg);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new AjaxError("获取识别引擎失败");
+        } finally {
+            if (faceEngine != null) {
+                faceEngineGeneralPool.returnObject(faceEngine);
+            }
+        }
+        return vo;
+    }
+
+    @Override
+    public List<String> faceSearch(String baseImg) {
+        return null;
+    }
+
+    @Override
+    public FaceBrand faceBrand() {
+        return FaceBrand.ARCSOFT;
+    }
+
+
+    @PostConstruct
+    public void init() {
+
+        if (!StrUtil.equals(SystemObject.config.getFaceType(), FaceBrand.ARCSOFT.getType())) {
+            return;
+        }
+        String appId = SystemObject.config.getArcsoftAppid();
+        String sdkKey = SystemObject.config.getArcsoftSdkKey();
+        log.info("Initializing------:{}:{}", appId, sdkKey);
+
+        GenericObjectPoolConfig detectPoolConfig = new GenericObjectPoolConfig();
+        detectPoolConfig.setMaxIdle(5);
+        detectPoolConfig.setMaxTotal(5);
+        detectPoolConfig.setMinIdle(5);
+        detectPoolConfig.setLifo(false);
+        EngineConfiguration detectCfg = new EngineConfiguration();
+        FunctionConfiguration detectFunctionCfg = new FunctionConfiguration();
+        detectFunctionCfg.setSupportFaceDetect(true);//开启人脸检测功能
+        detectFunctionCfg.setSupportFaceRecognition(true);//开启人脸识别功能
+        detectCfg.setFunctionConfiguration(detectFunctionCfg);
+        detectCfg.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);//图片检测模式,如果是连续帧的视频流图片,那么改成VIDEO模式
+        detectCfg.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);//人脸旋转角度
+        faceEngineGeneralPool = new GenericObjectPool(new FaceEngineFactory(appId, sdkKey, null, detectCfg), detectPoolConfig);//底层库算法对象池
+        compareExecutorService = Executors.newFixedThreadPool(5);
+
+
+    }
+
+
+}

+ 24 - 9
sp-core/sp-base/src/main/java/com/pj/face/handler/impl/TencenFaceHandlerImpl.java → sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/impl/TencenFaceHandlerImpl.java

@@ -1,12 +1,11 @@
-package com.pj.face.handler.impl;
+package com.pj.project4sp.face.handler.impl;
 
 import cn.hutool.core.util.StrUtil;
-import cn.hutool.json.JSONUtil;
 import cn.hutool.log.StaticLog;
-import com.pj.face.brand.FaceBrand;
-import com.pj.face.handler.IFaceHandler;
-import com.pj.face.handler.VerifyVO;
-import com.pj.face.properties.TencenProperties;
+import com.pj.project4sp.face.brand.FaceBrand;
+import com.pj.project4sp.face.handler.IFaceHandler;
+import com.pj.project4sp.face.handler.VerifyVO;
+import com.pj.project4sp.face.properties.TencenProperties;
 import com.pj.utils.sg.AjaxError;
 import com.tencentcloudapi.common.AbstractModel;
 import com.tencentcloudapi.common.Credential;
@@ -15,16 +14,14 @@ import com.tencentcloudapi.common.profile.ClientProfile;
 import com.tencentcloudapi.common.profile.HttpProfile;
 import com.tencentcloudapi.iai.v20200303.IaiClient;
 import com.tencentcloudapi.iai.v20200303.models.*;
-import io.swagger.models.auth.In;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Base64;
 import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * 人脸库管理地址
@@ -60,6 +57,12 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
         return vo;
     }
 
+    @Override
+    public VerifyVO verify(String faceId, byte[] imageBytes) {
+       String base64Images= Base64.getEncoder().encodeToString(imageBytes);
+        return verify(faceId, base64Images);
+    }
+
     /**
      * 查找人脸库
      *
@@ -111,6 +114,12 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
     }
 
     @Override
+    public void createPersonByBase(String faceId, String name, byte[] imageBase) {
+        String base64Images= Base64.getEncoder().encodeToString(imageBase);
+        createPersonByBase(faceId, name, base64Images);
+    }
+
+    @Override
     public void deletePerson(String faceId) {
         IaiClient client = this.createClient();
         DeletePersonRequest request = new DeletePersonRequest();
@@ -157,6 +166,12 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
         return true;
     }
 
+    @Override
+    public boolean checkHasPerson(byte[] imageBase) {
+        String base64Images= Base64.getEncoder().encodeToString(imageBase);
+        return checkHasPerson(base64Images);
+    }
+
     public boolean checkIsLive(String baseImg) {
         IaiClient client = this.createClient();
         DetectLiveFaceRequest req = new DetectLiveFaceRequest();

+ 1 - 1
sp-core/sp-base/src/main/java/com/pj/face/handler/impl/TencenRespBO.java → sp-service/sp-admin/src/main/java/com/pj/project4sp/face/handler/impl/TencenRespBO.java

@@ -1,4 +1,4 @@
-package com.pj.face.handler.impl;
+package com.pj.project4sp.face.handler.impl;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.Data;

+ 1 - 1
sp-core/sp-base/src/main/java/com/pj/face/properties/TencenProperties.java → sp-service/sp-admin/src/main/java/com/pj/project4sp/face/properties/TencenProperties.java

@@ -1,4 +1,4 @@
-package com.pj.face.properties;
+package com.pj.project4sp.face.properties;
 
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;

+ 2 - 9
sp-service/sp-admin/src/main/java/com/pj/project4sp/startup/StartUpInit.java

@@ -1,8 +1,6 @@
 package com.pj.project4sp.startup;
 
-import com.pj.current.config.SystemObject;
-import com.pj.face.brand.FaceBrand;
-import com.pj.face.config.FaceEngineConfig;
+
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
@@ -11,11 +9,6 @@ public class StartUpInit implements CommandLineRunner {
 
     @Override
     public void run(String... args) throws Exception {
-        String systemSetting=SystemObject.config.getFaceType();
-        String domain=SystemObject.config.getDomain();
-        String type=FaceBrand.ARCSOFT.getType();
-        if (type.equals(systemSetting)) {
-            FaceEngineConfig.initFaceEngine();
-        }
+
     }
 }

+ 58 - 7
sp-service/sp-admin/src/main/java/com/pj/project4sp/utils/ImageUtils.java

@@ -1,16 +1,16 @@
 package com.pj.project4sp.utils;
 
+import cn.hutool.core.util.RandomUtil;
 import cn.hutool.log.StaticLog;
 import net.coobird.thumbnailator.Thumbnails;
 import sun.misc.BASE64Decoder;
 import sun.misc.BASE64Encoder;
 
 import javax.imageio.ImageIO;
+import java.awt.*;
 import java.awt.image.BufferedImage;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
+import java.io.*;
+import java.nio.file.Files;
 import java.util.Base64;
 
 public class ImageUtils {
@@ -18,8 +18,6 @@ public class ImageUtils {
     private static final Integer KB = 1024;
 
 
-
-
     // 将Base64字符串解码为BufferedImage
     public static BufferedImage base64ToBufferedImage(String base64Image) throws IOException {
         byte[] imageBytes = Base64.getDecoder().decode(base64Image);
@@ -34,6 +32,7 @@ public class ImageUtils {
         byte[] imageBytes = baos.toByteArray();
         return Base64.getEncoder().encodeToString(imageBytes);
     }
+
     /**
      * 图片压缩指定长宽处理
      *
@@ -46,7 +45,7 @@ public class ImageUtils {
         try {
             originalImage = base64ToBufferedImage(base64Image);
         } catch (IOException e) {
-           return base64Image;
+            return base64Image;
         }
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -78,4 +77,56 @@ public class ImageUtils {
         return Base64.getEncoder().encodeToString(compressedImageBytes);
     }
 
+    public static String resizeImageBase64(String base64Input) throws IOException {
+        int targetWidth = 480;
+        int targetHeight = 720;
+        byte[] imageBytes = Base64.getDecoder().decode(base64Input);
+
+        try (ByteArrayInputStream bais = new ByteArrayInputStream(imageBytes);
+             ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            BufferedImage originalImage = ImageIO.read(bais);
+            BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, originalImage.getType());
+
+            Graphics2D g2d = resizedImage.createGraphics();
+            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+            g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            g2d.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null);
+            g2d.dispose();
+
+            ImageIO.write(resizedImage, "jpg", baos);
+            byte[] newImageBytes = baos.toByteArray();
+            return Base64.getEncoder().encodeToString(newImageBytes);
+        }
+    }
+    public static  byte[]  resizeByteImageBase64(String base64Input) throws IOException {
+        int targetWidth = 720;
+        int targetHeight = 1080;
+        byte[] imageBytes = Base64.getDecoder().decode(base64Input);
+
+        try (ByteArrayInputStream bais = new ByteArrayInputStream(imageBytes);
+             ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            BufferedImage originalImage = ImageIO.read(bais);
+            BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, originalImage.getType());
+
+            Graphics2D g2d = resizedImage.createGraphics();
+            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+            g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            g2d.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null);
+            g2d.dispose();
+
+            ImageIO.write(resizedImage, "jpg", baos);
+            return baos.toByteArray();
+        }
+    }
+
+    public static String encodeFileToBase64Binary(String fileName) throws IOException {
+        // 读取文件到字节数组
+        byte[] fileContent = Files.readAllBytes(new File(fileName).toPath());
+        // 使用Base64编码字节数组
+        return Base64.getEncoder().encodeToString(fileContent);
+
+    }
+
 }