|
@@ -0,0 +1,196 @@
|
|
|
+package cn.hmsoft.art.service.live;
|
|
|
+
|
|
|
+import cn.hmsoft.art.constants.ArtDefaultValue;
|
|
|
+import cn.hmsoft.art.constants.ArtParamName;
|
|
|
+import cn.hmsoft.art.constants.Constants;
|
|
|
+import cn.hmsoft.art.constants.StdMaterialType;
|
|
|
+import cn.hmsoft.art.data.dao.live.TxLivenessDetailDao;
|
|
|
+import cn.hmsoft.art.data.dao.live.TxStdLiveLogDao;
|
|
|
+import cn.hmsoft.art.data.dao.std.StdMaterialDao;
|
|
|
+import cn.hmsoft.art.data.dao.std.StdRegDao;
|
|
|
+import cn.hmsoft.art.data.model.live.TxLivenessDetail;
|
|
|
+import cn.hmsoft.art.data.model.live.TxStdLiveLog;
|
|
|
+import cn.hmsoft.art.data.model.live.txStdMaterialLog;
|
|
|
+import cn.hmsoft.art.data.model.std.StdMaterial;
|
|
|
+import cn.hmsoft.art.data.model.std.StdReg;
|
|
|
+import cn.hmsoft.art.data.response.live.*;
|
|
|
+import cn.hmsoft.art.data.vo.live.DetectAuthVO;
|
|
|
+import cn.hmsoft.art.enrol.helper.EnrolMaterialHelper;
|
|
|
+import cn.hmsoft.art.helper.ArtParamHelper;
|
|
|
+import cn.hmsoft.art.helper.GsonHelper;
|
|
|
+import cn.hmsoft.art.helper.ImageUtil;
|
|
|
+import cn.hmsoft.art.service.ArtService;
|
|
|
+import cn.hmsoft.frame.constants.FrameStatus;
|
|
|
+import cn.hmsoft.frame.exception.BusinessException;
|
|
|
+import cn.hmsoft.helper.CollectionHelper;
|
|
|
+import cn.hmsoft.helper.StringHelper;
|
|
|
+import cn.hmsoft.jdbc.entity.QueryOrder;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+public class LiveRecognitionService extends ArtService {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(LiveRecognitionService.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StdRegDao stdRegDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TxStdLiveLogDao txStdLiveLogDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TxLivenessDetailDao txLivenessDetailDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StdMaterialDao stdMaterialDao;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public DetectInfoResult saveDetectResult(String bizToken, String result) {
|
|
|
+ log.info("[saveDetectResult] bizToken:{},result:{}", bizToken, result);
|
|
|
+ DetectInfoResult detectInfoResult = new DetectInfoResult();
|
|
|
+ if (StringHelper.isNotEmpty(result)) {
|
|
|
+ DetectInfoBean detectInfoBean = GsonHelper.fromJson(result, DetectInfoBean.class);
|
|
|
+ DetectInfoText text = detectInfoBean.getText();
|
|
|
+ if (text == null) {
|
|
|
+ log.error("[saveDetectResult] bizToken:{} text为空", bizToken);
|
|
|
+ throw new BusinessException(Constants.SYSTEM_BUSY);
|
|
|
+ }
|
|
|
+ // 相似度
|
|
|
+ double sim = Double.parseDouble(
|
|
|
+ ArtParamHelper.getParamValue(ArtParamName.EnrolVerifyStdIdentityPercent, "" + ArtDefaultValue.EnrolIdentifyVerifyPercent));
|
|
|
+ if (StringHelper.isNotEmpty(text.getSim()) && Double.parseDouble(text.getSim()) > sim) {
|
|
|
+ //识别通过
|
|
|
+ detectInfoResult.setResult(Constants.TRUE_FLAG);
|
|
|
+ } else {
|
|
|
+ detectInfoResult.setResult(Constants.FALSE_FLAG);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存流水
|
|
|
+ List<DetectInfoDetail> livenessDetail = text.getLivenessDetail();
|
|
|
+ if (livenessDetail != null && !livenessDetail.isEmpty()) {
|
|
|
+ livenessDetail.forEach(item -> {
|
|
|
+ TxLivenessDetail detail = new TxLivenessDetail();
|
|
|
+ detail.setBiz_token(bizToken);
|
|
|
+ detail.setReq_time(item.getReqTime());
|
|
|
+ detail.setSeq(item.getSeq());
|
|
|
+ detail.setId_card(item.getIdcard());
|
|
|
+ detail.setName(item.getName());
|
|
|
+ detail.setSim(item.getSim());
|
|
|
+ detail.setNeed_charge(item.getNeedCharge());
|
|
|
+ detail.setError_code(item.getErrcode());
|
|
|
+ detail.setError_msg(item.getErrmsg());
|
|
|
+ detail.setLive_status(item.getLivestatus());
|
|
|
+ detail.setLive_msg(item.getLivemsg());
|
|
|
+ detail.setCompare_status(item.getComparestatus());
|
|
|
+ detail.setCompare_msg(item.getComparemsg());
|
|
|
+ detail.setCompare_lib_type(item.getCompareLibType());
|
|
|
+ detail.setLiveness_mode(item.getLivenessMode());
|
|
|
+ //保存流水
|
|
|
+ txLivenessDetailDao.insert(detail);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新拉取标志
|
|
|
+ List<TxStdLiveLog> stdLiveLogList = txStdLiveLogDao.list("biz_token", bizToken,
|
|
|
+ new QueryOrder("create_time", QueryOrder.QueryOrderType.DESC));
|
|
|
+ TxStdLiveLog txStdLiveLog;
|
|
|
+ if (CollectionHelper.isNotEmpty(stdLiveLogList)) {
|
|
|
+ txStdLiveLog = stdLiveLogList.get(0);
|
|
|
+ txStdLiveLog.setPull_flag(Constants.TRUE_FLAG);
|
|
|
+ txStdLiveLogDao.update(txStdLiveLog);
|
|
|
+ } else {
|
|
|
+ log.error("[saveDetectResult] biz_token:{} 找不到请求记录", bizToken);
|
|
|
+ throw new BusinessException(Constants.SYSTEM_BUSY);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存考生照片
|
|
|
+ try {
|
|
|
+ DetectInfoBestFrame bestFrame = detectInfoBean.getBestFrame();
|
|
|
+ if (bestFrame != null && StringHelper.isNotEmpty(bestFrame.getBestFrame())) {
|
|
|
+ StdReg reg = stdRegDao.findByStdId(txStdLiveLog.getStd_id());
|
|
|
+ String rootPath = EnrolMaterialHelper.getEnrolMaterialLocalPath();
|
|
|
+ // 文件名称
|
|
|
+ String fileName = EnrolMaterialHelper.generateMaterialName(StdMaterialType.NoCrownPhoto, reg.getCert_id()) + Constants.PHOTO_SUFFIX;
|
|
|
+ // 文件不存在创建
|
|
|
+ File file = new File(rootPath + fileName);
|
|
|
+ if(!file.exists()){
|
|
|
+ File parentFile = file.getParentFile();
|
|
|
+ if(!parentFile.exists()){
|
|
|
+ parentFile.mkdirs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存
|
|
|
+ boolean flag = ImageUtil.generateBase64StringToFile(bestFrame.getBestFrame(), file);
|
|
|
+ if (!flag) {
|
|
|
+ log.warn("[saveDetectResult] 保存图片失败");
|
|
|
+ // 失败 将考生的base64数据保存到数据库表中
|
|
|
+ txStdMaterialLog materialLog = new txStdMaterialLog();
|
|
|
+ materialLog.setStd_id(txStdLiveLog.getStd_id());
|
|
|
+ materialLog.setStd_photo(bestFrame.getBestFrame());
|
|
|
+ materialLog.setCreate_time(LocalDateTime.now());
|
|
|
+ stdMaterialDao.insert(materialLog);
|
|
|
+ } else {
|
|
|
+ // 数据写入到考生材料表
|
|
|
+ StdMaterial stdMaterial = new StdMaterial();
|
|
|
+ //是否存在
|
|
|
+ StdMaterial existMaterial = stdMaterialDao.findMaterial(txStdLiveLog.getStd_id(), StdMaterialType.NoCrownPhoto);
|
|
|
+ fileName = fileName.replace("\\","/");
|
|
|
+ if (existMaterial != null) {
|
|
|
+ existMaterial.setMaterial_file(fileName);
|
|
|
+ existMaterial.setUpload_time(LocalDateTime.now());
|
|
|
+ existMaterial.setVerify_status(FrameStatus.Active.toString());
|
|
|
+ existMaterial.setVerify_time(LocalDateTime.now());
|
|
|
+ stdMaterialDao.update(existMaterial);
|
|
|
+ } else {
|
|
|
+ stdMaterial.setStd_id(txStdLiveLog.getStd_id());
|
|
|
+ stdMaterial.setMaterial_type(StdMaterialType.NoCrownPhoto);
|
|
|
+ stdMaterial.setMaterial_file(fileName);
|
|
|
+ stdMaterial.setFile_type(Constants.PHOTO_SUFFIX_WITHOUT_DOT);
|
|
|
+ stdMaterial.setUpload_time(LocalDateTime.now());
|
|
|
+ stdMaterial.setVerify_status(FrameStatus.Active.toString());
|
|
|
+ stdMaterial.setVerify_time(LocalDateTime.now());
|
|
|
+ stdMaterialDao.insert(stdMaterial);
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新考生表中的头像
|
|
|
+ reg.setStd_image(fileName);
|
|
|
+ stdRegDao.update(reg);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("[saveDetectResult] 保存图片失败,{}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存视频数据(暂不保存)
|
|
|
+ }
|
|
|
+
|
|
|
+ return detectInfoResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveDetectAuth(DetectAuthBean bean, DetectAuthVO detectAuthVO) {
|
|
|
+ StdReg stdReg = stdRegDao.findStdRegByCertAndName(detectAuthVO.getCertId(), detectAuthVO.getStdName());
|
|
|
+ if (stdReg == null) {
|
|
|
+ log.warn("[saveDetectAuth] 考生信息不存在,std_name:{}, cert_id:{}", detectAuthVO.getStdName(), detectAuthVO.getCertId());
|
|
|
+ throw new BusinessException("考生信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存token
|
|
|
+ TxStdLiveLog log = new TxStdLiveLog();
|
|
|
+ log.setBiz_token(bean.getBizToken());
|
|
|
+ log.setStd_id(stdReg.getStd_id());
|
|
|
+ log.setCreate_time(LocalDateTime.now());
|
|
|
+ log.setPull_flag(Constants.FALSE_FLAG);
|
|
|
+ txStdLiveLogDao.insert(log);
|
|
|
+ }
|
|
|
+}
|