.
This commit is contained in:
138
src/com/eversec/common/FileKit.java
Normal file
138
src/com/eversec/common/FileKit.java
Normal file
@@ -0,0 +1,138 @@
|
||||
package com.eversec.common;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/5/31 10:23.
|
||||
*/
|
||||
public final class FileKit {
|
||||
|
||||
private FileKit() { }
|
||||
|
||||
public static void strToFile(String entityBody, File file) throws IOException {
|
||||
strToFile(entityBody, file, true);
|
||||
}
|
||||
|
||||
public static void strToFile(String entityBody, File file, boolean existDel) throws IOException {
|
||||
if (file.exists()) {
|
||||
if (existDel) {
|
||||
file.delete();
|
||||
}else {
|
||||
throw new RuntimeException(file.getPath() + "已经存在");
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.getParentFile().exists()){
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.write(entityBody.getBytes("UTF-8"));
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件/文件目录
|
||||
* @param source
|
||||
* @param target
|
||||
* @param linkPath
|
||||
*/
|
||||
public 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);
|
||||
});
|
||||
}else if (source.isFile()){
|
||||
try {
|
||||
String _linkPath = "";
|
||||
int index = linkPath.indexOf(File.separator, 1);
|
||||
if (index > 0){
|
||||
_linkPath = linkPath.substring(index);
|
||||
}
|
||||
File targetFile = new File(target.toPath() + _linkPath + File.separator + source.getName());
|
||||
if (!targetFile.getParentFile().exists()){
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
Files.copy(source.toPath(), targetFile.toPath(), REPLACE_EXISTING);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 clazz的路径,如果是jar里面的文件得到jar存放的目录,如:lib
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
}
|
||||
return filePath;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取流内的所有内容
|
||||
* @param inputStream
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String readAll(InputStream inputStream) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String str;
|
||||
while ((str = reader.readLine()) != null){
|
||||
buf.append(str+ "\n");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板到文件
|
||||
* @param sourceStr
|
||||
* @param target
|
||||
* @param 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 {
|
||||
String str = Engine.use().getTemplate(tplFile.getPath()).renderToString(para);
|
||||
strToFile(str, file);
|
||||
}
|
||||
}
|
69
src/com/eversec/common/JBean.java
Normal file
69
src/com/eversec/common/JBean.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.eversec.common;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/7/30 16:51.
|
||||
*/
|
||||
public class JBean {
|
||||
private int code;
|
||||
private String message;
|
||||
private Object body;
|
||||
private long timestamp;
|
||||
|
||||
public static JBean by(int code, String message){
|
||||
JBean jBean = new JBean();
|
||||
jBean.code = code;
|
||||
jBean.message = message;
|
||||
jBean.timestamp = System.currentTimeMillis();
|
||||
return jBean;
|
||||
}
|
||||
public static JBean by(int code, String message, Object result){
|
||||
JBean jBean = new JBean();
|
||||
jBean.code = code;
|
||||
jBean.message = message;
|
||||
jBean.body = result;
|
||||
jBean.timestamp = System.currentTimeMillis();
|
||||
return jBean;
|
||||
}
|
||||
public JBean set(int code, String message){
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JBean setCode(int code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JBean setMessage(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JBean setBody(Object body) {
|
||||
this.body = body;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public Object getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return JSONObject.toJSONString(this);
|
||||
}
|
||||
}
|
123
src/com/eversec/common/JdbcKit.java
Normal file
123
src/com/eversec/common/JdbcKit.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package com.eversec.common;
|
||||
|
||||
import com.eversec.kit.dev.Table;
|
||||
import com.jfinal.kit.Kv;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* JdbcKit.
|
||||
* 未做连接关闭,只可做为本地main运行测试使用,此工具类不可用于线上使用
|
||||
* @author: liangxianyou at 2018/10/8 10:39.
|
||||
*/
|
||||
public class JdbcKit {
|
||||
private static String url;
|
||||
private static String user;
|
||||
private static String pwd;
|
||||
|
||||
private static String showTableSql = "SELECT TABLE_NAME,TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '%s'"; //查询所有[表名、表备注],查询时%s需换为对应的数据库
|
||||
private static String showTableInfo = "show full columns from %s"; //查询%s表的 完整信息,查询时%s需换为对应的表名
|
||||
|
||||
private static Connection connection;
|
||||
|
||||
static {
|
||||
try {
|
||||
url = PropKit.getProperty("jdbc.url", "");
|
||||
user = PropKit.getProperty("jdbc.user", "");
|
||||
pwd = PropKit.getProperty("jdbc.pwd", "");
|
||||
connection = DriverManager.getConnection(url, user, pwd);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#show full columns from sys_userrecord;
|
||||
#show tables;
|
||||
#SELECT TABLE_NAME,TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE="BASE TABLE" #TABLE_SCHEMA like 'redbbs_dev'
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public List _tables(String database) throws SQLException {
|
||||
//String showTables = "SELECT TABLE_NAME,TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" + database + "'";
|
||||
|
||||
ResultSet rs = executeQuery(String.format(showTableSql, database));
|
||||
|
||||
List tables = new ArrayList();
|
||||
|
||||
while (rs.next()) {
|
||||
String tableName = rs.getString("table_name");
|
||||
String tableComment = rs.getString("table_comment");
|
||||
|
||||
Kv table = Kv.by("tableName", tableName).set("comment", tableComment);
|
||||
|
||||
ResultSet columns = executeQuery(String.format(showTableInfo, database+ "." +tableName));
|
||||
List fields = new ArrayList();
|
||||
while (columns.next()) {
|
||||
fields.add(Kv.by("name", columns.getString("field"))
|
||||
.set("type", columns.getString("type"))
|
||||
.set("comment", columns.getString("comment"))
|
||||
);
|
||||
}
|
||||
|
||||
table.set("fields", fields);
|
||||
tables.add(table);
|
||||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据库中所有的表
|
||||
* @param database
|
||||
* @return
|
||||
*/
|
||||
public static List<Table> tables(String database, String ... tables) throws SQLException {
|
||||
|
||||
List<Table> list = new ArrayList<>();
|
||||
ResultSet rs = null;
|
||||
if (tables != null && tables.length > 0) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (String s : tables) {
|
||||
buf.append("'").append(s).append("',");
|
||||
}
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
rs = executeQuery(String.format("SELECT TABLE_NAME,TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '%s' and table_name in (%s)", database, buf.toString()));
|
||||
} else {
|
||||
rs = executeQuery(String.format(showTableSql, database));
|
||||
}
|
||||
|
||||
while (rs.next()) {
|
||||
Table table = new Table(rs.getString("table_name"), rs.getString("table_comment"));
|
||||
|
||||
List<Table.Column> columns = new ArrayList<>();
|
||||
ResultSet rsColumns = executeQuery(String.format(showTableInfo, database+ "." +table.getName()));
|
||||
while (rsColumns.next()) {
|
||||
Table.Column column = new Table.Column(rsColumns.getString("field"), rsColumns.getString("type"),
|
||||
!rsColumns.getBoolean("null"), rsColumns.getString("comment"));
|
||||
columns.add(column);
|
||||
|
||||
}
|
||||
|
||||
table.setColumns(columns);
|
||||
list.add(table);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//通过sql 查询数据
|
||||
private static ResultSet executeQuery(String sql) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement(sql);
|
||||
return ps.executeQuery();
|
||||
|
||||
/*try(
|
||||
PreparedStatement ps = connection.prepareStatement(sql);
|
||||
ResultSet resultSet = ps.executeQuery()
|
||||
) { return resultSet; }*/
|
||||
}
|
||||
}
|
46
src/com/eversec/common/Kv.java
Normal file
46
src/com/eversec/common/Kv.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.eversec.common;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/3/12 14:17.
|
||||
*/
|
||||
public class Kv<K,V> extends LinkedHashMap {
|
||||
public static Kv of(){
|
||||
return new Kv();
|
||||
}
|
||||
|
||||
public static Kv of(Object k, Object v){
|
||||
return new Kv().set(k,v);
|
||||
}
|
||||
|
||||
public Kv<K, V> set(K k, V v){
|
||||
put(k, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Kv toKv(Object m) {
|
||||
return toKv(m, Kv.of(), m.getClass());
|
||||
}
|
||||
|
||||
private static Kv toKv(Object m, Kv kv, Class clazz) {
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
if (!kv.containsKey(field.getName())) {
|
||||
kv.set(field.getName(), field.get(m));
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Class superclass = clazz.getSuperclass();
|
||||
if (superclass != null) {
|
||||
kv = toKv(m, kv, superclass);
|
||||
}
|
||||
return kv;
|
||||
}
|
||||
}
|
35
src/com/eversec/common/PageBean.java
Normal file
35
src/com/eversec/common/PageBean.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.eversec.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/5/7 11:20.
|
||||
*/
|
||||
public class PageBean<M> {
|
||||
private List<M> rows;
|
||||
private long total;
|
||||
|
||||
public PageBean() {
|
||||
}
|
||||
|
||||
public PageBean(List<M> rows, long total) {
|
||||
this.rows = rows;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<M> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<M> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(long total) {
|
||||
this.total = total;
|
||||
}
|
||||
}
|
28
src/com/eversec/common/PropKit.java
Normal file
28
src/com/eversec/common/PropKit.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.eversec.common;
|
||||
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* PropertyKit
|
||||
* @author: liangxianyou at 2018/10/8 17:51.
|
||||
*/
|
||||
public class PropKit {
|
||||
public static String clazzRoot = FileKit.rootPath(ICreator.class);
|
||||
public static Properties prop = new Properties();
|
||||
static {
|
||||
try {
|
||||
prop.load(new FileInputStream(new File(clazzRoot + "conf/conf.txt")));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getProperty(String k, String defaultValue){
|
||||
return prop.getProperty(k, defaultValue).replace("${clazzRoot}", clazzRoot);
|
||||
}
|
||||
}
|
4
src/com/eversec/common/package-info.java
Normal file
4
src/com/eversec/common/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.eversec.common;
|
||||
/**
|
||||
通用工具包
|
||||
*/
|
27
src/com/eversec/dbq/E.java
Normal file
27
src/com/eversec/dbq/E.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.eversec.dbq;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
public enum E {
|
||||
//cate, table, 描述, 其他信息
|
||||
A(1, "tableA", "xx业务", "othInfo"),
|
||||
B(2, "tableA", "xx业务", "othInfo");
|
||||
|
||||
|
||||
public int cate;
|
||||
public String tableName;
|
||||
public String note;
|
||||
public String othInfo;
|
||||
|
||||
public String queryId;
|
||||
public Kv para;
|
||||
public String queryType;//mysql, bigData, method
|
||||
public String restType;//List, Map
|
||||
|
||||
E(int cate, String tableName, String note, String othInfo) {
|
||||
this.cate = cate;
|
||||
this.tableName = tableName;
|
||||
this.note = note;
|
||||
this.othInfo = othInfo;
|
||||
}
|
||||
}
|
25
src/com/eversec/dbq/QRuner.java
Normal file
25
src/com/eversec/dbq/QRuner.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.eversec.dbq;
|
||||
|
||||
import com.eversec.dbq.qtask.QTaskEs;
|
||||
import com.eversec.dbq.qtask.QTaskMethod;
|
||||
import com.eversec.dbq.qtask.QTaskMysql;
|
||||
|
||||
public class QRuner {
|
||||
|
||||
private E e;
|
||||
|
||||
public QRuner(E e) {
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
public Object query() {
|
||||
if ("mysql".equalsIgnoreCase(e.queryType)){
|
||||
return new QTaskMysql(e).execute();
|
||||
}else if ("bigData".equalsIgnoreCase(e.queryType)){
|
||||
return new QTaskEs(e).execute();
|
||||
}else if ("method".equalsIgnoreCase(e.queryType)){
|
||||
return new QTaskMethod(e).execute();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
25
src/com/eversec/dbq/Runner.java
Normal file
25
src/com/eversec/dbq/Runner.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.eversec.dbq;
|
||||
|
||||
import com.eversec.dbq.chattask.ChatTask;
|
||||
import com.eversec.dbq.stattask.StatTask;
|
||||
import com.eversec.dbq.stattask.StatTaskToMySql;
|
||||
|
||||
public class Runner {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
public static void queryChatData(){
|
||||
//chat DATA execute
|
||||
ChatTask chatTask = new ChatTask(E.A);
|
||||
|
||||
Object query = chatTask.query();//list / map
|
||||
|
||||
}
|
||||
|
||||
public static void statData(){
|
||||
StatTask statTaskToMySql = new StatTaskToMySql(E.A);
|
||||
statTaskToMySql.dataToDb();
|
||||
}
|
||||
}
|
17
src/com/eversec/dbq/chattask/ChatTask.java
Normal file
17
src/com/eversec/dbq/chattask/ChatTask.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.eversec.dbq.chattask;
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
import com.eversec.dbq.QRuner;
|
||||
|
||||
public class ChatTask {
|
||||
|
||||
private E e;
|
||||
|
||||
public ChatTask(E e) {
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
public Object query() {
|
||||
return new QRuner(e).query();
|
||||
}
|
||||
}
|
4
src/com/eversec/dbq/package-info.java
Normal file
4
src/com/eversec/dbq/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.eversec.dbq;
|
||||
/**
|
||||
通用查询组件
|
||||
*/
|
9
src/com/eversec/dbq/qtask/QTask.java
Normal file
9
src/com/eversec/dbq/qtask/QTask.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.eversec.dbq.qtask;
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
|
||||
public interface QTask {
|
||||
E getE();
|
||||
|
||||
Object execute();
|
||||
}
|
18
src/com/eversec/dbq/qtask/QTaskAbs.java
Normal file
18
src/com/eversec/dbq/qtask/QTaskAbs.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.eversec.dbq.qtask;
|
||||
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
|
||||
public abstract class QTaskAbs implements QTask {
|
||||
|
||||
private E e;
|
||||
|
||||
public QTaskAbs(E e) {
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getE() {
|
||||
return e;
|
||||
}
|
||||
}
|
16
src/com/eversec/dbq/qtask/QTaskEs.java
Normal file
16
src/com/eversec/dbq/qtask/QTaskEs.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.eversec.dbq.qtask;
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
|
||||
public class QTaskEs extends QTaskAbs {
|
||||
|
||||
public QTaskEs(E e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute() {
|
||||
//find result by es api todo:
|
||||
return null;
|
||||
}
|
||||
}
|
29
src/com/eversec/dbq/qtask/QTaskMethod.java
Normal file
29
src/com/eversec/dbq/qtask/QTaskMethod.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.eversec.dbq.qtask;
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
|
||||
public class QTaskMethod extends QTaskAbs implements QTask {
|
||||
|
||||
public QTaskMethod(E e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public String getClazz(){
|
||||
String clazz = getE().para.get("clazz")+"";
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public String getMethod(){
|
||||
String method = getE().para.get("method")+"";
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute() {
|
||||
|
||||
// execute JAVA method by CLASS AND METHOD
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
27
src/com/eversec/dbq/qtask/QTaskMysql.java
Normal file
27
src/com/eversec/dbq/qtask/QTaskMysql.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.eversec.dbq.qtask;
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
|
||||
public class QTaskMysql extends QTaskAbs implements QTask {
|
||||
|
||||
private Object mapper;
|
||||
|
||||
public QTaskMysql(E e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public String getSQL(){
|
||||
String sql = getE().para.get("sql")+"";
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute() {
|
||||
if ("Map".equalsIgnoreCase(getE().queryType)){
|
||||
// return mapper.findFirst(getSQL()); todo:
|
||||
} else if ("list".equalsIgnoreCase(getE().queryType)){
|
||||
// return mapper.findList(getSQL()); todo:
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
16
src/com/eversec/dbq/stattask/StatTask.java
Normal file
16
src/com/eversec/dbq/stattask/StatTask.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.eversec.dbq.stattask;
|
||||
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
|
||||
/**
|
||||
* 统计入库
|
||||
*/
|
||||
public interface StatTask {
|
||||
|
||||
E getE();
|
||||
|
||||
void dataToDb();
|
||||
|
||||
Object query();
|
||||
}
|
25
src/com/eversec/dbq/stattask/StatTaskAbs.java
Normal file
25
src/com/eversec/dbq/stattask/StatTaskAbs.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.eversec.dbq.stattask;
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
import com.eversec.dbq.QRuner;
|
||||
|
||||
public abstract class StatTaskAbs implements StatTask{
|
||||
|
||||
//private QTask qTask;
|
||||
private E e;
|
||||
|
||||
public StatTaskAbs(E e) {
|
||||
//this.qTask = qTask;
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getE() {
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object query() {
|
||||
return new QRuner(e).query();
|
||||
}
|
||||
}
|
27
src/com/eversec/dbq/stattask/StatTaskToMySql.java
Normal file
27
src/com/eversec/dbq/stattask/StatTaskToMySql.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.eversec.dbq.stattask;
|
||||
|
||||
import com.eversec.dbq.E;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StatTaskToMySql extends StatTaskAbs implements StatTask{
|
||||
|
||||
public StatTaskToMySql(E e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dataToDb() {
|
||||
Object query = query();
|
||||
|
||||
String tableName = getE().tableName;
|
||||
//data insert mysql db; 如:insert into
|
||||
if ("list".equalsIgnoreCase(getE().restType)){
|
||||
((List) query).forEach(x->{
|
||||
// todo: same as map
|
||||
});
|
||||
}else if ("map".equalsIgnoreCase(getE().restType)){
|
||||
// todo:
|
||||
}
|
||||
}
|
||||
}
|
BIN
src/com/eversec/dbq/代码架构设计图.png
Normal file
BIN
src/com/eversec/dbq/代码架构设计图.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
74
src/com/eversec/dynamic/DnyController.java
Normal file
74
src/com/eversec/dynamic/DnyController.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package com.eversec.dynamic;
|
||||
|
||||
import com.eversec.common.JBean;
|
||||
import com.eversec.common.PageBean;
|
||||
import com.eversec.dynamic.entity.DnyAttr;
|
||||
import com.eversec.dynamic.entity.DnyCate;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 动态数据管理
|
||||
* Created by liangxianyou at 2018/09/21
|
||||
*/
|
||||
public class DnyController {
|
||||
|
||||
private DnyService dnyService;
|
||||
|
||||
/**
|
||||
* 保存表数据
|
||||
* @param request
|
||||
*/
|
||||
public String save(HttpServletRequest request, DnyCate dnyCate){
|
||||
//deal Attr
|
||||
dnyCate.getAttrs().forEach(x->{
|
||||
dnyCate.set(x.getAttr(), request.getParameter(x.getAttr()));
|
||||
});
|
||||
|
||||
dnyService.save(dnyCate);
|
||||
|
||||
return JBean.by(200,"").toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询某一类别列表数据-(行转列)
|
||||
* @param request
|
||||
* @param dnyCate
|
||||
* @param pn
|
||||
* @param ps
|
||||
* @return
|
||||
*/
|
||||
public String findList(HttpServletRequest request, DnyCate dnyCate, int pn, int ps){
|
||||
//deal Attr
|
||||
dnyCate.getAttrs().forEach(x->{
|
||||
dnyCate.set(x.getAttr(), request.getParameter(x.getAttr()));
|
||||
});
|
||||
|
||||
PageBean list = dnyService.findList(dnyCate, pn, ps);
|
||||
|
||||
return JBean.by(200,"", list).toJson();
|
||||
}
|
||||
|
||||
|
||||
//---------- 属性管理 -----------
|
||||
/**
|
||||
* 数据类型主体属性列表
|
||||
* @param dnyCate
|
||||
* @return
|
||||
*/
|
||||
public String findAttr(DnyCate dnyCate){
|
||||
List<DnyAttr> attrs = dnyCate.getAttrs();
|
||||
return JBean.by(200,"", attrs).toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存属性
|
||||
* @param dnyAttr
|
||||
* @return
|
||||
*/
|
||||
public String saveAttr(DnyAttr dnyAttr){
|
||||
dnyService.saveAttr(dnyAttr);
|
||||
return JBean.by(200,"").toJson();
|
||||
}
|
||||
}
|
27
src/com/eversec/dynamic/DnyMapper.java
Normal file
27
src/com/eversec/dynamic/DnyMapper.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.eversec.dynamic;
|
||||
|
||||
import com.eversec.dynamic.entity.DnyAttr;
|
||||
import com.eversec.dynamic.entity.DnyCate;
|
||||
import com.eversec.dynamic.entity.DnyV;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/09/21
|
||||
*/
|
||||
public interface DnyMapper {
|
||||
List<DnyCate> findList(DnyCate cate, int pn, int ps);
|
||||
|
||||
int findCount(DnyCate cate);
|
||||
|
||||
List<DnyV> findAttrV(DnyCate dnyCate);
|
||||
|
||||
//保存数据主体
|
||||
void save(DnyCate dnyCate);//确保保持并且返回cateid(数据主键到数据中) [cateId==0 ? insert : update]
|
||||
|
||||
//保存数据属性
|
||||
void saveAttr(DnyAttr dnyAttr);
|
||||
|
||||
//保存数据
|
||||
void saveAttrV(DnyV attrV);
|
||||
}
|
98
src/com/eversec/dynamic/DnyService.java
Normal file
98
src/com/eversec/dynamic/DnyService.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package com.eversec.dynamic;
|
||||
|
||||
import com.eversec.common.PageBean;
|
||||
import com.eversec.dynamic.entity.DnyAttr;
|
||||
import com.eversec.dynamic.entity.DnyCate;
|
||||
import com.eversec.dynamic.entity.DnyV;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/09/21
|
||||
*/
|
||||
public class DnyService {
|
||||
|
||||
private DnyMapper dnyMapper;
|
||||
|
||||
/**
|
||||
* 保存类型及属性值
|
||||
*/
|
||||
public void save(DnyCate dnyCate){
|
||||
dnyMapper.save(dnyCate);
|
||||
|
||||
List<DnyV> vs = dnyMapper.findAttrV(dnyCate);
|
||||
|
||||
//save attr
|
||||
Map<String, Object> attach = dnyCate.getAttach();
|
||||
for (String k : attach.keySet()) {
|
||||
String v = dnyCate.get(k);
|
||||
|
||||
DnyAttr attr = dnyCate.getAttr(k);
|
||||
|
||||
if (attr == null){
|
||||
continue;
|
||||
}
|
||||
|
||||
DnyV dnyV = vs.stream().filter(x -> x.getAttrId() == attr.getAttrId()).findFirst().get();
|
||||
if (dnyV != null && dnyV.getV().equals(v)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dnyV == null){
|
||||
dnyV = dnyCate.createDnyV(attr, v);
|
||||
}else {
|
||||
dnyV.setV(v);
|
||||
}
|
||||
|
||||
dnyMapper.saveAttrV(dnyV);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表数据
|
||||
* @param dnyCate
|
||||
* @param pn
|
||||
* @param ps
|
||||
* @return
|
||||
*/
|
||||
public PageBean findList(DnyCate dnyCate, int pn, int ps) {
|
||||
List<DnyCate> list = dnyMapper.findList(dnyCate, pn, ps);
|
||||
int count = dnyMapper.findCount(dnyCate);
|
||||
|
||||
list.forEach(x-> setAttr(x));
|
||||
return new PageBean(list, count);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dnyCate
|
||||
* @return
|
||||
*/
|
||||
public DnyCate findFirst(DnyCate dnyCate){
|
||||
List<DnyCate> list = dnyMapper.findList(dnyCate, 0, 1);
|
||||
DnyCate cate = list.size() > 0 ? list.get(0) : null;
|
||||
return setAttr(cate);
|
||||
}
|
||||
|
||||
//通用设置属性 方法
|
||||
private DnyCate setAttr(DnyCate dnyCate){
|
||||
if (dnyCate == null) return null;
|
||||
|
||||
List<DnyV> vs = dnyMapper.findAttrV(dnyCate);
|
||||
|
||||
List<DnyAttr> attrs = dnyCate.getAttrs();
|
||||
vs.forEach(x->{
|
||||
DnyAttr dnyAttr = dnyCate.getAttr(x.getAttrId());
|
||||
if (dnyAttr != null){
|
||||
dnyCate.set(dnyAttr.getAttr(), x.getV());
|
||||
}
|
||||
});
|
||||
return dnyCate;
|
||||
}
|
||||
|
||||
|
||||
public void saveAttr(DnyAttr dnyAttr) {
|
||||
dnyMapper.saveAttr(dnyAttr);
|
||||
}
|
||||
}
|
43
src/com/eversec/dynamic/entity/DnyAttr.java
Normal file
43
src/com/eversec/dynamic/entity/DnyAttr.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.eversec.dynamic.entity;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/09/21
|
||||
*/
|
||||
public class DnyAttr {
|
||||
private int attrId; //属性id
|
||||
private int cate;//数据类型
|
||||
private String attr; //属性字段
|
||||
private String label; //属性名称
|
||||
|
||||
public int getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public int getAttrId() {
|
||||
return attrId;
|
||||
}
|
||||
|
||||
public void setAttrId(int attrId) {
|
||||
this.attrId = attrId;
|
||||
}
|
||||
|
||||
public String getAttr() {
|
||||
return attr;
|
||||
}
|
||||
|
||||
public void setAttr(String attr) {
|
||||
this.attr = attr;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
119
src/com/eversec/dynamic/entity/DnyCate.java
Normal file
119
src/com/eversec/dynamic/entity/DnyCate.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package com.eversec.dynamic.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/09/21
|
||||
*/
|
||||
public class DnyCate {
|
||||
|
||||
private int cateId; //类别主键
|
||||
private int cate; //类别标志
|
||||
private int cateName; //类别名称
|
||||
private Map attach = new HashMap();
|
||||
|
||||
public int getCateId() {
|
||||
return cateId;
|
||||
}
|
||||
|
||||
public void setCateId(int cateId) {
|
||||
this.cateId = cateId;
|
||||
}
|
||||
|
||||
public int getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public int getCateName() {
|
||||
return cateName;
|
||||
}
|
||||
|
||||
public void setCateName(int cateName) {
|
||||
this.cateName = cateName;
|
||||
}
|
||||
|
||||
public Map<String, Object> getAttach() {
|
||||
return attach;
|
||||
}
|
||||
|
||||
public void setAttach(Map attach) {
|
||||
this.attach = attach;
|
||||
}
|
||||
|
||||
|
||||
//---------- setAttach ---------------
|
||||
public DnyCate set(String k, Object v){
|
||||
attach.put(k, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String get(String k){
|
||||
return attach.get(k)+"";
|
||||
}
|
||||
|
||||
|
||||
//--------- 辅助处理 --------------
|
||||
private static Map<Integer, List<DnyAttr>> attrCache = new HashMap();//附加属性缓存
|
||||
//设置缓存数据
|
||||
public void setAttrCache(List<DnyAttr> attrs) {
|
||||
attrs.forEach(x->{
|
||||
List list = attrCache.get(x.getCate());
|
||||
if (list == null) {
|
||||
list = new ArrayList();
|
||||
}
|
||||
|
||||
list.add(x);
|
||||
attrCache.put(x.getCate(), list);
|
||||
});
|
||||
}
|
||||
|
||||
public List<DnyAttr> getAttrs(){
|
||||
List<DnyAttr> dnyAttrs = attrCache.get(cate);
|
||||
if (dnyAttrs == null){
|
||||
dnyAttrs = new ArrayList<>();
|
||||
}
|
||||
return dnyAttrs;
|
||||
}
|
||||
|
||||
//------------- getAttr --------------
|
||||
public DnyAttr getAttr(int attrId){
|
||||
List<DnyAttr> dnyAttrs = attrCache.get(cateId);
|
||||
if (dnyAttrs == null) return null;
|
||||
|
||||
return dnyAttrs.stream().filter(x->x.getAttrId() == attrId).findFirst().get();
|
||||
}
|
||||
|
||||
public DnyAttr getAttr(String attr) {
|
||||
List<DnyAttr> dnyAttrs = attrCache.get(cateId);
|
||||
if (dnyAttrs == null) return null;
|
||||
|
||||
return dnyAttrs.stream().filter(x->x.getAttr().equals(attr)).findFirst().get();
|
||||
}
|
||||
|
||||
//------------- createDnyV --------------
|
||||
public DnyV createDnyV(String attr, String v){
|
||||
return createDnyV(getAttr(attr), v);
|
||||
}
|
||||
|
||||
public DnyV createDnyV(int attrId, String v){
|
||||
return createDnyV(getAttr(attrId), v);
|
||||
}
|
||||
|
||||
public DnyV createDnyV(DnyAttr attr, String v){
|
||||
DnyV dnyV = new DnyV();
|
||||
dnyV.setCateId(cateId);
|
||||
dnyV.setAttrId(attr.getAttrId());
|
||||
dnyV.setV(v);
|
||||
|
||||
return dnyV;
|
||||
}
|
||||
|
||||
|
||||
}
|
34
src/com/eversec/dynamic/entity/DnyV.java
Normal file
34
src/com/eversec/dynamic/entity/DnyV.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.eversec.dynamic.entity;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/09/21
|
||||
*/
|
||||
public class DnyV {
|
||||
private int cateId;//类别主表主键
|
||||
private int attrId;//数据id
|
||||
private String v;//属性值
|
||||
|
||||
public int getCateId() {
|
||||
return cateId;
|
||||
}
|
||||
|
||||
public void setCateId(int cateId) {
|
||||
this.cateId = cateId;
|
||||
}
|
||||
|
||||
public int getAttrId() {
|
||||
return attrId;
|
||||
}
|
||||
|
||||
public void setAttrId(int attrId) {
|
||||
this.attrId = attrId;
|
||||
}
|
||||
|
||||
public String getV() {
|
||||
return v;
|
||||
}
|
||||
|
||||
public void setV(String v) {
|
||||
this.v = v;
|
||||
}
|
||||
}
|
4
src/com/eversec/dynamic/package-info.java
Normal file
4
src/com/eversec/dynamic/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.eversec.dynamic;
|
||||
/**
|
||||
通用动态属性实现
|
||||
*/
|
231
src/com/eversec/kit/creator/ICreator.java
Normal file
231
src/com/eversec/kit/creator/ICreator.java
Normal file
@@ -0,0 +1,231 @@
|
||||
package com.eversec.kit.creator;
|
||||
|
||||
import com.eversec.common.FileKit;
|
||||
import com.eversec.common.Kv;
|
||||
import com.eversec.service.CfgBean;
|
||||
import com.google.gson.Gson;
|
||||
import com.jfinal.template.Engine;
|
||||
import com.lxyer.excel.poi.ExcelKit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/5/3 18:10.
|
||||
*/
|
||||
public abstract class ICreator {
|
||||
private static CfgBean cfgBean;
|
||||
|
||||
private static String xlsPath;
|
||||
public static String tplPath;
|
||||
public static String dirPath;
|
||||
public static String pageDirPath;
|
||||
|
||||
public static String pkg;
|
||||
public static String pageModel;
|
||||
public static String author;
|
||||
private static List<String> sheetNames;
|
||||
/*static {
|
||||
xlsPath = PropKit.getProperty("xlsPath", "res/xls/table.xls");
|
||||
pkg = PropKit.getProperty("pkg", "");
|
||||
tplPath = PropKit.getProperty("tplPath", "");
|
||||
dirPath = PropKit.getProperty("dirPath", "");
|
||||
pageDirPath = PropKit.getProperty("page.dirPath", dirPath);
|
||||
|
||||
pageModel = PropKit.getProperty("page.model", "");
|
||||
author = PropKit.getProperty("author", "lxy-kit");
|
||||
sheetNames = sheets(PropKit.getProperty("sheetNames", ""));
|
||||
|
||||
//路径兼容处理
|
||||
if (!dirPath.endsWith("/")) dirPath += "/";
|
||||
if (!pageDirPath.endsWith("/")) pageDirPath += "/";
|
||||
}*/
|
||||
public static void setCfgBean(CfgBean cfgBean) {
|
||||
ICreator.cfgBean = cfgBean;
|
||||
xlsPath = cfgBean.getXlsPath();
|
||||
pkg = cfgBean.getPkg();
|
||||
tplPath = cfgBean.getTplPath();
|
||||
dirPath = cfgBean.getDirPath();
|
||||
pageDirPath = cfgBean.getPageDirPath(); //PropKit.getProperty("page.dirPath", dirPath);
|
||||
|
||||
pageModel = cfgBean.getPageModel();
|
||||
author = cfgBean.getAuthor();
|
||||
sheetNames = cfgBean.getSheetNames();
|
||||
|
||||
//路径兼容处理
|
||||
if (!dirPath.endsWith("/")) dirPath += "/";
|
||||
if (!pageDirPath.endsWith("/")) pageDirPath += "/";
|
||||
}
|
||||
|
||||
private static List<String> sheets(String sheetNames) {
|
||||
String[] strArr = sheetNames.split(",");
|
||||
List<String> sheets = new ArrayList<>(strArr.length+1);
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
String sheetName = strArr[i].trim();
|
||||
if (!sheetName.isEmpty()){
|
||||
sheets.add(sheetName);
|
||||
}
|
||||
}
|
||||
return sheets;
|
||||
}
|
||||
|
||||
public static String timeStr = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date());
|
||||
public static Engine engine = Engine.use();
|
||||
|
||||
public static Map<String, String> cateRelation = Kv.of("varchar", "String").set("text", "String").set("int", "Integer").set("bigint", "Long").set("long", "Long").set(null, "String").set("datetime", "Date");
|
||||
public static String[] fields = {"field","cate", "must","remark1", "remark2", "tag", "selects", "column","filter", "ck", "edit"};
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
public static List<String> sheetNames() {
|
||||
return sheetNames;
|
||||
}
|
||||
|
||||
//=================== 公用方法 ===================
|
||||
public abstract File getFile(String clazz);
|
||||
public abstract String createStr(String clazz, List<Map> fieldList, Map para);
|
||||
public static List<Map> readExcel(String fileName) throws IOException {
|
||||
List<Map> list = ExcelKit.readExcel(new File(xlsPath + fileName + ".xlsx"), fields);
|
||||
list.forEach(x->{
|
||||
x.put("field", toLowerCaseFirst(x.get("field")+""));
|
||||
});
|
||||
return list;
|
||||
}
|
||||
public static List<Map> readExcelSheet(String sheetName) throws IOException {
|
||||
List<Map> list = ExcelKit.readExcel(new File(xlsPath), fields, sheetName);
|
||||
list.forEach(x->{
|
||||
x.put("field", toLowerCaseFirst(x.get("field")+"").trim());
|
||||
});
|
||||
return list;
|
||||
}
|
||||
private static Map<String, Map> cacheTpl = new HashMap<>();
|
||||
public static Map readExcelHead(File file) throws IOException {
|
||||
Long modifiedTime = Files.getLastModifiedTime(file.toPath()).to(TimeUnit.MILLISECONDS);
|
||||
String ck = file.getName() + ":" + modifiedTime;//缓存键(name:modifiedTime)
|
||||
//缓存tpl模板
|
||||
if (cacheTpl.get(ck) == null) {
|
||||
cacheTpl.put(ck, ExcelKit.readExcelHead(file, fields));
|
||||
}
|
||||
return cacheTpl.get(ck);
|
||||
}
|
||||
public static Kv createTplData(String clazz){
|
||||
Kv kv = Kv.of("bean", clazz);
|
||||
kv.set("beanFL", toLowerCaseFirst(clazz));
|
||||
kv.set("beanL", clazz.toLowerCase());
|
||||
kv.set("author", ICreator.author);
|
||||
kv.set("pkg", ICreator.pkg);
|
||||
kv.set("ctime", timeStr);
|
||||
kv.set("pageModel", pageModel);
|
||||
return kv;
|
||||
}
|
||||
public void createFile(String entityBody, String clazz) throws IOException {
|
||||
FileKit.strToFile(entityBody, getFile(clazz), true);
|
||||
}
|
||||
|
||||
public static String toLowerCaseFirst(String str){
|
||||
if (str == null || str.length() < 1) return "";
|
||||
return str.substring(0, 1).toLowerCase() + str.substring(1);
|
||||
}
|
||||
public static String toUpperCaseFirst(String str){
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
}
|
||||
public static String getFiledType(String cate){
|
||||
for (String k : cateRelation.keySet()) {
|
||||
if (cate.startsWith(String.valueOf(k))) {
|
||||
return cateRelation.get(k);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("cate:"+cate);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isMust(Map map) {
|
||||
return false;//(map.get("must")+"") .equals("是") || (map.get("must")+"").equals("必须");
|
||||
}
|
||||
public static boolean isEmpty(Object obj){
|
||||
return obj == null || (obj+"").isEmpty();
|
||||
}
|
||||
|
||||
public String timeStr(){
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
||||
}
|
||||
|
||||
public static String getTableName(String clazz) {
|
||||
//分解
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < clazz.length(); i++) {
|
||||
if (Character.isUpperCase(clazz.charAt(i)) && i > 0)
|
||||
buf.append("_");
|
||||
buf.append(clazz.charAt(i));
|
||||
}
|
||||
|
||||
return buf.toString().toLowerCase();
|
||||
}
|
||||
|
||||
//ti_abc => TiAbc
|
||||
public static String getClazzName(String tName) {
|
||||
tName = tName.toLowerCase();
|
||||
String[] arr = tName.split("_");
|
||||
String str = "";
|
||||
for (String s : arr) {
|
||||
str += toUpperCaseFirst(s);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
protected static String getClazzName(Map note) {
|
||||
String field = note.get("field")+"";
|
||||
if (field.isEmpty()) return "";
|
||||
|
||||
|
||||
int inx = field.indexOf("(");
|
||||
|
||||
if(inx < 0){
|
||||
return field;
|
||||
}
|
||||
|
||||
field = field.substring(0, inx).toLowerCase();
|
||||
String[] arr = field.split("_");
|
||||
String str = "";
|
||||
for (String s : arr) {
|
||||
str += toUpperCaseFirst(s);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
//{field:"ti_abc(测试表)"} => 测试表
|
||||
protected static String getRemark(Map note) {
|
||||
String field = note.get("field")+"";
|
||||
if (field.isEmpty()) return "";
|
||||
|
||||
int s = field.indexOf("(");
|
||||
int e = field.indexOf(")");
|
||||
if (s > 0){
|
||||
return field.substring(s+1, e > 0 ? e : field.length());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
protected static String getVerify(Map map) {
|
||||
if (map.get("cate") == null){
|
||||
return "";
|
||||
}
|
||||
String str = (String) map.getOrDefault("cate","");
|
||||
return str.replace("|",",");
|
||||
}
|
||||
|
||||
protected static String[] getCondition(Map map) {
|
||||
if (map.get("must") == null || String.valueOf(map.get("must")).isEmpty()){
|
||||
return null;
|
||||
}
|
||||
String str = (String) map.getOrDefault("must","");
|
||||
return str.split("[|]");
|
||||
}
|
||||
|
||||
//createFile use this filePath
|
||||
public String filePath(String pkg){
|
||||
return dirPath + "java/" + pkg.replace('.', '/') + "/";
|
||||
}
|
||||
|
||||
}
|
131
src/com/eversec/kit/creator/Runner.java
Normal file
131
src/com/eversec/kit/creator/Runner.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package com.eversec.kit.creator;
|
||||
|
||||
import com.eversec.common.FileKit;
|
||||
import com.eversec.common.Kv;
|
||||
import com.eversec.kit.creator.impl.*;
|
||||
import com.eversec.kit.creator.impl.page.*;
|
||||
import com.eversec.service.CfgBean;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/30 11:31.
|
||||
*/
|
||||
public class Runner {
|
||||
private static List<ICreator> creators(CfgBean cfgBean){
|
||||
List<ICreator> creators = new ArrayList<>();
|
||||
|
||||
List<String> ca = cfgBean.getCa();
|
||||
ca.forEach(x -> {
|
||||
if ("service".equalsIgnoreCase(x)) {
|
||||
creators.add(new JavaBeanKit());// JavaBean
|
||||
creators.add(new XmlSqlKit());// 生成mysql 版本的xml配置文件, 如果要生成Es使用对应的实例对象即可
|
||||
creators.add(new ControllerKit());// Controller
|
||||
creators.add(new ServiceKit());//service
|
||||
creators.add(new ServiceImplKit());//ServiceImpl
|
||||
creators.add(new DaoMapper());// Mapper.java文件 针对使用Mybites创建对应的xxxMapper.java
|
||||
}
|
||||
if ("ddl".equalsIgnoreCase(x)) {
|
||||
creators.add(new SqlKit());// Mysql 建表语句,【提示Es或者其他建表语句可自行创建对应的实现】
|
||||
}
|
||||
if ("front".equalsIgnoreCase(x)) {
|
||||
creators.add(new CtrlKit());
|
||||
creators.add(new ListKit());
|
||||
creators.add(new EditKit());
|
||||
creators.add(new EditCtrlKit());
|
||||
creators.add(new ConditionKit());
|
||||
creators.add(new DetailKit());
|
||||
creators.add(new DetailCtrlKit());
|
||||
}
|
||||
});
|
||||
return creators;
|
||||
}
|
||||
|
||||
public static String doxx(List<ICreator> creators) throws IOException {
|
||||
StringBuffer infoBuf = new StringBuffer();
|
||||
|
||||
StringBuilder sqlBuf = new StringBuilder();
|
||||
List<Kv> ctrList = new ArrayList<>();
|
||||
|
||||
infoBuf.append("------------ start ... ------------\n");
|
||||
infoBuf.append("create service code path:" + ICreator.dirPath + "\n");
|
||||
infoBuf.append("create page code path:" + ICreator.pageDirPath + "\n");
|
||||
ICreator.sheetNames().forEach(k->{
|
||||
try {
|
||||
List<Map> list = ICreator.readExcelSheet(k);//map{field_A:v_A,field_B:v_B}
|
||||
dealData(list);//读取到的excel数据自定义处理
|
||||
|
||||
list.remove(1);//list[0] head info
|
||||
Map rowHead = list.remove(0);
|
||||
String remark = ICreator.getRemark(rowHead);//list[1] comment,
|
||||
String verify = ICreator.getVerify(rowHead);
|
||||
String[] condition = ICreator.getCondition(rowHead);
|
||||
String clazz = ICreator.getClazzName(rowHead);
|
||||
Kv para = Kv.of("remark", remark).set("verify", verify).set("condition", condition).set("table", k);
|
||||
|
||||
creators.forEach(x->{
|
||||
try {
|
||||
if (x instanceof CtrlExtKit){
|
||||
Kv kv = ((CtrlExtKit) x).createStrExt(list);
|
||||
|
||||
//kv.set("bean", ICreator.toLowerCaseFirst(clazz));
|
||||
kv.set("beanFL", ICreator.toLowerCaseFirst(clazz));
|
||||
kv.set("beanL", clazz.toLowerCase());
|
||||
kv.set("remark", remark);
|
||||
|
||||
ctrList.add(kv);
|
||||
}
|
||||
else if (x instanceof SqlKit){
|
||||
sqlBuf.append(x.createStr(clazz, list, para));
|
||||
}
|
||||
else {
|
||||
x.createFile(x.createStr(clazz, list, para), clazz);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
infoBuf.append("\t\t==> "+ k + "\n");
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
if (sqlBuf.length() > 0){
|
||||
File file = SqlKit.getFile();
|
||||
FileKit.strToFile(sqlBuf.toString(), file, true);
|
||||
infoBuf.append("sql.ddl:"+ ICreator.dirPath +"resources/ddl/\n\t\t==>"+ file.getName() + "\n");
|
||||
}
|
||||
|
||||
if (ctrList.size() > 0){
|
||||
String strCtr = ICreator.engine.getTemplate(ICreator.tplPath + "front/ext/CtrlExtTpl.js").renderToString(Kv.of("data", ctrList));
|
||||
FileKit.strToFile(strCtr, new File("tmp/listCtrl.js"));
|
||||
|
||||
String strList = ICreator.engine.getTemplate(ICreator.tplPath + "front/ext/listExtTpl.html").renderToString(Kv.of("data", ctrList));
|
||||
FileKit.strToFile(strList, new File("tmp/list.html"));
|
||||
}
|
||||
infoBuf.append("------------ complete! -----------\n");
|
||||
|
||||
System.out.println(infoBuf.toString());
|
||||
return infoBuf.toString();
|
||||
}
|
||||
|
||||
//自定义数据处理
|
||||
private static void dealData(List<Map> list) {
|
||||
list.stream().filter(x-> "tru".equalsIgnoreCase(x.get("field")+"")).forEach(x->{
|
||||
x.put("filter", "like");
|
||||
});
|
||||
}
|
||||
|
||||
public static String run(CfgBean cfgBean) throws IOException {
|
||||
ICreator.setCfgBean(cfgBean);
|
||||
|
||||
List<ICreator> creators = creators(cfgBean);
|
||||
return doxx(creators);
|
||||
}
|
||||
}
|
42
src/com/eversec/kit/creator/impl/ControllerKit.java
Normal file
42
src/com/eversec/kit/creator/impl/ControllerKit.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/5/4 10:23.
|
||||
*/
|
||||
public class ControllerKit extends ICreator {
|
||||
|
||||
private String pkg = ICreator.pkg + ".controller";
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(pkg) + clazz + "Controller.java");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
fieldList.forEach(x->{
|
||||
x.put("field", (x.get("field") + "").trim());
|
||||
x.put("isMust", isMust(x));
|
||||
x.put("fieldType", getFiledType(x.get("cate")+""));
|
||||
});
|
||||
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fieldList", fieldList);
|
||||
kv.set("hasDate", hasDate(fieldList));
|
||||
|
||||
return engine.getTemplate(tplPath + "ActionTpl.java").renderToString(kv);
|
||||
}
|
||||
|
||||
protected boolean hasDate(List<Map> fieldList) {
|
||||
return fieldList.stream().filter(x-> x.get("filter") != null && "Date".equalsIgnoreCase(String.valueOf(x.get("fieldType")))
|
||||
&& String.valueOf(x.get("filter")).length() > 0).count() > 0;
|
||||
}
|
||||
}
|
27
src/com/eversec/kit/creator/impl/DaoMapper.java
Normal file
27
src/com/eversec/kit/creator/impl/DaoMapper.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DaoMapper extends ICreator {
|
||||
|
||||
private String pkg = ICreator.pkg + ".dao";
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(pkg) + clazz + "Mapper.java");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
|
||||
return engine.getTemplate(tplPath + "MapperTpl.java").renderToString(kv);
|
||||
}
|
||||
}
|
45
src/com/eversec/kit/creator/impl/EsSqlKit.java
Normal file
45
src/com/eversec/kit/creator/impl/EsSqlKit.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2019/1/22 20:29.
|
||||
*/
|
||||
public class EsSqlKit extends XmlKit{
|
||||
|
||||
private String pkg = "resources.es_sql";
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(pkg) + clazz + ".sql");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
buf.append("# ").append(para.get("remark")).append("\n");
|
||||
buf.append("# 列表查询\n");
|
||||
buf.append("#sql("+ para.get("table") +".list)\n");
|
||||
|
||||
buf.append(" select * from " + para.get("table") + "_all\n");
|
||||
buf.append(" where 1=1\n");
|
||||
|
||||
fieldList.forEach(m -> {
|
||||
buf.append(" #if("+ m.get("field") +")\n");
|
||||
buf.append(" and `"+ m.get("field") +"`=").append("#("+ m.get("field") +")\n");
|
||||
buf.append(" #end\n");
|
||||
});
|
||||
buf.append(" and `status` != 9\n");
|
||||
buf.append(" order by `id` desc\n");
|
||||
|
||||
buf.append(" #if(maxResult)\n");
|
||||
buf.append(" limit #(startPosition),#(maxResult)\n");
|
||||
buf.append(" #end\n");
|
||||
|
||||
buf.append("#end\n");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
44
src/com/eversec/kit/creator/impl/JavaBeanKit.java
Normal file
44
src/com/eversec/kit/creator/impl/JavaBeanKit.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/5/3 18:29.
|
||||
*/
|
||||
public class JavaBeanKit extends ICreator {
|
||||
|
||||
private String pkg = ICreator.pkg + ".domain";
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(pkg) + clazz + ".java");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
fieldList.forEach(x->{
|
||||
x.put("field", (x.get("field") + "").trim());
|
||||
x.put("isMust", isMust(x));
|
||||
x.put("fieldType", getFiledType(x.get("cate")+""));
|
||||
x.put("remark", x.get("remark1") + " ("+ x.get("remark2") +")" );
|
||||
|
||||
});
|
||||
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fieldList", fieldList);
|
||||
kv.set("hasDate", hasDate(fieldList));
|
||||
|
||||
return engine.getTemplate(tplPath + "BeanTpl.java").renderToString(kv);
|
||||
}
|
||||
|
||||
protected boolean hasDate(List<Map> fieldList) {
|
||||
return fieldList.stream().filter(x->"Date".equalsIgnoreCase(String.valueOf(x.get("fieldType"))) ).count() > 0;
|
||||
}
|
||||
|
||||
}
|
28
src/com/eversec/kit/creator/impl/ServiceImplKit.java
Normal file
28
src/com/eversec/kit/creator/impl/ServiceImplKit.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/5/4 13:05.
|
||||
*/
|
||||
public class ServiceImplKit extends ICreator {
|
||||
private String pkg = ICreator.pkg + ".service.impl";
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(pkg) + clazz + "ServiceImpl.java");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
|
||||
return engine.getTemplate(tplPath + "ServiceImpTpl.java").renderToString(kv);
|
||||
}
|
||||
}
|
44
src/com/eversec/kit/creator/impl/ServiceKit.java
Normal file
44
src/com/eversec/kit/creator/impl/ServiceKit.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/5/3 18:29.
|
||||
*/
|
||||
public class ServiceKit extends ICreator {
|
||||
|
||||
private String pkg = ICreator.pkg + ".service";
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(pkg) + clazz + "Service.java");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
buf.append(
|
||||
"package "+ ICreator.pkg +".service;\n" +
|
||||
"\n" +
|
||||
"import "+ ICreator.pkg +".domain."+ clazz +";\n" +
|
||||
"import com.eversec.common.BaseService;\n" +
|
||||
"\n" +
|
||||
"/**\n" +
|
||||
" * 类名称: "+ clazz +"Service<br>\n" +
|
||||
" * 类描述: "+ para.get("remark") +"<br>\n" +
|
||||
" * 修改时间: "+ timeStr() +"<br>\n" +
|
||||
" * @author "+ author +"\n" +
|
||||
" */\n" +
|
||||
"public interface "+ clazz +"Service extends BaseService<"+ clazz +"> {\n" +
|
||||
" \n" +
|
||||
"}\n"
|
||||
);
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
52
src/com/eversec/kit/creator/impl/SqlKit.java
Normal file
52
src/com/eversec/kit/creator/impl/SqlKit.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/5/22 11:24.
|
||||
*/
|
||||
public class SqlKit extends ICreator {
|
||||
|
||||
private static String pkg = "resources.ddl";
|
||||
|
||||
public static File getFile(){
|
||||
return new File(dirPath + pkg.replace('.', '/') + "/" + "ddl.sql");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
fieldList.forEach(x->{
|
||||
x.put("field", (x.get("field") + "").trim());
|
||||
x.put("isMust", isMust(x));
|
||||
//x.put("fieldType", this.getFieldType(x.get("cate")+""));
|
||||
x.put("fieldType", x.get("cate"));
|
||||
x.put("remark", x.get("remark1"));
|
||||
});
|
||||
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fieldList", fieldList);
|
||||
kv.set("tableName", getTableName(clazz));
|
||||
|
||||
return engine.getTemplate(tplPath + "SqlTpl.sql").renderToString(kv);
|
||||
}
|
||||
|
||||
private Kv fieldType =
|
||||
Kv.of("string", "varchar(64)")
|
||||
.set("int", "int(11)")
|
||||
.set("long", "bigint(11)")
|
||||
.set("date", "datetime");
|
||||
private String getFieldType(String cate) {
|
||||
return (String) fieldType.getOrDefault(cate.trim().toLowerCase(),"varchar(64)");
|
||||
}
|
||||
}
|
226
src/com/eversec/kit/creator/impl/XmlESKit.java
Normal file
226
src/com/eversec/kit/creator/impl/XmlESKit.java
Normal file
@@ -0,0 +1,226 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/5/3 18:28.
|
||||
*/
|
||||
public class XmlESKit extends XmlKit {
|
||||
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(dirPath + "esmapper/" + clazz + "Mapper.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
String esIndex = clazz.substring(0,2).toLowerCase()+ "_" +clazz.substring(2).toLowerCase()+ "_all";
|
||||
String esType = clazz.substring(0,2).toLowerCase()+ "_" +clazz.substring(2).toLowerCase();
|
||||
|
||||
//head
|
||||
buf.append(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<mapper namespace=\""+ clazz +"Mapper\">\n"
|
||||
);
|
||||
|
||||
//=========================temple==================================
|
||||
buf.append(insertStr(clazz, fieldList, esType, esIndex));
|
||||
buf.append(findStr(clazz, fieldList, esType));
|
||||
|
||||
buf.append(updateStr(clazz, fieldList, esType));
|
||||
|
||||
|
||||
buf.append(
|
||||
"\n" +
|
||||
"</mapper>"
|
||||
);
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private StringBuffer updateStr(String clazz, List<Map> filed, String esType) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(
|
||||
"\t<sql id=\"update\">\n" +
|
||||
"\t\tupdate "+ esType +" set\n"
|
||||
);
|
||||
|
||||
List<String> arr = asList("status", "update_user_name", "update_user_id", "update_time");
|
||||
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
buf.append(
|
||||
"\t\t<isNotEmpty property=\""+ arr.get(i) +"\""+("status".equals(arr.get(i)) ? "" : " type=\"String\"")+">\n" +
|
||||
"\t\t\t"+ arr.get(i) +"=#{"+ arr.get(i) +"}"+ (i == arr.size()-1 ? "":",") + "\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
}
|
||||
buf.append(
|
||||
"\t\t where\n" +
|
||||
"\t\t<isNotEmpty property=\"uid\">\n" +
|
||||
"\t\t\t uid=#{uid}\n" +
|
||||
"\t\t</isNotEmpty>\n" +
|
||||
"\t</sql>\n\n"
|
||||
);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
private StringBuffer insertStr(String clazz, List<Map> filed, String esType, String esIndex) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(
|
||||
"\t<sql id=\"insert\">\n" +
|
||||
"\t\tinsert into\n" +
|
||||
"\t\t"+esIndex+"."+ esType +" (\n"
|
||||
);
|
||||
int tag = 0;
|
||||
//body- k
|
||||
for (Map map : filed) {//"field","cate", "must","remark1", "remark2"
|
||||
String field = (map.get("field")+"").toLowerCase();
|
||||
String type = getFiledType(map.get("cate") + "");
|
||||
|
||||
buf.append(
|
||||
isMust(map) ?
|
||||
"\t\t"+ (tag++ == 0 ? "" : ",") + field +"\n" :
|
||||
"\t\t<isNotEmpty property=\""+ field +"\"" +
|
||||
("String".equals(type) ? " type=\"String\">\n" : ">\n") +
|
||||
"\t\t\t"+ (tag++ == 0 ? "" : ",") + field +"\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
}
|
||||
buf.append(
|
||||
"\t\t)\n" +
|
||||
"\t\tvalues (\n"
|
||||
);
|
||||
tag = 0;
|
||||
//body- v
|
||||
for (Map map : filed) {
|
||||
String field = (map.get("field")+"").toLowerCase();
|
||||
String type = getFiledType(map.get("cate") + "");
|
||||
buf.append(
|
||||
"\t\t<isNotEmpty property=\""+ field +"\"" +
|
||||
("String".equals(type) ? " type=\"String\">\n" : ">\n") +
|
||||
"\t\t\t"+ (tag++ == 0 ? "" : ",") +"#{"+ field +"}\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
}
|
||||
buf.append(
|
||||
"\t\t)\n" +
|
||||
"\t</sql>\n\n"
|
||||
);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private StringBuffer findStr(String clazz, List<Map> filed, String esType) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
List<String> filter = asList("uid", "insert_user_id", "tru", "status");
|
||||
|
||||
List<String> conditions = asList("ip", "ip_md5", "url", "md5", "name", "domain", "organization", "version", "information", "interpolator"
|
||||
, "beforetitle", "aftertitle", "faketarget");
|
||||
|
||||
//条件模糊查询
|
||||
StringBuffer condBuf = new StringBuffer();
|
||||
List<String> _conditions = new ArrayList();
|
||||
filed.forEach(fMap->{
|
||||
if (conditions.contains((fMap.get("field")+"").toLowerCase())){
|
||||
_conditions.add((fMap.get("field")+"").toLowerCase());
|
||||
}
|
||||
});
|
||||
if (_conditions.size() > 0){
|
||||
condBuf.append(
|
||||
"\t\t<isNotEmpty property=\"condition\" type=\"String\">\n" +
|
||||
"\t\t\tand ("
|
||||
);
|
||||
for (int i = 0; i < _conditions.size(); i++) {
|
||||
condBuf.append((i==0? "":" or ") + _conditions.get(i) +" like #{condition}");
|
||||
}
|
||||
condBuf.append(
|
||||
")\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
}
|
||||
|
||||
buf.append(
|
||||
"\t<sql id=\"findCount\">\n" +
|
||||
"\t\tselect count(1) from "+ esType +" where 1=1\n"
|
||||
);
|
||||
//查询条件
|
||||
buf.append(
|
||||
"\n"
|
||||
);
|
||||
|
||||
buf.append(condBuf);//模糊查询
|
||||
|
||||
filter.forEach(x->{
|
||||
buf.append(
|
||||
"\t\t<isNotEmpty property=\""+ x +"\""+ ("status".equals(x) || "uid".equals(x) ? "" : " type=\"String\"") +">\n" +
|
||||
"\t\t\t and "+ x +"=#{"+ x +"}\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
});
|
||||
buf.append(
|
||||
"\t\t<isNotEmpty property=\"startDate\" type=\"String\">\n" +
|
||||
"\t\t\t and datatime > #{startDate}\n" +
|
||||
"\t\t</isNotEmpty>\n"+
|
||||
"\t\t<isNotEmpty property=\"endDate\" type=\"String\">\n" +
|
||||
"\t\t\t and datatime < #{endDate}\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
|
||||
|
||||
buf.append(
|
||||
"\n"
|
||||
);
|
||||
buf.append(
|
||||
"\t</sql>\n\n"
|
||||
);
|
||||
|
||||
buf.append(
|
||||
"\t<sql id=\"findList\">\n" +
|
||||
"\t\tselect * from "+ esType +" where 1=1\n"
|
||||
);
|
||||
//查询条件
|
||||
buf.append(
|
||||
"\n"
|
||||
);
|
||||
|
||||
buf.append(condBuf);//模糊查询
|
||||
|
||||
filter.forEach(x->{
|
||||
buf.append(
|
||||
"\t\t<isNotEmpty property=\""+ x +"\""+ ("status".equals(x) || "uid".equals(x) ? "" : " type=\"String\"") +">\n" +
|
||||
"\t\t\t and "+ x +"=#{"+ x +"}\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
});
|
||||
buf.append(
|
||||
"\t\t<isNotEmpty property=\"startDate\" type=\"String\">\n" +
|
||||
"\t\t\t and datatime > #{startDate}\n" +
|
||||
"\t\t</isNotEmpty>\n"+
|
||||
"\t\t<isNotEmpty property=\"endDate\" type=\"String\">\n" +
|
||||
"\t\t\t and datatime < #{endDate}\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
buf.append(
|
||||
"\t\t<isNotEmpty property=\"maxResult\">\n" +
|
||||
"\t\t\tlimit #{maxResult}\n" +
|
||||
"\t\t</isNotEmpty>\n" +
|
||||
"\t\t<isNotEmpty property=\"startPosition\">\n" +
|
||||
"\t\t\toffset #{startPosition}\n" +
|
||||
"\t\t</isNotEmpty>\n"
|
||||
);
|
||||
buf.append(
|
||||
"\t</sql>\n\n"
|
||||
);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
}
|
14
src/com/eversec/kit/creator/impl/XmlKit.java
Normal file
14
src/com/eversec/kit/creator/impl/XmlKit.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/5/22 14:41.
|
||||
*/
|
||||
public abstract class XmlKit extends ICreator {
|
||||
|
||||
@Override
|
||||
public String filePath(String pkg){
|
||||
return dirPath + pkg.replace('.', '/') + "/";
|
||||
}
|
||||
}
|
62
src/com/eversec/kit/creator/impl/XmlSqlKit.java
Normal file
62
src/com/eversec/kit/creator/impl/XmlSqlKit.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.eversec.kit.creator.impl;
|
||||
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/5/3 18:28.
|
||||
*/
|
||||
public class XmlSqlKit extends XmlKit {
|
||||
|
||||
private String pkg = "resources.mapper";
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(pkg) + clazz + "Mapper.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("verify", para.get("verify"));
|
||||
kv.set("condition", para.get("condition"));
|
||||
kv.set("table", getTableName(clazz));
|
||||
kv.set("fields", dealField(fieldList));
|
||||
kv.set("order", createOrder(clazz, fieldList));
|
||||
|
||||
return engine.getTemplate(tplPath + "MapperTpl.xml").renderToString(kv);
|
||||
}
|
||||
|
||||
private static Map ordMap =
|
||||
Kv.of(getClazzName("basic_platform"), "order by `keyPlat` desc,`id` desc")
|
||||
.set(getClazzName("basic_enterprise"), "order by `keyEnterprise` desc,`id` desc")
|
||||
.set(getClazzName("basic_ip"), "order by `status` desc,`id` desc");
|
||||
private String createOrder(String clazz, List<Map> fieldList) {
|
||||
return String.valueOf(ordMap.getOrDefault(clazz, "order by `id` desc"));
|
||||
}
|
||||
|
||||
private static List<String> numbers = asList("Integer", "Long");
|
||||
private List<Map> dealField(List<Map> fieldList) {
|
||||
//处理数值型字段标记,--在mybites 的xml中 数值型0 ,判断 != '' 的问题
|
||||
|
||||
fieldList.stream().forEach(f -> {
|
||||
String jType = getFiledType(f.get("cate")+"");
|
||||
if (jType != "Date" && jType != "String" && !numbers.contains(jType)) {
|
||||
System.out.println(jType);
|
||||
}
|
||||
|
||||
f.put("isNumber", numbers.contains(jType));
|
||||
});
|
||||
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
|
||||
}
|
27
src/com/eversec/kit/creator/impl/page/ConditionKit.java
Normal file
27
src/com/eversec/kit/creator/impl/page/ConditionKit.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/7 15:01.
|
||||
*/
|
||||
public class ConditionKit extends PageKit {
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(dirPath + pageModel +"/" + getFileDir(clazz) + "/condition.html");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fieldList", fieldList);
|
||||
|
||||
|
||||
return engine.getTemplate(tplPath + "front/conditionTpl.html").renderToString(kv);
|
||||
}
|
||||
}
|
35
src/com/eversec/kit/creator/impl/page/CtrlExtKit.java
Normal file
35
src/com/eversec/kit/creator/impl/page/CtrlExtKit.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/6 16:34.
|
||||
*/
|
||||
public class CtrlExtKit extends PageKit {
|
||||
|
||||
private static CtrlKit ctrlKit = new CtrlKit();
|
||||
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(clazz) + "/listCtrl.js");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
return ctrlKit.createStr(clazz,fieldList, para);
|
||||
}
|
||||
|
||||
public Kv createStrExt(List<Map> fieldList) {
|
||||
return ctrlKit.createFiledLabel(fieldList, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileDir(String clazz){
|
||||
return toLowerCaseFirst(clazz);
|
||||
}
|
||||
}
|
95
src/com/eversec/kit/creator/impl/page/CtrlKit.java
Normal file
95
src/com/eversec/kit/creator/impl/page/CtrlKit.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/6 16:34.
|
||||
*/
|
||||
public class CtrlKit extends PageKit {
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(clazz) + "/listCtrl.js");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fileDir", getFileDir(clazz));
|
||||
kv.set("fieldList", fieldList);
|
||||
kv.set("conditionLabel", getConditionLabel(fieldList, para));
|
||||
kv = createFiledLabel(fieldList, kv);
|
||||
|
||||
return engine.getTemplate(tplPath + "front/CtrlTpl.js").renderToString(kv);
|
||||
}
|
||||
|
||||
private static List<String> noShow = asList("id","tokenID","truCode","insertUserId","insertTime"
|
||||
,"updateUserName","updateUserId","updateTime","eventdate","status");
|
||||
private boolean showColumn(Map map){
|
||||
return "1".equalsIgnoreCase(String.valueOf(map.get("column"))) || !noShow.contains(map.get("field")+"");
|
||||
}
|
||||
|
||||
protected Kv createFiledLabel(List<Map> fieldList, Kv res){
|
||||
if (res == null) res = Kv.of();
|
||||
StringBuilder labelBuf = new StringBuilder();
|
||||
StringBuilder fieldBuf = new StringBuilder();
|
||||
fieldList.forEach(x->{
|
||||
if (showColumn(x)){
|
||||
labelBuf.append("\""+ x.get("remark1") +"\",");
|
||||
|
||||
if ("2".equals(String.valueOf(x.get("edit")))){
|
||||
fieldBuf.append("\""+ x.get("field") +"||"+ x.get("selects") +"\",");
|
||||
}else if ("SELECT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
|
||||
fieldBuf.append("\""+ x.get("field") + "="+ x.get("field") +"\",");
|
||||
}else if ("SELECT_EXT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
|
||||
fieldBuf.append("\""+ x.get("field") +"|"+ x.get("selects") +"\",");
|
||||
}else if ("INPUT_DT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
|
||||
fieldBuf.append("\""+ x.get("field") +"=dt\",");
|
||||
}
|
||||
|
||||
else if ("FILE_EXT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
|
||||
fieldBuf.append("\""+ x.get("selects") +"\",");
|
||||
}else {
|
||||
fieldBuf.append("\""+ x.get("field") +"\",");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (labelBuf.length() > 0){
|
||||
labelBuf.deleteCharAt(labelBuf.length()-1);
|
||||
}
|
||||
if (fieldBuf.length() > 0){
|
||||
fieldBuf.deleteCharAt(fieldBuf.length()-1);
|
||||
}
|
||||
res.set("label", labelBuf.toString());
|
||||
res.set("field", fieldBuf.toString());
|
||||
return res;
|
||||
}
|
||||
|
||||
//获取设置了关键字查询的 字段“描述”
|
||||
private String getConditionLabel(List<Map> fieldList, Map para) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (para.get("condition") != null){
|
||||
List<String> conditions = asList((String[]) para.get("condition"));
|
||||
fieldList.forEach(m->{
|
||||
for (String str : conditions) {
|
||||
//字段有大小写转换,这里需要使用 equalsIgnoreCase 进行比较
|
||||
if ((m.get("field")+"").trim().equalsIgnoreCase(str)) {
|
||||
buf.append(m.get("remark1")+"/");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (buf.length() > 0){
|
||||
buf.deleteCharAt(buf.length()-1);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
27
src/com/eversec/kit/creator/impl/page/DetailCtrlKit.java
Normal file
27
src/com/eversec/kit/creator/impl/page/DetailCtrlKit.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/20 16:08.
|
||||
*/
|
||||
public class DetailCtrlKit extends PageKit {
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(clazz) + "/detailCtrl.js");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fileDir", getFileDir(clazz));
|
||||
kv.set("fieldList", fieldList);
|
||||
|
||||
return engine.getTemplate(tplPath + "front/detailCtrlTpl.js").renderToString(kv);
|
||||
}
|
||||
}
|
42
src/com/eversec/kit/creator/impl/page/DetailKit.java
Normal file
42
src/com/eversec/kit/creator/impl/page/DetailKit.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/20 16:08.
|
||||
*/
|
||||
public class DetailKit extends PageKit {
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(clazz) + "/detail.html");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fileDir", getFileDir(clazz));
|
||||
kv.set("fieldList", fieldList);
|
||||
|
||||
fieldList.forEach(x->{
|
||||
String field = String.valueOf(x.get("field"));
|
||||
|
||||
if ("2".equals(String.valueOf(x.get("edit")))){
|
||||
field = field +"||"+ x.get("selects");
|
||||
}else if ("SELECT_EXT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
|
||||
field = field +"|"+ x.get("selects");
|
||||
}else if ("INPUT_DT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
|
||||
field = field +"=dt";
|
||||
}else if ("FILE_EXT".equalsIgnoreCase(String.valueOf(x.get("tag")))){
|
||||
field = String.valueOf(x.get("selects"));
|
||||
}
|
||||
x.put("field", field);
|
||||
});
|
||||
|
||||
return engine.getTemplate(tplPath + "front/detailTpl.html").renderToString(kv);
|
||||
}
|
||||
}
|
33
src/com/eversec/kit/creator/impl/page/EditCtrlKit.java
Normal file
33
src/com/eversec/kit/creator/impl/page/EditCtrlKit.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/7 12:44.
|
||||
*/
|
||||
public class EditCtrlKit extends PageKit {
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(clazz) + "/editCtrl.js");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fileDir", getFileDir(clazz));
|
||||
kv.set("fieldList", fieldList);
|
||||
kv.set("hasDate", hasDate(fieldList));
|
||||
|
||||
return engine.getTemplate(tplPath + "front/editCtrlTpl.js").renderToString(kv);
|
||||
}
|
||||
|
||||
private boolean hasDate(List<Map> fieldList) {
|
||||
return fieldList.stream().filter(x-> "1".equals(String.valueOf(x.get("edit")))
|
||||
&& "INPUT_DT".equalsIgnoreCase(String.valueOf(x.get("tag")))).count() > 0;
|
||||
}
|
||||
}
|
36
src/com/eversec/kit/creator/impl/page/EditKit.java
Normal file
36
src/com/eversec/kit/creator/impl/page/EditKit.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/7 10:15.
|
||||
*/
|
||||
public class EditKit extends PageKit {
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(clazz) + "/edit.html");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
fieldList.forEach(x->{
|
||||
x.put("isMust", isMust(x));
|
||||
});
|
||||
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fileDir", getFileDir(clazz));
|
||||
kv.set("fieldList", fieldList);
|
||||
kv.set("hasEdit2", hasEdit2(fieldList));
|
||||
|
||||
return engine.getTemplate(tplPath + "front/editTpl.html").renderToString(kv);
|
||||
}
|
||||
|
||||
private boolean hasEdit2(List<Map> fieldList) {
|
||||
return fieldList.stream().filter(x->"2".equalsIgnoreCase(String.valueOf(x.get("edit")))).count() > 0;
|
||||
}
|
||||
}
|
30
src/com/eversec/kit/creator/impl/page/JsServiceKit.java
Normal file
30
src/com/eversec/kit/creator/impl/page/JsServiceKit.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 创建 service.js
|
||||
* @author: liangxianyou at 2018/8/6 16:34.
|
||||
*/
|
||||
public class JsServiceKit extends PageKit {
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
String fileDir = getFileDir(clazz);
|
||||
return new File(dirPath + pageModel +"/" + fileDir + "/"+ fileDir +"Service.js");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
String fileDir = getFileDir(clazz);
|
||||
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("fileDir", fileDir);
|
||||
|
||||
return engine.getTemplate(tplPath + "front/ServiceTpl.js").renderToString(kv);
|
||||
}
|
||||
}
|
44
src/com/eversec/kit/creator/impl/page/ListKit.java
Normal file
44
src/com/eversec/kit/creator/impl/page/ListKit.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* 创建list.html
|
||||
* @author: liangxianyou at 2018/8/6 16:33.
|
||||
*/
|
||||
public class ListKit extends PageKit {
|
||||
@Override
|
||||
public File getFile(String clazz) {
|
||||
return new File(filePath(clazz) + "/list.html");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStr(String clazz, List<Map> fieldList, Map para) {
|
||||
Kv kv = createTplData(clazz);
|
||||
kv.set("remark", para.get("remark"));
|
||||
kv.set("condition", getCondition(fieldList, para));
|
||||
getFileDir(clazz);
|
||||
|
||||
return engine.getTemplate(tplPath + "front/listTpl.html").renderToString(kv);
|
||||
}
|
||||
|
||||
private String getCondition(List<Map> fieldList, Map para) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (para.get("condition") != null){
|
||||
List<String> list = asList((String[])para.get("condition"));
|
||||
fieldList.stream().filter(x -> list.contains(x.get("field") + "")).forEach(x->{
|
||||
buf.append(x.get("remark1")+"/");
|
||||
});
|
||||
}
|
||||
if (buf.length() > 0){
|
||||
buf.deleteCharAt(buf.length()-1);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
27
src/com/eversec/kit/creator/impl/page/PageKit.java
Normal file
27
src/com/eversec/kit/creator/impl/page/PageKit.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.eversec.kit.creator.impl.page;
|
||||
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/6 16:36.
|
||||
*/
|
||||
public abstract class PageKit extends ICreator {
|
||||
|
||||
public static String dirPath = ICreator.pageDirPath;
|
||||
|
||||
public String getFileDir(String clazz){
|
||||
/*for (String str : fileDirPir) {
|
||||
if (clazz.contains(str)){
|
||||
return clazz.replace(str, "").toLowerCase();
|
||||
}
|
||||
}
|
||||
return clazz.toLowerCase();*/
|
||||
return toLowerCaseFirst(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String filePath(String clazz){
|
||||
return dirPath + pageModel +"/" + getFileDir(clazz);
|
||||
}
|
||||
|
||||
}
|
110
src/com/eversec/kit/dev/DataKit.java
Normal file
110
src/com/eversec/kit/dev/DataKit.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.eversec.kit.dev;
|
||||
|
||||
import com.eversec.common.FileKit;
|
||||
import com.lxyer.excel.poi.ExcelKit;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class DataKit {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
//createUpdateSql();
|
||||
//sheetNames();
|
||||
createChart();
|
||||
}
|
||||
|
||||
public static void createUpdateSql() throws IOException {
|
||||
|
||||
String[] ports = {"8080","8000","8012","8003","8801","5004","20004","60001","80","60001","10001","23","82","23","4410","8443","5000","5002","60001","9600","1935"};
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Random random = new Random();
|
||||
for (int i = 1; i <= 61824; i++) {
|
||||
buf.append(String.format("update basic_goods set iPaddress='%s.%s.%s.%s',iPPort='%s' where id=%s;%n"
|
||||
, random.nextInt(256)
|
||||
, random.nextInt(256)
|
||||
, random.nextInt(256)
|
||||
, random.nextInt(256)
|
||||
, ports[random.nextInt(ports.length)]
|
||||
, i
|
||||
));
|
||||
|
||||
if (i> 0 && (i%20000 == 0 || i == 93863-1)){
|
||||
FileKit.strToFile(buf.toString(), new File("tmp/data/up_"+ i +".sql"), true);
|
||||
buf = new StringBuffer(buf.length()+100);
|
||||
}
|
||||
}
|
||||
|
||||
/*String tpl = "update basic_goods g,basic_enterprise e set g.unitCompany=e.companyName where e.id=%s and g.id in (%s);%n";
|
||||
for (int i = 18; i < 129; i++) {
|
||||
String ids = "";
|
||||
for (int j = i; j <= 61824; j = j + (128-18)) {
|
||||
ids += j+",";
|
||||
}
|
||||
ids = ids.substring(0, ids.length()-1);
|
||||
buf.append(String.format(tpl, i, ids));
|
||||
}
|
||||
|
||||
FileKit.strToFile(buf.toString(), new File("tmp/data/up_goods.sql"), true);*/
|
||||
}
|
||||
|
||||
public static void sheetNames() throws IOException {
|
||||
ExcelKit.getSheetNames(new File("res/xls/table.xls")).forEach(x->{
|
||||
System.out.print(String.format(",%s%n", x));
|
||||
});
|
||||
}
|
||||
|
||||
public static void createChart(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dealCompanyData() {
|
||||
File file = new File("C:\\Users\\eversec\\Documents\\WXWork\\1688854143550524\\Cache\\File\\2019-01\\basic_platform(2).xlsx");
|
||||
|
||||
String[] heads = {
|
||||
"xh", "id", "platId", "platName", "platDomain", "ip", "platType", "companyId", "accessProvince",
|
||||
"isKey", "firstTime", "accessType", "serviceType", "userNum", "contact", "tel", "email"
|
||||
};
|
||||
|
||||
String[] ks = {"platId", "platName", "platType", "companyId", "accessProvince",
|
||||
"isKey", "firstTime", "accessType", "serviceType", "userNum", "contact", "tel", "email"};
|
||||
|
||||
try {
|
||||
List<Map> list = ExcelKit.readExcel(file, heads);
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("insert basic_platform_1 (");
|
||||
asList(ks).forEach(k -> {
|
||||
buf.append(k).append(",");
|
||||
});
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
buf.append(") values \n");
|
||||
|
||||
list.forEach(r -> {
|
||||
buf.append("(");
|
||||
asList(ks).forEach(k -> {
|
||||
buf.append("'").append(r.getOrDefault(k, "")).append("',");
|
||||
});
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
buf.append("),\n");
|
||||
});
|
||||
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
|
||||
FileKit.strToFile(buf.toString(), new File("tmp/xxx.sql"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
222
src/com/eversec/kit/dev/Dict2Db.java
Normal file
222
src/com/eversec/kit/dev/Dict2Db.java
Normal file
@@ -0,0 +1,222 @@
|
||||
package com.eversec.kit.dev;
|
||||
|
||||
import com.eversec.common.FileKit;
|
||||
import com.eversec.common.Kv;
|
||||
import com.jfinal.template.Engine;
|
||||
import com.lxyer.excel.poi.ExcelKit;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* 字典数据入库
|
||||
* 1、读取excel
|
||||
* 2、生成入库语句
|
||||
*
|
||||
* @author: liangxianyou at 2018/8/15 10:54.
|
||||
*/
|
||||
public class Dict2Db {
|
||||
|
||||
public static String clazzRoot = Dict2Db.class.getClassLoader().getResource("").getPath();
|
||||
public static Engine engine = Engine.use();
|
||||
|
||||
public static void main(String[] args) {
|
||||
//
|
||||
//createSql(readExcel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取dict字典数据
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, List<Map>> readExcel(){
|
||||
try {
|
||||
return ExcelKit.readExcelAll(new File("res/xls/dict.xls"), new String[]{"id", "name", "code"});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建字典入库sql语句
|
||||
* @param listMap
|
||||
*/
|
||||
public static void createSql(Map<String, List<Map>> listMap) {
|
||||
|
||||
Kv kv = Kv.of("maps", listMap);
|
||||
String str = engine.getTemplate(clazzRoot + "libs/tpl/DictSqlTpl.sql").renderToString(kv);
|
||||
|
||||
try {
|
||||
FileKit.strToFile(str, new File("tmp/db/dict_data.sql"), true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Map> readCityData() {
|
||||
try {
|
||||
return ExcelKit.readExcel(new File("res/xls/省市县数据.xlsx"), new String[]{"code", "province", "city"});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Predicate<Map> isProvice = (s) -> String.valueOf(s.get("code")).trim().endsWith("0000");
|
||||
Predicate<Map> isCity = (s) -> String.valueOf(s.get("code")).trim().endsWith("00");
|
||||
Predicate<Map> isCounty = (s) -> !String.valueOf(s.get("code")).trim().endsWith("00");
|
||||
|
||||
/**
|
||||
* 处理 省-市-县数据
|
||||
*/
|
||||
//@Test
|
||||
public Map getCityData() {
|
||||
List<Map> maps = readCityData();
|
||||
maps.remove(0);
|
||||
|
||||
Map provices = new LinkedHashMap();
|
||||
maps.forEach(x -> {
|
||||
if (isProvice.test(x)) {
|
||||
//System.out.println(x);
|
||||
LinkedHashMap<Object, Object> provice = new LinkedHashMap<>();
|
||||
provice.put("name", x.get("province"));
|
||||
provices.put(x.get("code"), provice);
|
||||
} else {
|
||||
String proCode = String.valueOf(x.get("code")).trim().substring(0, 2) + "0000"; // 省编码
|
||||
String cityCode = String.valueOf(x.get("code")).trim().substring(0, 4) + "00"; // 市编码
|
||||
|
||||
Map provice = (Map) provices.getOrDefault(proCode, new LinkedHashMap<>()); //省数据
|
||||
Map city = (Map) provice.getOrDefault(cityCode, new LinkedHashMap<>()); //市数据
|
||||
if (isCity.test(x)) {
|
||||
city.put("name", x.get("city"));
|
||||
provice.put(x.get("code"), city);
|
||||
} else if (isCounty.test(x)){
|
||||
String countyCode = String.valueOf(x.get("code")).trim(); // 县编码
|
||||
Map county = (Map) provice.getOrDefault(countyCode, new LinkedHashMap<>()); //县数据
|
||||
county.put("name", x.get("city"));
|
||||
|
||||
city.put(countyCode, county);
|
||||
}
|
||||
provices.put(proCode, provice);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*try {
|
||||
FileKit.strToFile(new Gson().toJson(provices), new File("tmp/city.json"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
return provices;
|
||||
}
|
||||
|
||||
private BiFunction<String, Map<String, Object>, String> fun = (s, m) -> {
|
||||
//扫描第一层
|
||||
for (String k : m.keySet()) {
|
||||
if (!"name".equals(k)) {
|
||||
Map map = (Map) m.get(k);
|
||||
if (String.valueOf(map.get("name")).contains(s)) {
|
||||
return k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
private BiFunction<String[], Map<String, Object>, String[]> cityDeal = (ss, m) -> {
|
||||
String proCode = fun.apply(ss[0], m);
|
||||
String cityCode = null;
|
||||
|
||||
if (proCode != null) {
|
||||
Map<String, Object> proData = (Map<String, Object>) m.get(proCode);
|
||||
cityCode = fun.apply(ss[1], proData);
|
||||
|
||||
for (String k : proData.keySet()) {
|
||||
if (!"name".equals(k)) {
|
||||
cityCode = fun.apply(ss[1], (Map<String, Object>) proData.get(k));
|
||||
if (cityCode != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new String[]{proCode, cityCode};
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 中文反查询 城市编码
|
||||
*/
|
||||
@Test
|
||||
public void run1() {
|
||||
String provice = "宁夏";
|
||||
String city = "同心";
|
||||
|
||||
Kv kv = Kv.of(440000,"东莞市").set(370000,"临沂市").set(440000,"云浮市").set(440000,"佛山市").set(620000,"兰州市").set(110000,"北京").set(320000,"南京").set(360000,"南昌").set(350000,"厦门").set(340000,"合肥").set(150000,"呼和浩特").set(120000,"天津").set(140000,"太原").set(510000,"广元").set(440000,"广州").set(320000,"徐州").set(440000,"惠州").set(510000,"成都").set(440000,"揭阳").set(320000,"无锡").set(530000,"昆明").set(330000,"杭州").set(440000,"梅州").set(420000,"武汉").set(440000,"江门").set(350000,"泉州").set(370000,"泰安").set(370000,"济南").set(370000,"济宁").set(370000,"淄博").set(440000,"深圳").set(440000,"湛江").set(370000,"滨州").set(370000,"潍坊").set(370000,"烟台").set(440000,"珠海").set(650000,"石河子").set(350000,"福州").set(440000,"肇庆").set(340000,"芜湖").set(320000,"苏州").set(430000,"衡阳").set(630000,"西宁").set(610000,"西安").set(360000,"赣州").set(510000,"达州").set(130000,"邢台").set(420000,"鄂州").set(500000,"重庆").set(320000,"镇江").set(430000,"长沙").set(370000,"青岛").set(420000,"黄石");
|
||||
|
||||
String[] sArr = {provice, city};
|
||||
|
||||
Map<String, Map<String, Object>> cityData = getCityData();
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
cityData.forEach((k, v) -> {
|
||||
buf.append(String.format("('%s','%s'),%n", k, v.get("name")));
|
||||
|
||||
System.out.println(v);
|
||||
|
||||
v.forEach((k1, v1) -> {
|
||||
if (k1.equals("name")) {
|
||||
} else {
|
||||
buf.append(String.format("('%s','%s'),%n", k1, ((Map)v1).get("name")));
|
||||
|
||||
((Map) v1).forEach((k2,v2) -> {
|
||||
if (!k2.equals("name")) {
|
||||
buf.append(String.format("('%s','%s'),%n", k2, ((Map)v2).get("name")));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
FileKit.strToFile(buf.toString(), new File("tmp/city.sql"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
/*kv.forEach((k, v) -> {
|
||||
Map map = (Map) cityData.get(String.valueOf(k));
|
||||
map.forEach((_k,_v) -> {
|
||||
System.out.println(_v);
|
||||
if (!"name".equals(_k) && String.valueOf(((Map)_v).get("name")).equals(String.valueOf(v))) {
|
||||
System.out.printf("%s - %s", _k, v);
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*String[] apply = cityDeal.apply(sArr, cityData);
|
||||
|
||||
System.out.println(apply[0]);
|
||||
System.out.println(apply[1]);*/
|
||||
}
|
||||
|
||||
}
|
272
src/com/eversec/kit/dev/ExportTable.java
Normal file
272
src/com/eversec/kit/dev/ExportTable.java
Normal file
@@ -0,0 +1,272 @@
|
||||
package com.eversec.kit.dev;
|
||||
|
||||
import com.arangodb.ArangoCollection;
|
||||
import com.arangodb.ArangoCursor;
|
||||
import com.arangodb.ArangoDB;
|
||||
import com.arangodb.ArangoDatabase;
|
||||
import com.eversec.common.FileKit;
|
||||
import com.eversec.common.JdbcKit;
|
||||
import com.eversec.common.Kv;
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* export table example.
|
||||
* - export table to word.
|
||||
* - export to other.
|
||||
* @author: liangxianyou at 2018/10/8 10:55.
|
||||
*/
|
||||
public class ExportTable {
|
||||
|
||||
private static String rootPath = FileKit.rootPath(ExportTable.class);
|
||||
|
||||
/**
|
||||
* export table to word
|
||||
* 数据库表结构导出到word示例.
|
||||
* @throws SQLException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void demo() throws SQLException, IOException {
|
||||
//load table ddl; gxbii_dev 为database, 连接的数据库修改 JdbcKit
|
||||
//List<Table> tables = JdbcKit.tables("gxbii_dev");
|
||||
|
||||
List<Table> tables = ImportTable.tables();
|
||||
|
||||
|
||||
tables.forEach(t -> {
|
||||
System.out.println(t.getName() + " " + t.getComment());
|
||||
});
|
||||
|
||||
//export to word
|
||||
FileKit.tplRender(new File(rootPath + "/libs/tpl/wordTpl.xml"), new File("target/tables.docx"), Kv.of("tables", tables));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出工控数据库表结构到word
|
||||
*
|
||||
* @throws SQLException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void tableToWord() throws SQLException, IOException {
|
||||
|
||||
List<Table> tables = new ArrayList<>();
|
||||
|
||||
//load gxbii_dev
|
||||
JdbcKit.tables("gxbii_dev").stream().filter(t ->
|
||||
!t.getName().startsWith("ct_") &&
|
||||
!t.getName().startsWith("iplocation_") &&
|
||||
!t.getName().endsWith("_old") &&
|
||||
!t.getName().startsWith("Sheet")
|
||||
).forEach(t -> {
|
||||
tables.add(t);
|
||||
});
|
||||
|
||||
//load gxbii_cmd
|
||||
JdbcKit.tables("gxbii_cmd").stream().filter(t ->
|
||||
t.getName().startsWith("cmd_")
|
||||
).forEach(t -> {
|
||||
tables.add(t);
|
||||
});
|
||||
|
||||
/*tables.forEach(t->{
|
||||
System.out.println(t.getName()+ " " +t.getComment());
|
||||
});*/
|
||||
|
||||
//export
|
||||
FileKit.tplRender(new File(rootPath + "/libs/tpl/wordTpl.xml"), new File("target/tables.docx"), Kv.of("tables", tables));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过mysql 表创建 javaBean示例
|
||||
*/
|
||||
/* @Test
|
||||
public void tableToBean() {
|
||||
try {
|
||||
Table2BeanKit beanKit = new Table2BeanKit();
|
||||
List<Table> tables = JdbcKit.tables("gxbii_dev", "task_export");
|
||||
tables.forEach(x -> {
|
||||
String str = beanKit.createByTable(x);
|
||||
try {
|
||||
beanKit.createFile(str, ICreator.getClazzName(x.getName()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* 导出数据库结构到excel表
|
||||
*/
|
||||
@Test
|
||||
public void tableToExcel() {
|
||||
|
||||
}
|
||||
|
||||
//====================ArangoDB===========================
|
||||
private static ArangoDB arangoDb = new ArangoDB.Builder().host("120.24.230.60", 8529).user("root").password("root").build();
|
||||
private static ArangoDatabase dbDev = arangoDb.db("db_dev");
|
||||
private static ArangoCollection sysCols = dbDev.collection("sys_cols");
|
||||
private static ArangoCollection metaCols = dbDev.collection("meta_cols");
|
||||
|
||||
@Test
|
||||
public void t() {
|
||||
//
|
||||
String aql = "for d in meta_cols\n" +
|
||||
" return d";
|
||||
|
||||
ArangoCursor<MetaTable> cursor = dbDev.query(aql, null, null, MetaTable.class);
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
MetaTable col = cursor.next();
|
||||
|
||||
System.out.println(col);
|
||||
//System.out.println(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将mysql 数据库表结构导入到 arangodb
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Test
|
||||
public void tableToArango() throws SQLException {
|
||||
List<Table> redbbs = JdbcKit.tables("gxbii_dev");
|
||||
|
||||
redbbs.forEach(x -> {
|
||||
List columns = new ArrayList();
|
||||
x.getColumns().forEach(c -> {
|
||||
columns.add(Kv.of("name", c.getName()).set("label", c.getComment()).set("type", c.getType()));
|
||||
});
|
||||
|
||||
Kv doc = Kv.of("_key", x.getName()).set("name", x.getName()).set("comment", x.getComment()).set("item", columns);
|
||||
|
||||
Map document = sysCols.getDocument(x.getName(), Map.class);
|
||||
|
||||
if (document != null) {
|
||||
sysCols.updateDocument(x.getName(), doc);
|
||||
} else {
|
||||
sysCols.insertDocument(doc);
|
||||
}
|
||||
//System.out.println(doc);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excelToArango() {
|
||||
ICreator.sheetNames().forEach(k -> {
|
||||
try {
|
||||
List<Map> list = ICreator.readExcelSheet(k);
|
||||
//tables.add(toTable(list));
|
||||
Map doc = toCols(list);
|
||||
doc.put("sysPlatId", 4264801);
|
||||
|
||||
String _key = doc.get("name") + "";
|
||||
doc.put("_key", _key);
|
||||
|
||||
Map document = metaCols.getDocument(_key, Map.class);
|
||||
|
||||
System.out.println(doc);
|
||||
if (document != null) {
|
||||
metaCols.updateDocument(_key, doc);
|
||||
} else {
|
||||
//metaCols.insertDocument(doc);
|
||||
}
|
||||
|
||||
//System.out.println(doc);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装元数据
|
||||
*/
|
||||
private Map toCols(List<Map> list) {
|
||||
|
||||
Kv col = Kv.of();
|
||||
|
||||
list.remove(1);//list[0] head info
|
||||
Map rowHead = list.remove(0);
|
||||
|
||||
String comment = ImportTable.getComment(rowHead);//list[1] comment,
|
||||
String tableName = ImportTable.getTableName(rowHead);
|
||||
col.set("name", tableName).set("comment", comment);
|
||||
|
||||
//所有字段
|
||||
List<Kv> items = new ArrayList<>();
|
||||
|
||||
//展示的字段
|
||||
List<String> shows = new ArrayList<>();
|
||||
|
||||
//编辑的字段
|
||||
List<String> edits = new ArrayList<>();
|
||||
|
||||
//查询过滤用字段
|
||||
List<Kv> filters = new ArrayList<>();
|
||||
|
||||
|
||||
list.forEach(x -> {
|
||||
String field = x.get("field") + "";
|
||||
|
||||
Kv item = Kv.of();
|
||||
item.set("name", field);
|
||||
item.set("label", x.get("remark1"));
|
||||
item.set("remark", x.get("remark2"));
|
||||
item.set("type", x.get("cate"));
|
||||
item.set("inType", x.get("tag"));
|
||||
item.set("inExt", x.get("selects"));
|
||||
items.add(item);
|
||||
|
||||
|
||||
if ("1".equals(x.get("column") + "")) {
|
||||
shows.add(field);
|
||||
}
|
||||
|
||||
if ("1".equals(x.get("edit") + "")) {
|
||||
edits.add(field);
|
||||
}
|
||||
|
||||
if (x.get("filter") != null && !"".equals(x.get("filter") + "")) {
|
||||
String filter = x.get("filter") + "";
|
||||
filter = filter.replace("1", "EQUAL");
|
||||
filter = filter.replace("!1", "NOTEQUAL");
|
||||
filter = filter.replace("like", "LIKE");
|
||||
|
||||
filters.add(Kv.of("name", field).set("filterType", asList(filter.split(","))));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
col.set("items", items);
|
||||
col.set("shows", shows);
|
||||
col.set("edits", edits);
|
||||
col.set("filters", filters);
|
||||
return col;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadTables() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
75
src/com/eversec/kit/dev/ImportTable.java
Normal file
75
src/com/eversec/kit/dev/ImportTable.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.eversec.kit.dev;
|
||||
|
||||
import com.eversec.kit.creator.ICreator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 业务元数据管理实现:
|
||||
* 1、将业务属性统一存贮到 "属性元数据中",
|
||||
* 2、每个实体记录 "元属性的属性id" 、属性中文名称、是否必填、描述、备注
|
||||
* 3、业务实体 对应着多种功能,记录每种功能的业务元属性{}
|
||||
*
|
||||
* @author: liangxianyou at 2018/10/11 14:47.
|
||||
*/
|
||||
public class ImportTable {
|
||||
|
||||
public static List<Table> tables(){
|
||||
List<Table> tables = new ArrayList<>();
|
||||
ICreator.sheetNames().forEach(k->{
|
||||
try {
|
||||
List<Map> list = ICreator.readExcelSheet(k);
|
||||
tables.add(toTable(list));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
return tables;
|
||||
}
|
||||
|
||||
private static Table toTable(List<Map> list){
|
||||
list.remove(1);//list[0] head info
|
||||
Map rowHead = list.remove(0);
|
||||
|
||||
String comment = getComment(rowHead);//list[1] comment,
|
||||
String tableName = getTableName(rowHead);
|
||||
|
||||
Table table = new Table(tableName, comment);
|
||||
List<Table.Column> columns = new ArrayList<>();
|
||||
list.forEach(x->{
|
||||
//String name, String type, boolean notNull,String comment
|
||||
Table.Column column = new Table.Column(x.get("field") + "", x.get("cate") + "",
|
||||
ICreator.isMust(x), x.get("remark1") + "");
|
||||
columns.add(column);
|
||||
});
|
||||
|
||||
table.setColumns(columns);
|
||||
return table;
|
||||
}
|
||||
|
||||
public static String getTableName(Map rowHead) {
|
||||
String field = rowHead.get("field")+"";
|
||||
|
||||
int s = field.indexOf("(");
|
||||
if (s > 0){
|
||||
return field.substring(0, s);
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
|
||||
public static String getComment(Map rowHead){
|
||||
String field = rowHead.get("field")+"";
|
||||
|
||||
int s = field.indexOf("(");
|
||||
int e = field.indexOf(")");
|
||||
if (s > 0){
|
||||
return field.substring(s+1, e > 0 ? e : field.length());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
85
src/com/eversec/kit/dev/MetaTable.java
Normal file
85
src/com/eversec/kit/dev/MetaTable.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.eversec.kit.dev;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*
|
||||
* @author: liangxianyou at 2018/10/17 12:58.
|
||||
*/
|
||||
public class MetaTable {
|
||||
private String name;
|
||||
private String title;
|
||||
private String url;
|
||||
private List<Map> items;
|
||||
private List<String> shows;
|
||||
private List<String> edits;
|
||||
private List<Map> filters;
|
||||
|
||||
public void getTableCfg() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//=============== getter/setter ============
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public List<Map> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Map> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public List<String> getShows() {
|
||||
return shows;
|
||||
}
|
||||
|
||||
public void setShows(List<String> shows) {
|
||||
this.shows = shows;
|
||||
}
|
||||
|
||||
public List<String> getEdits() {
|
||||
return edits;
|
||||
}
|
||||
|
||||
public void setEdits(List<String> edits) {
|
||||
this.edits = edits;
|
||||
}
|
||||
|
||||
public List<Map> getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
public void setFilters(List<Map> filters) {
|
||||
this.filters = filters;
|
||||
}
|
||||
}
|
124
src/com/eversec/kit/dev/ProjectBuiler.java
Normal file
124
src/com/eversec/kit/dev/ProjectBuiler.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package com.eversec.kit.dev;
|
||||
|
||||
import com.eversec.common.FileKit;
|
||||
import com.jfinal.kit.Kv;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class ProjectBuiler {
|
||||
public static String clazzRoot = FileKit.rootPath(ProjectBuiler.class);
|
||||
|
||||
private static Kv kv = Kv.create();//准备用来渲染的基础数据
|
||||
|
||||
static {
|
||||
Properties prop = new Properties();
|
||||
try {
|
||||
prop.load(new FileInputStream(new File(clazzRoot + "conf/builer.txt")));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
prop.forEach((k,v) -> {
|
||||
kv.put(k, v);
|
||||
});
|
||||
}
|
||||
|
||||
private static List<String> tpl = asList(".png", ".jpg", ".jpeg",
|
||||
".npmignore",".js", ".ico", "package.json",".md");
|
||||
|
||||
public static boolean endWith(String str) {
|
||||
return tpl.stream().filter(x -> str.endsWith(x)).count() > 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAbc() throws IOException {
|
||||
ZipFile zipFile = new ZipFile(new File(clazzRoot + "doc/abc-front.zip"));
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
CountDownLatch latch = new CountDownLatch(4979);
|
||||
|
||||
List<ZipEntry> files = new ArrayList<>();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry zipEntry = entries.nextElement();
|
||||
files.add(zipEntry);
|
||||
}
|
||||
|
||||
int n = 30;
|
||||
for (int i = 0; i < files.size() / n + 1; i++) {
|
||||
new Thread() {
|
||||
int i;
|
||||
CountDownLatch latch;
|
||||
public synchronized void start(int i, CountDownLatch latch) {
|
||||
this.i = i;
|
||||
this.latch = latch;
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
files.subList(n * i, Math.min(n * (i + 1), files.size())).forEach(zipEntry -> {
|
||||
try {
|
||||
builerFile(zipFile, zipEntry, latch);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}.start(i, latch);
|
||||
}
|
||||
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
/*//依次遍历
|
||||
while (entries.hasMoreElements()){
|
||||
ZipEntry zipEntry = entries.nextElement();
|
||||
builer(zipFile, zipEntry, latch);
|
||||
}*/
|
||||
|
||||
System.out.println("文件总数:" + files.size() + "" + " 耗时:"
|
||||
+ (System.currentTimeMillis() - start) + "ms");
|
||||
}
|
||||
|
||||
/*11新语法,修改了,慎用。。*/
|
||||
public void builerFile(ZipFile zipFile, ZipEntry zipEntry, CountDownLatch latch) throws IOException {
|
||||
|
||||
do {
|
||||
InputStream is = zipFile.getInputStream(zipEntry);
|
||||
|
||||
File file = new File("target/pname/" + zipEntry.getName());
|
||||
System.out.println("latchCount:" + latch.getCount()/* +"--------" +zipEntry.getName()+ "----------"*/);
|
||||
if (zipEntry.isDirectory()) {
|
||||
file.mkdirs();
|
||||
latch.countDown();
|
||||
continue;
|
||||
}
|
||||
if (true || endWith(file.getName())) {
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(is.read(new byte[1024]));
|
||||
fos.close();
|
||||
latch.countDown();
|
||||
continue;
|
||||
}
|
||||
|
||||
String str = FileKit.readAll(is);
|
||||
FileKit.tplRender(str, file, kv);
|
||||
} while (false);
|
||||
}
|
||||
|
||||
}
|
106
src/com/eversec/kit/dev/Table.java
Normal file
106
src/com/eversec/kit/dev/Table.java
Normal file
@@ -0,0 +1,106 @@
|
||||
package com.eversec.kit.dev;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据库表.
|
||||
* @author: liangxianyou at 2018/10/8 10:58.
|
||||
*/
|
||||
public class Table {
|
||||
private String name; //表名称
|
||||
private String comment; //表备注
|
||||
private List<Column> columns; //表的字段列
|
||||
|
||||
/*public Table(Object o) {
|
||||
|
||||
}*/
|
||||
|
||||
public Table(String name, String comment) {
|
||||
this.name = name;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public List<Column> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(List<Column> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库表的列
|
||||
* @author: liangxianyou at 2018/10/8 10:59.
|
||||
*/
|
||||
public static class Column {
|
||||
private String name; //列名称
|
||||
private String type; //列类型
|
||||
private boolean notNull; //不为null
|
||||
private String comment; //列说明
|
||||
|
||||
public Column() {
|
||||
}
|
||||
|
||||
public Column(String name, String type, boolean notNull,String comment) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.notNull = notNull;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean getNotNull() {
|
||||
return notNull;
|
||||
}
|
||||
|
||||
public void setNotNull(boolean notNull) {
|
||||
this.notNull = notNull;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
}
|
||||
}
|
4
src/com/eversec/kit/package-info.java
Normal file
4
src/com/eversec/kit/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.eversec.kit;
|
||||
/**
|
||||
代码构建工具
|
||||
*/
|
55
src/com/eversec/service/AbcService.java
Normal file
55
src/com/eversec/service/AbcService.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.eversec.service;
|
||||
|
||||
import com.eversec.common.JBean;
|
||||
import com.eversec.kit.creator.Runner;
|
||||
import com.lxyer.excel.poi.ExcelKit;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
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.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2019/2/21 11:08.
|
||||
*/
|
||||
@RestService(name = "abc", automapping = true)
|
||||
public class AbcService extends BaseService {
|
||||
|
||||
@RestMapping(name = "sheets", comment = "得到所有的sheetName")
|
||||
public List<String> sheets(String fileName) {
|
||||
List<String> sheets = new ArrayList<>();
|
||||
try {
|
||||
File file = new File(apphome, "upload/" + fileName);
|
||||
if(file.exists()) {
|
||||
sheets = ExcelKit.getSheetNames(file);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return sheets.stream().filter(x -> {
|
||||
return !x.contains("版本记录") && !x.contains("表说明") && !x.contains("表名称");
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@RestMapping(name = "creater", comment = "构建代码")
|
||||
public JBean creater(CfgBean cfgBean) {
|
||||
JBean jBean = new JBean();
|
||||
try {
|
||||
cfgBean.setXlsPath(new File(apphome, "upload/" + cfgBean.getFileName()).getPath());
|
||||
cfgBean.appHome = apphome.getPath();
|
||||
|
||||
String res = Runner.run(cfgBean);
|
||||
res = res.replace("\n", "<br>").replace("\t", " ");
|
||||
jBean.setBody(res);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
jBean.set(-1, e.getMessage());
|
||||
}
|
||||
|
||||
return jBean;
|
||||
}
|
||||
}
|
93
src/com/eversec/service/BaseService.java
Normal file
93
src/com/eversec/service/BaseService.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package com.eversec.service;
|
||||
|
||||
import com.arangodb.Predicate;
|
||||
import com.google.gson.Gson;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.CacheSource;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/10/22 11:49.
|
||||
*/
|
||||
public class BaseService implements Service {
|
||||
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
protected File webroot;
|
||||
@Resource(name = "APP_HOME")
|
||||
protected File apphome;
|
||||
|
||||
public static Gson gson = new Gson();
|
||||
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
public static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||
public static boolean isWinos = System.getProperty("os.name").contains("Window");
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
@Resource(name = "cacheSource")
|
||||
protected CacheSource cacheSource;
|
||||
|
||||
@Resource(name = "APP_HOME")
|
||||
protected File APP_HOME;
|
||||
|
||||
public static Properties prop = new Properties();
|
||||
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
try {
|
||||
File file = new File(APP_HOME.toPath() + "/conf/config.txt");
|
||||
if (file.exists()) {
|
||||
prop.load(new FileInputStream(file));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public <T> T getT(String key, Class<T> clazz, Supplier<T> supplier) {
|
||||
Object obj = cacheSource.getAndRefresh(key, 1000 * 60 * 3, clazz);
|
||||
if (obj != null) {
|
||||
return (T) obj;
|
||||
}
|
||||
|
||||
T t = supplier.get();
|
||||
if (t != null) {
|
||||
cacheSource.set(1000 * 60 * 3, key, clazz, t);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public String getProperty(String k, String defaultValue){
|
||||
return prop.getProperty(k, defaultValue).replace("${APP_HOME}", APP_HOME.getPath());
|
||||
}
|
||||
@RestMapping(ignore = true)
|
||||
public String getProperty(String k){
|
||||
return prop.getProperty(k);
|
||||
}
|
||||
|
||||
}
|
85
src/com/eversec/service/BaseServlet.java
Normal file
85
src/com/eversec/service/BaseServlet.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.eversec.service;
|
||||
|
||||
import com.arangodb.ArangoDBException;
|
||||
import com.eversec.common.Kv;
|
||||
import com.google.gson.Gson;
|
||||
import org.redkale.net.http.HttpRequest;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/11/8 17:05.
|
||||
*/
|
||||
public class BaseServlet extends HttpServlet {
|
||||
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
protected File webroot;
|
||||
@Resource(name = "APP_HOME")
|
||||
protected File apphome;
|
||||
|
||||
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
protected static Gson gson = new Gson();
|
||||
|
||||
@Override
|
||||
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
String sessionid = request.getParameter("token");
|
||||
if (sessionid == null) {
|
||||
sessionid = request.getHeader("token");
|
||||
}
|
||||
if (sessionid == null) {
|
||||
sessionid = request.getSessionid(true);
|
||||
}
|
||||
|
||||
if (sessionid != null) {
|
||||
//User user = userService.current(sessionid);
|
||||
//request.setCurrentUser(user);
|
||||
}
|
||||
|
||||
super.preExecute(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void authenticate(HttpRequest request, HttpResponse response) throws IOException {
|
||||
/* fixme: 权限拦截
|
||||
if (request.currentUser() == null) {
|
||||
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))){
|
||||
response.finish(JBean.by(-2, "未登陆"));
|
||||
}else {
|
||||
response.finish(HttpScope.refer("/user/login.html"));
|
||||
}
|
||||
return;
|
||||
}*/
|
||||
super.authenticate(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
try {
|
||||
super.execute(request, response);
|
||||
} catch (ArangoDBException e) {
|
||||
logger.log(Level.INFO, "arangodb init!", e);
|
||||
//ArangoSource.init();
|
||||
}
|
||||
}
|
||||
|
||||
public Kv getParams(HttpRequest request, String... key) {
|
||||
Kv kv = Kv.of();
|
||||
for (String k : key) {
|
||||
if (k.contains("=")) { //如果没有值使用默认值
|
||||
kv.put(k.split("=")[0], request.getParameter(k.split("=")[0], k.split("=")[1]));
|
||||
continue;
|
||||
} else if (k.contains("<")) { //强制使用"<"右侧的值
|
||||
kv.put(k.split("<")[0], k.split("<")[1]);
|
||||
continue;
|
||||
}
|
||||
kv.put(k, request.getParameter(k));
|
||||
}
|
||||
return kv;
|
||||
}
|
||||
}
|
104
src/com/eversec/service/CfgBean.java
Normal file
104
src/com/eversec/service/CfgBean.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package com.eversec.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 代码构建配置对象
|
||||
* Created by liangxianyou at 2019/2/26 18:04.
|
||||
*/
|
||||
public class CfgBean {
|
||||
public static String appHome;
|
||||
//cfgBean={fileName:"table.xls",dirPath:"D:/wk/abc/src/main/",pageDirPath:"D:/wk/abc-front/app/src/modules/",pkg:"com.eversec.ac",pageModel:"",author:"",sheetNames:[""]}
|
||||
|
||||
private String fileName;
|
||||
private String xlsPath;
|
||||
|
||||
private String tplPath = "${APP_HOME}/tpl/";
|
||||
private String dirPath;
|
||||
private String pageDirPath;
|
||||
private String pkg;
|
||||
private String pageModel;
|
||||
private String author;
|
||||
private List<String> ca;
|
||||
private List<String> sheetNames;
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getXlsPath() {
|
||||
return xlsPath;
|
||||
}
|
||||
|
||||
public void setXlsPath(String xlsPath) {
|
||||
this.xlsPath = xlsPath;
|
||||
}
|
||||
|
||||
public String getTplPath() {
|
||||
return tplPath.replace("${APP_HOME}", appHome);
|
||||
}
|
||||
|
||||
public void setTplPath(String tplPath) {
|
||||
this.tplPath = tplPath;
|
||||
}
|
||||
|
||||
public String getDirPath() {
|
||||
return dirPath;
|
||||
}
|
||||
|
||||
public void setDirPath(String dirPath) {
|
||||
this.dirPath = dirPath;
|
||||
}
|
||||
|
||||
public String getPageDirPath() {
|
||||
return pageDirPath;
|
||||
}
|
||||
|
||||
public void setPageDirPath(String pageDirPath) {
|
||||
this.pageDirPath = pageDirPath;
|
||||
}
|
||||
|
||||
public String getPkg() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
public void setPkg(String pkg) {
|
||||
this.pkg = pkg;
|
||||
}
|
||||
|
||||
public String getPageModel() {
|
||||
return pageModel;
|
||||
}
|
||||
|
||||
public void setPageModel(String pageModel) {
|
||||
this.pageModel = pageModel;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public List<String> getCa() {
|
||||
return ca;
|
||||
}
|
||||
|
||||
public void setCa(List<String> ca) {
|
||||
this.ca = ca;
|
||||
}
|
||||
|
||||
public List<String> getSheetNames() {
|
||||
return sheetNames;
|
||||
}
|
||||
|
||||
public void setSheetNames(List<String> sheetNames) {
|
||||
this.sheetNames = sheetNames;
|
||||
}
|
||||
}
|
73
src/com/eversec/service/UploadServlet.java
Normal file
73
src/com/eversec/service/UploadServlet.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package com.eversec.service;
|
||||
|
||||
import com.eversec.common.Kv;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2019/2/21 11:06.
|
||||
*/
|
||||
@WebServlet(value = {"upload", "/upload/*"}, comment = "文件管理入口")
|
||||
public class UploadServlet extends BaseServlet {
|
||||
|
||||
@HttpMapping(url = "/upload/excel", auth = false, comment = "Execel上传")
|
||||
public void uploadExcel(HttpRequest request, HttpResponse response) {
|
||||
try {
|
||||
for (MultiPart part : request.multiParts()) {
|
||||
File destFile = new File(apphome, "upload/" + part.getFilename());
|
||||
destFile.getParentFile().mkdir();
|
||||
part.save(destFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
response.finish("");
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/upload/files", auth = false, comment = "已经上传文件的列表")
|
||||
public void uploadFiles(HttpRequest request, HttpResponse response) {
|
||||
List<Kv> list = new ArrayList();
|
||||
|
||||
File dir = new File(apphome, "upload");
|
||||
if (dir.exists() && dir.isDirectory()) {
|
||||
for (File file : dir.listFiles()) {
|
||||
list.add(
|
||||
Kv.of("name", file.getName())
|
||||
.set("size", file.length())
|
||||
.set("modified", file.lastModified())
|
||||
);
|
||||
}
|
||||
list = list.stream().sorted(Comparator.comparing(x -> Long.parseLong(x.get("modified") + ""))).collect(Collectors.toList());
|
||||
}
|
||||
response.finish(list);
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/upload/del", auth = false, comment = "删除文件")
|
||||
public void uploadDel(HttpRequest request, HttpResponse response) {
|
||||
String fileName = request.getParameter("fileName");
|
||||
File file = new File(apphome, "upload/" + fileName);
|
||||
if (file.exists()) {
|
||||
File target = new File(apphome, "upload_back/" + fileName);
|
||||
try {
|
||||
target.getParentFile().mkdirs();
|
||||
Files.move(file.toPath(), target.toPath(), new StandardCopyOption[]{StandardCopyOption.REPLACE_EXISTING});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
response.finish("");
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user