Browse Source

feat(增加组的概念):增加模板组,可以根据需求选择不同的组的模板,可以给数据源配置默认的包名、删除前缀、以及模板组,并且还可以在页面实时调整

(cherry picked from commit 9cfea6c4e8b962e68d78740a5175e68964150dcf)
张生龙 3 years ago
parent
commit
caffda3de3
46 changed files with 1140 additions and 200 deletions
  1. 16 3
      front/src/router/index.js
  2. 119 7
      front/src/views/generate/index.vue
  3. 124 0
      front/src/views/group/index.vue
  4. 38 0
      front/src/views/template/edit.vue
  5. 10 1
      front/src/views/template/index.vue
  6. 2 1
      front/vue.config.js
  7. 10 0
      gen/src/main/java/com/gitee/gen/common/GeneratorParam.java
  8. 11 2
      gen/src/main/java/com/gitee/gen/controller/TemplateConfigController.java
  9. 88 0
      gen/src/main/java/com/gitee/gen/controller/TemplateGroupController.java
  10. 74 36
      gen/src/main/java/com/gitee/gen/entity/DatasourceConfig.java
  11. 48 22
      gen/src/main/java/com/gitee/gen/entity/TemplateConfig.java
  12. 60 0
      gen/src/main/java/com/gitee/gen/entity/TemplateGroup.java
  13. 22 0
      gen/src/main/java/com/gitee/gen/gen/SQLContext.java
  14. 7 2
      gen/src/main/java/com/gitee/gen/mapper/TemplateConfigMapper.java
  15. 72 0
      gen/src/main/java/com/gitee/gen/mapper/TemplateGroupMapper.java
  16. 7 0
      gen/src/main/java/com/gitee/gen/service/GeneratorService.java
  17. 7 4
      gen/src/main/java/com/gitee/gen/service/TemplateConfigService.java
  18. 107 0
      gen/src/main/java/com/gitee/gen/service/TemplateGroupService.java
  19. 1 1
      gen/src/main/resources/application.properties
  20. 70 29
      gen/src/main/resources/mybatis/DatasourceConfigMapper.xml
  21. 63 17
      gen/src/main/resources/mybatis/TemplateConfigMapper.xml
  22. 106 0
      gen/src/main/resources/mybatis/TemplateGroupMapper.xml
  23. 1 1
      gen/src/main/resources/public/index.html
  24. 0 0
      gen/src/main/resources/public/static/css/app.aa6ee3c8.css
  25. 0 0
      gen/src/main/resources/public/static/css/chunk-34242e28.2864c242.css
  26. 1 1
      gen/src/main/resources/public/static/css/chunk-5fb3a2ba.36069daf.css
  27. 0 0
      gen/src/main/resources/public/static/css/chunk-44188c88.a254e507.css
  28. 1 1
      gen/src/main/resources/public/static/css/chunk-libs.2aad8290.css
  29. 1 0
      gen/src/main/resources/public/static/js/app.0cd732f6.js
  30. 0 1
      gen/src/main/resources/public/static/js/app.3a6801a7.js
  31. 0 1
      gen/src/main/resources/public/static/js/chunk-0a388286.be225d9f.js
  32. 0 0
      gen/src/main/resources/public/static/js/chunk-2d0efd67.7dba06b9.js
  33. 1 0
      gen/src/main/resources/public/static/js/chunk-2d228903.4316af3a.js
  34. 0 1
      gen/src/main/resources/public/static/js/chunk-2d228903.72e29674.js
  35. 1 0
      gen/src/main/resources/public/static/js/chunk-34242e28.ce617928.js
  36. 1 0
      gen/src/main/resources/public/static/js/chunk-4295c974.c99d0862.js
  37. 1 0
      gen/src/main/resources/public/static/js/chunk-44188c88.3620cd3a.js
  38. 0 1
      gen/src/main/resources/public/static/js/chunk-4de1c2b6.2c1febca.js
  39. 1 0
      gen/src/main/resources/public/static/js/chunk-4de1c2b6.9c50e0a4.js
  40. 4 2
      gen/src/main/resources/public/static/js/chunk-53ca05b2.2b9ec4ce.js
  41. 0 1
      gen/src/main/resources/public/static/js/chunk-5fb3a2ba.37de9787.js
  42. 0 1
      gen/src/main/resources/public/static/js/chunk-70c97e3b.3c1cab1d.js
  43. 1 0
      gen/src/main/resources/public/static/js/chunk-74aeca77.f3100fa9.js
  44. 0 60
      gen/src/main/resources/public/static/js/chunk-libs.3c441178.js
  45. 60 0
      gen/src/main/resources/public/static/js/chunk-libs.62e97045.js
  46. 4 4
      readme.md

+ 16 - 3
front/src/router/index.js

@@ -1,11 +1,10 @@
 import Vue from 'vue'
 import Router from 'vue-router'
-
-Vue.use(Router)
-
 /* Layout */
 import Layout from '@/layout'
 
