|
|
@@ -14,7 +14,11 @@ import com.ktg.common.exception.user.CaptchaException;
|
|
|
import com.ktg.common.exception.user.CaptchaExpireException;
|
|
|
import com.ktg.common.exception.user.UserPasswordNotMatchException;
|
|
|
import com.ktg.common.utils.*;
|
|
|
+import com.ktg.common.utils.face.FaceCutUtil;
|
|
|
+import com.ktg.common.utils.face.FaceMatchUtil;
|
|
|
import com.ktg.common.utils.ip.IpUtils;
|
|
|
+import com.ktg.common.vo.FaceCutVO;
|
|
|
+import com.ktg.common.vo.FaceMatchVO;
|
|
|
import com.ktg.common.vo.VerificationVO;
|
|
|
import com.ktg.framework.manager.AsyncManager;
|
|
|
import com.ktg.framework.manager.factory.AsyncFactory;
|
|
|
@@ -25,6 +29,7 @@ import com.ktg.system.service.ISysUserOnlineService;
|
|
|
import com.ktg.system.service.ISysUserService;
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
import io.jsonwebtoken.Jwts;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
@@ -38,6 +43,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
@@ -48,6 +54,7 @@ import java.util.stream.Collectors;
|
|
|
*
|
|
|
* @author guoruan
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
public class SysLoginService {
|
|
|
@Autowired
|
|
|
@@ -231,7 +238,6 @@ public class SysLoginService {
|
|
|
List<String> collect = list.stream().map(SysUserCharacteristic::getContent).collect(Collectors.toList());
|
|
|
// 通过指纹获取最相似的用户
|
|
|
VerificationVO verificationVO = FingerprintComparisonByDat.completableFutureComparison(file, new HashSet<>(collect));
|
|
|
- // VerificationVO verificationVO = FingerprintComparisonByDat.completableFutureComparison(file, collect);
|
|
|
Assert.notNull(verificationVO, "无法根据指纹确定您的身份,请通过其它方式登录!");
|
|
|
String fingerprint = verificationVO.getFingerprint();
|
|
|
SysUserCharacteristic one = iSysUserCharacteristicService.getOne(Wrappers.<SysUserCharacteristic>lambdaQuery()
|
|
|
@@ -246,5 +252,63 @@ public class SysLoginService {
|
|
|
return ajax;
|
|
|
}
|
|
|
|
|
|
+ public AjaxResult loginByFace(MultipartFile file) throws IOException {
|
|
|
+ Assert.isTrue(file.getSize() > 0, "输入的人脸不能为空!");
|
|
|
+ // 获取所有的用户人脸
|
|
|
+ List<SysUserCharacteristic> list = iSysUserCharacteristicService.list(Wrappers.<SysUserCharacteristic>lambdaQuery()
|
|
|
+ .eq(SysUserCharacteristic::getType, "2"));
|
|
|
+ Assert.isFalse(list.isEmpty(), "人脸库中暂无您的人脸信息!");
|
|
|
+ List<String> collect = list.stream().map(SysUserCharacteristic::getContent).collect(Collectors.toList());
|
|
|
+ // 通过人脸获取最相似的用户
|
|
|
+
|
|
|
+
|
|
|
+ // 记录开始时间
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ FaceCutVO faceCutVO = FaceCutUtil.imageFaceDetection(file, 0L, null);
|
|
|
+
|
|
|
+ // 记录结束时间
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ // 计算时间差(毫秒)
|
|
|
+ long duration = endTime - startTime;
|
|
|
+ System.out.println("Execution time in milliseconds: " + duration);
|
|
|
+
|
|
|
+
|
|
|
+ // 记录开始时间
|
|
|
+ long startTime1 = System.currentTimeMillis();
|
|
|
+ FaceMatchVO faceMatchVO = FaceMatchUtil.faceRecognitionComparison(faceCutVO.getContent(), new HashSet<>(collect));
|
|
|
+
|
|
|
+ // 记录结束时间
|
|
|
+ long endTime1 = System.currentTimeMillis();
|
|
|
+ // 计算时间差(毫秒)
|
|
|
+ long duration1 = endTime1 - startTime1;
|
|
|
+ System.out.println("Execution time in milliseconds: " + duration);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 删除刚刚上传的文件信息
|
|
|
+ File file1 = new File(faceCutVO.getContent());
|
|
|
+ if (!file1.delete()) {
|
|
|
+ log.error("面部临时裁剪文件删除失败: " + faceCutVO.getContent());
|
|
|
+ }
|
|
|
+ File file2 = new File(faceCutVO.getImagePath());
|
|
|
+ if (!file2.delete()) {
|
|
|
+ log.error("img文件删除失败: " + faceCutVO.getImagePath());
|
|
|
+ }
|
|
|
+ Assert.notNull(faceMatchVO, "无法根据人脸确定您的身份,请通过其它方式登录!");
|
|
|
+ String okFace = faceMatchVO.getContent();
|
|
|
+ SysUserCharacteristic one = iSysUserCharacteristicService.getOne(Wrappers.<SysUserCharacteristic>lambdaQuery()
|
|
|
+ .eq(SysUserCharacteristic::getContent, okFace)
|
|
|
+ .last("limit 1"));
|
|
|
+ SysUser sysUser = iSysUserService.getById(one.getUserId());
|
|
|
+ // 生成令牌
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ String token = loginWithoutPassword(sysUser);
|
|
|
+ ajax.put(Constants.TOKEN, token);
|
|
|
+ ajax.put("nickName", sysUser.getNickName());
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|