From 2f3c4eefd96d74b1021e25950582cc30f2378370 Mon Sep 17 00:00:00 2001 From: zhangxiongfeng Date: Wed, 5 Aug 2026 08:44:22 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=A4=A7=E5=8D=8E=E5=BE=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E4=BF=AE=E6=94=B91.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zcloud/primeport/service/DaHuaServiceImpl.java | 9 ++++++--- .../zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/web-app/src/main/java/com/zcloud/primeport/service/DaHuaServiceImpl.java b/web-app/src/main/java/com/zcloud/primeport/service/DaHuaServiceImpl.java index 3c826ec..d5d3e16 100644 --- a/web-app/src/main/java/com/zcloud/primeport/service/DaHuaServiceImpl.java +++ b/web-app/src/main/java/com/zcloud/primeport/service/DaHuaServiceImpl.java @@ -18,7 +18,7 @@ import org.springframework.stereotype.Service; import java.util.Map; @Service -@DubboService(version = "1.0.0", group = "primeport") +@DubboService public class DaHuaServiceImpl implements ZcloudDaHuaFacade { @Autowired @@ -63,8 +63,11 @@ public class DaHuaServiceImpl implements ZcloudDaHuaFacade { resp.setSuccess(dhSuccess != null ? dhSuccess : passed); resp.setErrCode(dhCode); resp.setErrMessage(dhErrMsg); - resp.setData(dhData); - System.out.println("大华同步人员最终返回 - success:" + resp.isSuccess() + ", errCode:" + resp.getErrCode() + ", errMessage:" + resp.getErrMessage() + ", data(dhData):" + dhData); + Map resultData = new HashMap<>(); + resultData.put("personId", personId); + resultData.put("dhData", dhData); + resp.setData(resultData); + System.out.println("大华同步人员最终返回 - success:" + resp.isSuccess() + ", errCode:" + resp.getErrCode() + ", errMessage:" + resp.getErrMessage() + ", personId:" + personId + ", dhData:" + dhData); return resp; } diff --git a/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java b/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java index 4b01178..2080740 100644 --- a/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java +++ b/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java @@ -168,8 +168,14 @@ public class DaHuaGatewayImpl implements DaHuaGateway { resultMap.put("errMsg", dhErrMsg); resultMap.put("result", dhResultObj); resultMap.put("dhData", dhData); - System.out.println("大华同步人员返回dhData: " + dhData); - if (!passed) { + System.out.println("==========[大华同步人员返回 dhData START]=========="); + System.out.println(JSONUtil.toJsonPrettyStr(dhData)); + System.out.println("==========[大华同步人员返回 dhData END]============"); + log.info("大华同步人员返回dhData: {}", JSONUtil.toJsonStr(dhData)); + if (passed) { + log.info("大华同步人员成功 - code={}, dhData={}", dhCode, JSONUtil.toJsonStr(dhData)); + System.out.println("大华同步人员成功: code=" + dhCode + ", dhData=" + JSONUtil.toJsonPrettyStr(dhData)); + } else { log.error("大华同步人员失败: code={}, errMsg={}, response={}", dhCode, dhErrMsg, responseJson); System.out.println("大华同步人员失败: code=" + dhCode + ", errMsg=" + dhErrMsg); } From 9502b52bf6d95eda665dfc3384a050bc30ca97ed Mon Sep 17 00:00:00 2001 From: shenzhidan Date: Wed, 29 Jul 2026 16:52:12 +0800 Subject: [PATCH 2/8] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=A4=A7=E5=8D=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primeport/command/DaHuaPersonSyncExe.java | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java index 62d113e..59d3547 100644 --- a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java +++ b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java @@ -1,10 +1,10 @@ package com.zcloud.primeport.command; import com.alibaba.cola.exception.BizException; -import com.zcloud.gbscommon.dahua.cmd.DaHuaPersonSyncCmd; 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; import com.zcloud.primeport.domain.model.PersonApplyE; import com.zcloud.primeport.domain.model.XgfApplyPersonE; import com.zcloud.primeport.dto.PersonApplyUpdateCmd; @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; /** - * 相关方及临时访客人员同步大华平台。 + * 相关方人员同步大华平台。 */ @Slf4j @Component @@ -28,7 +28,6 @@ import java.util.Map; public class DaHuaPersonSyncExe { private static final int RELATED_PARTY = 3; - private static final int TEMPORARY_VISITOR = 4; private final DaHuaGateway daHuaGateway; private final PersonApplyGateway personApplyGateway; @@ -37,11 +36,11 @@ public class DaHuaPersonSyncExe { private String fileUrl; /** - * 相关方及临时访客人员审核通过后,按证件号判断新增或更新大华人员。 + * 相关方人员审核通过后,按证件号判断新增或更新大华人员。 */ public void syncApprovedPersons(Long applyId) { XgfApplyPersonE apply = personApplyGateway.getXgfApplyPersonById(applyId); - if (apply == null || !isDahuaSyncPerson(apply.getPersonBelongType())) { + if (apply == null || !Integer.valueOf(RELATED_PARTY).equals(apply.getPersonBelongType())) { return; } List persons = personApplyGateway.personListByxgfApplyPersonId(applyId); @@ -53,7 +52,7 @@ public class DaHuaPersonSyncExe { Long dahuaPersonId = daHuaGateway.findPersonIdByPaperNumber(paperNumber); DaHuaPersonSyncCmd syncCmd = buildSyncCmd(dahuaPersonId, person.getEmployeePersonUserName(), paperNumber, person.getUserPhone(), person.getUserFaceUrl(), - apply.getVisitStartTime(), apply.getVisitEndTime(), person.getPersonCorpId()); + apply.getVisitStartTime(), apply.getVisitEndTime()); Map result; if (dahuaPersonId == null) { syncCmd.setId(daHuaGateway.generatePersonId()); @@ -66,10 +65,10 @@ public class DaHuaPersonSyncExe { } /** - * 相关方及临时访客人员信息修改后,同步更新大华人员。 + * 相关方人员信息修改后,同步更新大华人员。 */ public void syncUpdatedPerson(PersonApplyE original, PersonApplyUpdateCmd updated) { - if (original == null || !isDahuaSyncPerson(updated.getPersonBelongType())) { + if (original == null || !Integer.valueOf(RELATED_PARTY).equals(updated.getPersonBelongType())) { return; } String originalPaperNumber = decodeUserCard(original.getUserCard()); @@ -80,12 +79,12 @@ public class DaHuaPersonSyncExe { String updatedPaperNumber = decodeUserCard(updated.getUserCard()); DaHuaPersonSyncCmd syncCmd = buildSyncCmd(dahuaPersonId, updated.getEmployeePersonUserName(), updatedPaperNumber, updated.getUserPhone(), updated.getUserFaceUrl(), - updated.getVisitStartTime(), updated.getVisitEndTime(), updated.getPersonCorpId()); + updated.getVisitStartTime(), updated.getVisitEndTime()); checkResult(daHuaGateway.updatePerson(syncCmd), "修改大华人员失败"); } /** - * 删除相关方及临时访客人员时,同步删除对应的大华人员。 + * 删除相关方人员时,同步删除对应的大华人员。 */ public void syncDeletedPersons(List persons) { if (persons == null || persons.isEmpty()) { @@ -94,7 +93,7 @@ public class DaHuaPersonSyncExe { List dahuaPersonIds = new ArrayList<>(); for (PersonApplyE person : persons) { XgfApplyPersonE apply = personApplyGateway.getXgfApplyPersonById(person.getXgfApplyPersonId()); - if (apply == null || !isDahuaSyncPerson(apply.getPersonBelongType())) { + if (apply == null || !Integer.valueOf(RELATED_PARTY).equals(apply.getPersonBelongType())) { continue; } Long dahuaPersonId = daHuaGateway.findPersonIdByPaperNumber(decodeUserCard(person.getUserCard())); @@ -108,7 +107,7 @@ public class DaHuaPersonSyncExe { } private DaHuaPersonSyncCmd buildSyncCmd(Long id, String name, String paperNumber, String phone, - String faceUrl, String startTime, String endTime, Long corpId) { + String faceUrl, String startTime, String endTime) { DaHuaPersonSyncCmd cmd = new DaHuaPersonSyncCmd(); cmd.setService("evo-thirdParty"); cmd.setId(id); @@ -116,11 +115,7 @@ public class DaHuaPersonSyncExe { cmd.setCode("hbqa" + paperNumber); cmd.setPaperType(111); cmd.setPaperNumber(paperNumber); - Long dahuaDeptId = daHuaGateway.findDahuaDepartmentIdByCorpId(corpId); - if (dahuaDeptId == null) { - throw new BizException("未找到大华部门映射配置, corpId=" + corpId); - } - cmd.setDepartmentId(dahuaDeptId); + cmd.setDepartmentId(1L); cmd.setDepartmentType(2); cmd.setType(3); cmd.setPhone(phone); @@ -130,18 +125,19 @@ public class DaHuaPersonSyncExe { DaHuaPersonSyncCmd.PersonBiosignature face = new DaHuaPersonSyncCmd.PersonBiosignature(); face.setType(3); face.setIndex(1); + // 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("人员头像不能为空"); + throw new BizException("相关方人员头像不能为空"); } if (fileUrl == null || fileUrl.trim().isEmpty()) { throw new BizException("文件访问地址未配置"); @@ -154,14 +150,14 @@ public class DaHuaPersonSyncExe { try { String faceBase64 = Base64Util.urlToBase64(imageUrl); if (faceBase64 == null || faceBase64.trim().isEmpty()) { - throw new BizException("人员头像转换失败"); + throw new BizException("相关方人员头像转换失败"); } return faceBase64; } catch (BizException e) { throw e; } catch (Exception e) { - log.error("获取人员头像失败, imageUrl={}", imageUrl, e); - throw new BizException("获取人员头像失败"); + log.error("获取相关方人员头像失败, imageUrl={}", imageUrl, e); + throw new BizException("获取相关方人员头像失败"); } } @@ -169,11 +165,6 @@ public class DaHuaPersonSyncExe { return path.startsWith("/") ? path.substring(1) : path; } - private boolean isDahuaSyncPerson(Integer personBelongType) { - return Integer.valueOf(RELATED_PARTY).equals(personBelongType) - || Integer.valueOf(TEMPORARY_VISITOR).equals(personBelongType); - } - private String decodeUserCard(String userCard) { try { return Base64.decodeToString(userCard); @@ -188,4 +179,4 @@ public class DaHuaPersonSyncExe { throw new BizException(message + (errorMessage == null ? "" : ": " + errorMessage)); } } -} \ No newline at end of file +} From 04f9106abd798eccc194e8cbfe3b59865fee9b01 Mon Sep 17 00:00:00 2001 From: shenzhidan Date: Tue, 28 Jul 2026 17:08:43 +0800 Subject: [PATCH 3/8] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E8=BD=A6?= =?UTF-8?q?=E8=BE=86=E4=BA=BA=E5=91=98=E5=90=8C=E6=AD=A5=E5=A4=A7=E5=8D=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/gateway/DaHuaGateway.java | 17 +- .../primeport/dahua/api/DaHuaPersonApi.java | 37 +- .../gatewayimpl/DaHuaGatewayImpl.java | 600 +----------------- 3 files changed, 16 insertions(+), 638 deletions(-) diff --git a/web-domain/src/main/java/com/zcloud/primeport/domain/gateway/DaHuaGateway.java b/web-domain/src/main/java/com/zcloud/primeport/domain/gateway/DaHuaGateway.java index b4c6751..b050a09 100644 --- a/web-domain/src/main/java/com/zcloud/primeport/domain/gateway/DaHuaGateway.java +++ b/web-domain/src/main/java/com/zcloud/primeport/domain/gateway/DaHuaGateway.java @@ -1,10 +1,9 @@ package com.zcloud.primeport.domain.gateway; -import com.zcloud.gbscommon.dahua.cmd.DaHuaAccessRecordCmd; -import com.zcloud.gbscommon.dahua.cmd.DaHuaCarAddCmd; -import com.zcloud.gbscommon.dahua.cmd.DaHuaCarPageCmd; -import com.zcloud.gbscommon.dahua.cmd.DaHuaPersonSyncCmd; -import com.zcloud.gbscommon.dahua.cmd.DaHuaTempVehicleSaveCmd; +import com.zcloud.primeport.domain.model.DaHuaAccessRecordCmd; +import com.zcloud.primeport.domain.model.DaHuaCarAddCmd; +import com.zcloud.primeport.domain.model.DaHuaCarPageCmd; +import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd; import java.util.List; import java.util.Map; @@ -30,10 +29,4 @@ public interface DaHuaGateway { Map deleteCar(List carNumList); Map queryAccessRecord(DaHuaAccessRecordCmd cmd); - - String uploadPersonImg(String imageBase64); - - Map saveTempVehicle(DaHuaTempVehicleSaveCmd cmd); - - Long findDahuaDepartmentIdByCorpId(Long corpId); -} \ No newline at end of file +} diff --git a/web-infrastructure/src/main/java/com/zcloud/primeport/dahua/api/DaHuaPersonApi.java b/web-infrastructure/src/main/java/com/zcloud/primeport/dahua/api/DaHuaPersonApi.java index 8109f7a..287f346 100644 --- a/web-infrastructure/src/main/java/com/zcloud/primeport/dahua/api/DaHuaPersonApi.java +++ b/web-infrastructure/src/main/java/com/zcloud/primeport/dahua/api/DaHuaPersonApi.java @@ -25,9 +25,6 @@ public class DaHuaPersonApi { private static final String CAR_PAGE_URL = "/evo-apigw/evo-brm/1.2.0/car/subsystem/page"; private static final String CAR_DELETE_URL = "/evo-apigw/evo-brm/1.0.0/car/delete"; private static final String ACCESS_RECORD_URL = "/evo-apigw/evo-accesscontrol/1.0.0/card/accessControl/swingCardRecord/bycondition/combined"; - private static final String PERSON_UPLOAD_IMG_URL = "/evo-apigw/evo-brm/1.0.0/person/subsystem/third/upload/img"; - private static final String PERSON_SAVE_ALL_URL = "/evo-apigw/evo-brm/1.2.0/person/subsystem/save-person-all"; - private static final String TEMP_VEHICLE_AUDIT_SAVE_URL = "/evo-apigw/evo-brm/1.2.0/person/subsystem/temp-vehicle/audit-save"; public boolean isConfigured() { return daHuaApiClient != null; @@ -134,36 +131,4 @@ public class DaHuaPersonApi { headers.put("Authorization", "bearer " + token); return daHuaApiClient.postJson(ACCESS_RECORD_URL, body, headers); } - - public GeneralResponse uploadPersonImg(String imageBase64) throws ClientException { - if (daHuaApiClient == null) { - return null; - } - String token = daHuaApiClient.getToken(); - Map headers = new HashMap<>(); - headers.put("Authorization", "bearer " + token); - Map body = new HashMap<>(); - body.put("imageBase64", imageBase64); - return daHuaApiClient.postJson(PERSON_UPLOAD_IMG_URL, body, headers); - } - - public GeneralResponse savePersonAll(Map body) throws ClientException { - if (daHuaApiClient == null) { - return null; - } - String token = daHuaApiClient.getToken(); - Map headers = new HashMap<>(); - headers.put("Authorization", "bearer " + token); - return daHuaApiClient.postJson(PERSON_SAVE_ALL_URL, body, headers); - } - - public GeneralResponse saveTempVehicleAudit(Map body) throws ClientException { - if (daHuaApiClient == null) { - return null; - } - String token = daHuaApiClient.getToken(); - Map headers = new HashMap<>(); - headers.put("Authorization", "bearer " + token); - return daHuaApiClient.postJson(TEMP_VEHICLE_AUDIT_SAVE_URL, body, headers); - } -} \ No newline at end of file +} diff --git a/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java b/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java index 2080740..fe5f5a6 100644 --- a/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java +++ b/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java @@ -1,27 +1,21 @@ package com.zcloud.primeport.gatewayimpl; -import cn.hutool.http.HttpRequest; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.dahuatech.icc.exception.ClientException; import com.dahuatech.icc.oauth.model.v202010.GeneralResponse; import com.zcloud.primeport.dahua.api.DaHuaPersonApi; import com.zcloud.primeport.domain.gateway.DaHuaGateway; -import com.zcloud.gbscommon.dahua.cmd.DaHuaAccessRecordCmd; -import com.zcloud.gbscommon.dahua.cmd.DaHuaCarAddCmd; -import com.zcloud.gbscommon.dahua.cmd.DaHuaCarPageCmd; -import com.zcloud.gbscommon.dahua.cmd.DaHuaPersonSyncCmd; -import com.zcloud.gbscommon.dahua.cmd.DaHuaTempVehicleSaveCmd; -import com.zcloud.primeport.persistence.dataobject.DaHuaDepartmentCorpMappingDO; -import com.zcloud.primeport.persistence.repository.DaHuaDepartmentCorpMappingRepository; +import com.zcloud.primeport.domain.model.DaHuaAccessRecordCmd; +import com.zcloud.primeport.domain.model.DaHuaCarAddCmd; +import com.zcloud.primeport.domain.model.DaHuaCarPageCmd; +import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,9 +27,6 @@ public class DaHuaGatewayImpl implements DaHuaGateway { @Autowired(required = false) private DaHuaPersonApi daHuaPersonApi; - @Autowired - private DaHuaDepartmentCorpMappingRepository daHuaDeptMappingRepository; - @Override public Long generatePersonId() { if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { @@ -108,17 +99,9 @@ public class DaHuaGatewayImpl implements DaHuaGateway { if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { throw new RuntimeException("大华服务未配置"); } - Map uploadResult = uploadAndSetPersonBiosignaturePaths(cmd); - if (uploadResult != null) { - return uploadResult; - } Map body = convertToMap(cmd); - processDaHuaPersonBiosignatures(body); - System.out.println("==========[syncPerson 完整请求参数 START]=========="); - System.out.println(JSONUtil.toJsonPrettyStr(body)); - debugPrintPersonBiosignatures(body); - System.out.println("==========[syncPerson 完整请求参数 END]============"); log.info("大华同步人员请求参数: {}", JSONUtil.toJsonStr(body)); + System.out.println("大华同步人员请求参数: " + JSONUtil.toJsonStr(body)); Map resultMap = new HashMap<>(); try { GeneralResponse response = daHuaPersonApi.addPerson(body); @@ -131,51 +114,20 @@ public class DaHuaGatewayImpl implements DaHuaGateway { resultMap.put("success", false); resultMap.put("code", "SYSTEM_ERROR"); resultMap.put("errMsg", "response为null"); - resultMap.put("dhData", null); return resultMap; } JSONObject jsonObject = JSONUtil.parseObj(responseJson); Boolean dhSuccess = jsonObject.getBool("success", false); String dhCode = jsonObject.getStr("code", response.getCode()); String dhErrMsg = jsonObject.getStr("errMsg", ""); - Object dhResultObj = jsonObject.get("result"); - Object dhData = jsonObject.get("data"); - if (dhResultObj != null) { - try { - JSONObject bizObj; - if (dhResultObj instanceof String) { - bizObj = JSONUtil.parseObj((String) dhResultObj); - } else if (dhResultObj instanceof JSONObject) { - bizObj = (JSONObject) dhResultObj; - } else { - bizObj = JSONUtil.parseObj(JSONUtil.toJsonStr(dhResultObj)); - } - dhSuccess = bizObj.getBool("success", dhSuccess); - dhCode = bizObj.getStr("code", dhCode); - dhErrMsg = bizObj.getStr("errMsg", dhErrMsg); - Object tmpData = bizObj.get("data"); - if (tmpData != null) { - dhData = tmpData; - } - } catch (Exception e) { - log.warn("大华同步人员解析result字段失败: {}", e.getMessage()); - } - } + String dhResult = jsonObject.getStr("result", ""); boolean passed = "0".equals(dhCode); resultMap.put("passed", passed); resultMap.put("success", dhSuccess); resultMap.put("code", dhCode); resultMap.put("errMsg", dhErrMsg); - resultMap.put("result", dhResultObj); - resultMap.put("dhData", dhData); - System.out.println("==========[大华同步人员返回 dhData START]=========="); - System.out.println(JSONUtil.toJsonPrettyStr(dhData)); - System.out.println("==========[大华同步人员返回 dhData END]============"); - log.info("大华同步人员返回dhData: {}", JSONUtil.toJsonStr(dhData)); - if (passed) { - log.info("大华同步人员成功 - code={}, dhData={}", dhCode, JSONUtil.toJsonStr(dhData)); - System.out.println("大华同步人员成功: code=" + dhCode + ", dhData=" + JSONUtil.toJsonPrettyStr(dhData)); - } else { + resultMap.put("result", dhResult); + if (!passed) { log.error("大华同步人员失败: code={}, errMsg={}, response={}", dhCode, dhErrMsg, responseJson); System.out.println("大华同步人员失败: code=" + dhCode + ", errMsg=" + dhErrMsg); } @@ -186,7 +138,6 @@ public class DaHuaGatewayImpl implements DaHuaGateway { resultMap.put("success", false); resultMap.put("code", "CLIENT_EXCEPTION"); resultMap.put("errMsg", e.getMessage()); - resultMap.put("dhData", null); return resultMap; } } @@ -204,17 +155,9 @@ public class DaHuaGatewayImpl implements DaHuaGateway { emptyMap.put("errMsg", "id不能为空"); return emptyMap; } - Map uploadResult = uploadAndSetPersonBiosignaturePaths(cmd); - if (uploadResult != null) { - return uploadResult; - } Map body = convertToMap(cmd); - processDaHuaPersonBiosignatures(body); - System.out.println("==========[updatePerson 完整请求参数 START]=========="); - System.out.println(JSONUtil.toJsonPrettyStr(body)); - debugPrintPersonBiosignatures(body); - System.out.println("==========[updatePerson 完整请求参数 END]============"); log.info("大华修改人员请求参数: {}", JSONUtil.toJsonStr(body)); + System.out.println("大华修改人员请求参数: " + JSONUtil.toJsonStr(body)); Map resultMap = new HashMap<>(); try { GeneralResponse response = daHuaPersonApi.updatePerson(body); @@ -272,215 +215,6 @@ public class DaHuaGatewayImpl implements DaHuaGateway { return map; } - private static String getStr(Map m, String key) { - Object v = m.get(key); - return v == null ? null : v.toString(); - } - - private static String onlyPureBase64(String raw) { - if (raw == null) return null; - String s = raw.trim(); - if (s.isEmpty()) return s; - int comma = s.indexOf(','); - if (comma > 0 && comma < 100) { - String prefix = s.substring(0, comma).toLowerCase(); - if (prefix.startsWith("data:") && prefix.contains("base64")) { - s = s.substring(comma + 1).trim(); - } - } - return s.replaceAll("\\s+", ""); - } - - private static boolean isHttpUrl(String s) { - if (s == null) return false; - String low = s.toLowerCase().trim(); - return low.startsWith("http://") || low.startsWith("https://"); - } - - private static boolean looksLikeBase64(String s) { - if (s == null || s.length() < 50) return false; - String t = s.trim(); - if (t.startsWith("data:")) return true; - int ok = 0; - int check = Math.min(t.length(), 200); - for (int i = 0; i < check; i++) { - char c = t.charAt(i); - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') - || c == '+' || c == '/' || c == '=') ok++; - } - return ((double) ok / check) > 0.95; - } - - private static byte[] downloadUrlBytes(String url) { - return HttpRequest.get(url).timeout(15000).execute().bodyBytes(); - } - - private static String detectMimePrefix(byte[] bytes) { - if (bytes == null || bytes.length < 4) return "data:image/jpeg;base64,"; - if (bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xD8 && bytes[2] == (byte) 0xFF) { - return "data:image/jpeg;base64,"; - } - if (bytes.length >= 8 - && bytes[0] == (byte) 0x89 - && bytes[1] == (byte) 0x50 - && bytes[2] == (byte) 0x4E - && bytes[3] == (byte) 0x47 - && bytes[4] == (byte) 0x0D - && bytes[5] == (byte) 0x0A - && bytes[6] == (byte) 0x1A - && bytes[7] == (byte) 0x0A) { - return "data:image/png;base64,"; - } - return "data:image/jpeg;base64,"; - } - - @SuppressWarnings("unchecked") - private static void debugPrintPersonBiosignatures(Map body) { - Object bios = body.get("personBiosignatures"); - if (bios == null || !(bios instanceof List)) { - System.out.println("[DEBUG] personBiosignatures 字段: 不存在或不是List"); - return; - } - List list = (List) bios; - System.out.println("[DEBUG] personBiosignatures 数量: " + list.size()); - for (int i = 0; i < list.size(); i++) { - Object item = list.get(i); - System.out.println("[DEBUG] --- 第 " + (i + 1) + " 条 ---"); - if (item instanceof Map) { - Map m = (Map) item; - System.out.println("[DEBUG] 所有字段 keys: " + String.join(", ", m.keySet())); - for (Map.Entry e : m.entrySet()) { - Object v = e.getValue(); - if (v == null) { - System.out.println("[DEBUG] " + e.getKey() + " = null"); - } else { - String s = v.toString(); - String show = s.length() > 120 ? s.substring(0, 120) + "...(len=" + s.length() + ")" : s; - System.out.println("[DEBUG] " + e.getKey() + " = " + show); - } - } - } else { - System.out.println("[DEBUG] 类型不是Map, 是: " + (item == null ? "null" : item.getClass().getName())); - } - } - } - - @SuppressWarnings("unchecked") - private void processDaHuaPersonBiosignatures(Map body) { - Object bios = body.get("personBiosignatures"); - if (bios == null || !(bios instanceof List)) return; - List inList = (List) bios; - List> outList = new ArrayList<>(); - int seq = 0; - for (Object item : inList) { - seq++; - Object rawType = null; - Object rawIndex = null; - String path = null; - String rawBase64 = null; - - if (item instanceof Map) { - Map mm = (Map) item; - rawType = mm.get("type"); - rawIndex = mm.get("index"); - path = getStr(mm, "path"); - rawBase64 = getStr(mm, "base64Data"); - if (rawBase64 == null) rawBase64 = getStr(mm, "data"); - } else if (item instanceof DaHuaPersonSyncCmd.PersonBiosignature) { - DaHuaPersonSyncCmd.PersonBiosignature b = (DaHuaPersonSyncCmd.PersonBiosignature) item; - rawType = b.getType(); - rawIndex = b.getIndex(); - path = b.getPath(); - rawBase64 = b.getBase64Data(); - } else { - continue; - } - - Map out = new HashMap<>(); - if (rawType != null) out.put("type", rawType); - if (rawIndex != null) out.put("index", rawIndex); - - String finalBase64WithPrefix = null; - boolean pathAlreadyUploaded = false; - - if (path != null && !path.trim().isEmpty() && !looksLikeBase64(path) && !isHttpUrl(path)) { - pathAlreadyUploaded = true; - out.put("path", path.trim()); - System.out.println("[大华人员同步] seq=" + seq + " path已通过上传接口获取, 直接使用fileUrl=" + path.trim()); - log.info("[大华人员同步] seq={} 使用已上传的图片路径: {}", seq, path.trim()); - } else { - out.put("path", ""); - - if (rawBase64 != null && !rawBase64.trim().isEmpty()) { - String t = rawBase64.trim(); - if (t.toLowerCase().startsWith("data:")) { - finalBase64WithPrefix = t.replaceAll("\\s+", ""); - System.out.println("[大华人员同步] seq=" + seq + " base64Data已带前缀, 直接使用, len=" + finalBase64WithPrefix.length()); - } else { - String pure = t.replaceAll("\\s+", ""); - if (!pure.isEmpty()) { - finalBase64WithPrefix = "data:image/jpeg;base64," + pure; - System.out.println("[大华人员同步] seq=" + seq + " base64Data无前缀, 默认补jpeg前缀, len=" + finalBase64WithPrefix.length()); - } - } - } - if ((finalBase64WithPrefix == null || finalBase64WithPrefix.isEmpty()) - && path != null && !path.trim().isEmpty()) { - String p = path.trim(); - if (isHttpUrl(p)) { - System.out.println("[大华人员同步] seq=" + seq + " 下载图片URL=" + p); - try { - byte[] bytes = downloadUrlBytes(p); - if (bytes != null && bytes.length > 0) { - String mimePrefix = detectMimePrefix(bytes); - String pure = Base64.getEncoder().encodeToString(bytes); - finalBase64WithPrefix = mimePrefix + pure; - System.out.println("[大华人员同步] seq=" + seq + " 下载成功, mime=" - + (mimePrefix.contains("png") ? "png" : "jpeg") - + ", totalLen=" + finalBase64WithPrefix.length()); - } else { - System.err.println("[大华人员同步] seq=" + seq + " 下载失败(返回空)"); - } - } catch (Exception e) { - System.err.println("[大华人员同步] seq=" + seq + " 下载图片异常: " + e.getMessage()); - log.error("下载人脸图片失败, seq={}, url={}, err={}", seq, p, e.getMessage(), e); - } - } else if (looksLikeBase64(p)) { - String t = p.trim(); - if (t.toLowerCase().startsWith("data:")) { - finalBase64WithPrefix = t.replaceAll("\\s+", ""); - System.out.println("[大华人员同步] seq=" + seq + " path是带前缀base64, 转存base64Data, len=" + finalBase64WithPrefix.length()); - } else { - String pure = onlyPureBase64(t); - if (pure != null && !pure.isEmpty()) { - finalBase64WithPrefix = "data:image/jpeg;base64," + pure; - System.out.println("[大华人员同步] seq=" + seq + " path是纯base64, 转存base64Data并补jpeg前缀, len=" + finalBase64WithPrefix.length()); - } - } - } else { - System.out.println("[大华人员同步] seq=" + seq + " path内容: " - + (p.length() > 100 ? p.substring(0, 100) + "..." : p)); - } - } - - if (finalBase64WithPrefix != null && !finalBase64WithPrefix.isEmpty()) { - out.put("base64Data", finalBase64WithPrefix); - System.out.println("[大华人员同步] seq=" + seq + " 最终字段: type=" + out.get("type") - + ", index=" + out.get("index") - + ", path=\"\"(空字符串)" - + ", base64Data前80=" + finalBase64WithPrefix.substring(0, Math.min(80, finalBase64WithPrefix.length())) + "..."); - log.info("[大华人员同步] seq={} 最终: type={}, index={}, path=空串, base64DataLen={}", - seq, out.get("type"), out.get("index"), finalBase64WithPrefix.length()); - } else { - System.out.println("[大华人员同步] seq=" + seq + " 未得到有效base64,字段: type=" + out.get("type") - + ", index=" + out.get("index") + ", path=\"\"(空字符串), 无base64Data"); - } - } - outList.add(out); - } - body.put("personBiosignatures", outList); - } - @Override public Map deletePerson(List ids, Integer openDeleteFlag) { if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { @@ -853,318 +587,4 @@ public class DaHuaGatewayImpl implements DaHuaGateway { return resultMap; } } - - @Override - public String uploadPersonImg(String imageBase64) { - if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { - throw new RuntimeException("大华服务未配置"); - } - if (imageBase64 == null || imageBase64.trim().isEmpty()) { - throw new RuntimeException("图片base64不能为空"); - } - try { - GeneralResponse response = daHuaPersonApi.uploadPersonImg(imageBase64); - String responseJson = JSONUtil.toJsonStr(response); - log.info("大华上传人员图片返回结果: {}", responseJson); - System.out.println("大华上传人员图片返回结果: " + responseJson); - if (response == null) { - throw new RuntimeException("大华上传人员图片失败: response为null"); - } - JSONObject jsonObject = JSONUtil.parseObj(responseJson); - Boolean outerSuccess = jsonObject.getBool("success", false); - String outerCode = jsonObject.getStr("code", ""); - String outerErrMsg = jsonObject.getStr("errMsg", ""); - - Boolean bizSuccess = outerSuccess; - String resultCode = null; - String fileUrl = null; - String bizErrMsg = outerErrMsg; - - Object resultObj = jsonObject.get("result"); - if (resultObj != null) { - try { - JSONObject bizObj; - if (resultObj instanceof String) { - bizObj = JSONUtil.parseObj((String) resultObj); - } else if (resultObj instanceof JSONObject) { - bizObj = (JSONObject) resultObj; - } else { - bizObj = JSONUtil.parseObj(JSONUtil.toJsonStr(resultObj)); - } - bizSuccess = bizObj.getBool("success", bizSuccess); - bizErrMsg = bizObj.getStr("errMsg", bizErrMsg); - Object bizDataObj = bizObj.get("data"); - if (bizDataObj != null) { - JSONObject bizDataJson = JSONUtil.parseObj(bizDataObj); - resultCode = bizDataJson.getStr("result"); - fileUrl = bizDataJson.getStr("fileUrl"); - System.out.println("大华上传人员图片解析result字段成功: resultCode=" + resultCode + ", fileUrl=" + fileUrl); - } - } catch (Exception e) { - log.warn("大华上传人员图片解析result字段失败: {}", e.getMessage()); - System.out.println("大华上传人员图片解析result字段失败: " + e.getMessage()); - } - } - - boolean resultOk = (resultCode == null || resultCode.isEmpty()) || "0".equals(resultCode); - if (!bizSuccess || !resultOk) { - String msg = "大华上传人员图片失败: success=" + bizSuccess + ", result=" + resultCode + ", outerCode=" + outerCode + ", errMsg=" + bizErrMsg; - log.error(msg); - throw new RuntimeException(msg); - } - if (fileUrl == null || fileUrl.trim().isEmpty()) { - throw new RuntimeException("大华上传人员图片失败: 未返回fileUrl"); - } - System.out.println("大华上传人员图片成功, fileUrl=" + fileUrl); - return fileUrl; - } catch (ClientException e) { - log.error("大华上传人员图片异常: {}", e.getMessage(), e); - throw new RuntimeException("大华上传人员图片异常", e); - } - } - - @SuppressWarnings("unchecked") - private Map uploadAndSetPersonBiosignaturePaths(DaHuaPersonSyncCmd cmd) { - List bios = cmd.getPersonBiosignatures(); - if (bios == null || bios.isEmpty()) { - return null; - } - int seq = 0; - for (DaHuaPersonSyncCmd.PersonBiosignature bio : bios) { - seq++; - String base64Data = bio.getBase64Data(); - if (base64Data == null || base64Data.trim().isEmpty()) { - continue; - } - String finalBase64WithPrefix; - String t = base64Data.trim(); - if (t.toLowerCase().startsWith("data:")) { - finalBase64WithPrefix = t.replaceAll("\\s+", ""); - } else { - String pure = t.replaceAll("\\s+", ""); - if (pure.isEmpty()) { - continue; - } - finalBase64WithPrefix = "data:image/jpeg;base64," + pure; - } - System.out.println("[大华人员图片上传] seq=" + seq + " 开始上传图片, base64长度=" + finalBase64WithPrefix.length()); - try { - String fileUrl = uploadPersonImg(finalBase64WithPrefix); - bio.setPath(fileUrl); - System.out.println("[大华人员图片上传] seq=" + seq + " 上传成功, path=" + fileUrl); - } catch (Exception e) { - log.error("[大华人员图片上传] seq=" + seq + " 上传失败: {}", e.getMessage(), e); - System.err.println("[大华人员图片上传] seq=" + seq + " 上传失败: " + e.getMessage()); - Map resultMap = new HashMap<>(); - resultMap.put("passed", false); - resultMap.put("success", false); - resultMap.put("code", "IMG_UPLOAD_FAIL"); - resultMap.put("errMsg", "第" + seq + "张人脸图片上传失败: " + e.getMessage()); - resultMap.put("dhData", null); - return resultMap; - } - } - return null; - } - - @Override - public Map saveTempVehicle(DaHuaTempVehicleSaveCmd cmd) { - if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { - throw new RuntimeException("大华服务未配置"); - } - if (cmd.getId() == null) { - Long personId = generatePersonId(); - System.out.println("大华临时车辆全量保存自动生成人员ID: " + personId); - cmd.setId(personId); - } - if (cmd.getService() == null || cmd.getService().trim().isEmpty()) { - cmd.setService("evo-thirdParty"); - } - Map uploadResult = uploadAndSetTempVehicleBiosignaturePaths(cmd); - if (uploadResult != null) { - return uploadResult; - } - Map body = convertToMap(cmd); - processTempVehicleBiosignatures(body); - System.out.println("==========[saveTempVehicle 完整请求参数 START]=========="); - System.out.println(JSONUtil.toJsonPrettyStr(body)); - log.info("大华临时车辆全量保存请求参数: {}", JSONUtil.toJsonStr(body)); - Map resultMap = new HashMap<>(); - try { - GeneralResponse response = daHuaPersonApi.saveTempVehicleAudit(body); - String responseJson = JSONUtil.toJsonStr(response); - log.info("大华临时车辆全量保存返回结果: {}", responseJson); - System.out.println("大华临时车辆全量保存返回结果: " + responseJson); - if (response == null) { - log.error("大华临时车辆全量保存失败: response为null"); - resultMap.put("passed", false); - resultMap.put("success", false); - resultMap.put("code", "SYSTEM_ERROR"); - resultMap.put("errMsg", "response为null"); - resultMap.put("dhData", null); - return resultMap; - } - JSONObject jsonObject = JSONUtil.parseObj(responseJson); - Boolean dhSuccess = jsonObject.getBool("success", false); - String dhCode = jsonObject.getStr("code", response.getCode()); - String dhErrMsg = jsonObject.getStr("errMsg", ""); - Object dhResultObj = jsonObject.get("result"); - Object dhData = jsonObject.get("data"); - if (dhResultObj != null) { - try { - JSONObject bizObj; - if (dhResultObj instanceof String) { - bizObj = JSONUtil.parseObj((String) dhResultObj); - } else if (dhResultObj instanceof JSONObject) { - bizObj = (JSONObject) dhResultObj; - } else { - bizObj = JSONUtil.parseObj(JSONUtil.toJsonStr(dhResultObj)); - } - dhSuccess = bizObj.getBool("success", dhSuccess); - dhCode = bizObj.getStr("code", dhCode); - dhErrMsg = bizObj.getStr("errMsg", dhErrMsg); - Object tmpData = bizObj.get("data"); - if (tmpData != null) { - dhData = tmpData; - } - } catch (Exception e) { - log.warn("大华临时车辆全量保存解析result字段失败: {}", e.getMessage()); - } - } - boolean passed = "0".equals(dhCode); - resultMap.put("passed", passed); - resultMap.put("success", dhSuccess); - resultMap.put("code", dhCode); - resultMap.put("errMsg", dhErrMsg); - resultMap.put("result", dhResultObj); - resultMap.put("dhData", dhData); - System.out.println("大华临时车辆全量保存返回dhData: " + dhData); - if (!passed) { - log.error("大华临时车辆全量保存失败: code={}, errMsg={}, response={}", dhCode, dhErrMsg, responseJson); - System.out.println("大华临时车辆全量保存失败: code=" + dhCode + ", errMsg=" + dhErrMsg); - } - return resultMap; - } catch (ClientException e) { - log.error("大华临时车辆全量保存异常: {}", e.getMessage(), e); - resultMap.put("passed", false); - resultMap.put("success", false); - resultMap.put("code", "CLIENT_EXCEPTION"); - resultMap.put("errMsg", e.getMessage()); - resultMap.put("dhData", null); - return resultMap; - } - } - - @SuppressWarnings("unchecked") - private Map uploadAndSetTempVehicleBiosignaturePaths(DaHuaTempVehicleSaveCmd cmd) { - List bios = cmd.getPersonBiosignatures(); - if (bios == null || bios.isEmpty()) { - return null; - } - int seq = 0; - for (DaHuaTempVehicleSaveCmd.PersonBiosignature bio : bios) { - seq++; - String base64Data = bio.getBase64Data(); - if (base64Data == null || base64Data.trim().isEmpty()) { - continue; - } - String finalBase64WithPrefix; - String t = base64Data.trim(); - if (t.toLowerCase().startsWith("data:")) { - finalBase64WithPrefix = t.replaceAll("\\s+", ""); - } else { - String pure = t.replaceAll("\\s+", ""); - if (pure.isEmpty()) { - continue; - } - finalBase64WithPrefix = "data:image/jpeg;base64," + pure; - } - System.out.println("[大华临时车辆图片上传] seq=" + seq + " 开始上传图片, base64长度=" + finalBase64WithPrefix.length()); - try { - String fileUrl = uploadPersonImg(finalBase64WithPrefix); - bio.setPath(fileUrl); - bio.setBase64Data(null); - System.out.println("[大华临时车辆图片上传] seq=" + seq + " 上传成功, path=" + fileUrl); - } catch (Exception e) { - log.error("[大华临时车辆图片上传] seq=" + seq + " 上传失败: {}", e.getMessage(), e); - System.err.println("[大华临时车辆图片上传] seq=" + seq + " 上传失败: " + e.getMessage()); - Map resultMap = new HashMap<>(); - resultMap.put("passed", false); - resultMap.put("success", false); - resultMap.put("code", "IMG_UPLOAD_FAIL"); - resultMap.put("errMsg", "第" + seq + "张人脸图片上传失败: " + e.getMessage()); - resultMap.put("dhData", null); - return resultMap; - } - } - return null; - } - - @SuppressWarnings("unchecked") - private void processTempVehicleBiosignatures(Map body) { - Object bios = body.get("personBiosignatures"); - if (bios == null || !(bios instanceof List)) return; - List inList = (List) bios; - List> outList = new ArrayList<>(); - for (Object item : inList) { - Map out = new HashMap<>(); - if (item instanceof Map) { - Map mm = (Map) item; - if (mm.get("type") != null) out.put("type", mm.get("type")); - if (mm.get("index") != null) out.put("index", mm.get("index")); - Object path = mm.get("path"); - if (path != null && !path.toString().trim().isEmpty()) { - out.put("path", path.toString().trim()); - } else { - out.put("path", ""); - } - Object base64Data = mm.get("base64Data"); - if (base64Data != null && !base64Data.toString().trim().isEmpty()) { - String s = base64Data.toString().trim(); - if (!s.toLowerCase().startsWith("data:")) { - s = "data:image/jpeg;base64," + s.replaceAll("\\s+", ""); - } - out.put("base64Data", s); - } - Object data = mm.get("data"); - if (data != null && !data.toString().trim().isEmpty()) { - out.put("data", data); - } - } else if (item instanceof DaHuaTempVehicleSaveCmd.PersonBiosignature) { - DaHuaTempVehicleSaveCmd.PersonBiosignature b = (DaHuaTempVehicleSaveCmd.PersonBiosignature) item; - if (b.getType() != null) out.put("type", b.getType()); - if (b.getIndex() != null) out.put("index", b.getIndex()); - if (b.getPath() != null && !b.getPath().trim().isEmpty()) { - out.put("path", b.getPath().trim()); - } else { - out.put("path", ""); - } - if (b.getBase64Data() != null && !b.getBase64Data().trim().isEmpty()) { - String s = b.getBase64Data().trim(); - if (!s.toLowerCase().startsWith("data:")) { - s = "data:image/jpeg;base64," + s.replaceAll("\\s+", ""); - } - out.put("base64Data", s); - } - if (b.getData() != null && !b.getData().trim().isEmpty()) { - out.put("data", b.getData()); - } - } - outList.add(out); - } - body.put("personBiosignatures", outList); - } - - @Override - public Long findDahuaDepartmentIdByCorpId(Long corpId) { - if (corpId == null) { - return null; - } - DaHuaDepartmentCorpMappingDO mapping = daHuaDeptMappingRepository.findByCorpId(corpId); - if (mapping == null) { - log.warn("未找到大华部门映射配置, corpId={}", corpId); - return null; - } - return mapping.getDahuaDepartmentId(); - } -} \ No newline at end of file +} From 56e01d59b49bccf50b550bfc2005723621f68c77 Mon Sep 17 00:00:00 2001 From: shenzhidan Date: Tue, 28 Jul 2026 17:43:58 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=B9=E4=BA=BA=E5=91=98=E8=BD=A6=E8=BE=86=E5=A4=A7=E5=8D=8E?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=89=A7=E8=A1=8C=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primeport/command/DaHuaPersonSyncExe.java | 48 ++----------------- .../command/DaHuaVehicleSyncExe.java | 19 ++++---- 2 files changed, 11 insertions(+), 56 deletions(-) diff --git a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java index 59d3547..fad793b 100644 --- a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java +++ b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java @@ -1,7 +1,6 @@ package com.zcloud.primeport.command; import com.alibaba.cola.exception.BizException; -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; @@ -9,9 +8,7 @@ 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.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -22,9 +19,8 @@ import java.util.Map; /** * 相关方人员同步大华平台。 */ -@Slf4j @Component -@RequiredArgsConstructor +@AllArgsConstructor public class DaHuaPersonSyncExe { private static final int RELATED_PARTY = 3; @@ -32,9 +28,6 @@ public class DaHuaPersonSyncExe { private final DaHuaGateway daHuaGateway; private final PersonApplyGateway personApplyGateway; - @Value("${file.url:}") - private String fileUrl; - /** * 相关方人员审核通过后,按证件号判断新增或更新大华人员。 */ @@ -125,46 +118,11 @@ public class DaHuaPersonSyncExe { DaHuaPersonSyncCmd.PersonBiosignature face = new DaHuaPersonSyncCmd.PersonBiosignature(); face.setType(3); face.setIndex(1); - // userFaceUrl 是文件服务器相对路径,读取图片并转换为 Base64 后交给大华网关。 - face.setBase64Data(resolveFaceBase64(faceUrl)); + face.setPath(faceUrl); cmd.setPersonBiosignatures(Collections.singletonList(face)); return cmd; } - /** - * 根据文件服务地址读取相关方人员头像并转换为图片 Base64。 - * 大华人员接口的 path 必须是大华图片上传接口返回的 fileUrl,不能直接使用本系统路径。 - */ - private String resolveFaceBase64(String faceUrl) { - if (faceUrl == null || faceUrl.trim().isEmpty()) { - throw new BizException("相关方人员头像不能为空"); - } - 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 { - 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("获取相关方人员头像失败"); - } - } - - private String removeLeadingSlash(String path) { - return path.startsWith("/") ? path.substring(1) : path; - } - private String decodeUserCard(String userCard) { try { return Base64.decodeToString(userCard); diff --git a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaVehicleSyncExe.java b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaVehicleSyncExe.java index d8534a2..5f1ac48 100644 --- a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaVehicleSyncExe.java +++ b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaVehicleSyncExe.java @@ -1,10 +1,10 @@ package com.zcloud.primeport.command; import com.alibaba.cola.exception.BizException; -import com.zcloud.gbscommon.dahua.cmd.DaHuaCarAddCmd; import com.zcloud.primeport.domain.enums.VehicleBelongTypeEnum; import com.zcloud.primeport.domain.gateway.DaHuaGateway; import com.zcloud.primeport.domain.gateway.VehicleApplyGateway; +import com.zcloud.primeport.domain.model.DaHuaCarAddCmd; import com.zcloud.primeport.domain.model.VehicleApplyE; import com.zcloud.primeport.plan.mjDevice.dto.CarEnum; import lombok.AllArgsConstructor; @@ -25,18 +25,18 @@ public class DaHuaVehicleSyncExe { private final VehicleApplyGateway vehicleApplyGateway; /** - * 车辆审核通过后,同步新增大华车辆(所有车辆类型均同步)。 + * 相关方车辆审核通过后,同步新增大华车辆。 */ public void syncApprovedVehicle(Long vehicleApplyId) { VehicleApplyE vehicle = vehicleApplyGateway.getById(vehicleApplyId); - if (vehicle == null) { + if (!isRelatedPartyVehicle(vehicle)) { return; } syncAddedVehicle(vehicle); } /** - * 删除车辆时,同步删除对应的大华车辆(所有车辆类型均同步)。 + * 删除相关方车辆时,同步删除对应的大华车辆。 */ public void syncDeletedVehicles(List vehicles) { if (vehicles == null || vehicles.isEmpty()) { @@ -44,7 +44,7 @@ public class DaHuaVehicleSyncExe { } List carNumList = new ArrayList<>(); for (VehicleApplyE vehicle : vehicles) { - if (vehicle != null && vehicle.getLicenceNo() != null) { + if (isRelatedPartyVehicle(vehicle)) { carNumList.add(vehicle.getLicenceNo()); } } @@ -61,11 +61,8 @@ public class DaHuaVehicleSyncExe { DaHuaCarAddCmd cmd = new DaHuaCarAddCmd(); cmd.setCarNum(vehicle.getLicenceNo()); cmd.setCarNumColor(CarEnum.getMenuKeyByPath(vehicle.getLicenceType())); - Long dahuaDeptId = daHuaGateway.findDahuaDepartmentIdByCorpId(vehicle.getVehicleCorpId()); - if (dahuaDeptId == null) { - throw new BizException("未找到大华部门映射配置, corpId=" + vehicle.getVehicleCorpId()); - } - cmd.setDepartmentId(dahuaDeptId); + // 大华车辆类型与本地字典不一致,该字段可选,不能直接透传本地 vehicleType。 + cmd.setDepartmentId(1L); cmd.setDepartmentName(vehicle.getVehicleDepartmentName()); cmd.setService("evo-thirdParty"); return cmd; @@ -82,4 +79,4 @@ public class DaHuaVehicleSyncExe { throw new BizException(message + (errorMessage == null ? "" : ": " + errorMessage)); } } -} \ No newline at end of file +} From bf0c28806340bc2fd197f05fc2fa9d5b33ea9dd0 Mon Sep 17 00:00:00 2001 From: shenzhidan Date: Wed, 29 Jul 2026 11:03:56 +0800 Subject: [PATCH 5/8] =?UTF-8?q?1.=E4=B8=8A=E4=BC=A0=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primeport/command/DaHuaPersonSyncExe.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java index fad793b..4bbfc78 100644 --- a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java +++ b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java @@ -1,6 +1,10 @@ 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.primeport.domain.gateway.DaHuaGateway; import com.zcloud.primeport.domain.gateway.PersonApplyGateway; import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd; @@ -9,6 +13,7 @@ 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 org.springframework.stereotype.Component; import java.util.ArrayList; @@ -28,6 +33,9 @@ public class DaHuaPersonSyncExe { private final DaHuaGateway daHuaGateway; private final PersonApplyGateway personApplyGateway; + @DubboReference + private ZcloudUserFacade zcloudUserFacade; + /** * 相关方人员审核通过后,按证件号判断新增或更新大华人员。 */ @@ -118,11 +126,41 @@ public class DaHuaPersonSyncExe { DaHuaPersonSyncCmd.PersonBiosignature face = new DaHuaPersonSyncCmd.PersonBiosignature(); face.setType(3); face.setIndex(1); - face.setPath(faceUrl); + // userFaceUrl 是用户中心的文件路径,先通过 Dubbo 获取 Base64,交给网关上传到大华 + face.setBase64Data(resolveFaceBase64(faceUrl)); cmd.setPersonBiosignatures(Collections.singletonList(face)); return cmd; } + /** + * 通过用户中心把本系统头像路径转换为图片 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 response; + 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(); + } + } + throw new BizException("相关方人员头像转换失败"); + } + private String decodeUserCard(String userCard) { try { return Base64.decodeToString(userCard); From 77f915192dff6fc862ee1d689f54ea026f02dbc1 Mon Sep 17 00:00:00 2001 From: shenzhidan Date: Wed, 29 Jul 2026 16:52:12 +0800 Subject: [PATCH 6/8] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=A4=A7=E5=8D=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primeport/command/DaHuaPersonSyncExe.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java index 4bbfc78..59d3547 100644 --- a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java +++ b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java @@ -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 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) { From 113fadfe8a306f36e37a5790e291640632ac67b9 Mon Sep 17 00:00:00 2001 From: shenzhidan Date: Wed, 29 Jul 2026 17:55:00 +0800 Subject: [PATCH 7/8] =?UTF-8?q?1.=E4=B8=B4=E6=97=B6=E8=AE=BF=E5=AE=A2?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=A4=A7=E5=8D=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primeport/command/DaHuaPersonSyncExe.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java index 59d3547..7b09ecf 100644 --- a/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java +++ b/web-app/src/main/java/com/zcloud/primeport/command/DaHuaPersonSyncExe.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; /** - * 相关方人员同步大华平台。 + * 相关方及临时访客人员同步大华平台。 */ @Slf4j @Component @@ -28,6 +28,7 @@ import java.util.Map; public class DaHuaPersonSyncExe { private static final int RELATED_PARTY = 3; + private static final int TEMPORARY_VISITOR = 4; private final DaHuaGateway daHuaGateway; private final PersonApplyGateway personApplyGateway; @@ -36,11 +37,11 @@ public class DaHuaPersonSyncExe { private String fileUrl; /** - * 相关方人员审核通过后,按证件号判断新增或更新大华人员。 + * 相关方及临时访客人员审核通过后,按证件号判断新增或更新大华人员。 */ public void syncApprovedPersons(Long applyId) { XgfApplyPersonE apply = personApplyGateway.getXgfApplyPersonById(applyId); - if (apply == null || !Integer.valueOf(RELATED_PARTY).equals(apply.getPersonBelongType())) { + if (apply == null || !isDahuaSyncPerson(apply.getPersonBelongType())) { return; } List persons = personApplyGateway.personListByxgfApplyPersonId(applyId); @@ -65,10 +66,10 @@ public class DaHuaPersonSyncExe { } /** - * 相关方人员信息修改后,同步更新大华人员。 + * 相关方及临时访客人员信息修改后,同步更新大华人员。 */ public void syncUpdatedPerson(PersonApplyE original, PersonApplyUpdateCmd updated) { - if (original == null || !Integer.valueOf(RELATED_PARTY).equals(updated.getPersonBelongType())) { + if (original == null || !isDahuaSyncPerson(updated.getPersonBelongType())) { return; } String originalPaperNumber = decodeUserCard(original.getUserCard()); @@ -84,7 +85,7 @@ public class DaHuaPersonSyncExe { } /** - * 删除相关方人员时,同步删除对应的大华人员。 + * 删除相关方及临时访客人员时,同步删除对应的大华人员。 */ public void syncDeletedPersons(List persons) { if (persons == null || persons.isEmpty()) { @@ -93,7 +94,7 @@ public class DaHuaPersonSyncExe { List dahuaPersonIds = new ArrayList<>(); for (PersonApplyE person : persons) { XgfApplyPersonE apply = personApplyGateway.getXgfApplyPersonById(person.getXgfApplyPersonId()); - if (apply == null || !Integer.valueOf(RELATED_PARTY).equals(apply.getPersonBelongType())) { + if (apply == null || !isDahuaSyncPerson(apply.getPersonBelongType())) { continue; } Long dahuaPersonId = daHuaGateway.findPersonIdByPaperNumber(decodeUserCard(person.getUserCard())); @@ -132,12 +133,12 @@ public class DaHuaPersonSyncExe { } /** - * 根据文件服务地址读取相关方人员头像并转换为图片 Base64。 + * 根据文件服务地址读取人员头像并转换为图片 Base64。 * 大华人员接口的 path 必须是大华图片上传接口返回的 fileUrl,不能直接使用本系统路径。 */ private String resolveFaceBase64(String faceUrl) { if (faceUrl == null || faceUrl.trim().isEmpty()) { - throw new BizException("相关方人员头像不能为空"); + throw new BizException("人员头像不能为空"); } if (fileUrl == null || fileUrl.trim().isEmpty()) { throw new BizException("文件访问地址未配置"); @@ -150,14 +151,14 @@ public class DaHuaPersonSyncExe { try { String faceBase64 = Base64Util.urlToBase64(imageUrl); if (faceBase64 == null || faceBase64.trim().isEmpty()) { - throw new BizException("相关方人员头像转换失败"); + throw new BizException("人员头像转换失败"); } return faceBase64; } catch (BizException e) { throw e; } catch (Exception e) { - log.error("获取相关方人员头像失败, imageUrl={}", imageUrl, e); - throw new BizException("获取相关方人员头像失败"); + log.error("获取人员头像失败, imageUrl={}", imageUrl, e); + throw new BizException("获取人员头像失败"); } } @@ -165,6 +166,11 @@ public class DaHuaPersonSyncExe { return path.startsWith("/") ? path.substring(1) : path; } + private boolean isDahuaSyncPerson(Integer personBelongType) { + return Integer.valueOf(RELATED_PARTY).equals(personBelongType) + || Integer.valueOf(TEMPORARY_VISITOR).equals(personBelongType); + } + private String decodeUserCard(String userCard) { try { return Base64.decodeToString(userCard); From e81b45fcd1ff6c7abe78ae52590e0c3d5c726e68 Mon Sep 17 00:00:00 2001 From: zhangxiongfeng Date: Wed, 5 Aug 2026 08:44:22 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=A4=A7=E5=8D=8E=E5=BE=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E4=BF=AE=E6=94=B91.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gatewayimpl/DaHuaGatewayImpl.java | 600 +++++++++++++++++- 1 file changed, 590 insertions(+), 10 deletions(-) diff --git a/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java b/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java index fe5f5a6..2080740 100644 --- a/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java +++ b/web-infrastructure/src/main/java/com/zcloud/primeport/gatewayimpl/DaHuaGatewayImpl.java @@ -1,21 +1,27 @@ package com.zcloud.primeport.gatewayimpl; +import cn.hutool.http.HttpRequest; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.dahuatech.icc.exception.ClientException; import com.dahuatech.icc.oauth.model.v202010.GeneralResponse; import com.zcloud.primeport.dahua.api.DaHuaPersonApi; import com.zcloud.primeport.domain.gateway.DaHuaGateway; -import com.zcloud.primeport.domain.model.DaHuaAccessRecordCmd; -import com.zcloud.primeport.domain.model.DaHuaCarAddCmd; -import com.zcloud.primeport.domain.model.DaHuaCarPageCmd; -import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd; +import com.zcloud.gbscommon.dahua.cmd.DaHuaAccessRecordCmd; +import com.zcloud.gbscommon.dahua.cmd.DaHuaCarAddCmd; +import com.zcloud.gbscommon.dahua.cmd.DaHuaCarPageCmd; +import com.zcloud.gbscommon.dahua.cmd.DaHuaPersonSyncCmd; +import com.zcloud.gbscommon.dahua.cmd.DaHuaTempVehicleSaveCmd; +import com.zcloud.primeport.persistence.dataobject.DaHuaDepartmentCorpMappingDO; +import com.zcloud.primeport.persistence.repository.DaHuaDepartmentCorpMappingRepository; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,6 +33,9 @@ public class DaHuaGatewayImpl implements DaHuaGateway { @Autowired(required = false) private DaHuaPersonApi daHuaPersonApi; + @Autowired + private DaHuaDepartmentCorpMappingRepository daHuaDeptMappingRepository; + @Override public Long generatePersonId() { if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { @@ -99,9 +108,17 @@ public class DaHuaGatewayImpl implements DaHuaGateway { if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { throw new RuntimeException("大华服务未配置"); } + Map uploadResult = uploadAndSetPersonBiosignaturePaths(cmd); + if (uploadResult != null) { + return uploadResult; + } Map body = convertToMap(cmd); + processDaHuaPersonBiosignatures(body); + System.out.println("==========[syncPerson 完整请求参数 START]=========="); + System.out.println(JSONUtil.toJsonPrettyStr(body)); + debugPrintPersonBiosignatures(body); + System.out.println("==========[syncPerson 完整请求参数 END]============"); log.info("大华同步人员请求参数: {}", JSONUtil.toJsonStr(body)); - System.out.println("大华同步人员请求参数: " + JSONUtil.toJsonStr(body)); Map resultMap = new HashMap<>(); try { GeneralResponse response = daHuaPersonApi.addPerson(body); @@ -114,20 +131,51 @@ public class DaHuaGatewayImpl implements DaHuaGateway { resultMap.put("success", false); resultMap.put("code", "SYSTEM_ERROR"); resultMap.put("errMsg", "response为null"); + resultMap.put("dhData", null); return resultMap; } JSONObject jsonObject = JSONUtil.parseObj(responseJson); Boolean dhSuccess = jsonObject.getBool("success", false); String dhCode = jsonObject.getStr("code", response.getCode()); String dhErrMsg = jsonObject.getStr("errMsg", ""); - String dhResult = jsonObject.getStr("result", ""); + Object dhResultObj = jsonObject.get("result"); + Object dhData = jsonObject.get("data"); + if (dhResultObj != null) { + try { + JSONObject bizObj; + if (dhResultObj instanceof String) { + bizObj = JSONUtil.parseObj((String) dhResultObj); + } else if (dhResultObj instanceof JSONObject) { + bizObj = (JSONObject) dhResultObj; + } else { + bizObj = JSONUtil.parseObj(JSONUtil.toJsonStr(dhResultObj)); + } + dhSuccess = bizObj.getBool("success", dhSuccess); + dhCode = bizObj.getStr("code", dhCode); + dhErrMsg = bizObj.getStr("errMsg", dhErrMsg); + Object tmpData = bizObj.get("data"); + if (tmpData != null) { + dhData = tmpData; + } + } catch (Exception e) { + log.warn("大华同步人员解析result字段失败: {}", e.getMessage()); + } + } boolean passed = "0".equals(dhCode); resultMap.put("passed", passed); resultMap.put("success", dhSuccess); resultMap.put("code", dhCode); resultMap.put("errMsg", dhErrMsg); - resultMap.put("result", dhResult); - if (!passed) { + resultMap.put("result", dhResultObj); + resultMap.put("dhData", dhData); + System.out.println("==========[大华同步人员返回 dhData START]=========="); + System.out.println(JSONUtil.toJsonPrettyStr(dhData)); + System.out.println("==========[大华同步人员返回 dhData END]============"); + log.info("大华同步人员返回dhData: {}", JSONUtil.toJsonStr(dhData)); + if (passed) { + log.info("大华同步人员成功 - code={}, dhData={}", dhCode, JSONUtil.toJsonStr(dhData)); + System.out.println("大华同步人员成功: code=" + dhCode + ", dhData=" + JSONUtil.toJsonPrettyStr(dhData)); + } else { log.error("大华同步人员失败: code={}, errMsg={}, response={}", dhCode, dhErrMsg, responseJson); System.out.println("大华同步人员失败: code=" + dhCode + ", errMsg=" + dhErrMsg); } @@ -138,6 +186,7 @@ public class DaHuaGatewayImpl implements DaHuaGateway { resultMap.put("success", false); resultMap.put("code", "CLIENT_EXCEPTION"); resultMap.put("errMsg", e.getMessage()); + resultMap.put("dhData", null); return resultMap; } } @@ -155,9 +204,17 @@ public class DaHuaGatewayImpl implements DaHuaGateway { emptyMap.put("errMsg", "id不能为空"); return emptyMap; } + Map uploadResult = uploadAndSetPersonBiosignaturePaths(cmd); + if (uploadResult != null) { + return uploadResult; + } Map body = convertToMap(cmd); + processDaHuaPersonBiosignatures(body); + System.out.println("==========[updatePerson 完整请求参数 START]=========="); + System.out.println(JSONUtil.toJsonPrettyStr(body)); + debugPrintPersonBiosignatures(body); + System.out.println("==========[updatePerson 完整请求参数 END]============"); log.info("大华修改人员请求参数: {}", JSONUtil.toJsonStr(body)); - System.out.println("大华修改人员请求参数: " + JSONUtil.toJsonStr(body)); Map resultMap = new HashMap<>(); try { GeneralResponse response = daHuaPersonApi.updatePerson(body); @@ -215,6 +272,215 @@ public class DaHuaGatewayImpl implements DaHuaGateway { return map; } + private static String getStr(Map m, String key) { + Object v = m.get(key); + return v == null ? null : v.toString(); + } + + private static String onlyPureBase64(String raw) { + if (raw == null) return null; + String s = raw.trim(); + if (s.isEmpty()) return s; + int comma = s.indexOf(','); + if (comma > 0 && comma < 100) { + String prefix = s.substring(0, comma).toLowerCase(); + if (prefix.startsWith("data:") && prefix.contains("base64")) { + s = s.substring(comma + 1).trim(); + } + } + return s.replaceAll("\\s+", ""); + } + + private static boolean isHttpUrl(String s) { + if (s == null) return false; + String low = s.toLowerCase().trim(); + return low.startsWith("http://") || low.startsWith("https://"); + } + + private static boolean looksLikeBase64(String s) { + if (s == null || s.length() < 50) return false; + String t = s.trim(); + if (t.startsWith("data:")) return true; + int ok = 0; + int check = Math.min(t.length(), 200); + for (int i = 0; i < check; i++) { + char c = t.charAt(i); + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') + || c == '+' || c == '/' || c == '=') ok++; + } + return ((double) ok / check) > 0.95; + } + + private static byte[] downloadUrlBytes(String url) { + return HttpRequest.get(url).timeout(15000).execute().bodyBytes(); + } + + private static String detectMimePrefix(byte[] bytes) { + if (bytes == null || bytes.length < 4) return "data:image/jpeg;base64,"; + if (bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xD8 && bytes[2] == (byte) 0xFF) { + return "data:image/jpeg;base64,"; + } + if (bytes.length >= 8 + && bytes[0] == (byte) 0x89 + && bytes[1] == (byte) 0x50 + && bytes[2] == (byte) 0x4E + && bytes[3] == (byte) 0x47 + && bytes[4] == (byte) 0x0D + && bytes[5] == (byte) 0x0A + && bytes[6] == (byte) 0x1A + && bytes[7] == (byte) 0x0A) { + return "data:image/png;base64,"; + } + return "data:image/jpeg;base64,"; + } + + @SuppressWarnings("unchecked") + private static void debugPrintPersonBiosignatures(Map body) { + Object bios = body.get("personBiosignatures"); + if (bios == null || !(bios instanceof List)) { + System.out.println("[DEBUG] personBiosignatures 字段: 不存在或不是List"); + return; + } + List list = (List) bios; + System.out.println("[DEBUG] personBiosignatures 数量: " + list.size()); + for (int i = 0; i < list.size(); i++) { + Object item = list.get(i); + System.out.println("[DEBUG] --- 第 " + (i + 1) + " 条 ---"); + if (item instanceof Map) { + Map m = (Map) item; + System.out.println("[DEBUG] 所有字段 keys: " + String.join(", ", m.keySet())); + for (Map.Entry e : m.entrySet()) { + Object v = e.getValue(); + if (v == null) { + System.out.println("[DEBUG] " + e.getKey() + " = null"); + } else { + String s = v.toString(); + String show = s.length() > 120 ? s.substring(0, 120) + "...(len=" + s.length() + ")" : s; + System.out.println("[DEBUG] " + e.getKey() + " = " + show); + } + } + } else { + System.out.println("[DEBUG] 类型不是Map, 是: " + (item == null ? "null" : item.getClass().getName())); + } + } + } + + @SuppressWarnings("unchecked") + private void processDaHuaPersonBiosignatures(Map body) { + Object bios = body.get("personBiosignatures"); + if (bios == null || !(bios instanceof List)) return; + List inList = (List) bios; + List> outList = new ArrayList<>(); + int seq = 0; + for (Object item : inList) { + seq++; + Object rawType = null; + Object rawIndex = null; + String path = null; + String rawBase64 = null; + + if (item instanceof Map) { + Map mm = (Map) item; + rawType = mm.get("type"); + rawIndex = mm.get("index"); + path = getStr(mm, "path"); + rawBase64 = getStr(mm, "base64Data"); + if (rawBase64 == null) rawBase64 = getStr(mm, "data"); + } else if (item instanceof DaHuaPersonSyncCmd.PersonBiosignature) { + DaHuaPersonSyncCmd.PersonBiosignature b = (DaHuaPersonSyncCmd.PersonBiosignature) item; + rawType = b.getType(); + rawIndex = b.getIndex(); + path = b.getPath(); + rawBase64 = b.getBase64Data(); + } else { + continue; + } + + Map out = new HashMap<>(); + if (rawType != null) out.put("type", rawType); + if (rawIndex != null) out.put("index", rawIndex); + + String finalBase64WithPrefix = null; + boolean pathAlreadyUploaded = false; + + if (path != null && !path.trim().isEmpty() && !looksLikeBase64(path) && !isHttpUrl(path)) { + pathAlreadyUploaded = true; + out.put("path", path.trim()); + System.out.println("[大华人员同步] seq=" + seq + " path已通过上传接口获取, 直接使用fileUrl=" + path.trim()); + log.info("[大华人员同步] seq={} 使用已上传的图片路径: {}", seq, path.trim()); + } else { + out.put("path", ""); + + if (rawBase64 != null && !rawBase64.trim().isEmpty()) { + String t = rawBase64.trim(); + if (t.toLowerCase().startsWith("data:")) { + finalBase64WithPrefix = t.replaceAll("\\s+", ""); + System.out.println("[大华人员同步] seq=" + seq + " base64Data已带前缀, 直接使用, len=" + finalBase64WithPrefix.length()); + } else { + String pure = t.replaceAll("\\s+", ""); + if (!pure.isEmpty()) { + finalBase64WithPrefix = "data:image/jpeg;base64," + pure; + System.out.println("[大华人员同步] seq=" + seq + " base64Data无前缀, 默认补jpeg前缀, len=" + finalBase64WithPrefix.length()); + } + } + } + if ((finalBase64WithPrefix == null || finalBase64WithPrefix.isEmpty()) + && path != null && !path.trim().isEmpty()) { + String p = path.trim(); + if (isHttpUrl(p)) { + System.out.println("[大华人员同步] seq=" + seq + " 下载图片URL=" + p); + try { + byte[] bytes = downloadUrlBytes(p); + if (bytes != null && bytes.length > 0) { + String mimePrefix = detectMimePrefix(bytes); + String pure = Base64.getEncoder().encodeToString(bytes); + finalBase64WithPrefix = mimePrefix + pure; + System.out.println("[大华人员同步] seq=" + seq + " 下载成功, mime=" + + (mimePrefix.contains("png") ? "png" : "jpeg") + + ", totalLen=" + finalBase64WithPrefix.length()); + } else { + System.err.println("[大华人员同步] seq=" + seq + " 下载失败(返回空)"); + } + } catch (Exception e) { + System.err.println("[大华人员同步] seq=" + seq + " 下载图片异常: " + e.getMessage()); + log.error("下载人脸图片失败, seq={}, url={}, err={}", seq, p, e.getMessage(), e); + } + } else if (looksLikeBase64(p)) { + String t = p.trim(); + if (t.toLowerCase().startsWith("data:")) { + finalBase64WithPrefix = t.replaceAll("\\s+", ""); + System.out.println("[大华人员同步] seq=" + seq + " path是带前缀base64, 转存base64Data, len=" + finalBase64WithPrefix.length()); + } else { + String pure = onlyPureBase64(t); + if (pure != null && !pure.isEmpty()) { + finalBase64WithPrefix = "data:image/jpeg;base64," + pure; + System.out.println("[大华人员同步] seq=" + seq + " path是纯base64, 转存base64Data并补jpeg前缀, len=" + finalBase64WithPrefix.length()); + } + } + } else { + System.out.println("[大华人员同步] seq=" + seq + " path内容: " + + (p.length() > 100 ? p.substring(0, 100) + "..." : p)); + } + } + + if (finalBase64WithPrefix != null && !finalBase64WithPrefix.isEmpty()) { + out.put("base64Data", finalBase64WithPrefix); + System.out.println("[大华人员同步] seq=" + seq + " 最终字段: type=" + out.get("type") + + ", index=" + out.get("index") + + ", path=\"\"(空字符串)" + + ", base64Data前80=" + finalBase64WithPrefix.substring(0, Math.min(80, finalBase64WithPrefix.length())) + "..."); + log.info("[大华人员同步] seq={} 最终: type={}, index={}, path=空串, base64DataLen={}", + seq, out.get("type"), out.get("index"), finalBase64WithPrefix.length()); + } else { + System.out.println("[大华人员同步] seq=" + seq + " 未得到有效base64,字段: type=" + out.get("type") + + ", index=" + out.get("index") + ", path=\"\"(空字符串), 无base64Data"); + } + } + outList.add(out); + } + body.put("personBiosignatures", outList); + } + @Override public Map deletePerson(List ids, Integer openDeleteFlag) { if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { @@ -587,4 +853,318 @@ public class DaHuaGatewayImpl implements DaHuaGateway { return resultMap; } } -} + + @Override + public String uploadPersonImg(String imageBase64) { + if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { + throw new RuntimeException("大华服务未配置"); + } + if (imageBase64 == null || imageBase64.trim().isEmpty()) { + throw new RuntimeException("图片base64不能为空"); + } + try { + GeneralResponse response = daHuaPersonApi.uploadPersonImg(imageBase64); + String responseJson = JSONUtil.toJsonStr(response); + log.info("大华上传人员图片返回结果: {}", responseJson); + System.out.println("大华上传人员图片返回结果: " + responseJson); + if (response == null) { + throw new RuntimeException("大华上传人员图片失败: response为null"); + } + JSONObject jsonObject = JSONUtil.parseObj(responseJson); + Boolean outerSuccess = jsonObject.getBool("success", false); + String outerCode = jsonObject.getStr("code", ""); + String outerErrMsg = jsonObject.getStr("errMsg", ""); + + Boolean bizSuccess = outerSuccess; + String resultCode = null; + String fileUrl = null; + String bizErrMsg = outerErrMsg; + + Object resultObj = jsonObject.get("result"); + if (resultObj != null) { + try { + JSONObject bizObj; + if (resultObj instanceof String) { + bizObj = JSONUtil.parseObj((String) resultObj); + } else if (resultObj instanceof JSONObject) { + bizObj = (JSONObject) resultObj; + } else { + bizObj = JSONUtil.parseObj(JSONUtil.toJsonStr(resultObj)); + } + bizSuccess = bizObj.getBool("success", bizSuccess); + bizErrMsg = bizObj.getStr("errMsg", bizErrMsg); + Object bizDataObj = bizObj.get("data"); + if (bizDataObj != null) { + JSONObject bizDataJson = JSONUtil.parseObj(bizDataObj); + resultCode = bizDataJson.getStr("result"); + fileUrl = bizDataJson.getStr("fileUrl"); + System.out.println("大华上传人员图片解析result字段成功: resultCode=" + resultCode + ", fileUrl=" + fileUrl); + } + } catch (Exception e) { + log.warn("大华上传人员图片解析result字段失败: {}", e.getMessage()); + System.out.println("大华上传人员图片解析result字段失败: " + e.getMessage()); + } + } + + boolean resultOk = (resultCode == null || resultCode.isEmpty()) || "0".equals(resultCode); + if (!bizSuccess || !resultOk) { + String msg = "大华上传人员图片失败: success=" + bizSuccess + ", result=" + resultCode + ", outerCode=" + outerCode + ", errMsg=" + bizErrMsg; + log.error(msg); + throw new RuntimeException(msg); + } + if (fileUrl == null || fileUrl.trim().isEmpty()) { + throw new RuntimeException("大华上传人员图片失败: 未返回fileUrl"); + } + System.out.println("大华上传人员图片成功, fileUrl=" + fileUrl); + return fileUrl; + } catch (ClientException e) { + log.error("大华上传人员图片异常: {}", e.getMessage(), e); + throw new RuntimeException("大华上传人员图片异常", e); + } + } + + @SuppressWarnings("unchecked") + private Map uploadAndSetPersonBiosignaturePaths(DaHuaPersonSyncCmd cmd) { + List bios = cmd.getPersonBiosignatures(); + if (bios == null || bios.isEmpty()) { + return null; + } + int seq = 0; + for (DaHuaPersonSyncCmd.PersonBiosignature bio : bios) { + seq++; + String base64Data = bio.getBase64Data(); + if (base64Data == null || base64Data.trim().isEmpty()) { + continue; + } + String finalBase64WithPrefix; + String t = base64Data.trim(); + if (t.toLowerCase().startsWith("data:")) { + finalBase64WithPrefix = t.replaceAll("\\s+", ""); + } else { + String pure = t.replaceAll("\\s+", ""); + if (pure.isEmpty()) { + continue; + } + finalBase64WithPrefix = "data:image/jpeg;base64," + pure; + } + System.out.println("[大华人员图片上传] seq=" + seq + " 开始上传图片, base64长度=" + finalBase64WithPrefix.length()); + try { + String fileUrl = uploadPersonImg(finalBase64WithPrefix); + bio.setPath(fileUrl); + System.out.println("[大华人员图片上传] seq=" + seq + " 上传成功, path=" + fileUrl); + } catch (Exception e) { + log.error("[大华人员图片上传] seq=" + seq + " 上传失败: {}", e.getMessage(), e); + System.err.println("[大华人员图片上传] seq=" + seq + " 上传失败: " + e.getMessage()); + Map resultMap = new HashMap<>(); + resultMap.put("passed", false); + resultMap.put("success", false); + resultMap.put("code", "IMG_UPLOAD_FAIL"); + resultMap.put("errMsg", "第" + seq + "张人脸图片上传失败: " + e.getMessage()); + resultMap.put("dhData", null); + return resultMap; + } + } + return null; + } + + @Override + public Map saveTempVehicle(DaHuaTempVehicleSaveCmd cmd) { + if (daHuaPersonApi == null || !daHuaPersonApi.isConfigured()) { + throw new RuntimeException("大华服务未配置"); + } + if (cmd.getId() == null) { + Long personId = generatePersonId(); + System.out.println("大华临时车辆全量保存自动生成人员ID: " + personId); + cmd.setId(personId); + } + if (cmd.getService() == null || cmd.getService().trim().isEmpty()) { + cmd.setService("evo-thirdParty"); + } + Map uploadResult = uploadAndSetTempVehicleBiosignaturePaths(cmd); + if (uploadResult != null) { + return uploadResult; + } + Map body = convertToMap(cmd); + processTempVehicleBiosignatures(body); + System.out.println("==========[saveTempVehicle 完整请求参数 START]=========="); + System.out.println(JSONUtil.toJsonPrettyStr(body)); + log.info("大华临时车辆全量保存请求参数: {}", JSONUtil.toJsonStr(body)); + Map resultMap = new HashMap<>(); + try { + GeneralResponse response = daHuaPersonApi.saveTempVehicleAudit(body); + String responseJson = JSONUtil.toJsonStr(response); + log.info("大华临时车辆全量保存返回结果: {}", responseJson); + System.out.println("大华临时车辆全量保存返回结果: " + responseJson); + if (response == null) { + log.error("大华临时车辆全量保存失败: response为null"); + resultMap.put("passed", false); + resultMap.put("success", false); + resultMap.put("code", "SYSTEM_ERROR"); + resultMap.put("errMsg", "response为null"); + resultMap.put("dhData", null); + return resultMap; + } + JSONObject jsonObject = JSONUtil.parseObj(responseJson); + Boolean dhSuccess = jsonObject.getBool("success", false); + String dhCode = jsonObject.getStr("code", response.getCode()); + String dhErrMsg = jsonObject.getStr("errMsg", ""); + Object dhResultObj = jsonObject.get("result"); + Object dhData = jsonObject.get("data"); + if (dhResultObj != null) { + try { + JSONObject bizObj; + if (dhResultObj instanceof String) { + bizObj = JSONUtil.parseObj((String) dhResultObj); + } else if (dhResultObj instanceof JSONObject) { + bizObj = (JSONObject) dhResultObj; + } else { + bizObj = JSONUtil.parseObj(JSONUtil.toJsonStr(dhResultObj)); + } + dhSuccess = bizObj.getBool("success", dhSuccess); + dhCode = bizObj.getStr("code", dhCode); + dhErrMsg = bizObj.getStr("errMsg", dhErrMsg); + Object tmpData = bizObj.get("data"); + if (tmpData != null) { + dhData = tmpData; + } + } catch (Exception e) { + log.warn("大华临时车辆全量保存解析result字段失败: {}", e.getMessage()); + } + } + boolean passed = "0".equals(dhCode); + resultMap.put("passed", passed); + resultMap.put("success", dhSuccess); + resultMap.put("code", dhCode); + resultMap.put("errMsg", dhErrMsg); + resultMap.put("result", dhResultObj); + resultMap.put("dhData", dhData); + System.out.println("大华临时车辆全量保存返回dhData: " + dhData); + if (!passed) { + log.error("大华临时车辆全量保存失败: code={}, errMsg={}, response={}", dhCode, dhErrMsg, responseJson); + System.out.println("大华临时车辆全量保存失败: code=" + dhCode + ", errMsg=" + dhErrMsg); + } + return resultMap; + } catch (ClientException e) { + log.error("大华临时车辆全量保存异常: {}", e.getMessage(), e); + resultMap.put("passed", false); + resultMap.put("success", false); + resultMap.put("code", "CLIENT_EXCEPTION"); + resultMap.put("errMsg", e.getMessage()); + resultMap.put("dhData", null); + return resultMap; + } + } + + @SuppressWarnings("unchecked") + private Map uploadAndSetTempVehicleBiosignaturePaths(DaHuaTempVehicleSaveCmd cmd) { + List bios = cmd.getPersonBiosignatures(); + if (bios == null || bios.isEmpty()) { + return null; + } + int seq = 0; + for (DaHuaTempVehicleSaveCmd.PersonBiosignature bio : bios) { + seq++; + String base64Data = bio.getBase64Data(); + if (base64Data == null || base64Data.trim().isEmpty()) { + continue; + } + String finalBase64WithPrefix; + String t = base64Data.trim(); + if (t.toLowerCase().startsWith("data:")) { + finalBase64WithPrefix = t.replaceAll("\\s+", ""); + } else { + String pure = t.replaceAll("\\s+", ""); + if (pure.isEmpty()) { + continue; + } + finalBase64WithPrefix = "data:image/jpeg;base64," + pure; + } + System.out.println("[大华临时车辆图片上传] seq=" + seq + " 开始上传图片, base64长度=" + finalBase64WithPrefix.length()); + try { + String fileUrl = uploadPersonImg(finalBase64WithPrefix); + bio.setPath(fileUrl); + bio.setBase64Data(null); + System.out.println("[大华临时车辆图片上传] seq=" + seq + " 上传成功, path=" + fileUrl); + } catch (Exception e) { + log.error("[大华临时车辆图片上传] seq=" + seq + " 上传失败: {}", e.getMessage(), e); + System.err.println("[大华临时车辆图片上传] seq=" + seq + " 上传失败: " + e.getMessage()); + Map resultMap = new HashMap<>(); + resultMap.put("passed", false); + resultMap.put("success", false); + resultMap.put("code", "IMG_UPLOAD_FAIL"); + resultMap.put("errMsg", "第" + seq + "张人脸图片上传失败: " + e.getMessage()); + resultMap.put("dhData", null); + return resultMap; + } + } + return null; + } + + @SuppressWarnings("unchecked") + private void processTempVehicleBiosignatures(Map body) { + Object bios = body.get("personBiosignatures"); + if (bios == null || !(bios instanceof List)) return; + List inList = (List) bios; + List> outList = new ArrayList<>(); + for (Object item : inList) { + Map out = new HashMap<>(); + if (item instanceof Map) { + Map mm = (Map) item; + if (mm.get("type") != null) out.put("type", mm.get("type")); + if (mm.get("index") != null) out.put("index", mm.get("index")); + Object path = mm.get("path"); + if (path != null && !path.toString().trim().isEmpty()) { + out.put("path", path.toString().trim()); + } else { + out.put("path", ""); + } + Object base64Data = mm.get("base64Data"); + if (base64Data != null && !base64Data.toString().trim().isEmpty()) { + String s = base64Data.toString().trim(); + if (!s.toLowerCase().startsWith("data:")) { + s = "data:image/jpeg;base64," + s.replaceAll("\\s+", ""); + } + out.put("base64Data", s); + } + Object data = mm.get("data"); + if (data != null && !data.toString().trim().isEmpty()) { + out.put("data", data); + } + } else if (item instanceof DaHuaTempVehicleSaveCmd.PersonBiosignature) { + DaHuaTempVehicleSaveCmd.PersonBiosignature b = (DaHuaTempVehicleSaveCmd.PersonBiosignature) item; + if (b.getType() != null) out.put("type", b.getType()); + if (b.getIndex() != null) out.put("index", b.getIndex()); + if (b.getPath() != null && !b.getPath().trim().isEmpty()) { + out.put("path", b.getPath().trim()); + } else { + out.put("path", ""); + } + if (b.getBase64Data() != null && !b.getBase64Data().trim().isEmpty()) { + String s = b.getBase64Data().trim(); + if (!s.toLowerCase().startsWith("data:")) { + s = "data:image/jpeg;base64," + s.replaceAll("\\s+", ""); + } + out.put("base64Data", s); + } + if (b.getData() != null && !b.getData().trim().isEmpty()) { + out.put("data", b.getData()); + } + } + outList.add(out); + } + body.put("personBiosignatures", outList); + } + + @Override + public Long findDahuaDepartmentIdByCorpId(Long corpId) { + if (corpId == null) { + return null; + } + DaHuaDepartmentCorpMappingDO mapping = daHuaDeptMappingRepository.findByCorpId(corpId); + if (mapping == null) { + log.warn("未找到大华部门映射配置, corpId={}", corpId); + return null; + } + return mapping.getDahuaDepartmentId(); + } +} \ No newline at end of file