diff --git a/.gitignore b/.gitignore index 8046121..b7c1fd5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ +/static ### STS ### .apt_generated diff --git a/Dockerfile b/Dockerfile index 45e904a..01c1ee9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,8 @@ FROM java:8 VOLUME /tmp + +ADD gen/target/*.jar gen.jar +ADD dist/gen/view view + ADD gen/target/*.jar gen.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/gen.jar"] \ No newline at end of file diff --git a/build.sh b/build.sh index 5e1ae95..9234d86 100644 --- a/build.sh +++ b/build.sh @@ -7,22 +7,22 @@ dist_dir="dist" # 输出目录 target_dir="$dist_dir/$app_name" +rm -rf $dist_dir + echo "开始构建..." cd front -sh build.sh +npm install --unsafe-perm -cd .. +npm run build:prod --unsafe-perm +cd .. mvn clean package echo "复制文件到$target_dir" -rm -rf $dist_dir -mkdir -p $target_dir - cp -r gen/target/*.jar $target_dir/gen.jar cp -r script/* $target_dir diff --git a/changelog.md b/changelog.md index f2a063f..6b7a989 100644 --- a/changelog.md +++ b/changelog.md @@ -1,88 +1,181 @@ # changelog -## 1.4.0 +## 待定(暂不发版) +- 前端:代码生成页面新增仅下载文件功能 +- 前端:文件目录支持点分割以创建多级目录,如`service.impl` +- 前端:修改生成的zip包的名称为`code-yyyyMMddHHmmss.zip` +- 后端:模板列表按照文件名排序 + +## 1.5.4.2 +- 新增swagger风格模板 +- 模板新增${table.label}变量 +- 修复生成表字段后顺序不对的情况 + +## 1.5.4.1 +- 前端:调整数据源呈现格式 +- 前端:生成结果页面新增再次生成,方便修改模板时调试生成结果 +- 前后端:模板增加备注信息,更方便区分模板 +- 前后端:生成历史新增删除构建历史功能,并调整列表呈现内容 + +## 1.5.4 +- 模板新增${column.label}变量 + +## 1.5.3 +- 前端:修复修改数据源时候不管什么数据库都带出oracle数据库 +- 前端:新增oracle类型数据库数据库角色可以为空 +- 前端:修复数据库类型为oracle数据库时候测试连接服务器字段展示undefined问题 +- 前后端:新增author作者名配置,方便模板中插入作者 +- 后端:修复postgresql数据库表如果没有设置主键无法获取列数组问题 + +## 1.5.2 +- 支持`SqlServer`字段长度信息(`${column.maxLength}`,`${column.scale}`) +- 修复没有主键无法生成问题 + +## 1.5.1 +- 表字段信息,增加字段长度信息(`${column.maxLength}`,`${column.scale}`),目前只支持 mysql 和 oracle. [PR](https://gitee.com/durcframework/code-gen/pulls/12) + +## 1.5.0 +**注意:** + +> 从1.5.0开始前端打包后的文件不再放到`resource/public`下,而是单独放到外面`gen/view`下。 +> 理论上前端打包后的文件也属于编译后的文件,同class文件一样,不能提交到git,git只存放源码,这样在合并PR的时候会减少文件的冲突。 + +- 支持oracle服务名和SID连接 [pr](https://gitee.com/durcframework/code-gen/pulls/11) +- 支持模板指定目录名称 by Mario Luo +- 支持模板导入导出 by Mario Luo +- 优化表前缀删除功能 by Mario Luo +- 调整静态文件编译目录 + +## 1.4.16 +- 修复表名前缀替换问题 [pr](https://gitee.com/durcframework/code-gen/pulls/9/files) + +## 1.4.15 +- 修复PostgreSQL的numeric字段映射问题 + +## 1.4.14 +- 修复`不支持“variant”数据类型`错误 [#I3CSLO](https://gitee.com/durcframework/code-gen/issues/I3CSLO) +- 修复数据库名字带点.生成错误问题 [#I2EBRL](https://gitee.com/durcframework/code-gen/issues/I2EBRL) + +## 1.4.13 +- 优化类型转换 + +## 1.4.12 +- PostgreSQL数据源可指定schema(模板中可使用:`${table.schema}`) + +## 1.4.11 +- 优化模板管理交互 + +## 1.4.10 +- 修复PostgreSQL数值类型映射问题 + +## 1.4.9 +- 新增`${context.delPrefix}变量(删除前缀)` + +## 1.4.8 +- 支持PostgreSQL的jsonb类型 + +## 1.4.7 +- 修复PostgreSQL生成多个相同字段问题 +- 优化PostgreSQL精度类型 +- 优化Mysql表查询 [#I3C57N](https://gitee.com/durcframework/code-gen/issues/I3C57N) +- 修复可以看到删除掉的模板 [#I3AX6E](https://gitee.com/durcframework/code-gen/issues/I3AX6E) + + +## 1.4.6 +- 模板新增时间变量 +``` +${context.datetime}:日期时间,年月日时分秒 +${context.date}:日期,年月日 +${context.time}:时间,时分秒 +``` + +## 1.4.5 +- 可以格式化xml代码(application.properties中设置`gen.format-xml=true`) +## 1.4.4 +- jtds驱动替换成sqljdbc4 + +## 1.4.3 +- 【优化】模板编辑页面滚动条下拉可固定右侧变量区域 +- 【优化】模板编辑页面保存按钮优化 + +## 1.4.2 +- 修复oracle下同一库不同用户无法显示表问题 +- 修复模板名称重复问题 +- 数据源下拉框显示用户名 +- 修复${table.hasBigDecimalField}不生效问题 + +## 1.4.1 +- 修复数据库字段单个单词全部大写的情况下,实体字段会全部大写 +- 修复oracle的number类型映射问题 +- 生成代码页面自动选择上一次数据源 +- 修复新建模版template_config里group_name会丢失问题 + +## 1.4.0 - 增加模板组,可以根据需求选择不同的组的模板 - 可以给数据源配置默认的包名、删除前缀、以及模板组 - 表名检索忽略大小写 - 新增生成历史,可以对历史配置再次生成代码 ## 1.3.5 - - 修复mybatis的jdbcType隐射BIGINT错误 - 修复oracle隐射number类型错误 ## 1.3.4 - - 修复Mysql表名为关键字生成报错问题 - 优化交互 ## 1.3.3 - - 修复生成结果无法过滤文件错误 ## 1.3.2 - - 优化启动脚本 ## 1.3.1 - - 修复筛选表格后全选选中所有数据BUG ## 1.3.0 - - 支持C#变量,可生成C#文件 - 支持表过滤 - 支持数据源复制 ## 1.2.2 - - 优化模板编辑界面 ## 1.2.1 - - 修复保存模板时的错误 - 模板编辑器新增行号 - 新增admin-vue-CRUD模板 [doc](https://gitee.com/durcframework/code-gen/wikis/pages?sort_id=2688205&doc_id=27724) ## 1.2.0 - - 支持PostgreSQL ## 1.1.4 - - 修改mysql驱动为com.mysql.cj.jdbc.Driver - 修改mysql jdbc连接串,增加serverTimezone=Asia/Shanghai - 修复数据库名(dbName)包含'-'的异常.如(platform-cloud) ## 1.1.3 - - 新增${context.dbName}数据库名称变量 ## 1.1.2 - - 调整生成结果树状展示 ## 1.1.1 - - 优化下划线字段转驼峰字段算法 [I1PDHW](https://gitee.com/durcframework/code-gen/issues/I1PDHW) ## 1.1.0 - - 结果页面可下载代码 - 优化Connection连接数 - 修复测试连接问题 ## 1.0.2 - - 优化交互 ## 1.0.1 - - 新增复制代码功能 ## 1.0.0 - - 重构前端页面,采用elementUI - 优化了生成步骤 - 优化了模板编辑页面 diff --git a/db/mysql.sql b/db/mysql.sql index df956ad..bcd6607 100644 --- a/db/mysql.sql +++ b/db/mysql.sql @@ -23,6 +23,7 @@ CREATE TABLE `datasource_config` ( CREATE TABLE `template_config` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL DEFAULT '' COMMENT '模板名称', + `folder` varchar(64) NOT NULL DEFAULT '' COMMENT '目录名称', `file_name` varchar(128) NOT NULL DEFAULT '' COMMENT '文件名称', `content` text NOT NULL COMMENT '内容', `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除,1:已删除,0:未删除', diff --git a/docker-build.sh b/docker-build.sh index 290117b..909202f 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -1,9 +1,10 @@ #!/bin/sh -# 打包并运行docker镜像 +git pull + +sh build.sh -# 打包 -mvn clean package +# 打包并运行docker镜像 # 创建镜像 docker build -t tanghc2020/gen . diff --git a/front/README.md b/front/README.md index bf593f5..ac13180 100644 --- a/front/README.md +++ b/front/README.md @@ -4,8 +4,8 @@ 1. 启动服务端程序 2. `cd front` -3. 执行`npm install --registry=https://registry.npm.taobao.org` -4. 执行`npm run dev`,访问`http://localhost:9528/` +3. 执行`npm install --registry=https://registry.npm.taobao.org`,(下载依赖,执行一次即可) +4. 执行`npm run dev`,访问`http://localhost:9528/`,(后续每次启动都需要执行) - 修改端口号:打开`vue.config.js`,找到`port`属性 @@ -14,9 +14,4 @@ - 自动构建 -执行`build.sh` - -- 手动构建 - - - 执行`npm run build:prod`进行打包,结果在dist下 - - 把dist中的所有文件,放到`gen/src/main/resources/public`下 \ No newline at end of file +执行`npm run build:prod` diff --git a/front/build.sh b/front/build.sh deleted file mode 100644 index 7e13131..0000000 --- a/front/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -server_dest="../gen/src/main/resources/public" - -rm -rf dist/* -npm run build:prod -echo "复制dist文件内容到$server_dest" -rm -rf $server_dest -mkdir -p $server_dest -cp -r dist/* $server_dest diff --git a/front/package.json b/front/package.json index 144794e..2857973 100644 --- a/front/package.json +++ b/front/package.json @@ -6,8 +6,9 @@ "license": "MIT", "scripts": { "dev": "vue-cli-service serve", - "build:prod": "vue-cli-service build", - "build:stage": "vue-cli-service build --mode staging", + "build:dev": "vue-cli-service build --dest ../gen/target/view", + "build:prod": "vue-cli-service build --dest ../dist/gen/view", + "build:stage": "vue-cli-service build --mode staging --dest ../dist/gen/view", "preview": "node build/index.js --preview", "lint": "eslint --ext .js,.vue src", "test:unit": "jest --clearCache && vue-cli-service test:unit", diff --git a/front/public/velocity/csharp.json b/front/public/velocity/csharp.json index 2d75947..d6f77a7 100644 --- a/front/public/velocity/csharp.json +++ b/front/public/velocity/csharp.json @@ -39,6 +39,10 @@ { "expression": "${pk.comment}", "text": "主键字段注释" + }, + { + "expression": "${pk.label}", + "text": "返回注释,没有则返回数据库字段名" } ] }, @@ -46,6 +50,10 @@ "expression": "${context}", "text": "", "children": [ + { + "expression": "${context.author}", + "text": "作者名" + }, { "expression": "${context.dbName}", "text": "数据库名" @@ -58,9 +66,25 @@ "expression": "${context.packageName}", "text": "namespace" }, + { + "expression": "${context.delPrefix}", + "text": "删除前缀" + }, { "expression": "${context.pkName}", "text": "表主键名" + }, + { + "expression": "${context.datetime}", + "text": "日期时间,年月日时分秒" + }, + { + "expression": "${context.date}", + "text": "日期,年月日" + }, + { + "expression": "${context.time}", + "text": "时间,时分秒" } ] }, @@ -75,6 +99,14 @@ { "expression": "${table.comment}", "text": "表注释" + }, + { + "expression": "${table.schema}", + "text": "PostgreSQL中的Schema" + }, + { + "expression": "${table.label}", + "text": "返回表注释,没有则返回表名" } ] }, @@ -121,6 +153,18 @@ { "expression": "${column.comment}", "text": "字段注释" + }, + { + "expression": "${column.label}", + "text": "返回注释,没有则返回数据库字段名" + }, + { + "expression": "${column.maxLength}", + "text": "字段长度" + }, + { + "expression": "${column.scale}", + "text": "小数位长度" } ] } diff --git a/front/public/velocity/java.json b/front/public/velocity/java.json index 91585ff..bbce7ba 100644 --- a/front/public/velocity/java.json +++ b/front/public/velocity/java.json @@ -39,6 +39,10 @@ { "expression": "${pk.comment}", "text": "主键字段注释" + }, + { + "expression": "${pk.label}", + "text": "返回注释,没有则返回数据库字段名" } ] }, @@ -46,6 +50,10 @@ "expression": "${context}", "text": "", "children": [ + { + "expression": "${context.author}", + "text": "作者名" + }, { "expression": "${context.dbName}", "text": "数据库名" @@ -54,6 +62,10 @@ "expression": "${context.packageName}", "text": "包名" }, + { + "expression": "${context.delPrefix}", + "text": "删除前缀" + }, { "expression": "${context.javaBeanName}", "text": "Java类名" @@ -62,6 +74,18 @@ "expression": "${context.javaBeanNameLF}", "text": "Java类名且首字母小写" }, + { + "expression": "${context.datetime}", + "text": "日期时间,年月日时分秒" + }, + { + "expression": "${context.date}", + "text": "日期,年月日" + }, + { + "expression": "${context.time}", + "text": "时间,时分秒" + }, { "expression": "${context.pkName}", "text": "表主键名" @@ -91,6 +115,14 @@ { "expression": "${table.comment}", "text": "表注释" + }, + { + "expression": "${table.schema}", + "text": "PostgreSQL中的Schema" + }, + { + "expression": "${table.label}", + "text": "返回表注释,没有则返回表名" } ] }, @@ -145,6 +177,18 @@ { "expression": "${column.comment}", "text": "字段注释" + }, + { + "expression": "${column.label}", + "text": "返回注释,没有则返回数据库字段名" + }, + { + "expression": "${column.maxLength}", + "text": "字段长度" + }, + { + "expression": "${column.scale}", + "text": "小数位长度" } ] } diff --git a/front/src/icons/svg/github.svg b/front/src/icons/svg/github.svg new file mode 100644 index 0000000..935204b --- /dev/null +++ b/front/src/icons/svg/github.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/front/src/layout/components/Navbar.vue b/front/src/layout/components/Navbar.vue index 47275cd..1431db2 100644 --- a/front/src/layout/components/Navbar.vue +++ b/front/src/layout/components/Navbar.vue @@ -1,11 +1,17 @@ diff --git a/front/src/router/index.js b/front/src/router/index.js index 65f8915..d479f59 100644 --- a/front/src/router/index.js +++ b/front/src/router/index.js @@ -69,20 +69,6 @@ export const constantRoutes = [ } ] }, - { - path: '/group', - component: Layout, - meta: { title: '模板组管理', icon: 'example' }, - redirect: '/group/list', - children: [ - { - path: 'list', - name: 'List', - component: () => import('@/views/group/index'), - meta: { title: '模板组管理' } - } - ] - }, { path: '/template', component: Layout, diff --git a/front/src/utils/date.js b/front/src/utils/date.js new file mode 100644 index 0000000..c57ef43 --- /dev/null +++ b/front/src/utils/date.js @@ -0,0 +1,85 @@ +/** + * 时间工具类 + * @author lxy + */ + +/** 日期格式 命名参考hutool工具类 */ +var date_format = { + /** 标准日期格式:yyyy-MM-dd */ + normDatePattern: "yyyy-MM-dd", + /** 标准时间格式:hh:mm:ss */ + normTimePattern : "HH:mm:ss", + /** 标准日期时间格式,精确到分:yyyy-MM-dd HH:mm */ + normDatetimeMinutePattern:"yyyy-MM-dd HH:mm", + /** 标准日期时间格式,精确到秒:yyyy-MM-dd HH:mm:ss */ + normDatetimePattern:"yyyy-MM-dd HH:mm:ss", + /** 标准日期时间格式,精确到毫秒:yyyy-MM-dd HH:mm:ss.SSS */ + normDatetimeMsPattern:"yyyy-MM-dd HH:mm:ss.SSS", + /** 标准日期格式:yyyy年MM月dd日 */ + chineseDatePattern : "yyyy年MM月dd日", + /** 标准日期格式:yyyyMMdd */ + pureDatePattern : "yyyyMMdd", + /** 标准日期格式:HHmmss */ + pureTimePattern : "HHmmss", + /** 标准日期格式:yyyyMMddHHmmss */ + pureDatetimePattern : "yyyyMMddHHmmss", + /** 标准日期格式:yyyyMMddHHmmssSSS */ + pureDatetimeMsPattern : "yyyyMMddHHmmssSSS", +}; + +export default { + /** + * 当前时间,格式 yyyy-MM-dd HH:mm:ss + * + * @return 当前时间的标准形式字符串 + */ + now() { + return new Date().format("yyyy-MM-dd HH:mm:ss"); + }, + /** + * 格式化日期时间 + * 格式 yyyy-MM-dd HH:mm:ss + * + * @param date 被格式化的日期 + * @param format 格式化 参考 {@link date_format} + * @return 格式化后的日期 + */ + formatDateTime(date,format) { + if(format == undefined || format ==null ){ + format = "yyyy-MM-dd HH:mm:ss"; + } + return date.format(format); + }, + /** + * 只支持毫秒级别时间戳,如果需要秒级别时间戳,请自行×1000 + * + * @param timestamp 时间戳 + * @return 时间对象 + */ + date(timestamp) { + return new Date(timestamp); + }, + date_format +}; + +Date.prototype.format = function(fmt) { + var o = { + "M+" : this.getMonth()+1, //月份 + "d+" : this.getDate(), //日 + "H+" : this.getHours(), //小时 + "h+" : this.getHours(), //小时 + "m+" : this.getMinutes(), //分 + "s+" : this.getSeconds(), //秒 + "q+" : Math.floor((this.getMonth()+3)/3), //季度 + "S" : this.getMilliseconds() //毫秒 + }; + if(/(y+)/.test(fmt)) { + fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); + } + for(var k in o) { + if(new RegExp("("+ k +")").test(fmt)){ + fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); + } + } + return fmt; +}; diff --git a/front/src/utils/global.js b/front/src/utils/global.js index 1f925d2..8f64523 100644 --- a/front/src/utils/global.js +++ b/front/src/utils/global.js @@ -27,6 +27,7 @@ Object.assign(Vue.prototype, { if (code === '0') { // 成功 callback && callback.call(that, resp) } else { + errorCallback && errorCallback.call(that, resp) that.$message.error(resp.msg) } }).catch(function(error) { @@ -76,6 +77,9 @@ Object.assign(Vue.prototype, { } }).catch(function() {}) }, + handleCommand: function(command) { + command() + }, /** * 重置表单 * @param formName 表单元素的ref @@ -84,6 +88,15 @@ Object.assign(Vue.prototype, { const frm = this.$refs[formName] frm && frm.resetFields() }, + setAttr: function(key, val) { + if (val === undefined) { + val = '' + } + localStorage.setItem(key, val + '') + }, + getAttr: function(key) { + return localStorage.getItem(key) + }, logout: function() { const fullPath = this.$route.fullPath if (fullPath.indexOf('login?redirect') === -1) { @@ -133,6 +146,6 @@ Object.assign(Vue.prototype, { element.click() - document.body.removeChild(element); + document.body.removeChild(element) } }) diff --git a/front/src/views/dashboard/index.vue b/front/src/views/dashboard/index.vue index 80a61c9..5b870d1 100644 --- a/front/src/views/dashboard/index.vue +++ b/front/src/views/dashboard/index.vue @@ -1,7 +1,13 @@ diff --git a/front/src/views/generate/GenerateConfig/index.vue b/front/src/views/generate/GenerateConfig/index.vue index 2897d39..fead86d 100644 --- a/front/src/views/generate/GenerateConfig/index.vue +++ b/front/src/views/generate/GenerateConfig/index.vue @@ -1,19 +1,10 @@ - - + diff --git a/front/src/views/generate/GenerateHistory/index.vue b/front/src/views/generate/GenerateHistory/index.vue index 05fe884..3748cfc 100644 --- a/front/src/views/generate/GenerateHistory/index.vue +++ b/front/src/views/generate/GenerateHistory/index.vue @@ -1,50 +1,28 @@