parent
ff98dca6b5
commit
f44ecdb795
@ -0,0 +1,59 @@
|
|||||||
|
package com.dsideal.base.Test;
|
||||||
|
|
||||||
|
import com.dsideal.base.Plugin.YamlProp;
|
||||||
|
import com.jfinal.kit.Kv;
|
||||||
|
import com.jfinal.kit.Prop;
|
||||||
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||||||
|
import com.jfinal.plugin.activerecord.Db;
|
||||||
|
import com.jfinal.plugin.activerecord.SqlPara;
|
||||||
|
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
||||||
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||||||
|
import com.jfinal.plugin.activerecord.Record;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TestDataSet {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//加载配置文件
|
||||||
|
String configFile = "application_dataease.yaml";
|
||||||
|
Prop PropKit = new YamlProp(configFile);
|
||||||
|
HikariCpPlugin arpPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
||||||
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
||||||
|
arpPlugin.start();
|
||||||
|
|
||||||
|
// 配置ActiveRecord插件
|
||||||
|
ActiveRecordPlugin arp = new ActiveRecordPlugin("master", arpPlugin);
|
||||||
|
arp.setDialect(new MysqlDialect());
|
||||||
|
|
||||||
|
//遍历sql目录下所有的sql文件
|
||||||
|
File sqlDir;
|
||||||
|
String basePath = TestDataSet.class.getResource("/").getPath();
|
||||||
|
sqlDir = new File(basePath + "/Sql");
|
||||||
|
File[] sqlFiles = sqlDir.listFiles();
|
||||||
|
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
||||||
|
//只加载.sql文件
|
||||||
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
||||||
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arp.start();
|
||||||
|
|
||||||
|
//1、获取树根
|
||||||
|
SqlPara sqlPara = Db.getSqlPara("DataEase.getTreeRoot");
|
||||||
|
Record rRoot = Db.findFirst(sqlPara);
|
||||||
|
long rootId = rRoot.getLong("id");
|
||||||
|
|
||||||
|
//2、查询有哪些数据集
|
||||||
|
Kv kv = Kv.by("id", rootId);
|
||||||
|
kv.set("dataset",true);
|
||||||
|
sqlPara = Db.getSqlPara("DataEase.getAllDataSet", kv);
|
||||||
|
List<Record> list= Db.find(sqlPara);
|
||||||
|
|
||||||
|
for (Record record : list) {
|
||||||
|
long id= record.getLong("id");
|
||||||
|
String name= record.getStr("name");
|
||||||
|
System.out.println(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
#namespace("DataEase")
|
||||||
|
-- 获取树根
|
||||||
|
#sql("getTreeRoot")
|
||||||
|
select * from core_dataset_group where name like '云南省教科院项目';
|
||||||
|
#end
|
||||||
|
-- 获取所有的数据集
|
||||||
|
#sql("getAllDataSet")
|
||||||
|
WITH RECURSIVE tree_cte AS (
|
||||||
|
SELECT *
|
||||||
|
FROM core_dataset_group
|
||||||
|
WHERE id = #para(id) -- 根节点的id
|
||||||
|
UNION ALL
|
||||||
|
SELECT c.*
|
||||||
|
FROM core_dataset_group c
|
||||||
|
INNER JOIN tree_cte t ON c.pid = t.id
|
||||||
|
)
|
||||||
|
SELECT id ,name ,pid,node_type FROM tree_cte
|
||||||
|
#if(dataset)
|
||||||
|
where node_type='dataset'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
@ -0,0 +1,8 @@
|
|||||||
|
mysql:
|
||||||
|
# 数据库信息
|
||||||
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
user: root
|
||||||
|
password: Password123@mysql
|
||||||
|
jdbcUrl : jdbc:mysql://10.10.14.203:3306/dataease?rewriteBatchedStatements=true&useUnicode=true&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue