From 029b90b237994a6a842bafbcfcca4851bafe9ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 7 Feb 2020 13:03:59 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=E7=94=9F=E4=BA=A7=20?= =?UTF-8?q?=E5=A4=9A=E6=95=B0=E6=8D=AE=E6=BA=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pigx-common/pigx-common-bom/pom.xml | 8 +- .../pig4cloud/pigx/common/core/util/R.java | 1 + pigx-common/pigx-common-datasource/pom.xml | 10 +- .../DataSourceAutoConfiguration.java | 16 - .../DynamicDataSourceAutoConfiguration.java | 56 ++++ .../annotation/EnableDynamicDataSource.java | 7 +- .../config/DruidDataSourceProperties.java | 5 + .../datasource/config/DynamicDataSource.java | 25 -- .../config/DynamicDataSourceConfig.java | 104 ------ .../config/DynamicDatasourceInterceptor.java | 44 --- .../config/JdbcDynamicDataSourceProvider.java | 75 +++++ .../config/LastParamDsProcessor.java | 57 ++++ .../support/DataSourceConstants.java | 5 - .../DynamicDataSourceContextHolder.java | 40 --- .../main/resources/META-INF/spring.factories | 2 - pigx-visual/pigx-code/Dockerfile | 15 - pigx-visual/pigx-code/README.md | 90 ----- pigx-visual/pigx-code/pom.xml | 107 ------ .../pigx/code/PigxCodeApplication.java | 44 --- .../JdbcDynamicDataSourceProperties.java | 21 -- .../config/JdbcDynamicDataSourceProvider.java | 47 --- .../code/controller/GenDsConfController.java | 141 -------- .../controller/GenFormConfController.java | 127 ------- .../code/controller/GeneratorController.java | 74 ----- .../pigx/code/entity/ColumnEntity.java | 70 ---- .../pig4cloud/pigx/code/entity/GenConfig.java | 59 ---- .../pigx/code/entity/GenDatasourceConf.java | 79 ----- .../pigx/code/entity/GenFormConf.java | 79 ----- .../pigx/code/entity/TableEntity.java | 55 --- .../code/mapper/GenDatasourceConfMapper.java | 30 -- .../pigx/code/mapper/GenFormConfMapper.java | 33 -- .../pigx/code/mapper/GeneratorMapper.java | 59 ---- .../service/GenDatasourceConfService.java | 44 --- .../pigx/code/service/GenFormConfService.java | 40 --- .../pigx/code/service/GeneratorService.java | 48 --- .../impl/GenDatasourceConfServiceImpl.java | 68 ---- .../service/impl/GenFormConfServiceImpl.java | 98 ------ .../service/impl/GeneratorServiceImpl.java | 106 ------ .../pig4cloud/pigx/code/util/GenUtils.java | 312 ------------------ .../src/main/resources/bootstrap.yml | 16 - .../src/main/resources/generator.properties | 37 --- .../resources/mapper/GenFormConfMapper.xml | 33 -- .../main/resources/mapper/GeneratorMapper.xml | 23 -- .../resources/template/Controller.java.vm | 110 ------ .../main/resources/template/Entity.java.vm | 56 ---- .../main/resources/template/Mapper.java.vm | 31 -- .../src/main/resources/template/Mapper.xml.vm | 35 -- .../main/resources/template/Service.java.vm | 31 -- .../resources/template/ServiceImpl.java.vm | 34 -- .../src/main/resources/template/api.js.vm | 56 ---- .../src/main/resources/template/crud.js.vm | 17 - .../src/main/resources/template/index.vue.vm | 121 ------- .../src/main/resources/template/menu.sql.vm | 16 - pigx-visual/pigx-codegen/pom.xml | 5 + .../pigx/codegen/PigxCodeGenApplication.java | 1 + .../controller/GenDsConfController.java | 10 +- .../controller/GenFormConfController.java | 6 +- .../controller/GeneratorController.java | 6 +- .../pigx/codegen/entity/GenConfig.java | 4 +- .../pigx/codegen/mapper/GeneratorMapper.java | 7 +- .../service/GenDatasourceConfService.java | 25 ++ .../codegen/service/GenFormConfService.java | 4 +- .../codegen/service/GeneratorService.java | 32 +- .../impl/GenDatasourceConfServiceImpl.java | 103 +++++- .../service/impl/GenFormConfServiceImpl.java | 8 +- .../service/impl/GeneratorServiceImpl.java | 23 +- pigx-visual/pigx-dynamic-datasource/README.md | 94 ------ .../pigx-dynamic-datasource-api/pom.xml | 27 -- .../pigx/dynamic/feign/packge-info.java | 6 - .../pigx-dynamic-datasource-biz/pom.xml | 99 ------ .../PigxDynamicDatasourceApplication.java | 25 -- .../dynamic/controller/TestController.java | 96 ------ .../pigx/dynamic/mapper/TestMapper.java | 50 --- .../com/pig4cloud/pigx/dynamic/vo/UserVO.java | 10 - .../src/main/resources/bootstrap.yml | 16 - .../src/main/resources/logback-spring.xml | 70 ---- .../src/main/resources/mapper/TestMapper.xml | 13 - pigx-visual/pigx-dynamic-datasource/pom.xml | 179 ---------- pigx-visual/pom.xml | 2 - 79 files changed, 378 insertions(+), 3460 deletions(-) delete mode 100644 pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DataSourceAutoConfiguration.java create mode 100644 pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DynamicDataSourceAutoConfiguration.java delete mode 100644 pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDataSource.java delete mode 100644 pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDataSourceConfig.java delete mode 100644 pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDatasourceInterceptor.java create mode 100644 pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/JdbcDynamicDataSourceProvider.java create mode 100644 pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/LastParamDsProcessor.java delete mode 100644 pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/support/DynamicDataSourceContextHolder.java delete mode 100644 pigx-common/pigx-common-datasource/src/main/resources/META-INF/spring.factories delete mode 100644 pigx-visual/pigx-code/Dockerfile delete mode 100644 pigx-visual/pigx-code/README.md delete mode 100644 pigx-visual/pigx-code/pom.xml delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/PigxCodeApplication.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/config/JdbcDynamicDataSourceProperties.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/config/JdbcDynamicDataSourceProvider.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GenDsConfController.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GenFormConfController.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GeneratorController.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/ColumnEntity.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenConfig.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenDatasourceConf.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenFormConf.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/TableEntity.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GenDatasourceConfMapper.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GenFormConfMapper.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GeneratorMapper.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GenDatasourceConfService.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GenFormConfService.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GeneratorService.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GenDatasourceConfServiceImpl.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GenFormConfServiceImpl.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GeneratorServiceImpl.java delete mode 100644 pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/util/GenUtils.java delete mode 100644 pigx-visual/pigx-code/src/main/resources/bootstrap.yml delete mode 100644 pigx-visual/pigx-code/src/main/resources/generator.properties delete mode 100644 pigx-visual/pigx-code/src/main/resources/mapper/GenFormConfMapper.xml delete mode 100644 pigx-visual/pigx-code/src/main/resources/mapper/GeneratorMapper.xml delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/Controller.java.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/Entity.java.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/Mapper.java.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/Mapper.xml.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/Service.java.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/ServiceImpl.java.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/api.js.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/crud.js.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/index.vue.vm delete mode 100644 pigx-visual/pigx-code/src/main/resources/template/menu.sql.vm delete mode 100644 pigx-visual/pigx-dynamic-datasource/README.md delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-api/pom.xml delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-api/src/main/java/com/pig4cloud/pigx/dynamic/feign/packge-info.java delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/pom.xml delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/PigxDynamicDatasourceApplication.java delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/controller/TestController.java delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/mapper/TestMapper.java delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/vo/UserVO.java delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/bootstrap.yml delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/logback-spring.xml delete mode 100644 pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/mapper/TestMapper.xml delete mode 100644 pigx-visual/pigx-dynamic-datasource/pom.xml diff --git a/pigx-common/pigx-common-bom/pom.xml b/pigx-common/pigx-common-bom/pom.xml index 003fdee7f..107d1081f 100644 --- a/pigx-common/pigx-common-bom/pom.xml +++ b/pigx-common/pigx-common-bom/pom.xml @@ -18,7 +18,8 @@ 3.7.0 - 3.3.0 + 3.3.1 + 3.0.0 1.1.21 8.0.18 1.5.22 @@ -143,6 +144,11 @@ weixin-java-common ${mp.weixin.version} + + com.baomidou + dynamic-datasource-spring-boot-starter + ${dynamic-ds.version} + diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/R.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/R.java index 09b511c19..82fe04b54 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/R.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/util/R.java @@ -33,6 +33,7 @@ import java.io.Serializable; * @param * @author lengleng */ +@Builder @ToString @NoArgsConstructor @AllArgsConstructor diff --git a/pigx-common/pigx-common-datasource/pom.xml b/pigx-common/pigx-common-datasource/pom.xml index d8703af69..3b1f1d2e4 100644 --- a/pigx-common/pigx-common-datasource/pom.xml +++ b/pigx-common/pigx-common-datasource/pom.xml @@ -34,13 +34,11 @@ com.pig4cloud pigx-common-core - - - - com.pig4cloud - pigx-common-data - + + com.baomidou + dynamic-datasource-spring-boot-starter + com.baomidou mybatis-plus-boot-starter diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DataSourceAutoConfiguration.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DataSourceAutoConfiguration.java deleted file mode 100644 index 011876df7..000000000 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DataSourceAutoConfiguration.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.pig4cloud.pigx.common.datasource; - -import com.pig4cloud.pigx.common.datasource.config.DruidDataSourceProperties; -import lombok.AllArgsConstructor; -import org.springframework.boot.context.properties.EnableConfigurationProperties; - -/** - * @author Lucky - * @date 2019-05-18 - *

- * 自动配置类 - */ -@AllArgsConstructor -@EnableConfigurationProperties({DruidDataSourceProperties.class}) -public class DataSourceAutoConfiguration { -} 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 new file mode 100644 index 000000000..0e7dbd146 --- /dev/null +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/DynamicDataSourceAutoConfiguration.java @@ -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) + */ + +package com.pig4cloud.pigx.common.datasource; + +import com.baomidou.dynamic.datasource.processor.DsProcessor; +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 lombok.AllArgsConstructor; +import org.jasypt.encryption.StringEncryptor; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +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; + +/** + * @author lengleng + * @date 2020-02-06 + *

+ * 动态数据源切换配置 + */ +@Configuration +@AllArgsConstructor +@AutoConfigureAfter(DataSourceAutoConfiguration.class) +@EnableConfigurationProperties(DruidDataSourceProperties.class) +public class DynamicDataSourceAutoConfiguration { + private final StringEncryptor stringEncryptor; + private final DruidDataSourceProperties properties; + + @Bean + public DynamicDataSourceProvider dynamicDataSourceProvider() { + return new JdbcDynamicDataSourceProvider(stringEncryptor, properties); + } + + @Bean + public DsProcessor dsProcessor() { + return new LastParamDsProcessor(); + } +} diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/annotation/EnableDynamicDataSource.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/annotation/EnableDynamicDataSource.java index 99ebdbd6d..c04d6a105 100644 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/annotation/EnableDynamicDataSource.java +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/annotation/EnableDynamicDataSource.java @@ -1,6 +1,8 @@ package com.pig4cloud.pigx.common.datasource.annotation; -import com.pig4cloud.pigx.common.datasource.config.DynamicDataSourceConfig; +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; +import com.pig4cloud.pigx.common.datasource.DynamicDataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Import; import java.lang.annotation.*; @@ -15,6 +17,7 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@Import({DynamicDataSourceConfig.class}) +@EnableAutoConfiguration(exclude = {DruidDataSourceAutoConfigure.class}) +@Import(DynamicDataSourceAutoConfiguration.class) public @interface EnableDynamicDataSource { } diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DruidDataSourceProperties.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DruidDataSourceProperties.java index efb00821c..08a8ba6d3 100644 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DruidDataSourceProperties.java +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DruidDataSourceProperties.java @@ -18,4 +18,9 @@ public class DruidDataSourceProperties { private String password; private String url; private String driverClassName; + + /** + * 查询数据源的SQL + */ + private String queryDsSql; } diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDataSource.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDataSource.java deleted file mode 100644 index 557b5d236..000000000 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDataSource.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.pig4cloud.pigx.common.datasource.config; - -import com.pig4cloud.pigx.common.datasource.support.DynamicDataSourceContextHolder; -import lombok.extern.slf4j.Slf4j; -import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; - -/** - * @author lengleng - * @date 2019-03-31 - *

- * 动态数据源类 - */ -@Slf4j -public class DynamicDataSource extends AbstractRoutingDataSource { - - /** - * 指定路由Key - * - * @return - */ - @Override - protected Object determineCurrentLookupKey() { - return DynamicDataSourceContextHolder.getDataSourceType(); - } -} \ No newline at end of file diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDataSourceConfig.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDataSourceConfig.java deleted file mode 100644 index 56a0b870b..000000000 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDataSourceConfig.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.pig4cloud.pigx.common.datasource.config; - -import com.alibaba.druid.pool.DruidDataSource; -import com.mysql.cj.jdbc.Driver; -import com.pig4cloud.pigx.common.datasource.support.DataSourceConstants; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.jasypt.encryption.StringEncryptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.transaction.ChainedTransactionManager; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.TransactionManagementConfigurer; - -import javax.annotation.PostConstruct; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * @author lengleng - * @date 2019-03-31 - *

