diff --git a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/mybatis/MybatisPlusConfiguration.java b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/mybatis/MybatisPlusConfiguration.java index 119be18a4..95839a2fb 100644 --- a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/mybatis/MybatisPlusConfiguration.java +++ b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/mybatis/MybatisPlusConfiguration.java @@ -17,7 +17,6 @@ package com.pig4cloud.pigx.common.data.mybatis; -import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; @@ -83,7 +82,7 @@ public class MybatisPlusConfiguration implements WebMvcConfigurer { dataScopeInnerInterceptor.setDataScopeHandle(dataScopeHandle()); interceptor.addInnerInterceptor(dataScopeInnerInterceptor); // 分页支持 - interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); return interceptor; } diff --git a/pigx-common/pigx-common-datasource/pom.xml b/pigx-common/pigx-common-datasource/pom.xml index 18bcfb46b..e484f746a 100644 --- a/pigx-common/pigx-common-datasource/pom.xml +++ b/pigx-common/pigx-common-datasource/pom.xml @@ -32,5 +32,10 @@ druid-spring-boot-starter provided + + + org.springframework + spring-webmvc + \ No newline at end of file diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DynamicDataSourceAutoConfiguration.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DynamicDataSourceAutoConfiguration.java index cde3b1811..5daa24ca9 100644 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DynamicDataSourceAutoConfiguration.java +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DynamicDataSourceAutoConfiguration.java @@ -22,6 +22,7 @@ import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider; import com.pig4cloud.pigx.common.datasource.config.DruidDataSourceProperties; import com.pig4cloud.pigx.common.datasource.config.JdbcDynamicDataSourceProvider; import com.pig4cloud.pigx.common.datasource.config.LastParamDsProcessor; +import com.pig4cloud.pigx.common.datasource.config.WebMvcConfig; import lombok.AllArgsConstructor; import org.jasypt.encryption.StringEncryptor; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -29,6 +30,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @author lengleng @@ -56,4 +58,9 @@ public class DynamicDataSourceAutoConfiguration { return new LastParamDsProcessor(); } + @Bean + public WebMvcConfigurer webMvcConfigurer() { + return new WebMvcConfig(); + } + } diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/ClearTtlDsInterceptor.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/ClearTtlDsInterceptor.java new file mode 100644 index 000000000..9e05799cb --- /dev/null +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/ClearTtlDsInterceptor.java @@ -0,0 +1,29 @@ +package com.pig4cloud.pigx.common.datasource.config; + +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author lengleng + * @date 2020/12/11 + *

+ * 清空上文的DS 设置避免污染当前线程 + */ +public class ClearTtlDsInterceptor implements HandlerInterceptor { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + DynamicDataSourceContextHolder.clear(); + return true; + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, + Exception ex) { + DynamicDataSourceContextHolder.clear(); + } + +} diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/JdbcDynamicDataSourceProvider.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/JdbcDynamicDataSourceProvider.java index 7cbf48dd5..958a9f0f8 100644 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/JdbcDynamicDataSourceProvider.java +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/JdbcDynamicDataSourceProvider.java @@ -20,6 +20,8 @@ package com.pig4cloud.pigx.common.datasource.config; import com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider; import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; import com.pig4cloud.pigx.common.datasource.support.DataSourceConstants; +import com.pig4cloud.pigx.common.datasource.util.DsConfTypeEnum; +import com.pig4cloud.pigx.common.datasource.util.DsJdbcUrlEnum; import org.jasypt.encryption.StringEncryptor; import java.sql.ResultSet; @@ -61,9 +63,30 @@ public class JdbcDynamicDataSourceProvider extends AbstractJdbcDataSourceProvide String name = rs.getString(DataSourceConstants.DS_NAME); String username = rs.getString(DataSourceConstants.DS_USER_NAME); String password = rs.getString(DataSourceConstants.DS_USER_PWD); - String url = rs.getString(DataSourceConstants.DS_JDBC_URL); + Integer confType = rs.getInt(DataSourceConstants.DS_CONFIG_TYPE); + String dsType = rs.getString(DataSourceConstants.DS_TYPE); + + String url; + // JDBC 配置形式 + DsJdbcUrlEnum urlEnum = DsJdbcUrlEnum.get(dsType); + if (DsConfTypeEnum.JDBC.getType().equals(confType)) { + url = rs.getString(DataSourceConstants.DS_JDBC_URL); + } + else if (DsJdbcUrlEnum.MSSQL.getDbName().equals(dsType)) { + String host = rs.getString(DataSourceConstants.DS_HOST); + String port = rs.getString(DataSourceConstants.DS_PORT); + String dsName = rs.getString(DataSourceConstants.DS_NAME); + String instance = rs.getString(DataSourceConstants.DS_INSTANCE); + url = String.format(urlEnum.getUrl(), host, instance, port, dsName); + } + else { + String host = rs.getString(DataSourceConstants.DS_HOST); + String port = rs.getString(DataSourceConstants.DS_PORT); + String dsName = rs.getString(DataSourceConstants.DS_NAME); + url = String.format(urlEnum.getUrl(), host, port, dsName); + } + DataSourceProperty property = new DataSourceProperty(); - property.setDriverClassName(DataSourceConstants.DS_DRIVER); property.setUsername(username); property.setPassword(stringEncryptor.decrypt(password)); property.setUrl(url); @@ -75,7 +98,6 @@ public class JdbcDynamicDataSourceProvider extends AbstractJdbcDataSourceProvide property.setUsername(properties.getUsername()); property.setPassword(properties.getPassword()); property.setUrl(properties.getUrl()); - property.setDriverClassName(DataSourceConstants.DS_DRIVER); map.put(DataSourceConstants.DS_MASTER, property); return map; } diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/WebMvcConfig.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/WebMvcConfig.java new file mode 100644 index 000000000..77da071e1 --- /dev/null +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/WebMvcConfig.java @@ -0,0 +1,17 @@ +package com.pig4cloud.pigx.common.datasource.config; + +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * @author lengleng + * @date 2020/12/11 + */ +public class WebMvcConfig implements WebMvcConfigurer { + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new ClearTtlDsInterceptor()).addPathPatterns("/**"); + } + +} \ No newline at end of file diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/support/DataSourceConstants.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/support/DataSourceConstants.java index 38730f4b5..8f2a96d40 100644 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/support/DataSourceConstants.java +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/support/DataSourceConstants.java @@ -23,6 +23,11 @@ public interface DataSourceConstants { */ String DS_JDBC_URL = "url"; + /** + * 配置类型 + */ + String DS_CONFIG_TYPE = "conf_type"; + /** * 用户名 */ @@ -34,8 +39,23 @@ public interface DataSourceConstants { String DS_USER_PWD = "password"; /** - * 默认驱动名称 + * 数据库类型 */ - String DS_DRIVER = "com.mysql.cj.jdbc.Driver"; + String DS_TYPE = "ds_type"; + + /** + * 主机类型 + */ + String DS_HOST = "host"; + + /** + * 端口 + */ + String DS_PORT = "port"; + + /** + * 实例名称 + */ + String DS_INSTANCE = "instance"; } diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/util/DsConfTypeEnum.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/util/DsConfTypeEnum.java new file mode 100644 index 000000000..9579e7c72 --- /dev/null +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/util/DsConfTypeEnum.java @@ -0,0 +1,30 @@ +package com.pig4cloud.pigx.common.datasource.util; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author lengleng + * @date 2020/12/11 + *

