.
This commit is contained in:
@@ -8,8 +8,14 @@ const table = {
|
||||
sheetMySql({dbPlatId, catalog}) {
|
||||
return table._sheets({cate: "mysql", dbPlatId, catalog})
|
||||
},
|
||||
sheetInfo({filePath, sheetName}) {
|
||||
return red.postX('/_table/sheet_info', {cate: 'excel', filePath, sheetName})
|
||||
},
|
||||
|
||||
saveTable({dbPlatId, catalog, tableArr}) {
|
||||
return red.postX('/_table/table_save', {dbPlatId, catalog, tableArr: JSON.stringify(tableArr)})
|
||||
saveTable({dbPlatId, catalog, tableArr}) { //
|
||||
return red.postX('/_table/table_save', {cate: 'mysql', dbPlatId, catalog, tableArr: JSON.stringify(tableArr)})
|
||||
},
|
||||
saveSheet({filePath, sheetNames}) {
|
||||
return red.postX('/_table/table_save', {cate: 'excel', filePath, sheetNames: JSON.stringify(sheetNames)})
|
||||
}
|
||||
}
|
||||
@@ -56,13 +56,13 @@
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
<li @click="cate = 'excel'"><a href="###" data-target="#tab2Content1" data-toggle="tab">从本地上传</a></li>
|
||||
<li @click="cate = 'mysql'" class="active"><a href="###" data-target="#tab2Content2" data-toggle="tab">从数据源导入</a></li>
|
||||
<li @click="cate = 'oth'"><a href="###" data-target="#tab2Content3" data-toggle="tab">其他</a></li>
|
||||
<li @click="cate = 'excel'" :class="{active: cate=='excel'}"><a href="javascript:;">从本地上传</a></li>
|
||||
<li @click="cate = 'mysql'" :class="{active: cate=='mysql'}"><a href="javascript:;">从数据源导入</a></li>
|
||||
<li @click="cate = 'oth'" :class="{active: cate=='oth'}"><a href="javascript:;">其他</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<!-- 本地excel导入 -->
|
||||
<div class="tab-pane fade" id="tab2Content1">
|
||||
<div :class="['tab-pane', 'fade','in',{active: cate=='excel'}]">
|
||||
<div id="tableUploader" class="uploader">
|
||||
<!--<div class="uploader-message text-center">
|
||||
<div class="content"></div>
|
||||
@@ -83,7 +83,7 @@
|
||||
<td style="width: 38px; padding: 3px"><div class="file-icon"></div></td>
|
||||
<td style="padding: 0">
|
||||
<div style="position: relative; padding: 8px;">
|
||||
<strong class="file-field"></strong>
|
||||
<strong class="file-name"></strong>
|
||||
<div class="file-progress-bar"></div>
|
||||
</div>
|
||||
</td>
|
||||
@@ -120,7 +120,7 @@
|
||||
<li class="checkbox-inline clearfix" v-for="item in sheetArr" >
|
||||
<input type="checkbox"
|
||||
v-model="ck"
|
||||
:value="sheetData[item]['field']"
|
||||
:value="sheetData[item]['name']"
|
||||
:disabled="item=='表说明' || item=='表名称' || sheetData[item]['hv']==1"
|
||||
>
|
||||
<a :class="[{hv: sheetData[item]['hv']==1 }]" href="javascript:;" @click="sheet=item" data-target="#tab3Content1" data-toggle="tab" v-text="item"></a>
|
||||
@@ -156,7 +156,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in metaTable.items">
|
||||
<td v-text="item.field"></td>
|
||||
<td v-text="item.name"></td>
|
||||
<td v-text="item.label"></td>
|
||||
<td v-text="item.type"></td>
|
||||
<td v-text="item.inType"></td>
|
||||
@@ -182,7 +182,7 @@
|
||||
</div>
|
||||
|
||||
<!-- 从数据源导入 -->
|
||||
<div class="tab-pane fade active in" id="tab2Content2">
|
||||
<div :class="['tab-pane', 'fade','in',{active: cate=='mysql'}]">
|
||||
<div class="form-group">
|
||||
<label class="col-md-1 col-sm-1" style="padding-bottom: 10px;padding-top: 5px;">数据源选择</label>
|
||||
<div class="col-md-2 col-sm-10" style="padding-bottom: 10px">
|
||||
@@ -250,7 +250,7 @@
|
||||
</div>
|
||||
|
||||
<!-- 其他导入 -->
|
||||
<div class="tab-pane fade" id="tab2Content3">
|
||||
<div :class="['tab-pane', 'fade','in',{active: cate=='oth'}]">
|
||||
<p>其他一些定制的特殊格式的 实体数据形式</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -258,7 +258,7 @@
|
||||
<div class="modal-footer" v-show="cate=='excel'">
|
||||
<button @click="ck=[]" type="button" class="btn btn-default" data-dismiss="modal">取消选择</button>
|
||||
<button @click="back()" type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||
<button @click="saveSheet()" type="button" class="btn btn-primary">确定</button>
|
||||
<button @click="saveTable()" type="button" class="btn btn-primary">确定</button>
|
||||
</div>
|
||||
<div class="modal-footer" v-show="cate=='mysql'">
|
||||
<button @click="ckTable=[]" type="button" class="btn btn-default" data-dismiss="modal">取消选择</button>
|
||||
@@ -270,12 +270,12 @@
|
||||
<script>
|
||||
let {dbList} = plat
|
||||
let {catalogList, tableList, tableInfo} = db
|
||||
let {sheetMySql, saveTable} = table
|
||||
let {sheetsExcel, sheetMySql, sheetInfo, saveTable, saveSheet} = table
|
||||
|
||||
var vm = new Vue({
|
||||
el: ".importDev",
|
||||
data: {
|
||||
cate: 'mysql',
|
||||
cate: 'excel',
|
||||
|
||||
filePath: '',
|
||||
importStatus: false,
|
||||
@@ -289,7 +289,7 @@
|
||||
dbPlats: red.getData('dbPlats'),
|
||||
catalogs: [],
|
||||
tableData: {},
|
||||
tableArr:[],
|
||||
tableArr: [],
|
||||
dbPlat: red.getData("dbPlat",{}),
|
||||
dbPlatId: red.getData("dbPlatId",''),
|
||||
catalog: '',
|
||||
@@ -302,7 +302,7 @@
|
||||
var arr = [];
|
||||
var ck = [];
|
||||
for (k in v) {
|
||||
let field = v[k]['field'];
|
||||
let field = v[k]['name'];
|
||||
if (k!='表说明' && k!='表名称' && v[k]['hv'] != 1) {
|
||||
ck.push(field);
|
||||
}
|
||||
@@ -318,7 +318,6 @@
|
||||
},
|
||||
sheet: function (v) { // 查询sheet详情
|
||||
this.metaTable = this.sheetData[v];
|
||||
console.log(this.metaTable)
|
||||
if (this.metaTable['load'] != 1) {
|
||||
this.loadSheetData();
|
||||
}
|
||||
@@ -344,22 +343,29 @@
|
||||
if(!filePath) {
|
||||
return false;
|
||||
}
|
||||
red.post("/file/data",{filePath: filePath}, function (json) {
|
||||
console.log(json)
|
||||
vm.sheetData = json;
|
||||
sheetsExcel({filePath}).then(res => {
|
||||
vm.sheetData = res
|
||||
})
|
||||
},
|
||||
loadSheetData: function() {
|
||||
let sheetName = this.sheet;
|
||||
red.post("/file/sheet_data",{filePath: this.filePath, sheetName: sheetName}, function (json) {
|
||||
let sheetName = this.sheet
|
||||
sheetInfo({filePath: this.filePath, sheetName: this.sheet}).then(res => {
|
||||
res["hv"] = vm.sheetData[sheetName]["hv"]
|
||||
res["load"] = 1
|
||||
this.sheetData[sheetName] = res
|
||||
if (this.sheet == sheetName) {
|
||||
this.metaTable = res
|
||||
}
|
||||
})
|
||||
|
||||
/*red.post("/file/sheet_data",{filePath: this.filePath, sheetName}, function (json) {
|
||||
json["hv"] = vm.sheetData[sheetName]["hv"];
|
||||
json["load"] = 1;
|
||||
vm.sheetData[sheetName] = json;
|
||||
if (vm.sheet == sheetName) {
|
||||
vm.metaTable = json;
|
||||
}
|
||||
|
||||
})
|
||||
})*/
|
||||
},
|
||||
getSheetName: function (tableName) {
|
||||
for(k in this.sheetData) {
|
||||
@@ -416,12 +422,31 @@
|
||||
}
|
||||
},
|
||||
saveTable() { // 保存数据
|
||||
let [dbPlatId, catalog, tableArr] = [this.dbPlatId, this.catalog, this.ckTable]
|
||||
if (this.cate == 'mysql') {
|
||||
let [dbPlatId, catalog, tableArr] = [this.dbPlatId, this.catalog, this.ckTable]
|
||||
saveTable({dbPlatId, catalog, tableArr}).then(res => {
|
||||
red.showOk()
|
||||
this.loadTables()
|
||||
})
|
||||
} else if (this.cate == 'excel') {
|
||||
if (!this.ck || this.ck.length == 0) {
|
||||
red.showMsg({msg: "请选择导入数据", type: "danger", placement: "top"});
|
||||
return false;
|
||||
}
|
||||
saveSheet({filePath: this.filePath, sheetNames: this.ck}).then(res => {
|
||||
red.showOk()
|
||||
|
||||
saveTable({dbPlatId, catalog, tableArr}).then(res => {
|
||||
red.showOk()
|
||||
this.loadTables()
|
||||
})
|
||||
// 刷新列表
|
||||
let sheetData = this.sheetData
|
||||
for (let i in this.ck) {
|
||||
if (sheetData[this.ck[i]]) {
|
||||
sheetData[this.ck[i]]['hv'] = 1
|
||||
}
|
||||
}
|
||||
this.sheetData = sheetData
|
||||
this.ck = []
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
|
||||
@@ -94,14 +94,12 @@ var red = {
|
||||
method: 'post',
|
||||
data: params,
|
||||
transformRequest: [data => {
|
||||
console.log(data)
|
||||
let _data = ''
|
||||
for (k in data) {
|
||||
if (data[k] != undefined) {
|
||||
_data += k + '=' + data[k] + '&'
|
||||
}
|
||||
}
|
||||
console.log(_data)
|
||||
return _data
|
||||
}
|
||||
]
|
||||
|
||||
@@ -31,9 +31,8 @@ import java.util.*;
|
||||
|
||||
* 使用poi报表导出工具类
|
||||
* 把poi的一个调用接口抽出来,便于导出功能的管理
|
||||
* @author LiangXianYou lxy208@126.com
|
||||
* @param
|
||||
*
|
||||
* @author LiangXianYou lxy208@126.com
|
||||
*/
|
||||
public class ExcelKit {
|
||||
|
||||
@@ -85,10 +84,10 @@ public class ExcelKit {
|
||||
String[] hds = new String[headMap.size()];
|
||||
|
||||
int[] tag = {0};
|
||||
headMap.forEach((k,v) -> {
|
||||
headMap.forEach((k, v) -> {
|
||||
hds[tag[0]] = k;
|
||||
hdNames[tag[0]] = v;
|
||||
tag[0] ++;
|
||||
tag[0]++;
|
||||
});
|
||||
|
||||
return exportExcel(list, hdNames, hds);
|
||||
@@ -96,6 +95,7 @@ public class ExcelKit {
|
||||
|
||||
/**
|
||||
* 使用数据构建 excel 工作薄对象
|
||||
*
|
||||
* @param list 数据
|
||||
* @param hdNames 表头
|
||||
* @param hds 每条记录中数据的属性名
|
||||
@@ -395,10 +395,4 @@ public class ExcelKit {
|
||||
|
||||
return wk;
|
||||
}
|
||||
|
||||
//dev
|
||||
public void setWorkbook(File file) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ import static java.util.Arrays.asList;
|
||||
*/
|
||||
public final class FileKit {
|
||||
|
||||
private FileKit() { }
|
||||
private FileKit() {
|
||||
}
|
||||
|
||||
public static void strToFile(String entityBody, File file) throws IOException {
|
||||
strToFile(entityBody, file, true);
|
||||
@@ -23,12 +24,12 @@ public final class FileKit {
|
||||
if (file.exists()) {
|
||||
if (existDel) {
|
||||
file.delete();
|
||||
}else {
|
||||
} else {
|
||||
throw new RuntimeException(file.getPath() + "已经存在");
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.getParentFile().exists()){
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
@@ -38,27 +39,29 @@ public final class FileKit {
|
||||
|
||||
/**
|
||||
* 拷贝文件/文件目录
|
||||
*
|
||||
* @param source 源文件目录
|
||||
* @param target 目标目录
|
||||
*/
|
||||
private static void copyFiles(File source, File target) {
|
||||
copyFiles(source, target, "");
|
||||
}
|
||||
|
||||
private static void copyFiles(File source, File target, String linkPath) {
|
||||
if (source.isDirectory()){
|
||||
final String _linkPath = linkPath + File.separator+ source.getName();
|
||||
asList(source.listFiles()).forEach(f->{
|
||||
copyFiles(f, target, _linkPath);
|
||||
if (source.isDirectory()) {
|
||||
final String linkPath1 = linkPath + File.separator + source.getName();
|
||||
asList(source.listFiles()).forEach(f -> {
|
||||
copyFiles(f, target, linkPath1);
|
||||
});
|
||||
}else if (source.isFile()){
|
||||
} else if (source.isFile()) {
|
||||
try {
|
||||
String _linkPath = "";
|
||||
String linkPath1 = "";
|
||||
int index = linkPath.indexOf(File.separator, 1);
|
||||
if (index > 0){
|
||||
_linkPath = linkPath.substring(index);
|
||||
if (index > 0) {
|
||||
linkPath1 = linkPath.substring(index);
|
||||
}
|
||||
File targetFile = new File(target.toPath() + _linkPath + File.separator + source.getName());
|
||||
if (!targetFile.getParentFile().exists()){
|
||||
File targetFile = new File(target.toPath() + linkPath1 + File.separator + source.getName());
|
||||
if (!targetFile.getParentFile().exists()) {
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
@@ -71,16 +74,17 @@ public final class FileKit {
|
||||
|
||||
/**
|
||||
* 获取 clazz的路径,如果是jar里面的文件得到jar存放的目录,如:lib
|
||||
*
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static String rootPath(Class clazz){
|
||||
public static String rootPath(Class clazz) {
|
||||
//return clazz.getClassLoader().getResource("").getPath();
|
||||
URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
|
||||
try {
|
||||
String filePath = URLDecoder.decode(url.getPath(), "utf-8");
|
||||
if (filePath.endsWith(".jar")){
|
||||
return filePath.substring(0, filePath.lastIndexOf("/")+1);
|
||||
if (filePath.endsWith(".jar")) {
|
||||
return filePath.substring(0, filePath.lastIndexOf("/") + 1);
|
||||
}
|
||||
return filePath;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
@@ -89,12 +93,14 @@ public final class FileKit {
|
||||
|
||||
return "";
|
||||
}
|
||||
public static String rootPath(){
|
||||
|
||||
public static String rootPath() {
|
||||
return rootPath(FileKit.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取流内的所有内容
|
||||
*
|
||||
* @param inputStream
|
||||
* @return
|
||||
* @throws IOException
|
||||
@@ -103,8 +109,8 @@ public final class FileKit {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String str;
|
||||
while ((str = reader.readLine()) != null){
|
||||
buf.append(str+ "\n");
|
||||
while ((str = reader.readLine()) != null) {
|
||||
buf.append(str + "\n");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@@ -109,74 +109,72 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
||||
return (T) String.valueOf(v);
|
||||
}
|
||||
|
||||
Object _v = null;
|
||||
Object v1 = null;
|
||||
try {
|
||||
if (v == null || "".equals(v)) {
|
||||
|
||||
} else if (v.getClass() == Long.class) {//多种数值类型的处理: Long => x
|
||||
if (v.getClass() == Long.class) {//多种数值类型的处理: Long => x
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "int":
|
||||
case "Integer": _v = (int)(long) v; break;
|
||||
case "Integer": v1 = (int)(long) v; break;
|
||||
case "short":
|
||||
case "Short": _v = (short)(long) v; break;
|
||||
case "Short": v1 = (short)(long) v; break;
|
||||
case "float":
|
||||
case "Float": _v = (float)(long) v; break;
|
||||
default: _v = v;
|
||||
case "Float": v1 = (float)(long) v; break;
|
||||
default: v1 = v;
|
||||
}
|
||||
} else if (v.getClass() == Double.class && clazz != Double.class) {
|
||||
if (isNumber.test(clazz)) {
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "long":
|
||||
case "Long": _v = (long)(double) v; break;
|
||||
case "Long": v1 = (long)(double) v; break;
|
||||
case "int":
|
||||
case "Integer": _v = (int)(double) v; break;
|
||||
case "Integer": v1 = (int)(double) v; break;
|
||||
case "short":
|
||||
case "Short": _v = (short)(double) v; break;
|
||||
case "Short": v1 = (short)(double) v; break;
|
||||
case "float":
|
||||
case "Float": _v = (float)(double) v; break;
|
||||
default: _v = v;
|
||||
case "Float": v1 = (float)(double) v; break;
|
||||
default: v1 = v;
|
||||
}
|
||||
} else if (clazz == String.class){
|
||||
_v = String.valueOf(v);
|
||||
v1 = String.valueOf(v);
|
||||
}
|
||||
} else if (v.getClass() == String.class) {
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "Date":
|
||||
_v = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) v); break;
|
||||
v1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) v); break;
|
||||
//string ==> number
|
||||
case "short":
|
||||
case "Short": _v = (short)Double.parseDouble((String) v); break;
|
||||
case "Short": v1 = (short)Double.parseDouble((String) v); break;
|
||||
case "float":
|
||||
case "Float": _v = (float)Double.parseDouble((String) v); break;
|
||||
case "Float": v1 = (float)Double.parseDouble((String) v); break;
|
||||
case "int":
|
||||
case "Integer": _v = (int)Double.parseDouble((String) v); break;
|
||||
case "Integer": v1 = (int)Double.parseDouble((String) v); break;
|
||||
case "long":
|
||||
case "Long": _v = (long)Double.parseDouble((String) v); break;
|
||||
case "Long": v1 = (long)Double.parseDouble((String) v); break;
|
||||
case "double":
|
||||
case "Double": _v = Double.parseDouble((String) v); break;
|
||||
default: _v = v;
|
||||
case "Double": v1 = Double.parseDouble((String) v); break;
|
||||
default: v1 = v;
|
||||
}
|
||||
} else if (v.getClass() == Integer.class) {
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "long":
|
||||
case "Long": _v = (long) (int) v; break;
|
||||
case "Long": v1 = (long) (int) v; break;
|
||||
case "int":
|
||||
case "Integer": _v = (int) v; break;
|
||||
case "Integer": v1 = (int) v; break;
|
||||
case "short":
|
||||
case "Short": _v = (short) (int) v; break;
|
||||
case "Short": v1 = (short) (int) v; break;
|
||||
case "float":
|
||||
case "Float": _v = (float) (int) v; break;
|
||||
default: _v = v;
|
||||
case "Float": v1 = (float) (int) v; break;
|
||||
default: v1 = v;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
_v = v;
|
||||
v1 = v;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return (T) _v;
|
||||
return (T) v1;
|
||||
}
|
||||
|
||||
public static <T> T toBean(Map map, Class<T> clazz) {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class MetadataService extends BaseService { //arango
|
||||
|
||||
//修改item的排序
|
||||
@RestMapping(name = "itemsort", comment = "字段排序")
|
||||
public JBean itemSortSave(String alias , String[] items, @RestParam(name = "platToken") String token) {
|
||||
public JBean itemSortSave(String alias, String[] items, @RestParam(name = "platToken") String token) {
|
||||
|
||||
MetaTable metaTable = MetaKit.getMetaTableByAlias(alias);
|
||||
|
||||
@@ -141,7 +141,7 @@ public class MetadataService extends BaseService { //arango
|
||||
}
|
||||
|
||||
@RestMapping(name = "showsort", comment = "展示字段修改")
|
||||
public JBean showSort(String name , List<Map<String,String>> shows, @RestParam(name = "platToken") String token) {
|
||||
public JBean showSort(String name, List<Map<String, String>> shows, @RestParam(name = "platToken") String token) {
|
||||
if (shows == null || shows.size() == 0) return null;
|
||||
|
||||
MetaService metaService = MetaKit.getMetaService(name, token);
|
||||
@@ -151,7 +151,7 @@ public class MetadataService extends BaseService { //arango
|
||||
}
|
||||
|
||||
@RestMapping(name = "exportsave", comment = "导出配置保存")
|
||||
public JBean exportSave(String name , List<Map<String,String>> exports, @RestParam(name = "platToken") String token) {
|
||||
public JBean exportSave(String name, List<Map<String, String>> exports, @RestParam(name = "platToken") String token) {
|
||||
if (exports == null || exports.size() == 0) return null;
|
||||
|
||||
MetaService metaService = MetaKit.getMetaService(name, token);
|
||||
@@ -162,7 +162,7 @@ public class MetadataService extends BaseService { //arango
|
||||
}
|
||||
|
||||
@RestMapping(name = "importsort", comment = "导入字段保存")
|
||||
public JBean importSort(String serviceKey , List<String> items, @RestParam(name = "platToken") String token) {
|
||||
public JBean importSort(String serviceKey, List<String> items, @RestParam(name = "platToken") String token) {
|
||||
if (isEmpty.test(items)) return null;
|
||||
|
||||
MetaTable metaTable = MetaKit.getMetaTable(serviceKey, token);
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.tccn.service;
|
||||
import net.tccn.base.ExcelKit;
|
||||
import net.tccn.base.JBean;
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.dbq.Field;
|
||||
import net.tccn.meta.MetaTable;
|
||||
import net.tccn.plat.SysPlat;
|
||||
@@ -15,7 +16,9 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@@ -67,7 +70,7 @@ public class _FileService extends BaseService {
|
||||
});
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("for d in meta_cols\n" +
|
||||
buf.append("for d in MetaTable\n" +
|
||||
" filter d.name in [");
|
||||
data.values().forEach(x -> {
|
||||
buf.append("'").append(x.getName()).append("',");
|
||||
@@ -113,8 +116,8 @@ public class _FileService extends BaseService {
|
||||
return jBean;
|
||||
}
|
||||
|
||||
@RestMapping(name = "import_metatable", comment = "导入excel数据到metatable")
|
||||
public JBean importMetaTable(@RestParam(name = "sheetArr", comment = "sheet名") String[] sheetArr,
|
||||
@RestMapping(ignore = true, comment = "导入excel数据到metatable")
|
||||
public JBean saveSheet(@RestParam(name = "sheetArr", comment = "sheet名") String[] sheetArr,
|
||||
@RestParam(name = "filePath", comment = "文件路径") String filePath,
|
||||
@RestParam(name = "platToken") String token) {
|
||||
JBean jBean = new JBean();
|
||||
@@ -123,26 +126,24 @@ public class _FileService extends BaseService {
|
||||
String[] fields = {"field", "cate", "must", "remark1", "remark2", "tag", "selects", "column", "filter", "ck", "edit"};
|
||||
try {
|
||||
Map<String, List<Map>> map = ExcelKit.readExcelAll(file, fields);
|
||||
map.forEach((k, v) -> {
|
||||
if (v.size() > 2) {
|
||||
MetaTable table = toCols(v);
|
||||
for (String sn : sheetArr) {
|
||||
if (table.getName().equals(sn)) { //在选中列表中
|
||||
MetaTable metaTable = new MetaTable();
|
||||
metaTable.setSysPlatId(platId(token));
|
||||
metaTable.setName(table.getName());
|
||||
Set<String> ks = map.keySet();
|
||||
|
||||
MetaTable _metaTable = MetaTable.dao.findFirst(metaTable);
|
||||
if (_metaTable == null) {//库里没有数据保存
|
||||
table.setSysPlatId(platId(token));
|
||||
table.save();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// 找到需要导入的sheet名,并组装对应的数据
|
||||
MetaTable[] metaTables = Stream.of(sheetArr).filter(x -> {
|
||||
if (!ks.contains(x)) return false;
|
||||
|
||||
MetaTable bean = new MetaTable();
|
||||
bean.setSysPlatId(platId(token));
|
||||
bean.setName(x);
|
||||
return MetaTable.dao.findFirst(bean) == null;
|
||||
}).map(x -> {
|
||||
MetaTable metaTable = toCols(map.get(x));
|
||||
metaTable.setSysPlatId(platId(token));
|
||||
metaTable.setAlias(MetaKit.nextAlias());
|
||||
return metaTable;
|
||||
}).toArray(MetaTable[]::new);
|
||||
|
||||
MetaKit.save(metaTables);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -29,10 +29,9 @@ public class _TableService extends BaseService {
|
||||
|
||||
|
||||
@RestMapping(name = "sheets", comment = "导入选择列表数据准备")
|
||||
public JBean sheets(String cate, //类型
|
||||
//excel {文件地址}
|
||||
public JBean sheets(String cate, //类型 excel|mysql
|
||||
// excel
|
||||
String filePath,
|
||||
|
||||
//mysql {数据库连接账号、数据源id、数据库database数组}
|
||||
String dbPlatId, String catalog,
|
||||
@RestParam(name = "platToken") String token) {
|
||||
@@ -40,9 +39,9 @@ public class _TableService extends BaseService {
|
||||
JBean jBean = new JBean();
|
||||
|
||||
if ("excel".equals(cate)) {
|
||||
jBean.setBody(fileService.data(filePath, token));
|
||||
jBean = fileService.data(filePath, token);
|
||||
|
||||
} else if ("mysql".equals(cate)){
|
||||
} else if ("mysql".equals(cate)) {
|
||||
List<Table> list = dbService.tableList(dbPlatId, catalog, null);
|
||||
|
||||
String[] tableArr = list.stream().map(Table::getName).toArray(String[]::new);
|
||||
@@ -65,52 +64,45 @@ public class _TableService extends BaseService {
|
||||
return jBean;
|
||||
}
|
||||
|
||||
|
||||
/*public JBean tableInfo(DbAccount dbAccount,
|
||||
@RestMapping(name = "sheet_info", comment = "sheet详情")
|
||||
public JBean sheetInfo(String cate, @RestParam(name = "platToken") String token,
|
||||
// excel
|
||||
String filePath, String sheetName,
|
||||
// mysql
|
||||
String dbPlatId, String catalog, String tableName) {
|
||||
|
||||
dbService.tableInfo(dbAccount, dbPlatId, catalog, tableName)
|
||||
|
||||
if ("excel".equals(cate)) {
|
||||
return fileService.sheetData(filePath, sheetName, token);
|
||||
} else if ("mysql".equals(cate)) {
|
||||
return new JBean().setBody(dbService.tableInfo(dbPlatId, catalog, tableName));
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
@RestMapping(name = "table_save", comment = "保存数据源实体到元数据实体表")
|
||||
public void tableSave(String dbPlatId,
|
||||
String catalog,
|
||||
String[] tableArr,
|
||||
@RestParam(name = "platToken") String token) {
|
||||
|
||||
List<String> hv = MetaKit.tableExist(tableArr, token);
|
||||
List<Table> tables = dbService.tableInfoList(dbPlatId, catalog, tableArr);
|
||||
|
||||
MetaTable[] metaTables = tables.stream()
|
||||
.filter(t -> !hv.contains(t.getName())) // 去除同名
|
||||
.map(t -> {
|
||||
MetaTable metaTable = MetaTable.toAs(t);
|
||||
metaTable.setCatalog(catalog);
|
||||
metaTable.setDbPlatId(dbPlatId);
|
||||
metaTable.setAlias(MetaKit.nextAlias());// 表别名
|
||||
metaTable.setSysPlatId(platId(token));
|
||||
return metaTable;
|
||||
}).toArray(MetaTable[]::new);
|
||||
|
||||
MetaKit.save(metaTables);
|
||||
}
|
||||
|
||||
/*@Comment("查询元数据中存在的表")
|
||||
private CompletableFuture<List<String>> tableExist(String[] tableArr, String token) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("for d in MetaTable\n" +
|
||||
" filter d.name in [");
|
||||
for (String x : tableArr) {
|
||||
buf.append("'").append(x).append("',");
|
||||
}
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
buf.append("] and d.sysPlatId=='" + platId(token) + "'\n" +
|
||||
" return d.name");
|
||||
List<String> hv = MetaTable.dao.find(buf.toString(), String.class); //在元数据中已经存在的sheet
|
||||
return hv;
|
||||
});
|
||||
}*/
|
||||
|
||||
@RestMapping(name = "table_save", comment = "保存数据源实体到元数据实体表")
|
||||
public JBean tableSave(String cate, @RestParam(name = "platToken") String token,
|
||||
String filePath, String[] sheetNames,
|
||||
String dbPlatId, String catalog, String[] tableArr) {
|
||||
|
||||
if ("excel".equals(cate)) {
|
||||
return fileService.saveSheet(sheetNames, filePath, token);
|
||||
} else if ("mysql".equals(cate)) {
|
||||
List<String> hv = MetaKit.tableExist(tableArr, token);
|
||||
List<Table> tables = dbService.tableInfoList(dbPlatId, catalog, tableArr);
|
||||
|
||||
MetaTable[] metaTables = tables.stream()
|
||||
.filter(t -> !hv.contains(t.getName())) // 去除同名
|
||||
.map(t -> {
|
||||
MetaTable metaTable = MetaTable.toAs(t);
|
||||
metaTable.setCatalog(catalog);
|
||||
metaTable.setDbPlatId(dbPlatId);
|
||||
metaTable.setAlias(MetaKit.nextAlias());// 表别名
|
||||
metaTable.setSysPlatId(platId(token));
|
||||
return metaTable;
|
||||
}).toArray(MetaTable[]::new);
|
||||
|
||||
MetaKit.save(metaTables);
|
||||
}
|
||||
return JBean.OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.redkale.net.http.HttpResponse;
|
||||
import org.redkale.net.http.HttpServlet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -20,6 +21,8 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public class BaseServlet extends HttpServlet {
|
||||
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
protected File webroot;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
|
||||
41
src/main/java/net/tccn/servlet/FileServlet.java
Normal file
41
src/main/java/net/tccn/servlet/FileServlet.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package net.tccn.servlet;
|
||||
|
||||
import net.tccn.base.JBean;
|
||||
import net.tccn.base.Kv;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/10/11 17:08.
|
||||
*/
|
||||
@WebServlet(value = {"/upload/*"}, comment = "测试servlet")
|
||||
public class FileServlet extends BaseServlet {
|
||||
|
||||
@HttpMapping(url = "/upload/", comment = "文件上传,访问地址:/upload/x")
|
||||
public void uploadExcel(HttpRequest request, HttpResponse response) {
|
||||
JBean jBean = new JBean();
|
||||
List list = new ArrayList();
|
||||
try {
|
||||
for (MultiPart part : request.multiParts()) {
|
||||
String filePath = "u/table/" + part.getFilename();
|
||||
File destFile = new File(webroot, filePath);
|
||||
destFile.getParentFile().mkdirs();
|
||||
part.save(destFile);
|
||||
|
||||
list.add(
|
||||
Kv.of("name", part.getFilename())
|
||||
.set("filePath", filePath)
|
||||
.set("viewPath", filePath)
|
||||
);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
response.finish(jBean.set(0, "", list));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user