fix: 加锁,限制并发导致数据重复
This commit is contained in:
parent
ec06ed2272
commit
9f02f730c9
|
@ -56,6 +56,10 @@ public class GenericEventConsumer {
|
||||||
public static final String GETUSERAPPCODE="8000050001";
|
public static final String GETUSERAPPCODE="8000050001";
|
||||||
//获取钉钉部门详情接口编码
|
//获取钉钉部门详情接口编码
|
||||||
public static final String GETDETPAPPCODE="8000050002";
|
public static final String GETDETPAPPCODE="8000050002";
|
||||||
|
//user锁对象
|
||||||
|
static final Object userLockObj = new Object();
|
||||||
|
//dept部门锁
|
||||||
|
static final Object deptLockObj = new Object();
|
||||||
/**
|
/**
|
||||||
* 消费通讯录事件订阅消息
|
* 消费通讯录事件订阅消息
|
||||||
*
|
*
|
||||||
|
@ -95,21 +99,33 @@ public class GenericEventConsumer {
|
||||||
}
|
}
|
||||||
if (flag){
|
if (flag){
|
||||||
if ("user".equals(type)){
|
if ("user".equals(type)){
|
||||||
JSONArray userIds = bizData.getJSONArray("userId");
|
synchronized (userLockObj) {
|
||||||
//调用钉钉查询用户详情接口
|
JSONArray userIds = bizData.getJSONArray("userId");
|
||||||
for (int i=0; i<userIds.size();i++){
|
//调用钉钉查询用户详情接口
|
||||||
//获取用户详情
|
for (int i=0; i<userIds.size();i++){
|
||||||
String userRes = getUserById(String.valueOf(userIds.get(i)));
|
try {
|
||||||
//保存钉钉用户到mdm
|
//获取用户详情
|
||||||
String userMdmRes = createUser(userRes,eventType);
|
String userRes = getUserById(String.valueOf(userIds.get(i)));
|
||||||
|
//保存钉钉用户到mdm
|
||||||
|
String userMdmRes = createUser(userRes,eventType);
|
||||||
|
}catch (Exception ex ){
|
||||||
|
logger.error("钉钉用户保存到主数据报错:{}",ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else if ("dept".equals(type)){
|
}else if ("dept".equals(type)){
|
||||||
JSONArray deptIdArr = bizData.getJSONArray("deptId");
|
synchronized (deptLockObj){
|
||||||
for (int i=0; i<deptIdArr.size(); i++){
|
try {
|
||||||
//查询部门详情
|
JSONArray deptIdArr = bizData.getJSONArray("deptId");
|
||||||
String deptRes = getDeptById(deptIdArr.getLong(i));
|
for (int i=0; i<deptIdArr.size(); i++){
|
||||||
//保存部门到mdm
|
//查询部门详情
|
||||||
String deptMdmRes = createDept(deptRes,apiCode);
|
String deptRes = getDeptById(deptIdArr.getLong(i));
|
||||||
|
//保存部门到mdm
|
||||||
|
String deptMdmRes = createDept(deptRes,apiCode);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("钉钉部门保存到主数据报错:{}",e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue