From ff8de464f57aff3d2bd2913eec63636410f6f013 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Fri, 1 Jul 2022 14:36:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 129 +++++++++++++++ .vscode/settings.json | 3 + README.md | 14 ++ pom.xml | 150 ++++++++++++++++++ src/main/java/com/yuandian/common/App.java | 16 ++ .../java/com/yuandian/common/Database.java | 87 ++++++++++ src/main/resources/application.properties | 7 + src/main/resources/db_bus.mongodb | 44 +++++ src/main/resources/logback.xml | 13 ++ .../java/com/yuandian/common/AppTest.java | 17 ++ 10 files changed, 480 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/com/yuandian/common/App.java create mode 100644 src/main/java/com/yuandian/common/Database.java create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/db_bus.mongodb create mode 100644 src/main/resources/logback.xml create mode 100644 src/test/java/com/yuandian/common/AppTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f30ddae --- /dev/null +++ b/.gitignore @@ -0,0 +1,129 @@ +# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig +# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,linux,git,gradle,java,maven +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,linux,git,gradle,java,maven + +### Git ### +# Created by git for backups. To disable backups in Git: +# $ git config --global mergetool.keepBackup false +*.orig + +# Created by git when using merge tools for conflicts +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope +.vscode/*.code-snippets + +# Ignore code-workspaces +*.code-workspace + +### Gradle ### +.gradle +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core +# JDT-specific (Eclipse Java Development Tools) + +# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,linux,git,gradle,java,maven + +# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e0f15db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..74130d3 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# 源典骨架 + +## 使用方式 +* git clone clone git仓库 + +* 安装骨架 +```bash + git clone # clone git仓库 + mvn archetype:create-from-project + cd target/generated-sources/archetype + mvn install +``` + +* \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..00a7575 --- /dev/null +++ b/pom.xml @@ -0,0 +1,150 @@ + + + 4.0.0 + + com.yuandian.common + database + 1.0.0-SNAPSHOT + jar + + yd-common-archetype + http://maven.apache.org + + + UTF-8 + 8 + 8 + 8 + 2.1.0 + 1.30 + 1.2.11 + 1.7.36 + + + + + org.junit.jupiter + junit-jupiter-api + 5.8.2 + test + + + + + + + org.mongodb + mongodb-driver + 3.12.11 + + + + com.yuandian.common + config + 1.0.4 + + + + + + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + org.yaml + snakeyaml + ${snakeyaml.version} + + + + com.alibaba.nacos + nacos-client + ${nacos.version} + + + + org.projectlombok + lombok + 1.18.24 + provided + + + + + + scm:git:http://git.yuandian.com/project/yd-common-config.git + http://git.yuandian.com/project/yd-common-config.git + scm:git:http://git.yuandian.com/project/yd-common-config.git + HEAD + + + + + yuandian-nexus + yuandian-snapshots + http://mvn.yuandian.com/repository/maven-snapshots + + + yuandian-nexus + yuandian-releases + http://mvn.yuandian.com/repository/maven-releases + + + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + v@{project.version} + true + releases + + + + + org.sonatype.plugins + nxrm3-maven-plugin + 1.0.4 + + + default-deploy + deploy + + deploy + + + + + http://mvn.yuandian.com + + yuandian-nexus + + maven-snapshots + + true + + + + + + diff --git a/src/main/java/com/yuandian/common/App.java b/src/main/java/com/yuandian/common/App.java new file mode 100644 index 0000000..d7b6e61 --- /dev/null +++ b/src/main/java/com/yuandian/common/App.java @@ -0,0 +1,16 @@ +package com.yuandian.common; + +import lombok.extern.slf4j.Slf4j; + +/** + * Hello world! + * + */ +@Slf4j +public class App +{ + public static void main( String[] args ) + { + log.info("Hello Yuandian!"); + } +} diff --git a/src/main/java/com/yuandian/common/Database.java b/src/main/java/com/yuandian/common/Database.java new file mode 100644 index 0000000..b41c6f4 --- /dev/null +++ b/src/main/java/com/yuandian/common/Database.java @@ -0,0 +1,87 @@ +/** + * description + * + * @author eson + *2022年6月29日-10:16:15 + */ +package com.yuandian.common; + +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + +import org.bson.BsonDocument; +import org.bson.codecs.configuration.CodecRegistry; +import org.bson.conversions.Bson; + +import com.mongodb.BasicDBObject; +import com.mongodb.MongoClient; +import com.mongodb.MongoClientURI; +import com.mongodb.client.model.IndexOptions; +import com.mongodb.client.model.Indexes; + +import lombok.var; +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + *2022年6月29日-10:16:15 + */ +@Slf4j +public class Database { + + public class Origin { + T client; + + } + + public static void main(String[] args) throws Exception { + + Config.UseConfig("yuandian.database", (cnf) -> { + Map oriConfig = cnf.get("database", "mongodb", "ori"); + String uri = (String)oriConfig.get("uri"); // 获取 uri配置 + + MongoClient client = new MongoClient(new MongoClientURI(uri)); + + var dbInfoList = (ArrayList)oriConfig.get("db_info_list"); // 获取 db_info_list 列表 + + + return null; + }); + + + + // var cOriName = "bus_db"; + + // var db = client.getDatabase("yd-base"); + + // var busDB = db.getCollection(cOriName); + // var cur = busDB.listIndexes().iterator(); + + + + // if(!cur.hasNext()) { + + + // var bs = new BasicDBObject(); + // bs.js + + // bs.append("create_at", "1"); + + // bs.append("key", mapAsJavaMap(Map(("_id", "hashed")))) + + // busDB.createIndex(keys) + + // db.ex("db.db_bus.createIndex({ create_at: 1 },{expireAfterSeconds: 3600})"); + // var opt = new IndexOptions().expireAfter((long) 3600, TimeUnit.SECONDS); + // cOri.createIndex(Indexes.ascending("create_at"), opt); + // } + + + + // db.createCollection(cOriName); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..d05a5a9 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,7 @@ +# 启动端口 具体由项目而定 +# server.port=3440 + +# 测试环境的 nacos 配置地址 +yuandian.dataflow.config.nacos.server.addr=config.yuandian.local:8848 +# 测试环境的 nacos 配置地址 +yuandian.dataflow.config.nacos.server.addr-test=config.yuandian.local:8848 \ No newline at end of file diff --git a/src/main/resources/db_bus.mongodb b/src/main/resources/db_bus.mongodb new file mode 100644 index 0000000..586fb57 --- /dev/null +++ b/src/main/resources/db_bus.mongodb @@ -0,0 +1,44 @@ +// MongoDB Playground +// Use Ctrl+Space inside a snippet or a string literal to trigger completions. + +const database = 'yd-base'; +const collection = 'db_bus'; + +// The current database to use. +use(database); + +// Create a new collection. +// db.createCollection(collection); +// c = db.getCollection(collation); +db.db_bus.createIndex({ create_at: 1 },{expireAfterSeconds: 3600}) + +// The prototype form to create a regular collection: +/* db.createCollection( , + { + capped: , + autoIndexId: , + size: , + max: , + storageEngine: , + validator: , + validationLevel: , + validationAction: , + indexOptionDefaults: , + viewOn: , + pipeline: , + collation: , + writeConcern: + } +) */ + +// The prototype form to create a time-series collection: +/* db.createCollection( , + { + timeseries: { + timeField: , + metaField: , + granularity: + }, + expireAfterSeconds: + } +) */ diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..269a553 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{yyyyMMdd HH:mm:ss.SSS} %level %thread\(%file:%line\): %msg%n + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/yuandian/common/AppTest.java b/src/test/java/com/yuandian/common/AppTest.java new file mode 100644 index 0000000..bdeb531 --- /dev/null +++ b/src/test/java/com/yuandian/common/AppTest.java @@ -0,0 +1,17 @@ +package com.yuandian.common; + +import static org.junit.jupiter.api.Assertions.assertAll; + +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; + +@TestMethodOrder(OrderAnnotation.class) +public class AppTest { + @Test + @Order(1) + void testApp() { + //TODO: test 参考 http://doc.yuandian.com/pages/viewpage.action?pageId=4391012 + } +}