wangyunpeng hace 3 semanas
padre
commit
9acb3cc4f1

+ 22 - 0
api-module/src/test/java/com/tzld/piaoquan/api/WeComTest.java

@@ -0,0 +1,22 @@
+package com.tzld.piaoquan.api;
+
+import com.tzld.piaoquan.offline.job.WeComStaffDataJob;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest(classes = GrowthServerApplication.class)
+@Slf4j
+public class WeComTest {
+
+    @Autowired
+    WeComStaffDataJob weComStaffDataJob;
+
+    @Test
+    public void syncStaffJob() {
+        weComStaffDataJob.syncStaff("");
+    }
+
+
+}

+ 3 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/common/constant/WeComConstant.java

@@ -35,6 +35,9 @@ public interface WeComConstant {
     //获取配置了客户联系功能的成员列表
     String GET_WE_COM_FOLLOW_USER_LIST = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list";
 
+    //获取配置了客户联系功能的成员详情
+    String GET_WE_COM_FOLLOW_USER_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/user/get";
+
     //获取企业客户标签详情
     String POST_CORP_TAG_LIST = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list";
 

+ 34 - 5
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComStaffDataJob.java

@@ -9,9 +9,7 @@ import com.tzld.piaoquan.growth.common.dao.mapper.*;
 import com.tzld.piaoquan.growth.common.model.bo.XxlJobParam;
 import com.tzld.piaoquan.growth.common.model.po.*;
 import com.tzld.piaoquan.growth.common.service.WeComAccessTokenService;
-import com.tzld.piaoquan.growth.common.service.WeComSendService;
 import com.tzld.piaoquan.growth.common.utils.DateUtil;
-import com.tzld.piaoquan.growth.common.utils.DateUtils;
 import com.tzld.piaoquan.growth.common.utils.LarkRobotUtil;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
@@ -25,6 +23,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 import static com.tzld.piaoquan.growth.common.common.constant.WeComConstant.*;
@@ -57,8 +56,8 @@ public class WeComStaffDataJob {
     @Autowired
     private CorpStatisticsTotalMapper corpStatisticsTotalMapper;
 
-    @XxlJob("insertStaffJob")
-    public ReturnT<String> insertStaff(String param) {
+    @XxlJob("syncStaffJob")
+    public ReturnT<String> syncStaff(String param) {
         try {
             XxlJobParam xxlJobParam = new XxlJobParam();
             if (StringUtils.isNotEmpty(param)) {
@@ -78,6 +77,7 @@ public class WeComStaffDataJob {
                     continue;
                 }
                 for (String carrierId : carrierIdList) {
+                    JSONObject carrierInfo = getCarrierInfo(corp.getId(), carrierId);
                     StaffExample example = new StaffExample();
                     example.createCriteria().andCarrierIdEqualTo(carrierId).andCorpIdEqualTo(corp.getId());
                     List<Staff> staffList = staffMapper.selectByExample(example);
@@ -85,8 +85,18 @@ public class WeComStaffDataJob {
                         Staff staff = new Staff();
                         staff.setCorpId(corp.getId());
                         staff.setCarrierId(carrierId);
-                        staff.setRemark("");
+                        if (Objects.nonNull(carrierInfo) && carrierInfo.containsKey("name")) {
+                            staff.setRemark(carrierInfo.getString("name"));
+                        } else {
+                            staff.setRemark("");
+                        }
                         staffMapper.insert(staff);
+                    } else {
+                        Staff staff = staffList.get(0);
+                        if (Objects.nonNull(carrierInfo) && carrierInfo.containsKey("name")) {
+                            staff.setRemark(carrierInfo.getString("name"));
+                            staffMapper.updateByPrimaryKeySelective(staff);
+                        }
                     }
                 }
             }
@@ -115,6 +125,25 @@ public class WeComStaffDataJob {
         return null;
     }
 
+    private JSONObject getCarrierInfo(Long corpId, String userId) throws IOException {
+        String weComAccessToken = weComAccessTokenService.getWeComAccessToken(corpId);
+        String url = String.format(GET_WE_COM_FOLLOW_USER_DETAIL + "?access_token=%s", weComAccessToken);
+        url = String.format(url + "&userid=%s", userId);
+        String res;
+        if (corpId == 1L) {
+            res = httpPoolClient.get(url);
+        } else {
+            res = proxyHttpPoolClient.get(url);
+        }
+        log.info("getCarrierInfo corp = {} , userId = {}, res={}", corpId, userId, res);
+        JSONObject jsonObject = JSONObject.parseObject(res);
+        Integer errcode = jsonObject.getInteger("errcode");
+        if (errcode == 0) {
+            return jsonObject;
+        }
+        return null;
+    }
+
     @XxlJob("statisticsTotalJob")
     public ReturnT<String> statisticsTotal(String param) throws IOException {
         String date;