소스 검색

自动生成路由

xiongzhu 7 년 전
부모
커밋
1384f79279

+ 5 - 0
pom.xml

@@ -949,6 +949,11 @@
             <version>3.1.3</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.jenkins-ci.lib</groupId>
+            <artifactId>java-client-api</artifactId>
+            <version>0.3.8</version>
+        </dependency>
         <!--<dependency>-->
             <!--<groupId>com.baidu</groupId>-->
             <!--<artifactId>ueditor</artifactId>-->

+ 5 - 9
src/main/java/com/izouma/awesomeadmin/dto/Result.java

@@ -25,17 +25,13 @@ public class Result {
     public Result(boolean success, Object data) {
 
         this.success = success;
-        this.data = data;
-    }
-
-
-    public Result(boolean success, String error) {
-
-        this.success = success;
-        this.error = error;
+        if (!success) {
+            this.error = data.toString();
+        } else {
+            this.data = data;
+        }
     }
 
-
     public boolean isSuccess() {
 
         return success;

+ 26 - 0
src/main/java/com/izouma/awesomeadmin/model/GenCode.java

@@ -54,6 +54,11 @@ public class GenCode {
      */
     private Boolean genForm;
 
+    /**
+     * 是否生成路由
+     */
+    private Boolean genRouter;
+
     /**
      * 字段表id
      */
@@ -69,6 +74,11 @@ public class GenCode {
      */
     private String viewPath;
 
+    /**
+     * 路由生成路径
+     */
+    private String routerPath;
+
     /**
      * 数据库类型:Mysql/SqlServer
      */
@@ -213,6 +223,22 @@ public class GenCode {
         this.readTable = readTable;
     }
 
+    public String getRouterPath() {
+        return routerPath;
+    }
+
+    public void setRouterPath(String routerPath) {
+        this.routerPath = routerPath;
+    }
+
+    public Boolean getGenRouter() {
+        return genRouter;
+    }
+
+    public void setGenRouter(Boolean genRouter) {
+        this.genRouter = genRouter;
+    }
+
     public String getDataSourceCode() {
         return dataSourceCode;
     }

+ 9 - 2
src/main/java/com/izouma/awesomeadmin/web/GenCodeController.java

@@ -3,6 +3,7 @@ package com.izouma.awesomeadmin.web;
 import java.io.File;
 import java.util.*;
 
+import com.google.gson.Gson;
 import com.izouma.awesomeadmin.model.GenCode;
 import com.izouma.awesomeadmin.util.PinYinUtil;
 import com.izouma.codegenerator.*;
@@ -84,7 +85,8 @@ public class GenCodeController extends BaseController {
     @ResponseBody
     public Result save(@RequestBody GenCode record) {
         try {
-
+            Gson gson=new Gson();
+            record.setGenJson(gson.toJson(record));
             genCode(record);
 
             genCodeService.createGenCode(record);
@@ -103,7 +105,8 @@ public class GenCodeController extends BaseController {
     @ResponseBody
     public Result updateGenCode(@RequestBody GenCode record) {
         try {
-
+            Gson gson=new Gson();
+            record.setGenJson(gson.toJson(record));
             genCode(record);
 
             boolean num = genCodeService.updateGenCode(record);
@@ -152,6 +155,9 @@ public class GenCodeController extends BaseController {
         if (record.getGenForm()) {
             EditViewGenerator.GenEditView(record);
         }
+        if (record.getGenRouter()) {
+            RouterGenerator.GenRouter(record);
+        }
     }
 
     /**
@@ -180,6 +186,7 @@ public class GenCodeController extends BaseController {
         map.put("root", root);
         map.put("javaPath", "/src/main/java/" + path);
         map.put("viewPath", "/src/main/vue/src/pages");
+        map.put("routerPath", "/src/main/vue/src/router");
         return new Result(true, map);
     }
 

+ 42 - 0
src/main/java/com/izouma/awesomeadmin/web/SystemController.java

@@ -0,0 +1,42 @@
+package com.izouma.awesomeadmin.web;
+
+import com.izouma.awesomeadmin.dto.Result;
+import com.izouma.awesomeadmin.model.DepartInfo;
+import com.izouma.awesomeadmin.util.Base64;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.shiro.authz.annotation.RequiresAuthentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.net.URLEncoder;
+
+@Controller
+@RequestMapping("/system")
+@RequiresAuthentication
+public class SystemController {
+
+    @RequestMapping(value = "/deploy", method = RequestMethod.POST)
+    @ResponseBody
+    public Result deploy(DepartInfo record) {
+        try {
+            HttpClient httpClient = HttpClientBuilder.create().build();
+            HttpPost post = new HttpPost("http://49.4.67.181:8000/job/信牧基础平台/build");
+            post.addHeader("Authorization", "Basic " + Base64.getBase64("admin:3edc#EDC"));
+            HttpResponse response = httpClient.execute(post);
+            if (201 == response.getStatusLine().getStatusCode()) {
+                String location = response.getFirstHeader("Location").getValue();
+                return new Result(true, new StringBuilder(location));
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return new Result(false, null);
+    }
+
+}

+ 0 - 2
src/main/java/com/izouma/codegenerator/ControllerGenerator.java

@@ -24,8 +24,6 @@ public class ControllerGenerator {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 0 - 2
src/main/java/com/izouma/codegenerator/EditViewGenerator.java

@@ -22,8 +22,6 @@ public class EditViewGenerator {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 0 - 2
src/main/java/com/izouma/codegenerator/GenList.java

@@ -49,8 +49,6 @@ public class GenList {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, "/Users/xiongzhu/Projects/Java/awesomeAdmin/src/main/java/com/izouma/ModelGenerator/templates");
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 0 - 2
src/main/java/com/izouma/codegenerator/ListViewGenerator.java

@@ -22,8 +22,6 @@ public class ListViewGenerator {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 0 - 2
src/main/java/com/izouma/codegenerator/MapperGenerator.java

@@ -24,8 +24,6 @@ public class MapperGenerator {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 0 - 2
src/main/java/com/izouma/codegenerator/MapperXmlGenerator.java

@@ -23,8 +23,6 @@ public class MapperXmlGenerator {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 0 - 2
src/main/java/com/izouma/codegenerator/ModelGenerator.java

@@ -25,8 +25,6 @@ public class ModelGenerator {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 54 - 0
src/main/java/com/izouma/codegenerator/RouterGenerator.java

@@ -0,0 +1,54 @@
+package com.izouma.codegenerator;
+
+import com.izouma.awesomeadmin.model.GenCode;
+import org.apache.commons.lang.StringUtils;
+
+import java.io.*;
+
+public class RouterGenerator {
+    public static void GenRouter(GenCode model) {
+        try {
+            File file = new File(model.getRouterPath(), "index.js");
+            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
+            StringBuilder routerJs = new StringBuilder();
+            String line = null;
+            while ((line = reader.readLine()) != null) {
+                routerJs.append(line).append("\n");
+            }
+            reader.close();
+
+            int insertLocation = routerJs.indexOf("/**INSERT_LOCATION**/");
+            if (insertLocation > -1) {
+                String routeName = StringUtils.capitalize(model.getClassName());
+                String routePath = StringUtils.uncapitalize(model.getClassName());
+                String route = "{\n                    path: '/"
+                        + routePath
+                        + "',\n                    name: '"
+                        + routeName
+                        + "',\n                    component: () => import('../pages/"
+                        + routeName
+                        + "')\n                },\n                {\n                    path: '/"
+                        + routePath
+                        + "s',\n                    name: '"
+                        + routeName
+                        + "s',\n                    component: () => import('../pages/"
+                        + routeName
+                        + "s')\n                }\n                ";
+                boolean needComma = !routerJs.toString().substring(0, insertLocation).trim().endsWith(",");
+                if (needComma) {
+                    routerJs.insert(routerJs.toString().substring(0, insertLocation).lastIndexOf("}") + 1, ",");
+                    insertLocation++;
+                }
+                routerJs.insert(insertLocation, route);
+            }
+
+            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
+            bufferedOutputStream.write(routerJs.toString().trim().getBytes());
+            bufferedOutputStream.close();
+
+            System.out.println("成功生成路由:" + file.getAbsolutePath());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 0 - 2
src/main/java/com/izouma/codegenerator/ServiceGenerator.java

@@ -24,8 +24,6 @@ public class ServiceGenerator {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 0 - 2
src/main/java/com/izouma/codegenerator/ServiceImplGenerator.java

@@ -24,8 +24,6 @@ public class ServiceImplGenerator {
             Properties pro = new Properties();
             pro.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
             pro.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
-            pro.setProperty("directive.foreach.counter.name", "velocityCount");
-            pro.setProperty("directive.foreach.counter.initial.value", "1");
             Velocity.init(pro);
             ToolManager manager = new ToolManager(true, true);
             VelocityContext context = new VelocityContext(manager.createContext());

+ 3 - 3
src/main/resources/templates/ControllerTemplate.vm

@@ -136,14 +136,14 @@ public class ${model.className}Controller extends BaseController{
         String titleName = "${model.remark}数据表";
         String fileName = "${model.remark}表";
         int columnNumber = ${model.fields.size()};
-        int[] columnWidth = {#foreach(${field} in ${model.fields}) 20#if(${velocityCount} != ${model.fields.size()}),#end #end};
-        String[] columnName = {#foreach(${field} in ${model.fields}) #if(${field.remark}) "${field.remark}" #else "${field.modelName}"#end#if(${velocityCount} != ${model.fields.size()}),#end #end};
+        int[] columnWidth = {#foreach(${field} in ${model.fields}) 20#if($foreach.count != ${model.fields.size()}),#end #end};
+        String[] columnName = {#foreach(${field} in ${model.fields}) #if(${field.remark}) "${field.remark}" #else "${field.modelName}"#end#if($foreach.count != ${model.fields.size()}),#end #end};
         String[][] dataList = new String[${display.uncapitalize(${model.className})}s.size()][${model.fields.size()}];
 
         for (int i = 0; i < ${display.uncapitalize(${model.className})}s.size(); i++) {
 
             #foreach(${field} in ${model.fields})
-                #set($fund=$velocityCount - 1)
+                #set($fund=$foreach.count - 1)
             dataList[i][$fund] = String.valueOf(${display.uncapitalize(${model.className})}s.get(i).get${display.capitalize($field.modelName)}());
             #end
         }

+ 2 - 2
src/main/resources/templates/MapperXmlSqlServerTemplate.vm

@@ -13,7 +13,7 @@
     </resultMap>
     <sql id="Base_Column_List">
         #foreach($field in $model.fields)
-            ${field.name}#if($velocityCount!=$model.fields.size()),#end
+            ${field.name}#if($foreach.count!=$model.fields.size()),#end
         #end
     </sql>
     <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
@@ -194,7 +194,7 @@
 
         </where>
     </select>
-    <delete id="delete" parameterType="java.lang.Integer">
+    <delete id="delete">
         delete from ${model.tableName}
         where id = #{id,jdbcType=INTEGER}
     </delete>

+ 69 - 0
src/main/vue/src/pages/DeploySystem.vue

@@ -0,0 +1,69 @@
+<template>
+    <div>
+        <div v-if="building">
+            <div style="color:#606266;font-size:14px">部署中</div>
+            <el-progress :percentage="percentage"></el-progress>
+        </div>
+        <div v-else>
+            <el-alert title="请谨慎操作" type="warning" description="重新部署会导致网站暂时无法访问" :closable="false" show-icon> </el-alert>
+            <el-button size="small" style="margin-top:20px" @click="deploy">重新部署</el-button>
+        </div>
+    </div>
+</template>
+<script>
+import axios from 'axios'
+export default {
+    data() {
+        return {
+            url: '',
+            percentage: 0,
+            building: false
+        }
+    },
+    methods: {
+        deploy() {
+            this.$confirm('确定重新部署?', '提示', {
+                confirmButtonText: '确定',
+                cancelButtonText: '取消',
+                type: 'warning'
+            }).then(() => {
+                axios.post('http://49.4.67.181:8000/job/信牧基础平台/build', {
+                    auth: {
+                        username: 'admin',
+                        password: '3edc#EDC'
+                    }
+                }).then(res => {
+                    if (res.status === 201) {
+                        this.buildid = /(.*)\/(.+?)\/$/.exec(res.headers['location'])[2]
+                        this.percentage = 0
+                        this.building = true
+                        this.pollingStatus()
+                    } else {
+
+                    }
+                })
+            }).catch(() => { });
+        },
+        pollingStatus() {
+            axios.get(`http://49.4.67.181:8000/job/信牧基础平台/${this.buildid}/api/json`).then(res => {
+                if (res.status === 200) {
+                    if (res.data.building) {
+                        let p = (new Date().getTime() - res.data.timestamp) * 100 / res.data.estimatedDuration
+                        p = p < 0 ? 0 : (p >= 100 ? 99 : parseInt(p))
+                        this.percentage = p
+                        setTimeout(() => {
+                            this.pollingStatus()
+                        }, 500);
+                    } else {
+                        this.percentage = 100
+                        this.building = false
+                        this.$message.success('部署成功')
+                    }
+                }
+            })
+        }
+    }
+}
+</script>
+<style lang="less" scoped>
+</style>

+ 223 - 218
src/main/vue/src/pages/GenCode.vue

@@ -1,5 +1,5 @@
 <template>
-    <div>
+    <div v-loading="loading" element-loading-text="拼命加载中">
         <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small">
             <el-form-item prop="tableName" label="表名">
                 <el-input v-model="formData.tableName" style="width: 400px;"></el-input>
@@ -14,7 +14,8 @@
 
             </el-form-item>
             <el-form-item prop="dataBaseType" label="库类型">
-                <el-select placeholder="库类型" size="small" v-model="formData.dataBaseType" @change="cityDataBaseType" class="filter-item">
+                <el-select placeholder="库类型" size="small" v-model="formData.dataBaseType" @change="cityDataBaseType"
+                           class="filter-item">
                     <el-option label="Mysql" value="Mysql">
                     </el-option>
                     <el-option label="SqlServer" value="SqlServer">
@@ -24,7 +25,8 @@
             <el-form-item prop="datasourceInfo" label="数据库">
 
                 <el-select placeholder="数据库" size="small" v-model="formData.dataSourceCode" class="filter-item">
-                    <el-option v-for="item in datasourceInfoList" :label="item.databaseName" :value="item.code" :key="item.code"></el-option>
+                    <el-option v-for="item in datasourceInfoList" :label="item.databaseName" :value="item.code"
+                               :key="item.code"></el-option>
                 </el-select>
 
             </el-form-item>
@@ -34,12 +36,13 @@
                 <el-checkbox v-model="formData.genClass" label="类"></el-checkbox>
                 <el-checkbox v-model="formData.genList" label="列表"></el-checkbox>
                 <el-checkbox v-model="formData.genForm" label="表单"></el-checkbox>
+                <el-checkbox v-model="formData.genRouter" label="路由"></el-checkbox>
             </el-form-item>
             <el-form-item prop="javaPath" label="根目录">
                 <el-input v-model="formData.rootPath"></el-input>
             </el-form-item>
             <el-form-item prop="fields" label="数据" v-if="!formData.readTable">
-                <el-tabs value="1" type="border-card" @tab-click="tabClick">
+                <el-tabs value="1" type="border-card">
                     <el-tab-pane label="字段" name="1">
                         <el-table :data="fields">
                             <el-table-column prop="name" label="字段名" align="center">
@@ -50,7 +53,8 @@
                             <el-table-column prop="type" label="类型" width="150" align="center">
                                 <template slot-scope="{row}">
                                     <el-select v-model="row.jdbcType" filterable>
-                                        <el-option v-for="item in fieldTypes" :value="item" :label="item" :key="item"></el-option>
+                                        <el-option v-for="item in fieldTypes" :value="item" :label="item"
+                                                   :key="item"></el-option>
                                     </el-select>
                                 </template>
                             </el-table-column>
@@ -119,14 +123,16 @@
                             <el-table-column prop="formType" label="表单类型" width="150" align="center">
                                 <template slot-scope="{row}">
                                     <el-select v-model="row.formType">
-                                        <el-option v-for="item in formTypes" :label="item.label" :value="item.value" :key="item.value"></el-option>
+                                        <el-option v-for="item in formTypes" :label="item.label" :value="item.value"
+                                                   :key="item.value"></el-option>
                                     </el-select>
                                 </template>
                             </el-table-column>
                             <el-table-column prop="searchMethod" label="搜索方式" width="150" align="center">
                                 <template slot-scope="{row}">
                                     <el-select v-model="row.searchMethod">
-                                        <el-option v-for="item in searchMethods" :label="item" :value="item" :key="item"></el-option>
+                                        <el-option v-for="item in searchMethods" :label="item" :value="item"
+                                                   :key="item"></el-option>
                                     </el-select>
                                 </template>
                             </el-table-column>
@@ -169,7 +175,8 @@
                             <el-table-column prop="validatorType" label="校验类型" width="150" align="center">
                                 <template slot-scope="{row}">
                                     <el-select v-model="row.validatorType">
-                                        <el-option v-for="item in validatorTypes" :label="item.label" :value="item.label" :key="item.label"></el-option>
+                                        <el-option v-for="item in validatorTypes" :label="item.label"
+                                                   :value="item.label" :key="item.label"></el-option>
                                     </el-select>
                                 </template>
                             </el-table-column>
@@ -187,236 +194,234 @@
 </template>
 
 <script>
-import axios from 'axios'
+    import axios from 'axios'
 
-export default {
-    created() {
+    export default {
+        created() {
+            if (this.$route.query.id) {
+                this.loading = true;
+                this.$http.get({
+                    url: '/genCode/getOne',
+                    data: {
+                        id: this.$route.query.id
+                    }
+                }).then(res => {
+                    this.loading = false;
+                    if (res.success) {
+                        this.formData = {
+                            ...this.formData,
+                            ...JSON.parse(res.data.genJson)
+                        };
+                        this.fields = this.formData.fields;
+                        this.formData.id = res.data.id;
+                        this.formData.genRouter = false;
+                    }
+                }).catch(e => this.loading = false)
+            }
 
-        if (this.$route.query.id) {
             this.$http.get({
-                url: '/genCode/getOne',
-                data: {
-                    id: this.$route.query.id
+                url: '/genCode/getSrcPath'
+            }).then(res => {
+                if (res.success) {
+                    this.formData.rootPath = res.data.root;
+                    this.formData.javaPathRelative = res.data.javaPath;
+                    this.formData.viewPathRelative = res.data.viewPath;
+                    this.formData.routerPathRelative = res.data.routerPath;
                 }
+            });
+            this.$http.get({
+                url: '/dataSourceInfo/all'
             }).then(res => {
                 if (res.success) {
-                    this.formData = JSON.parse(res.data.genJson);
-                    this.fields = this.formData.fields;
-                    this.formData.id = res.data.id;
+                    this.MysqlDataSourceInfos.push(this.baseDataSource);
+
+                    if (res.data.length > 0) {
+                        res.data.forEach(item => {
+                            if ('Mysql' == item.databaseType) {
+                                this.MysqlDataSourceInfos.push(item);
+                            } else if ('SqlServer' == item.databaseType) {
+                                this.SqlServerDataSourceInfos.push(item);
+                            }
+                        })
+                    }
+                    this.datasourceInfoList = this.MysqlDataSourceInfos;
                 }
             })
-        }
-
-        this.$http.get({
-            url: '/genCode/getSrcPath'
-        }).then(res => {
-            if (res.success) {
-                this.formData.rootPath = res.data.root;
-                this.formData.javaPathRelative = res.data.javaPath;
-                this.formData.viewPathRelative = res.data.viewPath;
-            }
-        })
-
-        this.$http.get({
-            url: '/dataSourceInfo/all'
-        }).then(res => {
-            if (res.success) {
-                res.data;
-
-                this.MysqlDataSourceInfos.push(this.baseDataSource);
-
-                if (res.data.length > 0) {
-
-
-                    res.data.forEach(item => {
-                        if ('Mysql' == item.databaseType) {
-                            this.MysqlDataSourceInfos.push(item);
-                        } else if ('SqlServer' == item.databaseType) {
-                            this.SqlServerDataSourceInfos.push(item);
+        },
+        data() {
+            return {
+                loading: false,
+                fieldTypes: ['char', 'varchar', 'int', 'text', 'timestamp', 'datetime', 'decimal', 'float'],
+                searchMethods: ['=', '!=', '>', '>=', '<', '<=', 'between', 'like', 'left like', 'right like'],
+                formTypes: [
+                    {label: '单行文本', value: 'singleLineText'},
+                    {label: '多行文本', value: 'textarea'},
+                    {label: '富文本', value: 'richText'},
+                    {label: '数字', value: 'number'},
+                    {label: '日期选择', value: 'date'},
+                    {label: '单选下拉框', value: 'select'},
+                    {label: '多选下拉框', value: 'multiSelect'},
+                    {label: '单图上传', value: 'singleImage'},
+                    {label: '多图上传', value: 'multiImage'},
+                    {label: '文件上传', value: 'fileUpload'},
+                    {label: '树形选择', value: 'tree'},
+                    {label: '开关', value: 'switch'}
+                ],
+                validatorTypes: [
+                    {label: '英文', value: 'english'},
+                    {label: '数字', value: 'number'},
+                    {label: '手机', value: 'phone'},
+                    {label: '网址', value: 'url'},
+                    {label: '电子邮件', value: 'email'},
+                    {label: '身份证', value: 'id'}
+                ],
+                rules: {
+                    tableName: [
+                        {required: true, message: '请填写表名', trigger: 'blur'},
+                        {
+                            validator: (rule, value, callback) => {
+                                if (value) {
+                                    if (/^[\u4e00-\u9fa5a-zA-Z0-9_]*$/.test(value)) {
+                                        callback();
+                                    } else {
+                                        callback(new Error('表名不正确'));
+                                    }
+                                }
+                            }, trigger: 'blur'
                         }
+                    ],
+                    remark: [{required: true, message: '请填写描述', trigger: 'blur'}],
+                    rootPath: [{required: true, message: '请填写生成目录', trigger: 'blur'}],
+                    dataBaseType: [{required: true, message: '请选择数据库类型', trigger: 'blur'}],
+                    dataSourceCode: [{required: true, message: '请填选择数据库', trigger: 'blur'}],
+                },
+                formData: {
+                    tableName: '',
+                    remark: '',
+                    genTable: true,
+                    genClass: true,
+                    genList: true,
+                    genForm: true,
+                    genRouter: true,
+                    rootPath: '',
+                    javaPathRelative: '',
+                    viewPathRelative: '',
+                    dataBaseType: 'Mysql',
+                    readTable: false,
+                    dataSourceCode: 'dataSource'
+                },
+                fields: [
+                    {
+                        name: 'id',
+                        jdbcType: 'int',
+                        notNull: true,
+                        primaryKey: true,
+                        autoIncrease: true,
+                        remark: '',
+                        showInList: false,
+                        showInForm: false,
+                        searchable: false
+                    },
+                    {
+                        name: 'del_flag',
+                        jdbcType: 'char',
+                        notNull: true,
+                        primaryKey: false,
+                        autoIncrease: false,
+                        remark: '删除标识',
+                        showInList: false,
+                        showInForm: false,
+                        searchable: false,
+                        defaultValue: 'N',
+                        length: 1
+                    },
+                ],
+                MysqlDataSourceInfos: [],
+                SqlServerDataSourceInfos: [],
+                baseDataSource: {
+                    databaseType: 'Mysql',
+                    code: 'dataSource',
+                    databaseName: '基础数据库'
 
-                    })
+                },
+                datasourceInfoList: [],
+            }
+        },
+        computed: {
+            editableFields() {
+                return this.fields.filter(i => {
+                    return i.name
+                });
+            }
+        },
+        methods: {
+            onSave() {
+                this.$refs.form.validate((valid) => {
+                    if (valid) {
+                        this.submit();
+                    } else {
+                        return false;
+                    }
+                });
+            },
+            submit() {
 
-                }
-                this.datasourceInfoList = this.MysqlDataSourceInfos;
+                this.formData.fields = this.fields;
+                this.formData.javaPath = this.formData.rootPath + this.formData.javaPathRelative;
+                this.formData.viewPath = this.formData.rootPath + this.formData.viewPathRelative;
+                this.formData.routerPath = this.formData.rootPath + this.formData.routerPathRelative;
+                this.formData.genJson = '';
 
-            }
-        })
-    },
-    data() {
-        return {
-            fieldTypes: ['char', 'varchar', 'int', 'text', 'timestamp', 'datetime', 'decimal', 'float'],
-            searchMethods: ['=', '!=', '>', '>=', '<', '<=', 'between', 'like', 'left like', 'right like'],
-            formTypes: [
-                { label: '单行文本', value: 'singleLineText' },
-                { label: '多行文本', value: 'textarea' },
-                { label: '富文本', value: 'richText' },
-                { label: '数字', value: 'number' },
-                { label: '日期选择', value: 'date' },
-                { label: '单选下拉框', value: 'select' },
-                { label: '多选下拉框', value: 'multiSelect' },
-                { label: '单图上传', value: 'singleImage' },
-                { label: '多图上传', value: 'multiImage' },
-                { label: '文件上传', value: 'fileUpload' },
-                { label: '树形选择', value: 'tree' },
-                { label: '开关', value: 'switch' }
-            ],
-            validatorTypes: [
-                { label: '英文', value: 'english' },
-                { label: '数字', value: 'number' },
-                { label: '手机', value: 'phone' },
-                { label: '网址', value: 'url' },
-                { label: '电子邮件', value: 'email' },
-                { label: '身份证', value: 'id' }
-            ],
-            rules: {
-                tableName: [
-                    { required: true, message: '请填写表名', trigger: 'blur' },
-                    {
-                        validator: (rule, value, callback) => {
-                            if (value) {
-                                if (/^[\u4e00-\u9fa5a-zA-Z0-9_]*$/.test(value)) {
-                                    callback();
-                                } else {
-                                    callback(new Error('表名不正确'));
-                                }
-                            }
-                        }, trigger: 'blur'
+                this.$alert('生成代码可能会删除已有同名表、数据或文件,确认要生成么?', '警告', {type: 'error'}).then(() => {
+                    this.loading = true;
+                    return axios.post(this.formData.id ? '/genCode/update' : '/genCode/save', this.formData)
+                }).then(() => {
+                    this.loading = false;
+                    this.$message.success('代码生成成功');
+                    this.$router.go(-1);
+                }).catch(res => {
+                    this.loading = false;
+                    if ('cancel' === res) {
+                        this.$msgbox({title: '提示', type: 'error', message: '生成取消'});
+                    } else {
+                        this.$msgbox({title: '提示', type: 'error', message: '生成失败'});
                     }
-                ],
-                remark: [{ required: true, message: '请填写描述', trigger: 'blur' }],
-                rootPath: [{ required: true, message: '请填写生成目录', trigger: 'blur' }],
-                dataBaseType: [{ required: true, message: '请选择数据库类型', trigger: 'blur' }],
-                dataSourceCode: [{ required: true, message: '请填选择数据库', trigger: 'blur' }],
+                })
             },
-            formData: {
-                tableName: '',
-                remark: '',
-                genTable: true,
-                genClass: true,
-                genList: true,
-                genForm: true,
-                rootPath: '',
-                javaPathRelative: '',
-                viewPathRelative: '',
-                dataBaseType: 'Mysql',
-                readTable: false,
-                dataSourceCode: 'dataSource'
+            addField() {
+                this.fields.push({
+                    name: '',
+                    jdbcType: 'varchar',
+                    notNull: false,
+                    primaryKey: false,
+                    autoIncrease: false,
+                    remark: '',
+                    showInList: true,
+                    showInForm: true,
+                    searchable: false,
+                    formType: 'singleLineText'
+                });
             },
-            fields: [{
-                name: 'id',
-                jdbcType: 'int',
-                notNull: true,
-                primaryKey: true,
-                autoIncrease: true,
-                remark: '',
-                showInList: false,
-                showInForm: false,
-                searchable: false
+            removeField(i) {
+                if (this.fields.length > 1) {
+                    this.fields.splice(i, 1);
+                }
             },
-            {
-                name: 'del_flag',
-                jdbcType: 'char',
-                notNull: true,
-                primaryKey: false,
-                autoIncrease: false,
-                remark: '删除标识',
-                showInList: false,
-                showInForm: false,
-                searchable: false,
-                defaultValue: 'N',
-                length: 1
+            updateReadTable() {
+                this.formData.readTable = !this.formData.readTable;
+                this.formData.genTable = !this.formData.readTable;
             },
-            ],
-            MysqlDataSourceInfos: [],
-            SqlServerDataSourceInfos: [],
-            baseDataSource: {
-                databaseType: 'Mysql',
-                code: 'dataSource',
-                databaseName: '基础数据库'
-
+            cityDataBaseType() {
+                if ('Mysql' == this.formData.dataBaseType) {
+                    this.datasourceInfoList = this.MysqlDataSourceInfos;
+                    this.formData.dataSourceCode = 'dataSource';
+                } else if ('SqlServer' == this.formData.dataBaseType) {
+                    this.datasourceInfoList = this.SqlServerDataSourceInfos;
+                    this.formData.dataSourceCode = '';
+                }
             },
-            datasourceInfoList: [],
-        }
-    },
-    computed: {
-        editableFields() {
-            return this.fields.filter(i => {
-                return i.name
-            });
         }
-    },
-    methods: {
-        onSave() {
-            this.$refs.form.validate((valid) => {
-                if (valid) {
-                    this.submit();
-                } else {
-                    return false;
-                }
-            });
-        },
-        submit() {
-
-            this.formData.fields = this.fields;
-            this.formData.javaPath = this.formData.rootPath + this.formData.javaPathRelative;
-            this.formData.viewPath = this.formData.rootPath + this.formData.viewPathRelative;
-            this.formData.genJson = JSON.stringify(this.formData);
-            var alertMsg = "生成代码可能会删除已有同名表、数据或文件,确认要生成么?";
-
-            this.$alert(alertMsg, '警告', { type: 'error' }).then(() => {
-                return axios.post(this.formData.id ? '/genCode/update' : '/genCode/save', this.formData)
-            }).then(() => {
-                this.$msgbox({ title: '提示', type: 'success', message: '代码生成成功' });
-                this.$router.go(-1);
-            }).catch(() => {
-                if (res === 'cancel') {
-                    this.$msgbox({ title: '提示', type: 'error', message: '生成取消' });
-                } else {
-                    this.$msgbox({ title: '提示', type: 'error', message: '生成失败' });
-                }
-            })
-
-
-        },
-        addField() {
-            this.fields.push({
-                name: '',
-                jdbcType: 'varchar',
-                notNull: false,
-                primaryKey: false,
-                autoIncrease: false,
-                remark: '',
-                showInList: true,
-                showInForm: true,
-                searchable: false,
-                formType: 'singleLineText'
-            });
-        },
-        removeField(i) {
-            if (this.fields.length > 1) {
-                this.fields.splice(i, 1);
-            }
-        },
-        tabClick(tab) {
-            window.xxx = tab;
-            setTimeout(() => tab.$nextTick(), 1000);
-        },
-        updateReadTable() {
-            this.formData.readTable = !this.formData.readTable;
-            this.formData.genTable = !this.formData.readTable;
-        },
-        cityDataBaseType() {
-            if ('Mysql' == this.formData.dataBaseType) {
-                this.datasourceInfoList = this.MysqlDataSourceInfos;
-                this.formData.dataSourceCode = 'dataSource';
-            } else if ('SqlServer' == this.formData.dataBaseType) {
-                this.datasourceInfoList = this.SqlServerDataSourceInfos;
-                this.formData.dataSourceCode = '';
-            }
-        },
     }
-}
 </script>
 
 <style lang="less" scoped>

+ 6 - 0
src/main/vue/src/router/index.js

@@ -215,6 +215,12 @@ const router = new Router({
                     name: 'TestSqlserverAaa',
                     component: () => import('../pages/TestSqlserverAaa')
                 },
+                {
+                    path: '/deploySystem',
+                    name: 'DeploySystem',
+                    component: () => import('../pages/DeploySystem')
+                }
+                /**INSERT_LOCATION**/
             ]
         },
         {

+ 49 - 0
src/test/java/GenCodeTest.java

@@ -0,0 +1,49 @@
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+
+import java.io.*;
+
+public class GenCodeTest {
+    @Test
+    public void testGenRouter() {
+        String className = "DeploySystem";
+        try {
+            File file = new File("/Users/drew/Projects/Java/awesomeAdmin/src/main/vue/src/router", "index.js");
+            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
+            StringBuilder routerJs = new StringBuilder();
+            String line = null;
+            while ((line = reader.readLine()) != null) {
+                routerJs.append(line).append("\n");
+                System.out.println(line);
+            }
+            reader.close();
+
+            int insertLocation = routerJs.indexOf("/**INSERT_LOCATION**/");
+            if (insertLocation > -1) {
+                String routeName =   StringUtils.capitalize(className);
+                String routePath =  StringUtils.uncapitalize(className);
+                String route = "{\n                    path: '/"
+                        + routePath
+                        + "',\n                    name: '"
+                        + routeName
+                        + "',\n                    component: () => import('../pages/"
+                        + routeName
+                        + "')\n                }\n                ";
+                boolean needComma = !routerJs.toString().substring(0, insertLocation).trim().endsWith(",");
+                if (needComma) {
+                    routerJs.insert(routerJs.toString().substring(0, insertLocation).lastIndexOf("}") + 1, ",");
+                    insertLocation++;
+                }
+                routerJs.insert(insertLocation, route);
+            }
+
+            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
+            bufferedOutputStream.write(routerJs.toString().trim().getBytes());
+            bufferedOutputStream.close();
+
+            System.out.println("成功生成路由:" + file.getAbsolutePath());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}