Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
ftp_pic
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李辅翼
ftp_pic
Commits
df86ecb6
Commit
df86ecb6
authored
5 years ago
by
李辅翼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v14
parent
fa4a2747
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
196 additions
and
17 deletions
+196
-17
pom.xml
+12
-1
src/main/java/com/hikcreate/FtpPicApplication.java
+4
-1
src/main/java/com/hikcreate/annotation/DBSource.java
+17
-0
src/main/java/com/hikcreate/aspect/DynamicDataSource.java
+24
-0
src/main/java/com/hikcreate/aspect/DynamicDataSourceAspect.java
+63
-0
src/main/java/com/hikcreate/conf/DataSourceConfig.java
+54
-0
src/main/java/com/hikcreate/dao/DriverPhotoMapper.java
+4
-2
src/main/java/com/hikcreate/drv_photo_pic/impl/DrvPhotoImpl.java
+0
-6
src/main/java/com/hikcreate/schedul/PicSchedule.java
+2
-2
src/main/resources/application.properties
+16
-5
No files found.
pom.xml
View file @
df86ecb6
...
...
@@ -55,12 +55,22 @@
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
com.oracle
</groupId>
<artifactId>
ojdbc6
</artifactId>
<version>
11.2.0.3
</version>
...
...
@@ -127,7 +137,7 @@
</plugin>
</plugins>
<!--
<plugins>
<!--
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
...
...
@@ -143,6 +153,7 @@
</configuration>
</plugin>
</plugins>-->
</build>
</project>
This diff is collapsed.
Click to expand it.
src/main/java/com/hikcreate/FtpPicApplication.java
View file @
df86ecb6
...
...
@@ -3,9 +3,12 @@ package com.hikcreate;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
@SpringBootApplication
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
@EnableScheduling
@MapperScan
(
"com.hikcreate.dao"
)
public
class
FtpPicApplication
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/hikcreate/annotation/DBSource.java
0 → 100644
View file @
df86ecb6
package
com
.
hikcreate
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* Created by lifuyi on 2018/10/24.
*/
@Target
({
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DBSource
{
String
name
();
}
This diff is collapsed.
Click to expand it.
src/main/java/com/hikcreate/aspect/DynamicDataSource.java
0 → 100644
View file @
df86ecb6
package
com
.
hikcreate
.
aspect
;
import
org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
;
/**
* Created by lifuyi on 2018/10/24.
*/
public
class
DynamicDataSource
extends
AbstractRoutingDataSource
{
//保存自己线程的本地变量
private
static
final
ThreadLocal
<
String
>
datasourceHolder
=
new
ThreadLocal
<>();
@Override
protected
Object
determineCurrentLookupKey
()
{
return
datasourceHolder
.
get
();
}
static
void
setDataSource
(
String
sourceName
)
{
datasourceHolder
.
set
(
sourceName
);
}
static
void
clearDataSource
()
{
datasourceHolder
.
remove
();
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/hikcreate/aspect/DynamicDataSourceAspect.java
0 → 100644
View file @
df86ecb6
package
com
.
hikcreate
.
aspect
;
import
com.hikcreate.annotation.DBSource
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.After
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
java.lang.reflect.Method
;
/**
* Created by lifuyi on 2018/10/24.
*/
@Aspect
@Order
(-
1
)
// 保证该AOP在@Transactional之前执行
@Component
public
class
DynamicDataSourceAspect
{
@Before
(
value
=
"execution(* com.hikcreate.dao..*.*(..))"
)
public
void
changeDataSource
(
JoinPoint
point
)
throws
Throwable
{
String
sourceName
=
null
;
//获得当前访问的class
Class
<?>
classes
=
point
.
getTarget
().
getClass
();
//获得访问的方法名称
String
methodName
=
point
.
getSignature
().
getName
();
//定义的接口方法
Method
abstractMethod
=
((
MethodSignature
)
point
.
getSignature
()).
getMethod
();
//是否含有注解DBSource
if
(
abstractMethod
.
isAnnotationPresent
(
DBSource
.
class
))
{
sourceName
=
abstractMethod
.
getAnnotation
(
DBSource
.
class
).
name
();
}
//接口方法参数类型
Class
<?>[]
parameterTypes
=
abstractMethod
.
getParameterTypes
();
try
{
//实现类中的该方法
Method
method
=
classes
.
getMethod
(
methodName
,
parameterTypes
);
if
(
method
.
isAnnotationPresent
(
DBSource
.
class
))
{
sourceName
=
method
.
getAnnotation
(
DBSource
.
class
).
name
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
sourceName
!=
null
)
{
DynamicDataSource
.
setDataSource
(
sourceName
);
}
}
@Pointcut
(
"execution(* com.hikcreate.dao..*.*(..))"
)
public
void
pointCut
()
{
}
@After
(
"pointCut()"
)
public
void
after
(
JoinPoint
point
)
{
DynamicDataSource
.
clearDataSource
();
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/hikcreate/conf/DataSourceConfig.java
0 → 100644
View file @
df86ecb6
package
com
.
hikcreate
.
conf
;
import
com.hikcreate.aspect.DynamicDataSource
;
import
org.springframework.beans.factory.annotation.Value
;
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
javax.sql.DataSource
;
import
java.util.HashMap
;
import
java.util.Map
;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
/**
* Created by lifuyi on 2018/10/24.
*/
@Configuration
public
class
DataSourceConfig
{
@Value
(
"${spring.datasource.type}"
)
private
Class
<?
extends
DataSource
>
dataSourceType
;
@Bean
(
name
=
"masterDataSource"
,
destroyMethod
=
"close"
,
initMethod
=
"init"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource.hik"
)
public
DataSource
masterDataSource
()
{
return
DataSourceBuilder
.
create
().
type
(
dataSourceType
).
build
();
}
@Bean
(
name
=
"slaveDataSource"
,
destroyMethod
=
"close"
,
initMethod
=
"init"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource.bokang"
)
public
DataSource
slaveDataSource
()
{
return
DataSourceBuilder
.
create
().
type
(
dataSourceType
).
build
();
}
@Bean
(
name
=
"dataSource"
)
public
DataSource
dataSource
()
{
DynamicDataSource
dynamicDataSource
=
new
DynamicDataSource
();
// 配置多数据源
Map
<
Object
,
Object
>
targetDataSources
=
new
HashMap
<>();
targetDataSources
.
put
(
"hik"
,
masterDataSource
());
targetDataSources
.
put
(
"bokang"
,
slaveDataSource
());
dynamicDataSource
.
setTargetDataSources
(
targetDataSources
);
dynamicDataSource
.
setDefaultTargetDataSource
(
slaveDataSource
());
return
dynamicDataSource
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/hikcreate/dao/DriverPhotoMapper.java
View file @
df86ecb6
package
com
.
hikcreate
.
dao
;
import
com.hikcreate.annotation.DBSource
;
import
com.hikcreate.entity.DriverPhoto
;
import
org.springframework.stereotype.Component
;
...
...
@@ -7,9 +8,10 @@ import java.util.List;
@Component
public
interface
DriverPhotoMapper
{
@DBSource
(
name
=
"bokang"
)
List
<
DriverPhoto
>
getIncrePhoto
();
@DBSource
(
name
=
"bokang"
)
List
<
DriverPhoto
>
getIncrePhotoBySfzmhm
(
String
sfzmhm
);
@DBSource
(
name
=
"bokang"
)
List
<
DriverPhoto
>
getIncrePhotoStage
(
String
start
,
String
end
);
}
This diff is collapsed.
Click to expand it.
src/main/java/com/hikcreate/drv_photo_pic/impl/DrvPhotoImpl.java
View file @
df86ecb6
...
...
@@ -36,12 +36,6 @@ public class DrvPhotoImpl implements DrvPhoto {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
DrvPhotoImpl
.
class
);
@Value
(
"${url}"
)
private
String
url
;
@Value
(
"${username}"
)
private
String
username
;
@Value
(
"${password}"
)
private
String
password
;
@Value
(
"${roundDay}"
)
private
int
roundDay
;
@Autowired
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/hikcreate/schedul/PicSchedule.java
View file @
df86ecb6
...
...
@@ -25,7 +25,7 @@ public class PicSchedule {
/**
* 每天早上10点同步驾驶人头像增量数据
*/
@Scheduled
(
cron
=
"0 0 10 * * *"
)
//
@Scheduled(cron = "0 0 10 * * *")
public
void
getIncrementDrvPhoto
(){
drvPhoto
.
getIncrementDrvPhoto
();
}
...
...
@@ -35,7 +35,7 @@ public class PicSchedule {
/**
* 每天早上9点同步机动车的增量数据
*/
@Scheduled
(
cron
=
"0 0 9 * * *"
)
//
@Scheduled(cron = "0 0 9 * * *")
public
void
getIncrementVehPic
(){
vehicle
.
getIncrementVehPic
();
}
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/application.properties
View file @
df86ecb6
spring.datasource.url
=
jdbc:oracle:thin:@172.16.17.82:1521:gyjg
spring.datasource.username
=
gyjg_zckj
spring.datasource.password
=
zckj2018
spring.datasource.driver-class-name
=
oracle.jdbc.driver.OracleDriver
#数据库驱动
spring.datasource.hik.driver-class-name
=
oracle.jdbc.driver.OracleDriver
#数据源地址
spring.datasource.hik.url
=
jdbc:oracle:thin:@172.16.25.02:1521:orcl
#用户名
spring.datasource.hik.username
=
zckj
#密码
spring.datasource.hik.password
=
ZCKJ2018
#博康oracle
spring.datasource.bokang.url
=
jdbc:oracle:thin:@172.16.17.82:1521:gyjg
spring.datasource.bokang.username
=
gyjg_zckj
spring.datasource.bokang.password
=
zckj2018
spring.datasource.bokang.driver-class-name
=
oracle.jdbc.driver.OracleDriver
spring.datasource.type
=
com.alibaba.druid.pool.DruidDataSource
mybatis.mapper-locations
=
classpath:mapper/*.xml
mybatis.type-aliases-package
=
com.hikcreate.entity
...
...
@@ -27,7 +38,7 @@ fdfs.tracker-list[1] = 172.16.25.26:22122
fdfs.pool.max-total
=
200
fdfs.pool.max-wait-millis
=
150
#端口
server.port
=
808
4
server.port
=
808
5
hbase.zookeeper.property.clientPort
=
2181
hbase.zookeeper.quorum
=
172.16.25.25,172.16.25.28,172.16.25.24,172.16.25.26,172.16.25.27
...
...
This diff is collapsed.
Click to expand it.
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