|
|
@@ -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";
|
|
|
+
|
|
|
+}
|