- * 动态数据源切换配置 - */ -@Slf4j -@Configuration -@AllArgsConstructor -public class DynamicDataSourceConfig implements TransactionManagementConfigurer { - private final Map dataSourceMap = new HashMap<>(8); - private final DruidDataSourceProperties dataSourceProperties; - private final StringEncryptor stringEncryptor; - - @Bean("dynamicDataSource") - public DynamicDataSource dataSource() { - DynamicDataSource ds = new DynamicDataSource(); - DruidDataSource cads = new DruidDataSource(); - cads.setUrl(dataSourceProperties.getUrl()); - cads.setDriverClassName(dataSourceProperties.getDriverClassName()); - cads.setUsername(dataSourceProperties.getUsername()); - cads.setPassword(dataSourceProperties.getPassword()); - ds.setDefaultTargetDataSource(cads); - dataSourceMap.put(0, cads); - ds.setTargetDataSources(dataSourceMap); - return ds; - } - - /** - * 组装默认配置的数据源,查询数据库配置 - */ - @PostConstruct - public void init() { - DriverManagerDataSource dds = new DriverManagerDataSource(); - dds.setUrl(dataSourceProperties.getUrl()); - dds.setDriverClassName(dataSourceProperties.getDriverClassName()); - dds.setUsername(dataSourceProperties.getUsername()); - dds.setPassword(dataSourceProperties.getPassword()); - - List> dbList = new JdbcTemplate(dds).queryForList(DataSourceConstants.QUERY_DS_SQL); - log.info("开始 -> 初始化动态数据源"); - Optional.of(dbList).ifPresent(list -> list.forEach(db -> { - log.info("数据源:{}", db.get(DataSourceConstants.DS_NAME)); - DruidDataSource ds = new DruidDataSource(); - ds.setUrl(String.valueOf(db.get(DataSourceConstants.DS_JDBC_URL))); - ds.setDriverClassName(Driver.class.getName()); - ds.setUsername((String) db.get(DataSourceConstants.DS_USER_NAME)); - - String decPwd = stringEncryptor.decrypt((String) db.get(DataSourceConstants.DS_USER_PWD)); - ds.setPassword(decPwd); - dataSourceMap.put(db.get(DataSourceConstants.DS_ROUTE_KEY), ds); - })); - - log.info("完毕 -> 初始化动态数据源,共计 {} 条", dataSourceMap.size()); - } - - /** - * 重新加载数据源配置 - */ - public Boolean reload() { - init(); - DynamicDataSource dataSource = dataSource(); - dataSource.setTargetDataSources(dataSourceMap); - dataSource.afterPropertiesSet(); - return Boolean.FALSE; - } - - - @Bean - public PlatformTransactionManager txManager() { - DataSourceTransactionManager transactionManager - = new DataSourceTransactionManager(dataSource()); - return new ChainedTransactionManager(transactionManager); - } - - @Override - public PlatformTransactionManager annotationDrivenTransactionManager() { - return txManager(); - } - -} \ No newline at end of file diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDatasourceInterceptor.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDatasourceInterceptor.java deleted file mode 100644 index d10d0fac5..000000000 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/DynamicDatasourceInterceptor.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.pig4cloud.pigx.common.datasource.config; - -import com.pig4cloud.pigx.common.datasource.support.DynamicDataSourceContextHolder; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.lang.Nullable; -import org.springframework.stereotype.Component; -import org.springframework.web.servlet.HandlerInterceptor; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @author lengleng - * @date 2019-05-18 - *

