Преглед изворни кода

用户创建时同步详情

wangyunpeng пре 2 недеља
родитељ
комит
c03a0c717b

+ 25 - 21
api-module/src/main/java/com/tzld/piaoquan/api/job/wecom/thirdpart/WeComUserDetailJob.java

@@ -79,27 +79,7 @@ public class WeComUserDetailJob {
         for (ThirdPartWeComStaff staff : activeStaffList) {
             pool.execute(() -> {
                 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.setName(loginInfo.getUser_info().getObject().getNickname());
-                        staff.setRealName(loginInfo.getUser_info().getObject().getRealname());
-                        staff.setMobile(loginInfo.getUser_info().getObject().getMobile());
-                        staff.setAvatar(loginInfo.getUser_info().getObject().getAvatar());
-                        staff.setName(loginInfo.getUser_info().getObject().getNickname());
-                        staff.setUpdateTime(new Date());
-                        staffMapper.updateByPrimaryKeySelective(staff);
-                    }
-                    syncRoomList(staff);
-                    syncStaffUserList(staff);
+                    syncStaffUserDetail(staff);
                 } catch (Exception e) {
                     log.error("syncUserDetail error", e);
                 } finally {
@@ -115,6 +95,30 @@ public class WeComUserDetailJob {
         return ReturnT.SUCCESS;
     }
 
+    public void syncStaffUserDetail(ThirdPartWeComStaff staff) {
+        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.setName(loginInfo.getUser_info().getObject().getNickname());
+            staff.setRealName(loginInfo.getUser_info().getObject().getRealname());
+            staff.setMobile(loginInfo.getUser_info().getObject().getMobile());
+            staff.setAvatar(loginInfo.getUser_info().getObject().getAvatar());
+            staff.setName(loginInfo.getUser_info().getObject().getNickname());
+            staff.setUpdateTime(new Date());
+            staffMapper.updateByPrimaryKeySelective(staff);
+        }
+        syncRoomList(staff);
+        syncStaffUserList(staff);
+    }
+
     private void syncStaffUserList(ThirdPartWeComStaff staff) {
         List<ExternalContactsResponse.ContactItem> contactItemList = thirdPartyService.getExternalContacts(
                 new GetExternalContactsRequest(staff.getThirdUuid(), 100, 0));

+ 7 - 0
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/impl/WeComThirdPartyServiceImpl.java

@@ -12,6 +12,7 @@ import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComCorpMapper
 import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComRoomMapper;
 import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComStaffMapper;
 import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext.ThirdPartWeComMapperExt;
+import com.tzld.piaoquan.api.job.wecom.thirdpart.WeComUserDetailJob;
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.*;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.*;
 import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyService;
@@ -41,6 +42,8 @@ public class WeComThirdPartyServiceImpl implements WeComThirdPartyService {
     @Autowired
     private WeComThirdPartyApiClient apiClient;
     @Autowired
+    private WeComUserDetailJob weComUserDetailJob;
+    @Autowired
     private ThirdPartWeComStaffMapper thirdPartWeComStaffMapper;
     @Autowired
     private ThirdPartWeComRoomMapper thirdPartWeComRoomMapper;
@@ -177,6 +180,10 @@ public class WeComThirdPartyServiceImpl implements WeComThirdPartyService {
         }
         saveStaffQrCode(uuid);
 
+        // 同步用户详情
+        ThirdPartWeComStaff staff = getStaffByUuid(uuid);
+        weComUserDetailJob.syncStaffUserDetail(staff);
+
         // 清除掉线检测
         String offLineKey = "wecom:thirdpart:offline:" + uuid;
         redisUtils.del(offLineKey);