|
|
@@ -1,488 +0,0 @@
|
|
|
-package com.mrxu.admin.generator;
|
|
|
-
|
|
|
-import freemarker.template.Configuration;
|
|
|
-import freemarker.template.Template;
|
|
|
-import org.apache.ibatis.type.JdbcType;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileWriter;
|
|
|
-import java.io.Writer;
|
|
|
-import java.sql.Connection;
|
|
|
-import java.sql.DriverManager;
|
|
|
-import java.sql.ResultSet;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-public class MainNew {
|
|
|
- private static final String modelName = "flow";// 模块名
|
|
|
- private static final String menuName = "apiSupplier";
|
|
|
- private static final String modelCaption = "服务供应商";
|
|
|
- private static final String dbName = "mrxu_all_v2";
|
|
|
- private static final String tableName = "flow_api_supplier";
|
|
|
-
|
|
|
- private static final String url = "jdbc:mysql://110.42.247.201:3306/mrxu_all_v2";
|
|
|
- private static final String user = "root";
|
|
|
- private static final String pass = "xjw123";
|
|
|
- private static final Map<String, Object> root = new HashMap<>();
|
|
|
-
|
|
|
- private static String workSpace = null;//本地工作目录
|
|
|
- private static Configuration configuration;
|
|
|
-
|
|
|
- public static void main(String[] args) throws Exception {
|
|
|
- workSpace = MainNew.class.getResource("").getFile();
|
|
|
- workSpace = workSpace.substring(0, workSpace.indexOf("mrxu-manager/target/classes"));
|
|
|
- configuration = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
|
|
|
- configuration.setDirectoryForTemplateLoading(new File(workSpace + "/mrxu-manager/src/main/java/com/mrxu/admin/generator/template/"));
|
|
|
- // 关闭默认的数字格式化,即不添加千位分隔符
|
|
|
- configuration.setNumberFormat("#");
|
|
|
-
|
|
|
- root.put("modelName", modelName);
|
|
|
- root.put("modelClassName", Character.toUpperCase(modelName.charAt(0)) + modelName.substring(1));
|
|
|
- root.put("modelCaption", modelCaption);
|
|
|
- root.put("tableName", tableName);
|
|
|
- String beanName = ResultBuilder.lineToHump(tableName);
|
|
|
- beanName = Character.toUpperCase(beanName.charAt(0)) + beanName.substring(1);
|
|
|
- root.put("className", beanName);
|
|
|
- root.put("beanName", ResultBuilder.lineToHump(tableName));
|
|
|
-
|
|
|
- root.put("menuClassName", Character.toUpperCase(menuName.charAt(0)) + menuName.substring(1));
|
|
|
- root.put("menuName", menuName);
|
|
|
-
|
|
|
- String sql = "select column_name,column_comment,is_nullable,data_type,character_maximum_length as char_length,numeric_precision as num_length from information_schema.columns where table_schema='" + dbName + "' and table_name='" + tableName + "' order by ordinal_position asc ";
|
|
|
- Connection con = DriverManager.getConnection(url, user, pass);
|
|
|
- ResultSet rs = con.createStatement().executeQuery(sql);
|
|
|
- List<HashMap<String, Object>> list = ResultBuilder.build(rs);
|
|
|
- root.put("columnList", lineToHump(list));
|
|
|
- con.close();
|
|
|
-
|
|
|
- initMenu();
|
|
|
- createEntity();
|
|
|
- createDto();
|
|
|
- createMapperXml();
|
|
|
- createMapperJava();
|
|
|
- createService();
|
|
|
- createController();
|
|
|
- createIndex();
|
|
|
- createSearch();
|
|
|
- createEdit();
|
|
|
- createApiJs();
|
|
|
-
|
|
|
- System.out.println("http://localhost:5080/" + modelName + "/" + menuName + "/index.html");
|
|
|
- }
|
|
|
-
|
|
|
- private static void initMenu() throws Exception {
|
|
|
- String path = "/" + modelName + "/" + menuName;
|
|
|
- String url = "jdbc:mysql://110.42.247.201:3306/mrxu_all_v2";
|
|
|
- String sql = "select id from sys_menu where new_path = '" + path + "'";
|
|
|
- Connection con = DriverManager.getConnection(url, user, pass);
|
|
|
- ResultSet rs = con.createStatement().executeQuery(sql);
|
|
|
- List<HashMap<String, Object>> list = ResultBuilder.build(rs);
|
|
|
- if (list.size() == 0) {
|
|
|
- String insertSql = "insert into sys_menu (parent_id,new_open_type,for_front,name,new_path,new_component,authority,type,create_person) " +
|
|
|
- "values (63,0,'newFront','" + modelCaption + "','" + path + "','" + path + "','" + modelName + ":" + menuName + ":read',1,'system')";
|
|
|
- con.createStatement().execute(insertSql);
|
|
|
- rs = con.createStatement().executeQuery(sql);
|
|
|
- list = ResultBuilder.build(rs);
|
|
|
- Integer id = (Integer) list.get(0).get("id");
|
|
|
-
|
|
|
- insertSql = "insert into sys_menu (parent_id,for_front,name,authority,type,create_person) " +
|
|
|
- "values (" + id + ",'newFront','查看','" + modelName + ":" + menuName + ":read',2,'system')";
|
|
|
- con.createStatement().execute(insertSql);
|
|
|
-
|
|
|
- insertSql = "insert into sys_menu (parent_id,for_front,name,authority,type,create_person) " +
|
|
|
- "values (" + id + ",'newFront','编辑','" + modelName + ":" + menuName + ":update', 2, 'system')";
|
|
|
- con.createStatement().execute(insertSql);
|
|
|
-
|
|
|
- insertSql = "insert into sys_menu (parent_id,for_front,name,authority,type,create_person) " +
|
|
|
- "values (" + id + ",'newFront','删除','" + modelName + ":" + menuName + ":remove',2,'system')";
|
|
|
- con.createStatement().execute(insertSql);
|
|
|
-
|
|
|
- }
|
|
|
- con.close();
|
|
|
- }
|
|
|
-
|
|
|
- private static String getMybatisDataType(String type) {
|
|
|
- if ("bigint".equals(type)) {
|
|
|
- return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("binary".equals(type)) {//未知
|
|
|
- return JdbcType.BINARY.name();
|
|
|
- }
|
|
|
- if ("bit".equals(type)) {
|
|
|
- return JdbcType.BIT.name();
|
|
|
- }
|
|
|
- if ("blob".equals(type)) {
|
|
|
- return JdbcType.BLOB.name();
|
|
|
- }
|
|
|
- if ("char".equals(type)) {
|
|
|
- return JdbcType.CHAR.name();
|
|
|
- }
|
|
|
- if ("bigint".equals(type)) {
|
|
|
- return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("date".equals(type)) {
|
|
|
- return JdbcType.DATE.name();
|
|
|
- }
|
|
|
- if ("datetime".equals(type)) {
|
|
|
- return JdbcType.TIMESTAMP.name();
|
|
|
- }
|
|
|
- if ("decimal".equals(type)) {
|
|
|
- return JdbcType.DECIMAL.name();
|
|
|
- }
|
|
|
- if ("double".equals(type)) {
|
|
|
- return JdbcType.DOUBLE.name();
|
|
|
- }
|
|
|
- if ("enum".equals(type)) {
|
|
|
- //return JdbcType.ENUM.name();
|
|
|
- }
|
|
|
- if ("float".equals(type)) {
|
|
|
- return JdbcType.FLOAT.name();
|
|
|
- }
|
|
|
- if ("geometry".equals(type)) {
|
|
|
- //return JdbcType..name();
|
|
|
- }
|
|
|
- if ("geometrycollection".equals(type)) {
|
|
|
- return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("int".equals(type)) {
|
|
|
- return JdbcType.INTEGER.name();
|
|
|
- }
|
|
|
- if ("integer".equals(type)) {
|
|
|
- return JdbcType.INTEGER.name();
|
|
|
- }
|
|
|
- if ("linestring".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("longblob".equals(type)) {
|
|
|
- return JdbcType.BLOB.name();
|
|
|
- }
|
|
|
- if ("longtext".equals(type)) {
|
|
|
- return JdbcType.BLOB.name();
|
|
|
- }
|
|
|
- if ("mediumblob".equals(type)) {
|
|
|
- return JdbcType.BLOB.name();
|
|
|
- }
|
|
|
- if ("mediumint".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("mediumtext".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("multilinestring".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("multipoint".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("multipolygon".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("numeric".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("point".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("polygon".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("real".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("set".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- if ("smallint".equals(type)) {
|
|
|
- return JdbcType.SMALLINT.name();
|
|
|
- }
|
|
|
- if ("text".equals(type)) {
|
|
|
- return JdbcType.BLOB.name();
|
|
|
- }
|
|
|
- if ("time".equals(type)) {
|
|
|
- return JdbcType.TIME.name();
|
|
|
- }
|
|
|
- if ("timestamp".equals(type)) {
|
|
|
- return JdbcType.TIMESTAMP.name();
|
|
|
- }
|
|
|
-
|
|
|
- if ("tinyblob".equals(type)) {
|
|
|
- return JdbcType.BLOB.name();
|
|
|
- }
|
|
|
- if ("tinyint".equals(type)) {
|
|
|
- return JdbcType.TINYINT.name();
|
|
|
- }
|
|
|
- if ("tinytext".equals(type)) {
|
|
|
- return JdbcType.BLOB.name();
|
|
|
- }
|
|
|
- if ("varbinary".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
-
|
|
|
- if ("varchar".equals(type)) {
|
|
|
- return JdbcType.VARCHAR.name();
|
|
|
- }
|
|
|
- if ("year".equals(type)) {
|
|
|
- //return JdbcType.BIGINT.name();
|
|
|
- }
|
|
|
- throw new RuntimeException("不支持数据类型:" + type);
|
|
|
- }
|
|
|
-
|
|
|
- private static void createIndex() throws Exception {
|
|
|
- String path = workSpace + "/ele-admin-plus-js/src/views/" + root.get("modelName") + "/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("menuName") + ".vue");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("newIndex.vue");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- private static void createSearch() throws Exception {
|
|
|
- String path = workSpace + "/ele-admin-plus-js/src/views/" + root.get("modelName") + "/components/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("menuName") + "-search.vue");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("newSearch.vue");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- private static void createEdit() throws Exception {
|
|
|
- String path = workSpace + "/ele-admin-plus-js/src/views/" + root.get("modelName") + "/components/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("menuName") + "-edit.vue");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("newEdit.vue");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- private static void createApiJs() throws Exception {
|
|
|
- String path = workSpace + "/ele-admin-plus-js/src/api/" + root.get("modelName") + "/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("menuName") + ".js");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("newApi.js");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 字段名字 转换
|
|
|
- *
|
|
|
- * @param list
|
|
|
- * @return
|
|
|
- */
|
|
|
- private static List<HashMap<String, Object>> lineToHump(List<HashMap<String, Object>> list) {
|
|
|
- boolean hasProvince = false;
|
|
|
- boolean hasCity = false;
|
|
|
- boolean hasDistrict = false;
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- HashMap<String, Object> temp = list.get(i);
|
|
|
- temp.put("column_name_org", temp.get("column_name"));
|
|
|
- temp.put("column_name", ResultBuilder.lineToHump(temp.get("column_name").toString()));
|
|
|
-
|
|
|
- temp.put("mybatis_data_type", getMybatisDataType(temp.get("data_type").toString()));
|
|
|
-
|
|
|
- if ("province".equals(temp.get("column_name"))) {
|
|
|
- hasProvince = true;
|
|
|
- } else if ("city".equals(temp.get("column_name"))) {
|
|
|
- hasCity = true;
|
|
|
- } else if ("district".equals(temp.get("column_name"))) {
|
|
|
- hasDistrict = true;
|
|
|
- }
|
|
|
- }
|
|
|
- root.put("hasPlace", hasProvince && hasCity && hasDistrict);
|
|
|
-
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成controller代码
|
|
|
- */
|
|
|
- private static void createController() throws Exception {
|
|
|
- String path = workSpace + "/mrxu-manager/src/main/java/com/mrxu/admin/controller/" + root.get("modelName") + "/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("className") + "Controller.java");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("newController.ftl");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
-
|
|
|
- System.out.println("代码生成完成 !!!!!");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成service api接口代码
|
|
|
- */
|
|
|
- private static void createIapi() throws Exception {
|
|
|
- String path = workSpace + "/mrxu-" + root.get("modelName") + "/" + root.get("modelName") + "-sdk/src/main/java/com/mrxu/" + root.get("modelName") + "/api/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + "I" + root.get("className") + "Api.java");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("iapi.ftl");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成service api接口代码
|
|
|
- */
|
|
|
- private static void createEntity() throws Exception {
|
|
|
- String path = workSpace + "/mrxu-manager/src/main/java/com/mrxu/" + root.get("modelName") + "/entity/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("className") + ".java");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("entity.ftl");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成dto接口代码
|
|
|
- */
|
|
|
- private static void createDto() throws Exception {
|
|
|
- String path = workSpace + "/mrxu-manager/src/main/java/com/mrxu/" + root.get("modelName") + "/query/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("className") + "Dto.java");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("dto.ftl");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成api接口实现代码
|
|
|
- */
|
|
|
- private static void createApi() throws Exception {
|
|
|
- String path = workSpace + "/mrxu-manager/src/main/java/com/mrxu/" + root.get("modelName") + "/api/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("className") + "Api.java");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("api.ftl");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- private static void createService() throws Exception {
|
|
|
- String path = workSpace + "/mrxu-manager/src/main/java/com/mrxu/" + root.get("modelName") + "/service/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("className") + "Service.java");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("service.ftl");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- private static void createMapperJava() throws Exception {
|
|
|
- String path = workSpace + "/mrxu-manager/src/main/java/com/mrxu/" + root.get("modelName") + "/mapper/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("className") + "Mapper.java");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("mapperJava.ftl");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- private static void createMapperXml() throws Exception {
|
|
|
- String path = workSpace + "/mrxu-manager/src/main/resources/mapper/" + root.get("modelName") + "/";
|
|
|
- File pathDir = new File(path);
|
|
|
- if (!pathDir.exists()) {
|
|
|
- pathDir.mkdirs();
|
|
|
- }
|
|
|
- File file = new File(path + root.get("className") + "Mapper.xml");
|
|
|
- // 加载模板文件
|
|
|
- Template template = configuration.getTemplate("mapperXml.ftl");
|
|
|
- // 显示生成的数据
|
|
|
- Writer writer = new FileWriter(file);
|
|
|
- template.process(root, writer);
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|