- * 动态数据源拦截器 - */ -@Slf4j -@Component -@AllArgsConstructor -public class DynamicDatasourceInterceptor implements HandlerInterceptor { - - /** - * TODO 根据上下文判断路由哪个数据库 - * - * @param request - * @param response - * @param handler - * @return - */ - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - DynamicDataSourceContextHolder.setDataSourceType(1); - return true; - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, - @Nullable Exception ex) { - DynamicDataSourceContextHolder.clearDataSourceType(); - } - -} 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 new file mode 100644 index 000000000..b8706e57e --- /dev/null +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/JdbcDynamicDataSourceProvider.java @@ -0,0 +1,75 @@ +/* + * 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.common.datasource.config; + +import cn.hutool.core.util.StrUtil; +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 org.jasypt.encryption.StringEncryptor; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Map; + +/** + * @author lengleng + * @date 2020/2/6 + *

+ * 从数据源中获取 配置信息 + */ +public class JdbcDynamicDataSourceProvider extends AbstractJdbcDataSourceProvider { + private final DruidDataSourceProperties properties; + private final StringEncryptor stringEncryptor; + + public JdbcDynamicDataSourceProvider(StringEncryptor stringEncryptor, DruidDataSourceProperties properties) { + super(properties.getDriverClassName(), properties.getUrl(), properties.getUsername(), properties.getPassword()); + this.stringEncryptor = stringEncryptor; + this.properties = properties; + } + + /** + * 执行语句获得数据源参数 + * + * @param statement 语句 + * @return 数据源参数 + * @throws SQLException sql异常 + */ + @Override + protected Map executeStmt(Statement statement) throws SQLException { + ResultSet rs = statement.executeQuery(StrUtil.isBlank(properties.getQueryDsSql()) + ? DataSourceConstants.QUERY_DS_SQL + : properties.getQueryDsSql()); + + Map map = new HashMap<>(8); + while (rs.next()) { + 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); + DataSourceProperty property = new DataSourceProperty(); + property.setUsername(username); + property.setPassword(stringEncryptor.decrypt(password)); + property.setUrl(url); + map.put(name, property); + } + return map; + } +} diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/LastParamDsProcessor.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/LastParamDsProcessor.java new file mode 100644 index 000000000..10953abc9 --- /dev/null +++ b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/config/LastParamDsProcessor.java @@ -0,0 +1,57 @@ +/* + * 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.common.datasource.config; + +import com.baomidou.dynamic.datasource.processor.DsProcessor; +import org.aopalliance.intercept.MethodInvocation; + +/** + * @author lengleng + * @date 2020/2/6 + *

+ * 参数数据源解析 @DS("#last) + */ +public class LastParamDsProcessor extends DsProcessor { + + private static final String LAST_PREFIX = "#last"; + + + /** + * 抽象匹配条件 匹配才会走当前执行器否则走下一级执行器 + * + * @param key DS注解里的内容 + * @return 是否匹配 + */ + @Override + public boolean matches(String key) { + return key.startsWith(LAST_PREFIX); + } + + /** + * 抽象最终决定数据源 + * + * @param invocation 方法执行信息 + * @param key DS注解里的内容 + * @return 数据源名称 + */ + @Override + public String doDetermineDatasource(MethodInvocation invocation, String key) { + Object[] arguments = invocation.getArguments(); + return String.valueOf(arguments[arguments.length - 1]); + } +} 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 af57b82fc..3d23df3e8 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 @@ -12,11 +12,6 @@ public interface DataSourceConstants { */ String QUERY_DS_SQL = "select * from gen_datasource_conf where del_flag = 0"; - /** - * 动态路由KEY - */ - String DS_ROUTE_KEY = "id"; - /** * 数据源名称 */ diff --git a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/support/DynamicDataSourceContextHolder.java b/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/support/DynamicDataSourceContextHolder.java deleted file mode 100644 index d082585d4..000000000 --- a/pigx-common/pigx-common-datasource/src/main/java/com/pig4cloud/pigx/common/datasource/support/DynamicDataSourceContextHolder.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.pig4cloud.pigx.common.datasource.support; - -import lombok.experimental.UtilityClass; - -/** - * @author lengleng - * @date 2019-05-18 - *

- * 根据当前线程来选择具体的数据源 - */ -@UtilityClass -public class DynamicDataSourceContextHolder { - private final ThreadLocal CONTEXT_HOLDER = new ThreadLocal<>(); - - /** - * 提供给AOP去设置当前的线程的数据源的信息 - * - * @param dataSourceType - */ - public void setDataSourceType(Integer dataSourceType) { - CONTEXT_HOLDER.set(dataSourceType); - } - - /** - * 提供给AbstractRoutingDataSource的实现类,通过key选择数据源 - * - * @return - */ - public Integer getDataSourceType() { - return CONTEXT_HOLDER.get(); - } - - /** - * 使用默认的数据源 - * - */ - public void clearDataSourceType() { - CONTEXT_HOLDER.remove(); - } -} \ No newline at end of file diff --git a/pigx-common/pigx-common-datasource/src/main/resources/META-INF/spring.factories b/pigx-common/pigx-common-datasource/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 15efe41d9..000000000 --- a/pigx-common/pigx-common-datasource/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.pig4cloud.pigx.common.datasource.DataSourceAutoConfiguration \ No newline at end of file diff --git a/pigx-visual/pigx-code/Dockerfile b/pigx-visual/pigx-code/Dockerfile deleted file mode 100644 index fed99aa53..000000000 --- a/pigx-visual/pigx-code/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM anapsix/alpine-java:8_server-jre_unlimited - -MAINTAINER wangiegie@gmail.com - -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime - -RUN mkdir -p /pigx-code - -WORKDIR /pigx-code - -EXPOSE 5003 - -ADD ./pigx-visual/pigx-code/target/pigx-code.jar ./ - -CMD sleep 120;java -Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom -jar pigx-code.jar diff --git a/pigx-visual/pigx-code/README.md b/pigx-visual/pigx-code/README.md deleted file mode 100644 index fc2b73f3a..000000000 --- a/pigx-visual/pigx-code/README.md +++ /dev/null @@ -1,90 +0,0 @@ -## 使用说明 -``` -本模块是pigx-codegen的重写版本,使用dynamic-datasource实现,去除pigx-common-datasource依赖,功能未做扩展。 -``` -### pigx-code-dev.yml -``` -## spring security 配置 -security: - oauth2: - client: - client-id: ENC(gPFcUOmJm8WqM3k3eSqS0Q==) - client-secret: ENC(gPFcUOmJm8WqM3k3eSqS0Q==) - scope: server - resources: - static-locations: classpath:/static/,classpath:/views/ - -# 数据源 -spring: - datasource: - dynamic: - username: ${MYSQL-USER:root} - password: ${MYSQL-USER:root} - url: jdbc:mysql://${MYSQL-HOST:pigx-mysql}:${MYSQL-PORT:3306}/pigxx_codegen?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true - driverClassName: com.mysql.cj.jdbc.Driver - sql: select * from gen_datasource_conf - - -pigx: - tenant: - column: tenant_id - tables: - - sys_datasource_conf -``` -### 示例中的pigxx_codegen数据库及sql说明 -``` -pigxx_codegen数据库中gen_datasource_conf表必须存在一个name为master的数据库连接配置 - -INSERT INTO `gen_datasource_conf` VALUES ('8', 'master', 'jdbc:mysql://pigx-mysql:3306/pigxx_codegen?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true', 'root', 'ZkxR9PxP6sWvasdc9CG9Ww==', '2019-09-18 09:44:55', '2019-12-17 17:07:17', '0', null); -``` -### 修改菜单的url -``` -开发平台菜单下的/gen全部改为/code -如 /gen/datasource 改为 /code/datasource -``` -### 修改动态路由 -``` -{ - "routeId": "pigx-codegen", - "routeName": "代码生成模块", - "predicates": [ - { - "args": { - "_genkey_0": "/gen/**" - }, - "name": "Path" - } - ], - "filters": [], - "uri": "lb://pigx-codegen", - "order": 0, - "createTime": "2019-10-16 16:44:41", - "updateTime": "2019-11-05 22:36:58", - "delFlag": "0" - }, -改为 -{ - "routeId": "pigx-code", - "routeName": "多数据源代码生成模块", - "predicates": [ - { - "args": { - "_genkey_0": "/code/**" - }, - "name": "Path" - } - ], - "filters": [], - "uri": "lb://pigx-code", - "order": 0, - "createTime": "2019-10-16 16:44:41", - "updateTime": "2019-11-05 22:36:58", - "delFlag": "0" - }, -``` -### yml配置文件切换数据源 -``` -请参考:https://git.pig4cloud.com/pigx/pigx/src/liuyes_dev/pigx-visual/pigx-dynamic-datasource -``` -### 联系我 -QQ:55215085 \ No newline at end of file diff --git a/pigx-visual/pigx-code/pom.xml b/pigx-visual/pigx-code/pom.xml deleted file mode 100644 index 1ffaa6de9..000000000 --- a/pigx-visual/pigx-code/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - 4.0.0 - - - com.pig4cloud - pigx-visual - 3.5.0 - - - pigx-code - jar - - 多数据源代码生成模块 - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - - com.pig4cloud - pigx-common-data - - - - com.baomidou - dynamic-datasource-spring-boot-starter - 2.5.6 - - - - com.baomidou - mybatis-plus-boot-starter - - - mysql - mysql-connector-java - - - - com.alibaba - druid-spring-boot-starter - - - - com.pig4cloud - pigx-common-core - - - - com.pig4cloud - pigx-common-swagger - - - - com.pig4cloud - pigx-common-security - - - - com.pig4cloud - pigx-common-sentinel - - - com.pig4cloud - pigx-common-log - - - - velocity - org.apache.velocity - ${velocity.version} - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-undertow - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - com.spotify - docker-maven-plugin - - - - diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/PigxCodeApplication.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/PigxCodeApplication.java deleted file mode 100644 index 18def63af..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/PigxCodeApplication.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.code; - -import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; -import com.pig4cloud.pigx.common.security.annotation.EnablePigxFeignClients; -import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer; -import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.cloud.client.SpringCloudApplication; - -/** - * @author lengleng - * @date 2018/07/29 - * 代码生成模块 - */ -@EnablePigxSwagger2 -@SpringCloudApplication -@EnablePigxFeignClients -@EnablePigxResourceServer -@EnableAutoConfiguration(exclude={DruidDataSourceAutoConfigure.class}) -public class PigxCodeApplication { - - public static void main(String[] args) { - SpringApplication.run(PigxCodeApplication.class, args); - } - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/config/JdbcDynamicDataSourceProperties.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/config/JdbcDynamicDataSourceProperties.java deleted file mode 100644 index 20b157fd6..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/config/JdbcDynamicDataSourceProperties.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.pig4cloud.pigx.code.config; - -import lombok.AllArgsConstructor; -import lombok.Data; -import org.jasypt.encryption.StringEncryptor; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Component; - -@Data -@Component -@ConfigurationProperties("spring.datasource.dynamic") -public class JdbcDynamicDataSourceProperties { - private final StringEncryptor stringEncryptor; - private String username; - private String password; - private String url; - private String driverClassName; - private String sql; - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/config/JdbcDynamicDataSourceProvider.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/config/JdbcDynamicDataSourceProvider.java deleted file mode 100644 index 198a10ae9..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/config/JdbcDynamicDataSourceProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.pig4cloud.pigx.code.config; - -import com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider; -import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider; -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; -import lombok.AllArgsConstructor; -import org.jasypt.encryption.StringEncryptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; - -@Configuration -@AllArgsConstructor -public class JdbcDynamicDataSourceProvider { - private final StringEncryptor stringEncryptor; - private final JdbcDynamicDataSourceProperties properties; - - @Bean - public DynamicDataSourceProvider dynamicDataSourceProvider() { - return new AbstractJdbcDataSourceProvider(properties.getDriverClassName(), properties.getUrl(), properties.getUsername(), properties.getPassword()) { - @Override - protected Map executeStmt(Statement statement) throws SQLException { - Map map = new HashMap<>(); - ResultSet rs = statement.executeQuery(properties.getSql()); - while (rs.next()) { - String name = rs.getString("name"); - String username = rs.getString("username"); - String password = rs.getString("password"); - String url = rs.getString("url"); -// String driver = rs.getString("driver"); - DataSourceProperty property = new DataSourceProperty(); - property.setUsername(username); - property.setPassword(stringEncryptor.decrypt(password)); - property.setUrl(url); -// property.setDriverClassName(driver); - map.put(name, property); - } - return map; - } - }; - } -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GenDsConfController.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GenDsConfController.java deleted file mode 100644 index a43ad053c..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GenDsConfController.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.code.controller; - -import com.baomidou.dynamic.datasource.DynamicDataSourceCreator; -import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.pig4cloud.pigx.code.entity.GenDatasourceConf; -import com.pig4cloud.pigx.code.service.GenDatasourceConfService; -import com.pig4cloud.pigx.common.core.util.R; -import com.pig4cloud.pigx.common.log.annotation.SysLog; -import lombok.AllArgsConstructor; -import org.jasypt.encryption.StringEncryptor; -import org.springframework.web.bind.annotation.*; - -import javax.sql.DataSource; - - -/** - * 数据源管理 - * - * @author lengleng - * @date 2019-03-31 16:00:20 - */ -@RestController -@AllArgsConstructor -@RequestMapping("/dsconf") -public class GenDsConfController { - private final GenDatasourceConfService datasourceConfService; - private final StringEncryptor stringEncryptor; - private DataSource dataSource; - private DynamicDataSourceCreator dataSourceCreator; - - /** - * 分页查询 - * - * @param page 分页对象 - * @param datasourceConf 数据源表 - * @return - */ - @GetMapping("/page") - public R getSysDatasourceConfPage(Page page, GenDatasourceConf datasourceConf) { - return R.ok(datasourceConfService.page(page, Wrappers.query(datasourceConf))); - } - - /** - * 查询全部数据源 - * - * @return - */ - @GetMapping("/list") - public R list() { - return R.ok(datasourceConfService.list()); - } - - - /** - * 通过id查询数据源表 - * - * @param id id - * @return R - */ - @GetMapping("/{id}") - public R getById(@PathVariable("id") Integer id) { - return R.ok(datasourceConfService.getById(id)); - } - - /** - * 新增数据源表 - * - * @param datasourceConf 数据源表 - * @return R - */ - @SysLog("新增数据源表") - @PostMapping - public R save(@RequestBody GenDatasourceConf datasourceConf) { - DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; - DataSourceProperty dataSourceProperty = new DataSourceProperty(); - dataSourceProperty.setPollName(datasourceConf.getName()); - dataSourceProperty.setUrl(datasourceConf.getUrl()); - dataSourceProperty.setUsername(datasourceConf.getUsername()); - dataSourceProperty.setPassword(datasourceConf.getPassword()); - DataSource dataSource = dataSourceCreator.createDataSource(dataSourceProperty); - ds.addDataSource(dataSourceProperty.getPollName(), dataSource); - return R.ok(datasourceConfService.saveDsByEnc(datasourceConf)); - } - - /** - * 修改数据源表 - * - * @param sysDatasourceConf 数据源表 - * @return R - */ - @SysLog("修改数据源表") - @PutMapping - public R updateById(@RequestBody GenDatasourceConf sysDatasourceConf) { - DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; - //先移除 - ds.removeDataSource(datasourceConfService.getById(sysDatasourceConf.getId()).getName()); - //再添加 - DataSourceProperty dataSourceProperty = new DataSourceProperty(); - dataSourceProperty.setPollName(sysDatasourceConf.getName()); - dataSourceProperty.setUrl(sysDatasourceConf.getUrl()); - dataSourceProperty.setUsername(sysDatasourceConf.getUsername()); - dataSourceProperty.setPassword(sysDatasourceConf.getPassword()); - DataSource dataSource = dataSourceCreator.createDataSource(dataSourceProperty); - ds.addDataSource(dataSourceProperty.getPollName(), dataSource); - return R.ok(datasourceConfService.updateDsByEnc(sysDatasourceConf)); - } - - /** - * 通过id删除数据源表 - * - * @param id id - * @return R - */ - @SysLog("删除数据源表") - @DeleteMapping("/{id}") - public R removeById(@PathVariable Integer id) { - DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; - ds.removeDataSource(datasourceConfService.getById(id).getName()); - return R.ok(datasourceConfService.removeById(id)); - } - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GenFormConfController.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GenFormConfController.java deleted file mode 100644 index a2243bf2b..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GenFormConfController.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.code.controller; - -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.pig4cloud.pigx.code.entity.GenFormConf; -import com.pig4cloud.pigx.code.service.GenFormConfService; -import com.pig4cloud.pigx.common.core.util.R; -import com.pig4cloud.pigx.common.log.annotation.SysLog; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - - -/** - * 表单管理 - * - * @author lengleng - * @date 2019-08-12 15:55:35 - */ -@RestController -@AllArgsConstructor -@RequestMapping("/form") -@Api(value = "form", tags = "表单管理") -public class GenFormConfController { - private final GenFormConfService genRecordService; - - /** - * 分页查询 - * - * @param page 分页对象 - * @param formConf 生成记录 - * @return - */ - @ApiOperation(value = "分页查询", notes = "分页查询") - @GetMapping("/page") - public R getGenFormConfPage(Page page, GenFormConf formConf) { - return R.ok(genRecordService.page(page, Wrappers.query(formConf))); - } - - - /** - * 通过id查询生成记录 - * - * @param id id - * @return R - */ - @ApiOperation(value = "通过id查询", notes = "通过id查询") - @GetMapping("/{id}") - public R getById(@PathVariable("id") Integer id) { - return R.ok(genRecordService.getById(id)); - } - - /** - * 通过id查询生成记录 - * - * @param dsId 数据源ID - * @param tableName tableName - * @return R - */ - @ApiOperation(value = "通过tableName查询表单信息") - @GetMapping("/info") - public R form(Integer dsId, String tableName) { - return R.ok(genRecordService.getForm(dsId, tableName)); - } - - /** - * 新增生成记录 - * - * @param formConf 生成记录 - * @return R - */ - @ApiOperation(value = "新增生成记录", notes = "新增生成记录") - @SysLog("新增生成记录") - @PostMapping - @PreAuthorize("@pms.hasPermission('gen_form_add')") - public R save(@RequestBody GenFormConf formConf) { - return R.ok(genRecordService.save(formConf)); - } - - /** - * 修改生成记录 - * - * @param formConf 生成记录 - * @return R - */ - @ApiOperation(value = "修改生成记录", notes = "修改生成记录") - @SysLog("修改生成记录") - @PutMapping - @PreAuthorize("@pms.hasPermission('gen_form_edit')") - public R updateById(@RequestBody GenFormConf formConf) { - return R.ok(genRecordService.updateById(formConf)); - } - - /** - * 通过id删除生成记录 - * - * @param id id - * @return R - */ - @ApiOperation(value = "通过id删除生成记录", notes = "通过id删除生成记录") - @SysLog("通过id删除生成记录") - @DeleteMapping("/{id}") - @PreAuthorize("@pms.hasPermission('gen_form_del')") - public R removeById(@PathVariable Integer id) { - return R.ok(genRecordService.removeById(id)); - } - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GeneratorController.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GeneratorController.java deleted file mode 100644 index be97fa249..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/controller/GeneratorController.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.code.controller; - -import cn.hutool.core.io.IoUtil; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.pig4cloud.pigx.code.entity.GenConfig; -import com.pig4cloud.pigx.code.service.GeneratorService; -import com.pig4cloud.pigx.common.core.util.R; -import lombok.AllArgsConstructor; -import lombok.SneakyThrows; -import org.apache.commons.lang3.StringUtils; -import org.springframework.http.HttpHeaders; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * 代码生成器 - * - * @author lengleng - * @date 2018-07-30 - */ -@RestController -@AllArgsConstructor -@RequestMapping("/generator") -public class GeneratorController { - private final GeneratorService generatorService; - - /** - * 列表 - * - * @param tableName 参数集 - * @param id 数据源编号 - * @return 数据库表 - */ - @GetMapping("/page") - public R getPage(Page page, String tableName, String name, HttpServletRequest request) { - name = StringUtils.isEmpty(name) ? "master" : name; - request.getSession().setAttribute("dataSourceName", name); - return R.ok(generatorService.getPage(page, tableName)); - } - - /** - * 生成代码 - */ - @SneakyThrows - @PostMapping("/code") - public void generatorCode(@RequestBody GenConfig genConfig, HttpServletResponse response) { - byte[] data = generatorService.generatorCode(genConfig); - response.reset(); - response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=%s.zip", genConfig.getTableName())); - response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length)); - response.setContentType("application/octet-stream; charset=UTF-8"); - - IoUtil.write(response.getOutputStream(), Boolean.TRUE, data); - } -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/ColumnEntity.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/ColumnEntity.java deleted file mode 100644 index 92b0854a5..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/ColumnEntity.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.code.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; - /** - * 字段类型 - */ - private String columnType; - /** - * 是否可以为空 - */ - private Boolean nullable; - /** - * 是否隐藏 - */ - private Boolean hidden; -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenConfig.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenConfig.java deleted file mode 100644 index c23aa006c..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenConfig.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.code.entity; - -import lombok.Data; - -/** - * @author lengleng - * @date 2018/8/2 - * 生成配置 - */ -@Data -public class GenConfig { - /** - * 数据源ID - */ - private Integer id; - /** - * 包名 - */ - private String packageName; - /** - * 作者 - */ - private String author; - /** - * 模块名称 - */ - private String moduleName; - /** - * 表前缀 - */ - private String tablePrefix; - - /** - * 表名称 - */ - private String tableName; - - /** - * 表备注 - */ - private String comments; -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenDatasourceConf.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenDatasourceConf.java deleted file mode 100644 index d2965821f..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenDatasourceConf.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.code.entity; - -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableLogic; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.activerecord.Model; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.time.LocalDateTime; - -/** - * 数据源表 - * - * @author lengleng - * @date 2019-03-31 16:00:20 - */ -@Data -@TableName("gen_datasource_conf") -@EqualsAndHashCode(callSuper = true) -public class GenDatasourceConf extends Model { - private static final long serialVersionUID = 1L; - - /** - * 主键 - */ - @TableId - private Integer id; - /** - * 名称 - */ - private String name; - /** - * jdbcurl - */ - private String url; - /** - * 用户名 - */ - private String username; - /** - * 密码 - */ - private String password; - /** - * 创建时间 - */ - private LocalDateTime createDate; - /** - * 更新 - */ - private LocalDateTime updateDate; - /** - * 删除标记 - */ - @TableLogic - private String delFlag; - /** - * 租户ID - */ - private Integer tenantId; - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenFormConf.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenFormConf.java deleted file mode 100644 index 4c6ae7d56..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/GenFormConf.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.code.entity; - -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.activerecord.Model; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.time.LocalDateTime; - -/** - * 生成记录 - * - * @author lengleng - * @date 2019-08-12 15:55:35 - */ -@Data -@TableName("gen_form_conf") -@EqualsAndHashCode(callSuper = true) -@ApiModel(value = "生成记录") -public class GenFormConf extends Model { - private static final long serialVersionUID = 1L; - - /** - * ID - */ - @TableId - @ApiModelProperty(value = "ID") - private Integer id; - /** - * 表名称 - */ - @ApiModelProperty(value = "表名称") - private String tableName; - /** - * 表单信息 - */ - @ApiModelProperty(value = "表单信息") - private String formInfo; - /** - * 创建时间 - */ - @ApiModelProperty(value = "创建时间") - private LocalDateTime createTime; - /** - * 修改时间 - */ - @ApiModelProperty(value = "修改时间") - private LocalDateTime updateTime; - /** - * 删除标记 - */ - @ApiModelProperty(value = "删除标记") - private String delFlag; - /** - * 所属租户 - */ - @ApiModelProperty(value = "所属租户", hidden = true) - private Integer tenantId; -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/TableEntity.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/TableEntity.java deleted file mode 100644 index 4f0cf207c..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/entity/TableEntity.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.code.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-code/src/main/java/com/pig4cloud/pigx/code/mapper/GenDatasourceConfMapper.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GenDatasourceConfMapper.java deleted file mode 100644 index c761e1cbc..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GenDatasourceConfMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.code.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.pig4cloud.pigx.code.entity.GenDatasourceConf; - -/** - * 数据源表 - * - * @author lengleng - * @date 2019-03-31 16:00:20 - */ -public interface GenDatasourceConfMapper extends BaseMapper { - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GenFormConfMapper.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GenFormConfMapper.java deleted file mode 100644 index 145faf1a1..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GenFormConfMapper.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.code.mapper; - -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.pig4cloud.pigx.code.entity.GenFormConf; - -/** - * 生成记录 - * - * @author lengleng - * @date 2019-08-12 15:55:35 - */ -@DS("master") -public interface GenFormConfMapper extends BaseMapper { - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GeneratorMapper.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GeneratorMapper.java deleted file mode 100644 index 975b08d16..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/mapper/GeneratorMapper.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.code.mapper; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.ibatis.annotations.Param; - -import java.util.List; -import java.util.Map; - -/** - * 代码生成器 - * - * @author lengleng - * @date 2018-07-30 - */ -public interface GeneratorMapper { - - /** - * 分页查询表格 - * - * @param page - * @param tableName - * @return - */ - IPage>> queryList(Page page, @Param("tableName") String tableName); - - /** - * 查询表信息 - * - * @param tableName 表名称 - * @return - */ - Map queryTable(String tableName); - - /** - * 查询表列信息 - * - * @param tableName 表名称 - * @return - */ - List> queryColumns(String tableName); -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GenDatasourceConfService.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GenDatasourceConfService.java deleted file mode 100644 index c441b5cec..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GenDatasourceConfService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.code.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.pig4cloud.pigx.code.entity.GenDatasourceConf; - -/** - * 数据源表 - * - * @author lengleng - * @date 2019-03-31 16:00:20 - */ -public interface GenDatasourceConfService extends IService { - /** - * 保存数据源并且加密 - * - * @param genDatasourceConf - * @return - */ - Boolean saveDsByEnc(GenDatasourceConf genDatasourceConf); - - /** - * 更新数据源 - * - * @param genDatasourceConf - * @return - */ - Boolean updateDsByEnc(GenDatasourceConf genDatasourceConf); -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GenFormConfService.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GenFormConfService.java deleted file mode 100644 index c6468db33..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GenFormConfService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.code.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.pig4cloud.pigx.code.entity.GenFormConf; - -/** - * 表单管理 - * - * @author lengleng - * @date 2019-08-12 15:55:35 - */ -public interface GenFormConfService extends IService { - - /** - * 获取表单信息 - * - * @param dsId 数据源ID - * @param tableName 表名称 - * @return - */ - String getForm(Integer dsId, String tableName); - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GeneratorService.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GeneratorService.java deleted file mode 100644 index 5186eb6cc..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/GeneratorService.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.code.service; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.pig4cloud.pigx.code.entity.GenConfig; - -import java.util.List; -import java.util.Map; - -/** - * @author lengleng - * @date 2018/7/29 - */ -public interface GeneratorService { - /** - * 生成代码 - * - * @param tableNames 表名称 - * @return - */ - byte[] generatorCode(GenConfig tableNames); - - /** - * 分页查询表 - * - * @param page 分页信息 - * @param tableName 表名 - * @return - */ - IPage>> getPage(Page page, String tableName); -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GenDatasourceConfServiceImpl.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GenDatasourceConfServiceImpl.java deleted file mode 100644 index 49b6deea1..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GenDatasourceConfServiceImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.code.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.pig4cloud.pigx.code.entity.GenDatasourceConf; -import com.pig4cloud.pigx.code.mapper.GenDatasourceConfMapper; -import com.pig4cloud.pigx.code.service.GenDatasourceConfService; -import lombok.AllArgsConstructor; -import org.jasypt.encryption.StringEncryptor; -import org.springframework.stereotype.Service; - -/** - * 数据源表 - * - * @author lengleng - * @date 2019-03-31 16:00:20 - */ -@Service -@AllArgsConstructor -public class GenDatasourceConfServiceImpl extends ServiceImpl implements GenDatasourceConfService { - private final StringEncryptor stringEncryptor; - - /** - * 保存数据源并且加密 - * - * @param genDatasourceConf - * @return - */ - @Override - public Boolean saveDsByEnc(GenDatasourceConf genDatasourceConf) { - genDatasourceConf.setPassword(stringEncryptor.encrypt(genDatasourceConf.getPassword())); - this.baseMapper.insert(genDatasourceConf); - return true; -// return dynamicDataSourceConfig.reload(); - } - - /** - * 更新数据源 - * - * @param genDatasourceConf - * @return - */ - @Override - public Boolean updateDsByEnc(GenDatasourceConf genDatasourceConf) { - if (StrUtil.isNotBlank(genDatasourceConf.getPassword())) { - genDatasourceConf.setPassword(stringEncryptor.encrypt(genDatasourceConf.getPassword())); - } - this.baseMapper.updateById(genDatasourceConf); - return true; -// return dynamicDataSourceConfig.reload(); - } -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GenFormConfServiceImpl.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GenFormConfServiceImpl.java deleted file mode 100644 index 7c033efd3..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GenFormConfServiceImpl.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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.code.service.impl; - -import cn.hutool.core.util.CharsetUtil; -import cn.hutool.core.util.StrUtil; -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.pig4cloud.pigx.code.entity.ColumnEntity; -import com.pig4cloud.pigx.code.entity.GenFormConf; -import com.pig4cloud.pigx.code.mapper.GenFormConfMapper; -import com.pig4cloud.pigx.code.mapper.GeneratorMapper; -import com.pig4cloud.pigx.code.service.GenFormConfService; -import com.pig4cloud.pigx.code.util.GenUtils; -import lombok.AllArgsConstructor; -import lombok.SneakyThrows; -import org.apache.commons.lang.StringUtils; -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; -import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; -import org.springframework.stereotype.Service; - -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -/** - * 表单管理 - * - * @author lengleng - * @date 2019-08-12 15:55:35 - */ -@Service -@AllArgsConstructor -public class GenFormConfServiceImpl extends ServiceImpl implements GenFormConfService { - private final GeneratorMapper generatorMapper; - - /** - * 1. 根据数据源、表名称,查询已配置表单信息 - * 2. 不存在调用模板生成 - * - * @param dsId 数据源ID - * @param tableName 表名称 - * @return - */ - @DS("pigxx") - @Override - @SneakyThrows - public String getForm(Integer dsId, String tableName) { - GenFormConf form = getOne(Wrappers.lambdaQuery() - .eq(GenFormConf::getTableName, tableName) - .orderByDesc(GenFormConf::getCreateTime), false); - - if (form != null) { - return form.getFormInfo(); - } - -// DynamicDataSourceContextHolder.setDataSourceType(dsId); - List> columns = generatorMapper.queryColumns(tableName); - //设置velocity资源加载器 - Properties prop = new Properties(); - prop.put("file.resource.loader.class", ClasspathResourceLoader.class.getName()); - Velocity.init(prop); - Template template = Velocity.getTemplate("template/crud.js.vm", CharsetUtil.UTF_8); - VelocityContext context = new VelocityContext(); - - List columnList = new ArrayList<>(); - for (Map column : columns) { - ColumnEntity columnEntity = new ColumnEntity(); - columnEntity.setComments(column.get("columnComment")); - columnEntity.setLowerAttrName(StringUtils.uncapitalize(GenUtils.columnToJava(column.get("columnName")))); - columnList.add(columnEntity); - } - context.put("columns", columnList); - StringWriter writer = new StringWriter(); - template.merge(context, writer); - return StrUtil.trim(StrUtil.removePrefix(writer.toString(), GenUtils.CRUD_PREFIX)); - } - -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GeneratorServiceImpl.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GeneratorServiceImpl.java deleted file mode 100644 index 72e94731f..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/service/impl/GeneratorServiceImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.code.service.impl; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.util.StrUtil; -import com.baomidou.dynamic.datasource.annotation.DS; -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.code.entity.GenConfig; -import com.pig4cloud.pigx.code.entity.GenFormConf; -import com.pig4cloud.pigx.code.mapper.GenFormConfMapper; -import com.pig4cloud.pigx.code.mapper.GeneratorMapper; -import com.pig4cloud.pigx.code.service.GeneratorService; -import com.pig4cloud.pigx.code.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 lengleng - * @date 2018-07-30 - *

- * 代码生成器 - */ -@Service -@AllArgsConstructor -public class GeneratorServiceImpl implements GeneratorService { - private final GeneratorMapper generatorMapper; - private final GenFormConfMapper genFormConfMapper; - - /** - * 分页查询表 - * - * @param tableName 查询条件 - * @return - */ - @DS("#session.dataSourceName") - @Override - public IPage>> getPage(Page page, String tableName) { - return generatorMapper.queryList(page, tableName); - } - - /** - * 生成代码 - * - * @param genConfig 生成配置 - * @return - */ - @DS("#session.dataSourceName") - @Override - public byte[] generatorCode(GenConfig genConfig) { - //根据tableName 查询最新的表单配置 - List formConfList = genFormConfMapper.selectList(Wrappers.lambdaQuery() - .eq(GenFormConf::getTableName, genConfig.getTableName()) - .orderByDesc(GenFormConf::getCreateTime)); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ZipOutputStream zip = new ZipOutputStream(outputStream); - - String tableNames = genConfig.getTableName(); - for (String tableName : StrUtil.split(tableNames, StrUtil.DASHED)) { - //查询表信息 - Map table = queryTable(tableName); - //查询列信息 - List> columns = queryColumns(tableName); - //生成代码 - if (CollUtil.isNotEmpty(formConfList)) { - GenUtils.generatorCode(genConfig, table, columns, zip, formConfList.get(0)); - } else { - GenUtils.generatorCode(genConfig, table, columns, zip, null); - } - } - IoUtil.close(zip); - return outputStream.toByteArray(); - } - - private Map queryTable(String tableName) { - return generatorMapper.queryTable(tableName); - } - - private List> queryColumns(String tableName) { - return generatorMapper.queryColumns(tableName); - } -} diff --git a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/util/GenUtils.java b/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/util/GenUtils.java deleted file mode 100644 index 8907bdc96..000000000 --- a/pigx-visual/pigx-code/src/main/java/com/pig4cloud/pigx/code/util/GenUtils.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * 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.code.util; - -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.code.entity.ColumnEntity; -import com.pig4cloud.pigx.code.entity.GenConfig; -import com.pig4cloud.pigx.code.entity.GenFormConf; -import com.pig4cloud.pigx.code.entity.TableEntity; -import com.pig4cloud.pigx.common.core.constant.CommonConstants; -import com.pig4cloud.pigx.common.core.exception.CheckedException; -import lombok.SneakyThrows; -import lombok.experimental.UtilityClass; -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.StringWriter; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -/** - * 代码生成器 工具类 - * - * @author lengleng - * @date 2018-07-30 - */ -@Slf4j -@UtilityClass -public class GenUtils { - public final String CRUD_PREFIX = "export const tableOption ="; - private final String ENTITY_JAVA_VM = "Entity.java.vm"; - private final String MAPPER_JAVA_VM = "Mapper.java.vm"; - private final String SERVICE_JAVA_VM = "Service.java.vm"; - private final String SERVICE_IMPL_JAVA_VM = "ServiceImpl.java.vm"; - private final String CONTROLLER_JAVA_VM = "Controller.java.vm"; - private final String MAPPER_XML_VM = "Mapper.xml.vm"; - private final String MENU_SQL_VM = "menu.sql.vm"; - private final String INDEX_VUE_VM = "index.vue.vm"; - private final String API_JS_VM = "api.js.vm"; - private final String CRUD_JS_VM = "crud.js.vm"; - - private 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; - } - - /** - * 生成代码 - */ - @SneakyThrows - public void generatorCode(GenConfig genConfig, Map table, - List> columns, ZipOutputStream zip, GenFormConf formConf) { - //配置信息 - Configuration config = getConfig(); - boolean hasBigDecimal = false; - //表信息 - TableEntity tableEntity = new TableEntity(); - tableEntity.setTableName(table.get("tableName")); - - if (StrUtil.isNotBlank(genConfig.getComments())) { - tableEntity.setComments(genConfig.getComments()); - } else { - tableEntity.setComments(table.get("tableComment")); - } - - String tablePrefix; - if (StrUtil.isNotBlank(genConfig.getTablePrefix())) { - tablePrefix = genConfig.getTablePrefix(); - } else { - tablePrefix = config.getString("tablePrefix"); - } - - //表名转换成Java类名 - String className = tableToJava(tableEntity.getTableName(), tablePrefix); - tableEntity.setCaseClassName(className); - tableEntity.setLowerClassName(StringUtils.uncapitalize(className)); - //获取需要在swagger文档中隐藏的属性字段 - List hiddenColumns = config.getList("hiddenColumn"); - //列信息 - 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")); - columnEntity.setNullable("NO".equals(column.get("isNullable"))); - columnEntity.setColumnType(column.get("columnType")); - //隐藏不需要的在接口文档中展示的字段 - if (hiddenColumns.contains(column.get("columnName"))) { - columnEntity.setHidden(Boolean.TRUE); - } else { - columnEntity.setHidden(Boolean.FALSE); - } - //列名转换成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 && "BigDecimal".equals(attrType)) { - 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); - //封装模板数据 - Map map = new HashMap<>(16); - map.put("tableName", tableEntity.getTableName()); - 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("datetime", DateUtil.now()); - - if (StrUtil.isNotBlank(genConfig.getComments())) { - map.put("comments", genConfig.getComments()); - } else { - map.put("comments", tableEntity.getComments()); - } - - if (StrUtil.isNotBlank(genConfig.getAuthor())) { - map.put("author", genConfig.getAuthor()); - } else { - map.put("author", config.getString("author")); - } - - if (StrUtil.isNotBlank(genConfig.getModuleName())) { - map.put("moduleName", genConfig.getModuleName()); - } else { - map.put("moduleName", config.getString("moduleName")); - } - - if (StrUtil.isNotBlank(genConfig.getPackageName())) { - map.put("package", genConfig.getPackageName()); - map.put("mainPath", genConfig.getPackageName()); - } else { - map.put("package", config.getString("package")); - map.put("mainPath", config.getString("mainPath")); - } - VelocityContext context = new VelocityContext(map); - - //获取模板列表 - List templates = getTemplates(); - for (String template : templates) { - // 如果是crud - if (template.contains(CRUD_JS_VM) && formConf != null) { - zip.putNextEntry(new ZipEntry(Objects - .requireNonNull(getFileName(template, tableEntity.getCaseClassName() - , map.get("package").toString(), map.get("moduleName").toString())))); - IoUtil.write(zip, StandardCharsets.UTF_8, false, CRUD_PREFIX + formConf.getFormInfo()); - zip.closeEntry(); - continue; - } - - - //渲染模板 - StringWriter sw = new StringWriter(); - Template tpl = Velocity.getTemplate(template, CharsetUtil.UTF_8); - tpl.merge(context, sw); - - //添加到zip - zip.putNextEntry(new ZipEntry(Objects - .requireNonNull(getFileName(template, tableEntity.getCaseClassName() - , map.get("package").toString(), map.get("moduleName").toString())))); - IoUtil.write(zip, StandardCharsets.UTF_8, false, sw.toString()); - IoUtil.close(sw); - zip.closeEntry(); - } - } - - - /** - * 列名转换成Java属性名 - */ - public String columnToJava(String columnName) { - return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", ""); - } - - /** - * 表名转换成Java类名 - */ - private String tableToJava(String tableName, String tablePrefix) { - if (StringUtils.isNotBlank(tablePrefix)) { - tableName = tableName.replaceFirst(tablePrefix, ""); - } - return columnToJava(tableName); - } - - /** - * 获取配置信息 - */ - private Configuration getConfig() { - try { - return new PropertiesConfiguration("generator.properties"); - } catch (ConfigurationException e) { - throw new CheckedException("获取配置文件失败,", e); - } - } - - /** - * 获取文件名 - */ - private String getFileName(String template, String className, String packageName, String moduleName) { - String packagePath = CommonConstants.BACK_END_PROJECT + File.separator + "src" + 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(SERVICE_IMPL_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 CommonConstants.BACK_END_PROJECT + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "mapper" + File.separator + className + "Mapper.xml"; - } - - if (template.contains(MENU_SQL_VM)) { - return className.toLowerCase() + "_menu.sql"; - } - - if (template.contains(INDEX_VUE_VM)) { - return CommonConstants.FRONT_END_PROJECT + File.separator + "src" + File.separator + "views" + - File.separator + moduleName + File.separator + className.toLowerCase() + File.separator + "index.vue"; - } - - if (template.contains(API_JS_VM)) { - return CommonConstants.FRONT_END_PROJECT + File.separator + "src" + File.separator + "api" + File.separator + className.toLowerCase() + ".js"; - } - - if (template.contains(CRUD_JS_VM)) { - return CommonConstants.FRONT_END_PROJECT + File.separator + "src" + File.separator + "const" + - File.separator + "crud" + File.separator + className.toLowerCase() + ".js"; - } - - return null; - } -} diff --git a/pigx-visual/pigx-code/src/main/resources/bootstrap.yml b/pigx-visual/pigx-code/src/main/resources/bootstrap.yml deleted file mode 100644 index 370893775..000000000 --- a/pigx-visual/pigx-code/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,16 +0,0 @@ -server: - port: 5003 - -spring: - application: - name: @artifactId@ - cloud: - nacos: - discovery: - server-addr: ${NACOS-HOST:pigx-register}:${NACOS-PORT:8848} - config: - server-addr: ${spring.cloud.nacos.discovery.server-addr} - file-extension: yml - shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - profiles: - active: @profiles.active@ \ No newline at end of file diff --git a/pigx-visual/pigx-code/src/main/resources/generator.properties b/pigx-visual/pigx-code/src/main/resources/generator.properties deleted file mode 100644 index dfe6d305a..000000000 --- a/pigx-visual/pigx-code/src/main/resources/generator.properties +++ /dev/null @@ -1,37 +0,0 @@ -#\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 - -# hidden columns in Swagger Models -hiddenColumn=tenant_id diff --git a/pigx-visual/pigx-code/src/main/resources/mapper/GenFormConfMapper.xml b/pigx-visual/pigx-code/src/main/resources/mapper/GenFormConfMapper.xml deleted file mode 100644 index 22270ac54..000000000 --- a/pigx-visual/pigx-code/src/main/resources/mapper/GenFormConfMapper.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/pigx-visual/pigx-code/src/main/resources/mapper/GeneratorMapper.xml b/pigx-visual/pigx-code/src/main/resources/mapper/GeneratorMapper.xml deleted file mode 100644 index 7ef05fc4d..000000000 --- a/pigx-visual/pigx-code/src/main/resources/mapper/GeneratorMapper.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - diff --git a/pigx-visual/pigx-code/src/main/resources/template/Controller.java.vm b/pigx-visual/pigx-code/src/main/resources/template/Controller.java.vm deleted file mode 100644 index 9eb5102e8..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/Controller.java.vm +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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 ${package}.${moduleName}.controller; - -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.pig4cloud.pigx.common.core.util.R; -import com.pig4cloud.pigx.common.log.annotation.SysLog; -import ${package}.${moduleName}.entity.${className}; -import ${package}.${moduleName}.service.${className}Service; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.*; - - -/** - * ${comments} - * - * @author ${author} - * @date ${datetime} - */ -@RestController -@AllArgsConstructor -@RequestMapping("/${pathName}" ) -@Api(value = "${pathName}", tags = "${comments}管理") -public class ${className}Controller { - - private final ${className}Service ${classname}Service; - - /** - * 分页查询 - * @param page 分页对象 - * @param ${classname} ${comments} - * @return - */ - @ApiOperation(value = "分页查询", notes = "分页查询") - @GetMapping("/page" ) - public R get${className}Page(Page page, ${className} ${classname}) { - return R.ok(${classname}Service.page(page, Wrappers.query(${classname}))); - } - - - /** - * 通过id查询${comments} - * @param ${pk.lowerAttrName} id - * @return R - */ - @ApiOperation(value = "通过id查询", notes = "通过id查询") - @GetMapping("/{${pk.lowerAttrName}}" ) - public R getById(@PathVariable("${pk.lowerAttrName}" ) ${pk.attrType} ${pk.lowerAttrName}) { - return R.ok(${classname}Service.getById(${pk.lowerAttrName})); - } - - /** - * 新增${comments} - * @param ${classname} ${comments} - * @return R - */ - @ApiOperation(value = "新增${comments}", notes = "新增${comments}") - @SysLog("新增${comments}" ) - @PostMapping - @PreAuthorize("@pms.hasPermission('${moduleName}_${pathName}_add')" ) - public R save(@RequestBody ${className} ${classname}) { - return R.ok(${classname}Service.save(${classname})); - } - - /** - * 修改${comments} - * @param ${classname} ${comments} - * @return R - */ - @ApiOperation(value = "修改${comments}", notes = "修改${comments}") - @SysLog("修改${comments}" ) - @PutMapping - @PreAuthorize("@pms.hasPermission('${moduleName}_${pathName}_edit')" ) - public R updateById(@RequestBody ${className} ${classname}) { - return R.ok(${classname}Service.updateById(${classname})); - } - - /** - * 通过id删除${comments} - * @param ${pk.lowerAttrName} id - * @return R - */ - @ApiOperation(value = "通过id删除${comments}", notes = "通过id删除${comments}") - @SysLog("通过id删除${comments}" ) - @DeleteMapping("/{${pk.lowerAttrName}}" ) - @PreAuthorize("@pms.hasPermission('${moduleName}_${pathName}_del')" ) - public R removeById(@PathVariable ${pk.attrType} ${pk.lowerAttrName}) { - return R.ok(${classname}Service.removeById(${pk.lowerAttrName})); - } - -} diff --git a/pigx-visual/pigx-code/src/main/resources/template/Entity.java.vm b/pigx-visual/pigx-code/src/main/resources/template/Entity.java.vm deleted file mode 100644 index eb9a71379..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/Entity.java.vm +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 ${package}.${moduleName}.entity; - -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.activerecord.Model; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -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 -@TableName("${tableName}") -@EqualsAndHashCode(callSuper = true) -@ApiModel(value = "${comments}") -public class ${className} extends Model<${className}> { -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) - private $column.attrType $column.lowerAttrName; - #end -} diff --git a/pigx-visual/pigx-code/src/main/resources/template/Mapper.java.vm b/pigx-visual/pigx-code/src/main/resources/template/Mapper.java.vm deleted file mode 100644 index 867859b51..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/Mapper.java.vm +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 ${package}.${moduleName}.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import ${package}.${moduleName}.entity.${className}; - -/** - * ${comments} - * - * @author ${author} - * @date ${datetime} - */ -public interface ${className}Mapper extends BaseMapper<${className}> { - -} diff --git a/pigx-visual/pigx-code/src/main/resources/template/Mapper.xml.vm b/pigx-visual/pigx-code/src/main/resources/template/Mapper.xml.vm deleted file mode 100644 index 864e3d9ea..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/Mapper.xml.vm +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - #foreach($column in $columns) - #if($column.lowerAttrName==$pk.lowerAttrName) - - #else - - #end - #end - - diff --git a/pigx-visual/pigx-code/src/main/resources/template/Service.java.vm b/pigx-visual/pigx-code/src/main/resources/template/Service.java.vm deleted file mode 100644 index 5d808ef57..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/Service.java.vm +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 ${package}.${moduleName}.service; - -import com.baomidou.mybatisplus.extension.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-code/src/main/resources/template/ServiceImpl.java.vm b/pigx-visual/pigx-code/src/main/resources/template/ServiceImpl.java.vm deleted file mode 100644 index bce38eeea..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/ServiceImpl.java.vm +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 ${package}.${moduleName}.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import ${package}.${moduleName}.entity.${className}; -import ${package}.${moduleName}.mapper.${className}Mapper; -import ${package}.${moduleName}.service.${className}Service; -import org.springframework.stereotype.Service; - -/** - * ${comments} - * - * @author ${author} - * @date ${datetime} - */ -@Service -public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements ${className}Service { - -} diff --git a/pigx-visual/pigx-code/src/main/resources/template/api.js.vm b/pigx-visual/pigx-code/src/main/resources/template/api.js.vm deleted file mode 100644 index e257ce767..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/api.js.vm +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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-code/src/main/resources/template/crud.js.vm b/pigx-visual/pigx-code/src/main/resources/template/crud.js.vm deleted file mode 100644 index 0c9e51fa2..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/crud.js.vm +++ /dev/null @@ -1,17 +0,0 @@ -export const tableOption = { - "border": true, - "index": true, - "indexLabel": "序号", - "stripe": true, - "menuAlign": "center", - "align": "center", - "column": [ -#foreach ($column in $columns) - { - "type": "input", - "label": "$column.comments", - "prop": "$column.lowerAttrName" - }#if($foreach.hasNext),#end -#end - ] -} diff --git a/pigx-visual/pigx-code/src/main/resources/template/index.vue.vm b/pigx-visual/pigx-code/src/main/resources/template/index.vue.vm deleted file mode 100644 index 47fd26051..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/index.vue.vm +++ /dev/null @@ -1,121 +0,0 @@ - - - - \ No newline at end of file diff --git a/pigx-visual/pigx-code/src/main/resources/template/menu.sql.vm b/pigx-visual/pigx-code/src/main/resources/template/menu.sql.vm deleted file mode 100644 index c8a353d2a..000000000 --- a/pigx-visual/pigx-code/src/main/resources/template/menu.sql.vm +++ /dev/null @@ -1,16 +0,0 @@ --- 该脚本不要直接执行, 注意维护菜单的父节点ID 默认 父节点1000 - --- 菜单SQL -insert into `sys_menu` ( `parent_id`, `path`, `permission`, `type`, `icon`, `del_flag`, `create_time`, `sort`, `update_time`, `name`) - values ( '1000', '/${moduleName}/${pathName}/index', '', '0', 'icon-bangzhushouji', '0', '2018-01-20 13:17:19', '8', '2018-07-29 13:38:19', '${comments}管理'); - --- 按钮父菜单ID -set @parentId = @@identity; - --- 菜单对应按钮SQL -insert into `sys_menu` ( `parent_id`, `permission`, `type`, `path`, `icon`, `del_flag`, `create_time`, `sort`, `update_time`, `name`) - SELECT @parentId, '${moduleName}_${pathName}_add', '1', null, '1', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '${comments}新增'; -insert into `sys_menu` ( `parent_id`, `permission`, `type`, `path`, `icon`, `del_flag`, `create_time`, `sort`, `update_time`, `name`) - SELECT @parentId, '${moduleName}_${pathName}_edit', '1', null, '1', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '${comments}修改'; -insert into `sys_menu` ( `parent_id`, `permission`, `type`, `path`, `icon`, `del_flag`, `create_time`, `sort`, `update_time`, `name`) - SELECT @parentId, '${moduleName}_${pathName}_del', '1', null, '1', '0', '2018-05-15 21:35:18', '2', '2018-07-29 13:38:59', '${comments}删除'; diff --git a/pigx-visual/pigx-codegen/pom.xml b/pigx-visual/pigx-codegen/pom.xml index 559d0fce8..780b84407 100755 --- a/pigx-visual/pigx-codegen/pom.xml +++ b/pigx-visual/pigx-codegen/pom.xml @@ -25,6 +25,11 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config + + + com.pig4cloud + pigx-common-data + com.pig4cloud 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 index e500c0028..f37a655fc 100755 --- 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 @@ -36,6 +36,7 @@ import org.springframework.cloud.client.SpringCloudApplication; @EnablePigxResourceServer 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/controller/GenDsConfController.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenDsConfController.java index 8a76b1b80..9cc3e6f80 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenDsConfController.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenDsConfController.java @@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.*; public class GenDsConfController { private final GenDatasourceConfService datasourceConfService; + /** * 分页查询 * @@ -87,13 +88,13 @@ public class GenDsConfController { /** * 修改数据源表 * - * @param sysDatasourceConf 数据源表 + * @param conf 数据源表 * @return R */ @SysLog("修改数据源表") @PutMapping - public R updateById(@RequestBody GenDatasourceConf sysDatasourceConf) { - return R.ok(datasourceConfService.updateDsByEnc(sysDatasourceConf)); + public R updateById(@RequestBody GenDatasourceConf conf) { + return R.ok(datasourceConfService.updateDsByEnc(conf)); } /** @@ -105,7 +106,6 @@ public class GenDsConfController { @SysLog("删除数据源表") @DeleteMapping("/{id}") public R removeById(@PathVariable Integer id) { - return R.ok(datasourceConfService.removeById(id)); + return R.ok(datasourceConfService.removeByDsId(id)); } - } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenFormConfController.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenFormConfController.java index a06b04e4e..2ad1077d3 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenFormConfController.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenFormConfController.java @@ -72,14 +72,14 @@ public class GenFormConfController { /** * 通过id查询生成记录 * - * @param dsId 数据源ID + * @param dsName 数据源ID * @param tableName tableName * @return R */ @ApiOperation(value = "通过tableName查询表单信息") @GetMapping("/info") - public R form(Integer dsId, String tableName) { - return R.ok(genRecordService.getForm(dsId, tableName)); + public R form(String dsName, String tableName) { + return R.ok(genRecordService.getForm(dsName, tableName)); } /** diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GeneratorController.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GeneratorController.java index debc95f5c..8cddc4419 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GeneratorController.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GeneratorController.java @@ -45,12 +45,12 @@ public class GeneratorController { * 列表 * * @param tableName 参数集 - * @param id 数据源编号 + * @param dsName 数据源编号 * @return 数据库表 */ @GetMapping("/page") - public R getPage(Page page, String tableName, Integer id) { - return R.ok(generatorService.getPage(page, tableName, id)); + public R getPage(Page page, String tableName, String dsName) { + return R.ok(generatorService.getPage(page, tableName, dsName)); } /** diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenConfig.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenConfig.java index 579c45730..6fafa2f1c 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenConfig.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenConfig.java @@ -27,9 +27,9 @@ import lombok.Data; @Data public class GenConfig { /** - * 数据源ID + * 数据源name */ - private Integer id; + private 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 2476633de..d93819311 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 @@ -17,6 +17,7 @@ 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.Param; @@ -47,7 +48,8 @@ public interface GeneratorMapper { * @param tableName 表名称 * @return */ - Map queryTable(String tableName); + @DS("#last") + Map queryTable(@Param("tableName") String tableName, String dsName); /** * 查询表列信息 @@ -55,5 +57,6 @@ public interface GeneratorMapper { * @param tableName 表名称 * @return */ - List> queryColumns(String tableName); + @DS("#last") + List> queryColumns(@Param("tableName") String tableName, String dsName); } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenDatasourceConfService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenDatasourceConfService.java index c5e7e63a9..3b842f18f 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenDatasourceConfService.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenDatasourceConfService.java @@ -41,4 +41,29 @@ public interface GenDatasourceConfService extends IService { * @return */ Boolean updateDsByEnc(GenDatasourceConf genDatasourceConf); + + /** + * 更新动态数据的数据源列表 + * + * @param datasourceConf + * @return + */ + void addDynamicDataSource(GenDatasourceConf datasourceConf); + + + /** + * 校验数据源配置是否有效 + * + * @param datasourceConf 数据源信息 + * @return 有效/无效 + */ + Boolean checkDataSource(GenDatasourceConf datasourceConf); + + /** + * 通过数据源名称删除 + * + * @param dsId 数据源ID + * @return + */ + Boolean removeByDsId(Integer dsId); } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java index a26d1f951..695830b3d 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java @@ -31,10 +31,10 @@ public interface GenFormConfService extends IService { /** * 获取表单信息 * - * @param dsId 数据源ID + * @param dsName 数据源ID * @param tableName 表名称 * @return */ - String getForm(Integer dsId, String tableName); + String getForm(String dsName, String tableName); } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GeneratorService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GeneratorService.java index 9cc6df264..52c038cb1 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GeneratorService.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GeneratorService.java @@ -29,21 +29,21 @@ import java.util.Map; * @date 2018/7/29 */ public interface GeneratorService { - /** - * 生成代码 - * - * @param tableNames 表名称 - * @return - */ - byte[] generatorCode(GenConfig tableNames); + /** + * 生成代码 + * + * @param tableNames 表名称 + * @return + */ + byte[] generatorCode(GenConfig tableNames); - /** - * 分页查询表 - * - * @param page 分页信息 - * @param tableName 表名 - * @param id 数据源ID - * @return - */ - IPage>> getPage(Page page, String tableName, Integer id); + /** + * 分页查询表 + * + * @param page 分页信息 + * @param tableName 表名 + * @param name 数据源ID + * @return + */ + IPage>> getPage(Page page, String tableName, String name); } 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 1a5a2969d..3eae2701c 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 @@ -17,52 +17,129 @@ package com.pig4cloud.pigx.codegen.service.impl; import cn.hutool.core.util.StrUtil; +import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; +import com.baomidou.dynamic.datasource.creator.DataSourceCreator; +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.datasource.config.DynamicDataSourceConfig; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.jasypt.encryption.StringEncryptor; import org.springframework.stereotype.Service; +import javax.sql.DataSource; +import java.sql.DriverManager; +import java.sql.SQLException; + /** * 数据源表 * * @author lengleng * @date 2019-03-31 16:00:20 */ +@Slf4j @Service @AllArgsConstructor public class GenDatasourceConfServiceImpl extends ServiceImpl implements GenDatasourceConfService { - private final DynamicDataSourceConfig dynamicDataSourceConfig; + private DynamicRoutingDataSource dynamicRoutingDataSource; private final StringEncryptor stringEncryptor; + private DataSourceCreator dataSourceCreator; /** * 保存数据源并且加密 * - * @param genDatasourceConf + * @param conf * @return */ @Override - public Boolean saveDsByEnc(GenDatasourceConf genDatasourceConf) { - genDatasourceConf.setPassword(stringEncryptor.encrypt(genDatasourceConf.getPassword())); - this.baseMapper.insert(genDatasourceConf); - return dynamicDataSourceConfig.reload(); + public Boolean saveDsByEnc(GenDatasourceConf conf) { + // 校验配置合法性 + if (!checkDataSource(conf)) { + return Boolean.FALSE; + } + + //添加动态数据源 + addDynamicDataSource(conf); + + // 更新数据库配置 + conf.setPassword(stringEncryptor.encrypt(conf.getPassword())); + this.baseMapper.insert(conf); + return Boolean.TRUE; } /** * 更新数据源 * - * @param genDatasourceConf + * @param conf 数据源信息 * @return */ @Override - public Boolean updateDsByEnc(GenDatasourceConf genDatasourceConf) { - if (StrUtil.isNotBlank(genDatasourceConf.getPassword())) { - genDatasourceConf.setPassword(stringEncryptor.encrypt(genDatasourceConf.getPassword())); + public Boolean updateDsByEnc(GenDatasourceConf conf) { + if (!checkDataSource(conf)) { + return Boolean.FALSE; } - this.baseMapper.updateById(genDatasourceConf); - return dynamicDataSourceConfig.reload(); + //先移除 + dynamicRoutingDataSource.removeDataSource( + baseMapper.selectById(conf.getId()).getName()); + + //再添加 + addDynamicDataSource(conf); + + // 更新数据库配置 + if (StrUtil.isNotBlank(conf.getPassword())) { + conf.setPassword(stringEncryptor.encrypt(conf.getPassword())); + } + this.baseMapper.updateById(conf); + return Boolean.TRUE; + } + + + /** + * 通过数据源名称删除 + * + * @param dsId 数据源ID + * @return + */ + @Override + public Boolean removeByDsId(Integer dsId) { + dynamicRoutingDataSource.removeDataSource( + baseMapper.selectById(dsId).getName()); + this.baseMapper.deleteById(dsId); + return Boolean.TRUE; + } + + /** + * 添加动态数据源 + * + * @param conf 数据源信息 + */ + @Override + public void addDynamicDataSource(GenDatasourceConf conf) { + DataSourceProperty dataSourceProperty = new DataSourceProperty(); + dataSourceProperty.setPollName(conf.getName()); + dataSourceProperty.setUrl(conf.getUrl()); + dataSourceProperty.setUsername(conf.getUsername()); + dataSourceProperty.setPassword(conf.getPassword()); + DataSource dataSource = dataSourceCreator.createDataSource(dataSourceProperty); + dynamicRoutingDataSource.addDataSource(dataSourceProperty.getPollName(), dataSource); + } + + /** + * 校验数据源配置是否有效 + * + * @param conf 数据源信息 + * @return 有效/无效 + */ + @Override + public Boolean checkDataSource(GenDatasourceConf conf) { + try { + DriverManager.getConnection(conf.getUrl(),conf.getUsername(),conf.getPassword()); + } catch (SQLException e) { + log.error("数据源配置 {} , 获取链接失败", conf.getName(), e); + return Boolean.FALSE; + } + return Boolean.TRUE; } } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java index ef7df6c9a..29a5d7a10 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java @@ -26,7 +26,6 @@ import com.pig4cloud.pigx.codegen.mapper.GenFormConfMapper; import com.pig4cloud.pigx.codegen.mapper.GeneratorMapper; import com.pig4cloud.pigx.codegen.service.GenFormConfService; import com.pig4cloud.pigx.codegen.util.GenUtils; -import com.pig4cloud.pigx.common.datasource.support.DynamicDataSourceContextHolder; import lombok.AllArgsConstructor; import lombok.SneakyThrows; import org.apache.commons.lang.StringUtils; @@ -57,13 +56,13 @@ public class GenFormConfServiceImpl extends ServiceImpllambdaQuery() .eq(GenFormConf::getTableName, tableName) .orderByDesc(GenFormConf::getCreateTime), false); @@ -72,8 +71,7 @@ public class GenFormConfServiceImpl extends ServiceImpl> columns = generatorMapper.queryColumns(tableName); + List> columns = generatorMapper.queryColumns(tableName,dsName); //设置velocity资源加载器 Properties prop = new Properties(); prop.put("file.resource.loader.class", ClasspathResourceLoader.class.getName()); 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 581b1b10c..ed5e11d9c 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 @@ -20,6 +20,8 @@ package com.pig4cloud.pigx.codegen.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; 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; @@ -29,7 +31,6 @@ import com.pig4cloud.pigx.codegen.mapper.GenFormConfMapper; import com.pig4cloud.pigx.codegen.mapper.GeneratorMapper; import com.pig4cloud.pigx.codegen.service.GeneratorService; import com.pig4cloud.pigx.codegen.util.GenUtils; -import com.pig4cloud.pigx.common.datasource.support.DynamicDataSourceContextHolder; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; @@ -54,12 +55,12 @@ public class GeneratorServiceImpl implements GeneratorService { * 分页查询表 * * @param tableName 查询条件 - * @param id + * @param dsName * @return */ @Override - public IPage>> getPage(Page page, String tableName, Integer id) { - DynamicDataSourceContextHolder.setDataSourceType(id); + @DS("#last") + public IPage>> getPage(Page page, String tableName, String dsName) { return generatorMapper.queryList(page, tableName); } @@ -76,16 +77,16 @@ public class GeneratorServiceImpl implements GeneratorService { .eq(GenFormConf::getTableName, genConfig.getTableName()) .orderByDesc(GenFormConf::getCreateTime)); - DynamicDataSourceContextHolder.setDataSourceType(genConfig.getId()); + DynamicDataSourceContextHolder.push(genConfig.getDsName()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); String tableNames = genConfig.getTableName(); for (String tableName : StrUtil.split(tableNames, StrUtil.DASHED)) { //查询表信息 - Map table = queryTable(tableName); + Map table = generatorMapper.queryTable(tableName,genConfig.getDsName()); //查询列信息 - List> columns = queryColumns(tableName); + List> columns = generatorMapper.queryColumns(tableName, genConfig.getDsName()); //生成代码 if (CollUtil.isNotEmpty(formConfList)) { GenUtils.generatorCode(genConfig, table, columns, zip, formConfList.get(0)); @@ -96,12 +97,4 @@ public class GeneratorServiceImpl implements GeneratorService { IoUtil.close(zip); return outputStream.toByteArray(); } - - private Map queryTable(String tableName) { - return generatorMapper.queryTable(tableName); - } - - private List> queryColumns(String tableName) { - return generatorMapper.queryColumns(tableName); - } } diff --git a/pigx-visual/pigx-dynamic-datasource/README.md b/pigx-visual/pigx-dynamic-datasource/README.md deleted file mode 100644 index 4ac44ffb0..000000000 --- a/pigx-visual/pigx-dynamic-datasource/README.md +++ /dev/null @@ -1,94 +0,0 @@ -## 快速入门 -### 创建测试数据库 -``` -create database `test1` default character set utf8mb4 collate utf8mb4_general_ci; -create database `test2` default character set utf8mb4 collate utf8mb4_general_ci; -create database `test3` default character set utf8mb4 collate utf8mb4_general_ci; -``` -### 创建测试表 -``` - CREATE TABLE `user` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', - `username` varchar(255) DEFAULT NULL COMMENT '用户名', - `password` varchar(255) DEFAULT NULL COMMENT '密码', - PRIMARY KEY (`id`) USING BTREE - ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8mb4 COMMENT='用户测试表'; -``` -### 插入测试数据 -``` -use test1; -BEGIN; -INSERT INTO `user` VALUES (1, 'test1测试一', '123'); -INSERT INTO `user` VALUES (2, 'test1测试二', '123'); -INSERT INTO `user` VALUES (3, 'test1测试三', '123'); -COMMIT; -use test2; -BEGIN; -INSERT INTO `user` VALUES (1, 'test2测试一', '123'); -INSERT INTO `user` VALUES (2, 'test2测试二', '123'); -INSERT INTO `user` VALUES (3, 'test2测试三', '123'); -COMMIT; -use test3; -BEGIN; -INSERT INTO `user` VALUES (1, 'test3测试一', '123'); -INSERT INTO `user` VALUES (2, 'test3测试二', '123'); -INSERT INTO `user` VALUES (3, 'test3测试三', '123'); -COMMIT; -``` -### Nocas新增配置 -``` -## pigx-dynamic-datasource-biz.yml -## spring security 配置 -security: - oauth2: - client: - client-id: ENC(ltJPpR50wT0oIY9kfOe1Iw==) - client-secret: ENC(ltJPpR50wT0oIY9kfOe1Iw==) - scope: server - -# 数据源 -spring: - datasource: - dynamic: - primary: test1 #设置默认的数据源 - druid: - filters: stat - datasource: - test1: - username: ${MYSQL-USER:root} - password: ${MYSQL-USER:root} - url: jdbc:mysql://${MYSQL-HOST:pigx-mysql}:${MYSQL-PORT:3306}/test1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true - driver-class-name: com.mysql.cj.jdbc.Driver - test2: - username: ${MYSQL-USER:root} - password: ${MYSQL-USER:root} - url: jdbc:mysql://${MYSQL-HOST:pigx-mysql}:${MYSQL-PORT:3306}/test2?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true - driver-class-name: com.mysql.cj.jdbc.Driver - test3: - username: ${MYSQL-USER:root} - password: ${MYSQL-USER:root} - url: jdbc:mysql://${MYSQL-HOST:pigx-mysql}:${MYSQL-PORT:3306}/test3?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true - driver-class-name: com.mysql.cj.jdbc.Driver -``` -### 启动以下应用 -+ PigxNacosApplication -+ PigxSentinelApplication -+ PigxAuthApplication -+ PigxAdminApplication -+ PigxGatewayApplication -+ PigxDynamicDatasourceApplication -### Postman看效果 -``` -http://localhost:6060/test/getTest1 -http://localhost:6060/test/getTest2?current=1&size=5 -http://localhost:6060/test/getTest3?current=1&size=5 -``` -![test1数据库](http://i1.fuimg.com/704023/83e168e45242e135.png "test1数据库") -![test2数据库](http://i1.fuimg.com/704023/cf8c42fbc3512c32.png "test2数据库") -![test3数据库](http://i1.fuimg.com/704023/534483515e3f7cd0.png "test3数据库") -### 切换数据源 -``` -请参考:com/pig4cloud/pigx/dynamic/mapper/TestMapper.java -``` -### 联系我 -QQ:55215085 \ No newline at end of file diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-api/pom.xml b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-api/pom.xml deleted file mode 100644 index d44172a36..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-api/pom.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - 4.0.0 - - com.pig4cloud - pigx-dynamic-datasource - 3.5.0 - - - pigx-dynamic-datasource-api - - - - - com.pig4cloud - pigx-common-core - - - - com.baomidou - mybatis-plus-extension - - - \ No newline at end of file diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-api/src/main/java/com/pig4cloud/pigx/dynamic/feign/packge-info.java b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-api/src/main/java/com/pig4cloud/pigx/dynamic/feign/packge-info.java deleted file mode 100644 index b497b9232..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-api/src/main/java/com/pig4cloud/pigx/dynamic/feign/packge-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/* - @author pigx archetype - *

- * feign client 存放目录,注意 @EnablePigxFeignClients 的扫描范围 - */ -package com.pig4cloud.pigx.dynamic.feign; \ No newline at end of file diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/pom.xml b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/pom.xml deleted file mode 100644 index 481d203cd..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/pom.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - 4.0.0 - - com.pig4cloud - pigx-dynamic-datasource - 3.5.0 - - - pigx-dynamic-datasource-biz - - - - - org.springframework.boot - spring-boot-starter-undertow - - - - org.springframework.boot - spring-boot-starter-web - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - - com.pig4cloud - pigx-common-data - - - com.baomidou - mybatis-plus-boot-starter - - - druid-spring-boot-starter - com.alibaba - 1.1.20 - - - - com.baomidou - dynamic-datasource-spring-boot-starter - 2.5.6 - - - mysql - mysql-connector-java - - - com.pig4cloud - pigx-common-log - - - - com.pig4cloud - pigx-common-security - - - - com.pig4cloud - pigx-common-sentinel - - - - com.pig4cloud - pigx-dynamic-datasource-api - 3.5.0 - - - - com.pig4cloud - pigx-common-swagger - - - - org.springframework.boot - spring-boot-starter-test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/PigxDynamicDatasourceApplication.java b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/PigxDynamicDatasourceApplication.java deleted file mode 100644 index e572a2d4e..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/PigxDynamicDatasourceApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.pig4cloud.pigx.dynamic; - -import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; -import com.pig4cloud.pigx.common.security.annotation.EnablePigxFeignClients; -import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer; -import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.cloud.client.SpringCloudApplication; - -/** - * @author pigx archetype - *

- * 项目启动类 - */ -@EnablePigxSwagger2 -@SpringCloudApplication -@EnablePigxFeignClients -@EnablePigxResourceServer -@EnableAutoConfiguration(exclude={DruidDataSourceAutoConfigure.class}) -public class PigxDynamicDatasourceApplication { - public static void main(String[] args) { - SpringApplication.run(PigxDynamicDatasourceApplication.class, args); - } -} diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/controller/TestController.java b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/controller/TestController.java deleted file mode 100644 index 8f6208e7d..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/controller/TestController.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * - * 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.dynamic.controller; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.pig4cloud.pigx.common.core.util.R; -import com.pig4cloud.pigx.common.log.annotation.SysLog; -import com.pig4cloud.pigx.dynamic.mapper.TestMapper; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; -import java.util.Map; - -/** - * @author liuyes - * @date 2019/11/19 - */ -@RestController -@AllArgsConstructor -@RequestMapping("/test") -@Api(value = "test", tags = "动态多数据源示例模块") -public class TestController { - - private TestMapper testMapper; - - /** - * 获取test1数据库用户信息 - * - * @return 用户信息 - */ - @ApiOperation(value = "查询test1数据库用户信息", notes = "查询test1数据库用户信息") - @SysLog("查询test1数据库用户信息" ) - @PostMapping("/getTest1") - public R getTest1() { - List> list = testMapper.getTest1(); - if (list == null) { - return R.failed(null, "查询失败!"); - } - return R.ok(list,"操作成功!"); - } - - /** - * 获取test2数据库用户信息 - * - * @return 用户信息 - */ - @ApiOperation(value = "查询test2数据库用户信息", notes = "查询test2数据库用户信息") - @SysLog("查询test2数据库用户信息" ) - @PostMapping("/getTest2") - public R getTest2(Page page) { - IPage>> list = testMapper.getTest2(page); - if (list == null) { - return R.failed(null, "查询失败!"); - } - return R.ok(list,"操作成功!"); - } - /** - * 获取test3数据库用户信息 - * - * @return 用户信息 - */ - @ApiOperation(value = "查询test3数据库用户信息", notes = "查询test3数据库用户信息") - @SysLog("查询test3数据库用户信息" ) - @PostMapping("/getTest3") - public R getTest3(Page page) { - IPage>> list = testMapper.getTest3(page); - if (list == null) { - return R.failed(null, "查询失败!"); - } - return R.ok(list,"操作成功!"); - } - -} diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/mapper/TestMapper.java b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/mapper/TestMapper.java deleted file mode 100644 index 4a4bbfa3d..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/mapper/TestMapper.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * 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.dynamic.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.Select; - -import java.util.List; -import java.util.Map; - -/** - *

- * test Mapper 接口 - *

- * - * @author liuyes - * @date 2019/11/19 - */ -public interface TestMapper { - - @Select("SELECT * FROM user") - @DS("test1") - List> getTest1(); - - @DS("test2") - IPage>> getTest2(Page page); - - @DS("test3") - IPage>> getTest3(Page page); - -} diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/vo/UserVO.java b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/vo/UserVO.java deleted file mode 100644 index 0950a4b28..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/java/com/pig4cloud/pigx/dynamic/vo/UserVO.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.pig4cloud.pigx.dynamic.vo; - -import lombok.Data; - -@Data -public class UserVO { - private Integer id; - private String username; - private String password; -} diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/bootstrap.yml b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/bootstrap.yml deleted file mode 100644 index 05389d5f5..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,16 +0,0 @@ -server: - port: 6060 - -spring: - application: - name: @artifactId@ - cloud: - nacos: - discovery: - server-addr: ${NACOS-HOST:pigx-register}:${NACOS-PORT:8848} - config: - server-addr: ${spring.cloud.nacos.discovery.server-addr} - file-extension: yml - shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - profiles: - active: dev diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/logback-spring.xml b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/logback-spring.xml deleted file mode 100644 index 964ca8735..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - ${CONSOLE_LOG_PATTERN} - - - - - - ${log.path}/debug.log - - ${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz - 50MB - 30 - - - %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n - - - - - - ${log.path}/error.log - - ${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz - 50MB - 30 - - - %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n - - - ERROR - - - - - - - - - - - - - - - - - diff --git a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/mapper/TestMapper.xml b/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/mapper/TestMapper.xml deleted file mode 100644 index fcbe041f9..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pigx-dynamic-datasource-biz/src/main/resources/mapper/TestMapper.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/pigx-visual/pigx-dynamic-datasource/pom.xml b/pigx-visual/pigx-dynamic-datasource/pom.xml deleted file mode 100644 index bbb59f65c..000000000 --- a/pigx-visual/pigx-dynamic-datasource/pom.xml +++ /dev/null @@ -1,179 +0,0 @@ - - - - pigx-visual - com.pig4cloud - 3.5.0 - - - 4.0.0 - - pigx-dynamic-datasource - pom - pigx-dynamic-datasource - - - 2.1.10.RELEASE - Greenwich.SR3 - 2.1.0.RELEASE - Cairo-SR8 - UTF-8 - 1.8 - 1.8 - 5.0.5 - 3.5.0 - 0.0.9 - 2.1.1 - 2.10.2 - 2.1.6 - 2.3.6.RELEASE - - - - - pigx-dynamic-datasource-api - pigx-dynamic-datasource-biz - - - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - com.github.ulisesbocchio - jasypt-spring-boot-starter - ${jasypt.version} - - - - org.springframework.boot - spring-boot-starter-actuator - - - - de.codecentric - spring-boot-admin-starter-client - ${spring-boot-admin.version} - - - - org.projectlombok - lombok - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-dependencies - ${spring-boot.version} - pom - import - - - io.spring.platform - platform-bom - ${spring-platform.version} - pom - import - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - com.pig4cloud - pigx-common-bom - ${pigx.bom.version} - pom - import - - - - com.alibaba.cloud - spring-cloud-alibaba-dependencies - ${spring-cloud-alibaba.version} - pom - import - - - - org.springframework.security.oauth - spring-security-oauth2 - ${security.oauth.version} - - - - org.springframework.boot - spring-boot-starter-web - ${spring-boot.version} - - - - spring-boot-starter-tomcat - org.springframework.boot - - - - - - - - ${project.name} - - - src/main/resources - true - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot.version} - - - - repackage - - - - - - - - - maven-compiler-plugin - 3.8.0 - - ${maven.compiler.target} - ${maven.compiler.source} - UTF-8 - true - - - - pl.project13.maven - git-commit-id-plugin - 2.2.5 - - - - diff --git a/pigx-visual/pom.xml b/pigx-visual/pom.xml index 3d8ff74ad..f111e637c 100644 --- a/pigx-visual/pom.xml +++ b/pigx-visual/pom.xml @@ -42,7 +42,5 @@ pigx-sso-client-demo pigx-sentinel-dashboard pigx-tx-manager - pigx-dynamic-datasource - pigx-code