1.优化人脸同步大华
parent
dc1432e092
commit
11e495a15a
|
|
@ -1,10 +1,7 @@
|
||||||
package com.zcloud.primeport.command;
|
package com.zcloud.primeport.command;
|
||||||
|
|
||||||
import com.alibaba.cola.exception.BizException;
|
import com.alibaba.cola.exception.BizException;
|
||||||
import com.alibaba.cola.dto.MultiResponse;
|
import com.zcloud.gbscommon.utils.Base64Util;
|
||||||
import com.zcloud.gbscommon.zclouduser.facade.ZcloudUserFacade;
|
|
||||||
import com.zcloud.gbscommon.zclouduser.request.ZcloudUserImgQry;
|
|
||||||
import com.zcloud.gbscommon.zclouduser.response.ZcloudUserImgBase64Co;
|
|
||||||
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
|
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
|
||||||
import com.zcloud.primeport.domain.gateway.PersonApplyGateway;
|
import com.zcloud.primeport.domain.gateway.PersonApplyGateway;
|
||||||
import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd;
|
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.domain.model.XgfApplyPersonE;
|
||||||
import com.zcloud.primeport.dto.PersonApplyUpdateCmd;
|
import com.zcloud.primeport.dto.PersonApplyUpdateCmd;
|
||||||
import jodd.util.Base64;
|
import jodd.util.Base64;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -24,8 +22,9 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* 相关方人员同步大华平台。
|
* 相关方人员同步大华平台。
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@AllArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DaHuaPersonSyncExe {
|
public class DaHuaPersonSyncExe {
|
||||||
|
|
||||||
private static final int RELATED_PARTY = 3;
|
private static final int RELATED_PARTY = 3;
|
||||||
|
|
@ -33,8 +32,8 @@ public class DaHuaPersonSyncExe {
|
||||||
private final DaHuaGateway daHuaGateway;
|
private final DaHuaGateway daHuaGateway;
|
||||||
private final PersonApplyGateway personApplyGateway;
|
private final PersonApplyGateway personApplyGateway;
|
||||||
|
|
||||||
@DubboReference
|
@Value("${file.url:}")
|
||||||
private ZcloudUserFacade zcloudUserFacade;
|
private String fileUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 相关方人员审核通过后,按证件号判断新增或更新大华人员。
|
* 相关方人员审核通过后,按证件号判断新增或更新大华人员。
|
||||||
|
|
@ -126,40 +125,45 @@ public class DaHuaPersonSyncExe {
|
||||||
DaHuaPersonSyncCmd.PersonBiosignature face = new DaHuaPersonSyncCmd.PersonBiosignature();
|
DaHuaPersonSyncCmd.PersonBiosignature face = new DaHuaPersonSyncCmd.PersonBiosignature();
|
||||||
face.setType(3);
|
face.setType(3);
|
||||||
face.setIndex(1);
|
face.setIndex(1);
|
||||||
// userFaceUrl 是用户中心的文件路径,先通过 Dubbo 获取 Base64,交给网关上传到大华
|
// userFaceUrl 是文件服务器相对路径,读取图片并转换为 Base64 后交给大华网关。
|
||||||
face.setBase64Data(resolveFaceBase64(faceUrl));
|
face.setBase64Data(resolveFaceBase64(faceUrl));
|
||||||
cmd.setPersonBiosignatures(Collections.singletonList(face));
|
cmd.setPersonBiosignatures(Collections.singletonList(face));
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户中心把本系统头像路径转换为图片 Base64。
|
* 根据文件服务地址读取相关方人员头像并转换为图片 Base64。
|
||||||
* 大华人员接口的 path 必须是大华图片上传接口返回的 fileUrl,不能直接使用本系统路径。
|
* 大华人员接口的 path 必须是大华图片上传接口返回的 fileUrl,不能直接使用本系统路径。
|
||||||
*/
|
*/
|
||||||
private String resolveFaceBase64(String faceUrl) {
|
private String resolveFaceBase64(String faceUrl) {
|
||||||
if (faceUrl == null || faceUrl.trim().isEmpty()) {
|
if (faceUrl == null || faceUrl.trim().isEmpty()) {
|
||||||
throw new BizException("相关方人员头像不能为空");
|
throw new BizException("相关方人员头像不能为空");
|
||||||
}
|
}
|
||||||
ZcloudUserImgQry qry = new ZcloudUserImgQry();
|
if (fileUrl == null || fileUrl.trim().isEmpty()) {
|
||||||
qry.setUrlList(Collections.singletonList(faceUrl));
|
throw new BizException("文件访问地址未配置");
|
||||||
MultiResponse<ZcloudUserImgBase64Co> response;
|
}
|
||||||
|
String baseUrl = fileUrl.trim();
|
||||||
|
String relativePath = faceUrl.trim();
|
||||||
|
String imageUrl = baseUrl.endsWith("/")
|
||||||
|
? baseUrl + removeLeadingSlash(relativePath)
|
||||||
|
: baseUrl + "/" + removeLeadingSlash(relativePath);
|
||||||
try {
|
try {
|
||||||
response = zcloudUserFacade.listBase64ByUrl(qry);
|
String faceBase64 = Base64Util.urlToBase64(imageUrl);
|
||||||
} catch (Exception e) {
|
if (faceBase64 == null || faceBase64.trim().isEmpty()) {
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new BizException("相关方人员头像转换失败");
|
throw new BizException("相关方人员头像转换失败");
|
||||||
}
|
}
|
||||||
|
return faceBase64;
|
||||||
|
} catch (BizException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取相关方人员头像失败, imageUrl={}", imageUrl, e);
|
||||||
|
throw new BizException("获取相关方人员头像失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String removeLeadingSlash(String path) {
|
||||||
|
return path.startsWith("/") ? path.substring(1) : path;
|
||||||
|
}
|
||||||
|
|
||||||
private String decodeUserCard(String userCard) {
|
private String decodeUserCard(String userCard) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue