From 2438221d3b12668c2cfd6e0fb9b10ccd01aaf311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 30 Jul 2018 23:34:21 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pigx-common/pigx-common-core/pom.xml | 7 + .../pigx/common/core/util}/Query.java | 26 +- .../main/resources/config/application-dev.yml | 21 ++ .../main/resources/config/pigx-auth-dev.yml | 2 +- .../resources/config/pigx-codegen-dev.yml | 18 ++ .../main/resources/config/pigx-daemon-dev.yml | 4 +- .../resources/config/pigx-gateway-dev.yml | 9 + .../main/resources/config/pigx-upms-dev.yml | 23 +- pigx-upms/pigx-upms-api/pom.xml | 6 - .../pigx/admin/controller/DictController.java | 2 +- .../pigx/admin/controller/LogController.java | 2 +- .../OauthClientDetailsController.java | 2 +- .../pigx/admin/controller/RoleController.java | 2 +- .../pigx/admin/controller/UserController.java | 2 +- .../pigx/admin/mapper/SysRoleMapper.java | 2 +- .../pigx/admin/mapper/SysUserMapper.java | 2 +- .../pigx/admin/service/SysRoleService.java | 2 +- .../pigx/admin/service/SysUserService.java | 2 +- .../service/impl/SysRoleServiceImpl.java | 2 +- .../service/impl/SysUserServiceImpl.java | 2 +- pigx-visual/pigx-codegen/pom.xml | 81 ++++++ .../pigx/codegen/PigxCodeGenApplication.java | 34 +++ .../codegen/config/MybatisPlusConfigurer.java | 41 +++ .../controller/SysGeneratorController.java | 69 +++++ .../pigx/codegen/entity/ColumnEntity.java | 58 ++++ .../pigx/codegen/entity/TableEntity.java | 55 ++++ .../codegen/mapper/SysGeneratorMapper.java | 54 ++++ .../codegen/service/SysGeneratorService.java | 44 ++++ .../service/impl/SysGeneratorServiceImpl.java | 100 +++++++ .../pig4cloud/pigx/codegen/util/GenUtils.java | 247 ++++++++++++++++++ .../src/main/resources/bootstrap.yml | 26 ++ .../src/main/resources/generator.properties | 34 +++ .../resources/mapper/SysGeneratorMapper.xml | 33 +++ .../resources/template/Controller.java.vm | 90 +++++++ .../main/resources/template/Entity.java.vm | 34 +++ .../main/resources/template/Mapper.java.vm | 16 ++ .../src/main/resources/template/Mapper.xml.vm | 14 + .../main/resources/template/Service.java.vm | 14 + .../resources/template/ServiceImpl.java.vm | 17 ++ .../src/main/resources/template/api.js.vm | 56 ++++ .../src/main/resources/template/crud.js.vm | 35 +++ .../src/main/resources/template/index.vue.vm | 189 ++++++++++++++ .../src/main/resources/template/menu.sql.vm | 11 + .../pigx/codegen/RenrenApplicationTests.java | 33 +++ .../pigx/daemon/PigxDaemonApplication.java | 3 +- pigx-visual/pom.xml | 1 + 46 files changed, 1472 insertions(+), 55 deletions(-) rename {pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto => pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util}/Query.java (58%) create mode 100644 pigx-config/src/main/resources/config/pigx-codegen-dev.yml create mode 100755 pigx-visual/pigx-codegen/pom.xml create mode 100755 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java create mode 100644 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/MybatisPlusConfigurer.java create mode 100755 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/SysGeneratorController.java create mode 100755 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/ColumnEntity.java create mode 100755 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/TableEntity.java create mode 100755 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/SysGeneratorMapper.java create mode 100644 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/SysGeneratorService.java create mode 100755 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/SysGeneratorServiceImpl.java create mode 100644 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java create mode 100644 pigx-visual/pigx-codegen/src/main/resources/bootstrap.yml create mode 100755 pigx-visual/pigx-codegen/src/main/resources/generator.properties create mode 100755 pigx-visual/pigx-codegen/src/main/resources/mapper/SysGeneratorMapper.xml create mode 100755 pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm create mode 100755 pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm create mode 100755 pigx-visual/pigx-codegen/src/main/resources/template/Mapper.java.vm create mode 100755 pigx-visual/pigx-codegen/src/main/resources/template/Mapper.xml.vm create mode 100755 pigx-visual/pigx-codegen/src/main/resources/template/Service.java.vm create mode 100755 pigx-visual/pigx-codegen/src/main/resources/template/ServiceImpl.java.vm create mode 100644 pigx-visual/pigx-codegen/src/main/resources/template/api.js.vm create mode 100644 pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm create mode 100755 pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm create mode 100644 pigx-visual/pigx-codegen/src/main/resources/template/menu.sql.vm create mode 100755 pigx-visual/pigx-codegen/src/test/java/com/pig4cloud/pigx/codegen/RenrenApplicationTests.java diff --git a/pigx-common/pigx-common-core/pom.xml b/pigx-common/pigx-common-core/pom.xml index 03a903845..b53f71804 100644 --- a/pigx-common/pigx-common-core/pom.xml +++ b/pigx-common/pigx-common-core/pom.xml @@ -64,5 +64,12 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 + + + com.baomidou + mybatis-plus-core + ${mbp.boot.version} + compile + diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/Query.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/Query.java similarity index 58% rename from pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/Query.java rename to pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/Query.java index 8b4a53802..a64941996 100644 --- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/Query.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/Query.java @@ -1,23 +1,21 @@ /* + * Copyright (c) 2018-2025, lengleng All rights reserved. * - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - * + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) */ -package com.pig4cloud.pigx.admin.api.dto; +package com.pig4cloud.pigx.common.core.util; import com.baomidou.mybatisplus.plugins.Page; import org.apache.commons.lang.StringUtils; diff --git a/pigx-config/src/main/resources/config/application-dev.yml b/pigx-config/src/main/resources/config/application-dev.yml index c07ebe4ac..917bd37dd 100644 --- a/pigx-config/src/main/resources/config/application-dev.yml +++ b/pigx-config/src/main/resources/config/application-dev.yml @@ -45,6 +45,27 @@ ribbon: ReadTimeout: 10000 ConnectTimeout: 10000 +#mybaits-plus配置,修改主键类型,mapper.xml、type 别名等 +mybatis-plus: + mapper-locations: classpath:/mapper/*Mapper.xml + global-config: + #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID"; + id-type: 0 + #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断" + field-strategy: 1 + #驼峰下划线转换 + db-column-underline: true + #刷新mapper 调试神器 + refresh-mapper: false + # 逻辑删除字段 + logic-delete-value: 1 + logic-not-delete-value: 0 + #自定义SQL注入器 + sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector + configuration: + map-underscore-to-camel-case: true + cache-enabled: true + #swagger公共信息 swagger: title: 'PigX Swagger API' diff --git a/pigx-config/src/main/resources/config/pigx-auth-dev.yml b/pigx-config/src/main/resources/config/pigx-auth-dev.yml index 8abdbf645..0c0a5346a 100644 --- a/pigx-config/src/main/resources/config/pigx-auth-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-auth-dev.yml @@ -5,4 +5,4 @@ spring: driver-class-name: com.mysql.jdbc.Driver username: root password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false diff --git a/pigx-config/src/main/resources/config/pigx-codegen-dev.yml b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml new file mode 100644 index 000000000..a62c33ba0 --- /dev/null +++ b/pigx-config/src/main/resources/config/pigx-codegen-dev.yml @@ -0,0 +1,18 @@ +# 数据源配置 +spring: + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.jdbc.Driver + username: root + password: root + url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + jackson: + time-zone: GMT+8 + date-format: yyyy-MM-dd HH:mm:ss + resources: + static-locations: classpath:/static/,classpath:/views/ + +# mybaits 模块配置 +mybatis-plus: + typeAliasesPackage: com.pig4cloud.pigx.codegen.entity + diff --git a/pigx-config/src/main/resources/config/pigx-daemon-dev.yml b/pigx-config/src/main/resources/config/pigx-daemon-dev.yml index 35d1d78dd..e96bf2193 100644 --- a/pigx-config/src/main/resources/config/pigx-daemon-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-daemon-dev.yml @@ -5,11 +5,11 @@ spring: driver-class-name: com.mysql.jdbc.Driver username: root password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false elasticjob: # 分布式任务协调依赖zookeeper zookeeper: - server-lists: 127.0.0.1:2181 + server-lists: 114.116.45.246:13181 namespace: pigx-daemon # 普通任务 simples: diff --git a/pigx-config/src/main/resources/config/pigx-gateway-dev.yml b/pigx-config/src/main/resources/config/pigx-gateway-dev.yml index 30b6e0db8..a9467a58d 100644 --- a/pigx-config/src/main/resources/config/pigx-gateway-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-gateway-dev.yml @@ -4,6 +4,7 @@ spring: locator: enabled: true routes: + # 认证中心 - id: pigx-auth uri: lb://pigx-auth predicates: @@ -14,6 +15,7 @@ spring: # 前端密码解密 - PasswordDecoderFilter - StripPrefix=1 + #UPMS 模块 - id: pigx-upms uri: lb://pigx-upms predicates: @@ -37,6 +39,13 @@ spring: args: name: default fallbackUri: 'forward:/fallback' + # 代码生成模块 + - id: pigx-codegen + uri: lb://pigx-codegen + predicates: + - Path=/gen/** + filters: + - StripPrefix=1 security: encode: diff --git a/pigx-config/src/main/resources/config/pigx-upms-dev.yml b/pigx-config/src/main/resources/config/pigx-upms-dev.yml index d7d894a06..899c06078 100644 --- a/pigx-config/src/main/resources/config/pigx-upms-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-upms-dev.yml @@ -15,29 +15,12 @@ spring: driver-class-name: com.mysql.jdbc.Driver username: root password: root - url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false -#mybaits-plus配置,修改主键类型,mapper.xml、type 别名等 +# mybaits 模块配置 mybatis-plus: - mapper-locations: classpath:/mapper/*Mapper.xml typeAliasesPackage: com.pig4cloud.pigx.admin.api.entity - global-config: - #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID"; - id-type: 0 - #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断" - field-strategy: 1 - #驼峰下划线转换 - db-column-underline: true - #刷新mapper 调试神器 - refresh-mapper: true - # 逻辑删除字段 - logic-delete-value: 1 - logic-not-delete-value: 0 - #自定义SQL注入器 - sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector - configuration: - map-underscore-to-camel-case: true - cache-enabled: true + # swagger相关配置,覆盖全局配置 swagger: authorization: diff --git a/pigx-upms/pigx-upms-api/pom.xml b/pigx-upms/pigx-upms-api/pom.xml index 14c5274e5..419f7c35a 100644 --- a/pigx-upms/pigx-upms-api/pom.xml +++ b/pigx-upms/pigx-upms-api/pom.xml @@ -35,12 +35,6 @@ - - - com.baomidou - mybatis-plus - ${mbp.boot.version} - com.pig4cloud diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java index 8ca986e8e..208a814de 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/DictController.java @@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.entity.SysDict; import com.pig4cloud.pigx.admin.service.SysDictService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java index 47eefb0e9..b5b1a468b 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/LogController.java @@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.entity.SysLog; import com.pig4cloud.pigx.admin.service.SysLogService; import com.pig4cloud.pigx.common.core.constant.CommonConstant; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/OauthClientDetailsController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/OauthClientDetailsController.java index 66d9f9ee2..65252e3b5 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/OauthClientDetailsController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/OauthClientDetailsController.java @@ -21,7 +21,7 @@ package com.pig4cloud.pigx.admin.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails; import com.pig4cloud.pigx.admin.service.SysOauthClientDetailsService; import com.pig4cloud.pigx.common.core.util.R; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/RoleController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/RoleController.java index 5dff704f1..4f8799fd3 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/RoleController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/RoleController.java @@ -21,7 +21,7 @@ package com.pig4cloud.pigx.admin.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.dto.RoleDTO; import com.pig4cloud.pigx.admin.api.entity.SysRole; import com.pig4cloud.pigx.admin.service.SysRoleMenuService; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java index 667de8afa..c95cb7afc 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java @@ -21,7 +21,7 @@ package com.pig4cloud.pigx.admin.controller; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.plugins.Page; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.dto.UserDTO; import com.pig4cloud.pigx.admin.api.dto.UserInfo; import com.pig4cloud.pigx.admin.api.entity.SysUser; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMapper.java index 36ed59c7c..b027e2305 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMapper.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysRoleMapper.java @@ -20,7 +20,7 @@ package com.pig4cloud.pigx.admin.mapper; import com.baomidou.mybatisplus.mapper.BaseMapper; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.entity.SysRole; import java.util.List; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserMapper.java index 72a477535..7aa2af2ae 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserMapper.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysUserMapper.java @@ -20,7 +20,7 @@ package com.pig4cloud.pigx.admin.mapper; import com.baomidou.mybatisplus.mapper.BaseMapper; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.entity.SysUser; import com.pig4cloud.pigx.admin.api.vo.UserVO; import org.apache.ibatis.annotations.Param; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java index 95e320467..d35c8bb31 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java @@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.service; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.IService; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.dto.RoleDTO; import com.pig4cloud.pigx.admin.api.entity.SysRole; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java index 435ed7a69..4bf7c1d48 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java @@ -21,7 +21,7 @@ package com.pig4cloud.pigx.admin.service; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.IService; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.dto.UserDTO; import com.pig4cloud.pigx.admin.api.dto.UserInfo; import com.pig4cloud.pigx.admin.api.entity.SysUser; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java index dd82ea0da..497e0c3cb 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java @@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.dto.RoleDTO; import com.pig4cloud.pigx.admin.api.entity.SysRole; import com.pig4cloud.pigx.admin.api.entity.SysRoleDept; diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java index c9fef45fe..053bfcb45 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java @@ -25,7 +25,7 @@ import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.pig4cloud.pigx.admin.api.dto.Query; +import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.admin.api.dto.UserDTO; import com.pig4cloud.pigx.admin.api.dto.UserInfo; import com.pig4cloud.pigx.admin.api.entity.SysRole; diff --git a/pigx-visual/pigx-codegen/pom.xml b/pigx-visual/pigx-codegen/pom.xml new file mode 100755 index 000000000..2fae09534 --- /dev/null +++ b/pigx-visual/pigx-codegen/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + + com.pig4cloud + pigx-visual + ${pigx.version} + + + pigx-codegen + ${pigx.version} + jar + pigx-codegen + 代码生成模块 + + + 1.3.0 + 2.6 + 2.5 + 1.10 + 1.7 + + + + + + org.springframework.cloud + spring-cloud-starter-config + + + + com.baomidou + mybatis-plus-boot-starter + ${mbp.boot.version} + + + mysql + mysql-connector-java + + + + com.pig4cloud + pigx-common-core + ${pigx.version} + + + + velocity + org.apache.velocity + ${velocity.version} + + + + org.springframework.boot + spring-boot-starter-web + + + + spring-boot-starter-tomcat + org.springframework.boot + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java new file mode 100755 index 000000000..03c50be7a --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/PigxCodeGenApplication.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen; + +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; + +/** + * @author lengleng + * @date 2018/07/29 + * 代码生成模块 + */ +@SpringCloudApplication +public class PigxCodeGenApplication { + + public static void main(String[] args) { + SpringApplication.run(PigxCodeGenApplication.class, args); + } +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/MybatisPlusConfigurer.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/MybatisPlusConfigurer.java new file mode 100644 index 000000000..73e252f5e --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/MybatisPlusConfigurer.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen.config; + +import com.baomidou.mybatisplus.plugins.PaginationInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author lengleng + * @date 2017/10/29 + */ +@Configuration +@MapperScan("com.pig4cloud.pigx.codegen.mapper") +public class MybatisPlusConfigurer { + /** + * 分页插件 + * + * @return PaginationInterceptor + */ + @Bean + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); + } +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/SysGeneratorController.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/SysGeneratorController.java new file mode 100755 index 000000000..94f2bcfd1 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/SysGeneratorController.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen.controller; + +import cn.hutool.core.io.IoUtil; +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.codegen.service.SysGeneratorService; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; + +/** + * 代码生成器 + * + * @author chenshun + * @email sunlightcs@gmail.com + * @date 2016年12月19日 下午9:12:58 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/generator") +public class SysGeneratorController { + private final SysGeneratorService sysGeneratorService; + + /** + * 列表 + * + * @param params 参数集 + * @return 数据库表 + */ + @GetMapping("/page") + public Page list(@RequestParam Map params) { + return sysGeneratorService.queryPage(params); + } + + /** + * 生成代码 + */ + @GetMapping("/code/{tableName}") + public void code(@PathVariable String tableName, HttpServletResponse response) throws IOException { + byte[] data = sysGeneratorService.generatorCode(new String[]{tableName}); + + response.reset(); + response.setHeader("Content-Disposition", String.format("attachment; filename=%s.zip", tableName)); + response.addHeader("Content-Length", "" + data.length); + response.setContentType("application/octet-stream; charset=UTF-8"); + + IoUtil.write(response.getOutputStream(), Boolean.TRUE, data); + } +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/ColumnEntity.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/ColumnEntity.java new file mode 100755 index 000000000..91ef4cd7c --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/ColumnEntity.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen.entity; + +import lombok.Data; + +/** + * @author lengleng + * @date 2018/07/29 + * 列属性: https://blog.csdn.net/lkforce/article/details/79557482 + */ +@Data +public class ColumnEntity { + /** + * 列表 + */ + private String columnName; + /** + * 数据类型 + */ + private String dataType; + /** + * 备注 + */ + private String comments; + + /** + * 驼峰属性 + */ + private String caseAttrName; + /** + * 普通属性 + */ + private String lowerAttrName; + /** + * 属性类型 + */ + private String attrType; + /** + * 其他信息。 + */ + private String extra; +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/TableEntity.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/TableEntity.java new file mode 100755 index 000000000..d5f1bda66 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/TableEntity.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen.entity; + +import lombok.Data; + +import java.util.List; + +/** + * @author lengleng + * @date 2018/07/29 + * 表属性: https://blog.csdn.net/lkforce/article/details/79557482 + */ +@Data +public class TableEntity { + /** + * 名称 + */ + private String tableName; + /** + * 备注 + */ + private String comments; + /** + * 主键 + */ + private ColumnEntity pk; + /** + * 列名 + */ + private List columns; + /** + * 驼峰类型 + */ + private String caseClassName; + /** + * 普通类型 + */ + private String lowerClassName; +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/SysGeneratorMapper.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/SysGeneratorMapper.java new file mode 100755 index 000000000..351981d78 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/SysGeneratorMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen.mapper; + +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.common.core.util.Query; + +import java.util.List; +import java.util.Map; + +/** + * 代码生成器 + * + * @author chenshun + * @email sunlightcs@gmail.com + * @date 2016年12月19日 下午3:32:04 + */ +public interface SysGeneratorMapper { + + /** + * 分页查询表格 + * + * @param query + * @return + */ + List> queryList(Map query); + + /** + * 查询表数量 + * + * @param query + * @return + */ + int queryTotal(Map query); + + Map queryTable(String tableName); + + List> queryColumns(String tableName); +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/SysGeneratorService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/SysGeneratorService.java new file mode 100644 index 000000000..acfa5689c --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/SysGeneratorService.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen.service; + +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.common.core.util.Query; + +import java.util.Map; + +/** + * @author lengleng + * @date 2018/7/29 + */ +public interface SysGeneratorService { + /** + * 生成代码 + * + * @param tableNames 表名称 + * @return + */ + byte[] generatorCode(String[] tableNames); + + /** + * 分页查询表 + * @param query 查询条件 + * @return + */ + Page queryPage(Map query); +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/SysGeneratorServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/SysGeneratorServiceImpl.java new file mode 100755 index 000000000..7b09405da --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/SysGeneratorServiceImpl.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.IoUtil; +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.codegen.mapper.SysGeneratorMapper; +import com.pig4cloud.pigx.codegen.service.SysGeneratorService; +import com.pig4cloud.pigx.codegen.util.GenUtils; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.io.ByteArrayOutputStream; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipOutputStream; + +/** + * 代码生成器 + * + * @author chenshun + * @email sunlightcs@gmail.com + * @date 2016年12月19日 下午3:33:38 + */ +@Service +@AllArgsConstructor +public class SysGeneratorServiceImpl implements SysGeneratorService { + private final SysGeneratorMapper sysGeneratorMapper; + + + /** + * 分页查询表 + * + * @param query 查询条件 + * @return + */ + @Override + public Page queryPage(Map query) { + + Integer current = Integer.parseInt(query.getOrDefault("page", "1").toString()); + Integer limit = Integer.parseInt(query.getOrDefault("limit", "1").toString()); + Page page = new Page(current, limit); + + List> list = sysGeneratorMapper.queryList(query); + if (CollUtil.isEmpty(list)) { + return page; + } + + page.setTotal(sysGeneratorMapper.queryTotal(query)); + page.setRecords(list); + return page; + } + + /** + * 生成代码 + * + * @param tableNames 表名称 + * @return + */ + @Override + public byte[] generatorCode(String[] tableNames) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(outputStream); + + for (String tableName : tableNames) { + //查询表信息 + Map table = queryTable(tableName); + //查询列信息 + List> columns = queryColumns(tableName); + //生成代码 + GenUtils.generatorCode(table, columns, zip); + } + IoUtil.close(zip); + return outputStream.toByteArray(); + } + + private Map queryTable(String tableName) { + return sysGeneratorMapper.queryTable(tableName); + } + + private List> queryColumns(String tableName) { + return sysGeneratorMapper.queryColumns(tableName); + } +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java new file mode 100644 index 000000000..23bd781f2 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen.util; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.CharsetUtil; +import com.pig4cloud.pigx.codegen.entity.ColumnEntity; +import com.pig4cloud.pigx.codegen.entity.TableEntity; +import com.pig4cloud.pigx.common.core.exception.CheckedException; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.WordUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * 代码生成器 工具类 + * + * @author chenshun + * @email sunlightcs@gmail.com + * @date 2016年12月19日 下午11:40:24 + */ +@Slf4j +public class GenUtils { + + public static List getTemplates() { + List templates = new ArrayList<>(); + templates.add("template/Entity.java.vm" ); + templates.add("template/Mapper.java.vm" ); + templates.add("template/Mapper.xml.vm" ); + templates.add("template/Service.java.vm" ); + templates.add("template/ServiceImpl.java.vm" ); + templates.add("template/Controller.java.vm" ); + templates.add("template/menu.sql.vm" ); + + templates.add("template/index.vue.vm" ); + templates.add("template/api.js.vm" ); + templates.add("template/crud.js.vm" ); + return templates; + } + + /** + * 生成代码 + */ + public static void generatorCode(Map table, + List> columns, ZipOutputStream zip) { + //配置信息 + Configuration config = getConfig(); + boolean hasBigDecimal = false; + //表信息 + TableEntity tableEntity = new TableEntity(); + tableEntity.setTableName(table.get("tableName" )); + tableEntity.setComments(table.get("tableComment" )); + //表名转换成Java类名 + String className = tableToJava(tableEntity.getTableName(), config.getString("tablePrefix" )); + tableEntity.setCaseClassName(className); + tableEntity.setLowerClassName(StringUtils.uncapitalize(className)); + + //列信息 + List columnList = new ArrayList<>(); + for (Map column : columns) { + ColumnEntity columnEntity = new ColumnEntity(); + columnEntity.setColumnName(column.get("columnName" )); + columnEntity.setDataType(column.get("dataType" )); + columnEntity.setComments(column.get("columnComment" )); + columnEntity.setExtra(column.get("extra" )); + + //列名转换成Java属性名 + String attrName = columnToJava(columnEntity.getColumnName()); + columnEntity.setCaseAttrName(attrName); + columnEntity.setLowerAttrName(StringUtils.uncapitalize(attrName)); + + //列的数据类型,转换成Java类型 + String attrType = config.getString(columnEntity.getDataType(), "unknowType" ); + columnEntity.setAttrType(attrType); + if (!hasBigDecimal && attrType.equals("BigDecimal" )) { + hasBigDecimal = true; + } + //是否主键 + if ("PRI".equalsIgnoreCase(column.get("columnKey" )) && tableEntity.getPk() == null) { + tableEntity.setPk(columnEntity); + } + + columnList.add(columnEntity); + } + tableEntity.setColumns(columnList); + + //没主键,则第一个字段为主键 + if (tableEntity.getPk() == null) { + tableEntity.setPk(tableEntity.getColumns().get(0)); + } + + //设置velocity资源加载器 + Properties prop = new Properties(); + prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader" ); + Velocity.init(prop); + String mainPath = config.getString("mainPath" ); + mainPath = StringUtils.isBlank(mainPath) ? "com.pig4cloud.pigx" : mainPath; + //封装模板数据 + Map map = new HashMap<>(); + map.put("tableName", tableEntity.getTableName()); + map.put("comments", tableEntity.getComments()); + map.put("pk", tableEntity.getPk()); + map.put("className", tableEntity.getCaseClassName()); + map.put("classname", tableEntity.getLowerClassName()); + map.put("pathName", tableEntity.getLowerClassName().toLowerCase()); + map.put("columns", tableEntity.getColumns()); + map.put("hasBigDecimal", hasBigDecimal); + map.put("mainPath", mainPath); + map.put("package", config.getString("package" )); + map.put("moduleName", config.getString("moduleName" )); + map.put("author", config.getString("author" )); + map.put("datetime", DateUtil.now()); + VelocityContext context = new VelocityContext(map); + + //获取模板列表 + List templates = getTemplates(); + for (String template : templates) { + //渲染模板 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, CharsetUtil.UTF_8); + tpl.merge(context, sw); + + try { + //添加到zip + zip.putNextEntry(new ZipEntry(Objects + .requireNonNull(getFileName(template, tableEntity.getCaseClassName() + , config.getString("package" ), config.getString("moduleName" ))))); + IoUtil.write(zip, CharsetUtil.UTF_8, false, sw.toString()); + IoUtil.close(sw); + zip.closeEntry(); + } catch (IOException e) { + throw new CheckedException("渲染模板失败,表名:" + tableEntity.getTableName(), e); + } + } + } + + + /** + * 列名转换成Java属性名 + */ + private static String columnToJava(String columnName) { + return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "" ); + } + + /** + * 表名转换成Java类名 + */ + private static String tableToJava(String tableName, String tablePrefix) { + if (StringUtils.isNotBlank(tablePrefix)) { + tableName = tableName.replace(tablePrefix, "" ); + } + return columnToJava(tableName); + } + + /** + * 获取配置信息 + */ + public static Configuration getConfig() { + try { + return new PropertiesConfiguration("generator.properties" ); + } catch (ConfigurationException e) { + throw new CheckedException("获取配置文件失败,", e); + } + } + + /** + * 获取文件名 + */ + public static String getFileName(String template, String className, String packageName, String moduleName) { + String packagePath = "pigx" + File.separator + "main" + File.separator + "java" + File.separator; + if (StringUtils.isNotBlank(packageName)) { + packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator; + } + + if (template.contains("Entity.java.vm" )) { + return packagePath + "entity" + File.separator + className + ".java"; + } + + if (template.contains("Mapper.java.vm" )) { + return packagePath + "mapper" + File.separator + className + "Mapper.java"; + } + + if (template.contains("Service.java.vm" )) { + return packagePath + "service" + File.separator + className + "Service.java"; + } + + if (template.contains("ServiceImpl.java.vm" )) { + return packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java"; + } + + if (template.contains("Controller.java.vm" )) { + return packagePath + "controller" + File.separator + className + "Controller.java"; + } + + if (template.contains("Mapper.xml.vm" )) { + return "pigx" + File.separator + "main" + File.separator + "resources" + File.separator + "mapper" + File.separator + moduleName + File.separator + className + "Mapper.xml"; + } + + if (template.contains("menu.sql.vm" )) { + return className.toLowerCase() + "_menu.sql"; + } + + if (template.contains("index.vue.vm" )) { + return "pigx-ui" + File.separator + "src" + File.separator + "views" + + File.separator + moduleName + File.separator + className.toLowerCase() + File.separator + "index.vue"; + } + + if (template.contains("api.js.vm" )) { + return "pigx-ui" + File.separator + "src" + File.separator + "api" + File.separator + className.toLowerCase() + ".js"; + } + + if (template.contains("crud.js.vm" )) { + return "pigx-ui" + File.separator + "src" + File.separator + "const" + + File.separator + "curd" + File.separator + className.toLowerCase() + ".js"; + } + + return null; + } +} diff --git a/pigx-visual/pigx-codegen/src/main/resources/bootstrap.yml b/pigx-visual/pigx-codegen/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..359f44828 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/bootstrap.yml @@ -0,0 +1,26 @@ +server: + port: 5003 + +spring: + application: + name: pigx-codegen + #配置中心 + cloud: + config: + fail-fast: true + name: ${spring.application.name} + profile: dev + discovery: + enabled: true + service-id: pigx-config + +# 注册中心配置 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://pig:pig@localhost:1025/eureka/ +logging: + level: + root: debug diff --git a/pigx-visual/pigx-codegen/src/main/resources/generator.properties b/pigx-visual/pigx-codegen/src/main/resources/generator.properties new file mode 100755 index 000000000..60bff1558 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/generator.properties @@ -0,0 +1,34 @@ +#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F + +mainPath=com.pig4cloud.pigx +#\u5305\u540D +package=com.pig4cloud.pigx +moduleName=generator +#\u4F5C\u8005 +author=pigx code generator + +#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00) +tablePrefix=tb_ + +#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F +tinyint=Integer +smallint=Integer +mediumint=Integer +int=Integer +integer=Integer +bigint=Long +float=Float +double=Double +decimal=BigDecimal +bit=Boolean + +char=String +varchar=String +tinytext=String +text=String +mediumtext=String +longtext=String + +date=LocalDateTime +datetime=LocalDateTime +timestamp=LocalDateTime diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/SysGeneratorMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/SysGeneratorMapper.xml new file mode 100755 index 000000000..a60555241 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/mapper/SysGeneratorMapper.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm b/pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm new file mode 100755 index 000000000..f9256ba01 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm @@ -0,0 +1,90 @@ +package ${package}.${moduleName}.controller; + +import java.util.Arrays; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import com.pig4cloud.pigx.common.core.constant.CommonConstant; +import com.pig4cloud.pigx.common.core.util.Query; + +import ${package}.${moduleName}.entity.${className}; +import ${package}.${moduleName}.service.${className}Service; +import com.pig4cloud.pigx.common.core.util.R; +import java.util.Map; + + +/** + * ${comments} + * + * @author ${author} + * @date ${datetime} + */ +@RestController +@RequestMapping("${moduleName}/${pathName}") +public class ${className}Controller { + @Autowired + private ${className}Service ${classname}Service; + + + /** + * 列表 + * @param params + * @return + */ + @GetMapping("/page") + public Page page(@RequestParam Map params) { + params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL); + return ${classname}Service.selectPage(new Query<>(params), new EntityWrapper<>()); + } + + + /** + * 信息 + * @param ${pk.lowerAttrName} + * @return R + */ + @GetMapping("/{${pk.lowerAttrName}}") + public R info(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){ + ${className} ${classname} = ${classname}Service.selectById(${pk.lowerAttrName}); + + return new R<>(${classname}); + } + + /** + * 保存 + * @param ${classname} + * @return R + */ + @PostMapping("/save") + public R save(@RequestBody ${className} ${classname}){ + ${classname}Service.insert(${classname}); + + return new R<>(Boolean.TRUE); + } + + /** + * 修改 + * @param ${classname} + * @return R + */ + @PutMapping("/update") + public R update(@RequestBody ${className} ${classname}){ + ${classname}Service.updateById(${classname}); + + return new R<>(Boolean.TRUE); + } + + /** + * 删除 + * @param ${pk.lowerAttrName}s + * @return R + */ + @DeleteMapping("/delete") + public R delete(@RequestBody ${pk.attrType}[] ${pk.lowerAttrName}s){ + ${classname}Service.deleteBatchIds(Arrays.asList(${pk.lowerAttrName}s)); + + return new R<>(Boolean.TRUE); + } + +} diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm b/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm new file mode 100755 index 000000000..13edc09e4 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm @@ -0,0 +1,34 @@ +package ${package}.${moduleName}.entity; + +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + #if(${hasBigDecimal}) +import java.math.BigDecimal; +#end +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * ${comments} + * + * @author ${author} + * @date ${datetime} + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("${tableName}") +public class ${className} implements Serializable { + private static final long serialVersionUID = 1L; + +#foreach ($column in $columns) + /** + * $column.comments + */ + #if($column.columnName == $pk.columnName) +@TableId + #end +private $column.attrType $column.lowerAttrName; +#end +} diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/Mapper.java.vm b/pigx-visual/pigx-codegen/src/main/resources/template/Mapper.java.vm new file mode 100755 index 000000000..e48d74fcf --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/Mapper.java.vm @@ -0,0 +1,16 @@ +package ${package}.${moduleName}.mapper; + +import ${package}.${moduleName}.entity.${className}; +import com.baomidou.mybatisplus.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * ${comments} + * + * @author ${author} + * @date ${datetime} + */ +@Mapper +public interface ${className}Mapper extends BaseMapper<${className}> { + +} diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/Mapper.xml.vm b/pigx-visual/pigx-codegen/src/main/resources/template/Mapper.xml.vm new file mode 100755 index 000000000..73baf9a05 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/Mapper.xml.vm @@ -0,0 +1,14 @@ + + + + + + + +#foreach($column in $columns) + +#end + + + + diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/Service.java.vm b/pigx-visual/pigx-codegen/src/main/resources/template/Service.java.vm new file mode 100755 index 000000000..7adce4166 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/Service.java.vm @@ -0,0 +1,14 @@ +package ${package}.${moduleName}.service; + +import com.baomidou.mybatisplus.service.IService; +import ${package}.${moduleName}.entity.${className}; + +/** + * ${comments} + * + * @author ${author} + * @date ${datetime} + */ +public interface ${className}Service extends IService<${className}> { +} + diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/ServiceImpl.java.vm b/pigx-visual/pigx-codegen/src/main/resources/template/ServiceImpl.java.vm new file mode 100755 index 000000000..f9f7fe1ad --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/ServiceImpl.java.vm @@ -0,0 +1,17 @@ +package ${package}.${moduleName}.service.impl; + +import org.springframework.stereotype.Service; +import java.util.Map; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; + +import ${package}.${moduleName}.mapper.${className}Mapper; +import ${package}.${moduleName}.entity.${className}; +import ${package}.${moduleName}.service.${className}Service; + + +@Service("${classname}Service") +public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements ${className}Service { + +} diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/api.js.vm b/pigx-visual/pigx-codegen/src/main/resources/template/api.js.vm new file mode 100644 index 000000000..1e0092be8 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/api.js.vm @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +import request from '@/router/axios' + +export function fetchList(query) { + return request({ + url: '/${moduleName}/${pathName}/page', + method: 'get', + params: query + }) +} + +export function addObj(obj) { + return request({ + url: '/${moduleName}/${pathName}/', + method: 'post', + data: obj + }) +} + +export function getObj(id) { + return request({ + url: '/${moduleName}/${pathName}/' + id, + method: 'get' + }) +} + +export function delObj(id) { + return request({ + url: '/${moduleName}/${pathName}/' + id, + method: 'delete' + }) +} + +export function putObj(obj) { + return request({ + url: '/${moduleName}/${pathName}/', + method: 'put', + data: obj + }) +} diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm b/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm new file mode 100644 index 000000000..7e9ac84b7 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +export const tableOption = { + "border": true, + "index": true, + "stripe": true, + "menuAlign": "center", + "align": "center", + "editBtn": false, + "delBtn": false, + "dic": [], + "column": [ +#foreach ($column in $columns) + { + label: '$column.comments', + prop: '$column.lowerAttrName' + }, +#end + ] +} diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm b/pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm new file mode 100755 index 000000000..e30cb28c0 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm @@ -0,0 +1,189 @@ + + + + + + + + diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/menu.sql.vm b/pigx-visual/pigx-codegen/src/main/resources/template/menu.sql.vm new file mode 100644 index 000000000..2fbe36a2f --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/menu.sql.vm @@ -0,0 +1,11 @@ +-- 菜单SQL +insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`) + values ( '1', 'views/${moduleName}/${pathName}/index', '', '0', 'client', 'icon-bangzhushouji', '8', '0', '2018-01-20 13:17:19', '8', '2018-07-29 13:38:19', '${comments}管理'); + +-- 菜单对应按钮SQL +insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`) + values ( '8', null, '${moduleName}_${pathName}_add', '1', null, '1', '81', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '${comments}新增'); +insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`) + values ( '8', null, '${moduleName}_${pathName}_edit', '1', null, '1', '81', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '${comments}修改'); +insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`) + values ( '8', null, '${moduleName}_${pathName}_del', '1', null, '1', '81', '0', '2018-05-15 21:35:18', '2', '2018-07-29 13:38:59', '${comments}删除'); diff --git a/pigx-visual/pigx-codegen/src/test/java/com/pig4cloud/pigx/codegen/RenrenApplicationTests.java b/pigx-visual/pigx-codegen/src/test/java/com/pig4cloud/pigx/codegen/RenrenApplicationTests.java new file mode 100755 index 000000000..6a6e645a4 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/test/java/com/pig4cloud/pigx/codegen/RenrenApplicationTests.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.codegen; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class RenrenApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/pigx-visual/pigx-daemon/src/main/java/com/pig4cloud/pigx/daemon/PigxDaemonApplication.java b/pigx-visual/pigx-daemon/src/main/java/com/pig4cloud/pigx/daemon/PigxDaemonApplication.java index 8ad39c45d..cce51c6b2 100644 --- a/pigx-visual/pigx-daemon/src/main/java/com/pig4cloud/pigx/daemon/PigxDaemonApplication.java +++ b/pigx-visual/pigx-daemon/src/main/java/com/pig4cloud/pigx/daemon/PigxDaemonApplication.java @@ -20,6 +20,7 @@ package com.pig4cloud.pigx.daemon; import com.pig4cloud.pigx.common.job.annotation.EnablePigxJob; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.SpringCloudApplication; /** * @author lengleng @@ -27,7 +28,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; * 分布式任务调度模块 */ @EnablePigxJob -@SpringBootApplication +@SpringCloudApplication public class PigxDaemonApplication { public static void main(String[] args) { diff --git a/pigx-visual/pom.xml b/pigx-visual/pom.xml index 247f92c7e..5b0a16c8a 100644 --- a/pigx-visual/pom.xml +++ b/pigx-visual/pom.xml @@ -34,6 +34,7 @@ pom + pigx-codegen pigx-daemon pigx-monitor