|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package com.dsideal.Tools;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.util.RuntimeUtil;
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import com.dsideal.Utils.dsKit;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
@ -54,7 +53,9 @@ public class GenerateCode {
|
|
|
|
|
//表结构的描述JSON对象
|
|
|
|
|
JSONObject jo = new JSONObject();
|
|
|
|
|
//字段,不包含主键
|
|
|
|
|
Map<String, String> map = new LinkedHashMap<>();
|
|
|
|
|
Map<String, String> dataTypeMap = new LinkedHashMap<>();
|
|
|
|
|
//字段描述
|
|
|
|
|
Map<String, String> commentMap = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
|
|
//表注释
|
|
|
|
|
String comment = "";
|
|
|
|
@ -78,6 +79,8 @@ public class GenerateCode {
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
String Type = rs.getString("Type");
|
|
|
|
|
String Field = rs.getString("Field");
|
|
|
|
|
String Comment = rs.getString("Comment");
|
|
|
|
|
commentMap.put(Field, Comment);
|
|
|
|
|
fields.add(Field);
|
|
|
|
|
|
|
|
|
|
if (Type.contains("(")) {
|
|
|
|
@ -88,15 +91,16 @@ public class GenerateCode {
|
|
|
|
|
//记录主键
|
|
|
|
|
if (rs.getString("Key").equals("PRI")) {
|
|
|
|
|
jo.put("key", Field);
|
|
|
|
|
jo.put("key_type", dataTypeMap.get(Type));
|
|
|
|
|
jo.put("key_type", GenerateCode.dataTypeMap.get(Type));
|
|
|
|
|
} else {//否则记录到map中
|
|
|
|
|
map.put(Field, dataTypeMap.get(Type));
|
|
|
|
|
dataTypeMap.put(Field, GenerateCode.dataTypeMap.get(Type));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//关闭连接
|
|
|
|
|
rs.close();
|
|
|
|
|
stmt.close();
|
|
|
|
|
jo.put("fields", map);
|
|
|
|
|
jo.put("fields", dataTypeMap);
|
|
|
|
|
jo.put("fieldsComment", commentMap);
|
|
|
|
|
jo.put("beanNameWithoutT", beanNameWithoutT);
|
|
|
|
|
jo.put("comment", comment);
|
|
|
|
|
jo.put("table", table);
|
|
|
|
@ -192,6 +196,8 @@ public class GenerateCode {
|
|
|
|
|
//不带主键的其它字段,拼接成java的函数声明内容
|
|
|
|
|
// 迭代map将按照插入顺序
|
|
|
|
|
Map<String, String> fields = (Map<String, String>) jo.get("fields");
|
|
|
|
|
Map<String, String> fieldsComment = (Map<String, String>) jo.get("fieldsComment");
|
|
|
|
|
|
|
|
|
|
String fullParameters = "";//带数据类型+字段名称
|
|
|
|
|
String parameters = "";//不带数据类型,只有字段名称
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
@ -228,7 +234,15 @@ public class GenerateCode {
|
|
|
|
|
sb.append("/* 下面代码开始维护" + comment + " */\n");
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
//1、增加
|
|
|
|
|
sb.append(" //增加" + comment + "\n");
|
|
|
|
|
sb.append(" /**增加" + comment + "\n");
|
|
|
|
|
sb.append(" *\n");
|
|
|
|
|
//迭代
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
|
if (!entry.getKey().equals("create_time")) {
|
|
|
|
|
sb.append(" * @param " + entry.getKey() + " " + fieldsComment.get(entry.getKey()) + "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.append(" */\n");
|
|
|
|
|
sb.append(" @Before({POST.class})\n");
|
|
|
|
|
sb.append(" //@JwtCheckInterface({})\n");
|
|
|
|
|
sb.append(" //@EmptyInterface({\"\"})\n");
|
|
|
|
@ -252,7 +266,15 @@ public class GenerateCode {
|
|
|
|
|
|
|
|
|
|
//3、修改
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
sb.append(" //按ID修改" + comment + "\n");
|
|
|
|
|
sb.append(" /**按ID修改" + comment + "\n");
|
|
|
|
|
sb.append(" *\n");
|
|
|
|
|
//迭代
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
|
if (!entry.getKey().equals("create_time")) {
|
|
|
|
|
sb.append(" * @param " + entry.getKey() + " " + fieldsComment.get(entry.getKey()) + "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.append(" */\n");
|
|
|
|
|
sb.append(" @Before({POST.class})\n");
|
|
|
|
|
sb.append(" //@JwtCheckInterface({})\n");
|
|
|
|
|
sb.append(" //@EmptyInterface({\"\"})\n");
|
|
|
|
@ -292,7 +314,15 @@ public class GenerateCode {
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
//1、增加
|
|
|
|
|
sb.append(" //增加" + comment + "\n");
|
|
|
|
|
sb.append(" /**增加" + comment + "\n");
|
|
|
|
|
sb.append(" *\n");
|
|
|
|
|
//迭代
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
|
if (!entry.getKey().equals("create_time")) {
|
|
|
|
|
sb.append(" * @param " + entry.getKey() + " " + fieldsComment.get(entry.getKey()) + "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.append(" */\n");
|
|
|
|
|
sb.append(" public void add" + beanNameWithoutT + "(" + fullParameters + "){\n");
|
|
|
|
|
sb.append(" Record record = new Record();\n");
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
@ -314,7 +344,16 @@ public class GenerateCode {
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
|
|
|
|
|
//3、修改
|
|
|
|
|
sb.append(" //修改" + comment + "\n");
|
|
|
|
|
sb.append(" /**修改" + comment + "\n");
|
|
|
|
|
sb.append(" *\n");
|
|
|
|
|
//迭代
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
|
if (!entry.getKey().equals("create_time")) {
|
|
|
|
|
sb.append(" * @param " + entry.getKey() + " " + fieldsComment.get(entry.getKey()) + "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.append(" */\n");
|
|
|
|
|
|
|
|
|
|
sb.append(" public void update" + beanNameWithoutT + "ById(" + key_type + " " + key + "," + fullParameters + "){\n");
|
|
|
|
|
sb.append(" String sql=\"update " + table + " set ");
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
@ -328,7 +367,7 @@ public class GenerateCode {
|
|
|
|
|
sb.append(" where " + key + "=?\";\n");
|
|
|
|
|
sb.append(" Db.update(sql,");
|
|
|
|
|
for (Map.Entry<String, String> entry : fields.entrySet()) {
|
|
|
|
|
if(!entry.getKey().equals("create_time")){
|
|
|
|
|
if (!entry.getKey().equals("create_time")) {
|
|
|
|
|
sb.append(entry.getKey() + " , ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|