每日00:20二级门禁人员定时任务(含手机号变更 身份证兜底查询逻辑)
parent
a84d04a9bc
commit
6a16b9484a
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.zcloud.primeport.plan;
|
||||||
|
|
||||||
|
import com.jjb.saas.framework.job.Job;
|
||||||
|
import com.jjb.saas.framework.job.annotation.JobRegister;
|
||||||
|
import com.xxl.job.core.biz.model.ReturnT;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import com.zcloud.primeport.plan.mjDevice.TwoPersonUtil;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class TwoLevelPersonXxlJob implements Job {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TwoPersonUtil twoPersonUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JobRegister(cron = "0 20 0 * * ?", jobDesc = "闭区定时任务,每日00:20进行当日二级门禁可进门人员推送", triggerStatus = 1)
|
||||||
|
@XxlJob("com.zcloud.plan.TwoLevelPersonDockXxlJob")
|
||||||
|
public ReturnT<String> execute(String param) {
|
||||||
|
try {
|
||||||
|
// 二级门禁人员定时对接(含同步一级门禁)
|
||||||
|
twoPersonUtil.scheduledPeopleCompany();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ReturnT.FAIL;
|
||||||
|
}
|
||||||
|
return ReturnT.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -81,14 +81,27 @@ public class TwoPersonUtil {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 定时任务对接人
|
* 定时任务对接人
|
||||||
|
* 单个异常跳过不影响其他人员同步
|
||||||
* */
|
* */
|
||||||
public void scheduledPeopleCompany() throws Exception {
|
public void scheduledPeopleCompany() {
|
||||||
if (!dockFlag.equals(1)) return;
|
if (!dockFlag.equals(1)) return;
|
||||||
List<TwoLevelUser> userList = closedAreaPersonApplyRepository.getDockAuthTmpInfoById(null);
|
List<TwoLevelUser> userList = closedAreaPersonApplyRepository.getDockAuthTmpInfoById(null);
|
||||||
userList.addAll(closedAreaPersonApplyRepository.getDockAuthInfoById(null));
|
userList.addAll(closedAreaPersonApplyRepository.getDockAuthInfoById(null));
|
||||||
dockUserReal(userList);
|
// 二级门禁同步 — 逐个处理,单个失败继续下一个
|
||||||
|
for (TwoLevelUser user : userList) {
|
||||||
|
try {
|
||||||
|
dockUserReal(Collections.singletonList(user));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("二级门禁人员同步失败, userCard=" + user.getUserCard() + ", 原因: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 一级门禁(大华)同步 — 逐个处理,单个失败继续下一个
|
||||||
for (TwoLevelUser item : userList) {
|
for (TwoLevelUser item : userList) {
|
||||||
|
try {
|
||||||
dockOneLevelPerson(item.getUserCard(), item.getUserFaceImages(), item.getUserUid(), item.getUserName());
|
dockOneLevelPerson(item.getUserCard(), item.getUserFaceImages(), item.getUserUid(), item.getUserName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("一级门禁人员同步失败, userCard=" + item.getUserCard() + ", 原因: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,14 +247,24 @@ public class TwoPersonUtil {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对接二级口门人
|
* 对接二级口门人:用户不存在则新增,已存在跳过
|
||||||
|
* 先按手机号查询,手机号查不到则用身份证号(处理手机号变更场景)
|
||||||
*/
|
*/
|
||||||
public void dockLongTermUserAuthLevelTwo(TwoLevelUser towUser) {
|
public void dockLongTermUserAuthLevelTwo(TwoLevelUser towUser) {
|
||||||
// 跟据身份证号查询 这个人有没有一级门禁 没有新增一级门禁
|
|
||||||
if (!dockFlag.equals(1)) return;
|
if (!dockFlag.equals(1)) return;
|
||||||
JSONObject userListByUserCard = HKDeviceUtil.getUserListByPhone(Arrays.asList(towUser.getUserPhone()));
|
// 按手机号查询
|
||||||
if (userListByUserCard.getJSONArray("data").isEmpty()) return;
|
JSONObject phoneResult = HKDeviceUtil.getUserListByPhone(Collections.singletonList(towUser.getUserPhone()));
|
||||||
// 门禁系统里没有这个人,哪么需要把这个人的信息同步过去
|
if (!phoneResult.getJSONObject("data").getJSONArray("list").isEmpty()) {
|
||||||
|
// 手机号查到,用户已存在,无需新增
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 手机号查不到,尝试用身份证号(手机号可能变更了,但身份证号不变)
|
||||||
|
JSONObject idCardResult = HKDeviceUtil.getUserListByUserCard(towUser.getUserCard());
|
||||||
|
if (!idCardResult.getJSONObject("data").getJSONArray("list").isEmpty()) {
|
||||||
|
// 身份证查到 -> 用户存在,只是手机号变了,无需新增
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 手机号和身份证都查不到 -> 海康无此用户,新增
|
||||||
HKDeviceUtil.saveUser(towUser.getUserName(), towUser.getUserCard(), towUser.getUserFaceImagesBase64(), towUser.getUserPhone());
|
HKDeviceUtil.saveUser(towUser.getUserName(), towUser.getUserCard(), towUser.getUserFaceImagesBase64(), towUser.getUserPhone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,16 +278,34 @@ public class TwoPersonUtil {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 给人授权门禁范围
|
* 给人授权门禁范围
|
||||||
|
* 先按手机号批量查询 personId,手机号查不到的用户用身份证号(处理手机号变更场景)
|
||||||
* */
|
* */
|
||||||
public void dockLongAuthTwo(List<TwoLevelUser> userIdList, List<String> resourceInfos, String time) {
|
public void dockLongAuthTwo(List<TwoLevelUser> userIdList, List<String> resourceInfos, String time) {
|
||||||
if (!dockFlag.equals(1)) return;
|
if (!dockFlag.equals(1)) return;
|
||||||
JSONArray jsonArray = new JSONArray();
|
JSONArray userJsonArray = new JSONArray();
|
||||||
List<String> phoneList = userIdList.stream().map(TwoLevelUser::getUserPhone).collect(Collectors.toList());
|
List<String> phoneList = userIdList.stream().map(TwoLevelUser::getUserPhone).collect(Collectors.toList());
|
||||||
List<List<String>> partition = partition(phoneList, 20);
|
List<List<String>> partitions = partition(phoneList, 20);
|
||||||
partition.forEach(item -> {
|
Set<String> foundPhones = new HashSet<>();
|
||||||
|
partitions.forEach(item -> {
|
||||||
// 接口有限制 最多一次查询20个人
|
// 接口有限制 最多一次查询20个人
|
||||||
jsonArray.addAll(HKDeviceUtil.getUserListByPhone(item).getJSONObject("data").getJSONArray("list"));
|
JSONObject result = HKDeviceUtil.getUserListByPhone(item);
|
||||||
|
JSONArray list = result.getJSONObject("data").getJSONArray("list");
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
JSONObject user = list.getJSONObject(i);
|
||||||
|
userJsonArray.add(user);
|
||||||
|
foundPhones.add(user.getStr("phoneNo"));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
// 手机号查不到的用户,用身份证号查(手机号变更后海康仍存旧号,但身份证号不变)
|
||||||
|
for (TwoLevelUser user : userIdList) {
|
||||||
|
if (!foundPhones.contains(user.getUserPhone())) {
|
||||||
|
JSONObject result = HKDeviceUtil.getUserListByUserCard(user.getUserCard());
|
||||||
|
JSONArray list = result.getJSONObject("data").getJSONArray("list");
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
userJsonArray.add(list.getJSONObject(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
ArrayList<JSONObject> objects = new ArrayList<>();
|
ArrayList<JSONObject> objects = new ArrayList<>();
|
||||||
resourceInfos.forEach(item -> {
|
resourceInfos.forEach(item -> {
|
||||||
JSONObject entries = new JSONObject();
|
JSONObject entries = new JSONObject();
|
||||||
|
|
@ -274,8 +315,8 @@ public class TwoPersonUtil {
|
||||||
});
|
});
|
||||||
// 接口有限制 最多一次存1000个人
|
// 接口有限制 最多一次存1000个人
|
||||||
ArrayList<String> userIds = new ArrayList<>();
|
ArrayList<String> userIds = new ArrayList<>();
|
||||||
for (int i = 0; i < jsonArray.size(); i++) {
|
for (int i = 0; i < userJsonArray.size(); i++) {
|
||||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
JSONObject jsonObject = userJsonArray.getJSONObject(i);
|
||||||
userIds.add(jsonObject.getStr("personId"));
|
userIds.add(jsonObject.getStr("personId"));
|
||||||
}
|
}
|
||||||
List<List<String>> partitionUserIds = partition(userIds, 1000);
|
List<List<String>> partitionUserIds = partition(userIds, 1000);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue