Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

yumeng 1 rok temu
rodzic
commit
49ceca0924

+ 5 - 2
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/FeishuController.java

@@ -40,6 +40,8 @@ public class FeishuController {
     CsjResoureJob csjResoureJob;
     @Autowired
     IDianzhongConfigService dianzhongConfigService;
+    @Autowired
+    IFeishuService feishuService;
 
     @Autowired
     IUserLoginRecordService userLoginRecordService;
@@ -54,13 +56,14 @@ public class FeishuController {
 //        unbindWarnPushService.send();
 //        cutGroupRankPushService.send();
 //        reportsByBusinessPushService.test();
-
+        feishuService.uploadAvatar();
 //        csjResoureJob.csjResourceOssJob();
 //    dianzhongConfigService.pullMovieInfo("2025-08-08", 78012L);
 //        dianzhongConfigService.pullChannelInfo();
 //        dianzhongConfigService.pullMovieInfo(str);
 //        dianzhongConfigService.pullMovie();
-    dianzhongConfigService.syncPromoteLinkInfo();
+//        dianzhongConfigService.movieImageToOss();
+//    dianzhongConfigService.syncPromoteLinkInfo();
     }
 
 

+ 15 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/FeishuMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.job.bytedance.data.mapper;
+
+
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface FeishuMapper {
+
+    List<String> getPhoneNumbers();
+
+    int updateAvatar1(@Param("phone") String phonenumber, @Param("avatar") String avatarUrl);
+    int updateAvatar2(@Param("phone") String phonenumber, @Param("avatar") String avatarUrl);
+    int updateAvatar3(@Param("phone") String phonenumber, @Param("avatar") String avatarUrl);
+}

+ 22 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/FeishuMapper.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="cn.com.ctop.job.bytedance.data.mapper.FeishuMapper">
+    <update id="updateAvatar1">
+        update deepthink.sys_user set avatar = #{avatar} where phonenumber = #{phone}
+    </update>
+    <update id="updateAvatar2">
+        update thirtpart.ly_admin set profile_photo = #{avatar} where phone = #{phone}
+    </update>
+    <update id="updateAvatar3">
+        update thirtpart.ly_responsibility_person set profile_photo = #{avatar} where phone = #{phone}
+    </update>
+
+
+    <select id="getPhoneNumbers" resultType="java.lang.String">
+        select phonenumber from deepthink.sys_user where phonenumber is not null and phonenumber != ''
+        union all
+        select phone from thirtpart.ly_admin where phone is not null and phone != ''
+        union all
+        select phone from thirtpart.ly_responsibility_person where phone is not null and phone != ''
+    </select>
+</mapper>

+ 8 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IFeishuService.java

@@ -0,0 +1,8 @@
+package cn.com.ctop.job.bytedance.data.service;
+
+import java.io.IOException;
+
+public interface IFeishuService {
+
+    void uploadAvatar() throws IOException;
+}

+ 257 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/FeishuServiceImpl.java

@@ -0,0 +1,257 @@
+package cn.com.ctop.job.bytedance.data.service.impl;
+
+import cn.com.ctop.job.bytedance.data.mapper.FeishuMapper;
+import cn.com.ctop.job.bytedance.data.service.IFeishuService;
+import cn.com.ctop.job.bytedance.utils.FeishuRobotUtil;
+import cn.com.ctop.job.bytedance.utils.OssProperties;
+import cn.com.ctop.job.bytedance.utils.OssUtil;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class FeishuServiceImpl implements IFeishuService {
+
+    @Autowired
+    OssUtil ossUtil;
+    @Autowired
+    OssProperties ossProperties;
+    @Autowired
+    FeishuMapper feishuMapper;
+    FeishuRobotUtil feishuRobotUtil;
+
+
+    /*
+    电话号码-飞书用户id-头像-oss头像链接
+    ossPath: feishuAvatar/
+    ossName: {phonenumber}.jpg
+    拼接为oss链接 分别存储在sys_user, ly_admin, ly_responsibility_person
+     */
+    public void uploadAvatar() throws IOException {
+        //从三个表里取电话号码
+        List<String> phones = feishuMapper.getPhoneNumbers();
+        //根据电话号码取飞书用户id和头像
+        String token = FeishuRobotUtil.getFsZtTenantToken();
+        Map<String, String> phoneUserId = FeishuRobotUtil.getFsUserIds(token, phones);
+        Map<String, String> userIdPhone = phoneUserId.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey, (v1, v2) -> v1));
+        List<String> userIds = phoneUserId.values().stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
+        Map<String, JSONObject> userInfoMap = FeishuRobotUtil.batchGetUserInfo(token, userIds);
+
+        for (String userId : userIds){
+            JSONObject info = userInfoMap.get(userId);
+            String phone = userIdPhone.get(userId);
+            if (info == null){
+                continue;
+            }
+            JSONObject avatar = info.getJSONObject("avatar");
+            String avatar240Url = avatar.getString("avatar_240");
+            //上传头像到oss
+            String fileName = userId+".jpg";
+            String url = uploadToOss(avatar240Url, fileName);
+            if (url == null){
+                log.error("上传头像失败, userId: "+userId+", phone: "+phone);
+                continue;
+            }
+            //更新三个表的头像oss链接
+            String ossPath = url;
+            String ossUrl = ossProperties.getCsjDomain() + ossPath;
+
+            System.out.println("userId: "+userId+", ossUrl: "+ossUrl);
+
+//            feishuMapper.updateAvatar1(phone, ossUrl);
+            feishuMapper.updateAvatar2(phone, ossUrl);
+            feishuMapper.updateAvatar3(phone, ossUrl);
+        }
+
+    }
+
+
+
+
+    private String uploadToOss(String url, String fileName){
+        String objectKey = "feishu/avatar/" + fileName;
+        try {
+            System.out.println("文件: "+fileName + ", from: " + url);
+            ossUtil.uploadFromUrl(objectKey, url);
+            log.info("上传成功: " + objectKey);
+            return objectKey;
+        } catch (Exception e) {
+            log.error("上传失败: " + e.getMessage(), e);
+            return null;
+        }
+    }
+
+    public static void main(String[] args) {
+
+        String[] s1 = s.split("\n");
+        for (String s2 : s1) {
+            String[] s3 = s2.split("\t");
+            String name = s3[0];
+            String phone = s3[1].replace("+86", "");
+//            String sql = "update thirtpart.ly_responsibility_person set phone='"+phone+"' where (phone is null or phone = '') and name = '"+name+"';";
+            String sql = "update thirtpart.ly_admin set phone='"+phone+"' where (phone is null or phone = '') and name = '"+name+"';";
+            System.out.println(sql);
+        }
+    }
+
+    public static final String s = "马玲\t18145044665\n" +
+            "王建宁\t13718876769\n" +
+            "钱佳伊\t15801252586\n" +
+            "赵枳程\t15601231113\n" +
+            "胡正康\t13260852137\n" +
+            "孙博\t18618376179\n" +
+            "刘思敏\t19520087962\n" +
+            "栾家峰\t18612878117\n" +
+            "杨家丰\t13810483501\n" +
+            "金虎哲\t15011428926\n" +
+            "任东\t17611198869\n" +
+            "张韦\t18600831511\n" +
+            "张雯\t15801310402\n" +
+            "于洋\t15810643158\n" +
+            "王舒\t18513680330\n" +
+            "李亮\t18734678338\n" +
+            "安高奇\t13121136226\n" +
+            "黄平康\t18640301560\n" +
+            "赵彤鑫\t15110062501\n" +
+            "许圣琪\t13052877377\n" +
+            "武超\t18515555712\n" +
+            "赵西安\t15510197549\n" +
+            "李宁\t13264077236\n" +
+            "任宇鹏\t15011435553\n" +
+            "贺立强\t18533203386\n" +
+            "于蒙\t15611695226\n" +
+            "胡晓俞\t15544803608\n" +
+            "赵子淼\t13040310068\n" +
+            "杨宗霖\t17611102020\n" +
+            "刘峰\t18062736618\n" +
+            "郭昶\t13722875115\n" +
+            "张洺滈\t15841381153\n" +
+            "赵世佳\t13501271209\n" +
+            "葛涛\t15157189122\n" +
+            "陈玲\t18759876639\n" +
+            "陶梦茹\t19155507268\n" +
+            "杨莎莎\t18852018037\n" +
+            "蒋嘉毅\t18012940131\n" +
+            "冯晨晨\t17384433521\n" +
+            "王春燕\t15155674035\n" +
+            "沈晓娜\t17310795053\n" +
+            "张馨予\t18684153114\n" +
+            "王玉玉\t17801127515\n" +
+            "丁洁\t15339986105\n" +
+            "蓝宜琛\t18892686218\n" +
+            "汤睿涵\t13520520058\n" +
+            "叶美怡\t18318339538\n" +
+            "冯金懿\t17611486863\n" +
+            "唐玥\t17326031406\n" +
+            "廉宏磊\t15601170707\n" +
+            "隆玮琦\t18519745840\n" +
+            "郭东来\t17600800810\n" +
+            "刘柏泽\t15561868553\n" +
+            "祝圣航\t19850422714\n" +
+            "闻博\t18909474827\n" +
+            "董兵雨\t18298159075\n" +
+            "杨晓磊\t18901224561\n" +
+            "陈思琪\t18651887447\n" +
+            "李思雨\t17808273888\n" +
+            "康飞飞\t17610801133\n" +
+            "陈佳意\t13916766029\n" +
+            "杨佳\t18710735504\n" +
+            "王圣瑜\t13204076867\n" +
+            "席晓丹\t18519356022\n" +
+            "刘思彤\t19562219208\n" +
+            "岳淑慧\t15901502680\n" +
+            "任雪莹\t19932670047\n" +
+            "余洋\t18851137676\n" +
+            "朱宇静\t15180042624\n" +
+            "周友涛\t18852095505\n" +
+            "王烁然\t15663307215\n" +
+            "朱胜龙\t15855961836\n" +
+            "宋欣璐\t15643952579\n" +
+            "唐东明\t19551817275\n" +
+            "陈雨露\t13851725710\n" +
+            "戴阳\t18260066836\n" +
+            "张雅倩\t15703825517\n" +
+            "何梦豪\t15056329515\n" +
+            "张凯雯\t13321459366\n" +
+            "毛君\t18655362672\n" +
+            "孔雨婷\t18351101822\n" +
+            "章明\t17315099711\n" +
+            "靳丁敏\t15513003950\n" +
+            "刘青\t19155354441\n" +
+            "葛磊\t13813234249\n" +
+            "杨煜轩\t17602543482\n" +
+            "刘舒琪\t18361530973\n" +
+            "郑曦\t17630310601\n" +
+            "宋婷\t17314133931\n" +
+            "鞠智铭\t15251887302\n" +
+            "何露雪\t17312306192\n" +
+            "楼子君\t19539901510\n" +
+            "董俊豪\t17538390824\n" +
+            "朱敏\t17879020865\n" +
+            "宗心悦\t18136838690\n" +
+            "周彤\t17352409890\n" +
+            "王俊\t18537458195\n" +
+            "骆思琪\t15250820552\n" +
+            "韩浩宇\t13470792981\n" +
+            "王自宏\t18325522259\n" +
+            "续明博\t18804537866\n" +
+            "莫汇英\t15676289201\n" +
+            "朱康杰\t18792151759\n" +
+            "吴思璇\t13142993638\n" +
+            "徐泽文\t18601547309\n" +
+            "高瑞\t18839620432\n" +
+            "黄楷馨\t17730150686\n" +
+            "顾娜\t18552231120\n" +
+            "庄妍\t15205161268\n" +
+            "杨鑫\t18646418170\n" +
+            "张雨珊\t17703281898\n" +
+            "李想\t15189835867\n" +
+            "韦楚同\t15578918553\n" +
+            "马帅豪\t13673848676\n" +
+            "李一鸣\t18951990712\n" +
+            "王心语\t17365305808\n" +
+            "包珊珊\t15380941833\n" +
+            "张悦\t19804872392\n" +
+            "刘玥\t18061671282\n" +
+            "孙耀赟\t15371042110\n" +
+            "刘衍昱\t15344274064\n" +
+            "李雨婷\t13016987885\n" +
+            "金桐\t18652671227\n" +
+            "强梦琴\t18255302095\n" +
+            "杨杰\t18255807384\n" +
+            "仲硕硕\t17206162976\n" +
+            "汪燕\t15806256629\n" +
+            "滕龙\t17543763466\n" +
+            "范丽霖\t19156737841\n" +
+            "贾纽约\t17397141992\n" +
+            "雷晓敏\t15367356747\n" +
+            "郑子硕\t13083003533\n" +
+            "王雪婷\t15867845856\n" +
+            "梅立雪\t15312826900\n" +
+            "王费琴\t19967515231\n" +
+            "刘恩麟\t17623814254\n" +
+            "周婧\t15357340060\n" +
+            "钱皇豆\t17355745996\n" +
+            "唐晓姣\t18661246593\n" +
+            "叶娴\t15655688786\n" +
+            "方晓\t18755007520\n" +
+            "吴雁玲\t18752056147\n" +
+            "杨诚\t13914690448\n" +
+            "程丽彤\t13263319362\n" +
+            "赵桓宇\t13039272034\n" +
+            "安珏佳\t15810255852\n" +
+            "余星怡\t18735616226\n" +
+            "姜燚佳\t13954106358\n" +
+            "郝永峰\t17370233721\n" +
+            "张啸枫\t18612227794\n" +
+            "苏晨欢\t13301269557";
+
+}