+ * 数据源配置类型 + */ +@Getter +@AllArgsConstructor +public enum DsConfTypeEnum { + + /** + * 主机链接 + */ + HOST(0, "主机链接"), + + /** + * JDBC链接 + */ + JDBC(1, "JDBC链接"); + + private final Integer type; + + private final String description; + +} diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/util/DsJdbcUrlEnum.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/util/DsJdbcUrlEnum.java new file mode 100644 index 000000000..0987fcfaf --- /dev/null +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/util/DsJdbcUrlEnum.java @@ -0,0 +1,53 @@ +package com.pig4cloud.pigx.common.datasource.util; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @author lengleng + * @date 2020/12/11 + *

+ * jdbc-url + */ +@Getter +@AllArgsConstructor +public enum DsJdbcUrlEnum { + + /** + * mysql 数据库 + */ + MYSQL("mysql", + "jdbc:mysql://%s:%s/%s?characterEncoding=utf8" + + "&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true" + + "&useLegacyDatetimeCode=false&allowMultiQueries=true&allowPublicKeyRetrieval=true", + "mysql8 链接"), + + /** + * pg 数据库 + */ + PG("pg", "jdbc:postgresql://%s:%s/%s", "postgresql 链接"), + + /** + * SQL SERVER + */ + MSSQL("mssql", "jdbc:sqlserver://%s\\%s:%s;database=%s;characterEncoding=UTF-8", "sqlserver 链接"), + + /** + * oracle + */ + ORACLE("oracle", "jdbc:oracle:thin:@%s:%s:%s", "oracle 链接"); + + private final String dbName; + + private final String url; + + private final String description; + + public static DsJdbcUrlEnum get(String dsType) { + return Arrays.stream(DsJdbcUrlEnum.values()).filter(dsJdbcUrlEnum -> dsType.equals(dsJdbcUrlEnum.getDbName())) + .findFirst().get(); + } + +} diff --git a/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/support/SwaggerProvider.java b/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/support/SwaggerProvider.java index 8e308b321..82844c406 100644 --- a/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/support/SwaggerProvider.java +++ b/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/support/SwaggerProvider.java @@ -62,10 +62,11 @@ public class SwaggerProvider implements SwaggerResourcesProvider { .filter(predicateDefinition -> !swaggerProperties.getIgnoreProviders() .contains(routeDefinition.getId())) .map(predicateDefinition -> swaggerResource(routeDefinition.getId(), - predicateDefinition.getArgs() - .get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**", API_URI)))) + predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**", + API_URI)))) // 只显示注册中心 内已经正确启动的服务 - .filter(swaggerResource -> discoveryClient.getServices().stream().anyMatch(s -> s.equals(swaggerResource.getName()))) + .filter(swaggerResource -> discoveryClient.getServices().stream() + .anyMatch(s -> s.equals(swaggerResource.getName()))) .collect(Collectors.toList()); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysFileController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysFileController.java index 3bf44f4bf..bbe3c4c81 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysFileController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysFileController.java @@ -49,8 +49,7 @@ public class SysFileController { /** * 分页查询 - * - * @param page 分页对象 + * @param page 分页对象 * @param sysFile 文件管理 * @return */ @@ -62,7 +61,6 @@ public class SysFileController { /** * 通过id删除文件管理 - * * @param id id * @return R */ @@ -76,7 +74,6 @@ public class SysFileController { /** * 上传文件 文件名采用uuid,避免原始文件名中带"-"符号导致下载的时候解析出现异常 - * * @param file 资源 * @return R(/ admin / bucketName / filename) */ @@ -87,8 +84,7 @@ public class SysFileController { /** * 获取文件 - * - * @param bucket 桶名称 + * @param bucket 桶名称 * @param fileName 文件空间/名称 * @param response * @return diff --git a/pigx-visual/pigx-codegen/pom.xml b/pigx-visual/pigx-codegen/pom.xml index 30acc3974..055488dd2 100755 --- a/pigx-visual/pigx-codegen/pom.xml +++ b/pigx-visual/pigx-codegen/pom.xml @@ -14,6 +14,11 @@ 代码生成模块 + + 4.0 + 12.1.0.1-atlassian-hosted + + @@ -44,6 +49,23 @@ mysql mysql-connector-java + + + org.postgresql + postgresql + + + + com.oracle + ojdbc6 + ${oracle.version} + + + + com.microsoft.sqlserver + sqljdbc4 + ${sqlserver.version} + com.alibaba diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenDatasourceConf.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenDatasourceConf.java index a74dbc59a..c60caf818 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenDatasourceConf.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenDatasourceConf.java @@ -50,10 +50,40 @@ public class GenDatasourceConf extends Model { private String name; /** - * jdbcurl + * 数据库类型 + */ + private String dsType; + + /** + * 配置类型 (0 主机形式 | 1 url形式) + */ + private Integer confType; + + /** + * 主机地址 + */ + private String host; + + /** + * 端口 + */ + private Integer port; + + /** + * jdbc-url */ private String url; + /** + * 实例 + */ + private String instance; + + /** + * 数据库名称 + */ + private String dsName; + /** * 用户名 */ @@ -80,9 +110,4 @@ public class GenDatasourceConf extends Model { @TableLogic private String delFlag; - /** - * 租户ID - */ - private Integer tenantId; - } 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 index 59bbe048c..3a73c5368 100755 --- 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 @@ -58,4 +58,9 @@ public class TableEntity { */ private String lowerClassName; + /** + * 数据库类型 (用于根据数据库个性化) + */ + private String dbType; + } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GenTableColumnMapper.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GenTableColumnMapper.java deleted file mode 100644 index 3567d6e39..000000000 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GenTableColumnMapper.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.pig4cloud.pigx.codegen.mapper; - -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.pig4cloud.pigx.codegen.entity.ColumnEntity; -import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; - -import java.util.List; -import java.util.Map; - -/** - * @author lengleng - * @date 2020/5/18 - */ -@Mapper -public interface GenTableColumnMapper extends PigxBaseMapper { - - /** - * 分页查询表分页信息 - * @param page - * @param tableName - * @param dsName - * @return - */ - @DS("#last") - IPage selectTableColumn(Page page, @Param("tableName") String tableName, - @Param("dsName") String dsName); - - /** - * 查询表全部列信息 - * @param tableName - * @param dsName - * @return - */ - @DS("#last") - List selectTableColumn(@Param("tableName") String tableName, @Param("dsName") String dsName); - - /** - * 查询表全部列信息 - * @param tableName 表名称 - * @param dsName 数据源名称 - * @return - */ - @DS("#last") - List> selectMapTableColumn(@Param("tableName") String tableName, String dsName); - -} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMapper.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMapper.java index b6fc50401..057ef69df 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMapper.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMapper.java @@ -20,7 +20,8 @@ package com.pig4cloud.pigx.codegen.mapper; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.ibatis.annotations.Mapper; +import com.pig4cloud.pigx.codegen.entity.ColumnEntity; +import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -32,8 +33,7 @@ import java.util.Map; * @author lengleng * @date 2018-07-30 */ -@Mapper -public interface GeneratorMapper { +public interface GeneratorMapper extends PigxBaseMapper { /** * 分页查询表格 @@ -41,7 +41,7 @@ public interface GeneratorMapper { * @param tableName 表名称 * @return */ - IPage>> queryList(Page page, @Param("tableName") String tableName); + IPage>> queryTable(Page page, @Param("tableName") String tableName); /** * 查询表信息 @@ -52,4 +52,33 @@ public interface GeneratorMapper { @DS("#last") Map queryTable(@Param("tableName") String tableName, String dsName); + /** + * 分页查询表分页信息 + * @param page + * @param tableName + * @param dsName + * @return + */ + @DS("#last") + IPage selectTableColumn(Page page, @Param("tableName") String tableName, + @Param("dsName") String dsName); + + /** + * 查询表全部列信息 + * @param tableName + * @param dsName + * @return + */ + @DS("#last") + List selectTableColumn(@Param("tableName") String tableName, @Param("dsName") String dsName); + + /** + * 查询表全部列信息 + * @param tableName 表名称 + * @param dsName 数据源名称 + * @return + */ + @DS("#last") + List> selectMapTableColumn(@Param("tableName") String tableName, String dsName); + } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMssqlMapper.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMssqlMapper.java new file mode 100755 index 000000000..6849530bf --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMssqlMapper.java @@ -0,0 +1,31 @@ +/* + * 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 org.apache.ibatis.annotations.Mapper; + +/** + * 支持 SQL SERVER 代码生成器 + * + * @author lengleng + * @date 2020-12-11 + */ +@Mapper +public interface GeneratorMssqlMapper extends GeneratorMapper { + +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMySqlMapper.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMySqlMapper.java new file mode 100755 index 000000000..a490d67f6 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMySqlMapper.java @@ -0,0 +1,31 @@ +/* + * 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 org.apache.ibatis.annotations.Mapper; + +/** + * 支持 MySql 代码生成器 + * + * @author lengleng + * @date 2020-12-11 + */ +@Mapper +public interface GeneratorMySqlMapper extends GeneratorMapper { + +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorOracleMapper.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorOracleMapper.java new file mode 100755 index 000000000..4ad521c2b --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorOracleMapper.java @@ -0,0 +1,31 @@ +/* + * 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 org.apache.ibatis.annotations.Mapper; + +/** + * 支持 Oracle 代码生成器 + * + * @author lengleng + * @date 2020-12-11 + */ +@Mapper +public interface GeneratorOracleMapper extends GeneratorMapper { + +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorPgMapper.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorPgMapper.java new file mode 100755 index 000000000..b140f3e00 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorPgMapper.java @@ -0,0 +1,31 @@ +/* + * 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 org.apache.ibatis.annotations.Mapper; + +/** + * 支持 PostgreSQL 代码生成器 + * + * @author lengleng + * @date 2020-12-11 + */ +@Mapper +public interface GeneratorPgMapper extends GeneratorMapper { + +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableColumnService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableColumnService.java index 2c755124f..6eebf7e96 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableColumnService.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableColumnService.java @@ -19,7 +19,6 @@ package com.pig4cloud.pigx.codegen.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.IService; import com.pig4cloud.pigx.codegen.entity.ColumnEntity; import com.pig4cloud.pigx.codegen.entity.GenConfig; @@ -29,7 +28,7 @@ import com.pig4cloud.pigx.codegen.entity.GenConfig; * @author lengleng * @date 2020-05-18 */ -public interface GenTableColumnService extends IService { +public interface GenTableColumnService { /** * 查询表的字段信息 diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenDatasourceConfServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenDatasourceConfServiceImpl.java index b4c20b280..1002a76e0 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenDatasourceConfServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenDatasourceConfServiceImpl.java @@ -25,6 +25,8 @@ import com.pig4cloud.pigx.codegen.entity.GenDatasourceConf; import com.pig4cloud.pigx.codegen.mapper.GenDatasourceConfMapper; import com.pig4cloud.pigx.codegen.service.GenDatasourceConfService; import com.pig4cloud.pigx.common.core.util.SpringContextHolder; +import com.pig4cloud.pigx.common.datasource.util.DsConfTypeEnum; +import com.pig4cloud.pigx.common.datasource.util.DsJdbcUrlEnum; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jasypt.encryption.StringEncryptor; @@ -134,8 +136,24 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl implements GenFormConfService { - private final GenTableColumnMapper tableColumnMapper; - /** * 1. 根据数据源、表名称,查询已配置表单信息 2. 不存在调用模板生成 * @param dsName 数据源ID @@ -68,7 +66,8 @@ public class GenFormConfServiceImpl extends ServiceImpl columns = tableColumnMapper.selectTableColumn(tableName, dsName); + GeneratorMapper mapper = GenUtils.getMapper(dsName); + List columns = mapper.selectTableColumn(tableName, dsName); // 设置velocity资源加载器 Properties prop = new Properties(); prop.put("file.resource.loader.class", ClasspathResourceLoader.class.getName()); @@ -79,8 +78,15 @@ public class GenFormConfServiceImpl extends ServiceImpl columnList = new ArrayList<>(); for (ColumnEntity column : columns) { ColumnEntity columnEntity = new ColumnEntity(); - columnEntity.setComments(column.getComments()); columnEntity.setLowerAttrName(StringUtils.uncapitalize(GenUtils.columnToJava(column.getColumnName()))); + + // 判断注释是否为空 + if (StrUtil.isNotBlank(column.getComments())) { + columnEntity.setComments(column.getComments()); + } + else { + columnEntity.setComments(columnEntity.getLowerAttrName()); + } columnList.add(columnEntity); } context.put("columns", columnList); diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableColumnServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableColumnServiceImpl.java index f3c07c4da..b4ba6c100 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableColumnServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableColumnServiceImpl.java @@ -2,13 +2,12 @@ package com.pig4cloud.pigx.codegen.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.pig4cloud.pigx.codegen.entity.ColumnEntity; import com.pig4cloud.pigx.codegen.entity.GenConfig; -import com.pig4cloud.pigx.codegen.mapper.GenTableColumnMapper; +import com.pig4cloud.pigx.codegen.mapper.GeneratorMapper; import com.pig4cloud.pigx.codegen.service.GenTableColumnService; import com.pig4cloud.pigx.codegen.util.GenUtils; -import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; @@ -20,13 +19,13 @@ import org.springframework.stereotype.Service; * @date 2020/5/18 */ @Service -@AllArgsConstructor -public class GenTableColumnServiceImpl extends ServiceImpl - implements GenTableColumnService { +@RequiredArgsConstructor +public class GenTableColumnServiceImpl implements GenTableColumnService { @Override public IPage listTable(Page page, GenConfig genConfig) { - IPage columnPage = baseMapper.selectTableColumn(page, genConfig.getTableName(), + GeneratorMapper mapper = GenUtils.getMapper(genConfig.getDsName()); + IPage columnPage = mapper.selectTableColumn(page, genConfig.getTableName(), genConfig.getDsName()); // 处理 数据库类型和 Java 类型关系 diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java index d39399e2f..fa48b60b3 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java @@ -21,14 +21,13 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; -import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.pig4cloud.pigx.codegen.entity.GenConfig; import com.pig4cloud.pigx.codegen.entity.GenFormConf; import com.pig4cloud.pigx.codegen.mapper.GenFormConfMapper; -import com.pig4cloud.pigx.codegen.mapper.GenTableColumnMapper; import com.pig4cloud.pigx.codegen.mapper.GeneratorMapper; import com.pig4cloud.pigx.codegen.service.GeneratorService; import com.pig4cloud.pigx.codegen.util.GenUtils; @@ -50,10 +49,6 @@ import java.util.zip.ZipOutputStream; @AllArgsConstructor public class GeneratorServiceImpl implements GeneratorService { - private final GenTableColumnMapper tableColumnMapper; - - private final GeneratorMapper generatorMapper; - private final GenFormConfMapper genFormConfMapper; /** @@ -63,9 +58,11 @@ public class GeneratorServiceImpl implements GeneratorService { * @return */ @Override - @DS("#last") public IPage>> getPage(Page page, String tableName, String dsName) { - return generatorMapper.queryList(page, tableName); + GeneratorMapper mapper = GenUtils.getMapper(dsName); + // 手动切换数据源 + DynamicDataSourceContextHolder.push(dsName); + return mapper.queryTable(page, tableName); } @Override @@ -75,12 +72,14 @@ public class GeneratorServiceImpl implements GeneratorService { .eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime)); String tableNames = genConfig.getTableName(); + String dsName = genConfig.getDsName(); + GeneratorMapper mapper = GenUtils.getMapper(genConfig.getDsName()); + for (String tableName : StrUtil.split(tableNames, StrUtil.DASHED)) { // 查询表信息 - Map table = generatorMapper.queryTable(tableName, genConfig.getDsName()); + Map table = mapper.queryTable(tableName, dsName); // 查询列信息 - List> columns = tableColumnMapper.selectMapTableColumn(tableName, - genConfig.getDsName()); + List> columns = mapper.selectMapTableColumn(tableName, dsName); // 生成代码 if (CollUtil.isNotEmpty(formConfList)) { return GenUtils.generatorCode(genConfig, table, columns, null, formConfList.get(0)); @@ -107,12 +106,14 @@ public class GeneratorServiceImpl implements GeneratorService { ZipOutputStream zip = new ZipOutputStream(outputStream); String tableNames = genConfig.getTableName(); + String dsName = genConfig.getDsName(); + GeneratorMapper mapper = GenUtils.getMapper(dsName); + for (String tableName : StrUtil.split(tableNames, StrUtil.DASHED)) { // 查询表信息 - Map table = generatorMapper.queryTable(tableName, genConfig.getDsName()); + Map table = mapper.queryTable(tableName, dsName); // 查询列信息 - List> columns = tableColumnMapper.selectMapTableColumn(tableName, - genConfig.getDsName()); + List> columns = mapper.selectMapTableColumn(tableName, dsName); // 生成代码 if (CollUtil.isNotEmpty(formConfList)) { GenUtils.generatorCode(genConfig, table, columns, zip, formConfList.get(0)); 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 index ed5e86c1f..0eca90c31 100644 --- 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 @@ -21,13 +21,15 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; -import com.pig4cloud.pigx.codegen.entity.ColumnEntity; -import com.pig4cloud.pigx.codegen.entity.GenConfig; -import com.pig4cloud.pigx.codegen.entity.GenFormConf; -import com.pig4cloud.pigx.codegen.entity.TableEntity; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.pig4cloud.pigx.codegen.entity.*; +import com.pig4cloud.pigx.codegen.mapper.GenDatasourceConfMapper; +import com.pig4cloud.pigx.codegen.mapper.GeneratorMapper; import com.pig4cloud.pigx.common.core.constant.CommonConstants; import com.pig4cloud.pigx.common.core.constant.enums.StyleTypeEnum; import com.pig4cloud.pigx.common.core.exception.CheckedException; +import com.pig4cloud.pigx.common.core.util.SpringContextHolder; +import com.pig4cloud.pigx.common.datasource.util.DsJdbcUrlEnum; import lombok.SneakyThrows; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; @@ -39,6 +41,7 @@ import org.apache.commons.lang.WordUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; +import org.springframework.context.ApplicationContext; import java.io.File; import java.io.IOException; @@ -133,6 +136,8 @@ public class GenUtils { tableEntity.setComments(table.get("tableComment")); } + tableEntity.setDbType(table.get("dbType")); + String tablePrefix; if (StrUtil.isNotBlank(genConfig.getTablePrefix())) { tablePrefix = genConfig.getTablePrefix(); @@ -153,7 +158,6 @@ public class GenUtils { ColumnEntity columnEntity = new ColumnEntity(); columnEntity.setColumnName(column.get("columnName")); columnEntity.setDataType(column.get("dataType")); - columnEntity.setComments(column.get("comments")); columnEntity.setExtra(column.get("extra")); columnEntity.setNullable("NO".equals(column.get("isNullable"))); columnEntity.setColumnType(column.get("columnType")); @@ -169,6 +173,14 @@ public class GenUtils { columnEntity.setCaseAttrName(attrName); columnEntity.setLowerAttrName(StringUtils.uncapitalize(attrName)); + // 判断注释是否为空 + if (StrUtil.isNotBlank(column.get("comments"))) { + columnEntity.setComments(column.get("comments")); + } + else { + columnEntity.setComments(columnEntity.getLowerAttrName()); + } + // 列的数据类型,转换成Java类型 String attrType = config.getString(columnEntity.getDataType(), "unknowType"); columnEntity.setAttrType(attrType); @@ -389,4 +401,38 @@ public class GenUtils { return null; } + /** + * 根据目标数据源名称动态匹配Mapper + * @param dsName + * @return + */ + public GeneratorMapper getMapper(String dsName) { + // 获取目标数据源数据库类型 + GenDatasourceConfMapper datasourceConfMapper = SpringContextHolder.getBean(GenDatasourceConfMapper.class); + GenDatasourceConf datasourceConf = datasourceConfMapper + .selectOne(Wrappers.lambdaQuery().eq(GenDatasourceConf::getName, dsName)); + + String dbConfType; + // 默认MYSQL 数据源 + if (datasourceConf == null) { + dbConfType = DsJdbcUrlEnum.MYSQL.getDbName(); + } + else { + dbConfType = datasourceConf.getDsType(); + } + + // 获取全部数据实现 + ApplicationContext context = SpringContextHolder.getApplicationContext(); + Map beansOfType = context.getBeansOfType(GeneratorMapper.class); + + // 根据数据类型选择mapper + for (String key : beansOfType.keySet()) { + if (StrUtil.containsIgnoreCase(key, dbConfType)) { + return beansOfType.get(key); + } + } + + throw new IllegalArgumentException("dsName 不合法: " + dsName); + } + } diff --git a/pigx-visual/pigx-codegen/src/main/resources/generator.properties b/pigx-visual/pigx-codegen/src/main/resources/generator.properties index dfe6d305a..7a76a6e2a 100755 --- a/pigx-visual/pigx-codegen/src/main/resources/generator.properties +++ b/pigx-visual/pigx-codegen/src/main/resources/generator.properties @@ -1,37 +1,59 @@ #\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_ +# hidden columns in Swagger Models +hiddenColumn=tenant_id -#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F +#MYSQL \u7C7B\u578B\u8F6C\u6362 tinyint=Integer smallint=Integer mediumint=Integer -int=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 -# hidden columns in Swagger Models -hiddenColumn=tenant_id +# PG \u7C7B\u578B\u8F6C\u5316\u89C4\u5219 +int2=Integer +int4=Integer +int8=Long + +#ORACLE \u7279\u6B8A\u7C7B\u578B\u8F6C\u6362\u89C4\u5219 +INT=Integer +INTEGER=Integer +LONG=LONG +NUMBER=Integer +BINARY_INTEGER=Integer +FLOAT=Float +BINARY_FLOAT=Float +DOUBLE=Double +BINARY_DOUBLE=Double +DECIMAL=BigDecimal +CHAR=String +VARCHAR=String +VARCHAR2=String +NVARCHAR=String +NVARCHAR2=String +DATE=LocalDateTime +DATETIME=LocalDateTime +TIMESTAMP=LocalDateTime +CLOB=String +BLOB=String \ No newline at end of file diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/GenTableColumnMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/GenTableColumnMapper.xml deleted file mode 100755 index 0ad2f47b1..000000000 --- a/pigx-visual/pigx-codegen/src/main/resources/mapper/GenTableColumnMapper.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - SELECT - column_name columnName, - data_type dataType, - column_comment comments, - column_key columnKey, - extra, - is_nullable AS isNullable, - column_type AS columnType - FROM - information_schema.COLUMNS - WHERE - table_name = #{tableName} and table_schema = (select database()) order by ordinal_position - - - - - - - diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMapper.xml deleted file mode 100755 index 50905ea51..000000000 --- a/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMapper.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMssqlMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMssqlMapper.xml new file mode 100755 index 000000000..4ea9b31a5 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMssqlMapper.xml @@ -0,0 +1,87 @@ + + + + + + + + + SELECT + 'mssql' AS dbType, + CAST ( b.NAME AS NVARCHAR ( 500 ) ) AS columnName, + CAST ( sys.types.NAME AS NVARCHAR ( 500 ) ) AS dataType, + CAST ( sys.types.NAME AS NVARCHAR ( 500 ) ) AS columnType, + CAST ( c.VALUE AS NVARCHAR ( 500 ) ) AS comments, + ( + SELECT + CASE + COUNT + ( 1 ) + WHEN 1 THEN + 'PRI' ELSE '' + END + FROM + syscolumns, + sysobjects, + sysindexes, + sysindexkeys, + systypes + WHERE + syscolumns.xusertype = systypes.xusertype + AND syscolumns.id = object_id( A.NAME ) + AND sysobjects.xtype = 'PK' + AND sysobjects.parent_obj = syscolumns.id + AND sysindexes.id = syscolumns.id + AND sysobjects.NAME = sysindexes.NAME + AND sysindexkeys.id = syscolumns.id + AND sysindexkeys.indid = sysindexes.indid + AND syscolumns.colid = sysindexkeys.colid + AND syscolumns.NAME = B.NAME + ) AS columnKey, + '' AS extra + FROM + ( + SELECT + name, + object_id + FROM + sys.tables UNION ALL + SELECT + name, + object_id + FROM + sys.views + ) a + INNER JOIN sys.COLUMNS b ON b.object_id = a.object_id + LEFT JOIN sys.types ON b.user_type_id = sys.types.user_type_id + LEFT JOIN sys.extended_properties c ON c.major_id = b.object_id + AND c.minor_id = b.column_id + WHERE a.NAME = #{tableName} and sys.types.NAME != 'sysname' + + + + + + + diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMySqlMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMySqlMapper.xml new file mode 100755 index 000000000..e372b1a6c --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorMySqlMapper.xml @@ -0,0 +1,49 @@ + + + + + + + + + + SELECT + column_name columnName, + data_type dataType, + column_comment comments, + column_key columnKey, + extra, + is_nullable AS isNullable, + column_type AS columnType + FROM + information_schema.COLUMNS + WHERE + table_name = #{tableName} and table_schema = (select database()) order by ordinal_position + + + + + + + diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorOracleMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorOracleMapper.xml new file mode 100755 index 000000000..6a99dac34 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorOracleMapper.xml @@ -0,0 +1,72 @@ + + + + + + + + + SELECT + 'oracle' AS "dbType", + TEMP.COLUMN_NAME AS "columnName", + TEMP.data_type AS "columnType", + TEMP.data_type AS "dataType", + TEMP.comments AS comments, + CASE + TEMP.constraint_type + WHEN 'P' THEN + 'PRI' + WHEN 'C' THEN + 'UNI' ELSE'' + END "COLUMNKEY" + FROM + ( + SELECT + col.column_id, + col.COLUMN_NAME, + col.data_type, + colc.comments, + uc.constraint_type, + ROW_NUMBER ( ) OVER ( + PARTITION BY col.COLUMN_NAME + ORDER BY + uc.constraint_type DESC + ) AS row_flg + FROM + user_tab_columns col + LEFT JOIN user_col_comments colc ON colc.TABLE_NAME = col.TABLE_NAME + AND colc.COLUMN_NAME = col. + COLUMN_NAME LEFT JOIN user_cons_columns ucc ON ucc.TABLE_NAME = col.TABLE_NAME + AND ucc.COLUMN_NAME = col. + COLUMN_NAME LEFT JOIN user_constraints uc ON uc.CONSTRAINT_NAME = ucc.CONSTRAINT_NAME + WHERE + col.TABLE_NAME = UPPER ( #{tableName} ) + ) TEMP + WHERE + TEMP.row_flg = 1 + ORDER BY + TEMP.column_id + + + + + + + diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorPgMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorPgMapper.xml new file mode 100755 index 000000000..4b62ca251 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/mapper/GeneratorPgMapper.xml @@ -0,0 +1,57 @@ + + + + + + + + + + SELECT + 'pg' AS "dbType", + pa.attname AS "columnName", + pg_type.typname AS "columnType", + pg_type.typname AS "dataType", + col_description ( pa.attrelid, pa.attnum ) AS "comments", + ( + CASE + pcon.contype + WHEN 'p' THEN + 'PRI' ELSE'' + END + ) AS "columnKey" + FROM + pg_class AS pc, + pg_attribute AS pa + INNER JOIN pg_type ON pg_type.oid = pa.atttypid + LEFT JOIN pg_constraint pcon ON pa.attnum = pcon.conkey[1] + AND pa.attrelid = pcon.conrelid + WHERE + pc.relname = #{ tableName } + AND pa.attrelid = pc.oid + AND pa.attnum > 0; + + + + + + 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 index eb9a71379..64ba13d41 100755 --- a/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm +++ b/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm @@ -17,6 +17,9 @@ package ${package}.${moduleName}.entity; +#if($dbType != "mysql") +import com.baomidou.mybatisplus.annotation.IdType; +#end import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.activerecord.Model; @@ -41,16 +44,22 @@ import java.time.LocalDateTime; @EqualsAndHashCode(callSuper = true) @ApiModel(value = "${comments}") public class ${className} extends Model<${className}> { -private static final long serialVersionUID = 1L; - #foreach ($column in $columns) -/** + private static final long serialVersionUID = 1L; + +#foreach ($column in $columns) + /** * $column.comments */ - #if($column.columnName == $pk.columnName) -@TableId - #end -@ApiModelProperty(value="$column.comments"#if($column.hidden),hidden=$column.hidden#end) +#if($column.columnName == $pk.columnName) +#if($dbType == "mysql") + @TableId +#else + @TableId(type = IdType.ASSIGN_ID) +#end +#end + @ApiModelProperty(value="$column.comments"#if($column.hidden),hidden=$column.hidden#end) private $column.attrType $column.lowerAttrName; - #end + +#end }