From 9b20cd24bbc05de6edee4403135f41710916b512 Mon Sep 17 00:00:00 2001
From: jay <75509151@qq.com>
Date: Wed, 12 Jul 2023 16:23:22 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E9=93=B1=E5=A1=94=E6=99=BA=E8=81=94-?=
=?UTF-8?q?=E8=B4=A1=E7=8C=AE=E8=80=85=E5=88=9D=E5=A7=8B=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
data/init/contributor.json | 63 ++++++++++++++
.../service/ContributorDataInit.java | 82 +++++++++++++++++++
2 files changed, 145 insertions(+)
create mode 100644 data/init/contributor.json
create mode 100644 iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/ContributorDataInit.java
diff --git a/data/init/contributor.json b/data/init/contributor.json
new file mode 100644
index 00000000..b2fe3b91
--- /dev/null
+++ b/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": "
",
+ "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
+ }
+ ]
\ No newline at end of file
diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/ContributorDataInit.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/ContributorDataInit.java
new file mode 100644
index 00000000..1c0b1dfe
--- /dev/null
+++ b/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>() {
+ });
+ }
+
+ private T initData(String name, ICommonData service, TypeReference 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;
+ }
+
+}