+ 12 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/FeishuPushJob.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.job.bytedance.handler;
 
 import cn.com.ctop.job.bytedance.data.service.*;
+import cn.com.ctop.job.bytedance.utils.FeishuRobotUtil;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +28,8 @@ public class FeishuPushJob {
     ICutGroupRankPushService cutGroupRankPushService;
     @Autowired
     IReportsByBusinessPushService reportsByBusinessPushService;
+    @Autowired
+    IFeishuService feishuService;
 
     @XxlJob("unbindWarnPush")
     public void unbindWarnPush(){
@@ -88,4 +91,13 @@ public class FeishuPushJob {
     public void loginRecordPush(){
         userLoginRecordService.queryUserLoginRecord();
     }
+
+    @XxlJob("pullFeishuAvatar")
+    public void pullFeishuAvatar(){
+        try {
+            feishuService.uploadAvatar();
+        }catch (Exception e){
+            log.error("pullFeishuAvatar error: "+e.getMessage(), e);
+        }
+    }
 }

+ 48 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/utils/FeishuRobotUtil.java

@@ -1,11 +1,13 @@
 package cn.com.ctop.job.bytedance.utils;
 
 import cn.com.ctop.job.bytedance.data.utils.Check;
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
@@ -132,6 +134,52 @@ public class FeishuRobotUtil {
         }
     }
 
+    /**
+     * 批量获取用户信息
+     * return: userId -> userInfo
+     */
+    public static Map<String, JSONObject> batchGetUserInfo(String token, List<String> userIds) throws IOException{
+        Map<String, JSONObject> map = new HashMap<>();
+        int size = userIds.size();
+        int pageSize = 50;
+        int pageNum = size / pageSize + (size % pageSize == 0 ? 0 : 1);
+        for (int i = 0; i < pageNum; i++) {
+            int start = i * pageSize;
+            int end = Math.min(start + pageSize, size);
+            List<String> subList = userIds.subList(start, end);
+            Map<String, JSONObject> subMap = batchGetUserInfoOnePage(token, subList);
+            if (!Check.isNull(subMap)){
+                map.putAll(subMap);
+            }
+        }
+        return map;
+    }
+
+    private static Map<String, JSONObject> batchGetUserInfoOnePage(String token, List<String> userIds) throws IOException{
+        String url = "https://open.feishu.cn/open-apis/contact/v3/users/batch?user_id_type=user_id&department_id_type=open_department_id";
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Authorization", "Bearer "+token);
+        for (String u : userIds){
+            url = url + "&user_ids="+u;
+        }
+        String res = HttpUtils.httpGet(url, null, headers);
+        JSONObject obj = JSON.parseObject(res);
+        if (obj != null && obj.getInteger("code") == 0){
+            Map<String, JSONObject> map = new HashMap<>();
+            JSONObject data = obj.getJSONObject("data");
+            JSONArray items = data.getJSONArray("items");
+            for (int i = 0; i < items.size(); i++) {
+                JSONObject user = items.getJSONObject(i);
+                String userId = user.getString("user_id");
+                map.put(userId, user);
+            }
+            return map;
+        }else {
+            System.out.println(obj);
+        }
+        return null;
+    }
+
     public static void sendTextToDt(String text, List<String> userIds) throws IOException {
         JSONObject content = new JSONObject();
         content.put("text", text);