同步isc的bug修复

This commit is contained in:
guoshengxiong 2025-09-29 17:08:25 +08:00
parent c01312e639
commit 770cdef165
6 changed files with 83 additions and 51 deletions

View File

@ -142,7 +142,7 @@ public class AsyncHikvision {
* @param isSaveWorkerFace
* @return
*/
@Async("workerHkExecutor")
@Async("doubleCarbonExecutor")
public void addWorkerAndAuthAsync(WorkerInfo workerInfo, boolean isSaveWorker, boolean isSaveWorkerFace) {
addWorkerAsync(workerInfo, true, true);
projectUfaceConfigService.addWorkerInfo(workerInfo);
@ -155,7 +155,7 @@ public class AsyncHikvision {
* @param isSaveWorker
* @param isSaveWorkerFace
*/
@Async("workerHkExecutor")
@Async("doubleCarbonExecutor")
public void addWorkerAsync(WorkerInfo workerInfo, boolean isSaveWorker, boolean isSaveWorkerFace) {
try {
hikvisionCall.saveWorker(workerInfo, isSaveWorker, isSaveWorkerFace);
@ -183,7 +183,7 @@ public class AsyncHikvision {
* @param isSaveWorker
* @param isSaveWorkerFace
*/
@Async("workerHkExecutor")
@Async("doubleCarbonExecutor")
public void editWorkerAndAuthAsync(WorkerInfo workerInfo, boolean isSaveWorker, boolean isSaveWorkerFace) {
this.saveWorkerAsync(workerInfo, true, true);
projectUfaceConfigService.updateWorkerInfo(workerInfo, workerInfo);
@ -207,7 +207,7 @@ public class AsyncHikvision {
* @param isSaveWorker
* @param isSaveWorkerFace
*/
@Async("workerHkExecutor")
@Async("doubleCarbonExecutor")
public void saveWorkerAsync(WorkerInfo workerInfo, boolean isSaveWorker, boolean isSaveWorkerFace) {
try {
hikvisionCall.saveWorker(workerInfo, isSaveWorker, isSaveWorkerFace);
@ -585,7 +585,7 @@ public class AsyncHikvision {
* @param sendNotice
* @param flowStartUser
*/
@Async("workerAuthHkExecutor")
@Async("doubleCarbonExecutor")
public void sendBatchWorkerInfoAsync(List<UfaceDev> allDevList, List<WorkerInfo> workerList, List<JSONObject> workerAndDevSnList, Long userId, String projectSn, boolean checkEditWorkers, boolean sendNotice, Long flowStartUser) {
try {
if (CollUtil.isNotEmpty(workerAndDevSnList)) {
@ -857,37 +857,11 @@ public class AsyncHikvision {
//权限下发后进度100后查询权限条目列表人员列表设备列表接口去查返回参数有权限状态返回已下载的就是有权限
List<String> workerIds = devSnToJoEntry.getValue().stream().map(jsonObject -> jsonObject.getString("workerId")).collect(Collectors.toList());
JSONArray qaiList = this.queryAuthItemByWorkerList(project, workerIds, getDevRqParam(iscDevSnObj));
Set<String> rtWorkerIdSet;
if (CollUtil.isNotEmpty(qaiList)) {
for (int i = 0; i < qaiList.size(); i++) {
handlerBatchWorkersResult(workerIdMap, addAuthWorkerIds, sendNotice, dev, flowStartUser, qaiList.getJSONObject(i));
}
rtWorkerIdSet = qaiList.stream().map(o -> ((JSONObject) o).getString("personId")).collect(Collectors.toSet());
} else {
rtWorkerIdSet = new HashSet<>();
}
//处理删除权限的结果的
//1. 删除权限配置还没删除的时候权限变成 2更新待删除
//2. 删除以后删除的权限状态是 4未配置
//3. 这个人的权限都没了以后你就查不到这个权限条目了
//handlerBatchWorkersResultForDeleteAuth();
if (sendNotice && CollUtil.isNotEmpty(deleteAuthWorkerIds)) {
for (String workerId : deleteAuthWorkerIds) {
if (rtWorkerIdSet.contains(workerId)) {
//已经处理过了
continue;
}
hikvisionCall.updateSuccessStatus(projectSn, Long.valueOf(workerId), 3, 3, devSn);
Set<Long> noticeUserIds = hikvisionCall.getNoticeUserIds(flowStartUser, projectSn);
for (Long noticeUserId : noticeUserIds) {
noticeService.addUserNotice(noticeUserId,
"人员下发设备提醒", StrUtil.format("[{}]取消下发到[{}]{}",
workerIdMap.get(workerId).getWorkerName(),
dev.getDevName(),
"成功"),
"10");
}
}
Map<String, Integer> personId2FaceStatusMap = qaiList.stream().collect(Collectors.toMap(o -> ((JSONObject) o).getString("personId"), o -> ((JSONObject) o).getInteger("faceStatus"), (o1, o2) -> o1));
for (int i = 0; i < workerIds.size(); i++) {
String workerId = workerIds.get(i);
Integer faceStatus = personId2FaceStatusMap.get(workerId);
handlerBatchWorkersResult(workerIdMap, addAuthWorkerIds, sendNotice, dev, flowStartUser, workerId, faceStatus);
}
} catch (Exception e) {
log.error("批量下发权限失败:", e);
@ -963,14 +937,15 @@ public class AsyncHikvision {
/**
* 处理结果一个设备批量下发人员
*
* @param personId
* @param faceStatus
* @param workerIdMap
* @param addAuthWorkerIds
* @param sendNotice
* @param dev
* @param flowStartUser
*/
public void handlerBatchWorkersResult(Map<String, WorkerInfo> workerIdMap, List<String> addAuthWorkerIds, boolean sendNotice, UfaceDev dev, Long flowStartUser, JSONObject jo) {
String personId = jo.getString("personId");
public void handlerBatchWorkersResult(Map<String, WorkerInfo> workerIdMap, List<String> addAuthWorkerIds, boolean sendNotice, UfaceDev dev, Long flowStartUser, String personId, Integer faceStatus) {
String workerName = workerIdMap.get(personId).getWorkerName();
log.info("处理结果一个设备批量下发人员:{},{}", workerName, dev.getDevName());
String projectSn = dev.getProjectSn();
@ -983,7 +958,6 @@ public class AsyncHikvision {
//1. 删除权限配置还没删除的时候权限变成 2更新待删除
//2. 删除以后删除的权限状态是 4未配置
//3. 这个人的权限都没了以后你就查不到这个权限条目了
Integer faceStatus = jo.getInteger("faceStatus");
if (sendNotice) {
if (addAuthWorkerIds.contains(personId)) {
//添加权限
@ -1009,7 +983,7 @@ public class AsyncHikvision {
} else {
//删除权限
int deleteAuth = 4;
if (Objects.equals(faceStatus, deleteAuth)) {
if (Objects.equals(faceStatus, deleteAuth) || faceStatus == null) {
hikvisionCall.updateSuccessStatus(projectSn, Long.valueOf(personId), 3, 3, dev.getDevSn());
} else {
hikvisionCall.updateFailStatus(projectSn, Long.valueOf(personId), 3, 3, dev.getDevSn());

View File

@ -83,7 +83,7 @@ public class AsyncWorker {
*
* @param
*/
@Async("workerAuthHkExecutor")
@Async("doubleCarbonExecutor")
public void sendBatchWokerDevAsync(Map<String, Object> map, ProjectUfaceConfig projectUfaceConfig, List<UfaceDev> allDevList) {
try {
Long userId = MapUtils.getLong(map, "userId");

View File

@ -1206,6 +1206,7 @@ public class HikvisionCall {
lock.tryLock(100L, TimeUnit.SECONDS);
boolean existOrg = existOrg(project, String.valueOf(departmentInfo.getId()), hikvisionOrganization.getParentIndexCode());
if (!existOrg) {
renameOrgIfExistRepeatOrgName(departmentInfo.getDepartmentName() + Cts.ISC_SYNC_DEPARTMENT_SUFFIX, hikvisionOrganization.getParentIndexCode(), project);
addDepartmentInfoForHikvision(departmentInfo);
}
} catch (Exception e) {
@ -1226,16 +1227,21 @@ public class HikvisionCall {
* @throws Exception
*/
private void saveIfNotExistTeam(WorkerInfo workerInfo, Project project) throws Exception {
boolean existOrg = hikvisionCall.existOrg(project, workerInfo.getTeamId() + "", StringsUtils.getUniqueEnterpriseId(workerInfo.getEnterpriseId(), workerInfo.getProjectSn()));
String parentOrgId = StringsUtils.getUniqueEnterpriseId(workerInfo.getEnterpriseId(), workerInfo.getProjectSn());
boolean existOrg = hikvisionCall.existOrg(project, workerInfo.getTeamId() + "", parentOrgId);
if (!existOrg) {
RLock lock = null;
try {
String lockKey = "isc_org_team_add:" + workerInfo.getTeamId();
lock = redissonClient.getLock(lockKey);
lock.tryLock(100L, TimeUnit.SECONDS);
existOrg = hikvisionCall.existOrg(project, workerInfo.getTeamId() + "", StringsUtils.getUniqueEnterpriseId(workerInfo.getEnterpriseId(), workerInfo.getProjectSn()));
existOrg = hikvisionCall.existOrg(project, workerInfo.getTeamId() + "", parentOrgId);
if (!existOrg) {
TeamInfo teamInfo = teamInfoService.getById(workerInfo.getTeamId());
if (teamInfo == null) {
throw new OpenAlertException("工种不存在");
}
renameOrgIfExistRepeatOrgName(teamInfo.getTeamName() + Cts.ISC_SYNC_TEAM_SUFFIX, parentOrgId, project);
addTeamInfoForHikvision(teamInfo);
}
} catch (Exception e) {
@ -1412,7 +1418,11 @@ public class HikvisionCall {
Optional<JSONArray> fOp = Optional.ofNullable(dataJo).map(o -> o.getJSONArray("failures"));
if (fOp.isPresent() && fOp.get().size() != 0) {
if (X_00052102.equals(fOp.get().getJSONObject(0).getString(CODE))) {
msg = "同步失败,组织名称:" + orgName + "。失败原因:上级组织不存在";
if ("OrgName Exists In DB".equals(fOp.get().getJSONObject(0).getString("message"))) {
msg = "同步失败,组织名称:" + orgName + "。失败原因:组织已存在";
} else {
msg = "同步失败,组织名称:" + orgName + "。失败原因:上级组织不存在";
}
title += FAIL;
success = false;
} else {
@ -2564,8 +2574,10 @@ public class HikvisionCall {
EnterpriseInfo enterpriseInfo = enterpriseInfoService.getOne(new LambdaQueryWrapper<EnterpriseInfo>()
.eq(EnterpriseInfo::getId, enterpriseId).last(Cts.IGNORE_DATA_SCOPE_CONDITION));
String orgIndexCode = StringsUtils.getUniqueEnterpriseId(enterpriseInfo.getId(), project.getProjectSn());
//1.根据id查2.不存在就根据父级id和名称查然后删除
JSONArray orgList = getOrgList(project, orgIndexCode, project.getProjectSn());
if (CollUtil.isEmpty(orgList)) {
renameOrgIfExistRepeatOrgName(enterpriseInfo.getEnterpriseName(), project.getProjectSn(), project);
RLock lock = null;
try {
String lockKey = "isc_org_enterprise_add:" + enterpriseInfo.getId();
@ -2586,6 +2598,28 @@ public class HikvisionCall {
}
}
/**
* 重命名在isc上面创建的重复名称的组织
*
* @param orgName
* @param parentOrgIndexCode
* @param project
* @throws Exception
*/
private void renameOrgIfExistRepeatOrgName(String orgName, String parentOrgIndexCode, Project project) throws Exception {
JSONArray orgListByOrgName = getOrgListByOrgName(project, orgName, parentOrgIndexCode);
if (CollUtil.isNotEmpty(orgListByOrgName)) {
JSONObject jsonObject = orgListByOrgName.getJSONObject(0);
log.info("重命名在isc上面创建的重复名称的组织{}", jsonObject.getString("orgName"));
HikvisionOrganization hikvisionOrganization = new HikvisionOrganization();
hikvisionOrganization.setClientId(null);
hikvisionOrganization.setOrgIndexCode(jsonObject.getString("orgIndexCode"));
hikvisionOrganization.setOrgName(orgName + DateUtil.format(new Date(),"yyyyMMddHHmm"));
hikvisionOrganization.setParentIndexCode(jsonObject.getString("parentOrgIndexCode"));
HikvisionUtil.editOrg(project, hikvisionOrganization);
}
}
/**
* 删除组织
*
@ -2645,6 +2679,29 @@ public class HikvisionCall {
return jo.getJSONArray(LIST);
}
/**
* 根据组织名称查询组织包含下级组织=查询
*
* @param project
* @param orgName 组织名称
* @param parentOrgIndexCode
* @return
*/
private JSONArray getOrgListByOrgName(Project project, String orgName, String parentOrgIndexCode) throws Exception {
JSONObject param = new JSONObject();
param.put("pageNo", 1);
param.put("pageSize", 1000);
param.put("orgName", orgName);
param.put("parentOrgIndexCodes", parentOrgIndexCode);
String rs = HikvisionUtil.getOrgV2(project, param);
JSONObject jo = HikvisionUtil.getJsonObjectData(rs);
JSONArray jsonArray = jo.getJSONArray(LIST);
if (CollUtil.isEmpty(jsonArray)) {
return jsonArray;
}
return new JSONArray(jsonArray.stream().filter(o -> Objects.equals(((JSONObject) o).getString("orgName"), orgName)).collect(Collectors.toList()));
}
/**
* 映射isc的组织
*

View File

@ -20,11 +20,11 @@ public class AsyncConfig {
/**
* Set the ThreadPoolExecutor's core pool size.
*/
private int corePoolSize = 8;
private int corePoolSize = Runtime.getRuntime().availableProcessors();
/**
* Set the ThreadPoolExecutor's maximum pool size.
*/
private int maxPoolSize = 16;
private int maxPoolSize = Runtime.getRuntime().availableProcessors() * 2;
/**
* Set the capacity for the ThreadPoolExecutor's BlockingQueue.
*/
@ -71,10 +71,10 @@ public class AsyncConfig {
public ThreadPoolTaskExecutor doubleCarbonExecutor() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
executor.setCorePoolSize(corePoolSize * 9);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setMaxPoolSize(maxPoolSize * 18);
executor.setQueueCapacity(queueCapacity * 100);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */

View File

@ -511,6 +511,7 @@ public class ProjectUfaceConfigServiceImpl extends ServiceImpl<ProjectUfaceConfi
//清除以前的记录
xzHikvisionSyncMapper.delete(new LambdaQueryWrapper<XzHikvisionSync>()
.eq(XzHikvisionSync::getBigType, 1)
.eq(XzHikvisionSync::getType, 3)
.eq(XzHikvisionSync::getWhoId, workerInfo.getId())
);
for (String ds : StrUtil.split(devSns, Cts.COMMA)) {

View File

@ -143,10 +143,10 @@ public class HikvisionTask {
* 定时一分钟获取海康数据
*/
@SchedulerLock(name = "getRecordForHikvision", lockAtMostFor = 1000 * 30, lockAtLeastFor = 1000 * 30)
@Scheduled(cron = "0 */1 * * * ?")
@Scheduled(cron = "0 */2 * * * ?")
@RequestMapping("getRecordForHikvision")
public void getRecordForHikvision() {
String startTime = DateUtil.formatDateTime(DateUtil.offsetMinute(new Date(), -2));
String startTime = DateUtil.formatDateTime(DateUtil.offsetMinute(new Date(), -5));
String endTime = DateUtil.formatDateTime(new Date());
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>()
.eq(Project::getSyncHikvision, 1));