+Vue.use(Router)
+
 /**
  * Note: sub-menu only appear when route children.length >= 1
  * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
@@ -71,6 +70,20 @@ export const constantRoutes = [
     ]
   },
   {
+    path: '/group',
+    component: Layout,
+    meta: { title: '模板组管理', icon: 'table' },
+    redirect: '/group/list',
+    children: [
+      {
+        path: 'list',
+        name: 'List',
+        component: () => import('@/views/group/index'),
+        meta: { title: '模板组管理' }
+      }
+    ]
+  },
+  {
     path: '/template',
     component: Layout,
     meta: { title: '模板管理', icon: 'table' },

+ 119 - 7
front/src/views/generate/index.vue

@@ -26,7 +26,10 @@
         <el-button type="text" @click="onDataSourceAdd">新建数据源</el-button>
       </el-form-item>
       <el-form-item v-show="showTable" label="包名(package)">
-        <el-input v-model="clientParam.packageName" placeholder="可选,如:com.gitee.xxx" show-word-limit maxlength="100" />
+        <el-input v-model="clientParam.packageName" placeholder="可选,如:cn.studyjava.xxx" show-word-limit maxlength="100" />
+      </el-form-item>
+      <el-form-item v-show="showTable" label="删除前缀">
+        <el-input v-model="clientParam.delPrefix" placeholder="可选,如:sys_user对应Java类为User(多前缀逗号隔开)" show-word-limit maxlength="100" />
       </el-form-item>
     </el-form>
     <el-row v-show="showTable" :gutter="20">
@@ -57,13 +60,29 @@
           />
         </el-table>
       </el-col>
-      <el-col :span="12">
+      <el-col :span="12" id="templateSelect">
         <h4>选择模板</h4>
+        <el-select
+          v-model="clientParam.groupName"
+          placeholder="选择模板所在组"
+          size="mini"
+          @change="onDataGroupChange"
+          style="margin-bottom: 10px; width: 100%;"
+        >
+          <el-option
+            v-for="item in groupData"
+            :key="item.id"
+            :label="`${item.groupName}`"
+            :value="item.id"
+          >
+          </el-option>
+        </el-select>
         <el-table
           :data="templateListData"
           border
           :cell-style="cellStyleSmall()"
           :header-cell-style="headCellStyleSmall()"
+          :row-class-name="templateTableRowClassName"
           @selection-change="onTemplateListSelect"
         >
           <el-table-column
@@ -72,7 +91,12 @@
           <el-table-column
             prop="name"
             label="模板名称"
-          />
+          >
+            <span slot-scope="scope">
+<!--              {{scope.row.groupName}}-{{scope.row.name}}-->
+              {{scope.row.name}}
+            </span>
+          </el-table-column>
         </el-table>
         <el-button v-show="showTable" type="primary" @click="onGenerate">生成代码</el-button>
       </el-col>
@@ -118,6 +142,29 @@
         <el-form-item label="Password" prop="password">
           <el-input v-model="datasourceFormData.password" type="password" placeholder="密码" show-word-limit maxlength="100" />
         </el-form-item>
+        <el-form-item label="包名" prop="packageName">
+          <el-input v-model="datasourceFormData.packageName" placeholder="包名(package)" show-word-limit maxlength="100" />
+        </el-form-item>
+        <el-form-item label="删除前缀" prop="delPrefix">
+          <el-input v-model="datasourceFormData.delPrefix" placeholder="删除前缀(表名sys_user删除前缀sys_对应bean为User)多前缀逗号隔开" show-word-limit maxlength="200" />
+        </el-form-item>
+        <el-form-item label="代码生成器模板" prop="delPrefix">
+          <el-select
+            v-model="datasourceFormData.groupName"
+            placeholder="选择模板所在组"
+            size="mini"
+            @change="onDataGroupChange"
+            style="margin-bottom: 10px; width: 100%;"
+          >
+            <el-option
+              v-for="item in groupData"
+              :key="item.id"
+              :label="`${item.groupName}`"
+              :value="item.id"
+            >
+            </el-option>
+          </el-select>
+        </el-form-item>
         <el-form-item>
           <el-button type="success" @click="onDatasourceTest">测试连接</el-button>
           <el-button type="primary" @click="onDatasourceSave">保存</el-button>
@@ -142,17 +189,25 @@
   .el-table .hidden-row {
     display: none;
   }
+  #templateSelect {
+    .el-input { width: 100%;}
+  }
 </style>
 <script>
 export default {
   data() {
     return {
-      showTable: false,
+      groupId: '',
+      groupData: {},
+      showTable: true,
       clientParam: {
         datasourceConfigId: '',
         tableNames: [],
         templateConfigIdList: [],
-        packageName: ''
+        packageName: null,
+        delPrefix: null,
+        groupId: '',
+        groupName: ''
       },
       tableSearch: '',
       datasourceConfigList: [],
@@ -168,7 +223,11 @@ export default {
         port: '',
         username: '',
         password: '',
-        dbName: ''
+        dbName: '',
+        packageName: '',
+        delPrefix: '',
+        groupId: '',
+        groupName: ''
       },
       dbTypeConfig: [],
       datasourceRule: {
@@ -194,19 +253,40 @@ export default {
     this.loadDataSource()
     this.loadTemplate()
     this.loadDbType()
+    this.loadGroups()
   },
   methods: {
     tableRowClassName: function ({row, index}) {
+      // console.log("tablerow="+row.tableName+","+index)
       row.hidden = false
       if (this.tableSearch.length === 0) {
         return ''
       }
+      // console.log("tablerow="+row.tableName +","+ row.tableName.indexOf(this.tableName)+","+(!(row.tableName && row.tableName.indexOf(this.tableSearch) > -1)))
       if (!(row.tableName && row.tableName.toLowerCase().indexOf(this.tableSearch.toLowerCase()) > -1)) {
         row.hidden = true
         return 'hidden-row';
       }
       return ''
     },
+    templateTableRowClassName: function ({row, index}) {
+      // console.log("temprow="+row.id+",rowGroupId="+row.groupId+", this.groupId="+ this.groupId)
+      row.hidden = false
+      if (this.groupId == '' || this.groupId <= 0) {
+        return ''
+      }
+      // console.log("temprow="+row.groupId +","+(row.groupId && row.groupId == this.groupId))
+      if (row.groupId && row.groupId == this.groupId) {
+        return ''
+      }
+      row.hidden = true
+      return 'hidden-row';
+    },
+    loadGroups() {
+      this.post(`/group/list/`, {}, function(resp) {
+        this.groupData = resp.data
+      })
+    },
     loadDataSource() {
       this.post('/datasource/list', {}, resp => {
         this.datasourceConfigList = resp.data
@@ -224,6 +304,7 @@ export default {
     },
     onDataSourceAdd() {
       this.datasourceTitle = '新建连接'
+      Object.keys(this.datasourceFormData).forEach(key=>{this.datasourceFormData[key]=''})
       this.datasourceFormData.id = 0
       this.datasourceDlgShow = true
     },
@@ -233,10 +314,28 @@ export default {
         .map(row => row.tableName)
     },
     onTemplateListSelect(selectedRows) {
-      this.clientParam.templateConfigIdList = selectedRows.map(row => row.id)
+      this.clientParam.templateConfigIdList = selectedRows
+        .filter(row => row.hidden === undefined || row.hidden === false)
+        .map(row => row.id)
     },
     onDataSourceChange(datasourceConfigId) {
       this.clientParam.datasourceConfigId = datasourceConfigId
+      this.datasourceConfigList.find((item)=>{
+        if(item.id === datasourceConfigId){
+          this.clientParam.packageName = item.packageName;
+          this.clientParam.delPrefix = item.delPrefix;
+          this.groupId = item.groupId;
+          this.groupData.find((gitem)=>{
+            // console.log("gid="+gitem.id+",datasourceConfigGroupId="+item.groupId+","+(gitem.id == item.groupId))
+            if(gitem.id == item.groupId){
+              this.clientParam.groupName = gitem.groupName
+            }
+          });
+
+          console.log("this.clientParam.groupName="+this.clientParam.groupName)
+        }
+      });
+
       this.post(`/datasource/table/${datasourceConfigId}`, {}, resp => {
         this.showTable = true
         this.tableListData = resp.data
@@ -245,6 +344,12 @@ export default {
     onDataSourceUpdate(item) {
       this.datasourceTitle = '修改连接'
       Object.assign(this.datasourceFormData, item)
+      this.groupData.find((gitem)=>{
+        // console.log("gid="+gitem.id+",datasourceConfigGroupId="+item.groupId+","+(gitem.id == this.datasourceFormData.groupId))
+        if(gitem.id == item.groupId){
+          this.datasourceFormData.groupName = gitem.groupName
+        }
+      });
       this.datasourceDlgShow = true
     },
     onDataSourceDuplicate(item) {
@@ -289,6 +394,13 @@ export default {
         }
       })
     },
+    onDataGroupChange(groupId){
+      // console.log(groupId)
+      if(groupId != ''){
+        this.groupId = groupId
+        this.datasourceFormData.groupId = groupId
+      }
+    },
     onDatasourceSave() {
       this.$refs.datasourceForm.validate((valid) => {
         if (valid) {

+ 124 - 0
front/src/views/group/index.vue

@@ -0,0 +1,124 @@
+<template>
+  <div class="app-container">
+    <el-button type="primary" size="mini" icon="el-icon-plus" style="margin-bottom: 10px;" @click="onTableAdd">新增模板组</el-button>
+    <el-table
+      :data="tableData"
+      border
+      highlight-current-row
+    >
+      <el-table-column
+        prop="groupName"
+        label="模板组名称"
+      />
+      <el-table-column
+        label="操作"
+      >
+        <template slot-scope="scope">
+          <el-button type="text" size="mini" @click="onSelectTemplate(scope.row)">查看模板</el-button>
+          <el-button type="text" size="mini" @click="onTableUpdate(scope.row)">修改</el-button>
+          <el-button type="text" size="mini" @click="onTableDelete(scope.row)">删除</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <el-dialog
+      :title="groupTitle"
+      :visible.sync="groupDlgShow"
+    >
+      <el-form
+        ref="dialogForm"
+        :model="formData"
+        :rules="formRules"
+        size="mini"
+        label-width="120px"
+      >
+        <el-form-item prop="name" label="模板组名称">
+          <el-input v-model="formData.groupName" show-word-limit maxlength="100" />
+        </el-form-item>
+        <el-form-item>
+          <el-button type="primary" @click="onSave">保 存</el-button>
+        </el-form-item>
+      </el-form>
+    </el-dialog>
+
+  </div>
+</template>
+
+<script>
+export default {
+  data() {
+    return {
+      tableData: [],
+      groupTitle: '',
+      groupDlgShow: false,
+      formData: {
+        id: 0,
+        groupName: ''
+      },
+      formRules: {
+        groupName: [
+          { required: true, message: '不能为空', trigger: 'blur' }
+        ]
+      }
+    }
+  },
+  created() {
+    this.loadTable()
+  },
+  methods: {
+    loadTable: function() {
+      this.post('/group/list', {}, function(resp) {
+        this.tableData = resp.data
+      })
+    },
+    onTableAdd: function(row) {
+      this.groupTitle = '增加模板组'
+      this.formData = {
+        id: 0,
+        groupName: ''
+      }
+      this.groupDlgShow = true
+    },
+    onTableUpdate: function(row) {
+      this.groupTitle = '修改模板组'
+      this.post(`/group/get/${row.id}`, {}, function(resp) {
+        this.formData = resp.data
+      })
+      this.groupDlgShow = true
+    },
+    onTableDelete: function(row) {
+      this.confirm(`确认要删除【${row.groupName}】吗?`, function(done) {
+        this.post('/group/del', row, function() {
+          done()
+          this.tip('删除成功')
+          this.loadTable()
+        })
+      })
+    },
+    onAdd: function() {
+      this.goRoute('edit/0')
+    },
+    onSelectTemplate: function (row){
+      this.goRoute(`/template/list?groupId=${row.id}`)
+    },
+    onSave() {
+      this.$refs.dialogForm.validate((valid) => {
+        if (valid) {
+          console.log(this.formData.id)
+          const opt = this.formData.id ? 'update' : 'add'
+          console.log(opt)
+          const uri = `/group/${opt}`
+          this.post(uri, this.formData, resp => {
+            if (opt === 'add') {
+              this.formData.id = resp.data.id
+            }
+            this.tip('保存成功')
+            this.loadTable()
+            this.groupDlgShow = false
+          })
+        }
+      })
+    }
+  }
+}
+</script>

+ 38 - 0
front/src/views/template/edit.vue

@@ -10,6 +10,22 @@
           size="mini"
           label-position="top"
         >
+          <el-form-item prop="groupId" label="组名称">
+            <el-select
+              v-model="formData.groupId"
+              placeholder="选择模板所在组"
+              @change="onDataGroupChange"
+            >
+              <el-option
+                v-for="item in groupData"
+                :key="item.id"
+                :label="`${item.groupName}`"
+                :value="item.id"
+              >
+              </el-option>
+            </el-select>
+          </el-form-item>
+
           <el-form-item prop="name" label="模板名称">
             <el-input v-model="formData.name" show-word-limit maxlength="64" />
           </el-form-item>
@@ -88,13 +104,19 @@ export default {
   components: { codemirror },
   data() {
     return {
+      groupData: {},
       formData: {
         id: 0,
+        groupId: '',
+        groupName: '',
         name: '',
         fileName: '',
         content: ''
       },
       formRules: {
+        groupId: [
+          { required: true, message: '不能为空', trigger: 'blur' }
+        ],
         name: [
           { required: true, message: '不能为空', trigger: 'blur' }
         ],
@@ -131,6 +153,7 @@ export default {
       })
     }
     this.loadVelocityVar()
+    this.loadGroups()
   },
   methods: {
     loadVelocityVar() {
@@ -150,6 +173,21 @@ export default {
         })
       })
     },
+    loadGroups() {
+      this.post(`/group/list/`, {}, function(resp) {
+        this.groupData = resp.data
+      })
+    },
+    onDataGroupChange(groupId){
+      console.log(groupId)
+      this.formData.groupId = groupId;
+      this.groupData.find((item)=>{
+        if(item.id === groupId){
+          this.formData.groupName = item.groupName
+        }
+      });
+      console.log(this.formData.groupName)
+    },
     onExpressionClick(exp) {
       const codemirror = this.$refs.editor.codemirror
       // 插入表达式

+ 10 - 1
front/src/views/template/index.vue

@@ -7,6 +7,11 @@
       highlight-current-row
     >
       <el-table-column
+        prop="groupName"
+        label="组名称"
+        width="200"
+      />
+      <el-table-column
         prop="name"
         label="模板名称"
         width="200"
@@ -40,7 +45,11 @@ export default {
   },
   methods: {
     loadTable: function() {
-      this.post('/template/list', {}, function(resp) {
+      this.groupId = this.$route.query.groupId;
+      if (typeof this.groupId === 'undefined') {
+        this.groupId = '';
+      }
+      this.post(`/template/list?groupId=${this.groupId}`, {}, function(resp) {
         this.tableData = resp.data
       })
     },

+ 2 - 1
front/vue.config.js

@@ -88,7 +88,8 @@ module.exports = {
     config
     // https://webpack.js.org/configuration/devtool/#development
       .when(process.env.NODE_ENV === 'development',
-        config => config.devtool('cheap-source-map')
+        // config => config.devtool('cheap-source-map')
+        config => config.devtool('source-map')
       )
 
     config

+ 10 - 0
gen/src/main/java/com/gitee/gen/common/GeneratorParam.java

@@ -14,6 +14,8 @@ public class GeneratorParam {
 
 	private String packageName;
 
+	private String delPrefix;
+
 	private String charset = "UTF-8";
 
 	public int getDatasourceConfigId() {
@@ -48,6 +50,14 @@ public class GeneratorParam {
 		this.packageName = packageName;
 	}
 
+	public String getDelPrefix() {
+		return delPrefix;
+	}
+
+	public void setDelPrefix(String delPrefix) {
+		this.delPrefix = delPrefix;
+	}
+
 	public String getCharset() {
 		return charset;
 	}

+ 11 - 2
gen/src/main/java/com/gitee/gen/controller/TemplateConfigController.java

@@ -4,12 +4,15 @@ import com.gitee.gen.common.Action;
 import com.gitee.gen.common.Result;
 import com.gitee.gen.entity.TemplateConfig;
 import com.gitee.gen.service.TemplateConfigService;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 /**
  * @author tanghc
  */
