From cc6e055487620ff1827184e8600fa504b82a9f23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com>
Date: Mon, 14 Oct 2024 20:39:36 +0800
Subject: [PATCH] 'commit'
---
dsBuild/src/main/java/Util/PublishUtil.java | 27 +-
dsUtils/pom.xml | 8 +
.../dsideal/Code/WxFaultTypeController.txt | 50 --
.../com/dsideal/Code/WxFaultTypeModel.txt | 38 --
.../com/dsideal/Code/WxRecordController.txt | 76 ---
.../java/com/dsideal/Code/WxRecordModel.txt | 69 ---
.../java/com/dsideal/Tools/FreeMarker.java | 22 +
.../Tools/GenerateCodeWithFreeMaker.java | 473 ++++++++++++++++++
dsUtils/src/main/resources/Controller.ftl | 12 +
dsUtils/src/main/resources/Model.ftl | 7 +
dsUtils/src/main/resources/users.ftl | 7 +
dsUtils/target/classes/Controller.ftl | 12 +
dsUtils/target/classes/Model.ftl | 7 +
dsUtils/target/classes/users.ftl | 7 +
output_users.html | 14 +
15 files changed, 593 insertions(+), 236 deletions(-)
delete mode 100644 dsUtils/src/main/java/com/dsideal/Code/WxFaultTypeController.txt
delete mode 100644 dsUtils/src/main/java/com/dsideal/Code/WxFaultTypeModel.txt
delete mode 100644 dsUtils/src/main/java/com/dsideal/Code/WxRecordController.txt
delete mode 100644 dsUtils/src/main/java/com/dsideal/Code/WxRecordModel.txt
create mode 100644 dsUtils/src/main/java/com/dsideal/Tools/FreeMarker.java
create mode 100644 dsUtils/src/main/java/com/dsideal/Tools/GenerateCodeWithFreeMaker.java
create mode 100644 dsUtils/src/main/resources/Controller.ftl
create mode 100644 dsUtils/src/main/resources/Model.ftl
create mode 100644 dsUtils/src/main/resources/users.ftl
create mode 100644 dsUtils/target/classes/Controller.ftl
create mode 100644 dsUtils/target/classes/Model.ftl
create mode 100644 dsUtils/target/classes/users.ftl
create mode 100644 output_users.html
diff --git a/dsBuild/src/main/java/Util/PublishUtil.java b/dsBuild/src/main/java/Util/PublishUtil.java
index 92ee4a47..ddd07fc0 100644
--- a/dsBuild/src/main/java/Util/PublishUtil.java
+++ b/dsBuild/src/main/java/Util/PublishUtil.java
@@ -7,15 +7,31 @@ import com.jfinal.kit.Kv;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
-import java.io.FilenameFilter;
public class PublishUtil {
+ /**
+ * 功能:执行批处理命令
+ *
+ * @param path
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public static void ExecBatchCmd(String path) throws IOException, InterruptedException {
+ String[] cmd = {path};
+ Process process = Runtime.getRuntime().exec(cmd);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ System.out.println(line);
+ }
+ process.waitFor();
+ }
+
public static void doLogin(SSHUtil ssh, String username, String password) throws Exception {
String cmd = "docker login --username=" + username + " --password=" + password + " registry.cn-hangzhou.aliyuncs.com";
ssh.exec(cmd);
@@ -48,6 +64,11 @@ public class PublishUtil {
* docker push registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
*/
public static Kv publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
+ //判断是不是有需要批处理的生成JAR的过程
+ String cmdPath = workingPath + "生成依赖jar.bat";
+ if (FileUtil.exist(cmdPath)) {
+ ExecBatchCmd(cmdPath);
+ }
System.out.println("正在生成" + projectName + "的镜像...");
//配置文件
String path = PathKit.getRootClassPath() + "\\publishImage.json";
diff --git a/dsUtils/pom.xml b/dsUtils/pom.xml
index f4996685..fecf78c6 100644
--- a/dsUtils/pom.xml
+++ b/dsUtils/pom.xml
@@ -48,6 +48,14 @@
mysql-connector-java
${mysql.version}
+
+
+
+ org.freemarker
+ freemarker
+ 2.3.33
+
+
ch.qos.logback
diff --git a/dsUtils/src/main/java/com/dsideal/Code/WxFaultTypeController.txt b/dsUtils/src/main/java/com/dsideal/Code/WxFaultTypeController.txt
deleted file mode 100644
index 06fbba0a..00000000
--- a/dsUtils/src/main/java/com/dsideal/Code/WxFaultTypeController.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-/* 下面代码开始维护 */
-
- /**增加
- *
- * @param type_name 类型名称
- */
- @Before({POST.class})
- @JwtCheckInterface({})
- public void addWxFaultType(String type_name ){
- ym.addWxFaultType(type_name );
- renderJson(RetKit.renderSuccess());
- }
-
- //按ID删除
- @Before({POST.class})
- @JwtCheckInterface({})
- @IsNumericInterface({"type_id"})
- public void delWxFaultTypeById(int type_id){
- ym.delWxFaultTypeById(type_id);
- renderJson(RetKit.renderSuccess());
- }
-
- /**按ID修改
- *
- * @param type_name 类型名称
- */
- @Before({POST.class})
- @JwtCheckInterface({})
- //@IsNumericInterface({"type_id"})
- public void updateWxFaultTypeById(int type_id,String type_name ){
- ym.updateWxFaultTypeById(type_id,type_name );
- renderJson(RetKit.renderSuccess());
- }
-
- //按ID查询
- @Before({GET.class})
- @JwtCheckInterface({})
- @IsNumericInterface({"type_id"})
- public void getWxFaultTypeById(int type_id){
- renderJson(RetKit.renderSuccess(ym.getWxFaultTypeById(type_id)));
- }
-
- //分页查询
- @Before({GET.class})
- @JwtCheckInterface({})
- public void getWxFaultTypeList(int pageNum, int pageSize){
- Page listPage = ym.getWxFaultTypeList(pageNum, pageSize);
- renderJson(RetKit.renderSuccess(listPage));
- }
-
diff --git a/dsUtils/src/main/java/com/dsideal/Code/WxFaultTypeModel.txt b/dsUtils/src/main/java/com/dsideal/Code/WxFaultTypeModel.txt
deleted file mode 100644
index 2b48d9b2..00000000
--- a/dsUtils/src/main/java/com/dsideal/Code/WxFaultTypeModel.txt
+++ /dev/null
@@ -1,38 +0,0 @@
- /**增加
- *
- * @param type_name 类型名称
- */
- public void addWxFaultType(String type_name ){
- Record record = new Record();
- record.set("type_name",type_name);
- Db.save("t_wx_fault_type","type_id",record);
-}
-
- //删除
- public void delWxFaultTypeById(int type_id){
- String sql="delete from t_wx_fault_type where type_id=?";
- Db.update(sql,type_id);
- }
-
- /**修改
- *
- * @param type_name 类型名称
- */
- public void updateWxFaultTypeById(int type_id,String type_name ){
- String sql="update t_wx_fault_type set type_name= ? where type_id=?";
- Db.update(sql,type_name , type_id);
- }
-
- //单条查询
- public Record getWxFaultTypeById(int type_id){
- String sql="select * from t_wx_fault_type where type_id=?";
- return Db.findFirst(sql,type_id);
- }
-
- //分页查询
- public Page getWxFaultTypeList(int pageNum, int pageSize){
- String sql1="select * ";
- String sql2=" from t_wx_fault_type ";
- return Db.paginate(pageNum, pageSize, sql1,sql2);
- }
-
diff --git a/dsUtils/src/main/java/com/dsideal/Code/WxRecordController.txt b/dsUtils/src/main/java/com/dsideal/Code/WxRecordController.txt
deleted file mode 100644
index 41e83d58..00000000
--- a/dsUtils/src/main/java/com/dsideal/Code/WxRecordController.txt
+++ /dev/null
@@ -1,76 +0,0 @@
-/* 下面代码开始维护维修记录表 */
-
- /**增加维修记录表
- *
- * @param station_id 场站ID
- * @param station_name 场站名称
- * @param equipmentId 桩ID
- * @param equipmentName 桩名称
- * @param connectorId 枪ID
- * @param connectorNo 枪名称
- * @param wx_openid 维修人员的微信open_id
- * @param status_id 维修单状态: 1:正在维修,2:维修完成,3:无法维修
- * @param type_id 故障类型id
- * @param type_name 故障类型名称
- * @param memo 维修情况说明
- */
- @Before({POST.class})
- //@JwtCheckInterface({})
- //@EmptyInterface({""})
- //@IsNumericInterface({})
- public void addWxRecord(int station_id , String station_name , int equipmentId , String equipmentName , int connectorId , String connectorNo , String wx_openid , int status_id , int type_id , String type_name , String memo ){
- ym.addWxRecord(station_id , station_name , equipmentId , equipmentName , connectorId , connectorNo , wx_openid , status_id , type_id , type_name , memo );
- renderJson(RetKit.renderSuccess());
- }
-
- //按ID删除维修记录表
- @Before({POST.class})
- //@JwtCheckInterface({})
- //@EmptyInterface({""})
- //@IsNumericInterface({"id"})
- public void delWxRecordById(int id){
- ym.delWxRecordById(id);
- renderJson(RetKit.renderSuccess());
- }
-
- /**按ID修改维修记录表
- *
- * @param station_id 场站ID
- * @param station_name 场站名称
- * @param equipmentId 桩ID
- * @param equipmentName 桩名称
- * @param connectorId 枪ID
- * @param connectorNo 枪名称
- * @param wx_openid 维修人员的微信open_id
- * @param status_id 维修单状态: 1:正在维修,2:维修完成,3:无法维修
- * @param type_id 故障类型id
- * @param type_name 故障类型名称
- * @param memo 维修情况说明
- */
- @Before({POST.class})
- //@JwtCheckInterface({})
- //@EmptyInterface({""})
- //@IsNumericInterface({"id"})
- public void updateWxRecordById(int id,int station_id , String station_name , int equipmentId , String equipmentName , int connectorId , String connectorNo , String wx_openid , int status_id , int type_id , String type_name , String memo ){
- ym.updateWxRecordById(id,station_id , station_name , equipmentId , equipmentName , connectorId , connectorNo , wx_openid , status_id , type_id , type_name , memo );
- renderJson(RetKit.renderSuccess());
- }
-
- //按ID查询维修记录表
- @Before({GET.class})
- //@JwtCheckInterface({})
- //@EmptyInterface({""})
- //@IsNumericInterface({"id"})
- public void getWxRecordById(int id){
- renderJson(RetKit.renderSuccess(ym.getWxRecordById(id)));
- }
-
- //分页查询维修记录表
- @Before({GET.class})
- //@JwtCheckInterface({})
- //@EmptyInterface({""})
- public void getWxRecordList(int pageNum, int pageSize){
- Page listPage = ym.getWxRecordList(pageNum, pageSize);
- renderJson(RetKit.renderSuccess(listPage));
- }
-
diff --git a/dsUtils/src/main/java/com/dsideal/Code/WxRecordModel.txt b/dsUtils/src/main/java/com/dsideal/Code/WxRecordModel.txt
deleted file mode 100644
index 5e7fa68f..00000000
--- a/dsUtils/src/main/java/com/dsideal/Code/WxRecordModel.txt
+++ /dev/null
@@ -1,69 +0,0 @@
- /**增加维修记录表
- *
- * @param station_id 场站ID
- * @param station_name 场站名称
- * @param equipmentId 桩ID
- * @param equipmentName 桩名称
- * @param connectorId 枪ID
- * @param connectorNo 枪名称
- * @param wx_openid 维修人员的微信open_id
- * @param status_id 维修单状态: 1:正在维修,2:维修完成,3:无法维修
- * @param type_id 故障类型id
- * @param type_name 故障类型名称
- * @param memo 维修情况说明
- */
- public void addWxRecord(int station_id , String station_name , int equipmentId , String equipmentName , int connectorId , String connectorNo , String wx_openid , int status_id , int type_id , String type_name , String memo ){
- Record record = new Record();
- record.set("station_id",station_id);
- record.set("station_name",station_name);
- record.set("equipmentId",equipmentId);
- record.set("equipmentName",equipmentName);
- record.set("connectorId",connectorId);
- record.set("connectorNo",connectorNo);
- record.set("wx_openid",wx_openid);
- record.set("status_id",status_id);
- record.set("create_time", DateTime.now());
- record.set("type_id",type_id);
- record.set("type_name",type_name);
- record.set("memo",memo);
- Db.save("t_wx_record","id",record);
-}
-
- //删除维修记录表
- public void delWxRecordById(int id){
- String sql="delete from t_wx_record where id=?";
- Db.update(sql,id);
- }
-
- /**修改维修记录表
- *
- * @param station_id 场站ID
- * @param station_name 场站名称
- * @param equipmentId 桩ID
- * @param equipmentName 桩名称
- * @param connectorId 枪ID
- * @param connectorNo 枪名称
- * @param wx_openid 维修人员的微信open_id
- * @param status_id 维修单状态: 1:正在维修,2:维修完成,3:无法维修
- * @param type_id 故障类型id
- * @param type_name 故障类型名称
- * @param memo 维修情况说明
- */
- public void updateWxRecordById(int id,int station_id , String station_name , int equipmentId , String equipmentName , int connectorId , String connectorNo , String wx_openid , int status_id , int type_id , String type_name , String memo ){
- String sql="update t_wx_record set station_id= ?,station_name= ?,equipmentId= ?,equipmentName= ?,connectorId= ?,connectorNo= ?,wx_openid= ?,status_id= ?,create_time= DateTime.now(),type_id= ?,type_name= ?,memo= ? where id=?";
- Db.update(sql,station_id , station_name , equipmentId , equipmentName , connectorId , connectorNo , wx_openid , status_id , type_id , type_name , memo , id);
- }
-
- //单条查询维修记录表
- public Record getWxRecordById(int id){
- String sql="select * from t_wx_record where id=?";
- return Db.findFirst(sql,id);
- }
-
- //分页查询维修记录表
- public Page getWxRecordList(int pageNum, int pageSize){
- String sql1="select * ";
- String sql2="fromt_wx_record ";
- return Db.paginate(pageNum, pageSize, sql1,sql2);
- }
-
diff --git a/dsUtils/src/main/java/com/dsideal/Tools/FreeMarker.java b/dsUtils/src/main/java/com/dsideal/Tools/FreeMarker.java
new file mode 100644
index 00000000..dc8d5f83
--- /dev/null
+++ b/dsUtils/src/main/java/com/dsideal/Tools/FreeMarker.java
@@ -0,0 +1,22 @@
+package com.dsideal.Tools;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.Version;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class FreeMarker {
+ public static void main(String[] args) throws IOException, TemplateException {
+
+
+ }
+}
\ No newline at end of file
diff --git a/dsUtils/src/main/java/com/dsideal/Tools/GenerateCodeWithFreeMaker.java b/dsUtils/src/main/java/com/dsideal/Tools/GenerateCodeWithFreeMaker.java
new file mode 100644
index 00000000..a20bb025
--- /dev/null
+++ b/dsUtils/src/main/java/com/dsideal/Tools/GenerateCodeWithFreeMaker.java
@@ -0,0 +1,473 @@
+package com.dsideal.Tools;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.json.JSONObject;
+import com.dsideal.Utils.dsKit;
+import com.jfinal.kit.PropKit;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
+import com.jfinal.plugin.hikaricp.HikariCpPlugin;
+
+import javax.sql.DataSource;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.*;
+
+import com.jfinal.plugin.activerecord.Record;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.Version;
+
+public class GenerateCodeWithFreeMaker {
+
+ // JavaBean保存的位置
+ public static String beanPath;
+
+ // mysql与java的数据类型映射
+ public static Map dataTypeMap = new HashMap<>();
+
+ /**
+ * 获取当前数据库下的表
+ *
+ * @return List
+ * @throws Exception
+ */
+ public static List getTableNames(Connection conn) throws Exception {
+ List tables = new ArrayList<>();
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("show tables");
+ while (rs.next()) {
+ String tableName = rs.getString(1);
+ if (tableName.equals(PropKit.get("tableName"))) {
+ tables.add(tableName);
+ }
+ }
+ rs.close();
+ stmt.close();
+ return tables;
+ }
+
+
+ /**
+ * 获得某表的注释信息+列信息
+ *
+ * @param table
+ * @return
+ * @throws Exception
+ */
+ public static JSONObject getStructure(Connection conn, String table) throws Exception {
+ //表结构的描述JSON对象
+ JSONObject jo = new JSONObject();
+ //字段,不包含主键
+ Map dataTypeMap = new LinkedHashMap<>();
+ //字段描述
+ Map commentMap = new LinkedHashMap<>();
+
+ //表注释
+ String comment = "";
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("show create table " + table);
+ if (rs != null && rs.next()) {
+ String createDDL = rs.getString(2);
+ int index = createDDL.indexOf("COMMENT='");
+ if (index >= 0) {
+ comment = createDDL.substring(index + 9);
+ comment = comment.substring(0, comment.length() - 1);
+ }
+ }
+ //类名
+ String beanNameWithoutT = dsKit.toCamelCase(dsKit.capitalizeFirstLetter(table));
+
+
+ List fields = new ArrayList<>();
+ //字段信息
+ rs = stmt.executeQuery("show full columns from " + table);
+ 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("(")) {
+ Type = Type.substring(0, Type.indexOf("("));
+ }
+ Type = Type.toUpperCase();
+
+ //记录主键
+ if (rs.getString("Key").equals("PRI")) {
+ jo.put("key", Field);
+ jo.put("key_type", GenerateCodeWithFreeMaker.dataTypeMap.get(Type));
+ } else {//否则记录到map中
+ dataTypeMap.put(Field, GenerateCodeWithFreeMaker.dataTypeMap.get(Type));
+ }
+ }
+ //关闭连接
+ rs.close();
+ stmt.close();
+ jo.put("fields", dataTypeMap);
+ jo.put("fieldsComment", commentMap);
+ jo.put("beanNameWithoutT", beanNameWithoutT);
+ jo.put("comment", comment);
+ jo.put("table", table);
+ return jo;
+ }
+
+ /**
+ * 功能:初始化数据库类型映射
+ */
+ public static void initMap() {
+ //mysql与java的数据类型映射
+ dataTypeMap.put("INT", "int");
+ dataTypeMap.put("BIGINT", "long");
+ dataTypeMap.put("DOUBLE", "double");
+ dataTypeMap.put("FLOAT", "float");
+ dataTypeMap.put("TINYINT", "int");
+ dataTypeMap.put("DATE", "java.util.Date");
+ dataTypeMap.put("TIMESTAMP", "java.util.Date");
+ dataTypeMap.put("BIGINT UNSIGNED", "long");
+ dataTypeMap.put("INT UNSIGNED", "long");
+ dataTypeMap.put("MEDIUMINT", "int");
+ dataTypeMap.put("MEDIUMINT UNSIGNED", "long");
+ dataTypeMap.put("SMALLINT", "int");
+ dataTypeMap.put("SMALLINT UNSIGNED", "long");
+ dataTypeMap.put("TINYINT UNSIGNED", "long");
+ dataTypeMap.put("LONGTEXT", "String");
+ dataTypeMap.put("VARCHAR", "String");
+ dataTypeMap.put("CHAR", "String");
+ dataTypeMap.put("TEXT", "String");
+ dataTypeMap.put("DATETIME", "java.util.Date");
+ dataTypeMap.put("DECIMAL", "BigDecimal");
+ dataTypeMap.put("BOOLEAN", "boolean");
+ }
+
+ public static void main(String[] args) throws Exception {
+ //加载配置文件
+ PropKit.use("application.properties");
+ beanPath = PropKit.get("beanPath");
+ if (!FileUtil.exist(beanPath)) {
+ FileUtil.mkdir(beanPath);
+ }
+ initMap();
+
+ // 配置Druid数据源插件
+ HikariCpPlugin hpPlugin = new HikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
+ PropKit.get("password").trim(), PropKit.get("driverClassName"));
+ hpPlugin.start();
+
+ // 配置ActiveRecord插件
+ ActiveRecordPlugin arp = new ActiveRecordPlugin(hpPlugin);
+ hpPlugin.start();
+ arp.start();
+ DataSource dataSource = hpPlugin.getDataSource();
+ // 数据库连接
+ Connection conn = dataSource.getConnection();
+
+ //开始生成
+ List tables = getTableNames(conn);
+
+ String tableNames = "";
+ //表描述
+ for (String table : tables) {
+ JSONObject jo = getStructure(conn, table);
+ tableNames += table + ",";
+
+ if (StrKit.isBlank(jo.getStr("key"))) {
+ dsKit.print("表" + table + "没有主键,请检查!");
+ }
+ //生成代码
+ autoCodeFreeMaker(jo);
+ }
+ if (StrKit.isBlank(tableNames)) {
+ dsKit.print("没有找到表,请检查!");
+ return;
+ }
+ //去掉最后的逗号
+ tableNames = tableNames.substring(0, tableNames.length() - 1);
+
+ //关闭数据库
+ conn.close();
+ arp.stop();
+ hpPlugin.stop();
+
+ System.out.println(dsKit.getCurrentTimeStr() + " 恭喜,表" + tableNames + "代码已成功生成!");
+ }
+
+ /**
+ * 功能:生成代码
+ *
+ * @param jo
+ */
+ public static void autoCode(JSONObject jo) {
+ //不带主键的其它字段,拼接成java的函数声明内容
+ // 迭代map将按照插入顺序
+ Map fields = (Map) jo.get("fields");
+ Map fieldsComment = (Map) jo.get("fieldsComment");
+
+ String fullParameters = "";//带数据类型+字段名称
+ String parameters = "";//不带数据类型,只有字段名称
+ for (Map.Entry entry : fields.entrySet()) {
+ if (!entry.getKey().equals("create_time") && !entry.getKey().equals("b_use")) {
+ fullParameters += entry.getValue() + " " + entry.getKey() + " , ";//这里必须是反着来的,否则数据类型会重复
+ parameters += entry.getKey() + " , ";
+ }
+ }
+ //移除最后一个逗号
+ fullParameters = fullParameters.substring(0, fullParameters.length() - 1);
+ if (fullParameters.endsWith(",")) {//去掉最后的逗号
+ fullParameters = fullParameters.substring(0, fullParameters.length() - 1);
+ }
+ parameters = parameters.substring(0, parameters.length() - 1);
+ if (parameters.endsWith(",")) {
+ parameters = parameters.substring(0, parameters.length() - 1);
+ }
+ //后缀名称
+ String beanNameWithoutT = jo.getStr("beanNameWithoutT");
+ if (beanNameWithoutT.startsWith("T")) {
+ beanNameWithoutT = beanNameWithoutT.substring(1);
+ }
+ //表的描述
+ String comment = jo.getStr("comment");
+
+ //主键
+ String key = jo.getStr("key");
+ String key_type = jo.getStr("key_type");
+ //表名
+ String table = jo.getStr("table");
+
+ StringBuilder sb = new StringBuilder();
+ //sb.append("//-------------------下面是Controller部分-------------------\n");
+ sb.append("/* 下面代码开始维护" + comment + " */\n");
+ sb.append("\n");
+ //1、增加
+ sb.append(" /**增加" + comment + "\n");
+ sb.append(" *\n");
+ //迭代
+ for (Map.Entry 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(" public void add" + beanNameWithoutT + "(" + fullParameters + "){\n");
+ sb.append(" " + PropKit.get("daoName") + ".add" + beanNameWithoutT + "(" + parameters + ");\n");
+ sb.append(" renderJson(RetKit.renderSuccess());\n");
+ sb.append(" }\n");
+
+ //2、删除
+ sb.append("\n");
+ sb.append(" //按ID删除" + comment + "\n");
+ sb.append(" @Before({POST.class})\n");
+ sb.append(" @JwtCheckInterface({})\n");
+ sb.append(" @IsNumericInterface({\"" + key + "\"})\n");
+ sb.append(" public void del" + beanNameWithoutT + "ById(" + key_type + " " + key + "){\n");
+ sb.append(" " + PropKit.get("daoName") + ".del" + beanNameWithoutT + "ById(" + key + ");\n");
+ sb.append(" renderJson(RetKit.renderSuccess());\n");
+ sb.append(" }\n");
+
+ //3、修改
+ sb.append("\n");
+ sb.append(" /**按ID修改" + comment + "\n");
+ sb.append(" *\n");
+ //迭代
+ for (Map.Entry 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(" //@IsNumericInterface({\"" + key + "\"})\n");
+ sb.append(" public void update" + beanNameWithoutT + "ById(" + key_type + " " + key + "," + fullParameters + "){\n");
+ sb.append(" " + PropKit.get("daoName") + ".update" + beanNameWithoutT + "ById(" + key + "," + parameters + ");\n");
+ sb.append(" renderJson(RetKit.renderSuccess());\n");
+ sb.append(" }\n");
+ sb.append("\n");
+
+ //4、单条查询
+ sb.append(" //按ID查询" + comment + "\n");
+ sb.append(" @Before({GET.class})\n");
+ sb.append(" @JwtCheckInterface({})\n");
+ sb.append(" @IsNumericInterface({\"" + key + "\"})\n");
+ sb.append(" public void get" + beanNameWithoutT + "ById(" + key_type + " " + key + "){\n");
+ sb.append(" renderJson(RetKit.renderSuccess(" + PropKit.get("daoName") + ".get" + beanNameWithoutT + "ById(" + key + ")));\n");
+ sb.append(" }\n");
+ sb.append("\n");
+
+ //5、分页查询
+ sb.append(" //分页查询" + comment + "\n");
+ sb.append(" @Before({GET.class})\n");
+ sb.append(" @JwtCheckInterface({})\n");
+ sb.append(" public void get" + beanNameWithoutT + "List(int pageNum, int pageSize){\n");
+ sb.append(" Page listPage = " + PropKit.get("daoName") + ".get" + beanNameWithoutT + "List(pageNum, pageSize);\n");
+ sb.append(" renderJson(RetKit.renderSuccess(listPage));\n");
+ sb.append(" }\n");
+ sb.append("\n");
+
+ FileUtil.writeUtf8String(sb.toString(), beanPath + "/" + beanNameWithoutT + "Controller.txt");
+
+
+ sb.append("/* 下面代码开始维护" + comment + " */\n");
+ sb.append("\n");
+ sb = new StringBuilder();
+ //1、增加
+ sb.append(" /**增加" + comment + "\n");
+ sb.append(" *\n");
+ //迭代
+ for (Map.Entry 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 entry : fields.entrySet()) {
+ if (!entry.getKey().equals("create_time")) {
+ sb.append(" record.set(\"" + entry.getKey() + "\"," + entry.getKey() + ");\n");
+ } else {
+ sb.append(" record.set(\"" + entry.getKey() + "\", DateTime.now());\n");
+ }
+ }
+ sb.append(" Db.save(\"" + table + "\",\"" + key + "\",record);\n");
+ sb.append("}\n");
+ //2、删除
+ sb.append("\n");
+ sb.append(" //删除" + comment + "\n");
+ sb.append(" public void del" + beanNameWithoutT + "ById(" + key_type + " " + key + "){\n");
+ sb.append(" String sql=\"delete from " + table + " where " + key + "=?\";\n");
+ sb.append(" Db.update(sql," + key + ");\n");
+ sb.append(" }\n");
+ sb.append("\n");
+
+ //3、修改
+ sb.append(" /**修改" + comment + "\n");
+ sb.append(" *\n");
+ //迭代
+ for (Map.Entry 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 entry : fields.entrySet()) {
+ if (!entry.getKey().equals("create_time")) {
+ sb.append(entry.getKey() + "= ?,");
+ } else {
+ sb.append(entry.getKey() + "= DateTime.now(),");
+ }
+ }
+ sb = sb.deleteCharAt(sb.length() - 1);
+ sb.append(" where " + key + "=?\";\n");
+ sb.append(" Db.update(sql,");
+ for (Map.Entry entry : fields.entrySet()) {
+ if (!entry.getKey().equals("create_time")) {
+ sb.append(entry.getKey() + " , ");
+ }
+ }
+ sb.append(key);
+ sb.append(");\n");
+ sb.append(" }\n");
+ //4、单条查询
+ sb.append("\n");
+ sb.append(" //单条查询" + comment + "\n");
+ sb.append(" public Record get" + beanNameWithoutT + "ById(" + key_type + " " + key + "){\n");
+ sb.append(" String sql=\"select * from " + table + " where " + key + "=?\";\n");
+ sb.append(" return Db.findFirst(sql," + key + ");\n");
+ sb.append(" }\n");
+ sb.append("\n");
+
+ //5、分页查询
+ sb.append(" //分页查询" + comment + "\n");
+ sb.append(" public Page get" + beanNameWithoutT + "List(int pageNum, int pageSize){\n");
+ sb.append(" String sql1=\"select * \";\n");
+ sb.append(" String sql2=\" from " + table + " \";\n");
+ sb.append(" return Db.paginate(pageNum, pageSize, sql1,sql2);\n");
+ sb.append(" }\n");
+ sb.append("\n");
+ FileUtil.writeUtf8String(sb.toString(), beanPath + "/" + beanNameWithoutT + "Model.txt");
+ }
+
+
+ public static void autoCodeFreeMaker(JSONObject jo) throws IOException, TemplateException {
+ //不带主键的其它字段,拼接成java的函数声明内容
+ // 迭代map将按照插入顺序
+ Map fields = (Map) jo.get("fields");
+ Map fieldsComment = (Map) jo.get("fieldsComment");
+
+ String fullParameters = "";//带数据类型+字段名称
+ String parameters = "";//不带数据类型,只有字段名称
+ for (Map.Entry entry : fields.entrySet()) {
+ if (!entry.getKey().equals("create_time") && !entry.getKey().equals("b_use")) {
+ fullParameters += entry.getValue() + " " + entry.getKey() + " , ";//这里必须是反着来的,否则数据类型会重复
+ parameters += entry.getKey() + " , ";
+ }
+ }
+ //移除最后一个逗号
+ fullParameters = fullParameters.substring(0, fullParameters.length() - 1);
+ if (fullParameters.endsWith(",")) {//去掉最后的逗号
+ fullParameters = fullParameters.substring(0, fullParameters.length() - 1);
+ }
+ parameters = parameters.substring(0, parameters.length() - 1);
+ if (parameters.endsWith(",")) {
+ parameters = parameters.substring(0, parameters.length() - 1);
+ }
+ //后缀名称
+ String beanNameWithoutT = jo.getStr("beanNameWithoutT");
+ if (beanNameWithoutT.startsWith("T")) {
+ beanNameWithoutT = beanNameWithoutT.substring(1);
+ }
+ //表的描述
+ String comment = jo.getStr("comment");
+ //主键
+ String key = jo.getStr("key");
+ String key_type = jo.getStr("key_type");
+ //表名
+ String table = jo.getStr("table");
+
+ Map dataModel = new HashMap<>();
+ dataModel.put("comment", comment);
+ List params = new ArrayList<>();
+ //迭代
+ for (Map.Entry entry : fields.entrySet()) {
+ if (!entry.getKey().equals("create_time")) {
+ Record record = new Record();
+ record.set("key", entry.getKey());
+ record.set("comment", fieldsComment.get(entry.getKey()));
+ params.add(record);
+ }
+ }
+ dataModel.put("params", params);
+ dataModel.put("daoName", PropKit.get("daoName"));
+ dataModel.put("beanNameWithoutT", beanNameWithoutT);
+ dataModel.put("fullParameters", fullParameters);
+ dataModel.put("parameters", parameters);
+
+ // 创建一个 Configuration 实例
+ Configuration cfg = new Configuration(new Version(2, 3, 33));
+ // 设置模板目录
+ String path = System.getProperty("user.dir") + "/dsUtils/src/main/resources";
+ cfg.setDirectoryForTemplateLoading(new File(path));
+ // 设置字符编码
+ cfg.setDefaultEncoding("UTF-8");
+ // 加载模板
+ Template template = cfg.getTemplate("Controller.ftl");
+
+ // 渲染模板到文件
+ Writer out = new FileWriter("c:/output_users.txt");
+ template.process(dataModel, out);
+ out.close();
+ }
+}
diff --git a/dsUtils/src/main/resources/Controller.ftl b/dsUtils/src/main/resources/Controller.ftl
new file mode 100644
index 00000000..81612581
--- /dev/null
+++ b/dsUtils/src/main/resources/Controller.ftl
@@ -0,0 +1,12 @@
+/**
+* 增加${comment}
+<#list params as param>
+* @param ${param.key} ${param.comment}
+#list>
+*/
+@Before({POST.class})
+@JwtCheckInterface({})
+public void add${beanNameWithoutT}(${fullParameters}){
+ ${daoName}.add${beanNameWithoutT}(${parameters});
+ renderJson(RetKit.renderSuccess());
+}
\ No newline at end of file
diff --git a/dsUtils/src/main/resources/Model.ftl b/dsUtils/src/main/resources/Model.ftl
new file mode 100644
index 00000000..49aa3e03
--- /dev/null
+++ b/dsUtils/src/main/resources/Model.ftl
@@ -0,0 +1,7 @@
+列表
+<#list users as user>
+ ${user.name} - ${user.age}
+#list>
+
+变量
+${title}
\ No newline at end of file
diff --git a/dsUtils/src/main/resources/users.ftl b/dsUtils/src/main/resources/users.ftl
new file mode 100644
index 00000000..49aa3e03
--- /dev/null
+++ b/dsUtils/src/main/resources/users.ftl
@@ -0,0 +1,7 @@
+列表
+<#list users as user>
+ ${user.name} - ${user.age}
+#list>
+
+变量
+${title}
\ No newline at end of file
diff --git a/dsUtils/target/classes/Controller.ftl b/dsUtils/target/classes/Controller.ftl
new file mode 100644
index 00000000..81612581
--- /dev/null
+++ b/dsUtils/target/classes/Controller.ftl
@@ -0,0 +1,12 @@
+/**
+* 增加${comment}
+<#list params as param>
+* @param ${param.key} ${param.comment}
+#list>
+*/
+@Before({POST.class})
+@JwtCheckInterface({})
+public void add${beanNameWithoutT}(${fullParameters}){
+ ${daoName}.add${beanNameWithoutT}(${parameters});
+ renderJson(RetKit.renderSuccess());
+}
\ No newline at end of file
diff --git a/dsUtils/target/classes/Model.ftl b/dsUtils/target/classes/Model.ftl
new file mode 100644
index 00000000..49aa3e03
--- /dev/null
+++ b/dsUtils/target/classes/Model.ftl
@@ -0,0 +1,7 @@
+列表
+<#list users as user>
+ ${user.name} - ${user.age}
+#list>
+
+变量
+${title}
\ No newline at end of file
diff --git a/dsUtils/target/classes/users.ftl b/dsUtils/target/classes/users.ftl
new file mode 100644
index 00000000..49aa3e03
--- /dev/null
+++ b/dsUtils/target/classes/users.ftl
@@ -0,0 +1,7 @@
+列表
+<#list users as user>
+ ${user.name} - ${user.age}
+#list>
+
+变量
+${title}
\ No newline at end of file
diff --git a/output_users.html b/output_users.html
new file mode 100644
index 00000000..3160b301
--- /dev/null
+++ b/output_users.html
@@ -0,0 +1,14 @@
+
+
+
+ User List
+
+
+User List
+
+ - Alice - 25
+ - Bob - 30
+ - Charlie - 35
+
+
+
\ No newline at end of file