.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -11,6 +11,6 @@
|
||||
/tmp/
|
||||
/lib/
|
||||
/libs/
|
||||
/u/
|
||||
/root/u/
|
||||
|
||||
apidoc.*
|
||||
@@ -210,7 +210,8 @@
|
||||
<th></th>
|
||||
<th>字段名</th>
|
||||
<th>中文名</th>
|
||||
<!--<th>展示名</th>-->
|
||||
<th>格式化类型</th>
|
||||
<th>附加参数</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="item in serviceInfo.exports">
|
||||
@@ -218,7 +219,17 @@
|
||||
<input type="hidden" name="item" :value="JSON.stringify(item)">
|
||||
</td>
|
||||
<td v-text="item.col" style="background-color: rgb(235, 235, 228);"></td>
|
||||
<td style="padding: 1px;"><input v-model="item.label" class="form-control" style="width: 130px;padding: 0px"></td>
|
||||
<td style="padding: 1px;"><input v-model="item.label" class="form-control" style="padding: 0px"></td>
|
||||
<td style="padding: 1px;">
|
||||
<select v-model="item.inType" class="form-control" style="width: 130px">
|
||||
<option></option>
|
||||
<option v-for="x in exportFmtTypes" :value="x">{{x}}</option>
|
||||
</select>
|
||||
</td>
|
||||
<td style="padding: 1px;" title="格式化类型为:funs或qtask的时候需要填写附加参数">
|
||||
<input v-show="item.inType == 'FUNC' || item.inType == 'QTASK' || item.inType == 'DICT'" v-model="item.inExt" class="form-control" style="width: 130px;padding: 0px">
|
||||
<input disabled v-show="item.inType != 'FUNC' && item.inType != 'QTASK' && item.inType != 'DICT'" v-model="item.inExt" class="form-control" style="width: 130px;padding: 0px">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@@ -428,7 +439,7 @@
|
||||
<br>
|
||||
|
||||
<div v-show="serviceInfo.dels.cate == 'UP_FIELD'" class="form-group">
|
||||
<label for="name" class="col-md-2">SQL</label>
|
||||
<label class="col-md-2">SQL</label>
|
||||
<div class="col-md-8">
|
||||
<textarea v-model="serviceInfo.dels.sql1" disabled style="width: 100%;" rows="5"></textarea>
|
||||
<!--
|
||||
@@ -438,7 +449,7 @@
|
||||
</div>
|
||||
|
||||
<div v-show="serviceInfo.dels.cate == 'SQL'" class="form-group">
|
||||
<label for="name" class="col-md-2">SQL</label>
|
||||
<label class="col-md-2">SQL</label>
|
||||
<div class="col-md-8">
|
||||
<textarea v-model="serviceInfo.dels.sql" style="width: 100%;" rows="5"></textarea>
|
||||
<!--
|
||||
@@ -507,6 +518,8 @@
|
||||
sheetArr: ["a"],//别名
|
||||
sheet: "a",//别名
|
||||
|
||||
exportFmtTypes: ["DICT"], // , "DAY", "TIME"
|
||||
|
||||
filterRemarks: {
|
||||
EQUAL:"等于", NOTEQUAL:"不等于", IN: "包含", NOTIN:"不包含", LIKE: "模糊查询", RANGE: "范围"
|
||||
},
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 required">任务名称</label>
|
||||
<div class="col-md-6 col-sm-10">
|
||||
<input v-model="row.comment" class="form-control" placeholder="请输入 业务名称">
|
||||
<input v-model="row.title" class="form-control" placeholder="请输入 业务名称">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -76,7 +76,7 @@
|
||||
<div class="form-group" style="margin-bottom: 0">
|
||||
<label class="col-md-2 required">执行内容</label>
|
||||
<div class="col-md-10">
|
||||
<textarea v-model="row.content" class="form-control layui-code" rows="10" placeholder="请输入 SQL (支持jfinal-enjoy模板语法)" > </textarea>
|
||||
<textarea v-model="row.content" class="form-control layui-code" rows="5" placeholder="请输入 SQL (支持jfinal-enjoy模板语法)" > </textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -100,6 +100,12 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="para" class="col-sm-2">备注(注释)</label>
|
||||
<div class="col-sm-10">
|
||||
<input v-model="row.remark" class="form-control" id="remark" placeholder="请输入 备注">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -139,7 +145,8 @@
|
||||
title: "QTask 管理",
|
||||
cols: [
|
||||
{col: "name", label: "任务标识码",},
|
||||
{col: "comment", label: "任务名称",},
|
||||
{col: "title", label: "任务名称",},
|
||||
{col: "remark", label: "备注",},
|
||||
],
|
||||
filters: [],
|
||||
cates: ["find","update"]
|
||||
|
||||
@@ -29,10 +29,20 @@ import java.util.*;
|
||||
* 使用poi报表导出工具类
|
||||
* 把poi的一个调用接口抽出来,便于导出功能的管理
|
||||
*
|
||||
* @param
|
||||
* @author LiangXianYou lxy208@126.com
|
||||
*/
|
||||
public class ExcelKit {
|
||||
|
||||
// 在已有的excel中新增sheet并写入数据
|
||||
public static <T> Workbook exportExcel(List<T> list, LinkedHashMap<String, String> headMap, Workbook workbook, String sheetName) {
|
||||
return dataToWorkBook(list, headMap, workbook, sheetName);
|
||||
}
|
||||
|
||||
public static <T> Workbook exportExcel(List<T> list, LinkedHashMap<String, String> headMap, Workbook workbook) {
|
||||
return dataToWorkBook(list, headMap, workbook, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excels导出多个sheet
|
||||
*
|
||||
@@ -40,22 +50,24 @@ public class ExcelKit {
|
||||
* @date 2015-6-16 下午5:56:56
|
||||
*/
|
||||
//map:data,sheetName,hds,hdNames,
|
||||
public static <T> Workbook exportExcels(List<Map<String, Object>> list) throws Exception {
|
||||
public static <T> Workbook exportExcels(List<Map<String, Object>> list) {
|
||||
|
||||
Workbook wb = new SXSSFWorkbook();
|
||||
Workbook wb = new SXSSFWorkbook(); //创建工作薄
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map<String, Object> map = list.get(i);
|
||||
Sheet sheet = wb.createSheet();
|
||||
Sheet sheet = wb.createSheet(); //创建工作表
|
||||
String sheetName = (String) map.get("sheetName");
|
||||
wb.setSheetName(i, sheetName);
|
||||
//写入表头---Excel的第一行数据
|
||||
Row nRow = sheet.createRow(0);
|
||||
Row nRow = sheet.createRow(0); //创建行
|
||||
String[] hdNames = (String[]) map.get("hdNames");
|
||||
for (int j = 0; j < hdNames.length; j++) {
|
||||
Cell nCell = nRow.createCell(j);
|
||||
Cell nCell = nRow.createCell(j); //创建单元格
|
||||
nCell.setCellValue(hdNames[j]);
|
||||
}
|
||||
|
||||
//写入每一行数据---一条记录就是一行数据
|
||||
@SuppressWarnings("unchecked")
|
||||
List<T> data = (List<T>) map.get("data");
|
||||
String[] hds = (String[]) map.get("hds");
|
||||
dataToSheet(sheet, data, hds, 1);
|
||||
@@ -65,16 +77,28 @@ public class ExcelKit {
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数说明:
|
||||
* list:list数据集合
|
||||
* headMap:每一列的字段名和对应的表头名称 如:{name:"姓名", age:"年龄"}
|
||||
* 通过数据构建 Workbook 对象
|
||||
*
|
||||
* @param list 数据
|
||||
* @param headMap 每一列的字段名和对应的表头名称 如:{name:"姓名", age:"年龄"}
|
||||
* @param <T> 数据泛型,支持javaBean 或Map
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @author LiangXianYou
|
||||
* @date 2015-3-13 上午11:00:30
|
||||
*/
|
||||
public static <T> Workbook exportExcel(List<T> list, LinkedHashMap<String, String> headMap) throws Exception {
|
||||
public static <T> Workbook exportExcel(List<T> list, LinkedHashMap<String, String> headMap) {
|
||||
return dataToWorkBook(list, headMap, null, null);
|
||||
}
|
||||
|
||||
private static <T> Workbook dataToWorkBook(List<T> list, LinkedHashMap<String, String> headMap, Workbook wb, String sheetName) {
|
||||
if (wb == null) {
|
||||
wb = new SXSSFWorkbook();
|
||||
}
|
||||
|
||||
Sheet sheet = sheetName != null && !sheetName.isEmpty() ?
|
||||
wb.createSheet(sheetName) : wb.createSheet();
|
||||
|
||||
String[] hdNames = new String[headMap.size()]; //
|
||||
String[] hds = new String[headMap.size()];
|
||||
|
||||
@@ -85,45 +109,25 @@ public class ExcelKit {
|
||||
tag[0]++;
|
||||
});
|
||||
|
||||
return exportExcel(list, hdNames, hds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用数据构建 excel 工作薄对象
|
||||
*
|
||||
* @param list 数据
|
||||
* @param hdNames 表头
|
||||
* @param hds 每条记录中数据的属性名
|
||||
* @param <T> 数据泛型,支持javaBean 或Map
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @author LiangXianYou
|
||||
* @date 2015-3-13 上午11:00:30
|
||||
*/
|
||||
public static <T> Workbook exportExcel(List<T> list, String[] hdNames, String[] hds) throws Exception {
|
||||
|
||||
Workbook wb = new SXSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
//写入表头---Excel的第一行数据
|
||||
Row nRow = sheet.createRow(0);
|
||||
for (int i = 0; i < hdNames.length; i++) {
|
||||
Cell nCell = nRow.createCell(i);
|
||||
nCell.setCellValue(hdNames[i]);
|
||||
}
|
||||
|
||||
// 写入每一条记录
|
||||
dataToSheet(sheet, list, hds, 1);
|
||||
return wb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过泛型实例对象得到某一字段值
|
||||
*
|
||||
* @author LiangXianYou
|
||||
* @date 2015-3-13 上午10:53:32
|
||||
*/
|
||||
private static <T> Object getFieldValue(T t, String fieldName) throws Exception {
|
||||
Object v;
|
||||
private static <T> Object getFieldValue(T t, String fieldName) throws NoSuchFieldException, IllegalAccessException {
|
||||
Object v = null;
|
||||
|
||||
if (t == null) {
|
||||
v = null;
|
||||
@@ -156,8 +160,8 @@ public class ExcelKit {
|
||||
Cell cell = nRow.createCell(k);
|
||||
|
||||
try {
|
||||
Object v = getFieldValue(list.get(j), hds[k]);
|
||||
dataToCell(cell, v);
|
||||
Object v = getFieldValue(list.get(j), hds[k]); //得到列的值
|
||||
dataToCell(cell, v); //将值写入Excel
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -181,49 +185,49 @@ public class ExcelKit {
|
||||
//======================= 读取excel ===============================
|
||||
|
||||
//read excel head
|
||||
public static Map readExcelHead(File file, String[] fields) throws IOException {
|
||||
public static Map readExcelHead(File file, String[] fields) {
|
||||
List<Map> list = readExcel(file, fields, 1, null);
|
||||
return list.size() > 0 ? list.get(0) : new HashMap();
|
||||
}
|
||||
|
||||
//read excel head by sheetName
|
||||
public static Map readExcelHead(File file, String[] fields, String sheetName) throws IOException {
|
||||
public static Map readExcelHead(File file, String[] fields, String sheetName) {
|
||||
List<Map> list = readExcel(file, fields, 1, sheetName);
|
||||
return list.size() > 0 ? list.get(0) : new HashMap();
|
||||
}
|
||||
|
||||
//read excel sheet[0]
|
||||
public static List<Map> readExcel(File file, String[] fields) throws IOException {
|
||||
public static List<Map> readExcel(File file, String[] fields) {
|
||||
return readExcel(file, fields, -1, null);
|
||||
}
|
||||
|
||||
//read excel sheet[0] no fields
|
||||
public static List<Map> readExcel(File file) throws IOException {
|
||||
public static List<Map> readExcel(File file) {
|
||||
return readExcel(file, null, -1, null);
|
||||
}
|
||||
|
||||
//read excel by sheetName
|
||||
public static List<Map> readExcel(File file, String[] fields, String sheetName) throws IOException {
|
||||
public static List<Map> readExcel(File file, String[] fields, String sheetName) {
|
||||
return readExcel(file, fields, -1, sheetName);
|
||||
}
|
||||
|
||||
//read excel by sheetName no fields
|
||||
public static List<Map> readExcel(File file, String sheetName) throws IOException {
|
||||
public static List<Map> readExcel(File file, String sheetName) {
|
||||
return readExcel(file, null, -1, sheetName);
|
||||
}
|
||||
|
||||
//read excel all sheet
|
||||
public static Map<String, List<Map>> readExcelAll(File file, String[] fields) throws IOException {
|
||||
public static Map<String, List<Map>> readExcelAll(File file, String[] fields) {
|
||||
return readExcelAll(file, fields, -1);
|
||||
}
|
||||
|
||||
//read all excel no fields
|
||||
public static Map<String, List<Map>> readExcelAll(File file) throws IOException {
|
||||
public static Map<String, List<Map>> readExcelAll(File file) {
|
||||
return readExcelAll(file, null, -1);
|
||||
}
|
||||
|
||||
//read excel sheet[0]
|
||||
private static List<Map> readExcel(File file, String[] fields, int lastRowNum, String sheetName) throws IOException {
|
||||
private static List<Map> readExcel(File file, String[] fields, int lastRowNum, String sheetName) {
|
||||
Workbook wk = getWorkbook(file);
|
||||
Sheet sheet = sheetName == null ? wk.getSheetAt(0) : wk.getSheet(sheetName);
|
||||
if (sheet == null) throw new OfficeXmlFileException("sheet[" + sheetName + "] can't findList");
|
||||
@@ -244,7 +248,7 @@ public class ExcelKit {
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private static Map<String, List<Map>> readExcelAll(File file, String[] fields, int lastRowNum) throws IOException {
|
||||
private static Map<String, List<Map>> readExcelAll(File file, String[] fields, int lastRowNum) {
|
||||
Workbook wk = getWorkbook(file);
|
||||
|
||||
Map<String, List<Map>> data = new LinkedHashMap<>();
|
||||
@@ -253,6 +257,10 @@ public class ExcelKit {
|
||||
Sheet sheet = wk.getSheetAt(i);
|
||||
List<Map> maps = readExcel(sheet, fields, lastRowNum);
|
||||
|
||||
//move head
|
||||
/*if (lastRowNum < 0 && maps.size() > 0) {
|
||||
maps.remove(0);
|
||||
}*/
|
||||
data.put(sheet.getSheetName(), maps);
|
||||
}
|
||||
return data;
|
||||
@@ -263,7 +271,7 @@ public class ExcelKit {
|
||||
*
|
||||
* @author Lxyer 2016/8/1 10:32.
|
||||
*/
|
||||
private static List<Map> readExcel(Sheet sheet, String[] fields, int lastRowNum) throws OfficeXmlFileException {
|
||||
private static List<Map> readExcel(Sheet sheet, String[] fields, int lastRowNum) {
|
||||
if (lastRowNum < 0 || lastRowNum > sheet.getLastRowNum()) {
|
||||
lastRowNum = sheet.getLastRowNum();
|
||||
}
|
||||
@@ -286,6 +294,9 @@ public class ExcelKit {
|
||||
|
||||
Map map = new HashMap();
|
||||
for (int j = 0; j < cellNum && j < fields.length; j++) {
|
||||
if (fields[j] == null || "".equals(fields[j])) {
|
||||
continue;
|
||||
}
|
||||
Cell cell = row.getCell(j);
|
||||
if (cell == null) {
|
||||
map.put(fields[j], "");
|
||||
@@ -306,7 +317,7 @@ public class ExcelKit {
|
||||
/**
|
||||
* @author Lxyer 2016/9/21 00:38.
|
||||
*/
|
||||
private static List<Map> readExcel(Sheet sheet, int lastRowNum) throws OfficeXmlFileException {
|
||||
private static List<Map> readExcel(Sheet sheet, int lastRowNum) {
|
||||
List<Map> list = new ArrayList<>();
|
||||
if (lastRowNum < 0 || lastRowNum > sheet.getLastRowNum()) {
|
||||
lastRowNum = sheet.getLastRowNum();
|
||||
@@ -361,7 +372,7 @@ public class ExcelKit {
|
||||
}
|
||||
|
||||
//get all sheet names
|
||||
public static List<String> getSheetNames(File file) throws IOException {
|
||||
public static List<String> getSheetNames(File file) {
|
||||
Workbook wk = getWorkbook(file);
|
||||
List<String> sheetNames = new ArrayList<>();
|
||||
for (int i = 0; i < wk.getNumberOfSheets(); i++) {
|
||||
@@ -370,24 +381,12 @@ public class ExcelKit {
|
||||
return sheetNames;
|
||||
}
|
||||
|
||||
private static Workbook getWorkbook(File file) throws IOException {
|
||||
public static Workbook getWorkbook(File file) {
|
||||
try {
|
||||
return WorkbookFactory.create(file);
|
||||
/*Workbook wk;
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
try {
|
||||
wk = new HSSFWorkbook(fis);//if excel version 2007+ will throws OfficeXmlFileException
|
||||
} catch (OfficeXmlFileException e) {
|
||||
wk = new SXSSFWorkbook(new XSSFWorkbook(fis));
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wk;*/
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package net.tccn.base;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.template.Engine;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
import static java.util.Arrays.asList;
|
||||
@@ -16,11 +20,11 @@ public final class FileKit {
|
||||
private FileKit() {
|
||||
}
|
||||
|
||||
public static void strToFile(String entityBody, File file) throws IOException {
|
||||
public static void strToFile(String entityBody, File file) {
|
||||
strToFile(entityBody, file, true);
|
||||
}
|
||||
|
||||
public static void strToFile(String entityBody, File file, boolean existDel) throws IOException {
|
||||
public static void strToFile(String entityBody, File file, boolean existDel) {
|
||||
if (file.exists()) {
|
||||
if (existDel) {
|
||||
file.delete();
|
||||
@@ -32,11 +36,15 @@ public final class FileKit {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
try (
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
) {
|
||||
out.write(entityBody.getBytes("UTF-8"));
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件/文件目录
|
||||
*
|
||||
@@ -47,20 +55,27 @@ public final class FileKit {
|
||||
copyFiles(source, target, "");
|
||||
}
|
||||
|
||||
private static void copyFiles(File source, File target, String linkPath) {
|
||||
/**
|
||||
* 拷贝文件/文件目录
|
||||
*
|
||||
* @param source
|
||||
* @param target
|
||||
* @param linkPath
|
||||
*/
|
||||
public static void copyFiles(File source, File target, String linkPath) {
|
||||
if (source.isDirectory()) {
|
||||
final String linkPath1 = linkPath + File.separator + source.getName();
|
||||
final String _linkPath = linkPath + File.separator + source.getName();
|
||||
asList(source.listFiles()).forEach(f -> {
|
||||
copyFiles(f, target, linkPath1);
|
||||
copyFiles(f, target, _linkPath);
|
||||
});
|
||||
} else if (source.isFile()) {
|
||||
try {
|
||||
String linkPath1 = "";
|
||||
String _linkPath = "";
|
||||
int index = linkPath.indexOf(File.separator, 1);
|
||||
if (index > 0) {
|
||||
linkPath1 = linkPath.substring(index);
|
||||
_linkPath = linkPath.substring(index);
|
||||
}
|
||||
File targetFile = new File(target.toPath() + linkPath1 + File.separator + source.getName());
|
||||
File targetFile = new File(target.toPath() + _linkPath + File.separator + source.getName());
|
||||
if (!targetFile.getParentFile().exists()) {
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
@@ -105,58 +120,43 @@ public final class FileKit {
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String readAll(InputStream inputStream) throws IOException {
|
||||
public static String readAll(InputStream inputStream) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String str;
|
||||
try {
|
||||
while ((str = reader.readLine()) != null) {
|
||||
buf.append(str + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板到文件
|
||||
*
|
||||
* @param sourceStr
|
||||
* @param target
|
||||
* @param kv
|
||||
*/
|
||||
/*public static void tplRender(String sourceStr, File target, Kv kv){
|
||||
public static void tplRender(String sourceStr, File target, Kv kv) {
|
||||
String str = "";
|
||||
if (sourceStr != null && !sourceStr.isEmpty()) {
|
||||
str = Engine.use().getTemplateByString(sourceStr).renderToString(kv);
|
||||
}
|
||||
try {
|
||||
strToFile(str, target, true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 通过模板创建内容
|
||||
*
|
||||
* @param tplFile
|
||||
* @param para
|
||||
*/
|
||||
/*public static void tplRender(File tplFile, File file, Map para) throws IOException {
|
||||
public static void tplRender(File tplFile, File file, Map para) throws IOException {
|
||||
String str = Engine.use().getTemplate(tplFile.getPath()).renderToString(para);
|
||||
strToFile(str, file);
|
||||
}*/
|
||||
|
||||
/*public static String tplRender(File tplFile, Map para){
|
||||
return Engine.use().getTemplate(tplFile.getPath()).renderToString(para);
|
||||
}*/
|
||||
|
||||
/*public static void objToFile(Object obj, File file) throws FileNotFoundException {
|
||||
if (file.exists()) {
|
||||
throw new RuntimeException(file.getPath() + "已经存在");
|
||||
}
|
||||
|
||||
if (!file.getParentFile().exists()){
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.write(obj.);
|
||||
out.close();
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ import net.tccn.base.arango.Doc;
|
||||
import net.tccn.dbq.jdbc.api.DbAccount;
|
||||
import net.tccn.dbq.jdbc.api.DbKit;
|
||||
import net.tccn.dbq.table.Field;
|
||||
import net.tccn.dict.DictKit;
|
||||
import net.tccn.meta.*;
|
||||
import net.tccn.plat.DbPlat;
|
||||
import net.tccn.plat.SysPlat;
|
||||
import net.tccn.qtask.TaskEntity;
|
||||
import net.tccn.qtask.TaskKit;
|
||||
import net.tccn.user.User;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.Comment;
|
||||
@@ -15,7 +18,6 @@ import org.redkale.util.TypeToken;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -25,7 +27,6 @@ import java.util.stream.Collectors;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
*
|
||||
* Created by liangxianyou at 2019/1/7 13:31.
|
||||
*/
|
||||
public final class MetaKit {
|
||||
@@ -42,9 +43,12 @@ public final class MetaKit {
|
||||
private static List<SysPlat> sysPlats;
|
||||
@Getter
|
||||
private static List<User> users;
|
||||
@Getter
|
||||
private static List<TaskEntity> taskEntities;
|
||||
|
||||
protected static String dcate;
|
||||
private static final JsonConvert convert = JsonConvert.root();
|
||||
|
||||
// -----------------------------------
|
||||
public static void init() {
|
||||
reload(MetaTable.class);
|
||||
@@ -53,46 +57,57 @@ public final class MetaKit {
|
||||
reload(DbAccount.class);
|
||||
reload(SysPlat.class);
|
||||
reload(User.class);
|
||||
reload(TaskEntity.class);
|
||||
|
||||
DictKit dictKit = DictKit.use("");
|
||||
|
||||
}
|
||||
|
||||
public static <T extends Doc> void reload(Class<T> clazz) {
|
||||
reload(clazz, null);
|
||||
}
|
||||
|
||||
public static <T extends Doc> void reload(T t) {
|
||||
reload(t.getClass(), t.getKey());
|
||||
}
|
||||
|
||||
public static <T extends Doc> void reload(Class<T> clazz, String key) {
|
||||
|
||||
try {
|
||||
File file = new File(String.format("tmp/%s.json", clazz.getSimpleName()));
|
||||
if ("file".equals(dcate)) {
|
||||
if (MetaTable.class == clazz) {
|
||||
Type type = new TypeToken<List<MetaTable>>() {}.getType();
|
||||
Type type = new TypeToken<List<MetaTable>>() {
|
||||
}.getType();
|
||||
metaTables = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (MetaLink.class == clazz) {
|
||||
Type type = new TypeToken<List<MetaLink>>() {}.getType();
|
||||
} else if (MetaLink.class == clazz) {
|
||||
Type type = new TypeToken<List<MetaLink>>() {
|
||||
}.getType();
|
||||
metaLinks = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (MetaService.class == clazz) {
|
||||
Type type = new TypeToken<List<MetaService>>() {}.getType();
|
||||
} else if (MetaService.class == clazz) {
|
||||
Type type = new TypeToken<List<MetaService>>() {
|
||||
}.getType();
|
||||
metaServices = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (DbAccount.class == clazz) {
|
||||
Type type = new TypeToken<List<DbAccount>>() {}.getType();
|
||||
} else if (DbAccount.class == clazz) {
|
||||
Type type = new TypeToken<List<DbAccount>>() {
|
||||
}.getType();
|
||||
dbPlats = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (DbPlat.class == clazz) {
|
||||
Type type = new TypeToken<List<DbAccount>>() {}.getType();
|
||||
} else if (DbPlat.class == clazz) {
|
||||
Type type = new TypeToken<List<DbAccount>>() {
|
||||
}.getType();
|
||||
dbPlats = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (SysPlat.class == clazz) {
|
||||
Type type = new TypeToken<List<SysPlat>>() {}.getType();
|
||||
} else if (SysPlat.class == clazz) {
|
||||
Type type = new TypeToken<List<SysPlat>>() {
|
||||
}.getType();
|
||||
sysPlats = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (User.class == clazz) {
|
||||
Type type = new TypeToken<List<User>>() {}.getType();
|
||||
} else if (User.class == clazz) {
|
||||
Type type = new TypeToken<List<User>>() {
|
||||
}.getType();
|
||||
users = convert.convertFrom(type, new FileInputStream(file));
|
||||
} else if (TaskEntity.class == clazz) {
|
||||
Type type = new TypeToken<List<TaskEntity>>() {
|
||||
}.getType();
|
||||
taskEntities = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
} else {
|
||||
if (MetaTable.class == clazz) metaTables = MetaTable.dao.find();
|
||||
@@ -102,6 +117,10 @@ public final class MetaKit {
|
||||
else if (DbPlat.class == clazz) dbPlats = DbAccount.dao.find();
|
||||
else if (SysPlat.class == clazz) sysPlats = SysPlat.dao.find();
|
||||
else if (User.class == clazz) users = User.dao.find();
|
||||
else if (TaskEntity.class == clazz) {
|
||||
taskEntities = TaskEntity.dao.find();
|
||||
TaskKit.init();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -116,6 +135,7 @@ public final class MetaKit {
|
||||
cacheSave(DbPlat.class);
|
||||
cacheSave(SysPlat.class);
|
||||
cacheSave(User.class);
|
||||
cacheSave(TaskEntity.class);
|
||||
}
|
||||
|
||||
private static void cacheSave(Class clazz) {
|
||||
@@ -132,15 +152,12 @@ public final class MetaKit {
|
||||
|
||||
File file = new File(String.format("tmp/%s.json", list.get(0).getClass().getSimpleName()));
|
||||
file.getParentFile().mkdirs();
|
||||
try {
|
||||
FileKit.strToFile(MetaKit.convert.convertTo(list), file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到业务主表
|
||||
*
|
||||
* @param serviceName
|
||||
* @param token
|
||||
* @return
|
||||
@@ -158,6 +175,7 @@ public final class MetaKit {
|
||||
|
||||
/**
|
||||
* 通过 别名 查询 MetaTable
|
||||
*
|
||||
* @param alias
|
||||
* @return
|
||||
*/
|
||||
@@ -493,6 +511,7 @@ public final class MetaKit {
|
||||
}
|
||||
|
||||
public static String lastAlias;
|
||||
|
||||
public static String nextAlias() {
|
||||
if (lastAlias == null) {
|
||||
String aql = TplKit.use(true).getTpl("metaTable.lastAlias");
|
||||
|
||||
31
src/main/java/net/tccn/base/PropKit.java
Normal file
31
src/main/java/net/tccn/base/PropKit.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package net.tccn.base;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou
|
||||
*/
|
||||
public final class PropKit {
|
||||
private static Properties properties = new Properties();
|
||||
static {
|
||||
try {
|
||||
// 读取导入配置文件
|
||||
|
||||
properties.load(new FileReader(new File("conf/config.txt")));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getProperty(String key) {
|
||||
return properties.getProperty(key);
|
||||
}
|
||||
public static String getProperty(String key, String value) {
|
||||
String oldValue = getProperty(key);
|
||||
properties.setProperty(key, value);
|
||||
return oldValue;
|
||||
}
|
||||
}
|
||||
16
src/main/java/net/tccn/dict/Dict.java
Normal file
16
src/main/java/net/tccn/dict/Dict.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package net.tccn.dict;
|
||||
|
||||
import net.tccn.base.arango.Doc;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou
|
||||
*/
|
||||
public class Dict extends Doc<Dict> implements Serializable {
|
||||
private String type; // 字典类型
|
||||
private String value; // 字典值
|
||||
private String label; // 中文名
|
||||
private String pValue; // 父级字典值
|
||||
private String code; //
|
||||
}
|
||||
160
src/main/java/net/tccn/dict/DictKit.java
Normal file
160
src/main/java/net/tccn/dict/DictKit.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package net.tccn.dict;
|
||||
|
||||
import com.arangodb.ArangoDB;
|
||||
import com.arangodb.ArangoDatabase;
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.base.PropKit;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 字典工具类
|
||||
* 每个 token(平台token) 对应一个DictKit实例
|
||||
*
|
||||
* @author: liangxianyou
|
||||
*/
|
||||
public final class DictKit {
|
||||
private static Map<String, DictKit> kits = new HashMap<>();
|
||||
private String platToken;
|
||||
private Map<String, List<Map>> dicts = new HashMap<>();
|
||||
|
||||
private DictKit() {
|
||||
}
|
||||
|
||||
public synchronized static DictKit use(String platToken) {
|
||||
DictKit dictKit = kits.get(platToken);
|
||||
if (dictKit == null) {
|
||||
dictKit = new DictKit();
|
||||
dictKit.platToken = platToken;
|
||||
dictKit.init();
|
||||
kits.put(platToken, dictKit);
|
||||
}
|
||||
return dictKit;
|
||||
}
|
||||
|
||||
// 初始化字典,不同模式下,数据来源不同
|
||||
private void init() {
|
||||
// arangodb 加载模式
|
||||
loadByArangodb();
|
||||
|
||||
// 文件数据模式
|
||||
|
||||
// excel 加载数据
|
||||
|
||||
// mysql 加载数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过arangodb 加载字典数据
|
||||
*/
|
||||
private void loadByArangodb() {
|
||||
String host = PropKit.getProperty("arango.host");
|
||||
int port = Kv.toAs(PropKit.getProperty("arango.port", "8529"), int.class);
|
||||
String user = PropKit.getProperty("arango.user");
|
||||
String passwd = PropKit.getProperty("arango.passwd");
|
||||
|
||||
ArangoDB arangoDb = new ArangoDB.Builder().host(host, port).user(user).password(passwd).build();
|
||||
ArangoDatabase dbDemo = arangoDb.db("db_demo");
|
||||
|
||||
String platId = MetaKit.getPlatId(platToken);
|
||||
String dictAQL = String.format("for d in Dict filter d.sysPlatId=='%s'return d", platId);
|
||||
List<Map<String, String>> list = (List) dbDemo.query(dictAQL, Map.class).asListRemaining();
|
||||
|
||||
String[] fields = {"label", "value", "pValue"};
|
||||
list.forEach(x -> {
|
||||
String type = x.get("type");
|
||||
List<Map> items = dicts.getOrDefault(type, new ArrayList<>());
|
||||
Map dict = new HashMap();
|
||||
for (String field : fields) {
|
||||
dict.put(field, x.get(field));
|
||||
}
|
||||
items.add(dict);
|
||||
dicts.put(type, items);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel 文件加载字典
|
||||
*/
|
||||
private void loadByExcel() {
|
||||
/*Map<String, List<Map>> dicts = ExcelKit.readExcelAll(new File("tmp/ip_dict_ok.xlsx"), new String[]{"", "label", "value", "pValue"});
|
||||
dicts.forEach((k, v) -> {
|
||||
String code = k.substring(k.lastIndexOf("|") + 1);
|
||||
List<Map> list = v;
|
||||
list.remove(0);
|
||||
DictKit.dicts.put(code, list);
|
||||
});
|
||||
|
||||
Predicate<Map> isProvice = (s) -> String.valueOf(s.get("value")).trim().endsWith("0000");
|
||||
Predicate<Map> isCity = (s) -> !isProvice.test(s); // && String.valueOf(s.get("value")).trim().endsWith("00");
|
||||
BiPredicate<Map, Map> belongProvice = (p, x) -> String.valueOf(x.get("value")).trim().startsWith(String.valueOf(p.get("value")).trim().substring(0, 2));
|
||||
|
||||
|
||||
// 城市数据
|
||||
List<Map> cityAll = ExcelKit.readExcel(new File("tmp/city.xls"), new String[]{"value", "label1", "label2"});
|
||||
List<Map> provice = cityAll.stream().filter(x -> isProvice.test(x)).map(x -> {
|
||||
x.put("label", String.valueOf(x.get("label1")).trim());
|
||||
x.put("value", String.valueOf(x.get("value")).trim());
|
||||
x.put("pValue", "0");
|
||||
return x;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
List<Map> city = cityAll.stream().filter(x -> isCity.test(x)).collect(Collectors.toList());
|
||||
provice.forEach(p -> {
|
||||
city.stream().filter(x -> belongProvice.test(p, x)).forEach(x -> {
|
||||
x.put("label", String.valueOf(x.get("label2")).trim());
|
||||
x.put("value", String.valueOf(x.get("value")).trim());
|
||||
x.put("pValue", String.valueOf(p.get("value")).trim());
|
||||
});
|
||||
});
|
||||
|
||||
List<Map> cityDict = new ArrayList<>();
|
||||
cityDict.addAll(provice);
|
||||
cityDict.addAll(city);
|
||||
cityDict.forEach(x -> {
|
||||
x.remove("label1");
|
||||
x.remove("label2");
|
||||
});
|
||||
DictKit.dicts.put("city", cityDict);*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定类别的字典
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
public List<Map> getDicts(String code) {
|
||||
Objects.requireNonNull(code, "code 不能为空");
|
||||
return dicts.getOrDefault(code, new ArrayList<>());
|
||||
}
|
||||
|
||||
public Map<String, List<Map>> getDicts() {
|
||||
return dicts;
|
||||
}
|
||||
|
||||
public String getDictLabel(String code, String value) {
|
||||
Objects.requireNonNull(code, "code 不能为空");
|
||||
Objects.requireNonNull(value, "value 不能为空");
|
||||
List<Map> dicts = getDicts(code);
|
||||
Optional<Map> any = dicts.stream().filter(x -> value.equals(x.get("value"))).findAny();
|
||||
return any.isPresent() ? any.get().get("label") + "" : "";
|
||||
}
|
||||
|
||||
public String getDictValue(String code, String label) {
|
||||
Objects.requireNonNull(code, "code 不能为空");
|
||||
Objects.requireNonNull(label, "label 不能为空");
|
||||
|
||||
List<Map> dicts = getDicts(code);
|
||||
Optional<Map> any = dicts.stream().filter(x -> label.equals(x.get("label"))).findAny();
|
||||
return any.isPresent() ? any.get().get("value") + "" : "";
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void dictTest() {
|
||||
System.out.println(getDictLabel("useSubclass", "3")); // 云
|
||||
System.out.println(getDictValue("isp", "广电")); // 5
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,13 +13,14 @@ import net.tccn.dbq.jdbc.api.DbAccount;
|
||||
@Data
|
||||
public class Task {
|
||||
|
||||
private String name; // 任务名,同一系统唯一
|
||||
private String name; // 任务标识,同一系统唯一
|
||||
private String dbPlatId; // 数据源id
|
||||
private String catalog; // 数据库 database
|
||||
|
||||
private String content;
|
||||
private String comment;
|
||||
private Kv para;
|
||||
private String content; // 任务内容
|
||||
private String title; // 任务标题
|
||||
private Kv para; // 任务参数
|
||||
private String remark; // 任务备注
|
||||
|
||||
private DbAccount dbAccount;
|
||||
|
||||
|
||||
@@ -14,12 +14,13 @@ public class TaskEntity extends Doc<TaskEntity> {
|
||||
public static TaskEntity dao = dao(TaskEntity.class);
|
||||
|
||||
private String name; // 任务标识码
|
||||
private String comment; // 任务名称
|
||||
private String title; // 任务名称
|
||||
//private String cate; // 任务类型
|
||||
private String dbPlatId; // 数据平台id
|
||||
private String catalog; //
|
||||
|
||||
private String content; // 任务内容
|
||||
private String remark; // 任务备注
|
||||
private String para; // 任务参数
|
||||
private String sysPlatId; // 平台id
|
||||
|
||||
|
||||
@@ -17,7 +17,11 @@ public class TaskKit {
|
||||
private static List<TaskEntity> taskEntities;
|
||||
|
||||
static {
|
||||
taskEntities = TaskEntity.dao.find();
|
||||
init();
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
taskEntities = MetaKit.getTaskEntities();
|
||||
}
|
||||
|
||||
public static Task buildTask(String name, String platToken, Kv para) {
|
||||
@@ -28,7 +32,7 @@ public class TaskKit {
|
||||
public static Task buildTask(TaskEntity taskEntity, Kv para) {
|
||||
Task task = new Task();
|
||||
task.setName(taskEntity.getName());
|
||||
task.setComment(taskEntity.getComment());
|
||||
task.setTitle(taskEntity.getTitle());
|
||||
task.setContent(taskEntity.getContent());
|
||||
task.setDbPlatId(taskEntity.getDbPlatId());
|
||||
task.setCatalog(taskEntity.getCatalog());
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
package net.tccn.qtask.impl;
|
||||
|
||||
import com.jfinal.plugin.activerecord.PageSqlKit;
|
||||
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
||||
import com.jfinal.template.Engine;
|
||||
import com.jfinal.template.Template;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.base.PageBean;
|
||||
import net.tccn.dbq.jdbc.api.DbKit;
|
||||
import net.tccn.qtask.QTask;
|
||||
import net.tccn.qtask.Task;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class QTaskMysql extends QTaskAbs implements QTask {
|
||||
|
||||
@@ -36,6 +31,8 @@ public class QTaskMysql extends QTaskAbs implements QTask {
|
||||
Template tpl = engine.getTemplateByString(task.getContent());
|
||||
String sql = tpl.renderToString(getTask().getPara()).replaceAll("[\\s]+", " ");
|
||||
|
||||
/*
|
||||
// todo: 从sql分析,支持多种sql处理类别,
|
||||
if (sql.startsWith("select count")) {
|
||||
return dbKit.queryInt(sql);
|
||||
} else if (sql.startsWith("select ")) {
|
||||
@@ -59,7 +56,8 @@ public class QTaskMysql extends QTaskAbs implements QTask {
|
||||
sql.startsWith("delete ") || sql.startsWith("DELETE ") ||
|
||||
sql.startsWith("insert ") || sql.startsWith("INSERT ")){
|
||||
dbKit.exetute(sql);
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
return dbKit.findList(sql, Map.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.tccn.service;
|
||||
|
||||
import com.arangodb.Predicate;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.base.TplKit;
|
||||
import net.tccn.base.X;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.service.Service;
|
||||
@@ -13,9 +13,6 @@ import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Logger;
|
||||
@@ -30,23 +27,8 @@ public class BaseService implements Service {
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
protected File webroot;
|
||||
|
||||
|
||||
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
|
||||
public static Predicate isEmpty = (x) -> {
|
||||
if (x == null)
|
||||
return true;
|
||||
if (x instanceof List)
|
||||
return ((List) x).isEmpty();
|
||||
if (x instanceof String)
|
||||
return ((String) x).isEmpty();
|
||||
if (x instanceof Map)
|
||||
return ((Map) x).isEmpty();
|
||||
if (x instanceof Collection)
|
||||
return ((Collection) x).isEmpty();
|
||||
return false;
|
||||
};
|
||||
|
||||
public static boolean isWinos = System.getProperty("os.name").contains("Window");
|
||||
|
||||
@Resource(name = "cacheSource")
|
||||
@@ -110,4 +92,7 @@ public class BaseService implements Service {
|
||||
return MetaKit.getPlatId(token);
|
||||
}
|
||||
|
||||
public boolean isEmpty(Object obj) {
|
||||
return X.isEmpty(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,26 @@ package net.tccn.service;
|
||||
import net.tccn.base.*;
|
||||
import net.tccn.dbq.DbExecutors;
|
||||
import net.tccn.dbq.fbean.FBean;
|
||||
import net.tccn.dict.DictKit;
|
||||
import net.tccn.meta.MetaService;
|
||||
import org.redkale.net.http.HttpScope;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.util.Comment;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* 数据服务 对外提供服务
|
||||
*
|
||||
* @author: liangxianyou at 2019/1/6 20:46.
|
||||
*/
|
||||
@RestService(name = "data", automapping = true, comment = "数据服务")
|
||||
public class DataService extends BaseService {
|
||||
|
||||
@Resource
|
||||
private MetadataService metadataService;
|
||||
|
||||
|
||||
@RestMapping(name = "list", auth = false, comment = "数据分页列表")
|
||||
public JBean findList(FBean fBean, @RestParam(name = "platToken") String token) {
|
||||
JBean jBean = new JBean();
|
||||
@@ -59,12 +58,43 @@ public class DataService extends BaseService {
|
||||
PageBean page = DbExecutors.findPage(fBean);
|
||||
Kv heads = MetaKit.cfgExport(fBean.getName(), token);
|
||||
|
||||
if (isEmpty.test(fileName)) {
|
||||
if (X.isEmpty(fileName)) {
|
||||
fileName = String.format("export_excel_%s", System.currentTimeMillis());
|
||||
}
|
||||
|
||||
List<Map> data = page.getRows();
|
||||
|
||||
//dataDeal
|
||||
MetaService metaService = MetaKit.getMetaService(fBean.getName(), token);
|
||||
List<Map<String, String>> exports = metaService.getExports();
|
||||
DictKit dictKit = DictKit.use(token);
|
||||
//字典映射 、日期转换 、时间转换
|
||||
data.forEach(r -> {
|
||||
exports.forEach(x -> {
|
||||
String oldV = r.getOrDefault(x.get("col"), "") + "";
|
||||
String inType = x.getOrDefault("inType", "");
|
||||
|
||||
String label = "";
|
||||
switch (inType) {
|
||||
case "DICT":
|
||||
label = dictKit.getDictLabel(x.get("inExt"), oldV);
|
||||
break;
|
||||
case "DAY":
|
||||
label = ""; //TODO: 日期转换
|
||||
break;
|
||||
case "TIME":
|
||||
label = ""; //TODO: 时间转换
|
||||
break;
|
||||
}
|
||||
|
||||
if (!"".equals(label)) {
|
||||
r.put(x.get("col"), label);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Kv attrs = Kv.of();
|
||||
attrs.put("data", page.getRows());
|
||||
attrs.put("data", data);
|
||||
attrs.put("heads", heads);
|
||||
attrs.put("fileName", fileName);
|
||||
|
||||
|
||||
28
src/main/java/net/tccn/service/DictService.java
Normal file
28
src/main/java/net/tccn/service/DictService.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.tccn.service;
|
||||
|
||||
import net.tccn.base.JBean;
|
||||
import net.tccn.dict.DictKit;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典服务
|
||||
* @author: liangxianyou
|
||||
*/
|
||||
@RestService(name = "dict", automapping = true, comment = "字典服务")
|
||||
public class DictService extends BaseService {
|
||||
|
||||
@RestMapping(name = "list")
|
||||
public JBean list(@RestParam(name = "platToken") String token) {
|
||||
JBean jBean = new JBean();
|
||||
DictKit dictKit = DictKit.use(token);
|
||||
|
||||
|
||||
Map dicts = dictKit.getDicts();
|
||||
jBean.setBody(dicts);
|
||||
return jBean;
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,11 @@ public class MetadataService extends BaseService { //arango
|
||||
public JBean tableList(@RestParam(name = "platToken") String token, String catalog, String dbPlatId, String name) {
|
||||
JBean jBean = new JBean();
|
||||
|
||||
List<Kv> list = MetaKit.getMetaTables().stream().filter(x ->
|
||||
(isEmpty.test(catalog) || catalog.equals(x.getCatalog())) &&
|
||||
(isEmpty.test(dbPlatId) || dbPlatId.equals(x.getDbPlatId())) &&
|
||||
(isEmpty.test(name) || x.getName().contains(name)) &&
|
||||
(isEmpty.test(token) || x.getSysPlatId().equals(platId(token)))
|
||||
List<Kv> list = MetaKit.getMetaTables().stream().filter(x
|
||||
-> (isEmpty(catalog) || catalog.equals(x.getCatalog())) &&
|
||||
(isEmpty(dbPlatId) || dbPlatId.equals(x.getDbPlatId())) &&
|
||||
(isEmpty(name) || x.getName().contains(name)) &&
|
||||
(isEmpty(token) || x.getSysPlatId().equals(platId(token)))
|
||||
).map(x -> Kv.of("name", x.getName())
|
||||
.set("comment", x.getComment())
|
||||
.set("catalog", x.getCatalog())
|
||||
@@ -61,10 +61,10 @@ public class MetadataService extends BaseService { //arango
|
||||
JBean jBean = new JBean();
|
||||
|
||||
MetaTable metaTable = null;
|
||||
if (!isEmpty.test(name)) {
|
||||
if (!isEmpty(name)) {
|
||||
metaTable = MetaKit.getMetaTable(name, token);
|
||||
}
|
||||
if (metaTable == null && !isEmpty.test(alias)) {
|
||||
if (metaTable == null && !isEmpty(alias)) {
|
||||
metaTable = MetaKit.getMetaTableByAlias(alias);
|
||||
}
|
||||
|
||||
@@ -76,13 +76,13 @@ public class MetadataService extends BaseService { //arango
|
||||
JBean jBean = new JBean();
|
||||
do {
|
||||
// 标识码非空校验
|
||||
if (isEmpty.test(service.getTable())) {
|
||||
if (isEmpty(service.getTable())) {
|
||||
jBean.set(-1, "请选择业务主表");
|
||||
break;
|
||||
}
|
||||
|
||||
// 标识码非空校验
|
||||
if (isEmpty.test(service.getName())) {
|
||||
if (isEmpty(service.getName())) {
|
||||
jBean.set(-1, "业务标识码无效");
|
||||
break;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public class MetadataService extends BaseService { //arango
|
||||
|
||||
@RestMapping(name = "importsort", comment = "导入字段保存")
|
||||
public JBean importSort(String serviceKey, List<String> items, @RestParam(name = "platToken") String token) {
|
||||
if (isEmpty.test(items)) return null;
|
||||
if (isEmpty(items)) return null;
|
||||
|
||||
MetaTable metaTable = MetaKit.getMetaTable(serviceKey, token);
|
||||
//fixme: metaTable.setImports(items);
|
||||
@@ -229,7 +229,7 @@ public class MetadataService extends BaseService { //arango
|
||||
JBean jBean = new JBean();
|
||||
|
||||
List<Kv> list = MetaKit.getMetaTables().stream()
|
||||
.filter(x -> (isEmpty.test(token) || x.getSysPlatId().equals(platId(token))))
|
||||
.filter(x -> (isEmpty(token) || x.getSysPlatId().equals(platId(token))))
|
||||
.map(x -> {
|
||||
Kv kv = Kv.of("name", x.getName())
|
||||
.set("comment", x.getComment())
|
||||
@@ -275,7 +275,7 @@ public class MetadataService extends BaseService { //arango
|
||||
|
||||
List<MetaLink> links = MetaKit.getMetaLinks();
|
||||
|
||||
if (!isEmpty.test(alias)) {
|
||||
if (!isEmpty(alias)) {
|
||||
links = links.stream()
|
||||
.filter(x -> x.getTables()[0].equals(alias) || x.getTables()[1].equals(alias))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -34,15 +33,11 @@ public class _FileService extends BaseService {
|
||||
@RestMapping(name = "sheets", comment = "得到所有的sheetName")
|
||||
public List<String> sheets(String filePath) {
|
||||
List<String> sheets = new ArrayList<>();
|
||||
try {
|
||||
|
||||
File file = new File(webroot, filePath);
|
||||
if (file.exists()) {
|
||||
sheets = ExcelKit.getSheetNames(file);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return sheets.stream().filter(x -> {
|
||||
return !x.contains("版本记录") && !x.contains("表说明") && !x.contains("表名称");
|
||||
@@ -59,7 +54,6 @@ public class _FileService extends BaseService {
|
||||
//SysPlat sysPlat = getSysPlat(token);
|
||||
File file = new File(webroot, filePath);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
Map<String, List<Map>> map = ExcelKit.readExcelAll(file, FIELDS);
|
||||
|
||||
Kv<String, MetaTable> data = Kv.of();
|
||||
@@ -70,18 +64,6 @@ public class _FileService extends BaseService {
|
||||
});
|
||||
|
||||
String[] tableArr = data.keySet().toArray(new String[data.size()]);
|
||||
|
||||
/*StringBuffer buf = new StringBuffer();
|
||||
buf.append("for d in MetaTable\n" +
|
||||
" filter d.name in [");
|
||||
data.values().forEach(x -> {
|
||||
buf.append("'").append(x.getName()).append("',");
|
||||
});
|
||||
// 此处有bug
|
||||
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);*/
|
||||
List<String> hv = MetaKit.tableExist(tableArr, token);
|
||||
|
||||
Kv res = Kv.of();
|
||||
@@ -95,9 +77,6 @@ public class _FileService extends BaseService {
|
||||
});
|
||||
|
||||
jBean.setBody(res);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return jBean;
|
||||
@@ -107,15 +86,10 @@ public class _FileService extends BaseService {
|
||||
public JBean sheetData(String filePath, String sheetName, @RestParam(name = "platToken") String token) {
|
||||
JBean jBean = new JBean();
|
||||
File file = new File(webroot, filePath);
|
||||
try {
|
||||
List<Map> list = ExcelKit.readExcel(file, FIELDS, sheetName);
|
||||
MetaTable metaTable = toMetaTable(list);
|
||||
|
||||
jBean.setBody(metaTable);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
jBean.set(-1, String.format("读取sheet[%s]失败", sheetName));
|
||||
}
|
||||
|
||||
return jBean;
|
||||
}
|
||||
@@ -128,7 +102,6 @@ public class _FileService extends BaseService {
|
||||
|
||||
File file = new File(webroot, filePath);
|
||||
String[] fields = {"field", "cate", "must", "remark1", "remark2", "tag", "selects", "column", "filter", "ck", "edit"};
|
||||
try {
|
||||
Map<String, List<Map>> map = ExcelKit.readExcelAll(file, fields);
|
||||
Set<String> ks = map.keySet();
|
||||
|
||||
@@ -148,9 +121,6 @@ public class _FileService extends BaseService {
|
||||
}).toArray(MetaTable[]::new);
|
||||
|
||||
MetaKit.save(metaTables);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return jBean;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class _QtaskService extends BaseService{
|
||||
JBean jBean = new JBean();
|
||||
|
||||
do {
|
||||
if (isEmpty.test(task.getName())) {
|
||||
if (isEmpty(task.getName())) {
|
||||
jBean.set(-1, "任务标识码不能为空");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import net.tccn.dbq.fbean.FBean;
|
||||
import net.tccn.dbq.jdbc.api.DbAccount;
|
||||
import net.tccn.dbq.jdbc.api.DbKit;
|
||||
import net.tccn.dbq.parser.ParseMysql;
|
||||
import net.tccn.dict.DictKit;
|
||||
import net.tccn.meta.MetaService;
|
||||
import net.tccn.meta.MetaTable;
|
||||
import net.tccn.qtask.TaskEntity;
|
||||
@@ -19,10 +20,8 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@@ -52,6 +51,7 @@ public class RunTest<T> {
|
||||
//System.out.println(query.getClass());
|
||||
}*/
|
||||
ParseMysql parser = new ParseMysql();
|
||||
|
||||
//@Test
|
||||
public void parseFBeanTest() {
|
||||
String str = "{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}}";
|
||||
@@ -229,6 +229,7 @@ public class RunTest<T> {
|
||||
String tpl = tplKit.getTpl("service.method", kv, false);
|
||||
System.out.println(tpl);
|
||||
}
|
||||
|
||||
private String toUpperCaseFirst(String str) {
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
}
|
||||
@@ -249,14 +250,10 @@ public class RunTest<T> {
|
||||
|
||||
MetaKit metaKit = new MetaKit();
|
||||
|
||||
try {
|
||||
File file = new File("tmp/metaKit.json");
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
FileKit.strToFile(convert.convertTo(metaKit), file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
40
src/test/java/TimerKit.java
Normal file
40
src/test/java/TimerKit.java
Normal file
@@ -0,0 +1,40 @@
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou
|
||||
*/
|
||||
public class TimerKit {
|
||||
private static Timer timer = new Timer();
|
||||
|
||||
/**
|
||||
* 延迟执行
|
||||
*
|
||||
* @param runnable 执行的任务
|
||||
* @param delay 延迟时间
|
||||
*/
|
||||
public static void schedule(Runnable runnable, long delay) {
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟周期执行
|
||||
*
|
||||
* @param runnable 执行的任务
|
||||
* @param delay 延迟时间
|
||||
* @param period 执行周期
|
||||
*/
|
||||
public static void schedule(Runnable runnable, long delay, long period) {
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
}, delay, period);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user