大华微服务修改微服务
parent
e81b45fcd1
commit
c4ae60c686
|
|
@ -4,7 +4,7 @@ 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;
|
||||
import com.zcloud.gbscommon.dahua.cmd.DaHuaPersonSyncCmd;
|
||||
import com.zcloud.primeport.domain.model.PersonApplyE;
|
||||
import com.zcloud.primeport.domain.model.XgfApplyPersonE;
|
||||
import com.zcloud.primeport.dto.PersonApplyUpdateCmd;
|
||||
|
|
@ -185,4 +185,4 @@ public class DaHuaPersonSyncExe {
|
|||
throw new BizException(message + (errorMessage == null ? "" : ": " + errorMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import com.alibaba.cola.exception.BizException;
|
|||
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.gbscommon.dahua.cmd.DaHuaCarAddCmd;
|
||||
import com.zcloud.primeport.domain.model.VehicleApplyE;
|
||||
import com.zcloud.primeport.plan.mjDevice.dto.CarEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
|
@ -79,4 +79,4 @@ public class DaHuaVehicleSyncExe {
|
|||
throw new BizException(message + (errorMessage == null ? "" : ": " + errorMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,457 @@
|
|||
package com.zcloud.primeport.service;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.zcloud.primeport.domain.gateway.DaHuaAccessRecordRepositoryGateway;
|
||||
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
|
||||
import com.zcloud.primeport.domain.gateway.DaHuaResourceRepositoryGateway;
|
||||
import com.zcloud.primeport.domain.gateway.DaHuaAccessRecordSyncGateway;
|
||||
import com.zcloud.primeport.domain.model.CorpInfoSnapshotE;
|
||||
import com.zcloud.gbscommon.dahua.cmd.DaHuaAccessRecordCmd;
|
||||
import com.zcloud.primeport.domain.model.DaHuaAccessRecordE;
|
||||
import com.zcloud.primeport.domain.model.DaHuaAccessRecordSyncResultE;
|
||||
import com.zcloud.primeport.domain.model.DaHuaDepartmentCorpMappingE;
|
||||
import com.zcloud.primeport.domain.model.DaHuaDeviceChannelE;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.Normalizer;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DaHuaAccessRecordSyncApplicationService implements DaHuaAccessRecordSyncGateway {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
private static final int MAX_EXCEPTION_DETAILS = 100;
|
||||
|
||||
private final DaHuaGateway daHuaGateway;
|
||||
private final DaHuaResourceRepositoryGateway resourceRepositoryGateway;
|
||||
private final DaHuaAccessRecordRepositoryGateway accessRecordRepositoryGateway;
|
||||
|
||||
public DaHuaAccessRecordSyncResultE sync(String startSwingTime,
|
||||
String endSwingTime,
|
||||
String startCreateTime,
|
||||
String endCreateTime,
|
||||
int pageSize) {
|
||||
validateTimeRange(startSwingTime, endSwingTime, "swing time");
|
||||
validateOptionalTimeRange(startCreateTime, endCreateTime, "create time");
|
||||
if (pageSize < 1 || pageSize > 10000) {
|
||||
throw new IllegalArgumentException("pageSize must be between 1 and 10000");
|
||||
}
|
||||
|
||||
SyncIndex index = buildIndex();
|
||||
Map<String, DaHuaAccessRecordE> synchronizedRecords = new HashMap<>();
|
||||
DaHuaAccessRecordSyncResultE result = new DaHuaAccessRecordSyncResultE();
|
||||
int pageNum = 1;
|
||||
while (true) {
|
||||
List<Map<String, Object>> pageData = fetchPage(pageNum, pageSize, startSwingTime,
|
||||
endSwingTime, startCreateTime, endCreateTime);
|
||||
result.setPageCount(result.getPageCount() + 1);
|
||||
if (pageData.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
persistPage(pageData, index, synchronizedRecords, result);
|
||||
if (pageData.size() < pageSize) {
|
||||
break;
|
||||
}
|
||||
pageNum++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaHuaAccessRecordSyncResultE syncIncremental(int pageSize,
|
||||
int delayMinutes,
|
||||
int overlapMinutes,
|
||||
int initialLookbackMinutes) {
|
||||
LocalDateTime endCreateTime = LocalDateTime.now().minusMinutes(Math.max(delayMinutes, 0));
|
||||
LocalDateTime latestCreateTime = accessRecordRepositoryGateway.findLatestDahuaCreateTime();
|
||||
LocalDateTime startCreateTime = latestCreateTime == null
|
||||
? endCreateTime.minusMinutes(Math.max(initialLookbackMinutes, 1))
|
||||
: latestCreateTime.minusMinutes(Math.max(overlapMinutes, 0));
|
||||
if (!startCreateTime.isBefore(endCreateTime)) {
|
||||
return new DaHuaAccessRecordSyncResultE();
|
||||
}
|
||||
return sync(format(startCreateTime.minusDays(2)), format(endCreateTime.plusDays(1)),
|
||||
format(startCreateTime), format(endCreateTime), pageSize);
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> fetchPage(int pageNum,
|
||||
int pageSize,
|
||||
String startSwingTime,
|
||||
String endSwingTime,
|
||||
String startCreateTime,
|
||||
String endCreateTime) {
|
||||
DaHuaAccessRecordCmd cmd = new DaHuaAccessRecordCmd();
|
||||
cmd.setPageNum(pageNum);
|
||||
cmd.setPageSize(pageSize);
|
||||
cmd.setStartSwingTime(startSwingTime);
|
||||
cmd.setEndSwingTime(endSwingTime);
|
||||
cmd.setStartCreateTime(blankToNull(startCreateTime));
|
||||
cmd.setEndCreateTime(blankToNull(endCreateTime));
|
||||
Map<String, Object> response = daHuaGateway.queryAccessRecord(cmd);
|
||||
if (response == null || !isSuccessful(response)) {
|
||||
String code = response == null ? null : stringValue(response.get("code"));
|
||||
String errMsg = response == null ? "empty response" : stringValue(response.get("errMsg"));
|
||||
throw new IllegalStateException("Dahua access record query failed: code=" + code
|
||||
+ ", errMsg=" + errMsg);
|
||||
}
|
||||
Map<String, Object> data = toMap(response.get("data"));
|
||||
return toRecordList(data.get("pageData"));
|
||||
}
|
||||
|
||||
protected void persistPage(List<Map<String, Object>> pageData,
|
||||
SyncIndex index,
|
||||
Map<String, DaHuaAccessRecordE> synchronizedRecords,
|
||||
DaHuaAccessRecordSyncResultE result) {
|
||||
Set<String> recordIds = new LinkedHashSet<>();
|
||||
for (Map<String, Object> source : pageData) {
|
||||
String recordId = blankToNull(firstString(source, "id", "recordId"));
|
||||
if (recordId != null && !synchronizedRecords.containsKey(recordId)) {
|
||||
recordIds.add(recordId);
|
||||
}
|
||||
}
|
||||
for (DaHuaAccessRecordE existing : accessRecordRepositoryGateway.listByDahuaRecordIds(recordIds)) {
|
||||
synchronizedRecords.put(existing.getDahuaRecordId(), existing);
|
||||
}
|
||||
|
||||
for (Map<String, Object> source : pageData) {
|
||||
result.setRecordTotal(result.getRecordTotal() + 1);
|
||||
try {
|
||||
String recordId = blankToNull(firstString(source, "id", "recordId"));
|
||||
if (recordId == null) {
|
||||
throw new IllegalArgumentException("record id is missing");
|
||||
}
|
||||
DaHuaAccessRecordE record = synchronizedRecords.get(recordId);
|
||||
boolean created = record == null;
|
||||
if (created) {
|
||||
record = new DaHuaAccessRecordE();
|
||||
}
|
||||
mapRecord(record, source, recordId, index);
|
||||
if (created) {
|
||||
accessRecordRepositoryGateway.add(record);
|
||||
result.setRecordCreated(result.getRecordCreated() + 1);
|
||||
} else {
|
||||
accessRecordRepositoryGateway.update(record);
|
||||
result.setRecordUpdated(result.getRecordUpdated() + 1);
|
||||
}
|
||||
synchronizedRecords.put(recordId, record);
|
||||
} catch (Exception e) {
|
||||
result.setRecordInvalid(result.getRecordInvalid() + 1);
|
||||
addDetail(result.getExceptionDetails(), "Access record sync failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void mapRecord(DaHuaAccessRecordE record,
|
||||
Map<String, Object> source,
|
||||
String recordId,
|
||||
SyncIndex index) {
|
||||
String channelCode = blankToNull(firstString(source, "channelCode", "acsChannelCode"));
|
||||
String departmentName = blankToNull(firstString(source, "deptName", "departmentName"));
|
||||
Long departmentId = firstLong(source, "deptId", "departmentId");
|
||||
String orgCode = blankToNull(firstString(source, "orgCode", "departmentCode", "deptCode"));
|
||||
DaHuaDeviceChannelE channel = channelCode == null ? null : index.channelsByCode.get(channelCode);
|
||||
DaHuaDepartmentCorpMappingE personMapping = resolvePersonMapping(
|
||||
index, departmentId, orgCode, departmentName);
|
||||
CorpInfoSnapshotE personCorp = personMapping == null
|
||||
? null : index.corpsById.get(personMapping.getCorpId());
|
||||
CorpInfoSnapshotE deviceCorp = channel == null
|
||||
? null : index.corpsById.get(channel.getCorpId());
|
||||
|
||||
record.setDahuaRecordId(recordId);
|
||||
record.setCorpId(null);
|
||||
record.setCorpName(null);
|
||||
record.setPortArea(null);
|
||||
record.setDahuaDepartmentId(departmentId);
|
||||
if (personMapping != null) {
|
||||
record.setCorpId(personMapping.getCorpId());
|
||||
record.setCorpName(personCorp == null ? personMapping.getCorpName() : personCorp.getCorpName());
|
||||
record.setPortArea(personCorp == null ? null : personCorp.getPortArea());
|
||||
if (record.getDahuaDepartmentId() == null) {
|
||||
record.setDahuaDepartmentId(personMapping.getDahuaDepartmentId());
|
||||
}
|
||||
}
|
||||
record.setDahuaDepartmentName(departmentName != null
|
||||
? departmentName : (personMapping == null ? null : personMapping.getDahuaDepartmentName()));
|
||||
|
||||
record.setDeviceCorpId(null);
|
||||
record.setDeviceCorpName(null);
|
||||
record.setDevicePortArea(null);
|
||||
record.setMkmjId(null);
|
||||
record.setPassageId(null);
|
||||
record.setGateId(null);
|
||||
if (channel != null) {
|
||||
record.setDeviceCorpId(channel.getCorpId());
|
||||
record.setDeviceCorpName(deviceCorp == null ? null : deviceCorp.getCorpName());
|
||||
record.setDevicePortArea(deviceCorp == null ? null : deviceCorp.getPortArea());
|
||||
record.setMkmjId(channel.getMkmjId());
|
||||
record.setPassageId(channel.getPassageId());
|
||||
record.setGateId(channel.getGateId());
|
||||
}
|
||||
|
||||
record.setChannelCode(channelCode);
|
||||
record.setChannelName(firstString(source, "channelName", "acsChannelName"));
|
||||
record.setDeviceCode(firstString(source, "deviceCode"));
|
||||
record.setDeviceName(firstString(source, "deviceName"));
|
||||
record.setPersonId(firstLong(source, "personId"));
|
||||
record.setPersonCode(firstString(source, "personCode"));
|
||||
record.setPersonName(firstString(source, "personName"));
|
||||
record.setPaperNumber(firstString(source, "paperNumber"));
|
||||
record.setCardNumber(firstString(source, "cardNumber"));
|
||||
record.setCardStatus(firstInteger(source, "cardStatus"));
|
||||
record.setCardType(firstInteger(source, "cardType"));
|
||||
record.setImageType(firstInteger(source, "imageType"));
|
||||
record.setEnterOrExit(firstInteger(source, "enterOrExit"));
|
||||
record.setOpenType(firstInteger(source, "openType"));
|
||||
record.setOpenResult(firstInteger(source, "openResult"));
|
||||
record.setRecordImageUrl(firstString(source, "recordImageUrl"));
|
||||
record.setRemark(firstString(source, "remark"));
|
||||
record.setSwingTime(firstDateTime(source, "swingTime"));
|
||||
record.setDahuaCreateTime(firstDateTime(source, "createTime"));
|
||||
record.setMaskState(firstInteger(source, "maskState"));
|
||||
record.setOverTemp(firstBoolean(source, "overTemp"));
|
||||
record.setCurrentTemperature(firstDecimal(source, "curTemp"));
|
||||
record.setSourceType("PULL");
|
||||
record.setRawData(JSONUtil.toJsonStr(source));
|
||||
record.setLastSyncTime(LocalDateTime.now());
|
||||
record.setDeleteEnum("FALSE");
|
||||
}
|
||||
|
||||
private SyncIndex buildIndex() {
|
||||
SyncIndex index = new SyncIndex();
|
||||
for (CorpInfoSnapshotE corp : nullSafe(resourceRepositoryGateway.listActiveCorps())) {
|
||||
index.corpsById.put(corp.getId(), corp);
|
||||
}
|
||||
for (DaHuaDeviceChannelE channel : nullSafe(resourceRepositoryGateway.listDeviceChannels())) {
|
||||
if (channel.getChannelCode() != null && !"TRUE".equalsIgnoreCase(channel.getDeleteEnum())) {
|
||||
index.channelsByCode.put(channel.getChannelCode(), channel);
|
||||
}
|
||||
}
|
||||
for (DaHuaDepartmentCorpMappingE mapping : nullSafe(resourceRepositoryGateway.listMappings())) {
|
||||
if (!isActive(mapping)) {
|
||||
continue;
|
||||
}
|
||||
if (mapping.getDahuaDepartmentId() != null) {
|
||||
index.mappingsByDepartmentId.put(mapping.getDahuaDepartmentId(), mapping);
|
||||
}
|
||||
String orgCode = blankToNull(mapping.getDahuaOrgCode());
|
||||
if (orgCode != null) {
|
||||
index.mappingsByOrgCode.put(orgCode, mapping);
|
||||
}
|
||||
String key = normalizeName(mapping.getDahuaDepartmentName());
|
||||
if (key != null) {
|
||||
index.mappingsByDepartmentName.computeIfAbsent(key, ignored -> new ArrayList<>()).add(mapping);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private DaHuaDepartmentCorpMappingE resolvePersonMapping(SyncIndex index,
|
||||
Long departmentId,
|
||||
String orgCode,
|
||||
String departmentName) {
|
||||
DaHuaDepartmentCorpMappingE mapping = departmentId == null
|
||||
? null : index.mappingsByDepartmentId.get(departmentId);
|
||||
if (mapping == null && orgCode != null) {
|
||||
mapping = index.mappingsByOrgCode.get(orgCode);
|
||||
}
|
||||
return mapping != null
|
||||
? mapping : uniqueMapping(index.mappingsByDepartmentName, departmentName);
|
||||
}
|
||||
|
||||
private boolean isSuccessful(Map<String, Object> response) {
|
||||
Object passed = response.get("passed");
|
||||
if (passed instanceof Boolean) {
|
||||
return (Boolean) passed;
|
||||
}
|
||||
Object success = response.get("success");
|
||||
return Boolean.TRUE.equals(success) || "0".equals(stringValue(response.get("code")));
|
||||
}
|
||||
|
||||
private boolean isActive(DaHuaDepartmentCorpMappingE mapping) {
|
||||
return mapping != null
|
||||
&& !"TRUE".equalsIgnoreCase(mapping.getDeleteEnum())
|
||||
&& (mapping.getBindStatus() == null || mapping.getBindStatus().intValue() == 1);
|
||||
}
|
||||
|
||||
private DaHuaDepartmentCorpMappingE uniqueMapping(
|
||||
Map<String, List<DaHuaDepartmentCorpMappingE>> mappingsByName,
|
||||
String departmentName) {
|
||||
List<DaHuaDepartmentCorpMappingE> matches = mappingsByName.get(normalizeName(departmentName));
|
||||
return matches != null && matches.size() == 1 ? matches.get(0) : null;
|
||||
}
|
||||
|
||||
private void validateOptionalTimeRange(String start, String end, String label) {
|
||||
if (isBlank(start) && isBlank(end)) {
|
||||
return;
|
||||
}
|
||||
if (isBlank(start) || isBlank(end)) {
|
||||
throw new IllegalArgumentException(label + " start and end must both be provided");
|
||||
}
|
||||
validateTimeRange(start, end, label);
|
||||
}
|
||||
|
||||
private void validateTimeRange(String start, String end, String label) {
|
||||
LocalDateTime startTime = parseRequiredDateTime(start, label + " start");
|
||||
LocalDateTime endTime = parseRequiredDateTime(end, label + " end");
|
||||
if (startTime.isAfter(endTime)) {
|
||||
throw new IllegalArgumentException(label + " start cannot be after end");
|
||||
}
|
||||
}
|
||||
|
||||
private LocalDateTime parseRequiredDateTime(String value, String field) {
|
||||
if (isBlank(value)) {
|
||||
throw new IllegalArgumentException(field + " cannot be blank");
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(value.trim(), DATE_TIME_FORMATTER);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw new IllegalArgumentException(field + " must use yyyy-MM-dd HH:mm:ss", e);
|
||||
}
|
||||
}
|
||||
|
||||
private LocalDateTime firstDateTime(Map<String, Object> source, String... fields) {
|
||||
String value = firstString(source, fields);
|
||||
if (isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
return parseRequiredDateTime(value, fields[0]);
|
||||
}
|
||||
|
||||
private Object firstValue(Map<String, Object> source, String... fields) {
|
||||
for (String field : fields) {
|
||||
Object value = source.get(field);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String firstString(Map<String, Object> source, String... fields) {
|
||||
return stringValue(firstValue(source, fields));
|
||||
}
|
||||
|
||||
private Long firstLong(Map<String, Object> source, String... fields) {
|
||||
Object value = firstValue(source, fields);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).longValue();
|
||||
}
|
||||
return Long.valueOf(value.toString());
|
||||
}
|
||||
|
||||
private Integer firstInteger(Map<String, Object> source, String... fields) {
|
||||
Object value = firstValue(source, fields);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).intValue();
|
||||
}
|
||||
return Integer.valueOf(value.toString());
|
||||
}
|
||||
|
||||
private Boolean firstBoolean(Map<String, Object> source, String... fields) {
|
||||
Object value = firstValue(source, fields);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof Boolean) {
|
||||
return (Boolean) value;
|
||||
}
|
||||
return Boolean.valueOf(value.toString());
|
||||
}
|
||||
|
||||
private BigDecimal firstDecimal(Map<String, Object> source, String... fields) {
|
||||
Object value = firstValue(source, fields);
|
||||
return value == null ? null : new BigDecimal(value.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> toMap(Object value) {
|
||||
if (value == null) {
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
if (value instanceof Map) {
|
||||
return new LinkedHashMap<>((Map<String, Object>) value);
|
||||
}
|
||||
return JSONUtil.parseObj(JSONUtil.toJsonStr(value));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> toRecordList(Object value) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
if (!(value instanceof Iterable)) {
|
||||
return result;
|
||||
}
|
||||
for (Object item : (Iterable<?>) value) {
|
||||
if (item instanceof Map) {
|
||||
result.add(new LinkedHashMap<>((Map<String, Object>) item));
|
||||
} else if (item != null) {
|
||||
result.add(JSONUtil.parseObj(JSONUtil.toJsonStr(item)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> Collection<T> nullSafe(Collection<T> values) {
|
||||
return values == null ? new ArrayList<>() : values;
|
||||
}
|
||||
|
||||
private String normalizeName(String value) {
|
||||
if (isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
return Normalizer.normalize(value, Normalizer.Form.NFKC)
|
||||
.replaceAll("\\s+", "")
|
||||
.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private String stringValue(Object value) {
|
||||
return value == null ? null : value.toString();
|
||||
}
|
||||
|
||||
private String blankToNull(String value) {
|
||||
return isBlank(value) ? null : value.trim();
|
||||
}
|
||||
|
||||
private boolean isBlank(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
|
||||
private String format(LocalDateTime value) {
|
||||
return value.format(DATE_TIME_FORMATTER);
|
||||
}
|
||||
|
||||
private void addDetail(List<String> details, String detail) {
|
||||
if (details.size() < MAX_EXCEPTION_DETAILS) {
|
||||
details.add(detail);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SyncIndex {
|
||||
private final Map<Long, CorpInfoSnapshotE> corpsById = new HashMap<>();
|
||||
private final Map<String, DaHuaDeviceChannelE> channelsByCode = new HashMap<>();
|
||||
private final Map<Long, DaHuaDepartmentCorpMappingE> mappingsByDepartmentId = new HashMap<>();
|
||||
private final Map<String, DaHuaDepartmentCorpMappingE> mappingsByOrgCode = new HashMap<>();
|
||||
private final Map<String, List<DaHuaDepartmentCorpMappingE>> mappingsByDepartmentName =
|
||||
new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
@ -11,10 +11,18 @@ import com.zcloud.gbscommon.dahua.cmd.DaHuaPersonSyncCmd;
|
|||
import com.zcloud.gbscommon.dahua.cmd.DaHuaTempVehicleSaveCmd;
|
||||
import com.zcloud.gbscommon.dahua.facade.ZcloudDaHuaFacade;
|
||||
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
|
||||
import com.zcloud.primeport.domain.model.DaHuaAccessRecordSyncResultE;
|
||||
import com.zcloud.primeport.domain.model.DaHuaResourceSyncResultE;
|
||||
import com.zcloud.primeport.dto.DaHuaAccessRecordSyncCmd;
|
||||
import com.zcloud.primeport.dto.DaHuaResourceSyncCmd;
|
||||
import com.zcloud.primeport.dto.clientobject.DaHuaAccessRecordSyncResultCO;
|
||||
import com.zcloud.primeport.dto.clientobject.DaHuaResourceSyncResultCO;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
|
|
@ -24,6 +32,12 @@ public class DaHuaServiceImpl implements ZcloudDaHuaFacade {
|
|||
@Autowired
|
||||
private DaHuaGateway daHuaGateway;
|
||||
|
||||
@Autowired
|
||||
private DaHuaResourceSyncApplicationService daHuaResourceSyncApplicationService;
|
||||
|
||||
@Autowired
|
||||
private DaHuaAccessRecordSyncApplicationService daHuaAccessRecordSyncApplicationService;
|
||||
|
||||
private Long resolveDahuaDeptId(Long corpId) {
|
||||
if (corpId == null) {
|
||||
return null;
|
||||
|
|
@ -229,6 +243,16 @@ public class DaHuaServiceImpl implements ZcloudDaHuaFacade {
|
|||
return resp;
|
||||
}
|
||||
|
||||
public SingleResponse<DaHuaAccessRecordSyncResultCO> syncAccessRecords(DaHuaAccessRecordSyncCmd cmd) {
|
||||
int pageSize = cmd.getPageSize() == null ? 1000 : cmd.getPageSize();
|
||||
DaHuaAccessRecordSyncResultE result = daHuaAccessRecordSyncApplicationService.sync(
|
||||
cmd.getStartSwingTime(), cmd.getEndSwingTime(), cmd.getStartCreateTime(),
|
||||
cmd.getEndCreateTime(), pageSize);
|
||||
DaHuaAccessRecordSyncResultCO data = new DaHuaAccessRecordSyncResultCO();
|
||||
BeanUtils.copyProperties(result, data);
|
||||
return SingleResponse.of(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleResponse<Object> saveTempVehicle(DaHuaTempVehicleSaveCmd cmd) {
|
||||
cmd.setDepartmentId(resolveDahuaDeptId(cmd.getDepartmentId()));
|
||||
|
|
@ -261,4 +285,15 @@ public class DaHuaServiceImpl implements ZcloudDaHuaFacade {
|
|||
System.out.println("大华临时车辆全量保存最终返回 - success:" + resp.isSuccess() + ", errCode:" + resp.getErrCode() + ", errMessage:" + resp.getErrMessage() + ", data(dhData):" + dhData);
|
||||
return resp;
|
||||
}
|
||||
|
||||
public SingleResponse<DaHuaResourceSyncResultCO> syncResources(DaHuaResourceSyncCmd cmd) {
|
||||
DaHuaResourceSyncCmd actualCmd = cmd == null ? new DaHuaResourceSyncCmd() : cmd;
|
||||
int pageSize = actualCmd.getPageSize() == null ? 200 : actualCmd.getPageSize();
|
||||
boolean autoMatchByName = actualCmd.getAutoMatchByName() == null || actualCmd.getAutoMatchByName();
|
||||
DaHuaResourceSyncResultE result = daHuaResourceSyncApplicationService.sync(
|
||||
pageSize, actualCmd.getSubsystem(), autoMatchByName);
|
||||
DaHuaResourceSyncResultCO data = new DaHuaResourceSyncResultCO();
|
||||
BeanUtils.copyProperties(result, data);
|
||||
return SingleResponse.of(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
package com.zcloud.primeport.domain.gateway;
|
||||
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -29,4 +30,10 @@ public interface DaHuaGateway {
|
|||
Map<String, Object> deleteCar(List<String> carNumList);
|
||||
|
||||
Map<String, Object> queryAccessRecord(DaHuaAccessRecordCmd cmd);
|
||||
}
|
||||
|
||||
String uploadPersonImg(String imageBase64);
|
||||
|
||||
Map<String, Object> saveTempVehicle(DaHuaTempVehicleSaveCmd cmd);
|
||||
|
||||
Long findDahuaDepartmentIdByCorpId(Long corpId);
|
||||
}
|
||||
|
|
@ -25,6 +25,8 @@ 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 UPLOAD_PERSON_IMG_URL = "/evo-apigw/evo-brm/1.0.0/person/uploadFace";
|
||||
private static final String TEMP_VEHICLE_AUDIT_URL = "/evo-apigw/evo-brm/1.0.0/tempVehicle/saveAudit";
|
||||
|
||||
public boolean isConfigured() {
|
||||
return daHuaApiClient != null;
|
||||
|
|
@ -131,4 +133,26 @@ 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<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "bearer " + token);
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("faceData", imageBase64);
|
||||
return daHuaApiClient.postJson(UPLOAD_PERSON_IMG_URL, body, headers);
|
||||
}
|
||||
|
||||
public GeneralResponse saveTempVehicleAudit(Map<String, Object> body) throws ClientException {
|
||||
if (daHuaApiClient == null) {
|
||||
return null;
|
||||
}
|
||||
String token = daHuaApiClient.getToken();
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "bearer " + token);
|
||||
return daHuaApiClient.postJson(TEMP_VEHICLE_AUDIT_URL, body, headers);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue