Эх сурвалжийг харах

feat: 铱塔智联-贡献者初始化

jay 1 жил өмнө
parent
commit
9b20cd24bb

+ 63 - 0
data/init/contributor.json

@@ -0,0 +1,63 @@
+
+  [
+    {
+      "id": 437355835748421,
+      "contributor": "tangtang",
+      "avatar": "http://159.75.222.119:9000/iotkit/2023/07/10/8032cfb8cda445ab9ca4c044242aefb8.jpg",
+      "post": 1,
+      "intro": "来自于一个切图仔的自我修养",
+      "tags": "vue,react,node,uniapp,flutter",
+      "title": "前端精神小伙",
+      "context": "<p><br></p>",
+      "score": null,
+      "status": null
+    },
+    {
+      "id": 437356273557573,
+      "contributor": "花木水之间",
+      "avatar": "http://159.75.222.119:9000/iotkit/2023/07/09/f2ef7070ecd74dbc87654e145b2ba088.jpg",
+      "post": 2,
+      "intro": "技术骚客,啥都做",
+      "tags": "无人零售,linux,java/python/c/go",
+      "title": null,
+      "context": null,
+      "score": null,
+      "status": null
+    },
+    {
+      "id": 437670919086149,
+      "contributor": "regan",
+      "avatar": "http://159.75.222.119:9000/iotkit/2023/07/10/a535035899d5477cb6ca0041a261b57f.jpg",
+      "post": 2,
+      "intro": "物联网技术爱好者,单身可撩。",
+      "tags": "物联网,大数据,边缘计算",
+      "title": null,
+      "context": null,
+      "score": null,
+      "status": null
+    },
+    {
+      "id": 437687202414661,
+      "contributor": "闹腾",
+      "avatar": "http://159.75.222.119:9000/iotkit/2023/07/10/ec85a20d2612485c86ae8df554e1167a.jpg",
+      "post": 2,
+      "intro": "早日实现金钱自由",
+      "tags": "java ,go,python",
+      "title": null,
+      "context": null,
+      "score": null,
+      "status": null
+    },
+    {
+      "id": 437970532069445,
+      "contributor": "大橙子",
+      "avatar": "http://159.75.222.119:9000/iotkit/2023/07/11/cb98ba42a08b4ee9a1d8b1c8fc450411.png",
+      "post": 5,
+      "intro": "过往经验:\n电商/物流/教育/美业",
+      "tags": "PS,AI,AE,figma,XD",
+      "title": null,
+      "context": null,
+      "score": null,
+      "status": null
+    }
+  ]

+ 82 - 0
iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/ContributorDataInit.java

@@ -0,0 +1,82 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.contribution.service;
+
+import cc.iotkit.common.utils.JsonUtils;
+
+import cc.iotkit.contribution.data.IIotContributorData;
+import cc.iotkit.contribution.data.impl.IotContributorDataImpl;
+import cc.iotkit.contribution.model.IotContributor;
+import cc.iotkit.data.ICommonData;
+import cc.iotkit.model.Id;
+import com.fasterxml.jackson.core.type.TypeReference;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
+import org.springframework.beans.factory.SmartInitializingSingleton;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+@Slf4j
+@Service
+public class ContributorDataInit implements SmartInitializingSingleton {
+
+    @Autowired
+    private IIotContributorData contributorData;
+
+    @Override
+    public void afterSingletonsInstantiated() {
+        //等redis实例化后再执行
+        Timer timer = new Timer();
+        timer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                try {
+
+                    initSysData();
+
+
+
+                } catch (
+                        Throwable e) {
+                    log.error("init error", e);
+                }
+            }
+        }, 100);
+
+    }
+
+    private void initSysData() throws IOException {
+
+        initData("contributor", contributorData, new TypeReference<List<IotContributor>>() {
+        });
+    }
+
+    private <T> T initData(String name, ICommonData service, TypeReference<T> type) throws IOException {
+        log.info("init {} data...", name);
+        if (service.count() > 0) {
+            return null;
+        }
+        String json = FileUtils.readFileToString(new File("./data/init/" + name + ".json"), StandardCharsets.UTF_8);
+        List list = (List) JsonUtils.parseObject(json, type);
+        for (Object obj : list) {
+            service.save((Id) obj);
+        }
+        return (T) list;
+    }
+
+}