From 3ccbd635c9d8c350d09c4d78069634f54438ac1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=AF=BA?= <1253070437@qq.com> Date: Fri, 25 Dec 2020 18:18:30 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20=E5=BC=80=E6=BA=90=E7=89=88V1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _sql/xiaonuo-vue-pub.sql | 25 ++ .../src/api/modular/gen/codeGenerateManage.js | 106 +++++ _web/src/views/gen/codeGenerate/addForm.vue | 244 ++++++++++++ _web/src/views/gen/codeGenerate/editForm.vue | 253 ++++++++++++ _web/src/views/gen/codeGenerate/index.vue | 219 +++++++++++ xiaonuo-base/pom.xml | 1 + .../xiaonuo/core/consts/CommonConstant.java | 7 +- xiaonuo-base/xiaonuo-gen/README.md | 1 + xiaonuo-base/xiaonuo-gen/pom.xml | 44 +++ .../xiaonuo/generate/core/config/Config.java | 116 ++++++ .../core/context/XnVelocityContext.java | 52 +++ .../core/enums/TableFilteredFieldsEnum.java | 39 ++ .../generate/core/param/TableField.java | 48 +++ .../generate/core/param/XnCodeGenParam.java | 94 +++++ .../generate/core/tool/JavaSqlTool.java | 55 +++ .../generate/core/tool/NamingConTool.java | 48 +++ .../generate/core/tool/StringDateTool.java | 27 ++ .../cn/xiaonuo/generate/core/util/Util.java | 73 ++++ .../controller/CodeGenerateController.java | 149 +++++++ .../generate/modular/entity/CodeGenerate.java | 89 +++++ .../enums/CodeGenerateExceptionEnum.java | 75 ++++ .../modular/mapper/CodeGenerateMapper.java | 57 +++ .../mapper/mapping/CodeGenerateMapper.xml | 36 ++ .../modular/param/CodeGenerateParam.java | 98 +++++ .../result/InforMationColumnsResult.java | 34 ++ .../modular/result/InformationResult.java | 34 ++ .../modular/service/CodeGenerateService.java | 106 +++++ .../service/impl/CodeGenerateServiceImpl.java | 368 ++++++++++++++++++ .../resources/template/Controller.java.vm | 137 +++++++ .../resources/template/ExceptionEnum.java.vm | 64 +++ .../src/main/resources/template/Manage.js.vm | 71 ++++ .../main/resources/template/Mapper.java.vm | 37 ++ .../src/main/resources/template/Mapper.xml.vm | 5 + .../src/main/resources/template/Param.java.vm | 48 +++ .../main/resources/template/Service.java.vm | 88 +++++ .../resources/template/ServiceImpl.java.vm | 136 +++++++ .../main/resources/template/addForm.vue.vm | 84 ++++ .../main/resources/template/editForm.vue.vm | 96 +++++ .../main/resources/template/entity.java.vm | 60 +++ .../src/main/resources/template/index.vue.vm | 135 +++++++ .../core/listener/ConstantsInitListener.java | 4 + xiaonuo-main/pom.xml | 7 + 42 files changed, 3469 insertions(+), 1 deletion(-) create mode 100644 _web/src/api/modular/gen/codeGenerateManage.js create mode 100644 _web/src/views/gen/codeGenerate/addForm.vue create mode 100644 _web/src/views/gen/codeGenerate/editForm.vue create mode 100644 _web/src/views/gen/codeGenerate/index.vue create mode 100644 xiaonuo-base/xiaonuo-gen/README.md create mode 100644 xiaonuo-base/xiaonuo-gen/pom.xml create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/config/Config.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/context/XnVelocityContext.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/enums/TableFilteredFieldsEnum.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/param/TableField.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/param/XnCodeGenParam.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/JavaSqlTool.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/NamingConTool.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/StringDateTool.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/util/Util.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/controller/CodeGenerateController.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/entity/CodeGenerate.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/enums/CodeGenerateExceptionEnum.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/mapper/CodeGenerateMapper.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/mapper/mapping/CodeGenerateMapper.xml create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/param/CodeGenerateParam.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/result/InforMationColumnsResult.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/result/InformationResult.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/service/CodeGenerateService.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/service/impl/CodeGenerateServiceImpl.java create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/Controller.java.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/ExceptionEnum.java.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/Manage.js.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/Mapper.java.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/Mapper.xml.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/Param.java.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/Service.java.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/ServiceImpl.java.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/addForm.vue.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/editForm.vue.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/entity.java.vm create mode 100644 xiaonuo-base/xiaonuo-gen/src/main/resources/template/index.vue.vm diff --git a/_sql/xiaonuo-vue-pub.sql b/_sql/xiaonuo-vue-pub.sql index 077552d0..3b4d3337 100644 --- a/_sql/xiaonuo-vue-pub.sql +++ b/_sql/xiaonuo-vue-pub.sql @@ -1000,3 +1000,28 @@ CREATE TABLE `sys_vis_log` ( -- ---------------------------- SET FOREIGN_KEY_CHECKS = 1; + +-- ---------------------------- +-- Table structure for `sys_code_generate` +-- ---------------------------- +DROP TABLE IF EXISTS `sys_code_generate`; +CREATE TABLE `sys_code_generate` ( + `id` bigint(20) NOT NULL COMMENT '主键', + `author_name` varchar(255) NOT NULL COMMENT '作者姓名', + `class_name` varchar(255) NOT NULL COMMENT '类名', + `table_prefix` varchar(255) NOT NULL COMMENT '是否移除表前缀', + `generate_type` varchar(255) NOT NULL COMMENT '生成位置类型', + `table_name` varchar(255) NOT NULL COMMENT '数据库表名', + `package_name` varchar(255) DEFAULT NULL COMMENT '包名称', + `bus_name` varchar(255) DEFAULT NULL COMMENT '业务名', + `table_comment` varchar(255) DEFAULT NULL COMMENT '功能名', + `create_user` bigint(20) DEFAULT NULL COMMENT '创建人', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + `update_user` bigint(20) DEFAULT NULL COMMENT '更新人', + `update_time` datetime DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='代码生成基础配置'; + +-- ---------------------------- +-- Records of sys_code_generate +-- ---------------------------- diff --git a/_web/src/api/modular/gen/codeGenerateManage.js b/_web/src/api/modular/gen/codeGenerateManage.js new file mode 100644 index 00000000..4f13b19e --- /dev/null +++ b/_web/src/api/modular/gen/codeGenerateManage.js @@ -0,0 +1,106 @@ +/** + * 代码生成 + * + * @author yubaoshan + * @date 2020/12/23 15:00 + */ +import { axios } from '@/utils/request' + +/** + * 查询列表 + * + * @author yubaoshan + * @date 2020/12/23 15:00 + */ +export function codeGeneratePage (parameter) { + return axios({ + url: '/codeGenerate/page', + method: 'get', + params: parameter + }) +} + +/** + * 增加 + * + * @author yubaoshan + * @date 2020/12/23 15:00 + */ +export function codeGenerateAdd (parameter) { + return axios({ + url: '/codeGenerate/add', + method: 'post', + data: parameter + }) +} + +/** + * 编辑 + * + * @author yubaoshan + * @date 2020/12/23 15:00 + */ +export function codeGenerateEdit (parameter) { + return axios({ + url: '/codeGenerate/edit', + method: 'post', + data: parameter + }) +} + +/** + * 删除 + * + * @author yubaoshan + * @date 2020/12/23 15:00 + */ +export function codeGenerateDelete (parameter) { + return axios({ + url: '/codeGenerate/delete', + method: 'post', + data: parameter + }) +} + +/** + * 查询当前数据库用户下的所有表 + * + * @author yubaoshan + * @date 2020/12/23 15:00 + */ +export function codeGenerateInformationList (parameter) { + return axios({ + url: '/codeGenerate/InformationList', + method: 'get', + params: parameter + }) +} + +/** + * 本地生成 + * + * @author yubaoshan + * @date 2020/12/23 15:00 + */ +export function codeGenerateRunLocal (parameter) { + return axios({ + url: '/codeGenerate/runLocal', + method: 'post', + data: parameter + }) +} + +/** + * 压缩包方式下载 + * + * @author yubaoshan + * @date 2020/12/23 15:00 + */ +export function codeGenerateRunDown (parameter) { + return axios({ + url: '/codeGenerate/runDown', + method: 'get', + params: parameter, + responseType: 'blob' + }) +} diff --git a/_web/src/views/gen/codeGenerate/addForm.vue b/_web/src/views/gen/codeGenerate/addForm.vue new file mode 100644 index 00000000..0b023725 --- /dev/null +++ b/_web/src/views/gen/codeGenerate/addForm.vue @@ -0,0 +1,244 @@ + + + diff --git a/_web/src/views/gen/codeGenerate/editForm.vue b/_web/src/views/gen/codeGenerate/editForm.vue new file mode 100644 index 00000000..987efbe5 --- /dev/null +++ b/_web/src/views/gen/codeGenerate/editForm.vue @@ -0,0 +1,253 @@ + + + diff --git a/_web/src/views/gen/codeGenerate/index.vue b/_web/src/views/gen/codeGenerate/index.vue new file mode 100644 index 00000000..c80915e7 --- /dev/null +++ b/_web/src/views/gen/codeGenerate/index.vue @@ -0,0 +1,219 @@ + + + diff --git a/xiaonuo-base/pom.xml b/xiaonuo-base/pom.xml index 74a1749b..13db0fe0 100644 --- a/xiaonuo-base/pom.xml +++ b/xiaonuo-base/pom.xml @@ -18,6 +18,7 @@ xiaonuo-core xiaonuo-system + xiaonuo-gen diff --git a/xiaonuo-base/xiaonuo-core/src/main/java/com/cn/xiaonuo/core/consts/CommonConstant.java b/xiaonuo-base/xiaonuo-core/src/main/java/com/cn/xiaonuo/core/consts/CommonConstant.java index 50885c99..73768302 100644 --- a/xiaonuo-base/xiaonuo-core/src/main/java/com/cn/xiaonuo/core/consts/CommonConstant.java +++ b/xiaonuo-base/xiaonuo-core/src/main/java/com/cn/xiaonuo/core/consts/CommonConstant.java @@ -27,7 +27,7 @@ package com.cn.xiaonuo.core.consts; /** * 通用常量 * - * @author xuyuxiang + * @author xuyuxiang yubaoshan * @date 2020/3/11 16:51 */ public interface CommonConstant { @@ -106,4 +106,9 @@ public interface CommonConstant { * 请求号在header中的唯一标识 */ String REQUEST_NO_HEADER_NAME = "Request-No"; + + /** + * 数据库链接URL标识 + */ + String DATABASE_URL_NAME = "DATABASE_URL_NAME"; } diff --git a/xiaonuo-base/xiaonuo-gen/README.md b/xiaonuo-base/xiaonuo-gen/README.md new file mode 100644 index 00000000..7854e6a6 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/README.md @@ -0,0 +1 @@ +** 代码生成 ** diff --git a/xiaonuo-base/xiaonuo-gen/pom.xml b/xiaonuo-base/xiaonuo-gen/pom.xml new file mode 100644 index 00000000..43c625cc --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + + cn.xiaonuo + xiaonuo-base + 1.1.0 + ../pom.xml + + + xiaonuo-gen + + jar + + + + cn.xiaonuo + xiaonuo-core + 1.1.0 + + + + + cn.xiaonuo + xiaonuo-system + 1.1.0 + + + + + org.apache.velocity + velocity + 1.7 + + + + + + ${project.artifactId} + + diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/config/Config.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/config/Config.java new file mode 100644 index 00000000..c9f54672 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/config/Config.java @@ -0,0 +1,116 @@ +package com.cn.xiaonuo.generate.core.config; + + +/** + * 代码生成配置 + * + * @author yubaoshan + * @date 2020-12-19 02:30:56 + */ +public class Config { + + /** + * 存放vm模板位置 + */ + public static String templatePath = "template/"; + + /** + * 主键标识 + */ + public static String DB_TABLE_COM_KRY = "PRI"; + + /** + * 模块名(一般为modular,无特殊要求一般不改) + */ + public static String MODULAR_NAME = "modular"; + + /** + * 本项目生成时是否覆盖 + */ + public static final boolean FLAG = false; + + /** + * 大模块名称(生成到代码中哪个模块下) + */ + public static String BASE_MODULAR_NAME = "xiaonuo-main"; + + /** + * java文件夹 + */ + public static String BASE_JAVA_PAHT = "\\src\\main\\java\\"; + + /** + * vue文件夹 + */ + public static String BASE_VUE_PAHT = "\\_web\\src\\"; + + /** + * 代码生成路径 + */ + public static String controllerPath; + public static String entityPath; + public static String enumsPath; + public static String mapperPath; + public static String mappingPath; + public static String paramPath; + public static String servicePath; + public static String serviceImplPath; + public static String manageJsPath; + public static String vueIndexPath; + public static String vueAddFromPath; + public static String vueEditFromPath; + + /** + * 各个代码存放路径文件夹 + */ + public static String[] xnCodeGenFilePath (String busName, String packageName) { + String packageNameString = packageName.replace(".","\\") + "\\"; + controllerPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + "\\" + busName + "\\" + "controller" + "\\"; + entityPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + "\\" + busName + "\\" + "entity" + "\\"; + enumsPath = BASE_JAVA_PAHT+ packageNameString + MODULAR_NAME + "\\" + busName + "\\" + "enums" + "\\"; + mapperPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + "\\" + busName + "\\" + "mapper" + "\\"; + mappingPath = mapperPath + "\\" + "mapping" + "\\"; + paramPath = BASE_JAVA_PAHT+ "\\" + packageNameString + MODULAR_NAME + "\\" + busName + "\\" + "param" + "\\"; + servicePath = BASE_JAVA_PAHT+ "\\" + packageNameString + MODULAR_NAME + "\\" + busName + "\\" + "service" + "\\"; + serviceImplPath = servicePath + "\\" + "impl" + "\\"; + manageJsPath = BASE_VUE_PAHT + "\\" + "api\\" + MODULAR_NAME + "\\main\\" + busName + "\\"; + vueIndexPath = BASE_VUE_PAHT + "\\" + "views\\main\\" + busName + "\\"; + vueAddFromPath = BASE_VUE_PAHT + "\\" + "views\\main\\" + busName + "\\"; + vueEditFromPath = BASE_VUE_PAHT + "\\" + "views\\main\\" + busName + "\\"; + return new String[] { + controllerPath, entityPath, enumsPath, mapperPath, mappingPath, paramPath, servicePath, serviceImplPath, manageJsPath, vueIndexPath, vueAddFromPath, vueEditFromPath + }; + } + + /** + * 模板文件 + */ + public static String[] xnCodeGenTempFile = { + "Controller.java.vm", + "entity.java.vm", + "ExceptionEnum.java.vm", + "Mapper.java.vm", + "Mapper.xml.vm", + "Param.java.vm", + "Service.java.vm", + "ServiceImpl.java.vm", + "Manage.js.vm", + "index.vue.vm", + "addForm.vue.vm", + "editForm.vue.vm", + }; + + /** + * 本地项目根目录 + */ + public static String getLocalPath () { + return System.getProperty("user.dir") + "\\" + BASE_MODULAR_NAME + "\\"; + } + + /** + * vue前端 + */ + public static String getLocalFrontPath () { + return System.getProperty("user.dir") + "\\" ; + } +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/context/XnVelocityContext.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/context/XnVelocityContext.java new file mode 100644 index 00000000..377a8a14 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/context/XnVelocityContext.java @@ -0,0 +1,52 @@ +package com.cn.xiaonuo.generate.core.context; + +import com.cn.xiaonuo.generate.core.param.XnCodeGenParam; +import org.apache.velocity.VelocityContext; + +/** + * 设置上下文缓存 + * + * @author yubaoshan + * @date 2020年12月17日02:04:56 + */ +public class XnVelocityContext { + + /** + * 创建上下文用到的参数 + * + * @author yubaoshan + * @date 2020年12月17日02:04:56 + */ + public VelocityContext createVelContext (XnCodeGenParam xnCodeGenParam) { + VelocityContext velocityContext = new VelocityContext(); + // 取得类名 + String DomainName = xnCodeGenParam.getClassName(); + String domainName = DomainName.substring(0,1).toLowerCase()+DomainName.substring(1); + // 类名称 + velocityContext.put("ClassName",DomainName); + // 类名(首字母小写) + velocityContext.put("className",domainName); + + // 功能名 + velocityContext.put("functionName",xnCodeGenParam.getFunctionName()); + + // 包名称 + velocityContext.put("packageName",xnCodeGenParam.getPackageName()); + // 模块名称 + velocityContext.put("modularName",xnCodeGenParam.getModularNane()); + // 业务名 + velocityContext.put("busName",xnCodeGenParam.getBusName()); + + // 作者姓名 + velocityContext.put("authorName", xnCodeGenParam.getAuthorName()); + // 代码生成时间 + velocityContext.put("createDateString", xnCodeGenParam.getCreateTimeString()); + + // 数据库表名 + velocityContext.put("tableName", xnCodeGenParam.getTableName()); + // 数据库字段 + velocityContext.put("tableField", xnCodeGenParam.getTableField()); + + return velocityContext; + } +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/enums/TableFilteredFieldsEnum.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/enums/TableFilteredFieldsEnum.java new file mode 100644 index 00000000..a6c388be --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/enums/TableFilteredFieldsEnum.java @@ -0,0 +1,39 @@ +package com.cn.xiaonuo.generate.core.enums; + +import lombok.Getter; + +/** + * 代码生成过程中被过滤的字段 + * + * @author yubaoshan + * @date 2020年12月17日00:11:40 + */ +@Getter +public enum TableFilteredFieldsEnum { + + CREATE_TIME("create_time"), + UPDATE_TIME("update_time"), + CREATE_USER("create_user"), + UPDATE_USER("update_user"); + + private final String propertyName; + + TableFilteredFieldsEnum(String propertyName) { + this.propertyName = propertyName; + } + + /** + * 是否本枚举包含该字段 + * + * @author yubaoshan + * @date 2020年12月17日00:11:40 + */ + public static boolean contains(String propertyName) { + for (TableFilteredFieldsEnum gunsFilteredFieldsEnum : TableFilteredFieldsEnum.values()) { + if (gunsFilteredFieldsEnum.propertyName.equals(propertyName)) { + return true; + } + } + return false; + } +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/param/TableField.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/param/TableField.java new file mode 100644 index 00000000..47c7f0f4 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/param/TableField.java @@ -0,0 +1,48 @@ +package com.cn.xiaonuo.generate.core.param; + +import lombok.Data; + +/** + * 数据库表字段实体 + * + * @author yubaoshan + * @date 2020年12月17日00:08:40 + */ +@Data +public class TableField { + + /** + * 字段名 + */ + public String columnName; + + /** + * 数据库中类型 + */ + public String dataType; + + /** + * 字段描述 + */ + public String columnComment; + + /** + * 主外键(用来做判断的) + */ + public String columnKey; + + /** + * 主键(转换后的) + */ + public String columnKeyName; + + /** + * Java类型(String,Integer,Date等) + */ + private String javaType; + + /** + * 是否是主键 + */ + private Boolean primaryKeyFlag = false; +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/param/XnCodeGenParam.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/param/XnCodeGenParam.java new file mode 100644 index 00000000..848ec3d0 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/param/XnCodeGenParam.java @@ -0,0 +1,94 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package com.cn.xiaonuo.generate.core.param; + +import com.cn.xiaonuo.generate.core.config.Config; +import lombok.Data; +import java.util.List; + +@Data +public class XnCodeGenParam { + + /** + * 作者姓名 + */ + private String authorName; + + /** + * 类名 + */ + private String className; + + /** + * 功能名 + */ + private String functionName; + + /** + * 是否移除表前缀 + */ + private String tablePrefix; + + /** + * 生成方式 + */ + private String generateType; + + /** + * 数据库表名 + */ + private String tableName; + + /** + * 数据库表名(经过组装的) + */ + private String tableNameAss; + + /** + * 代码包名 + */ + private String packageName; + + /** + * 生成时间(String类型的) + */ + private String createTimeString; + + /** + * 数据库表中字段集合 + */ + private List tableField; + + /** + * 模块名 + */ + private String modularNane = Config.MODULAR_NAME; + + /** + * 业务名 + */ + private String busName; + +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/JavaSqlTool.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/JavaSqlTool.java new file mode 100644 index 00000000..14ae71c0 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/JavaSqlTool.java @@ -0,0 +1,55 @@ +package com.cn.xiaonuo.generate.core.tool; + +/** + * java与sql工具类 + * + * @author yubaoshan + * @date 2020-12-17 23:42 + */ +public class JavaSqlTool { + + /** + * 数据类型转化JAVA + * + * @author yubaoshan + * @date 2020-12-17 23:42 + */ + public static String sqlToJava (String sqlType) { + if( sqlType == null || sqlType.trim().length() == 0 ) return sqlType; + sqlType = sqlType.toLowerCase(); + switch(sqlType){ + case "nvarchar":return "String"; + case "char":return "String"; + case "varchar":return "String"; + case "text":return "String"; + case "nchar":return "String"; + case "blob":return "byte[]"; + case "integer":return "Long"; + case "int":return "Integer"; + case "tinyint":return "Integer"; + case "smallint":return "Integer"; + case "mediumint":return "Integer"; + case "bit":return "Boolean"; + case "bigint":return "Long"; + case "float":return "Fload"; + case "double":return "Double"; + case "decimal":return "BigDecimal"; + case "boolean":return "Boolean"; + case "id":return "Long"; + case "date":return "Date"; + case "datetime":return "Date"; + case "year":return "Date"; + case "time":return "Time"; + case "timestamp":return "Timestamp"; + case "numeric":return "BigDecimal"; + case "real":return "BigDecimal"; + case "money":return "Double"; + case "smallmoney":return "Double"; + case "image":return "byte[]"; + default: + System.out.println("-----------------》转化失败:未发现的类型" + sqlType); + break; + } + return sqlType; + } +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/NamingConTool.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/NamingConTool.java new file mode 100644 index 00000000..42c3b421 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/core/tool/NamingConTool.java @@ -0,0 +1,48 @@ +package com.cn.xiaonuo.generate.core.tool; + +/** + * 命名转换 + * + * @author yubaoshan + * @date 2020-12-17 23:55 + */ +public class NamingConTool { + + /** + * 下划线命名转为驼峰命名 + * + * @author yubaoshan + * @date 2020-12-17 23:55 + */ + public static String UnderlineToHump(String para, String prefix){ + StringBuilder result=new StringBuilder(); + String a[]=para.split("_"); + for(String s:a){ + if(result.length()==0){ + result.append(s.toLowerCase()); + }else{ + result.append(s.substring(0, 1).toUpperCase()); + result.append(s.substring(1).toLowerCase()); + } + } + return result.toString(); + } + + /** + * 驼峰命名转为下划线命名 + * + * @author yubaoshan + * @date 2020-12-17 23:55 + */ + public static String HumpToUnderline(String para){ + StringBuilder sb=new StringBuilder(para); + int temp=0;//偏移量,第i个下划线的位置是 当前的位置+ 偏移量(i-1),第一个下划线偏移量是0 + for(int i=0;i page(CodeGenerateParam codeGenerateParam) { + return codeGenerateService.page(codeGenerateParam); + } + + /** + * 代码生成基础配置保存 + * + * @auther yubaoshan + * @date 12/15/20 11:20 PM + */ + @Permission + @PostMapping("/codeGenerate/add") + @BusinessLog(title = "代码生成配置_增加", opType = LogAnnotionOpTypeEnum.ADD) + public ResponseData add(@RequestBody @Validated(CodeGenerateParam.add.class) CodeGenerateParam codeGenerateParam) { + this.codeGenerateService.add(codeGenerateParam); + return new SuccessResponseData(); + } + + /** + * 代码生成基础配置编辑 + * + * @auther yubaoshan + * @date 2020年12月16日20:56:19 + */ + @Permission + @PostMapping("/codeGenerate/edit") + @BusinessLog(title = "代码生成配置_编辑", opType = LogAnnotionOpTypeEnum.EDIT) + public ResponseData edit(@RequestBody @Validated(CodeGenerateParam.add.class) CodeGenerateParam codeGenerateParam) { + codeGenerateService.edit(codeGenerateParam); + return new SuccessResponseData(); + } + + /** + * 删除代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日22:13:32 + */ + @Permission + @PostMapping("/codeGenerate/delete") + @BusinessLog(title = "代码生成配置_删除", opType = LogAnnotionOpTypeEnum.DELETE) + public ResponseData delete(@RequestBody @Validated(CodeGenerateParam.delete.class) List codeGenerateParamList) { + codeGenerateService.delete(codeGenerateParamList); + return new SuccessResponseData(); + } + + /** + * 查询当前数据库用户下的所有表 + * + * @author yubaoshan + * @date 2020-12-16 01:55:48 + */ + @Permission + @GetMapping("/codeGenerate/InformationList") + @BusinessLog(title = "数据库表列表_查询", opType = LogAnnotionOpTypeEnum.QUERY) + public ResponseData InformationList() { + return ResponseData.success(codeGenerateService.InformationTableList()); + } + + /** + * 代码生成基础配置生成 + * + * @auther yubaoshan + * @date 12/15/20 11:20 PM + */ + @Permission + @PostMapping("/codeGenerate/runLocal") + @BusinessLog(title = "代码生成_本地项目", opType = LogAnnotionOpTypeEnum.OTHER) + public ResponseData runLocal(@RequestBody @Validated(CodeGenerateParam.detail.class) CodeGenerateParam codeGenerateParam) { + this.codeGenerateService.runLocal(codeGenerateParam); + return new SuccessResponseData(); + } + + /** + * 代码生成基础配置生成 + * + * @auther yubaoshan + * @date 12/15/20 11:20 PM + */ + @Permission + @GetMapping("/codeGenerate/runDown") + @BusinessLog(title = "代码生成_下载方式", opType = LogAnnotionOpTypeEnum.OTHER) + public void runDown(@Validated(CodeGenerateParam.detail.class) CodeGenerateParam codeGenerateParam, HttpServletResponse response) { + this.codeGenerateService.runDown(codeGenerateParam, response); + } +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/entity/CodeGenerate.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/entity/CodeGenerate.java new file mode 100644 index 00000000..2d8f2943 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/entity/CodeGenerate.java @@ -0,0 +1,89 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package com.cn.xiaonuo.generate.modular.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cn.xiaonuo.core.pojo.base.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日21:04:37 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@TableName("sys_code_generate") +public class CodeGenerate extends BaseEntity { + + /** + * 主键 + */ + @TableId(type = IdType.ASSIGN_ID) + private Long id; + + /** + * 作者姓名 + */ + private String authorName; + + /** + * 类名 + */ + private String className; + + /** + * 是否移除表前缀 + */ + private String tablePrefix; + + /** + * 生成方式 + */ + private String generateType; + + /** + * 数据库表名 + */ + private String tableName; + /** + * 包名 + */ + private String packageName; + + /** + * 业务名(业务代码包名称) + */ + private String busName; + + /** + * 功能名(数据库表名称) + */ + private String tableComment; +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/enums/CodeGenerateExceptionEnum.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/enums/CodeGenerateExceptionEnum.java new file mode 100644 index 00000000..a7803018 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/enums/CodeGenerateExceptionEnum.java @@ -0,0 +1,75 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package com.cn.xiaonuo.generate.modular.enums; + +import com.cn.xiaonuo.core.annotion.ExpEnumType; +import com.cn.xiaonuo.core.exception.enums.abs.AbstractBaseExceptionEnum; +import com.cn.xiaonuo.core.factory.ExpEnumCodeFactory; +import com.cn.xiaonuo.sys.core.consts.SysExpEnumConstant; + +/** + * 代码生成基础配置相关异常枚举 + * + * @author yubaoshan + * @date 2020年12月16日21:21:14 + */ +@ExpEnumType(module = SysExpEnumConstant.XIAONUO_SYS_MODULE_EXP_CODE, kind = SysExpEnumConstant.SYS_APP_EXCEPTION_ENUM) +public enum CodeGenerateExceptionEnum implements AbstractBaseExceptionEnum { + + /** + * 代码生成基础配置不存在 + */ + CODE_GEN_NOT_EXIST(1, "代码生成基础配置不存在"), + + /** + * 本地生成代码输出路径错误 + */ + CODE_GEN_NOT_PATH(2,"本地生成代码输出路径错误"), + + /** + * 请检查此数据表中主键的定义 + */ + CODE_GEN_TABLE_NOT_PRI(3,"请检查此数据表中主键的定义"); + + private final Integer code; + + private final String message; + + CodeGenerateExceptionEnum(Integer code, String message) { + this.code = code; + this.message = message; + } + + @Override + public Integer getCode() { + return ExpEnumCodeFactory.getExpEnumCode(this.getClass(), code); + } + + @Override + public String getMessage() { + return message; + } + +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/mapper/CodeGenerateMapper.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/mapper/CodeGenerateMapper.java new file mode 100644 index 00000000..0745fc23 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/mapper/CodeGenerateMapper.java @@ -0,0 +1,57 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package com.cn.xiaonuo.generate.modular.mapper; + +import com.cn.xiaonuo.generate.modular.entity.CodeGenerate; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.cn.xiaonuo.generate.modular.result.InforMationColumnsResult; +import com.cn.xiaonuo.generate.modular.result.InformationResult; +import org.apache.ibatis.annotations.Param; +import java.util.List; + +/** + * 代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日21:07:28 + */ +public interface CodeGenerateMapper extends BaseMapper { + + /** + * 查询指定库中所有表 + * + * @author yubaoshan + * @date 2020年12月17日20:06:05 + */ + List selectInformationTable(@Param("dbName") String dbName); + + /** + * 查询指定表中所有字段 + * + * @author yubaoshan + * @date 2020年12月17日20:06:05 + */ + List selectInformationColumns(@Param("dbName") String dbName, @Param("tableName") String tableName); +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/mapper/mapping/CodeGenerateMapper.xml b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/mapper/mapping/CodeGenerateMapper.xml new file mode 100644 index 00000000..70d67740 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/mapper/mapping/CodeGenerateMapper.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/param/CodeGenerateParam.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/param/CodeGenerateParam.java new file mode 100644 index 00000000..6c214007 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/param/CodeGenerateParam.java @@ -0,0 +1,98 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package com.cn.xiaonuo.generate.modular.param; + +import com.cn.xiaonuo.core.pojo.base.param.BaseParam; +import com.cn.xiaonuo.core.validation.flag.FlagValue; +import lombok.Data; +import lombok.EqualsAndHashCode; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 代码生成参数类 + * + * @author yubaoshan + * @date 2020年12月16日20:41:21 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class CodeGenerateParam extends BaseParam { + + /** + * 主键 + */ + @NotNull(message = "id不能为空,请检查id参数", groups = {edit.class, delete.class, detail.class}) + private Long id; + + /** + * 作者姓名 + */ + @NotBlank(message = "作者姓名不能为空,请检查authorName参数", groups = {BaseParam.add.class, edit.class}) + private String authorName; + + /** + * 类名 + */ + @NotBlank(message = "类名不能为空,请检查className参数", groups = {BaseParam.add.class, edit.class}) + private String className; + + /** + * 是否移除表前缀 + */ + @NotBlank(message = "是否移除表前缀不能为空,请检查tablePrefix参数", groups = {BaseParam.add.class, edit.class}) + @FlagValue(message = "是否移除表前缀格式错误,正确格式应该Y或者N,请检查tablePrefix参数", groups = {add.class, edit.class}) + private String tablePrefix; + + /** + * 生成方式 + */ + @NotBlank(message = "生成方式不能为空,请检查generateType参数", groups = {BaseParam.add.class, edit.class}) + private String generateType; + + /** + * 数据库表名 + */ + @NotBlank(message = "数据库表名不能为空,请检查tableName参数", groups = {BaseParam.add.class, edit.class}) + private String tableName; + + /** + * 代码包名 + */ + private String packageName; + + /** + * 业务名(业务代码包名称) + */ + @NotBlank(message = "业务名不能为空,请检查busName参数", groups = {BaseParam.add.class, edit.class}) + private String busName; + + /** + * 功能名(数据库表名称) + */ + @NotBlank(message = "功能名不能为空,请检查tableComment参数", groups = {BaseParam.add.class, edit.class}) + private String tableComment; + +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/result/InforMationColumnsResult.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/result/InforMationColumnsResult.java new file mode 100644 index 00000000..c8946053 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/result/InforMationColumnsResult.java @@ -0,0 +1,34 @@ +package com.cn.xiaonuo.generate.modular.result; + +import lombok.Data; + +/** + * 数据库表中返回对象 + * + * @author yubaoshan + * @date 2020年12月17日20:00:31 + */ +@Data +public class InforMationColumnsResult { + + /** + * 字段名 + */ + public String columnName; + + /** + * 数据库中类型 + */ + public String dataType; + + /** + * 字段描述 + */ + public String columnComment; + + /** + * 主外键 + */ + public String columnKey; + +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/result/InformationResult.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/result/InformationResult.java new file mode 100644 index 00000000..f643991c --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/result/InformationResult.java @@ -0,0 +1,34 @@ +package com.cn.xiaonuo.generate.modular.result; + +import lombok.Data; + +/** + * 数据表返回对象 + * + * @author yubaoshan + * @date 2020年12月17日20:01:56 + */ +@Data +public class InformationResult { + + /** + * 表名(字母形式的) + */ + public String tableName; + + /** + * 创建时间 + */ + public String createTime; + + /** + * 更新时间 + */ + public String updateTime; + + /** + * 表名称描述(注释)(功能名) + */ + public String tableComment; + +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/service/CodeGenerateService.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/service/CodeGenerateService.java new file mode 100644 index 00000000..365d7fda --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/service/CodeGenerateService.java @@ -0,0 +1,106 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package com.cn.xiaonuo.generate.modular.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.cn.xiaonuo.core.pojo.page.PageResult; +import com.cn.xiaonuo.generate.modular.entity.CodeGenerate; +import com.cn.xiaonuo.generate.modular.param.CodeGenerateParam; +import com.cn.xiaonuo.generate.modular.result.InformationResult; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 代码生成基础配置service接口 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ +public interface CodeGenerateService extends IService { + + /** + * 查询代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ + PageResult page(CodeGenerateParam codeGenerateParam); + + /** + * 添加查询代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ + void add(CodeGenerateParam codeGenerateParam); + + /** + * 删除查询代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ + void delete(List codeGenerateParamList); + + /** + * 编辑查询代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ + void edit(CodeGenerateParam codeGenerateParam); + + /** + * 查看查询代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ + CodeGenerate detail(CodeGenerateParam codeGenerateParam); + + /** + * 查询当前数据库用户下的所有表 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ + List InformationTableList (); + + /** + * 本地生成代码 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ + void runLocal(CodeGenerateParam codeGenerateParam); + + /** + * 下载zip方式 + * + * @author yubaoshan + * @date 2020年12月16日21:03:15 + */ + void runDown(CodeGenerateParam codeGenerateParam, HttpServletResponse response); +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/service/impl/CodeGenerateServiceImpl.java b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/service/impl/CodeGenerateServiceImpl.java new file mode 100644 index 00000000..1db7d547 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/java/com/cn/xiaonuo/generate/modular/service/impl/CodeGenerateServiceImpl.java @@ -0,0 +1,368 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package com.cn.xiaonuo.generate.modular.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.cn.xiaonuo.core.consts.CommonConstant; +import com.cn.xiaonuo.core.context.constant.ConstantContext; +import com.cn.xiaonuo.core.exception.ServiceException; +import com.cn.xiaonuo.core.factory.PageFactory; +import com.cn.xiaonuo.core.pojo.page.PageResult; +import com.cn.xiaonuo.generate.core.context.XnVelocityContext; +import com.cn.xiaonuo.generate.core.param.TableField; +import com.cn.xiaonuo.generate.core.param.XnCodeGenParam; +import com.cn.xiaonuo.generate.core.tool.JavaSqlTool; +import com.cn.xiaonuo.generate.core.tool.NamingConTool; +import com.cn.xiaonuo.generate.core.tool.StringDateTool; +import com.cn.xiaonuo.generate.core.config.Config; +import com.cn.xiaonuo.generate.core.enums.TableFilteredFieldsEnum; +import com.cn.xiaonuo.generate.core.util.Util; +import com.cn.xiaonuo.generate.modular.entity.CodeGenerate; +import com.cn.xiaonuo.generate.modular.enums.CodeGenerateExceptionEnum; +import com.cn.xiaonuo.generate.modular.mapper.CodeGenerateMapper; +import com.cn.xiaonuo.generate.modular.param.CodeGenerateParam; +import com.cn.xiaonuo.generate.modular.result.InforMationColumnsResult; +import com.cn.xiaonuo.generate.modular.result.InformationResult; +import com.cn.xiaonuo.generate.modular.service.CodeGenerateService; +import org.apache.commons.io.IOUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.app.VelocityEngine; +import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + + +/** + * 代码生成基础配置service接口实现类 + * + * @author yubaoshan + * @date 2020年12月16日21:31:57 + */ +@Service +public class CodeGenerateServiceImpl extends ServiceImpl implements CodeGenerateService { + + /** + * 模板后缀 + */ + private static String TEMP_SUFFIX = ".vm"; + + /** + * 转换的编码 + */ + private static String ENCODED = "UTF-8"; + + /** + * 转换模板名称所需变量 + */ + private static String ADD_FORM_PAGE_NAME = "addForm.vue"; + private static String EDIT_FORM_PAGE_NAME = "editForm.vue"; + private static String INDEX_PAGE_NAME = "index.vue"; + private static String MANAGE_JS_NAME = "Manage.js"; + private static String JAVA_SUFFIX = ".java"; + private static String TEMP_ENTITY_NAME = "entity"; + + + @Override + public PageResult page(CodeGenerateParam codeGenerateParam) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotNull(codeGenerateParam)) { + //根据表名模糊查询 + if (ObjectUtil.isNotEmpty(codeGenerateParam.getTableName())) { + queryWrapper.lambda().like(CodeGenerate::getTableName, codeGenerateParam.getTableName()); + } + } + return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper)); + } + + @Override + public void add(CodeGenerateParam codeGenerateParam) { + CodeGenerate codeGenerate = new CodeGenerate(); + BeanUtil.copyProperties(codeGenerateParam, codeGenerate); + if (!vldTablePri(codeGenerate.getTableName())) { + throw new ServiceException(CodeGenerateExceptionEnum.CODE_GEN_TABLE_NOT_PRI); + } + this.save(codeGenerate); + } + + @Override + public void delete(List codeGenerateParamList) { + codeGenerateParamList.forEach(codeGenerateParam -> { + this.removeById(codeGenerateParam.getId()); + }); + } + + @Override + public void edit(CodeGenerateParam codeGenerateParam) { + CodeGenerate codeGenerate = this.queryCodeGenerate(codeGenerateParam); + BeanUtil.copyProperties(codeGenerateParam, codeGenerate); + if (!vldTablePri(codeGenerate.getTableName())) { + throw new ServiceException(CodeGenerateExceptionEnum.CODE_GEN_TABLE_NOT_PRI); + } + this.updateById(codeGenerate); + } + + @Override + public CodeGenerate detail(CodeGenerateParam codeGenerateParam) { + return this.queryCodeGenerate(codeGenerateParam); + } + + /** + * 获取代码生成基础配置 + * + * @author yubaoshan + * @date 2020年12月16日21:19:10 + */ + private CodeGenerate queryCodeGenerate(CodeGenerateParam codeGenerateParam) { + CodeGenerate codeGenerate = this.getById(codeGenerateParam.getId()); + if (ObjectUtil.isNull(codeGenerate)) { + throw new ServiceException(CodeGenerateExceptionEnum.CODE_GEN_NOT_EXIST); + } + return codeGenerate; + } + + @Override + public List InformationTableList () { + String databaseUrl = ConstantContext.me().getStr(CommonConstant.DATABASE_URL_NAME); + String dbName = databaseUrl.substring(Util.getIndex(databaseUrl, 3, "/") + 1, databaseUrl.indexOf("?")); + return this.baseMapper.selectInformationTable(dbName); + } + + @Override + public void runLocal(CodeGenerateParam codeGenerateParam) { + XnCodeGenParam xnCodeGenParam = copyParams(codeGenerateParam); + codeGenLocal(xnCodeGenParam); + } + + @Override + public void runDown(CodeGenerateParam codeGenerateParam, HttpServletResponse response) { + XnCodeGenParam xnCodeGenParam = copyParams(codeGenerateParam); + downloadCode(xnCodeGenParam, response); + } + + /** + * 校验表中是否包含主键 + * + * @author yubaoshan + * @date 2020年12月23日 00点32分 + */ + private boolean vldTablePri (String tableName) { + String databaseUrl = ConstantContext.me().getStr(CommonConstant.DATABASE_URL_NAME); + String dbName = databaseUrl.substring(Util.getIndex(databaseUrl, 3, "/") + 1, databaseUrl.indexOf("?")); + List inforMationColumnsResultList = this.baseMapper.selectInformationColumns(dbName, tableName); + for (int a = 0; a < inforMationColumnsResultList.size(); a++) { + if (inforMationColumnsResultList.get(a).columnKey.equals(Config.DB_TABLE_COM_KRY)) { + return true; + } + } + return false; + } + + /** + * 下载方式组装代码基础 + * + * @author yubaoshan + * @date 2020年12月23日 00点32分 + */ + private void downloadCode(XnCodeGenParam xnCodeGenParam, HttpServletResponse response) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); + codeGenDown(xnCodeGenParam, zipOutputStream); + IOUtils.closeQuietly(zipOutputStream); + outputStream.toByteArray(); + try { + Util.DownloadGen(response, outputStream.toByteArray()); + } catch (Exception e) { + throw new ServiceException(CodeGenerateExceptionEnum.CODE_GEN_NOT_PATH); + } + } + + /** + * 转换数据为代码生成上下文中所使用的数据 + * + * @author yubaoshan + * @date 2020年12月17日 23点30分 + */ + private XnCodeGenParam copyParams (CodeGenerateParam codeGenerateParam) { + CodeGenerate codeGenerate = this.queryCodeGenerate(codeGenerateParam); + String databaseUrl = ConstantContext.me().getStr(CommonConstant.DATABASE_URL_NAME); + String dbName = databaseUrl.substring(Util.getIndex(databaseUrl, 3, "/") + 1, databaseUrl.indexOf("?")); + List inforMationColumnsResultList = this.baseMapper.selectInformationColumns(dbName, codeGenerate.getTableName()); + + XnCodeGenParam param = new XnCodeGenParam(); + List tableFieldList = new ArrayList(); + inforMationColumnsResultList.forEach(item -> { + TableField tableField = new TableField(); + BeanUtil.copyProperties(item, tableField); + if (tableField.getColumnKey().equals(Config.DB_TABLE_COM_KRY)) { + tableField.setPrimaryKeyFlag(true); + String columnName = NamingConTool.UnderlineToHump(item.getColumnName(),""); + tableField.setColumnKeyName(columnName.substring(0,1).toUpperCase() + columnName.substring(1,columnName.length())); + } + + // 字段类型转换Java类型 + tableField.setJavaType(JavaSqlTool.sqlToJava(item.getDataType())); + + // 字段名称转换 + tableField.setColumnName(NamingConTool.UnderlineToHump(item.getColumnName(), codeGenerate.getTablePrefix())); + + // 过滤掉通用字段 + if (!TableFilteredFieldsEnum.contains(item.getColumnName())) { + tableFieldList.add(tableField); + } + }); + BeanUtil.copyProperties(codeGenerate, param); + // 功能名 + param.setFunctionName(codeGenerate.getTableComment()); + param.setTableField(tableFieldList); + param.setCreateTimeString(StringDateTool.getStringDate()); + return param; + } + + /** + * 本地项目生成 + */ + private void codeGenLocal (XnCodeGenParam xnCodeGenParam) { + XnVelocityContext context = new XnVelocityContext(); + //初始化参数 + Properties properties=new Properties(); + //设置velocity资源加载方式为class + properties.setProperty("resource.loader", "class"); + //设置velocity资源加载方式为file时的处理类 + properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + //实例化一个VelocityEngine对象 + VelocityEngine velocityEngine=new VelocityEngine(properties); + + String[] filePath = Config.xnCodeGenFilePath(xnCodeGenParam.getClassName().toLowerCase(), xnCodeGenParam.getPackageName()); + for (int i = 0; i < filePath.length; i++) { + String templateName = Config.xnCodeGenTempFile[i]; + + String fileBaseName = ResetFileBaseName(xnCodeGenParam.getClassName(), + templateName.substring(templateName.indexOf("/") + 1, templateName.lastIndexOf(TEMP_SUFFIX))); + String path = Config.getLocalPath (); + // 前端VUE位置有所变化 + if (fileBaseName.contains(INDEX_PAGE_NAME) || fileBaseName.contains(ADD_FORM_PAGE_NAME) || + fileBaseName.contains(EDIT_FORM_PAGE_NAME) ||fileBaseName.contains(MANAGE_JS_NAME)) { + path = Config.getLocalFrontPath(); + } + + File file = new File(path + filePath[i] + fileBaseName); + + //判断是否覆盖存在的文件 + if(file.exists() && !Config.FLAG){ + continue; + } + + //获取父目录 + File parentFile = file.getParentFile(); + if(!parentFile.exists()){ + parentFile.mkdirs(); + } + try { + Writer writer = new FileWriter(file); + velocityEngine.mergeTemplate(Config.templatePath + templateName,ENCODED,context.createVelContext(xnCodeGenParam),writer); + writer.close(); + } catch (Exception e) { + throw new ServiceException(CodeGenerateExceptionEnum.CODE_GEN_NOT_PATH); + } + } + } + + /** + * 下载ZIP方式 + */ + private void codeGenDown (XnCodeGenParam xnCodeGenParam,ZipOutputStream zipOutputStream) { + Util.initVelocity(); + XnVelocityContext context = new XnVelocityContext(); + + String[] filePath = Config.xnCodeGenFilePath(xnCodeGenParam.getClassName().toLowerCase(), xnCodeGenParam.getPackageName()); + for (int a = 0; a < filePath.length; a++) { + String templateName = Config.xnCodeGenTempFile[a]; + + String fileBaseName = ResetFileBaseName(xnCodeGenParam.getClassName(), + templateName.substring(templateName.indexOf("/") + 1, templateName.lastIndexOf(TEMP_SUFFIX))); + XnZipOutputStream(context.createVelContext(xnCodeGenParam), + Config.templatePath + templateName, + filePath[a] + fileBaseName, + zipOutputStream); + } + } + + /** + * 重置文件名称 + */ + private static String ResetFileBaseName (String className,String fileName) { + String fileBaseName = className + fileName; + // 实体类名称单独处理 + if (fileBaseName.contains(TEMP_ENTITY_NAME)) { + return className + JAVA_SUFFIX; + } + // 首页index.vue界面 + if (fileBaseName.contains(INDEX_PAGE_NAME)) { + return INDEX_PAGE_NAME; + } + // 表单界面名称 + if (fileBaseName.contains(ADD_FORM_PAGE_NAME)) { + return ADD_FORM_PAGE_NAME; + } + if (fileBaseName.contains(EDIT_FORM_PAGE_NAME)) { + return EDIT_FORM_PAGE_NAME; + } + // js名称 + if (fileBaseName.contains(MANAGE_JS_NAME)) { + return className.substring(0,1).toLowerCase() + className.substring(1) + MANAGE_JS_NAME; + } + return fileBaseName; + } + + /** + * 生成ZIP + */ + private void XnZipOutputStream (VelocityContext velContext,String tempName, String fileBaseName, ZipOutputStream zipOutputStream) { + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(tempName, ENCODED); + tpl.merge(velContext, sw); + try { + // 添加到zip + zipOutputStream.putNextEntry(new ZipEntry(fileBaseName)); + IOUtils.write(sw.toString(), zipOutputStream, ENCODED); + IOUtils.closeQuietly(sw); + zipOutputStream.flush(); + zipOutputStream.closeEntry(); + } catch (IOException e) { + throw new ServiceException(CodeGenerateExceptionEnum.CODE_GEN_NOT_PATH); + } + } + +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Controller.java.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Controller.java.vm new file mode 100644 index 00000000..79491ac2 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Controller.java.vm @@ -0,0 +1,137 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package ${packageName}.${modularName}.${busName}.controller; + +import com.cn.xiaonuo.core.annotion.BusinessLog; +import com.cn.xiaonuo.core.annotion.Permission; +import com.cn.xiaonuo.core.enums.LogAnnotionOpTypeEnum; +import com.cn.xiaonuo.core.pojo.page.PageResult; +import com.cn.xiaonuo.core.pojo.response.ResponseData; +import com.cn.xiaonuo.core.pojo.response.SuccessResponseData; +import ${packageName}.${modularName}.${busName}.entity.${ClassName}; +import ${packageName}.${modularName}.${busName}.param.${ClassName}Param; +import ${packageName}.${modularName}.${busName}.service.${ClassName}Service; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import javax.annotation.Resource; +import java.util.List; + +/** + * ${functionName}控制器 + * + * @author ${authorName} + * @date ${createDateString} + */ +@Controller +public class ${ClassName}Controller { + + @Resource + private ${ClassName}Service ${className}Service; + + /** + * 查询${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + @Permission + @GetMapping("/${className}/page") + @BusinessLog(title = "${functionName}_查询", opType = LogAnnotionOpTypeEnum.QUERY) + public PageResult<${ClassName}> page(${ClassName}Param ${className}Param) { + return ${className}Service.page(${className}Param); + } + + /** + * 添加${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + @Permission + @PostMapping("/${className}/add") + @BusinessLog(title = "${functionName}_增加", opType = LogAnnotionOpTypeEnum.ADD) + public ResponseData add(@RequestBody @Validated(${ClassName}Param.add.class) ${ClassName}Param ${className}Param) { + ${className}Service.add(${className}Param); + return new SuccessResponseData(); + } + + /** + * 删除${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + @Permission + @PostMapping("/${className}/delete") + @BusinessLog(title = "${functionName}_删除", opType = LogAnnotionOpTypeEnum.DELETE) + public ResponseData delete(@RequestBody @Validated(${ClassName}Param.delete.class) List<${ClassName}Param> ${className}ParamList) { + ${className}Service.delete(${className}ParamList); + return new SuccessResponseData(); + } + + /** + * 编辑${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + @Permission + @PostMapping("/${className}/edit") + @BusinessLog(title = "${functionName}_编辑", opType = LogAnnotionOpTypeEnum.EDIT) + public ResponseData edit(@RequestBody @Validated(${ClassName}Param.edit.class) ${ClassName}Param ${className}Param) { + ${className}Service.edit(${className}Param); + return new SuccessResponseData(); + } + + /** + * 查看${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + @Permission + @GetMapping("/${className}/detail") + @BusinessLog(title = "${functionName}_查看", opType = LogAnnotionOpTypeEnum.DETAIL) + public ResponseData detail(@Validated(${ClassName}Param.detail.class) ${ClassName}Param ${className}Param) { + return new SuccessResponseData(${className}Service.detail(${className}Param)); + } + + /** + * ${functionName}列表 + * + * @author ${authorName} + * @date ${createDateString} + */ + @Permission + @GetMapping("/${className}/list") + @BusinessLog(title = "${functionName}_列表", opType = LogAnnotionOpTypeEnum.QUERY) + public ResponseData list(${ClassName}Param ${className}Param) { + return new SuccessResponseData(${className}Service.list(${className}Param)); + } + +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/ExceptionEnum.java.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/ExceptionEnum.java.vm new file mode 100644 index 00000000..1de02725 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/ExceptionEnum.java.vm @@ -0,0 +1,64 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package ${packageName}.${modularName}.${busName}.enums; + +import com.cn.xiaonuo.core.annotion.ExpEnumType; +import com.cn.xiaonuo.core.exception.enums.abs.AbstractBaseExceptionEnum; +import com.cn.xiaonuo.core.factory.ExpEnumCodeFactory; +import com.cn.xiaonuo.sys.core.consts.SysExpEnumConstant; + +/** + * ${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ +@ExpEnumType(module = SysExpEnumConstant.XIAONUO_SYS_MODULE_EXP_CODE, kind = SysExpEnumConstant.SYS_POS_EXCEPTION_ENUM) +public enum ${ClassName}ExceptionEnum implements AbstractBaseExceptionEnum { + + /** + * 数据不存在 + */ + NOT_EXIST(1, "此数据不存在"); + + private final Integer code; + + private final String message; + ${ClassName}ExceptionEnum(Integer code, String message) { + this.code = code; + this.message = message; + } + + @Override + public Integer getCode() { + return ExpEnumCodeFactory.getExpEnumCode(this.getClass(), code); + } + + @Override + public String getMessage() { + return message; + } + +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Manage.js.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Manage.js.vm new file mode 100644 index 00000000..acce32eb --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Manage.js.vm @@ -0,0 +1,71 @@ +import { axios } from '@/utils/request' + +/** + * 查询${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ +export function ${className}Page (parameter) { + return axios({ + url: '/${className}/page', + method: 'get', + params: parameter + }) +} + +/** + * ${functionName}列表 + * + * @author ${authorName} + * @date ${createDateString} + */ +export function ${className}List (parameter) { + return axios({ + url: '/${className}/list', + method: 'get', + params: parameter + }) +} + +/** + * 添加${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ +export function ${className}Add (parameter) { + return axios({ + url: '/${className}/add', + method: 'post', + data: parameter + }) +} + +/** + * 编辑${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ +export function ${className}Edit (parameter) { + return axios({ + url: '/${className}/edit', + method: 'post', + data: parameter + }) +} + +/** + * 删除${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ +export function ${className}Delete (parameter) { + return axios({ + url: '/${className}/delete', + method: 'post', + data: parameter + }) +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Mapper.java.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Mapper.java.vm new file mode 100644 index 00000000..e32d6b5a --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Mapper.java.vm @@ -0,0 +1,37 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package ${packageName}.${modularName}.${busName}.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import ${packageName}.${modularName}.${busName}.entity.${ClassName}; + +/** + * ${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ +public interface ${ClassName}Mapper extends BaseMapper<${ClassName}> { +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Mapper.xml.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Mapper.xml.vm new file mode 100644 index 00000000..57d67cac --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Mapper.xml.vm @@ -0,0 +1,5 @@ + + + + + diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Param.java.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Param.java.vm new file mode 100644 index 00000000..d64b9610 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Param.java.vm @@ -0,0 +1,48 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package ${packageName}.${modularName}.${busName}.param; + +import com.cn.xiaonuo.core.pojo.base.param.BaseParam; +import lombok.Data; +import java.util.*; + + +/** +* ${functionName}参数类 + * + * @author ${authorName} + * @date ${createDateString} +*/ +@Data +public class ${ClassName}Param extends BaseParam { +#foreach ($column in $tableField) + + /** + * ${column.columnComment} + */ + private ${column.javaType} ${column.columnName}; + +#end +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Service.java.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Service.java.vm new file mode 100644 index 00000000..31550e7f --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/Service.java.vm @@ -0,0 +1,88 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package ${packageName}.${modularName}.${busName}.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.cn.xiaonuo.core.pojo.page.PageResult; +import ${packageName}.${modularName}.${busName}.entity.${ClassName}; +import ${packageName}.${modularName}.${busName}.param.${ClassName}Param; +import java.util.List; + +/** + * ${functionName}service接口 + * + * @author ${authorName} + * @date ${createDateString} + */ +public interface ${ClassName}Service extends IService<${ClassName}> { + + /** + * 查询${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + PageResult<${ClassName}> page(${ClassName}Param ${className}Param); + + /** + * ${functionName}列表 + * + * @author ${authorName} + * @date ${createDateString} + */ + List<${ClassName}> list(${ClassName}Param ${className}Param); + + /** + * 添加${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + void add(${ClassName}Param ${className}Param); + + /** + * 删除${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + void delete(List<${ClassName}Param> ${className}ParamList); + + /** + * 编辑${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + void edit(${ClassName}Param ${className}Param); + + /** + * 查看${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + ${ClassName} detail(${ClassName}Param ${className}Param); +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/ServiceImpl.java.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/ServiceImpl.java.vm new file mode 100644 index 00000000..ab0d1c19 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/ServiceImpl.java.vm @@ -0,0 +1,136 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package ${packageName}.${modularName}.${busName}.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.cn.xiaonuo.core.consts.CommonConstant; +import com.cn.xiaonuo.core.enums.CommonStatusEnum; +import com.cn.xiaonuo.core.exception.ServiceException; +import com.cn.xiaonuo.core.factory.PageFactory; +import com.cn.xiaonuo.core.pojo.page.PageResult; +import ${packageName}.${modularName}.${busName}.entity.${ClassName}; +import ${packageName}.${modularName}.${busName}.enums.${ClassName}ExceptionEnum; +import ${packageName}.${modularName}.${busName}.mapper.${ClassName}Mapper; +import ${packageName}.${modularName}.${busName}.param.${ClassName}Param; +import ${packageName}.${modularName}.${busName}.service.${ClassName}Service; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; +import java.util.List; + +/** + * ${functionName}service接口实现类 + * + * @author ${authorName} + * @date ${createDateString} + */ +@Service +public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements ${ClassName}Service { + + @Override + public PageResult<${ClassName}> page(${ClassName}Param ${className}Param) { + QueryWrapper<${ClassName}> queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotNull(${className}Param)) { + #foreach ($column in $tableField) + #if (${column.primaryKeyFlag}) + // 根据条件 模糊查询 + if (ObjectUtil.isNotEmpty(${className}Param.get${column.columnKeyName}())) { + queryWrapper.lambda().like(${ClassName}::get${column.columnKeyName}, ${className}Param.get${column.columnKeyName}()); + } + #end + #end + } + return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper)); + } + + @Override + public List<${ClassName}> list(${ClassName}Param ${className}Param) { + LambdaQueryWrapper<${ClassName}> queryWrapper = new LambdaQueryWrapper<>(); + if (ObjectUtil.isNotNull(${className}Param)) { + //根据条件模糊查询 +#foreach ($column in $tableField) + #if (${column.primaryKeyFlag}) + if (ObjectUtil.isNotEmpty(${className}Param.get${column.columnKeyName}())) { + queryWrapper.eq(${ClassName}::get${column.columnKeyName}, ${className}Param.get${column.columnKeyName}()); + } + #end +#end + } + return this.list(queryWrapper); + } + + @Override + public void add(${ClassName}Param ${className}Param) { + ${ClassName} ${className} = new ${ClassName}(); + BeanUtil.copyProperties(${className}Param, ${className}); + this.save(${className}); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void delete(List<${ClassName}Param> ${className}ParamList) { + ${className}ParamList.forEach(${className}Param -> { + ${ClassName} ${className} = this.query${ClassName}(${className}Param); +#foreach ($column in $tableField) + #if (${column.primaryKeyFlag}) + this.removeById(${className}.get${column.columnKeyName}()); + }); + #end +#end + + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void edit(${ClassName}Param ${className}Param) { + ${ClassName} ${className} = this.query${ClassName}(${className}Param); + BeanUtil.copyProperties(${className}Param, ${className}); + this.updateById(${className}); + } + + @Override + public ${ClassName} detail(${ClassName}Param ${className}Param) { + return this.query${ClassName}(${className}Param); + } + + /** + * 获取${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ + private ${ClassName} query${ClassName}(${ClassName}Param ${className}Param) { + ${ClassName} ${className} = this.getById(${className}Param.getId()); + if (ObjectUtil.isNull(${className})) { + throw new ServiceException(${ClassName}ExceptionEnum.NOT_EXIST); + } + return ${className}; + } +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/addForm.vue.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/addForm.vue.vm new file mode 100644 index 00000000..cfdb416c --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/addForm.vue.vm @@ -0,0 +1,84 @@ + + + diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/editForm.vue.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/editForm.vue.vm new file mode 100644 index 00000000..634c3a7d --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/editForm.vue.vm @@ -0,0 +1,96 @@ + + + diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/entity.java.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/entity.java.vm new file mode 100644 index 00000000..1c059a2a --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/entity.java.vm @@ -0,0 +1,60 @@ +/* +Copyright [2020] [https://www.xiaonuo.vip] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +XiaoNuo采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + +1.请不要删除和修改根目录下的LICENSE文件。 +2.请不要删除和修改XiaoNuo源码头部的版权声明。 +3.请保留源码和相关描述文件的项目出处,作者声明等。 +4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/xiaonuo-layui +6.若您的项目无法满足以上几点,可申请商业授权,获取XiaoNuo商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package ${packageName}.${modularName}.${busName}.entity; + +import com.baomidou.mybatisplus.annotation.*; +import com.cn.xiaonuo.core.pojo.base.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import java.util.*; + + +/** + * ${functionName} + * + * @author ${authorName} + * @date ${createDateString} + */ +@EqualsAndHashCode(callSuper = true) +@Data +@TableName("${tableName}") +public class ${ClassName} extends BaseEntity { + +#foreach ($column in $tableField) +#if (${column.primaryKeyFlag}) + /** + * 主键 + */ + @TableId(type = IdType.ASSIGN_ID) + private ${column.javaType} ${column.columnName}; +#else + + /** + * ${column.columnComment} + */ + private ${column.javaType} ${column.columnName}; +#end +#end +} diff --git a/xiaonuo-base/xiaonuo-gen/src/main/resources/template/index.vue.vm b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/index.vue.vm new file mode 100644 index 00000000..689be7e4 --- /dev/null +++ b/xiaonuo-base/xiaonuo-gen/src/main/resources/template/index.vue.vm @@ -0,0 +1,135 @@ + + + diff --git a/xiaonuo-base/xiaonuo-system/src/main/java/com/cn/xiaonuo/sys/core/listener/ConstantsInitListener.java b/xiaonuo-base/xiaonuo-system/src/main/java/com/cn/xiaonuo/sys/core/listener/ConstantsInitListener.java index 6f5a834d..1d79e714 100644 --- a/xiaonuo-base/xiaonuo-system/src/main/java/com/cn/xiaonuo/sys/core/listener/ConstantsInitListener.java +++ b/xiaonuo-base/xiaonuo-system/src/main/java/com/cn/xiaonuo/sys/core/listener/ConstantsInitListener.java @@ -30,6 +30,7 @@ import cn.hutool.db.Entity; import cn.hutool.db.handler.EntityListHandler; import cn.hutool.db.sql.SqlExecutor; import cn.hutool.log.Log; +import com.cn.xiaonuo.core.consts.CommonConstant; import com.cn.xiaonuo.core.context.constant.ConstantContext; import com.cn.xiaonuo.core.enums.CommonStatusEnum; import com.cn.xiaonuo.core.exception.ServiceException; @@ -76,6 +77,9 @@ public class ConstantsInitListener implements ApplicationListener1.1.0 + + + cn.xiaonuo + xiaonuo-gen + 1.1.0 + + org.springframework.boot spring-boot-starter-test