소스 검색

更新员工任务

xueyiming 6 달 전
부모
커밋
e504c42204

+ 2 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/common/constant/WeComConstant.java

@@ -48,4 +48,6 @@ public interface WeComConstant {
     //external_userid转换
     String POST_WE_COM_EXTERNAL_USER_ID = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/from_service_external_userid";
 
+    //获取配置了客户联系功能的成员列表
+    String GET_WE_COM_FOLLOW_USER_LIST = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list";
 }

+ 65 - 1
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComStaffDataJob.java

@@ -1,9 +1,73 @@
 package com.tzld.piaoquan.wecom.job;
 
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.wecom.dao.mapper.StaffMapper;
+import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
+import com.tzld.piaoquan.wecom.model.po.Staff;
+import com.tzld.piaoquan.wecom.model.po.StaffExample;
+import com.tzld.piaoquan.wecom.service.AccessTokenService;
+import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
+import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
+import com.tzld.piaoquan.wecom.utils.LarkRobotUtil;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.GET_WE_COM_EXTERNAL_CONTACT_LIST;
+import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.GET_WE_COM_FOLLOW_USER_LIST;
+
+@Slf4j
 @Component
 public class WeComStaffDataJob {
 
-    
+    private static final HttpPoolClient httpPoolClientDefault = HttpClientUtil.create(30000, 30000, 2000, 5000, 5, 30000);
+
+
+    @Autowired
+    private AccessTokenService accessTokenService;
+
+    @Autowired
+    private StaffMapper staffMapper;
+
+    @XxlJob("insertStaffJob")
+    public ReturnT<String> insertStaff(String param) {
+        try {
+            List<String> carrierIdList = getCarrierIdList();
+            for (String carrierId: carrierIdList){
+                StaffExample example = new StaffExample();
+                example.createCriteria().andCarrierIdEqualTo(carrierId);
+                List<Staff> staffList = staffMapper.selectByExample(example);
+                if(CollectionUtils.isEmpty(staffList)){
+                    Staff staff = new Staff();
+                    staff.setCarrierId(carrierId);
+                    staff.setRemark("");
+                }
+            }
+        }catch (Exception e){
+            LarkRobotUtil.sendMessage("更新员工失败");
+            log.error("insertStaff error",e);
+        }
+        return ReturnT.SUCCESS;
+    }
+
+    public List<String> getCarrierIdList() throws IOException {
+        String weComAccessToken = accessTokenService.getWeComAccessToken();
+        String url = String.format(GET_WE_COM_FOLLOW_USER_LIST + "?access_token=%s", weComAccessToken);
+        String res = httpPoolClientDefault.get(url);
+        JSONObject jsonObject = JSONObject.parseObject(res);
+        Integer errcode = jsonObject.getInteger("errcode");
+        if (errcode == 0) {
+            return jsonObject.getJSONArray("follow_user").stream().map(String::valueOf).collect(Collectors.toList());
+        }
+        return null;
+    }
+
 }