@@ -32,8 +35,14 @@ public class TemplateConfigController {
     }
 
     @RequestMapping("/list")
-    public Result list() {
-        return Action.ok(templateConfigService.listAll());
+    public Result list(String groupId) {
+        List<TemplateConfig> templateConfigs = null;
+        if(StringUtils.isEmpty(groupId)){
+            templateConfigs = templateConfigService.listAll();
+        }else {
+            templateConfigs = templateConfigService.listByGroupId(groupId);
+        }
+        return Action.ok(templateConfigs);
     }
 
     @RequestMapping("/update")

+ 88 - 0
gen/src/main/java/com/gitee/gen/controller/TemplateGroupController.java

@@ -0,0 +1,88 @@
+package com.gitee.gen.controller;
+
+import com.gitee.gen.common.Action;
+import com.gitee.gen.common.Result;
+import com.gitee.gen.entity.TemplateGroup;
+import com.gitee.gen.service.TemplateGroupService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author : zsljava
+ * @date Date : 2020-12-15 9:51
+ * @Description: TODO
+ */
+@RestController
+@RequestMapping("group")
+public class TemplateGroupController {
+
+    @Autowired
+    private TemplateGroupService templateGroupService;
+
+    /**
+     * 查询所有记录
+     *
+     * @return 返回集合,没有返回空List
+     */
+    @RequestMapping("list")
+    public Result listAll() {
+        List<TemplateGroup> templateGroups = templateGroupService.listAll();
+        return Action.ok(templateGroups);
+    }
+
+
+    /**
+     * 根据主键查询
+     *
+     * @param id 主键
+     * @return 返回记录,没有返回null
+     */
+    @RequestMapping("get/{id}")
+    public Result get(@PathVariable("id") int id) {
+        TemplateGroup group = templateGroupService.getById(id);
+        return Action.ok(group);
+    }
+
+    /**
+     * 新增,忽略null字段
+     *
+     * @param templateGroup 新增的记录
+     * @return 返回影响行数
+     */
+    @RequestMapping("add")
+    public Result insert(@RequestBody TemplateGroup templateGroup) {
+        templateGroupService.insertIgnoreNull(templateGroup);
+        return Action.ok(templateGroup);
+    }
+
+    /**
+     * 修改,忽略null字段
+     *
+     * @param templateGroup 修改的记录
+     * @return 返回影响行数
+     */
+    @RequestMapping("update")
+    public Result update(@RequestBody TemplateGroup templateGroup) {
+//        templateGroupService.updateIgnoreNull(templateGroup);
+        templateGroupService.updateGroup(templateGroup);
+        return Action.ok();
+    }
+
+    /**
+     * 删除记录
+     *
+     * @param templateGroup 待删除的记录
+     * @return 返回影响行数
+     */
+    @RequestMapping("del")
+    public Result delete(@RequestBody TemplateGroup templateGroup) {
+        templateGroupService.deleteGroup(templateGroup);
+        return Action.ok();
+    }
+
+}

+ 74 - 36
gen/src/main/java/com/gitee/gen/entity/DatasourceConfig.java

@@ -1,7 +1,7 @@
 package com.gitee.gen.entity;
 
 
-import com.gitee.gen.gen.DbType;
+import java.util.Objects;
 
 /**
  * 数据源配置表
@@ -24,110 +24,148 @@ public class DatasourceConfig {
     private String password;
     /** 是否已删除,1:已删除,0:未删除 */
     private Integer isDeleted;
+    /** 包名*/
+    private String packageName;
+    /** 删除的前缀*/
+    private String delPrefix;
+    /** 代码生成器模板组id*/
+    private String groupId;
+
+    public Integer getId() {
+        return id;
+    }
 
     public void setId(Integer id) {
         this.id = id;
     }
 
-    public Integer getId() {
-        return this.id;
+    public Integer getDbType() {
+        return dbType;
     }
 
     public void setDbType(Integer dbType) {
         this.dbType = dbType;
     }
 
-    public Integer getDbType() {
-        return this.dbType;
+    public String getDriverClass() {
+        return driverClass;
     }
 
     public void setDriverClass(String driverClass) {
         this.driverClass = driverClass;
     }
 
-    public String getDriverClass() {
-        DbType dbType = DbType.of(this.dbType);
-        if (dbType == null) {
-            return "unknown";
-        }
-        return dbType.getDriverClass();
+    public String getDbName() {
+        return dbName;
     }
 
     public void setDbName(String dbName) {
         this.dbName = dbName;
     }
 
-    public String getDbName() {
-        return this.dbName;
+    public String getHost() {
+        return host;
     }
 
     public void setHost(String host) {
         this.host = host;
     }
 
-    public String getHost() {
-        return this.host;
+    public Integer getPort() {
+        return port;
     }
 
     public void setPort(Integer port) {
         this.port = port;
     }
 
-    public Integer getPort() {
-        return this.port;
+    public String getUsername() {
+        return username;
     }
 
     public void setUsername(String username) {
         this.username = username;
     }
 
-    public String getUsername() {
-        return this.username;
+    public String getPassword() {
+        return password;
     }
 
     public void setPassword(String password) {
         this.password = password;
     }
 
-    public String getPassword() {
-        return this.password;
+    public Integer getIsDeleted() {
+        return isDeleted;
     }
 
     public void setIsDeleted(Integer isDeleted) {
         this.isDeleted = isDeleted;
     }
 
-    public Integer getIsDeleted() {
-        return this.isDeleted;
+    public String getPackageName() {
+        return packageName;
+    }
+
+    public void setPackageName(String packageName) {
+        this.packageName = packageName;
     }
 
+    public String getDelPrefix() {
+        return delPrefix;
+    }
+
+    public void setDelPrefix(String delPrefix) {
+        this.delPrefix = delPrefix;
+    }
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
 
     @Override
     public boolean equals(Object o) {
-        if (this == o) { return true; }
-        if (o == null || getClass() != o.getClass()) {return false;}
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
         DatasourceConfig that = (DatasourceConfig) o;
-        return id.equals(that.id);
+        return Objects.equals(id, that.id) &&
+                Objects.equals(dbType, that.dbType) &&
+                Objects.equals(driverClass, that.driverClass) &&
+                Objects.equals(dbName, that.dbName) &&
+                Objects.equals(host, that.host) &&
+                Objects.equals(port, that.port) &&
+                Objects.equals(username, that.username) &&
+                Objects.equals(password, that.password) &&
+                Objects.equals(isDeleted, that.isDeleted) &&
+                Objects.equals(packageName, that.packageName) &&
+                Objects.equals(delPrefix, that.delPrefix) &&
+                Objects.equals(groupId, that.groupId);
     }
 
     @Override
     public int hashCode() {
-        return java.util.Objects.hash(id);
+        return Objects.hash(id, dbType, driverClass, dbName, host, port, username, password, isDeleted, packageName, delPrefix, groupId);
     }
 
     @Override
     public String toString() {
         return "DatasourceConfig{" +
                 "id=" + id +
-                ",dbType='" + dbType + "'" +
-                ",driverClass='" + driverClass + "'" +
-                ",dbName='" + dbName + "'" +
-                ",host='" + host + "'" +
-                ",port='" + port + "'" +
-                ",username='" + username + "'" +
-                ",password='" + password + "'" +
-                ",isDeleted='" + isDeleted + "'" +
+                ", dbType=" + dbType +
+                ", driverClass='" + driverClass + '\'' +
+                ", dbName='" + dbName + '\'' +
+                ", host='" + host + '\'' +
+                ", port=" + port +
+                ", username='" + username + '\'' +
+                ", password='" + password + '\'' +
+                ", isDeleted=" + isDeleted +
+                ", packageName='" + packageName + '\'' +
+                ", delPrefix='" + delPrefix + '\'' +
+                ", groupId='" + groupId + '\'' +
                 '}';
     }
-
 }

+ 48 - 22
gen/src/main/java/com/gitee/gen/entity/TemplateConfig.java

@@ -1,11 +1,15 @@
 package com.gitee.gen.entity;
 
 
+import java.util.Objects;
+
 /**
  * 模板表
  */
 public class TemplateConfig {
     private Integer id;
+    private Integer groupId;
+    private String groupName;
     /** 模板名称 */
     private String name;
     /** 文件名称 */
@@ -15,69 +19,91 @@ public class TemplateConfig {
     /** 是否删除,1:已删除,0:未删除 */
     private Integer isDeleted;
 
+    public Integer getId() {
+        return id;
+    }
+
     public void setId(Integer id) {
         this.id = id;
     }
 
-    public Integer getId() {
-        return this.id;
+    public Integer getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(Integer groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getGroupName() {
+        return groupName;
+    }
+
+    public void setGroupName(String groupName) {
+        this.groupName = groupName;
+    }
+
+    public String getName() {
+        return name;
     }
 
     public void setName(String name) {
         this.name = name;
     }
 
-    public String getName() {
-        return this.name;
+    public String getFileName() {
+        return fileName;
     }
 
     public void setFileName(String fileName) {
         this.fileName = fileName;
     }
 
-    public String getFileName() {
-        return this.fileName;
+    public String getContent() {
+        return content;
     }
 
     public void setContent(String content) {
         this.content = content;
     }
 
-    public String getContent() {
-        return this.content;
+    public Integer getIsDeleted() {
+        return isDeleted;
     }
 
     public void setIsDeleted(Integer isDeleted) {
         this.isDeleted = isDeleted;
     }
 
-    public Integer getIsDeleted() {
-        return this.isDeleted;
-    }
-
-
     @Override
     public boolean equals(Object o) {
-        if (this == o) { return true; }
-        if (o == null || getClass() != o.getClass()) {return false;}
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
         TemplateConfig that = (TemplateConfig) o;
-        return id.equals(that.id);
+        return Objects.equals(id, that.id) &&
+                Objects.equals(groupId, that.groupId) &&
+                Objects.equals(groupName, that.groupName) &&
+                Objects.equals(name, that.name) &&
+                Objects.equals(fileName, that.fileName) &&
+                Objects.equals(content, that.content) &&
+                Objects.equals(isDeleted, that.isDeleted);
     }
 
     @Override
     public int hashCode() {
-        return java.util.Objects.hash(id);
+        return Objects.hash(id, groupId, groupName, name, fileName, content, isDeleted);
     }
 
     @Override
     public String toString() {
         return "TemplateConfig{" +
                 "id=" + id +
-                ",name='" + name + "'" +
-                ",fileName='" + fileName + "'" +
-                ",content='" + content + "'" +
-                ",isDeleted='" + isDeleted + "'" +
+                ", groupId=" + groupId +
+                ", groupName='" + groupName + '\'' +
+                ", name='" + name + '\'' +
+                ", fileName='" + fileName + '\'' +
+                ", content='" + content + '\'' +
+                ", isDeleted=" + isDeleted +
                 '}';
     }
-
 }

+ 60 - 0
gen/src/main/java/com/gitee/gen/entity/TemplateGroup.java

@@ -0,0 +1,60 @@
+package com.gitee.gen.entity;
+
+/**
+ * @author : zsljava
+ * @date Date : 2020-12-15 9:49
+ * @Description: TODO
+ */
+public class TemplateGroup {
+    private Integer id;
+    private String groupName;
+    private Integer isDeleted;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return this.id;
+    }
+
+    public void setGroupName(String groupName) {
+        this.groupName = groupName;
+    }
+
+    public String getGroupName() {
+        return this.groupName;
+    }
+
+    public void setIsDeleted(Integer isDeleted) {
+        this.isDeleted = isDeleted;
+    }
+
+    public Integer getIsDelete() {
+        return this.isDeleted;
+    }
+
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) { return true; }
+        if (o == null || getClass() != o.getClass()) {return false;}
+        TemplateGroup that = (TemplateGroup) o;
+        return id.equals(that.id);
+    }
+
+    @Override
+    public int hashCode() {
+        return java.util.Objects.hash(id);
+    }
+
+    @Override
+    public String toString() {
+        return "TemplateGroup{" +
+                "id=" + id +
+                ",groupName='" + groupName + "'" +
+                ",isDelete='" + isDeleted + "'" +
+                '}';
+    }
+
+}

+ 22 - 0
gen/src/main/java/com/gitee/gen/gen/SQLContext.java

@@ -1,6 +1,7 @@
 package com.gitee.gen.gen;
 
 import com.gitee.gen.util.FieldUtil;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * SQL上下文,这里可以取到表,字段信息<br>
@@ -17,6 +18,12 @@ public class SQLContext {
      * 包名
      */
     private String packageName;
+
+    /**
+     * 删除的前缀
+     */
+    private String delPrefix;
+
     /**
      * 数据库名
      */
@@ -54,6 +61,13 @@ public class SQLContext {
      */
     public String getJavaBeanNameLF() {
         String tableName = tableDefinition.getTableName();
+        if(delPrefix != null){
+            String[] split = delPrefix.split(",");
+            for (String prefix : split){
+                tableName = tableName.startsWith(prefix) && !StringUtils.isEmpty(prefix) ? tableName.replace(prefix, "") : tableName;
+            }
+        }
+
         tableName = FieldUtil.underlineFilter(tableName);
         tableName = FieldUtil.dotFilter(tableName);
         return FieldUtil.lowerFirstLetter(tableName);
@@ -99,6 +113,14 @@ public class SQLContext {
         this.packageName = packageName;
     }
 
+    public String getDelPrefix() {
+        return delPrefix;
+    }
+
+    public void setDelPrefix(String delPrefix) {
+        this.delPrefix = delPrefix;
+    }
+
     public String getDbName() {
         return dbName;
     }

+ 7 - 2
gen/src/main/java/com/gitee/gen/mapper/TemplateConfigMapper.java

@@ -1,10 +1,10 @@
 package com.gitee.gen.mapper;
 
-import java.util.List;
-
 import com.gitee.gen.entity.TemplateConfig;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 @Mapper
 public interface TemplateConfigMapper {
 
@@ -66,4 +66,9 @@ public interface TemplateConfigMapper {
      */
     int delete(TemplateConfig templateConfig);
 
+    List<TemplateConfig> listByGroupId(String groupId);
+
+    int updateGroupNameByGroupId(Integer groupId, String groupName);
+
+    int deleteByGroupId(Integer id);
 }

+ 72 - 0
gen/src/main/java/com/gitee/gen/mapper/TemplateGroupMapper.java

@@ -0,0 +1,72 @@
+package com.gitee.gen.mapper;
+
+import com.gitee.gen.entity.TemplateGroup;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * @author : zsljava
+ * @date Date : 2020-12-15 9:50
+ * @Description: TODO
+ */
+@Mapper
+public interface TemplateGroupMapper {
+
+    /**
+     * 查询所有记录
+     *
+     * @return 返回集合,没有返回空List
+     */
+    List<TemplateGroup> listAll();
+
+
+    /**
+     * 根据主键查询
+     *
+     * @param id 主键
+     * @return 返回记录,没有返回null
+     */
+    TemplateGroup getById(Integer id);
+
+    /**
+     * 新增,插入所有字段
+     *
+     * @param templateGroup 新增的记录
+     * @return 返回影响行数
+     */
+    int insert(TemplateGroup templateGroup);
+
+    /**
+     * 新增,忽略null字段
+     *
+     * @param templateGroup 新增的记录
+     * @return 返回影响行数
+     */
+    int insertIgnoreNull(TemplateGroup templateGroup);
+
+    /**
+     * 修改,修改所有字段
+     *
+     * @param templateGroup 修改的记录
+     * @return 返回影响行数
+     */
+    int update(TemplateGroup templateGroup);
+
+    /**
+     * 修改,忽略null字段
+     *
+     * @param templateGroup 修改的记录
+     * @return 返回影响行数
+     */
+    int updateIgnoreNull(TemplateGroup templateGroup);
+
+    /**
+     * 删除记录
+     *
+     * @param templateGroup 待删除的记录
+     * @return 返回影响行数
+     */
+    int delete(TemplateGroup templateGroup);
+
+}

+ 7 - 0
gen/src/main/java/com/gitee/gen/service/GeneratorService.java

@@ -40,6 +40,7 @@ public class GeneratorService {
 
         for (SQLContext sqlContext : contextList) {
             setPackageName(sqlContext, generatorParam.getPackageName());
+            setDelPrefix(sqlContext, generatorParam.getDelPrefix());
             for (int tcId : generatorParam.getTemplateConfigIdList()) {
                 TemplateConfig template = templateConfigService.getById(tcId);
                 String folder = template.getName();
@@ -90,6 +91,12 @@ public class GeneratorService {
         }
     }
 
+    private void setDelPrefix(SQLContext sqlContext, String delPrefix) {
+        if (StringUtils.hasText(delPrefix)) {
+            sqlContext.setDelPrefix(delPrefix);
+        }
+    }
+
     private String doGenerator(SQLContext sqlContext, String template) {
         if (template == null) {
             return "";

+ 7 - 4
gen/src/main/java/com/gitee/gen/service/TemplateConfigService.java

@@ -26,10 +26,10 @@ public class TemplateConfigService {
     }
 
     public void insert(TemplateConfig templateConfig) {
-        TemplateConfig existObj = templateConfigMapper.getByName(templateConfig.getName());
-        if (existObj != null) {
-            throw new RuntimeException("模板名称已存在");
-        }
+//        TemplateConfig existObj = templateConfigMapper.getByName(templateConfig.getName());
+//        if (existObj != null) {
+//            throw new RuntimeException("模板名称已存在");
+//        }
         templateConfig.setIsDeleted(0);
         templateConfigMapper.insert(templateConfig);
     }
@@ -46,4 +46,7 @@ public class TemplateConfigService {
         templateConfigMapper.delete(templateConfig);
     }
 
+    public List<TemplateConfig> listByGroupId(String groupId) {
+        return templateConfigMapper.listByGroupId(groupId);
+    }
 }

+ 107 - 0
gen/src/main/java/com/gitee/gen/service/TemplateGroupService.java

@@ -0,0 +1,107 @@
+package com.gitee.gen.service;
+
+import com.gitee.gen.entity.TemplateGroup;
+import com.gitee.gen.mapper.TemplateConfigMapper;
+import com.gitee.gen.mapper.TemplateGroupMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author : zsljava
+ * @date Date : 2020-12-15 9:50
+ * @Description: TODO
+ */
+@Service
+public class TemplateGroupService {
+
+    @Autowired
+    private TemplateGroupMapper templateGroupMapper;
+
+    @Autowired
+    private TemplateConfigMapper templateConfigMapper;
+
+    /**
+     * 查询所有记录
+     *
+     * @return 返回集合,没有返回空List
+     */
+    public List<TemplateGroup> listAll() {
+        return templateGroupMapper.listAll();
+    }
+
+
+    /**
+     * 根据主键查询
+     *
+     * @param id 主键
+     * @return 返回记录,没有返回null
+     */
+    public TemplateGroup getById(Integer id) {
+        return templateGroupMapper.getById(id);
+    }
+
+    /**
+     * 新增,插入所有字段
+     *
+     * @param templateGroup 新增的记录
+     * @return 返回影响行数
+     */
+    public int insert(TemplateGroup templateGroup) {
+        return templateGroupMapper.insert(templateGroup);
+    }
+
+    /**
+     * 新增,忽略null字段
+     *
+     * @param templateGroup 新增的记录
+     * @return 返回影响行数
+     */
+    public int insertIgnoreNull(TemplateGroup templateGroup) {
+        templateGroup.setIsDeleted(0);
+        return templateGroupMapper.insertIgnoreNull(templateGroup);
+    }
+
+    /**
+     * 修改,修改所有字段
+     *
+     * @param templateGroup 修改的记录
+     * @return 返回影响行数
+     */
+    public int update(TemplateGroup templateGroup) {
+        return templateGroupMapper.update(templateGroup);
+    }
+
+    /**
+     * 修改,忽略null字段
+     *
+     * @param templateGroup 修改的记录
+     * @return 返回影响行数
+     */
+    public int updateIgnoreNull(TemplateGroup templateGroup) {
+        return templateGroupMapper.updateIgnoreNull(templateGroup);
+    }
+
+    /**
+     * 删除记录
+     *
+     * @param templateGroup 待删除的记录
+     * @return 返回影响行数
+     */
+    public int delete(TemplateGroup templateGroup) {
+        return templateGroupMapper.delete(templateGroup);
+    }
+
+    public int updateGroup(TemplateGroup templateGroup) {
+        int count = updateIgnoreNull(templateGroup);
+        templateConfigMapper.updateGroupNameByGroupId(templateGroup.getId(), templateGroup.getGroupName());
+        return count;
+    }
+
+    public int deleteGroup(TemplateGroup templateGroup) {
+        int delete = templateGroupMapper.delete(templateGroup);
+        templateConfigMapper.deleteByGroupId(templateGroup.getId());
+        return delete;
+    }
+}

+ 1 - 1
gen/src/main/resources/application.properties

@@ -1,5 +1,5 @@
 spring.application.name=gen
-server.port=6969
+server.port=9999
 
 spring.datasource.driver-class-name=org.sqlite.JDBC
 spring.datasource.url=jdbc:sqlite:gen.db

+ 70 - 29
gen/src/main/resources/mybatis/DatasourceConfigMapper.xml

@@ -2,15 +2,18 @@
 <!DOCTYPE  mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="com.gitee.gen.mapper.DatasourceConfigMapper">
     <resultMap id="BaseResultMap" type="com.gitee.gen.entity.DatasourceConfig">
-        <result column="id" property="id"/>
-        <result column="db_type" property="dbType"/>
-        <result column="driver_class" property="driverClass"/>
-        <result column="db_name" property="dbName"/>
-        <result column="host" property="host"/>
-        <result column="port" property="port"/>
-        <result column="username" property="username"/>
-        <result column="password" property="password"/>
-        <result column="is_deleted" property="isDeleted"/>
+        <result column="id" property="id" />
+        <result column="db_type" property="dbType" />
+        <result column="driver_class" property="driverClass" />
+        <result column="db_name" property="dbName" />
+        <result column="host" property="host" />
+        <result column="port" property="port" />
+        <result column="username" property="username" />
+        <result column="password" property="password" />
+        <result column="is_deleted" property="isDeleted" />
+        <result column="package_name" property="packageName" />
+        <result column="del_prefix" property="delPrefix" />
+        <result column="group_id" property="groupId" />
     </resultMap>
 
     <!-- 表字段 -->
@@ -24,20 +27,22 @@
         , t.username
         , t.password
         , t.is_deleted
+        , t.package_name
+        , t.del_prefix
+        , t.group_id
         </sql>
 
     <!-- 查询全部 -->
     <select id="listAll" resultMap="BaseResultMap">
         SELECT
-        <include refid="baseColumns"/>
+        <include refid="baseColumns" />
         FROM datasource_config t
-        WHERE is_deleted=0
     </select>
 
     <!-- 根据主键获取单条记录 -->
-    <select id="getById" resultMap="BaseResultMap" parameterType="Integer">
+    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
         SELECT
-        <include refid="baseColumns"/>
+        <include refid="baseColumns" />
         FROM datasource_config t
         WHERE id = #{id}
     </select>
@@ -56,6 +61,9 @@
             username,
             password,
             is_deleted,
+            package_name,
+            del_prefix,
+            group_id,
         </trim>
         <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
             #{dbType},
@@ -66,6 +74,9 @@
             #{username},
             #{password},
             #{isDeleted},
+            #{packageName},
+            #{delPrefix},
+            #{groupId},
         </trim>
     </insert>
 
@@ -100,32 +111,50 @@
             <if test="isDeleted != null">
                 is_deleted,
             </if>
+            <if test="packageName != null">
+                package_name,
+            </if>
+            <if test="delPrefix != null">
+                del_prefix,
+            </if>
+            <if test="groupId != null">
+                group_id,
+            </if>
         </trim>
         <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
-            <if test="dbType != null">
+            <if test="dbType != null" >
                 #{dbType},
             </if>
-            <if test="driverClass != null">
+            <if test="driverClass != null" >
                 #{driverClass},
             </if>
-            <if test="dbName != null">
+            <if test="dbName != null" >
                 #{dbName},
             </if>
-            <if test="host != null">
+            <if test="host != null" >
                 #{host},
             </if>
-            <if test="port != null">
+            <if test="port != null" >
                 #{port},
             </if>
-            <if test="username != null">
+            <if test="username != null" >
                 #{username},
             </if>
-            <if test="password != null">
+            <if test="password != null" >
                 #{password},
             </if>
-            <if test="isDeleted != null">
+            <if test="isDeleted != null" >
                 #{isDeleted},
             </if>
+            <if test="packageName != null" >
+                #{packageName},
+            </if>
+            <if test="delPrefix != null" >
+                #{delPrefix},
+            </if>
+            <if test="groupId != null" >
+                #{groupId},
+            </if>
         </trim>
     </insert>
 
@@ -141,6 +170,9 @@
             username=#{username},
             password=#{password},
             is_deleted=#{isDeleted},
+            package_name=#{packageName},
+            del_prefix=#{delPrefix},
+            group_id=#{groupId},
         </set>
         WHERE id = #{id}
     </update>
@@ -150,30 +182,39 @@
     <update id="updateIgnoreNull" parameterType="com.gitee.gen.entity.DatasourceConfig">
         UPDATE datasource_config
         <set>
-            <if test="dbType != null">
+            <if test="dbType != null" >
                 db_type=#{dbType},
             </if>
-            <if test="driverClass != null">
+            <if test="driverClass != null" >
                 driver_class=#{driverClass},
             </if>
-            <if test="dbName != null">
+            <if test="dbName != null" >
                 db_name=#{dbName},
             </if>
-            <if test="host != null">
+            <if test="host != null" >
                 host=#{host},
             </if>
-            <if test="port != null">
+            <if test="port != null" >
                 port=#{port},
             </if>
-            <if test="username != null">
+            <if test="username != null" >
                 username=#{username},
             </if>
-            <if test="password != null">
+            <if test="password != null" >
                 password=#{password},
             </if>
-            <if test="isDeleted != null">
+            <if test="isDeleted != null" >
                 is_deleted=#{isDeleted},
             </if>
+            <if test="packageName != null" >
+                package_name=#{packageName},
+            </if>
+            <if test="delPrefix != null" >
+                del_prefix=#{delPrefix},
+            </if>
+            <if test="groupId != null" >
+                group_id=#{groupId},
+            </if>
         </set>
         WHERE id = #{id}
     </update>

+ 63 - 17
gen/src/main/resources/mybatis/TemplateConfigMapper.xml

@@ -2,16 +2,20 @@
 <!DOCTYPE  mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="com.gitee.gen.mapper.TemplateConfigMapper">
     <resultMap id="BaseResultMap" type="com.gitee.gen.entity.TemplateConfig">
-        <result column="id" property="id"/>
-        <result column="name" property="name"/>
-        <result column="file_name" property="fileName"/>
-        <result column="content" property="content"/>
-        <result column="is_deleted" property="isDeleted"/>
+        <result column="id" property="id" />
+        <result column="group_id" property="groupId" />
+        <result column="group_name" property="groupName" />
+        <result column="name" property="name" />
+        <result column="file_name" property="fileName" />
+        <result column="content" property="content" />
+        <result column="is_deleted" property="isDeleted" />
     </resultMap>
 
     <!-- 表字段 -->
     <sql id="baseColumns">
          t.id
+        , t.group_id
+        , t.group_name
         , t.name
         , t.file_name
         , t.content
@@ -21,9 +25,9 @@
     <!-- 查询全部 -->
     <select id="listAll" resultMap="BaseResultMap">
         SELECT
-        <include refid="baseColumns"/>
+        <include refid="baseColumns" />
         FROM template_config t
-        WHERE is_deleted=0
+        WHERE t.is_deleted = 0
     </select>
 
     <select id="getByName" resultMap="BaseResultMap">
@@ -34,9 +38,9 @@
     </select>
 
     <!-- 根据主键获取单条记录 -->
-    <select id="getById" resultMap="BaseResultMap" parameterType="Integer">
+    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
         SELECT
-        <include refid="baseColumns"/>
+        <include refid="baseColumns" />
         FROM template_config t
         WHERE id = #{id}
     </select>
@@ -47,12 +51,16 @@
     >
         INSERT INTO template_config
         <trim prefix="(" suffix=")" suffixOverrides=",">
+            group_id,
+            group_name,
             name,
             file_name,
             content,
             is_deleted,
         </trim>
         <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
+            #{groupId},
+            #{groupName},
             #{name},
             #{fileName},
             #{content},
@@ -67,6 +75,12 @@
         INSERT INTO template_config
         <trim prefix="(" suffix=")" suffixOverrides=",">
 
+            <if test="groupId != null">
+                group_id,
+            </if>
+            <if test="groupName != null">
+                group_name,
+            </if>
             <if test="name != null">
                 name,
             </if>
@@ -81,16 +95,22 @@
             </if>
         </trim>
         <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
-            <if test="name != null">
+            <if test="groupId != null" >
+                #{groupId},
+            </if>
+            <if test="groupName != null" >
+                #{groupName},
+            </if>
+            <if test="name != null" >
                 #{name},
             </if>
-            <if test="fileName != null">
+            <if test="fileName != null" >
                 #{fileName},
             </if>
-            <if test="content != null">
+            <if test="content != null" >
                 #{content},
             </if>
-            <if test="isDeleted != null">
+            <if test="isDeleted != null" >
                 #{isDeleted},
             </if>
         </trim>
@@ -100,6 +120,8 @@
     <update id="update" parameterType="com.gitee.gen.entity.TemplateConfig">
         UPDATE template_config
         <set>
+            group_id=#{groupId},
+            group_name=#{groupName},
             name=#{name},
             file_name=#{fileName},
             content=#{content},
@@ -113,16 +135,22 @@
     <update id="updateIgnoreNull" parameterType="com.gitee.gen.entity.TemplateConfig">
         UPDATE template_config
         <set>
-            <if test="name != null">
+            <if test="groupId != null" >
+                group_id=#{groupId},
+            </if>
+            <if test="groupName != null" >
+                group_name=#{groupName},
+            </if>
+            <if test="name != null" >
                 name=#{name},
             </if>
-            <if test="fileName != null">
+            <if test="fileName != null" >
                 file_name=#{fileName},
             </if>
-            <if test="content != null">
+            <if test="content != null" >
                 content=#{content},
             </if>
-            <if test="isDeleted != null">
+            <if test="isDeleted != null" >
                 is_deleted=#{isDeleted},
             </if>
         </set>
@@ -137,5 +165,23 @@
 		WHERE id = #{id}
 	</delete>
 
+    <select id="listByGroupId" parameterType="java.lang.String" resultType="com.gitee.gen.entity.TemplateConfig">
+        SELECT
+        <include refid="baseColumns" />
+        FROM template_config t
+        WHERE group_id = #{groupId}
+    </select>
+
+    <update id="updateGroupNameByGroupId">
+        UPDATE template_config
+        SET group_name = #{groupName}
+        WHERE group_id = #{groupId}
+    </update>
+
+    <update id="deleteByGroupId">
+        UPDATE template_config
+        SET is_deleted=1
+        WHERE group_id = #{groupId}
+    </update>
 
 </mapper>

+ 106 - 0
gen/src/main/resources/mybatis/TemplateGroupMapper.xml

@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE  mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.gitee.gen.mapper.TemplateGroupMapper">
+    <resultMap id="BaseResultMap" type="com.gitee.gen.entity.TemplateGroup">
+        <result column="id" property="id" />
+        <result column="group_name" property="groupName" />
+        <result column="is_deleted" property="isDeleted" />
+    </resultMap>
+
+    <!-- 表字段 -->
+    <sql id="baseColumns">
+         t.id
+        , t.group_name
+        , t.is_deleted
+        </sql>
+
+    <!-- 查询全部 -->
+    <select id="listAll" resultMap="BaseResultMap">
+        SELECT
+        <include refid="baseColumns" />
+        FROM template_group t
+        WHERE t.is_deleted = 0
+    </select>
+
+    <!-- 根据主键获取单条记录 -->
+    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
+        SELECT
+        <include refid="baseColumns" />
+        FROM template_group t
+        WHERE id = #{id}
+    </select>
+
+    <!-- 插入全部字段 -->
+    <insert id="insert" parameterType="com.gitee.gen.entity.TemplateGroup"
+            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
+    >
+        INSERT INTO template_group
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            group_name,
+            is_deleted,
+        </trim>
+        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
+            #{groupName},
+            #{isDeleted},
+        </trim>
+    </insert>
+
+    <!-- 插入不为NULL的字段 -->
+    <insert id="insertIgnoreNull" parameterType="com.gitee.gen.entity.TemplateGroup"
+            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
+    >
+        INSERT INTO template_group
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+
+            <if test="groupName != null">
+                group_name,
+            </if>
+            <if test="isDeleted != null">
+                is_deleted,
+            </if>
+        </trim>
+        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
+            <if test="groupName != null" >
+                #{groupName},
+            </if>
+            <if test="isDeleted != null" >
+                #{isDeleted},
+            </if>
+        </trim>
+    </insert>
+
+    <!-- 更新,更新全部字段 -->
+    <update id="update" parameterType="com.gitee.gen.entity.TemplateGroup">
+        UPDATE template_group
+        <set>
+            group_name=#{groupName},
+            is_deleted=#{isDeleted},
+        </set>
+        WHERE id = #{id}
+    </update>
+
+
+    <!-- 更新不为NULL的字段 -->
+    <update id="updateIgnoreNull" parameterType="com.gitee.gen.entity.TemplateGroup">
+        UPDATE template_group
+        <set>
+            <if test="groupName != null" >
+                group_name=#{groupName},
+            </if>
+            <if test="isDeleted != null" >
+                is_deleted=#{isDeleted},
+            </if>
+        </set>
+        WHERE id = #{id}
+    </update>
+
+
+    <!-- 根据主键删除记录 -->
+    <delete id="delete" parameterType="com.gitee.gen.entity.TemplateGroup">
+		UPDATE template_group
+		SET is_deleted = 1
+		WHERE id = #{id}
+	</delete>
+
+
+</mapper>

File diff suppressed because it is too large
+ 1 - 1
gen/src/main/resources/public/index.html


gen/src/main/resources/public/static/css/app.e2731d09.css → gen/src/main/resources/public/static/css/app.aa6ee3c8.css


gen/src/main/resources/public/static/css/chunk-0a388286.2864c242.css → gen/src/main/resources/public/static/css/chunk-34242e28.2864c242.css


+ 1 - 1
gen/src/main/resources/public/static/css/chunk-5fb3a2ba.36069daf.css

@@ -1 +1 @@
-.code-gen{margin:0 auto;width:70%}.code-gen .el-input{width:450px}.code-gen .el-row h4{text-align:center}.code-gen .el-row .el-button{margin-top:20px}.el-table .hidden-row{display:none}
+.code-gen{margin:0 auto;width:70%}.code-gen .el-input{width:450px}.code-gen .el-row h4{text-align:center}.code-gen .el-row .el-button{margin-top:20px}.el-table .hidden-row{display:none}#templateSelect .el-input{width:100%}

gen/src/main/resources/public/static/css/chunk-70c97e3b.a254e507.css → gen/src/main/resources/public/static/css/chunk-44188c88.a254e507.css


File diff suppressed because it is too large
+ 1 - 1
gen/src/main/resources/public/static/css/chunk-libs.2aad8290.css


File diff suppressed because it is too large
+ 1 - 0
gen/src/main/resources/public/static/js/app.0cd732f6.js


File diff suppressed because it is too large
+ 0 - 1
gen/src/main/resources/public/static/js/app.3a6801a7.js


File diff suppressed because it is too large
+ 0 - 1
gen/src/main/resources/public/static/js/chunk-0a388286.be225d9f.js


gen/src/main/resources/public/static/js/chunk-2d0efd67.3b6b1643.js → gen/src/main/resources/public/static/js/chunk-2d0efd67.7dba06b9.js


File diff suppressed because it is too large
+ 1 - 0
gen/src/main/resources/public/static/js/chunk-2d228903.4316af3a.js


File diff suppressed because it is too large
+ 0 - 1
gen/src/main/resources/public/static/js/chunk-2d228903.72e29674.js


File diff suppressed because it is too large
+ 1 - 0
gen/src/main/resources/public/static/js/chunk-34242e28.ce617928.js


File diff suppressed because it is too large
+ 1 - 0
gen/src/main/resources/public/static/js/chunk-4295c974.c99d0862.js


File diff suppressed because it is too large
+ 1 - 0
gen/src/main/resources/public/static/js/chunk-44188c88.3620cd3a.js


File diff suppressed because it is too large
+ 0 - 1
gen/src/main/resources/public/static/js/chunk-4de1c2b6.2c1febca.js


File diff suppressed because it is too large
+ 1 - 0
gen/src/main/resources/public/static/js/chunk-4de1c2b6.9c50e0a4.js


File diff suppressed because it is too large
+ 4 - 2
gen/src/main/resources/public/static/js/chunk-53ca05b2.2b9ec4ce.js


File diff suppressed because it is too large
+ 0 - 1
gen/src/main/resources/public/static/js/chunk-5fb3a2ba.37de9787.js


File diff suppressed because it is too large
+ 0 - 1
gen/src/main/resources/public/static/js/chunk-70c97e3b.3c1cab1d.js


File diff suppressed because it is too large
+ 1 - 0
gen/src/main/resources/public/static/js/chunk-74aeca77.f3100fa9.js


File diff suppressed because it is too large
+ 0 - 60
gen/src/main/resources/public/static/js/chunk-libs.3c441178.js


File diff suppressed because it is too large
+ 60 - 0
gen/src/main/resources/public/static/js/chunk-libs.62e97045.js


+ 4 - 4
readme.md

@@ -12,7 +12,7 @@
 
 - 前往[发行版页面](https://gitee.com/durcframework/code-gen/releases),下载最新版本zip文件
 - 解压zip,如果是Mac/Linux操作系统,运行`startup.sh`文件启动,Windows操作系统运行cmd输入`java -jar gen.jar`启动
-- 浏览器访问`http://localhost:6969/`
+- 浏览器访问`http://localhost:9999/`
 
 默认端口是6969,更改端口号按如下方式:
 
@@ -25,7 +25,7 @@
 
 `docker pull tanghc2020/gen:latest`
 
-下载完毕后,执行`docker run --name gen -p 6969:6969 -d <镜像ID>`
+下载完毕后,执行`docker run --name gen -p 9999:9999 -d <镜像ID>`
 
 浏览器访问`http://ip:6969/`
 
@@ -33,7 +33,7 @@
 
 clone代码,然后执行`docker-build.sh`脚本
 
-执行`docker run --name gen -p 6969:6969 -d <镜像ID>`
+执行`docker run --name gen -p 9999:9999 -d <镜像ID>`
 
 ## 其它
 
@@ -67,7 +67,7 @@ Mac/Linux系统可直接执行`build.sh`进行构建,构建结果在`dist`文
     - 执行`mvn clean package`,在`gen/target`下会生成一个`gen-xx-SNAPSHOT.jar`(xx表示本号)
     - 将`gen-xx-SNAPSHOT.jar`和db下的`gen.db`放在同一个文件夹下
     - 执行`java -jar gen-xx-SNAPSHOT.jar`
-    - 浏览器访问`http://localhost:6969/`
+    - 浏览器访问`http://localhost:9999/`
 
 ## 效果图