.
This commit is contained in:
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;
|
||||
/**
|
||||
代码构建工具
|
||||
*/
|
Reference in New Issue
Block a user