Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-tool
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tool
amos-tool
Commits
69c03080
Commit
69c03080
authored
Feb 28, 2024
by
2539630746
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
平台通用分类,配置多数据源后mybatis-plus未生成Mapper
parent
f7c8abac
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
266 additions
and
44 deletions
+266
-44
.gitignore
.gitignore
+0
-0
pom.xml
pom.xml
+10
-1
Application.java
src/main/java/com/yeejoin/amos/Application.java
+4
-2
DataSourceConfig.java
...va/com/yeejoin/amos/api/tool/config/DataSourceConfig.java
+0
-31
DatabaseContextHolder.java
...m/yeejoin/amos/api/tool/config/DatabaseContextHolder.java
+14
-0
DatabaseType.java
...n/java/com/yeejoin/amos/api/tool/config/DatabaseType.java
+23
-0
DynamicDataSource.java
...a/com/yeejoin/amos/api/tool/config/DynamicDataSource.java
+12
-0
MybatisConfig.java
.../java/com/yeejoin/amos/api/tool/config/MybatisConfig.java
+110
-0
AdapterCategoryController.java
...n/amos/api/tool/controller/AdapterCategoryController.java
+88
-0
AgencyManagementResource.java
...in/amos/api/tool/controller/AgencyManagementResource.java
+1
-1
DataApiResource.java
...com/yeejoin/amos/api/tool/controller/DataApiResource.java
+1
-1
ToolUtils.java
src/main/java/com/yeejoin/amos/api/tool/utils/ToolUtils.java
+0
-2
application-dev.properties
src/main/resources/application-dev.properties
+2
-6
StudioResourceMapper.xml
src/main/resources/mapper/StudioResourceMapper.xml
+1
-0
No files found.
.gitignore
View file @
69c03080
pom.xml
View file @
69c03080
...
@@ -183,13 +183,22 @@
...
@@ -183,13 +183,22 @@
<artifactId>
dynamic-datasource-spring-boot-starter
</artifactId>
<artifactId>
dynamic-datasource-spring-boot-starter
</artifactId>
<version>
3.3.1
</version>
<version>
3.3.1
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
1.2.6
</version>
<!-- 替换为最新版本 -->
</dependency>
<dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<artifactId>
gson
</artifactId>
<version>
2.8.9
</version>
<!-- 使用最新版本 -->
<version>
2.8.9
</version>
<!-- 使用最新版本 -->
</dependency>
</dependency>
<dependency>
<groupId>
com.yeejoin
</groupId>
<artifactId>
visual-component-api
</artifactId>
<version>
1.10.3
</version>
</dependency>
</dependencies>
</dependencies>
<dependencyManagement>
<dependencyManagement>
...
...
src/main/java/com/yeejoin/amos/Application.java
View file @
69c03080
...
@@ -5,6 +5,7 @@ import org.apache.logging.log4j.Logger;
...
@@ -5,6 +5,7 @@ import org.apache.logging.log4j.Logger;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
@@ -18,10 +19,11 @@ import java.net.InetAddress;
...
@@ -18,10 +19,11 @@ import java.net.InetAddress;
@EnableAsync
@EnableAsync
@EnableEurekaClient
@EnableEurekaClient
@MapperScan
(
value
=
{
"org.typroject.tyboot.*.*.face.orm.dao"
,
"com.yeejoin.amos.api.*.face.orm.dao"
})
@MapperScan
(
value
=
{
"org.typroject.tyboot.*.*.face.orm.dao"
,
"com.yeejoin.amos.api.*.face.orm.dao"
},
sqlSessionFactoryRef
=
"sessionFactory"
)
@ComponentScan
({
"org.typroject"
,
"com.yeejoin.amos"
})
@ComponentScan
({
"org.typroject"
,
"com.yeejoin.amos"
})
@EnableFeignClients
@EnableFeignClients
@SpringBootApplication
@SpringBootApplication
(
exclude
=
DataSourceAutoConfiguration
.
class
)
public
class
Application
{
public
class
Application
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
Application
.
class
);
private
static
final
Logger
log
=
LogManager
.
getLogger
(
Application
.
class
);
...
...
src/main/java/com/yeejoin/amos/api/tool/config/DataSourceConfig.java
deleted
100644 → 0
View file @
f7c8abac
package
com
.
yeejoin
.
amos
.
api
.
tool
.
config
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.jdbc.DataSourceBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
javax.sql.DataSource
;
/**
* 配置多个数据源
* @author Gary.Li
* @date 2023/12/14
*/
@Configuration
public
class
DataSourceConfig
{
@Primary
@Bean
(
name
=
"primaryDataSource"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource"
)
public
DataSource
primaryDataSource
()
{
return
DataSourceBuilder
.
create
().
build
();
}
@Bean
(
name
=
"dataSource-amos-studio"
)
@ConfigurationProperties
(
prefix
=
"spring.second-datasource"
)
public
DataSource
secondDataSource
()
{
return
DataSourceBuilder
.
create
().
build
();
}
}
\ No newline at end of file
src/main/java/com/yeejoin/amos/api/tool/config/DatabaseContextHolder.java
0 → 100644
View file @
69c03080
package
com
.
yeejoin
.
amos
.
api
.
tool
.
config
;
public
class
DatabaseContextHolder
{
private
static
final
ThreadLocal
<
DatabaseType
>
contextHolder
=
new
ThreadLocal
<>();
public
static
void
setDatabaseType
(
DatabaseType
type
){
contextHolder
.
set
(
type
);
}
public
static
DatabaseType
getDatabaseType
(){
return
contextHolder
.
get
();
}
}
src/main/java/com/yeejoin/amos/api/tool/config/DatabaseType.java
0 → 100644
View file @
69c03080
package
com
.
yeejoin
.
amos
.
api
.
tool
.
config
;
public
enum
DatabaseType
{
DATASOURCE_ATL
(
"ATL"
,
"1"
),
DATASOURCE_AS
(
"AS"
,
"2"
);
DatabaseType
(
String
name
,
String
value
)
{
this
.
name
=
name
;
this
.
value
=
value
;
}
private
String
name
;
private
String
value
;
public
String
getName
()
{
return
name
;
}
public
String
getValue
()
{
return
value
;
}
}
src/main/java/com/yeejoin/amos/api/tool/config/DynamicDataSource.java
0 → 100644
View file @
69c03080
package
com
.
yeejoin
.
amos
.
api
.
tool
.
config
;
import
org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
;
public
class
DynamicDataSource
extends
AbstractRoutingDataSource
{
@Override
protected
Object
determineCurrentLookupKey
()
{
return
DatabaseContextHolder
.
getDatabaseType
();
}
}
src/main/java/com/yeejoin/amos/api/tool/config/MybatisConfig.java
0 → 100644
View file @
69c03080
package
com
.
yeejoin
.
amos
.
api
.
tool
.
config
;
import
javax.sql.DataSource
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.mybatis.spring.SqlSessionFactoryBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
@Configuration
public
class
MybatisConfig
{
@Value
(
"${spring.datasource.driver-class-name}"
)
private
String
dbDriver
;
@Value
(
"${spring.datasource.jdbc-url}"
)
private
String
dbUrl
;
@Value
(
"${spring.datasource.username}"
)
private
String
dbUsername
;
@Value
(
"${spring.datasource.password}"
)
private
String
dbPassword
;
// MySQL
@Value
(
"${spring.second-datasource.driver-class-name}"
)
private
String
dbDriver_workplatform
;
@Value
(
"${spring.second-datasource.jdbc-url}"
)
private
String
dbUrl_workplatform
;
@Value
(
"${spring.second-datasource.username}"
)
private
String
dbUsername_workplatform
;
@Value
(
"${spring.second-datasource.password}"
)
private
String
dbPassword_workplatform
;
@Bean
(
name
=
"primaryDataSource"
)
public
DataSource
dataSourceSqlServer
()
throws
Exception
{
DruidDataSource
dataSource
=
new
DruidDataSource
();
dataSource
.
setDriverClassName
(
dbDriver
);
dataSource
.
setUrl
(
dbUrl
);
dataSource
.
setUsername
(
dbUsername
);
dataSource
.
setPassword
(
dbPassword
);
return
dataSource
;
}
@Bean
(
name
=
"dataSource-amos-studio"
)
public
DataSource
dataSourceMySQL
()
throws
Exception
{
DruidDataSource
dataSource
=
new
DruidDataSource
();
dataSource
.
setDriverClassName
(
dbDriver_workplatform
);
dataSource
.
setUrl
(
dbUrl_workplatform
);
dataSource
.
setUsername
(
dbUsername_workplatform
);
dataSource
.
setPassword
(
dbPassword_workplatform
);
return
dataSource
;
}
/**
* 1、创建动态数据源
* @throws Exception
* @Primary 该注解表示在同一个接口有多个类可以注入的时候,默认选择哪个,而不是让@Autowired报错
*/
@Bean
(
name
=
"dynamicDataSource"
)
@Primary
public
DynamicDataSource
DataSource
(
@Qualifier
(
"primaryDataSource"
)
DataSource
dataSourceATL
,
@Qualifier
(
"dataSource-amos-studio"
)
DataSource
dataSourceAS
){
//将已知的所有数据源信息放进 AbstractRoutingDataSource 类的 targetDataSource 属性中.
Map
<
Object
,
Object
>
targetDataSource
=
new
HashMap
<>();
targetDataSource
.
put
(
DatabaseType
.
DATASOURCE_AS
,
dataSourceAS
);
targetDataSource
.
put
(
DatabaseType
.
DATASOURCE_ATL
,
dataSourceATL
);
DynamicDataSource
dataSource
=
new
DynamicDataSource
();
dataSource
.
setTargetDataSources
(
targetDataSource
);
dataSource
.
setDefaultTargetDataSource
(
dataSourceAS
);
return
dataSource
;
}
/**
* 根据当前数据源创建SqlSessionFactory
* @throws Exception
*/
@Bean
(
name
=
"sessionFactory"
)
public
SqlSessionFactory
sessionFactory
(
@Qualifier
(
"dynamicDataSource"
)
DynamicDataSource
dataSource
)
throws
Exception
{
SqlSessionFactoryBean
sessionFactoryBean
=
new
SqlSessionFactoryBean
();
sessionFactoryBean
.
setDataSource
(
dataSource
);
PathMatchingResourcePatternResolver
resolver
=
new
PathMatchingResourcePatternResolver
();
sessionFactoryBean
.
setMapperLocations
(
resolver
.
getResources
(
"classpath:/mapper/*.xml"
));
return
sessionFactoryBean
.
getObject
();
}
/**
* 手动修改数据源
* @param environment
*/
public
static
void
setDataSourceByEnvironment
(
DatabaseType
environment
){
DatabaseContextHolder
.
setDatabaseType
(
environment
);
}
}
src/main/java/com/yeejoin/amos/api/tool/controller/AdapterCategoryController.java
0 → 100644
View file @
69c03080
package
com
.
yeejoin
.
amos
.
api
.
tool
.
controller
;
import
com.yeejoin.amos.api.component.face.model.AdapterCategoryModel
;
import
com.yeejoin.amos.api.component.face.service.AdapterCategoryService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.doc.TycloudResource
;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.util.List
;
@RestController
@Api
(
tags
=
"平台通用分类"
)
@RequestMapping
(
value
=
"/adapter"
)
@TycloudResource
(
module
=
"atl"
,
value
=
"adapter"
)
public
class
AdapterCategoryController
{
@Autowired
private
AdapterCategoryService
adapterCategoryService
;
/**
* 新增
* @param adapterCategoryModel AdapterCategory平台通用分类
* @return AdapterCategoryModel
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@PostMapping
(
value
=
"/save"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"新增"
,
notes
=
"新增"
)
public
ResponseModel
<
AdapterCategoryModel
>
save
(
@RequestBody
AdapterCategoryModel
adapterCategoryModel
)
throws
Exception
{
adapterCategoryModel
=
adapterCategoryService
.
createAdapterCategory
(
adapterCategoryModel
);
return
ResponseHelper
.
buildResponse
(
adapterCategoryModel
);
}
/**
* 根据sequenceNbr更新
* @param sequenceNbr 编码
* @return AdapterCategoryModel
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@PutMapping
(
value
=
"/{sequenceNbr}"
)
@ApiOperation
(
httpMethod
=
"PUT"
,
value
=
"根据sequenceNbr更新"
,
notes
=
"根据sequenceNbr更新"
)
public
ResponseModel
<
AdapterCategoryModel
>
update
(
@RequestBody
AdapterCategoryModel
adapterCategoryModel
,
@PathVariable
(
value
=
"sequenceNbr"
)
Long
sequenceNbr
)
throws
Exception
{
adapterCategoryModel
.
setSequenceNbr
(
sequenceNbr
);
return
ResponseHelper
.
buildResponse
(
adapterCategoryService
.
updateAdapterCategory
(
adapterCategoryModel
));
}
/**
* 根据sequenceNbr删除
* @param sequenceNbr 编码
* @return Boolean
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@DeleteMapping
(
value
=
"/{sequenceNbr}"
)
@ApiOperation
(
httpMethod
=
"DELETE"
,
value
=
"根据sequenceNbr删除"
,
notes
=
"根据sequenceNbr删除"
)
public
ResponseModel
<
Boolean
>
deleteBySequenceNbr
(
@PathVariable
(
value
=
"sequenceNbr"
)
Long
sequenceNbr
)
{
return
ResponseHelper
.
buildResponse
(
adapterCategoryService
.
deleteBySeq
(
sequenceNbr
));
}
/**
* 根据sequenceNbr查询
* @param sequenceNbr 物理主键
* @return ApiSourceDto
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@GetMapping
(
value
=
"/{sequenceNbr}"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"根据sequenceNbr查询单个"
,
notes
=
"根据sequenceNbr查询单个"
)
public
ResponseModel
<
AdapterCategoryModel
>
selectOne
(
@PathVariable
Long
sequenceNbr
){
return
ResponseHelper
.
buildResponse
(
adapterCategoryService
.
queryBySeq
(
sequenceNbr
));
}
/**
* 列表树形结构查询
* @return List<AdapterCategoryModel>
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"列表树形结构查询"
,
notes
=
"列表树形结构查询"
)
@GetMapping
(
value
=
"/tree"
)
public
ResponseModel
<
List
<
AdapterCategoryModel
>>
selectForTree
(
@RequestParam
(
"categoryType"
)
String
categoryType
)
throws
Exception
{
return
ResponseHelper
.
buildResponse
(
adapterCategoryService
.
queryAdapterCategoryForTree
(
false
,
categoryType
,
""
));
}
}
src/main/java/com/yeejoin/amos/api/tool/controller/AgencyManagementResource.java
View file @
69c03080
...
@@ -55,7 +55,7 @@ public class AgencyManagementResource {
...
@@ -55,7 +55,7 @@ public class AgencyManagementResource {
*
*
* @return String
* @return String
*/
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@GetMapping
(
value
=
"/export/{agencyCode}/{ipSeq}/{dbSeqs}"
)
@GetMapping
(
value
=
"/export/{agencyCode}/{ipSeq}/{dbSeqs}"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"导出"
,
notes
=
"导出"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"导出"
,
notes
=
"导出"
)
public
void
generateSQL
(
public
void
generateSQL
(
...
...
src/main/java/com/yeejoin/amos/api/tool/controller/DataApiResource.java
View file @
69c03080
...
@@ -46,7 +46,7 @@ public class DataApiResource {
...
@@ -46,7 +46,7 @@ public class DataApiResource {
*
*
* @throws SQLException
* @throws SQLException
*/
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@ApiOperation
(
value
=
"导出应用快搭增量脚本"
)
@ApiOperation
(
value
=
"导出应用快搭增量脚本"
)
@RequestMapping
(
value
=
"/generateSQL"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/generateSQL"
,
method
=
RequestMethod
.
GET
)
public
void
generateSQL
(
public
void
generateSQL
(
...
...
src/main/java/com/yeejoin/amos/api/tool/utils/ToolUtils.java
View file @
69c03080
...
@@ -11,8 +11,6 @@ public class ToolUtils {
...
@@ -11,8 +11,6 @@ public class ToolUtils {
public
static
final
Boolean
IS_DELETE
=
true
;
public
static
final
Boolean
IS_DELETE
=
true
;
public
static
final
Boolean
IS_NOT_DELETE
=
false
;
private
static
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
();
private
static
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
();
@Autowired
@Autowired
...
...
src/main/resources/application-dev.properties
View file @
69c03080
...
@@ -12,7 +12,7 @@ spring.datasource.hikari.max-lifetime=1800000
...
@@ -12,7 +12,7 @@ spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout
=
30000
spring.datasource.hikari.connection-timeout
=
30000
spring.datasource.hikari.connection-test-query
=
SELECT 1
spring.datasource.hikari.connection-test-query
=
SELECT 1
spring.second-datasource.jdbc-url
=
jdbc:mysql://172.16.3.18:3306/amos_studio?allowMultiQueries=true
spring.second-datasource.jdbc-url
=
jdbc:mysql://172.16.3.18:3306/amos_studio
_delete
?allowMultiQueries=true
spring.second-datasource.username
=
root
spring.second-datasource.username
=
root
spring.second-datasource.password
=
Yeejoin@2020
spring.second-datasource.password
=
Yeejoin@2020
spring.second-datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.second-datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
...
@@ -26,6 +26,7 @@ spring.second-datasource.hikari.max-lifetime=1800000
...
@@ -26,6 +26,7 @@ spring.second-datasource.hikari.max-lifetime=1800000
spring.second-datasource.hikari.connection-timeout
=
30000
spring.second-datasource.hikari.connection-timeout
=
30000
spring.second-datasource.hikari.connection-test-query
=
SELECT 1
spring.second-datasource.hikari.connection-test-query
=
SELECT 1
mybatis-plus.configuration.map-underscore-to-camel-case
=
true
#eureka
#eureka
eureka.instance.hostname
=
172.16.3.18
eureka.instance.hostname
=
172.16.3.18
...
@@ -81,10 +82,5 @@ datasource.username=root
...
@@ -81,10 +82,5 @@ datasource.username=root
datasource.password
=
Yeejoin@2020
datasource.password
=
Yeejoin@2020
datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
#studio_visual_designer 都有
#studio_template_category 只有amos_tool_library有
#studio_template 都有
#studio_data_api_category 只有amos_tool_library有
src/main/resources/mapper/StudioResourceMapper.xml
View file @
69c03080
...
@@ -19,3 +19,4 @@
...
@@ -19,3 +19,4 @@
ordinal_position
ordinal_position
</select>
</select>
</mapper>
</mapper>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment