|
@@ -23,10 +23,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.LinkedBlockingQueue;
|
|
|
-import java.util.concurrent.ThreadPoolExecutor;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -57,6 +54,9 @@ public class WeComUserDetailJob {
|
|
|
@Value("${create.room.member.max.nums:40}")
|
|
|
private Integer memberMaxNums;
|
|
|
|
|
|
+ @Value("${create.room.auto.send.msg:false}")
|
|
|
+ private Boolean autoSendMsg;
|
|
|
+
|
|
|
private final static ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.SECONDS,
|
|
|
new LinkedBlockingQueue<>(1000),
|
|
|
new ThreadFactoryBuilder().setNameFormat("SyncUserDetailJob-%d").build(),
|
|
@@ -65,29 +65,36 @@ public class WeComUserDetailJob {
|
|
|
@XxlJob("syncUserDetail")
|
|
|
public ReturnT<String> syncUserDetail(String param) {
|
|
|
List<ThirdPartWeComStaff> activeStaffList = thirdPartyService.getActiveStaffList();
|
|
|
+ CountDownLatch cdl = new CountDownLatch(activeStaffList.size());
|
|
|
for (ThirdPartWeComStaff staff : activeStaffList) {
|
|
|
pool.execute(() -> {
|
|
|
- String uuid = staff.getThirdUuid();
|
|
|
- String offLineKey = "wecom:thirdpart:offline:" + uuid;
|
|
|
- if (redisUtils.containsKey(offLineKey)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- String response = apiClient.getRunClientByUuid(new UuidRequest(uuid));
|
|
|
- CommonResponse<LoginInfo> commonResponse =
|
|
|
- JSONObject.parseObject(response, new TypeReference<CommonResponse<LoginInfo>>() {});
|
|
|
- if (commonResponse.getErrcode() != 0) {
|
|
|
- return;
|
|
|
- } else {
|
|
|
- LoginInfo loginInfo = commonResponse.getData();
|
|
|
- staff.setAvatar(loginInfo.getUser_info().getObject().getAvatar());
|
|
|
- staff.setName(loginInfo.getUser_info().getObject().getNickname());
|
|
|
- staff.setUpdateTime(new Date());
|
|
|
- staffMapper.updateByPrimaryKeySelective(staff);
|
|
|
+ try {
|
|
|
+ String uuid = staff.getThirdUuid();
|
|
|
+ String offLineKey = "wecom:thirdpart:offline:" + uuid;
|
|
|
+ if (redisUtils.containsKey(offLineKey)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String response = apiClient.getRunClientByUuid(new UuidRequest(uuid));
|
|
|
+ CommonResponse<LoginInfo> commonResponse =
|
|
|
+ JSONObject.parseObject(response, new TypeReference<CommonResponse<LoginInfo>>() {
|
|
|
+ });
|
|
|
+ if (commonResponse.getErrcode() == 0) {
|
|
|
+ LoginInfo loginInfo = commonResponse.getData();
|
|
|
+ staff.setAvatar(loginInfo.getUser_info().getObject().getAvatar());
|
|
|
+ staff.setName(loginInfo.getUser_info().getObject().getNickname());
|
|
|
+ staff.setUpdateTime(new Date());
|
|
|
+ staffMapper.updateByPrimaryKeySelective(staff);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ cdl.countDown();
|
|
|
}
|
|
|
- syncRoomList(uuid, staff);
|
|
|
- syncStaffUserList(uuid, staff);
|
|
|
});
|
|
|
}
|
|
|
+ try {
|
|
|
+ cdl.await();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("syncUserDetail error", e);
|
|
|
+ }
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -172,8 +179,20 @@ public class WeComUserDetailJob {
|
|
|
@XxlJob("syncRoomDetail")
|
|
|
public ReturnT<String> syncRoomDetail(String param) {
|
|
|
List<ThirdPartWeComStaff> activeStaffList = thirdPartyService.getActiveStaffList();
|
|
|
+ CountDownLatch cdl = new CountDownLatch(activeStaffList.size());
|
|
|
for (ThirdPartWeComStaff staff : activeStaffList) {
|
|
|
- pool.execute(() -> syncRoomList(staff.getThirdUuid(), staff));
|
|
|
+ pool.execute(() -> {
|
|
|
+ try {
|
|
|
+ syncRoomList(staff.getThirdUuid(), staff);
|
|
|
+ } finally {
|
|
|
+ cdl.countDown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ cdl.await();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("syncRoomDetail error", e);
|
|
|
}
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
@@ -209,10 +228,10 @@ public class WeComUserDetailJob {
|
|
|
roomDetail.setName(roomInfo.getNickname());
|
|
|
roomDetail.setUpdateTime(new Date());
|
|
|
if (staff.getAutoCreateRoom() == 1) {
|
|
|
- if (roomDetail.getMemberCount() >= memberMaxNums){
|
|
|
+ if (roomDetail.getMemberCount() >= memberMaxNums) {
|
|
|
roomDetail.setAddUserStatus(0);
|
|
|
}
|
|
|
- if (roomDetail.getMemberCount() >= sendMsgStatusNums) {
|
|
|
+ if (roomDetail.getMemberCount() >= sendMsgStatusNums && autoSendMsg) {
|
|
|
roomDetail.setSendStatus(1);
|
|
|
}
|
|
|
}
|