'多表支持修改,完成1、列表配置,2、查询配置,3、导出配置'

This commit is contained in:
2019-03-29 16:07:43 +08:00
parent 49be875e5d
commit 3df7e52e61
13 changed files with 579 additions and 310 deletions

View File

@@ -65,6 +65,7 @@
<script src="../res/zui/lib/sortable/zui.sortable.js"></script>
<script src="../res/js/red.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
<script>
var vm = new Vue({
el: ".container-fluid",
@@ -76,7 +77,7 @@
{name: "MetaData", url: "/meta", nodes: [
/*{url:"/metadata/metatable/list.html", name:"TableList"},*/
{url:"/metadata/metatable/metaTable.html", name:"MetaTable"},
{url:"/metadata/metaLink.html", name:"MetaLink"},
/*{url:"/metadata/metaLink.html", name:"MetaLink"},*/
{url:"/metadata/metaService.html", name:"MetaService"},
{url:"/metadata/dataList.html", name:"数据查询"},
]

View File

@@ -2,6 +2,12 @@
.panel-body {
padding: 0;
}
.tlist>li.active>a,
.tlist>li.active>a:focus,
.tlist>li.active>a:hover,
.tlist>li>a:hover {
background-color: #92b0cb;
}
</style>
<row class="meta-service">
<div class="col-md-12" style="padding-top: 10px;">
@@ -10,10 +16,12 @@
<span class="input-group-btn">
<button class="btn btn-default" type="button">选择业务类型</button>
</span>
<select class="form-control" v-model="table" style="width: 180px;">
<select class="form-control" v-model="service" style="width: 180px;">
<option v-for="item in services" :value="item.name"> {{item.name}}&nbsp;&nbsp;&nbsp;[{{item.comment}}]</option>
</select>
<span class="input-group-btn" style="padding-left: 20px">
<button @click="status=5" :class="['btn',{'btn-primary':status==5}]" type="button"> 列表配置</button>
</span>
@@ -34,80 +42,54 @@
</div>
</div>
<div class="col-md-7">
<table class="table-bordered" style="width: 100%">
<thead>
<tr style="background-color: #f1f1f1">
<td v-show="status==3 || status==4 || status==5 || status==6"><input type="checkbox"></td>
<th v-show="status==1"></th>
<th>字段名</th>
<th>中文名</th>
<th>数据类型</th>
<th>输入类型</th>
<th>附加属性</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in meta.items">
<td v-show="status==3"><input type="checkbox" v-model="meta.exports" :value="item.name" class="form-control"></td>
<td v-show="status==4"><input type="checkbox" v-model="meta.imports" :value="item.name" class="form-control"></td>
<td v-show="status==5"><input type="checkbox" v-model="meta.shows" :value="item.name" class="form-control"></td>
<td v-show="status==6"><input type="checkbox" v-model="filterArr" :value="item.name" class="form-control"></td>
<td v-show="status==1" class="icon icon-move"></td>
<td v-show="status!=2" v-text="item.name" style="background-color: rgb(235, 235, 228);"></td>
<td v-show="status!=2" v-text="item.label"></td>
<td v-show="status!=2" v-text="item.type"></td>
<td v-show="status!=2" v-text="item.inType"></td>
<td v-show="status!=2" v-text="item.inExt"></td>
<td v-show="status!=2" v-text="item.remark"></td>
<td v-show="status==2">
<input v-model="item" type="hidden">
<input :value="item.name" disabled class="form-control">
<input v-model="item.name" type="hidden">
<input name="name" type="hidden" :value="item.name">
</td>
<td v-show="status==2"><input v-model="item.label" class="form-control"></td>
<td v-show="status==2"><input v-model="item.type" class="form-control"></td>
<td v-show="status==2"><!--<input v-model="item.inType">-->
<select v-model="item.inType" class="form-control" style="width: 130px">
<option></option>
<option v-for="x in inTypes" :value="x">{{x}}</option>
</select>
</td>
<td v-show="status==2"><input v-model="item.inExt" class="form-control"></td>
<td v-show="status==2"><input v-model="item.remark" class="form-control"></td>
</tr>
</tbody>
</table>
<div class="col-xs-1" style="padding-right: 0px">
<ul class="nav nav-tabs nav-stacked tlist" style="height: 100%">
<li @click="sheet=item" :class="[{active: sheet==item }]" v-for="item in sheetArr" >
<a href="javascript:;" data-target="#tab3Content1" data-toggle="tab" v-text="serviceDetail['tables'][item]['name']"></a>
</li>
</ul>
</div>
<!-- sort -->
<!--<div class="col-md-5" v-show="false">
<table class="table-bordered table-auto">
<thead>
<tr style="background-color: #f1f1f1">
<th></th>
<th>字段名</th>
<th>中文名</th>
<th>展示名</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in meta.items">
<td v-show="status!=2" class="icon icon-move"></td>
<td v-show="status!=2" v-text="item.name" style="background-color: rgb(235, 235, 228);"></td>
<td v-show="status!=2" v-text="item.label"></td>
<td v-show="status!=2"><input v-model="item.label" style="width: 100px;"></td>
</tr>
</tbody>
</table>
</div>-->
<div class="col-xs-6" style="padding-left: 0px;">
<div class="tab-content">
<div class="tab-pane fade active in" id="">
<table class="table-bordered table-auto" style="width: 100%">
<thead>
<tr style="background-color: #f1f1f1">
<td v-show="status==3 || status==4 || status==5 || status==6"><input type="checkbox"></td>
<th v-show="status==1"></th>
<th>字段名</th>
<th>中文名</th>
<th>数据类型</th>
<th>输入类型</th>
<th>附加属性</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in serviceDetail['tables'][sheet].items">
<td v-show="status==3"><input type="checkbox" v-model="serviceInfo.exports" :value="sheet + '$' + item.name" class=""></td>
<td v-show="status==4"><input type="checkbox" v-model="serviceInfo.imports" :value="sheet + '$' + item.name" class=""></td>
<td v-show="status==5"><input type="checkbox" v-model="serviceInfo.shows" :value="sheet + '$' + item.name" class=""></td>
<td v-show="status==6"><input type="checkbox" v-model="filterArr" :value="sheet + '$' + item.name" class=""></td>
<!-- shows -->
<div class="col-md-5" v-show="status==5">
<div class="panel">
<td v-show="status==1" class="icon icon-move"></td>
<td v-show="status!=2" v-text="item.name" style="background-color: rgb(235, 235, 228);"></td>
<td v-show="status!=2" v-text="item.label"></td>
<td v-show="status!=2" v-text="item.type"></td>
<td v-show="status!=2" v-text="item.inType"></td>
<td v-show="status!=2" v-text="item.inExt"></td>
<td v-show="status!=2" v-text="item.remark"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-xs-5" style="padding-left: 0px;padding-right: 0px">
<!-- shows -->
<div class="panel" v-show="status==5">
<div class="panel-heading">列表展示的属性</div>
<div id="show" class="panel-body">
<table class="table-bordered table-auto" style="width: 100%">
@@ -120,7 +102,7 @@
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in meta.shows">
<tr v-for="(item, index) in serviceInfo.shows">
<td class="icon icon-move">
<input name="name" :value="item" type="hidden">
</td>
@@ -132,11 +114,9 @@
</table>
</div>
</div>
</div>
<!-- exports -->
<div class="col-md-5" v-show="status==3">
<div class="panel">
<!-- exports -->
<div class="panel" v-show="status==3">
<div class="panel-heading">导出的属性配置</div>
<div id="export" class="panel-body">
<table class="table-bordered table-auto" style="width: 100%">
@@ -149,7 +129,7 @@
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in meta.exports">
<tr v-for="(item, index) in serviceInfo.exports">
<td class="icon icon-move">
<input name="name" :value="item" type="hidden">
</td>
@@ -161,11 +141,9 @@
</table>
</div>
</div>
</div>
<!-- imports -->
<div class="col-md-5" v-show="status==4">
<div class="panel">
<!-- imports -->
<div class="panel" v-show="status==4">
<div class="panel-heading">
导入的属性配置
</div>
@@ -180,7 +158,7 @@
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in meta.imports">
<tr v-for="(item, index) in serviceInfo.imports">
<td class="icon icon-move">
<input name="name" :value="item" type="hidden">
</td>
@@ -192,11 +170,9 @@
</table>
</div>
</div>
</div>
<!-- filters -->
<div class="col-md-5" v-show="status==6">
<div class="panel">
<!-- filters -->
<div class="panel" v-show="status==6">
<div class="panel-heading">查询配置</div>
<div id="filter" class="panel-body" style="overflow:auto;">
<table class="table-bordered table-auto" style="width: 100%">
@@ -210,20 +186,20 @@
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in filters">
<tr v-for="(item, index) in filterArr">
<td class="icon icon-move">
<input name="name" :value="item.name" type="hidden">
<input name="name" :value="item" type="hidden">
</td>
<td v-text="item.name" style="background-color: rgb(235, 235, 228);"></td>
<td v-text="">{{getFieldLabel(item.name)}}</td>
<td v-text="item" style="background-color: rgb(235, 235, 228);"></td>
<td v-text="">{{getFieldLabel(item)}}</td>
<td>
<label>
<input type="checkbox" v-model="item.checked" value="1"> 展示
<input type="checkbox" v-model="filterMap[item].checked" value="1"> 展示
</label>
</td>
<td>
<label class="checkbox-inline" v-for="c in filterCate">
<input type="checkbox" v-model="item.filterType" :value="c"> {{c}}
<input type="checkbox" v-model="filterMap[item].filterType" :value="c"> {{c}}
</label>
</td>
</tr>
@@ -233,32 +209,7 @@
</div>
</div>
<!-- dbPlat -->
<div class="col-lg-5" v-show="status==7 ">
<div class="panel">
<div class="panel-heading">数据平台配置</div>
<div class="panel-body" style="overflow:auto;">
<form>
<div class="form-group">
<label class="col-sm-2">数据平台</label>
<div class="col-md-6">
<input type="hidden" v-model="row.key">
<select v-model="row.dbPlatId" class="form-control">
<option></option>
<option v-for="item in dbPlats" :value="item.key" v-text="item.name"></option>
</select>
</div>
<div class="col-md-4">
<select v-model="row.catalog" class="form-control">
<option></option>
<option v-for="item in catalogs()" :value="item" v-text="item"></option>
</select>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="clearfix"></div>
</row>
@@ -267,11 +218,14 @@
var vm = new Vue({
el: ".meta-service",
data: {
//new
sheetArr: ["a"],//别名
sheet: "a",//别名
inTypes: ["INPUT", "SELECT_EXT", "INPUT_DT"],
dataTypes: ["bigint(20)", "varchar(255)", "varchar(64)", "varchar(32)", "varchar(16)", "int(11)", "int(3)", "int(2)", "datetime"],
filterCate: ["EQUAL", "NOTEQUAL", "LIKE", "IN"],
tables: [],//所有的业务类型,【测试用】
meta: {
serviceInfo: {
name:"",
table:"",
items: [],
@@ -279,10 +233,12 @@
exports: [],
imports: [],
filters: [{name:"", filterType:[""]}]
},//完整的元数据数据,
},
serviceDetail: {tables: {a:{items:[]}}},
move: false,
status: 0, //页面默认状态
table: "", //页面选择的业务类型
itemSort: [], //待保存的业务属性
oldItems: [], //不被修改的字段属性
@@ -293,117 +249,113 @@
filter: {db: "", catalog: "", name: ""},//tableList 过滤条件
filters:[],//查询配置
status: 0, //页面默认状态
services: [],//业务列表
service: "", //页面选择的业务类型
table: "",//表别名
filterArr:[],
services: []
filterMap:{},
},
watch: {
status: function (v) {
this.setMove(v)
},
table: function (table) {
this.loadDetail(table);
services: function (v) {
if(v.length > 0) {
vm.service = v[0]["name"];
}
},
"meta.items": {
handler: function (nv, ov) {
var itemNv = nv || [];
var itemOv = vm.oldItems || [];
if (itemOv.length == 0) return;
var itemEdit = [];
a:for (var i = 0; i < itemOv.length; i++) {
var attr = ["label", "name", "remark", "type", "inType"];
for (var j = 0; j < attr.length; j++) {
var k = attr[j];
if (itemOv[i][k] != itemNv[i][k]) {
itemEdit.push(itemNv[i]);
continue a;
service: function (v) {
this.loadInfo(v);
this.loadDetail(v);
},
serviceInfo: function(v) {
let arr = [];
let map = {};
v["filters"].forEach(function (f) {
arr.push(f["name"]);
map[f["name"]] = f;
});
this.filterMap = map;
this.filterArr = arr;
},
serviceDetail: function (v) {
var arr = [];
for(k in v.tables) {
arr.push(k);
}
this.sheetArr = arr;//别名
this.sheet = arr[0];
},
sheet: function (v) {
this.table = v;
},
filterArr: function (v) {
let map = {};
for(j in v) {
let k = v[j];
map[k] = this.filterMap[k];
if (!map[k]) {
for (i in vm.serviceInfo.filters) {
if (vm.serviceInfo.filters[i]["name"] == k) {
map[k] = vm.serviceInfo.filters[i];
}
}
}
vm.itemEdit = itemEdit;
},
deep: true
},
"meta.shows": function (v) {
//console.log(v.length)
},
tables: function (v) {
if(v.length > 0) {
vm.table = v[0]["name"];
if (!map[k]) {
map[k] = {name: k, filterType:[], checked: false};//构造filter 对象
}
}
this.filterMap = map;
},
meta: function (v) {
vm.row = {key:v.key, dbPlatId: v.dbPlatId, catalog: v.catalog};
vm.filters = v.filters;
var filterArr = [];
/*vm.filters.forEach(function (item) {
filterArr.push(item.name);
})*/
vm.filterArr = filterArr;
},
filterArr: function (v) {
var filters = [];
vm.filterArr.forEach(function (item) {
var filter;
for (i in vm.filters) {
if (item == vm.filters[i].name) {
filter = vm.filters[i];
}
}
/*vm.meta.filters.forEach(function (x) {
if (item == x.name) {
//filters.push(x);
filter = x;
}
})*/
if (!filter) {
filter = {name: item, filterType:[], checked: 0};
}
filters.push(filter);
});
vm.filters = filters;
}
},
methods: {
loadDetail: function (cate) {
//this.status = 0;
red.getJSON("/meta/tableinfo",{name: cate}, function (json) {
var row = json;
loadInfo: function (name) {
red.getJSON("/meta/service_info",{name: name}, function (json) {
var row = red.replacePoint(json);
row.shows = row.shows || [];
row.exports = row.exports || [];
row.imports = row.imports || [];
row.filters = row.filters || [];
vm.meta = row;
var oldItems = [];
row.items.forEach(function (item) {
var d = {};
["label", "name", "remark", "type", "inType"].forEach(function (k) {
d[k] = item[k];
});
oldItems.push(d);
});
vm.oldItems = oldItems;
});
},
tableList: function () {
red.getJSON("/meta/tablelist",{}, function (json) {
vm.tables = json;
vm.serviceInfo = row;
});
},
catalogs: function() {
loadDetail: function (name) {
red.getJSON("/meta/service_detail",{name: name}, function (json) {
vm.serviceDetail = red.replacePoint(json);
});
},
serviceList: function () {
red.getJSON("/meta/service_list",{}, function (json) {
vm.services = red.replacePoint(json);
});
},
getFieldLabel: function (col) {
if (!col) {
return "";
}
var tableInfo = vm.serviceDetail['tables'][col.split("$")[0]];
if (tableInfo) {
for (var i = 0; i < tableInfo.items.length; i++) {
if (tableInfo.items[i].name == col.split("$")[1]) {
return tableInfo.items[i].label;
}
}
}
return '';
},
/*catalogs: function() {
var dbPlats = this.dbPlats;
for (i in dbPlats) {
if (dbPlats[i].key == this.row.dbPlatId) {
return dbPlats[i]["catalogs"]
}
}
},
},*/
setMove: function () {
if (this.status == 1) {
$('#sortableList,table>tbody').sortable({
@@ -429,7 +381,7 @@
var item = $(rows[i]).find("input[name='name']").val();
shows.push(item);
}
vm.meta.shows = shows;
vm.serviceInfo.shows = shows;
}
});
} else if (this.status == 4) {
@@ -442,7 +394,7 @@
var item = $(rows[i]).find("input[name='name']").val();
shows.push(item);
}
vm.meta.imports = shows;
vm.serviceInfo.imports = shows;
}
});
} else if (this.status == 3) {
@@ -455,7 +407,7 @@
var item = $(rows[i]).find("input[name='name']").val();
shows.push(item);
}
vm.meta.exports = shows;
vm.serviceInfo.exports = shows;
}
});
}
@@ -512,28 +464,37 @@
items: JSON.stringify(vm.itemEdit)
});
}
else if (vm.status == 3 || vm.status == 4 || vm.status == 5) {
else if (vm.status == 3 || vm.status == 4 /*|| vm.status == 5*/) {
var urls = {3: "/meta/exportsort", 4: "/meta/importsort", 5: "/meta/showsort"};
var items = {3: vm.meta.exports, 4: vm.meta.imports, 5: vm.meta.shows};
var items = {3: vm.serviceInfo.exports, 4: vm.serviceInfo.imports, 5: vm.serviceInfo.shows};
var dataStr = JSON.stringify(red.replace$(items[vm.status]));
red.post(urls[vm.status], {
serviceKey: vm.table,
items: JSON.stringify(items[vm.status])
serviceKey: this.service,
items: dataStr
});
}
else if (vm.status == 5) {
var dataStr = JSON.stringify(red.replace$(vm.serviceInfo.shows));
console.log("dataStr", dataStr);
red.post("/meta/showsort", {
serviceKey: vm.table,
items: JSON.stringify(vm.meta.shows)
serviceKey: vm.service,
items: dataStr
});
}
else if (vm.status == 6) {
console.log(vm.filters);
let filterData = [];
for (i in this.filterArr) {
filterData.push(this.filterMap[this.filterArr[i]]);
}
red.post("/meta/filter_update", {
serviceKey: vm.table,
filters: JSON.stringify(vm.filters)
serviceKey: vm.service,
filters: JSON.stringify(red.replace$(filterData))
});
}
@@ -546,26 +507,16 @@
else {
red.showMsg();
}
},
getFieldLabel: function (col) {
if (!col) {
return "";
}
for (var i = 0; i < vm.oldItems.length; i++) {
if (vm.oldItems[i].name == col) {
return vm.oldItems[i].label;
}
}
}
},
mounted: function (){
//dbPlats 列表初始化
red.dbPlats(function (json) {
/*red.dbPlats(function (json) {
vm.dbPlats = json;
});
});*/
this.tableList();
this.serviceList();
/*$(window).keydown(function (event) {
// 监听 Ctrl + Enter 可全屏查看

View File

@@ -240,26 +240,30 @@
<!-- dbPlat -->
<div class="col-lg-5" v-show="status==7">
<div class="panel">
<div class="panel-heading">数据平台配置</div>
<div class="panel-heading">基本属性配置</div>
<div class="panel-body" style="overflow:auto;">
<form class="form-horizontal">
<input type="hidden" v-model="row.key">
<div class="form-group">
<label for="name" class="col-md-2">Table名称</label>
<div class="col-md-6 col-sm-10">
<div class="col-md-4 col-sm-8">
<input v-model="row.name" class="form-control" id="name" placeholder="请输入Table名称">
</div>
<label for="name" class="col-md-2">表别名</label>
<div class="col-md-3 col-sm-2">
<input v-model="row.alias" class="form-control" readonly>
</div>
</div>
<div class="form-group">
<label for="comment" class="col-md-2">Table标题</label>
<div class="col-md-6 col-sm-10">
<div class="col-md-4 col-sm-8">
<input v-model="row.comment" class="form-control" id="comment" placeholder="请输入 Table标题">
</div>
</div>
<div class="form-group">
<label class="col-md-2">数据平台</label>
<div class="col-md-6">
<div class="col-md-4 col-sm-8">
<select v-model="row.dbPlatId" class="form-control">
<option></option>
<option v-for="item in dbPlats" :value="item.key" v-text="item.name"></option>
@@ -304,7 +308,7 @@
itemEdit: {}, //待修改的字段属性
dbPlats:[],
row: {key: "", platId: "", dbPlatId:"", catalog: "", name:"", comment:""},
row: {key: "", platId: "", dbPlatId:"", catalog: "", name:"", comment:"", alias: ""},
filter: {db: "", catalog: "", name: ""},//tableList 过滤条件
filters:[],//查询配置
@@ -348,7 +352,7 @@
}
},
meta: function (v) {
vm.row = {key:v.key, dbPlatId: v.dbPlatId, catalog: v.catalog, name:v.name, comment:v.comment};
vm.row = {key:v.key, dbPlatId: v.dbPlatId, catalog: v.catalog, name:v.name, comment:v.comment, alias: v.alias};
/*vm.filters = v.filters;
var filterArr = [];
vm.filters.forEach(function (item) {
@@ -381,6 +385,11 @@
red.getJSON("/meta/tablelist",{}, function (json) {
vm.tables = json;
});
/*red.getJSON("/meta/service_info",{name: "user_service"}, function (json) {
var x = red.replaceAll(json);
console.log(x)
});*/
},
catalogs: function() {
var dbPlats = this.dbPlats;

View File

@@ -1,6 +1,6 @@
var red = {
showMsg: function(option) {
var defOption = {msg: "操作成功", type:"info", placement: "bottom-right"};
var defOption = {msg: "操作成功", type:"info", placement: "top"};
option = option || defOption;
for (var k in defOption) {
@@ -137,5 +137,21 @@ var red = {
location.href = "/user/login.html";
}, 2000);
}
},
replaceAll: function (d, s, t) {
var reg=new RegExp(s,"g"); //创建正则RegExp对象
var str = JSON.stringify(d);
str = str.replace(reg, t)
return JSON.parse(str);
},
replacePoint: function(d) {
return red.replaceAll(d, "[.]", "$");
},
replace$: function (d) {
return red.replaceAll(d, "[$]", ".");
}
}
String.prototype.replaceAll=function(s,t){
return red.replaceAll(this, s, t);
}

View File

@@ -51,79 +51,110 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
}
public <T> T toBean(Class<T> type) {
return (T) toBean(this, type);
return toBean(this, type);
}
// 首字母大写
private static Function<String, String> upFirst = (s) -> {
return s.substring(0, 1).toUpperCase() + s.substring(1);
};
private static Map<Class, Class[]> clazzMap = new HashMap<>();
/*private static Map<Class, Class[]> clazzMap = new HashMap<>();
static {
clazzMap.put(ArrayList.class, new Class[]{List.class, ArrayList.class, String.class});
clazzMap.put(HashMap.class, new Class[]{Map.class, HashMap.class, String.class});
clazzMap.put(Long.class, new Class[]{Long.class, Integer.class, long.class, int.class, short.class, String.class});
clazzMap.put(String.class, new Class[]{String.class, Integer.class, Date.class});
clazzMap.put(Double.class, new Class[]{Double.class, Long.class, Integer.class, long.class, int.class, short.class, String.class});
}
}*/
private static Predicate<Class> isNumber = (t) -> {
return t == Integer.class || t == int.class
|| t == Long.class || t == long.class
|| t == Double.class || t == double.class
;
};
public static <T> T toBean(Map m, Class<T> type) {
/*public static <T> T toBean2(Map m, Class<T> type) {
try {
Object obj = type.newInstance();
m.forEach((k, v) -> {
String methodName = "set" + upFirst.apply(k+"");
Class[] clazzs = clazzMap.get(v == null ? null : v.getClass());
if (clazzs == null) {
//doc.set(k, v);
} else {
for (Class clazz : clazzs) {
Method method = null;
try {
method = type.getDeclaredMethod(methodName, clazz);
} catch (NoSuchMethodException e) {
}
if (method != null) {
try {
Object _v = toAs(v, clazz);
//如发现 映射异常,打开下面的注释查看 进行映射的值,并对上面的值转换过程升级
//System.out.printf("%s:%s %s%n", k,v, v.getClass());
method.invoke(obj, _v);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
break;
}
}
for (String k : (Set<String>)m.keySet()) {
Object v = m.get(k);
if (v == null) {
continue;
}
});
//得到目标方法
String methodName = "set" + upFirst.apply(k + "");
Method method = null;
Class tClazz = null;
try {
method = type.getDeclaredMethod(methodName, tClazz = v.getClass());
if (method == null) {
Class[] clazzs = clazzMap.get(v == null ? null : v.getClass());
if (clazzs == null) {
//doc.set(k, v);
} else {
for (Class clazz : clazzs) {
try {
type.getMethods();
method = type.getDeclaredMethod(methodName, tClazz = clazz);
} catch (NoSuchMethodException e) {
}
}
if (method != null) {
try {
Object _v = toAs(v, tClazz);
//如发现 映射异常,打开下面的注释查看 进行映射的值,并对上面的值转换过程升级
//System.out.printf("%s:%s %s%n", k,v, v.getClass());
method.invoke(obj, _v);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
break;
}
}
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
if (method != null) {
}
//已知keyvalue 一个实例类型对象
//找到目标方法
//转换数据类型
}
return (T) obj;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}*/
public static <T> T toAs(Object v, Class<T> clazz) {
if (v == null) {
return null;
}
if (v.getClass() == clazz) {
} else if (v.getClass() == clazz) {
return (T) v;
} else if (clazz == String.class) {
return (T) String.valueOf(v);
}
Object _v = null;
try {
if (v == null || "".equals(v)) {
} else if (v.getClass() == Long.class && clazz != Long.class) {//多种数值类型的处理: Long => x
} else if (v.getClass() == Long.class) {//多种数值类型的处理: Long => x
switch (clazz.getSimpleName()) {
case "int":
case "Integer": _v = (int)(long) v; break;
@@ -176,4 +207,103 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
}
return (T) _v;
}
public static <T> T toBean(Map map, Class<T> clazz) {
//按照方法名 + 类型寻找,
//按照方法名 寻找
//+
Object obj = null;
try {
obj = clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
for (String k : (Set<String>)map.keySet()) {
Object v = map.get(k);
if (v == null) continue;
//寻找method
try {
String methodName = "set" + upFirst.apply(k);
Class tClazz = null;
Method method = null;
try {
method = clazz.getMethod(methodName, tClazz = v.getClass());
} catch (NoSuchMethodException e) {
//e.printStackTrace();
}
if (method == null) {
for (Method _method : clazz.getMethods()) {
if (methodName.equals(_method.getName()) && _method.getParameterCount() == 1) {
method = _method;
tClazz = _method.getParameterTypes()[0];
}
}
}
if (method == null) {
for (Method _method : clazz.getMethods()) {
if (methodName.equalsIgnoreCase(_method.getName()) && _method.getParameterCount() == 1) {
method = _method;
tClazz = _method.getParameterTypes()[0];
}
}
}
if (method != null) {
method.invoke(obj, toAs(v, tClazz));
}
//没有方法,找属性注解
if (method == null) {
Field field = null;
Field[] fields = clazz.getDeclaredFields();
for (Field _field : fields) {
To to = _field.getAnnotation(To.class);
if (to != null && k.equals(to.value())) {
field = _field;
tClazz = _field.getType();
break;
}
}
/*if (field == null) {
fields = clazz.getDeclaredFields();
continue;
}
while (true){
break;
}*/
if (field != null) {
field.setAccessible(true);
field.set(obj, toAs(v, tClazz));
}
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
return (T) obj;
}
public static void main(String[] args) {
Map map = new HashMap<>();
map.put("name", "xxxx");
map.put("age", 12);
map.put("abx", 123);
User user = toBean(map, User.class);
System.out.println(user);
}
}

View File

@@ -0,0 +1,12 @@
package net.tccn.base;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by liangxianyou at 2019/3/26 20:35.
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface To {
String value();
}

View File

@@ -0,0 +1,29 @@
package net.tccn.base;
/**
* Created by liangxianyou at 2019/3/26 19:36.
*/
public class User {
private String name;
private int age;
@To("")
private float attr;
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", age=" + age +
", attr='" + attr + '\'' +
'}';
}
}

View File

@@ -0,0 +1,23 @@
package net.tccn.base;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Created by liangxianyou at 2019/3/19 18:01.
*/
public class UtilityExt {
public static <T> Set<T> streamConcat(Stream<T> ... streams) {
Stream<T> stream = Stream.empty();
for (int i = 0; i < streams.length-1; i++) {
stream = Stream.concat(
stream, streams[i]
);
}
return stream.collect(Collectors.toSet());
}
}

View File

@@ -45,7 +45,7 @@ public class ParseMysql implements Parser {
@Deprecated
Function<FBean, Kv<String, MetaTable>> tablesFun = fbean -> {
MetaService metaService = MetaKit.metaService(fbean.getName());
MetaService metaService = MetaKit.getMetaService(fbean.getName());
List<Filter> filters = fbean.getFilters();
List<String> shows = metaService.getShows();
@@ -91,10 +91,10 @@ public class ParseMysql implements Parser {
Predicate<Kv<String, MetaTable>> sameDbFun = (kv) -> {
String dbPlatId = null;
for (MetaTable table : kv.values()) {
for (MetaTable metaTable : kv.values()) {
if (dbPlatId == null) {
dbPlatId = table.getDbPlatId();
} else if (!dbPlatId.equals(table.getDbPlatId())) {
dbPlatId = metaTable.getDbPlatId();
} else if (!dbPlatId.equals(metaTable.getDbPlatId())) {
return false;
}
}
@@ -103,20 +103,18 @@ public class ParseMysql implements Parser {
@Override
public String[] parse(FBean fBean) {
MetaService metaService = MetaKit.metaService(fBean.getName());
MetaService metaService = MetaKit.getMetaService(fBean.getName());
Kv<String, MetaTable> tables = tablesFun.apply(fBean);//所有的关联表信息
Kv<String, MetaTable> tables = MetaKit.getMetaTables(metaService);//所有的关联表信息
MetaTable metaTable = tables.get(metaService.getTable());//基础元数据
List<String> shows = metaService.getShows();//查询的属性
List<String> _filters = fBean.getFilters().stream().map(Filter::getCol).collect(Collectors.toList());
List<MetaLink> links = MetaKit.getMetaLinks(metaService.getTable(), shows, _filters);
//查询条件
List<Filter> filters = fBean.getFilters();
Limit limit = fBean.getLimit();
List<Order> orders = fBean.getOrders();
//Map<String, List<Filter>> filterMap = filters.stream().collect(Collectors.groupingBy(x -> x.getCol().split("[.]")[0]));
//Map<String, List<String>> showMap = shows.stream().collect(Collectors.groupingBy(x -> x.split("[.]")[0]));

View File

@@ -1,16 +1,12 @@
package net.tccn.meta;
import net.tccn.base.Kv;
import net.tccn.dbq.jdbc.api.DbAccount;
import net.tccn.base.UtilityExt;
import net.tccn.dbq.Field;
import net.tccn.dbq.fbean.FilterType;
import net.tccn.dbq.jdbc.api.DbAccount;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -111,7 +107,7 @@ public class MetaKit {
* @param name
* @return
*/
public static MetaService metaService(String name) {
public static MetaService getMetaService(String name) {
Optional<MetaService> service = metaServices.stream().filter(x -> x.getName().equals(name)).findAny();
//处理业务逻辑
service.ifPresent(x -> {
@@ -168,7 +164,7 @@ public class MetaKit {
Field field = getField.apply(x);
if (field != null) {
Kv col = Kv.of();
col.set("col", x.split("[.]]")[0] + field.showField());//a.createtime=dt
col.set("col", x.split("$]")[0] + field.showField());//a.createtime=dt
col.set("label", field.getLabel());
col.set("order", 1);//dev 是否支持排序
_cols.add(col);
@@ -233,7 +229,7 @@ public class MetaKit {
//showUpdate
public static BiFunction<String, List<String>, MetaService> showUpdate = (serviceKey, shows) -> {
MetaService metaService = metaService(serviceKey);
MetaService metaService = getMetaService(serviceKey);
MetaService _metaService = MetaService.dao.findByKey(metaService.getKey());
_metaService.setShows(shows);
@@ -277,4 +273,51 @@ public class MetaKit {
.collect(Collectors.toList());
return links;
}
public static Kv buildeDetail(MetaService metaService) {
//tables
Kv<String, MetaTable> tables = getMetaTables(metaService);
return Kv.of("tables", tables)
.set("links", Kv.of());
}
public static Kv<String, MetaTable> getMetaTables(MetaService metaService) {
Kv<String, MetaTable> tables = Kv.of();
String table = metaService.getTable();//
tables.set(table, getMetaTableByAlias(table));
//收集所有的col
Set<String> allAlias = UtilityExt.streamConcat(
metaService.getFilters().stream().map(f -> {
String col = (String) f.get("name");
String alias = col.split("[.]")[0];
return alias;
}),
metaService.getShows().stream().map(x -> x.split("[.]")[0]),
metaService.getEdits().stream().map(x -> x.split("[.]")[0])
);
allAlias.forEach(x -> tables.set(x, getMetaTableByAlias(x)));
return tables;
}
public String nextAlias(String x) {
return next(x, "");
}
//使用['a',...,'z'] 创建Table 别名
private String next(String x, String end) {
if (x == null || "".equals(x)) {
return "a" + end;
}
char c = x.charAt(x.length() - 1);
String sub = x.substring(0, x.length() - 1);
if (c < 'z') {
return sub + (++c) + end;
} else if (c == 'z') {
return next(sub, "a" + end);
}
return null;
}
}

View File

@@ -1,5 +1,6 @@
package net.tccn.meta;
import net.tccn.base.Kv;
import net.tccn.base.arango.Doc;
import javax.persistence.Table;
@@ -23,6 +24,7 @@ public class MetaService extends Doc<MetaService> {
private List<String> shows = new ArrayList<>();
private List<String> edits = new ArrayList<>();
private List<Map> filters = new ArrayList<>();
private List<String> exports = new ArrayList<>();
//待组装数据
//private MetaTable metaTable;
@@ -86,6 +88,14 @@ public class MetaService extends Doc<MetaService> {
this.filters = filters;
}
public List<String> getExports() {
return exports;
}
public void setExports(List<String> exports) {
this.exports = exports;
}
/*public MetaTable getMetaTable() {
return metaTable;
}

View File

@@ -51,7 +51,7 @@ public class MetadataService extends BaseService { //arango
public JBean listCfg(String key, @RestParam(name = "platToken") String token) {
JBean jBean = JBean.by(0, "");
MetaService metaService = MetaKit.metaService(key);
MetaService metaService = MetaKit.getMetaService(key);
fixme: jBean.set(0, "", MetaKit.builderCfg.apply(metaService));
return jBean;
}
@@ -67,10 +67,7 @@ public class MetadataService extends BaseService { //arango
//----------- 元数据管理 ---------------
@RestMapping(name = "tablelist", comment = "table列表")
public JBean tableList(@RestParam(name = "platToken") String token,
String catalog,
String dbPlatId,
String name) {
public JBean tableList(@RestParam(name = "platToken") String token, String catalog, String dbPlatId, String name) {
JBean jBean = JBean.by(0, "");
SysPlat sysPlat = qtaskService.getSysPlat(token);
if (sysPlat == null) {
@@ -114,6 +111,20 @@ public class MetadataService extends BaseService { //arango
return JBean.by(0, "", findMetaTable(name, token));
}
@RestMapping(name = "service_info", comment = "service基本信息")
public JBean serviceInfo(@RestParam(name = "platToken") String token, String name) {
MetaService metaService = MetaKit.getMetaService(name);
return JBean.by(0, "", metaService);
}
@RestMapping(name = "service_detail", comment = "service详情")
public JBean serviceDetail(@RestParam(name = "platToken") String token, String name) {
MetaService metaService = MetaKit.getMetaService(name);
Kv detail = MetaKit.buildeDetail(metaService);
return JBean.by(0, "", detail);
}
//修改item的排序
@RestMapping(name = "itemsort", comment = "字段排序")
public String[] itemSortSave(String serviceKey , String[] items, @RestParam(name = "platToken") String token) {
@@ -146,9 +157,10 @@ public class MetadataService extends BaseService { //arango
public List<String> exportSort(String serviceKey , List<String> items, @RestParam(name = "platToken") String token) {
if (items == null || items.size() == 0) return null;
MetaTable metaTable = findMetaTable(serviceKey, token);
//fixme: metaTable.setExports(items);
metaTable.update();
MetaService metaService = MetaKit.getMetaService(serviceKey);
metaService.setExports(items);
metaService.update();
return items;
}
@@ -180,11 +192,10 @@ public class MetadataService extends BaseService { //arango
@RestParam(name = "filters") String filters,
@RestParam(name = "platToken") String token) {
List _filters = gson.fromJson(filters, List.class);
MetaTable metaTable = findMetaTable(serviceKey, token);
//fixme: metaTable.setFilters(_filters);
metaTable.update();
MetaService metaService = MetaKit.getMetaService(serviceKey);
metaService.setFilters(_filters);
metaService.update();
return JBean.by(0, "");
}

View File

@@ -1,10 +1,10 @@
import com.google.gson.Gson;
import net.tccn.base.Kv;
import net.tccn.base.RealType;
import net.tccn.dbq.fbean.FBean;
import net.tccn.dbq.fbean.ParseMysql;
import net.tccn.dbq.jdbc.api.DbAccount;
import net.tccn.dbq.jdbc.api.DbKit;
import net.tccn.meta.MetaKit;
import net.tccn.qtask.QRuner;
import net.tccn.qtask.Task;
import org.junit.Test;
@@ -13,6 +13,8 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import static java.util.Arrays.asList;
/**
* @author: liangxianyou at 2019/1/20 12:43.
*/
@@ -25,7 +27,7 @@ public class RunTest<T> {
public static Task e = new Task("http", "http://192.168.91.5:9200/_sql?sql=select%20*%20from%20basic_iotdevice_all%20limit%2010", "查询数据平台列表", Kv.of());
//@Test
public void t() {
public void qtaskTest() {
long start = System.currentTimeMillis();
Object query = QRuner.query(d);
System.out.printf("耗时:%s MS" ,System.currentTimeMillis() - start);
@@ -38,7 +40,7 @@ public class RunTest<T> {
}
ParseMysql parser = new ParseMysql();
@Test
public void t2() {
public void parseFBeanTest() {
FBean fBean = new Gson().fromJson("{name:'user_service', filters:[{col:'a.username',type:'like',value:'lxy'}], orders:[{col:a.`id`,desc: -1},{col:a.`deptName`,desc: 1}], limit:{ps:2,pn:10}}", FBean.class);
String[] parse = parser.parse(fBean);
@@ -98,4 +100,38 @@ public class RunTest<T> {
System.out.println(date1);
}
@Test
public void buildeDetailTest() {
Kv kv = MetaKit.buildeDetail(MetaKit.getMetaService("user_service"));
System.out.println(kv);
}
@Test
public void upDb$() {
/*MetaKit.getMetaServices().forEach(m -> {
List<String> shows = new ArrayList<>();
m.getShows().forEach(x -> {
shows.add(x.replace(".", "$"));
});
m.setShows(shows);
m.update();
});*/
//System.out.println("a$id".split("[$]")[0]);
}
@Test
public void findMaxNum() {
int xx = asList("1", "5", "3").stream().filter(x -> !x.isEmpty()).mapToInt(x -> {
return Integer.parseInt(x) * 2;
}).min().orElseGet(()-> 0);
System.out.println(xx);
}
}