Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jobs
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
曲欣亮
jobs
Commits
d17d6fe2
Commit
d17d6fe2
authored
Oct 31, 2018
by
zhangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
2ce1c995
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
172 additions
and
60 deletions
+172
-60
pom.xml
pom.xml
+4
-0
DataSourceConfig.java
...va/com/egolm/jobs/config/datasource/DataSourceConfig.java
+6
-6
ScheduleDataSourceConfig.java
...golm/jobs/config/datasource/ScheduleDataSourceConfig.java
+0
-43
ScheduleJob.java
...main/java/com/egolm/jobs/config/schedule/ScheduleJob.java
+7
-0
JobController.java
src/main/java/com/egolm/jobs/controller/JobController.java
+65
-0
JobService.java
src/main/java/com/egolm/jobs/service/JobService.java
+16
-0
JobServiceImpl.java
...main/java/com/egolm/jobs/service/impl/JobServiceImpl.java
+72
-0
application-dev.properties
src/main/resources/application-dev.properties
+2
-11
No files found.
pom.xml
View file @
d17d6fe2
...
@@ -26,6 +26,10 @@
...
@@ -26,6 +26,10 @@
<artifactId>
spring-boot-devtools
</artifactId>
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
mysql
</groupId>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
...
...
src/main/java/com/egolm/jobs/config/datasource/
Shop
DataSourceConfig.java
→
src/main/java/com/egolm/jobs/config/datasource/DataSourceConfig.java
View file @
d17d6fe2
...
@@ -16,11 +16,11 @@ import com.egolm.common.jdbc.JdbcTemplate;
...
@@ -16,11 +16,11 @@ import com.egolm.common.jdbc.JdbcTemplate;
import
com.egolm.common.jdbc.dialect.MySqlDialect
;
import
com.egolm.common.jdbc.dialect.MySqlDialect
;
@Configuration
@Configuration
public
class
Shop
DataSourceConfig
{
public
class
DataSourceConfig
{
@Bean
@Bean
@Primary
@Primary
@Qualifier
(
"
shopD
ataSource"
)
@Qualifier
(
"
d
ataSource"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource.shop"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource.shop"
)
public
DataSource
getDataSource
()
{
public
DataSource
getDataSource
()
{
return
DataSourceBuilder
.
create
().
type
(
DruidDataSource
.
class
).
build
();
return
DataSourceBuilder
.
create
().
type
(
DruidDataSource
.
class
).
build
();
...
@@ -28,15 +28,15 @@ public class ShopDataSourceConfig {
...
@@ -28,15 +28,15 @@ public class ShopDataSourceConfig {
@Bean
@Bean
@Primary
@Primary
@Qualifier
(
"
shopT
xManager"
)
@Qualifier
(
"
t
xManager"
)
public
PlatformTransactionManager
getTransactionManager
(
@Qualifier
(
"
shopD
ataSource"
)
DataSource
dataSource
)
{
public
PlatformTransactionManager
getTransactionManager
(
@Qualifier
(
"
d
ataSource"
)
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
return
new
DataSourceTransactionManager
(
dataSource
);
}
}
@Bean
@Bean
@Primary
@Primary
@Qualifier
(
"
shopJ
dbcTemplate"
)
@Qualifier
(
"
j
dbcTemplate"
)
public
JdbcTemplate
getJdbcTemplate
(
@Qualifier
(
"
shopD
ataSource"
)
DataSource
dataSource
)
{
public
JdbcTemplate
getJdbcTemplate
(
@Qualifier
(
"
d
ataSource"
)
DataSource
dataSource
)
{
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
();
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
();
jdbcTemplate
.
setDataSource
(
dataSource
);
jdbcTemplate
.
setDataSource
(
dataSource
);
jdbcTemplate
.
setDialect
(
new
MySqlDialect
());
jdbcTemplate
.
setDialect
(
new
MySqlDialect
());
...
...
src/main/java/com/egolm/jobs/config/datasource/ScheduleDataSourceConfig.java
deleted
100644 → 0
View file @
2ce1c995
package
com
.
egolm
.
jobs
.
config
.
datasource
;
import
javax.sql.DataSource
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.jdbc.dialect.MySqlDialect
;
@Configuration
public
class
ScheduleDataSourceConfig
{
@Bean
@Qualifier
(
"shopDataSource"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource.schedule"
)
public
DataSource
getDataSource
()
{
return
DataSourceBuilder
.
create
().
type
(
DruidDataSource
.
class
).
build
();
}
@Bean
@Qualifier
(
"shopTxManager"
)
public
PlatformTransactionManager
getTransactionManager
(
@Qualifier
(
"shopDataSource"
)
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
@Bean
@Qualifier
(
"shopJdbcTemplate"
)
public
JdbcTemplate
getJdbcTemplate
(
@Qualifier
(
"shopDataSource"
)
DataSource
dataSource
)
{
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
();
jdbcTemplate
.
setDataSource
(
dataSource
);
jdbcTemplate
.
setDialect
(
new
MySqlDialect
());
jdbcTemplate
.
setSql_level
(
3
);
return
jdbcTemplate
;
}
}
\ No newline at end of file
src/main/java/com/egolm/jobs/config/schedule/ScheduleJob.java
View file @
d17d6fe2
...
@@ -4,14 +4,18 @@ import org.quartz.JobExecutionContext;
...
@@ -4,14 +4,18 @@ import org.quartz.JobExecutionContext;
import
org.quartz.JobExecutionException
;
import
org.quartz.JobExecutionException
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
com.egolm.common.StringUtil
;
import
com.egolm.common.StringUtil
;
import
com.egolm.jobs.service.JobService
;
public
class
ScheduleJob
extends
QuartzJobBean
{
public
class
ScheduleJob
extends
QuartzJobBean
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ScheduleJob
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ScheduleJob
.
class
);
@Autowired
private
JobService
jobService
;
/**
/**
* 计划任务执行入口
* 计划任务执行入口
*/
*/
...
@@ -24,6 +28,9 @@ public class ScheduleJob extends QuartzJobBean {
...
@@ -24,6 +28,9 @@ public class ScheduleJob extends QuartzJobBean {
if
(
data
==
null
)
{
if
(
data
==
null
)
{
throw
new
XScheduleException
(
"任务定义实体[data]不能为空"
);
throw
new
XScheduleException
(
"任务定义实体[data]不能为空"
);
}
}
//调用业务逻辑
jobService
.
executeJob
(
jobCommon
);
}
}
}
}
src/main/java/com/egolm/jobs/controller/JobController.java
0 → 100644
View file @
d17d6fe2
package
com
.
egolm
.
jobs
.
controller
;
import
java.util.Date
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
org.quartz.Scheduler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.jobs.config.schedule.JobCommon
;
import
com.egolm.jobs.config.schedule.ScheduleUtils
;
import
com.egolm.jobs.service.JobService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
@Api
(
tags
={
"定时任务相关接口"
})
@RestController
@RequestMapping
(
"job"
)
public
class
JobController
{
@Autowired
private
JobService
jobService
;
@Autowired
private
Scheduler
scheduler
;
@ApiOperation
(
"启动/停止"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"id"
,
dataType
=
"String"
,
required
=
true
,
value
=
"任务ID"
,
defaultValue
=
""
)
,
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"type"
,
dataType
=
"String"
,
required
=
true
,
value
=
"操作"
,
defaultValue
=
"start/stop"
)
,
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"userNO"
,
dataType
=
"String"
,
required
=
true
,
value
=
"用户"
,
defaultValue
=
""
)
})
@RequestMapping
(
value
=
"/execute"
,
method
=
RequestMethod
.
GET
)
public
String
execute
(
HttpServletRequest
request
)
{
String
id
=
request
.
getParameter
(
"id"
);
String
type
=
request
.
getParameter
(
"type"
);
Map
<
String
,
Object
>
params
=
jobService
.
queryById
(
id
);
if
(
params
!=
null
)
{
if
(
type
.
equals
(
"start"
))
{
JobCommon
jobCommon
=
new
JobCommon
();
jobCommon
.
setsJobID
(
id
);
jobCommon
.
setnRunFlg
(
0
);
jobCommon
.
setsCronExpression
(
params
.
get
(
"sCron"
)+
""
);
jobCommon
.
setData
(
params
.
get
(
"sClass"
));
ScheduleUtils
.
createScheduleJob
(
scheduler
,
jobCommon
);
ScheduleUtils
.
resumeJob
(
scheduler
,
id
);
}
else
if
(
type
.
equals
(
"stop"
))
{
ScheduleUtils
.
deleteScheduleJob
(
scheduler
,
id
);
}
else
{
return
Rjx
.
jsonErr
().
setMessage
(
"操作类型错误"
).
toJson
();
}
}
else
{
return
Rjx
.
jsonErr
().
setMessage
(
"任务不存在"
).
toJson
();
}
return
Rjx
.
jsonOk
().
toString
();
}
}
src/main/java/com/egolm/jobs/service/JobService.java
0 → 100644
View file @
d17d6fe2
package
com
.
egolm
.
jobs
.
service
;
import
java.util.List
;
import
java.util.Map
;
import
com.egolm.jobs.config.schedule.JobCommon
;
public
interface
JobService
{
public
Map
<
String
,
Object
>
queryById
(
String
id
);
public
List
<
Map
<
String
,
Object
>>
queryAll
();
public
void
modify
(
Map
<
String
,
Object
>
params
);
public
void
executeJob
(
JobCommon
jobCommon
)
;
}
src/main/java/com/egolm/jobs/service/impl/JobServiceImpl.java
0 → 100644
View file @
d17d6fe2
package
com
.
egolm
.
jobs
.
service
.
impl
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.jobs.config.schedule.JobCommon
;
import
com.egolm.jobs.service.JobService
;
@Service
public
class
JobServiceImpl
implements
JobService
{
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
RedisTemplate
redisTemplate
;
public
Map
<
String
,
Object
>
queryById
(
String
id
){
try
{
String
sql
=
"SELECT * FROM tQuartz WHERE nID = ? AND nTag&1=0"
;
return
jdbcTemplate
.
queryForMap
(
sql
,
id
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
List
<
Map
<
String
,
Object
>>
queryAll
(){
try
{
String
sql
=
"SELECT * FROM tQuartz WHERE nTag&1=0"
;
return
jdbcTemplate
.
queryForList
(
sql
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
@Override
public
void
modify
(
Map
<
String
,
Object
>
params
)
{
String
id
=
params
.
get
(
"id"
)+
""
;
String
status
=
params
.
get
(
"status"
)+
""
;
String
userNO
=
params
.
get
(
"userNO"
)+
""
;
String
sql
=
"UPDATE tQuartz SET nStatus = ? ,sChangeUser = ? ,dChangeDate = getdate() ,dLastUpdateTime = getdate() WHERE nID = ?"
;
jdbcTemplate
.
update
(
sql
,
status
,
userNO
,
id
);
}
public
void
executeJob
(
JobCommon
jobCommon
)
{
String
data
=
jobCommon
.
getData
()+
""
;
if
(
data
.
equals
(
"redisInit"
))
{
String
sql
=
"SELECT * FROM tSystemCtrl WHERE sCode IN ('Client_Md5Key') AND nTag&1=0 "
;
List
<
Map
<
String
,
Object
>>
list
=
jdbcTemplate
.
queryForList
(
sql
);
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
Map
<
String
,
Object
>
map:
list
)
{
if
(
map
.
get
(
"sCode"
).
equals
(
"Client_Md5Key"
))
{
redisTemplate
.
opsForValue
().
set
(
"Client_Md5Key"
,
map
.
get
(
"sValue1"
));
}
}
}
}
}
}
src/main/resources/application-dev.properties
View file @
d17d6fe2
...
@@ -11,19 +11,10 @@ spring.http.encoding.force=true
...
@@ -11,19 +11,10 @@ spring.http.encoding.force=true
spring.http.encoding.enabled
=
true
spring.http.encoding.enabled
=
true
spring.http.encoding.charset
=
utf-8
spring.http.encoding.charset
=
utf-8
spring.datasource.schedule.url
=
jdbc:mysql://10.10.0.20:3306/msgcenter?useSSL=false
spring.datasource.schedule.username
=
root
spring.datasource.schedule.password
=
egolm2018
spring.datasource.schedule.driver-class-name
=
com.mysql.jdbc.Driver
spring.datasource.schedule.testWhileIdle
=
true
spring.datasource.schedule.validationQuery
=
SELECT 1
spring.datasource.schedule.timeBetweenEvictionRunsMillis
=
3600000
spring.datasource.shop.username
=
ERP
spring.datasource.shop.username
=
ERP
spring.datasource.shop.password
=
qiyang@2013
spring.datasource.shop.password
=
qiyang@2013
spring.datasource.shop.url
=
jdbc:sqlserver://10.10.0.22:1433;instanceName=SQLSERVER;DatabaseName=EGOLMDEV
spring.datasource.shop.url
=
jdbc:sqlserver://10.10.0.22:1433;instanceName=SQLSERVER;DatabaseName=EGOLMDEV
;SelectMethod=cursor;
spring.datasource.shop.driver-class-name
=
com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.shop.driver-class-name
=
com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.shop.testWhileIdle
=
true
spring.datasource.shop.testWhileIdle
=
true
spring.datasource.shop.validationQueryTimeout
=
5
spring.datasource.shop.validationQueryTimeout
=
5
...
...
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