1.优化人脸同步大华

dev
shenzhidan 2026-07-29 16:52:12 +08:00
parent dc1432e092
commit 11e495a15a
1 changed files with 31 additions and 27 deletions

View File

@ -1,10 +1,7 @@
package com.zcloud.primeport.command;
import com.alibaba.cola.exception.BizException;
import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.gbscommon.zclouduser.facade.ZcloudUserFacade;
import com.zcloud.gbscommon.zclouduser.request.ZcloudUserImgQry;
import com.zcloud.gbscommon.zclouduser.response.ZcloudUserImgBase64Co;
import com.zcloud.gbscommon.utils.Base64Util;
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
import com.zcloud.primeport.domain.gateway.PersonApplyGateway;
import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd;
@ -12,8 +9,9 @@ import com.zcloud.primeport.domain.model.PersonApplyE;
import com.zcloud.primeport.domain.model.XgfApplyPersonE;
import com.zcloud.primeport.dto.PersonApplyUpdateCmd;
import jodd.util.Base64;
import lombok.AllArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
@ -24,8 +22,9 @@ import java.util.Map;
/**
*
*/
@Slf4j
@Component
@AllArgsConstructor
@RequiredArgsConstructor
public class DaHuaPersonSyncExe {
private static final int RELATED_PARTY = 3;
@ -33,8 +32,8 @@ public class DaHuaPersonSyncExe {
private final DaHuaGateway daHuaGateway;
private final PersonApplyGateway personApplyGateway;
@DubboReference
private ZcloudUserFacade zcloudUserFacade;
@Value("${file.url:}")
private String fileUrl;
/**
*
@ -126,39 +125,44 @@ public class DaHuaPersonSyncExe {
DaHuaPersonSyncCmd.PersonBiosignature face = new DaHuaPersonSyncCmd.PersonBiosignature();
face.setType(3);
face.setIndex(1);
// userFaceUrl 是用户中心的文件路径,先通过 Dubbo 获取 Base64交给网关上传到大华
// userFaceUrl 是文件服务器相对路径,读取图片并转换为 Base64 后交给大华网关。
face.setBase64Data(resolveFaceBase64(faceUrl));
cmd.setPersonBiosignatures(Collections.singletonList(face));
return cmd;
}
/**
* Base64
* Base64
* path fileUrl使
*/
private String resolveFaceBase64(String faceUrl) {
if (faceUrl == null || faceUrl.trim().isEmpty()) {
throw new BizException("相关方人员头像不能为空");
}
ZcloudUserImgQry qry = new ZcloudUserImgQry();
qry.setUrlList(Collections.singletonList(faceUrl));
MultiResponse<ZcloudUserImgBase64Co> response;
if (fileUrl == null || fileUrl.trim().isEmpty()) {
throw new BizException("文件访问地址未配置");
}
String baseUrl = fileUrl.trim();
String relativePath = faceUrl.trim();
String imageUrl = baseUrl.endsWith("/")
? baseUrl + removeLeadingSlash(relativePath)
: baseUrl + "/" + removeLeadingSlash(relativePath);
try {
response = zcloudUserFacade.listBase64ByUrl(qry);
} catch (Exception e) {
throw new BizException("获取相关方人员头像失败");
}
if (response == null || response.getData() == null) {
throw new BizException("获取相关方人员头像失败");
}
for (ZcloudUserImgBase64Co image : response.getData()) {
if (image != null && faceUrl.equals(image.getUserAvatarUrl())
&& image.getUserAvatarBase64() != null
&& !image.getUserAvatarBase64().trim().isEmpty()) {
return image.getUserAvatarBase64();
String faceBase64 = Base64Util.urlToBase64(imageUrl);
if (faceBase64 == null || faceBase64.trim().isEmpty()) {
throw new BizException("相关方人员头像转换失败");
}
return faceBase64;
} catch (BizException e) {
throw e;
} catch (Exception e) {
log.error("获取相关方人员头像失败, imageUrl={}", imageUrl, e);
throw new BizException("获取相关方人员头像失败");
}
throw new BizException("相关方人员头像转换失败");
}
private String removeLeadingSlash(String path) {
return path.startsWith("/") ? path.substring(1) : path;
}
private String decodeUserCard(String userCard) {