Browse Source

add:考勤打卡人脸识别

caozixuan 1 year ago
parent
commit
eb90d7b45e

+ 6 - 6
sop-business/src/main/java/com/qmth/sop/business/bean/params/DingSaveParam.java

@@ -32,8 +32,8 @@ public class DingSaveParam {
     @NotBlank(message = "缺少签到地址")
     private String signAddress;
 
-    @ApiModelProperty("人脸识别通过?")
-    private Boolean facePass;
+    @ApiModelProperty("人脸对比照片地址")
+    private String facePhotoPath;
 
     @ApiModelProperty("x坐标")
     @NotNull(message = "缺少x坐标")
@@ -77,12 +77,12 @@ public class DingSaveParam {
         this.signAddress = signAddress;
     }
 
-    public Boolean getFacePass() {
-        return facePass;
+    public String getFacePhotoPath() {
+        return facePhotoPath;
     }
 
-    public void setFacePass(Boolean facePass) {
-        this.facePass = facePass;
+    public void setFacePhotoPath(String facePhotoPath) {
+        this.facePhotoPath = facePhotoPath;
     }
 
     public String getAxisX() {

+ 55 - 54
sop-business/src/main/java/com/qmth/sop/business/entity/TBDingHistory.java

@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * <p>
@@ -29,6 +30,9 @@ public class TBDingHistory implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long dingId;
 
+    @ApiModelProperty(value = "派单号")
+    private String sopNo;
+
     @ApiModelProperty(value = "签到日期")
     private String signDate;
 
@@ -36,28 +40,25 @@ public class TBDingHistory implements Serializable {
     private DingDateTypeEnum dateType;
 
     @ApiModelProperty(value = "签到时间")
-    private Long signInTime;
+    private Long signTime;
 
     @ApiModelProperty(value = "坐标轴X")
-    private String axisInX;
+    private String axisX;
 
     @ApiModelProperty(value = "坐标轴Y")
-    private String axisInY;
-
-    @ApiModelProperty(value = "人脸识别是否通过,0:未通过,1:通过")
-    private Boolean faceInError;
+    private String axisY;
 
-    @ApiModelProperty(value = "签退时间")
-    private Long signOutTime;
+    @ApiModelProperty(value = "人脸识别是否启用,0:未启用,1:启用")
+    private Boolean faceOpen;
 
-    @ApiModelProperty(value = "坐标轴X")
-    private String axisOutX;
+    @ApiModelProperty(value = "人脸识别是否通过,0:未通过,1:通过")
+    private Boolean facePass;
 
-    @ApiModelProperty(value = "坐标轴Y")
-    private String axisOutY;
+    @ApiModelProperty(value = "抓拍照片地址")
+    private String facePhotoPath;
 
-    @ApiModelProperty(value = "人脸识别是否通过,0:未通过,1:通过")
-    private Boolean faceOutError;
+    @ApiModelProperty(value = "对比分数")
+    private BigDecimal matchScore;
 
     @ApiModelProperty(value = "创建人id")
     @JsonSerialize(using = ToStringSerializer.class)
@@ -66,14 +67,6 @@ public class TBDingHistory implements Serializable {
     @ApiModelProperty(value = "创建时间")
     private Long createTime;
 
-    public DingDateTypeEnum getDateType() {
-        return dateType;
-    }
-
-    public void setDateType(DingDateTypeEnum dateType) {
-        this.dateType = dateType;
-    }
-
     public Long getId() {
         return id;
     }
@@ -90,6 +83,14 @@ public class TBDingHistory implements Serializable {
         this.dingId = dingId;
     }
 
+    public String getSopNo() {
+        return sopNo;
+    }
+
+    public void setSopNo(String sopNo) {
+        this.sopNo = sopNo;
+    }
+
     public String getSignDate() {
         return signDate;
     }
@@ -98,68 +99,68 @@ public class TBDingHistory implements Serializable {
         this.signDate = signDate;
     }
 
-    public Long getSignInTime() {
-        return signInTime;
+    public DingDateTypeEnum getDateType() {
+        return dateType;
     }
 
-    public void setSignInTime(Long signInTime) {
-        this.signInTime = signInTime;
+    public void setDateType(DingDateTypeEnum dateType) {
+        this.dateType = dateType;
     }
 
-    public String getAxisInX() {
-        return axisInX;
+    public Long getSignTime() {
+        return signTime;
     }
 
-    public void setAxisInX(String axisInX) {
-        this.axisInX = axisInX;
+    public void setSignTime(Long signTime) {
+        this.signTime = signTime;
     }
 
-    public String getAxisInY() {
-        return axisInY;
+    public String getAxisX() {
+        return axisX;
     }
 
-    public void setAxisInY(String axisInY) {
-        this.axisInY = axisInY;
+    public void setAxisX(String axisX) {
+        this.axisX = axisX;
     }
 
-    public Boolean getFaceInError() {
-        return faceInError;
+    public String getAxisY() {
+        return axisY;
     }
 
-    public void setFaceInError(Boolean faceInError) {
-        this.faceInError = faceInError;
+    public void setAxisY(String axisY) {
+        this.axisY = axisY;
     }
 
-    public Long getSignOutTime() {
-        return signOutTime;
+    public Boolean getFaceOpen() {
+        return faceOpen;
     }
 
-    public void setSignOutTime(Long signOutTime) {
-        this.signOutTime = signOutTime;
+    public void setFaceOpen(Boolean faceOpen) {
+        this.faceOpen = faceOpen;
     }
 
-    public String getAxisOutX() {
-        return axisOutX;
+    public Boolean getFacePass() {
+        return facePass;
     }
 
-    public void setAxisOutX(String axisOutX) {
-        this.axisOutX = axisOutX;
+    public void setFacePass(Boolean facePass) {
+        this.facePass = facePass;
     }
 
-    public String getAxisOutY() {
-        return axisOutY;
+    public String getFacePhotoPath() {
+        return facePhotoPath;
     }
 
-    public void setAxisOutY(String axisOutY) {
-        this.axisOutY = axisOutY;
+    public void setFacePhotoPath(String facePhotoPath) {
+        this.facePhotoPath = facePhotoPath;
     }
 
-    public Boolean getFaceOutError() {
-        return faceOutError;
+    public BigDecimal getMatchScore() {
+        return matchScore;
     }
 
-    public void setFaceOutError(Boolean faceOutError) {
-        this.faceOutError = faceOutError;
+    public void setMatchScore(BigDecimal matchScore) {
+        this.matchScore = matchScore;
     }
 
     public Long getCreateId() {

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/service/SysConfigService.java

@@ -21,4 +21,12 @@ public interface SysConfigService extends IService<SysConfig> {
      * @return
      */
     List<SysConfig> selectAll();
+
+    /**
+     * 根据key查询系统配置参数
+     *
+     * @param configKey key
+     * @return 系统配置
+     */
+    SysConfig findByConfigKey(String configKey);
 }

+ 2 - 1
sop-business/src/main/java/com/qmth/sop/business/service/TBDingService.java

@@ -9,6 +9,7 @@ import com.qmth.sop.business.entity.TBDing;
 import com.qmth.sop.common.enums.DingResultEnum;
 import com.qmth.sop.common.enums.InOutTypeEnum;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
@@ -48,7 +49,7 @@ public interface TBDingService extends IService<TBDing> {
      * @param dingSaveParam 打卡记录保存参数
      * @param userId        当前请求用户id
      */
-    void dingSave(DingSaveParam dingSaveParam, Long userId);
+    void dingSave(DingSaveParam dingSaveParam, Long userId) throws IOException;
 
 
     /**

+ 15 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysConfigServiceImpl.java

@@ -1,11 +1,13 @@
 package com.qmth.sop.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.sop.business.cache.CommonCacheService;
 import com.qmth.sop.business.entity.SysConfig;
 import com.qmth.sop.business.mapper.SysConfigMapper;
 import com.qmth.sop.business.service.SysConfigService;
 import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
@@ -62,4 +64,17 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
         }
         return sysConfigList;
     }
+
+    @Override
+    public SysConfig findByConfigKey(String configKey) {
+        List<SysConfig> sysConfigList = this.list(new QueryWrapper<SysConfig>().lambda().eq(SysConfig::getConfigKey, configKey));
+        if (CollectionUtils.isEmpty(sysConfigList)) {
+            throw ExceptionResultEnum.ERROR.exception("未找到key[" + configKey + "]的系统变量");
+        }
+        if (sysConfigList.size() > 1) {
+            throw ExceptionResultEnum.ERROR.exception(String.format("key为[%s]的系统变量有多个", configKey));
+        }
+
+        return sysConfigList.get(0);
+    }
 }

+ 69 - 7
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBDingServiceImpl.java

@@ -8,19 +8,26 @@ import com.qmth.sop.business.bean.dto.SopCrmInfo;
 import com.qmth.sop.business.bean.params.DingSaveParam;
 import com.qmth.sop.business.bean.result.*;
 import com.qmth.sop.business.entity.TBDing;
+import com.qmth.sop.business.entity.TBDingHistory;
 import com.qmth.sop.business.entity.TBUserArchives;
 import com.qmth.sop.business.entity.TFFlowApprove;
 import com.qmth.sop.business.mapper.TBDingMapper;
 import com.qmth.sop.business.service.*;
+import com.qmth.sop.business.sync.FaceApiUtils;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
 import com.qmth.sop.common.util.DateDisposeUtils;
+import com.qmth.sop.common.util.FileStoreUtil;
+import com.qmth.sop.common.util.FileUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -49,9 +56,18 @@ public class TBDingServiceImpl extends ServiceImpl<TBDingMapper, TBDing> impleme
     private SysDingDateService sysDingDateService;
     @Resource
     private TBSopInfoService tbSopInfoService;
+    @Resource
+    private FileStoreUtil fileStoreUtil;
+    @Resource
+    private FaceApiUtils faceApiUtils;
+    @Resource
+    private SysConfigService sysConfigService;
+    @Resource
+    private TBDingHistoryService tbDingHistoryService;
 
     @Override
     public DingElementResult findDingElements(String sopNo, Long userId) {
+
         SopCrmInfo sopCrmInfo = tbCrmService.findSopCrmInfoBySop(sopNo);
         Long serviceUnitId = sopCrmInfo.getServiceUnitId();
 
@@ -213,21 +229,52 @@ public class TBDingServiceImpl extends ServiceImpl<TBDingMapper, TBDing> impleme
     }
 
     @Override
-    public void dingSave(DingSaveParam dingSaveParam, Long userId) {
+    public void dingSave(DingSaveParam dingSaveParam, Long userId) throws IOException {
         String sopNo = dingSaveParam.getSopNo();
+        SopCrmInfo sopCrmInfo = tbCrmService.findSopCrmInfoBySop(sopNo);
+        Long serviceUnitId = sopCrmInfo.getServiceUnitId();
+        DingElementResult dingElementResult = this.baseMapper.findDingResultByUserId(userId, serviceUnitId);
+
         Long signTime = dingSaveParam.getSignTime();
         DingDateTypeEnum dateType = sysDingDateService.getDingDateType(DateDisposeUtils.timestampToLocalDate(signTime));
 
         InOutTypeEnum signType = dingSaveParam.getSignType();
         String signAddress = dingSaveParam.getSignAddress();
-        Boolean facePass = dingSaveParam.getFacePass();
+        String facePhotoPath = dingSaveParam.getFacePhotoPath();
         String axisX = dingSaveParam.getAxisX();
         String axisY = dingSaveParam.getAxisY();
 
         TBUserArchives tbUserArchives = tbUserArchivesService.findByUserId(userId);
         Long userArchivesId = tbUserArchives.getId();
+        // 人脸识别
+        Boolean faceOpen = dingElementResult.getFaceOpen();
+        BigDecimal score = null;
+        Boolean facePass = null;
+        if (faceOpen) {
+            // 开启人脸识别
+            if (facePhotoPath == null || facePhotoPath.length() == 0) {
+                throw ExceptionResultEnum.ERROR.exception("缺少人脸识别照片");
+            }
+            String basePhotoPath = tbUserArchives.getBasePhotoPath();
+            String basePhotoSuffix = basePhotoPath.substring(basePhotoPath.lastIndexOf(".")).toLowerCase();
+            File basePhotoTemp = SystemConstant.getFileTempVar(basePhotoSuffix);
+            String facePhotoSuffix = facePhotoPath.substring(facePhotoPath.lastIndexOf(".")).toLowerCase();
+            File facePhotoTemp = SystemConstant.getFileTempVar(facePhotoSuffix);
+            try {
+                basePhotoTemp = fileStoreUtil.ossDownload(basePhotoPath, basePhotoTemp, UploadFileEnum.FILE.getFssType());
+                facePhotoTemp = fileStoreUtil.ossDownload(facePhotoPath, facePhotoTemp, UploadFileEnum.FILE.getFssType());
+                score = faceApiUtils.faceMatch(basePhotoTemp, facePhotoTemp);
+            } catch (Exception e) {
+                throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+            } finally {
+                FileUtil.deleteFile(basePhotoTemp);
+                FileUtil.deleteFile(facePhotoTemp);
+            }
+            String limitStr = sysConfigService.findByConfigKey(SystemConstant.BAIDU_FACE_COMPARE_SCORE).getConfigValue();
+            BigDecimal limit = new BigDecimal(limitStr);
+            facePass = score.compareTo(limit) > -1;
+        }
 
-        SopCrmInfo sopCrmInfo = tbCrmService.findSopCrmInfoBySop(sopNo);
         String crmNo = sopCrmInfo.getCrmNo();
         Long serviceId = sopCrmInfo.getServiceUnitId();
         Long flowId = sopCrmInfo.getFlowId();
@@ -295,26 +342,41 @@ public class TBDingServiceImpl extends ServiceImpl<TBDingMapper, TBDing> impleme
 
             switch (signType) {
                 case IN: // 签到打卡
-                    recordList = recordList.stream().peek(e -> {
+                    for (TBDing e : recordList) {
                         e.setSignInTime(signTime);
                         e.setSignInAddress(signAddress);
                         e.setAxisInX(axisX);
                         e.setAxisInY(axisY);
                         e.setFaceInPass(facePass);
-                    }).collect(Collectors.toList());
+                    }
                     break;
                 case OUT: // 签退打卡
-                    recordList = recordList.stream().peek(e -> {
+                    for (TBDing e : recordList) {
                         e.setSignOutTime(signTime);
                         e.setSignOutAddress(signAddress);
                         e.setAxisOutX(axisX);
                         e.setAxisOutY(axisY);
                         e.setFaceOutPass(facePass);
-                    }).collect(Collectors.toList());
+                    }
                     break;
             }
             this.updateBatchById(recordList);
         }
+
+        // 新增打卡历史记录
+        TBDingHistory history = new TBDingHistory();
+        history.setSopNo(sopNo);
+        history.setSignDate(signDate);
+        history.setDateType(dateType);
+        history.setSignTime(signTime);
+        history.setAxisX(axisX);
+        history.setAxisY(axisY);
+        history.setFaceOpen(faceOpen);
+        history.setFacePass(facePass);
+        history.setFacePhotoPath(facePhotoPath);
+        history.setMatchScore(score);
+        history.setCreateId(userId);
+        tbDingHistoryService.save(history);
     }
 
     /**

+ 68 - 0
sop-business/src/main/java/com/qmth/sop/business/sync/FaceApiUtils.java

@@ -0,0 +1,68 @@
+package com.qmth.sop.business.sync;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.sop.business.service.SysConfigService;
+import com.qmth.sop.common.been.FaceMatchParam;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import com.qmth.sop.common.util.FileUtil;
+import com.qmth.sop.common.util.HttpUtil;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Description: 百度人脸识别工具类
+ * @Author: CaoZixuan
+ * @Date: 2023-09-14
+ */
+@Service
+public class FaceApiUtils {
+    @Resource
+    private SysConfigService sysConfigService;
+
+    /**
+     * 百度人脸识别-人脸对比
+     *
+     * @param f1 人脸图片文件1
+     * @param f2 人脸图片文件2
+     * @return 识别度
+     * @throws IOException 异常
+     */
+    public BigDecimal faceMatch(File f1, File f2) throws IOException {
+        String appId = sysConfigService.findByConfigKey(SystemConstant.FACE_VERIFY_BAIDU_LOCAL_APP_ID).getConfigValue();
+        String uri = sysConfigService.findByConfigKey(SystemConstant.FACE_VERIFY_BAIDU_LOCAL_URL_PREFIX).getConfigValue();
+        String url = sysConfigService.findByConfigKey(SystemConstant.BAIDU_FACE_COMPARE_URL).getConfigValue();
+
+        String postUrl = uri + url + "?appId=" + appId;
+        List<FaceMatchParam> faceMatchParamList = new ArrayList<>();
+        FaceMatchParam p1 = new FaceMatchParam();
+        p1.setImage(FileUtil.fileToBase64(f1));
+        p1.setImage_type("BASE64");
+        faceMatchParamList.add(p1);
+
+        FaceMatchParam p2 = new FaceMatchParam();
+        p2.setImage(FileUtil.fileToBase64(f2));
+        p2.setImage_type("BASE64");
+        faceMatchParamList.add(p2);
+        String json = JSONArray.toJSONString(faceMatchParamList);
+
+        String result = HttpUtil.postJson(postUrl, json, null, null, false);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        String errorCode = jsonObject.getString("error_code");
+        String errorMsg = jsonObject.getString("error_msg");
+
+        if (!errorCode.equals("0")) {
+            throw ExceptionResultEnum.ERROR.exception(String.format("人脸识别对比请求失败,错误码: %s [%s]", errorCode, errorMsg));
+        }
+        JSONObject detail = jsonObject.getJSONObject("result");
+        return detail.getBigDecimal("score").setScale(2, RoundingMode.HALF_UP);
+    }
+}

+ 24 - 1
sop-business/src/main/resources/db/log/caozixuan_update_log.sql

@@ -279,4 +279,27 @@ UPDATE sys_privilege SET related = '281' WHERE (id = '106');
 -- 2023-09-13
 -- 服务范围设置
 UPDATE sys_privilege SET related = '2006,2007' WHERE (id = '228');
-UPDATE sys_privilege SET related = '2006,2007' WHERE (id = '231');
+UPDATE sys_privilege SET related = '2006,2007' WHERE (id = '231');
+
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('35', 'face.verify.baiduLocalAppId', '百度人脸识别appId', 'test', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('36', 'face.verify.baiduLocalUrlPrefix', '百度人脸识别请求url', 'http://192.168.20.253', '1', '1', '1');
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('37', 'baidu.face.compare.url', '百度人脸识别人脸比对接口', '/face-api/v3/face/match', '1', '1', '1');
+
+ALTER TABLE t_b_ding_history
+    ADD COLUMN sop_no VARCHAR(20) NULL COMMENT 'sop编号' AFTER ding_id,
+    CHANGE COLUMN ding_id ding_id BIGINT NULL COMMENT '考勤id' ;
+
+INSERT INTO sys_config (id, config_key, config_name, config_value, enable, sort, create_id) VALUES ('38', 'baidu.face.compare.score', '百度人脸识别人脸比对阈值', '70', '1', '1', '1');
+
+ALTER TABLE t_b_ding_history
+    DROP COLUMN face_out_error,
+    DROP COLUMN axis_out_Y,
+    DROP COLUMN axis_out_x,
+    DROP COLUMN sign_out_time,
+    ADD COLUMN face_open TINYINT NULL COMMENT '是否开启人脸识别' AFTER axis_y,
+    ADD COLUMN face_photo_path VARCHAR(500) NULL COMMENT '抓拍照片地址' AFTER face_pass,
+    ADD COLUMN match_score DECIMAL(8,2) NULL COMMENT '对比分数' AFTER face_photo_path,
+    CHANGE COLUMN sign_in_time sign_time BIGINT NULL DEFAULT NULL COMMENT '签到时间' ,
+    CHANGE COLUMN axis_in_x axis_x VARCHAR(20) NULL DEFAULT NULL COMMENT '坐标轴X' ,
+    CHANGE COLUMN axis_in_y axis_y VARCHAR(20) NULL DEFAULT NULL COMMENT '坐标轴Y' ,
+    CHANGE COLUMN face_in_error face_pass TINYINT NULL DEFAULT NULL COMMENT '人脸识别是否通过,0:未通过,1:通过' ;

+ 1 - 1
sop-business/src/main/resources/mapper/TBDingMapper.xml

@@ -261,7 +261,7 @@
             tbua.base_photo_path AS basePhotoPath,
             sdg.sign_in_time AS signInTimeScope,
             sdg.sign_out_time AS signOutTimeScope,
-            sdg.reissue_card_count AS reissueCardCount
+            sdg.reissue_card_count AS reissueCardCount,
             sdg.face_open AS faceOpen
         FROM
             t_b_user_archives tbua

+ 4 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -208,6 +208,10 @@ public class SystemConstant {
     public static final String WXAPP_APP_ID = "wxapp.appid";
     public static final String WXAPP_REQUEST_URL = "wxapp.request.url";
     public static final String WXAPP_PHONE_BIND_NEW_URL = "wxapp.phone.bind.new.url";
+    public static final String FACE_VERIFY_BAIDU_LOCAL_APP_ID = "face.verify.baiduLocalAppId";
+    public static final String FACE_VERIFY_BAIDU_LOCAL_URL_PREFIX = "face.verify.baiduLocalUrlPrefix";
+    public static final String BAIDU_FACE_COMPARE_URL = "baidu.face.compare.url";
+    public static final String BAIDU_FACE_COMPARE_SCORE = "baidu.face.compare.score";
 
     /**
      * api前缀

+ 0 - 50
sop-common/src/main/java/com/qmth/sop/common/sync/FaceApiUtils.java

@@ -1,50 +0,0 @@
-package com.qmth.sop.common.sync;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.qmth.sop.common.been.FaceMatchParam;
-import com.qmth.sop.common.util.FileUtil;
-import com.qmth.sop.common.util.HttpUtil;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @Description: 百度人脸识别工具类
- * @Author: CaoZixuan
- * @Date: 2023-09-14
- */
-public class FaceApiUtils {
-    public static void faceMatch() throws IOException {
-        // TODO: 2023/9/14 demo 
-        File f1 = new File("E:\\pictures\\wj1.jpeg");
-        File f2 = new File("E:\\pictures\\wj2.jpeg");
-
-        String appId = "test";
-        String uri = "http://192.168.20.253";
-        String url = "/face-api/v3/face/match";
-        String postUrl = uri + url + "?appId=" + appId;
-        List<FaceMatchParam> faceMatchParamList = new ArrayList<>();
-        FaceMatchParam p1 = new FaceMatchParam();
-        p1.setImage(FileUtil.fileToBase64(f1));
-        p1.setImage_type("BASE64");
-        faceMatchParamList.add(p1);
-
-        FaceMatchParam p2 = new FaceMatchParam();
-        p2.setImage(FileUtil.fileToBase64(f2));
-        p2.setImage_type("BASE64");
-        faceMatchParamList.add(p2);
-        String json = JSONArray.toJSONString(faceMatchParamList);
-        System.out.println(json);
-
-        String result = HttpUtil.postJson(postUrl, json, null, null, false);
-        JSONObject jsonObject = JSONObject.parseObject(result);
-        System.out.println(jsonObject);
-    }
-
-    public static void main(String[] args) throws IOException {
-        faceMatch();
-    }
-}

+ 11 - 0
sop-common/src/main/java/com/qmth/sop/common/util/FileUtil.java

@@ -36,4 +36,15 @@ public class FileUtil {
         }
         return new String(base64Byte);
     }
+
+    public static void deleteFile(String path) {
+        File file = new File(path);
+        deleteFile(file);
+    }
+
+    public static void deleteFile(File file) {
+        if (file.isFile() && file.exists()) {
+            file.delete();
+        }
+    }
 }