Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JeeSpringCloud
Commits
d3ad3768
Commit
d3ad3768
authored
Nov 12, 2018
by
Huang
Browse files
no commit message
parent
b6becbcd
Changes
393
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
20 of 393+
files are displayed.
Plain diff
Email patch
JeeSpringCloud/src/main/java/com/jeespring/modules/job/entity/SysJobLog.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.job.entity
;
import
org.hibernate.validator.constraints.Length
;
import
java.util.Date
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.jeespring.common.persistence.AbstractBaseEntity
;
import
com.jeespring.common.utils.excel.annotation.ExcelField
;
import
com.jeespring.modules.sys.utils.DictUtils
;
/**
* 定时任务调度日志表Entity
* @author JeeSpring
* @version 2018-08-16
*/
public
class
SysJobLog
extends
AbstractBaseEntity
<
SysJobLog
>
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
jobName
;
// 任务名称
private
String
jobGroup
;
// 任务组名
private
String
methodName
;
// 任务方法
private
String
methodParams
;
// 方法参数
private
String
jobMessage
;
// 日志信息
private
String
status
;
// 执行状态(0正常 1失败)
private
String
statusLabel
;
// 执行状态(0正常 1失败)Label
private
String
statusPicture
;
// 执行状态(0正常 1失败)Picture
private
String
exceptionInfo
;
// 异常信息
private
java
.
util
.
Date
beginCreateDate
;
// 开始 创建时间
private
java
.
util
.
Date
endCreateDate
;
// 结束 创建时间
public
SysJobLog
()
{
super
();
}
public
SysJobLog
(
String
id
){
super
(
id
);
}
@Length
(
min
=
1
,
max
=
64
,
message
=
"任务名称长度必须介于 1 和 64 之间"
)
@ExcelField
(
title
=
"任务名称"
,
align
=
2
,
sort
=
1
)
public
String
getJobName
()
{
return
jobName
;
}
public
void
setJobName
(
String
jobName
)
{
this
.
jobName
=
jobName
;
}
@Length
(
min
=
1
,
max
=
64
,
message
=
"任务组名长度必须介于 1 和 64 之间"
)
@ExcelField
(
title
=
"任务组名"
,
align
=
2
,
sort
=
2
)
public
String
getJobGroup
()
{
return
jobGroup
;
}
public
void
setJobGroup
(
String
jobGroup
)
{
this
.
jobGroup
=
jobGroup
;
}
@Length
(
min
=
0
,
max
=
500
,
message
=
"任务方法长度必须介于 0 和 500 之间"
)
@ExcelField
(
title
=
"任务方法"
,
align
=
2
,
sort
=
3
)
public
String
getMethodName
()
{
return
methodName
;
}
public
void
setMethodName
(
String
methodName
)
{
this
.
methodName
=
methodName
;
}
@Length
(
min
=
0
,
max
=
200
,
message
=
"方法参数长度必须介于 0 和 200 之间"
)
@ExcelField
(
title
=
"方法参数"
,
align
=
2
,
sort
=
4
)
public
String
getMethodParams
()
{
return
methodParams
;
}
public
void
setMethodParams
(
String
methodParams
)
{
this
.
methodParams
=
methodParams
;
}
@Length
(
min
=
0
,
max
=
500
,
message
=
"日志信息长度必须介于 0 和 500 之间"
)
@ExcelField
(
title
=
"日志信息"
,
align
=
2
,
sort
=
5
)
public
String
getJobMessage
()
{
return
jobMessage
;
}
public
void
setJobMessage
(
String
jobMessage
)
{
this
.
jobMessage
=
jobMessage
;
}
@Length
(
min
=
0
,
max
=
1
,
message
=
"执行状态(0正常 1失败)长度必须介于 0 和 1 之间"
)
@ExcelField
(
title
=
"执行状态(0正常 1失败)"
,
dictType
=
"job_status"
,
align
=
2
,
sort
=
6
)
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
status
)
{
this
.
status
=
status
;
}
public
String
getStatusLabel
()
{
return
DictUtils
.
getDictLabel
(
status
,
"job_status"
,
""
);
}
public
String
getStatusPicture
()
{
return
DictUtils
.
getDictPicture
(
status
,
"job_status"
,
""
);
}
@ExcelField
(
title
=
"异常信息"
,
align
=
2
,
sort
=
7
)
public
String
getExceptionInfo
()
{
return
exceptionInfo
;
}
public
void
setExceptionInfo
(
String
exceptionInfo
)
{
this
.
exceptionInfo
=
exceptionInfo
;
}
public
Date
getBeginCreateDate
()
{
return
beginCreateDate
;
}
public
void
setBeginCreateDate
(
Date
beginCreateDate
)
{
this
.
beginCreateDate
=
beginCreateDate
;
}
public
Date
getEndCreateDate
()
{
return
endCreateDate
;
}
public
void
setEndCreateDate
(
Date
endCreateDate
)
{
this
.
endCreateDate
=
endCreateDate
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/job/rest/SysJobLogRestController.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.job.rest
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.Logical
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.utils.DateUtils
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.utils.excel.ExportExcel
;
import
com.jeespring.common.utils.excel.ImportExcel
;
import
com.jeespring.modules.job.entity.SysJobLog
;
import
com.jeespring.modules.job.service.SysJobLogService
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.jeespring.common.web.Result
;
import
com.jeespring.common.web.ResultFactory
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
/**
* 定时任务调度日志表Controller
* @author JeeSpring
* @version 2018-08-16
*/
@RestController
@RequestMapping
(
value
=
"/rest/job/sysJobLog"
)
@Api
(
value
=
"定时任务调度日志接口"
,
description
=
"定时任务调度日志接口"
)
public
class
SysJobLogRestController
extends
AbstractBaseController
{
@Autowired
private
SysJobLogService
sysJobLogService
;
/**
* 定时任务调度日志信息
*/
@RequestMapping
(
value
=
{
"get"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"定时任务调度日志信息(Content-Type为text/html)"
,
notes
=
"定时任务调度日志信息(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"定时任务调度日志id"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
getRequestParam
(
@RequestParam
(
required
=
false
)
String
id
)
{
return
get
(
id
);
}
@RequestMapping
(
value
=
{
"get/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"定时任务调度日志信息(Content-Type为application/json)"
,
notes
=
"定时任务调度日志信息(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"定时任务调度日志id"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
getRequestBody
(
@RequestBody
(
required
=
false
)
String
id
)
{
return
get
(
id
);
}
private
Result
get
(
String
id
)
{
SysJobLog
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
sysJobLogService
.
getCache
(
id
);
//entity = sysJobLogService.get(id);
}
if
(
entity
==
null
){
entity
=
new
SysJobLog
();
}
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
entity
);
return
result
;
}
/**
* 定时任务调度日志列表(不包含页信息)
*/
//RequiresPermissions("job:sysJobLog:findList")
@RequestMapping
(
value
=
{
"findList"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"定时任务调度日志列表(不包含页信息)(Content-Type为text/html)"
,
notes
=
"定时任务调度日志列表(不包含页信息)(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"query"
)
public
Result
findListRequestParam
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
findList
(
sysJobLog
,
model
);
}
@RequestMapping
(
value
=
{
"findList/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"定时任务调度日志列表(不包含页信息)(Content-Type为application/json)"
,
notes
=
"定时任务调度日志列表(不包含页信息)(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"body"
)
public
Result
findListRequestBody
(
@RequestBody
SysJobLog
sysJobLog
,
Model
model
)
{
return
findList
(
sysJobLog
,
model
);
}
private
Result
findList
(
SysJobLog
sysJobLog
,
Model
model
)
{
List
<
SysJobLog
>
list
=
sysJobLogService
.
findListCache
(
sysJobLog
);
//List<SysJobLog> list = sysJobLogService.findList(sysJobLog);
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
list
);
return
result
;
}
/**
* 定时任务调度日志列表(包含页信息)
*/
//RequiresPermissions("job:sysJobLog:list")
@RequestMapping
(
value
=
{
"list"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"定时任务调度日志列表(包含页信息)(Content-Type为text/html)"
,
notes
=
"定时任务调度日志列表(包含页信息)(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"query"
)
public
Result
listRequestParam
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
list
(
sysJobLog
,
model
);
}
@RequestMapping
(
value
=
{
"list/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"定时任务调度日志列表(包含页信息)(Content-Type为application/json)"
,
notes
=
"定时任务调度日志列表(包含页信息)(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"body"
)
public
Result
listRequestBody
(
@RequestBody
SysJobLog
sysJobLog
,
Model
model
)
{
return
list
(
sysJobLog
,
model
);
}
private
Result
list
(
SysJobLog
sysJobLog
,
Model
model
)
{
Page
<
SysJobLog
>
page
=
sysJobLogService
.
findPageCache
(
new
Page
<
SysJobLog
>(
sysJobLog
.
getPageNo
(),
sysJobLog
.
getPageSize
(),
sysJobLog
.
getOrderBy
()),
sysJobLog
);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(sysJobLog.getPageNo(),sysJobLog.getPageSize(),sysJobLog.getOrderBy()), sysJobLog);
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
page
);
return
result
;
}
/**
* 定时任务调度日志获取列表第一条记录
*/
//RequiresPermissions("job:sysJobLog:listFrist")
@RequestMapping
(
value
=
{
"listFrist"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"定时任务调度日志获取列表第一条记录(Content-Type为text/html)"
,
notes
=
"定时任务调度日志获取列表第一条记录(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"query"
)
public
Result
listFristRequestParam
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
listFrist
(
sysJobLog
,
model
);
}
@RequestMapping
(
value
=
{
"listFrist/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"定时任务调度日志获取列表第一条记录(Content-Type为application/json)"
,
notes
=
"定时任务调度日志获取列表第一条记录(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"body"
)
public
Result
listFristRequestBody
(
@RequestBody
SysJobLog
sysJobLog
,
Model
model
)
{
return
listFrist
(
sysJobLog
,
model
);
}
private
Result
listFrist
(
SysJobLog
sysJobLog
,
Model
model
)
{
Page
<
SysJobLog
>
page
=
sysJobLogService
.
findPageCache
(
new
Page
<
SysJobLog
>(
sysJobLog
.
getPageNo
(),
sysJobLog
.
getPageSize
(),
sysJobLog
.
getOrderBy
()),
sysJobLog
);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(sysJobLog.getPageNo(),sysJobLog.getPageSize(),sysJobLog.getOrderBy()), sysJobLog);
Result
result
=
ResultFactory
.
getSuccessResult
();
if
(
page
.
getList
().
size
()>
0
){
result
.
setResultObject
(
page
.
getList
().
get
(
0
));
}
else
{
result
=
ResultFactory
.
getErrorResult
(
"没有记录!"
);
}
return
result
;
}
/**
* 保存定时任务调度日志
*/
//RequiresPermissions(value={"job:sysJobLog:add","job:sysJobLog:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"保存定时任务调度日志(Content-Type为text/html)"
,
notes
=
"保存定时任务调度日志(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"query"
)
public
Result
saveRequestParam
(
SysJobLog
sysJobLog
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
return
save
(
sysJobLog
,
model
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"save/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"保存定时任务调度日志(Content-Type为application/json)"
,
notes
=
"保存定时任务调度日志(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"body"
)
public
Result
saveRequestBody
(
@RequestBody
SysJobLog
sysJobLog
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
return
save
(
sysJobLog
,
model
,
redirectAttributes
);
}
private
Result
save
(
SysJobLog
sysJobLog
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
sysJobLog
)){
Result
result
=
ResultFactory
.
getErrorResult
(
"数据验证失败"
);
}
sysJobLogService
.
save
(
sysJobLog
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"保存定时任务调度日志成功"
);
return
result
;
}
/**
* 删除定时任务调度日志
*/
//RequiresPermissions("job:sysJobLog:del")
@RequestMapping
(
value
=
"delete"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"删除定时任务调度日志(Content-Type为text/html)"
,
notes
=
"删除定时任务调度日志(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"query"
)
public
Result
deleteRequestParam
(
SysJobLog
sysJobLog
,
RedirectAttributes
redirectAttributes
)
{
return
delete
(
sysJobLog
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"delete/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"删除定时任务调度日志(Content-Type为application/json)"
,
notes
=
"删除定时任务调度日志(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"body"
)
public
Result
deleteRequestBody
(
@RequestBody
SysJobLog
sysJobLog
,
RedirectAttributes
redirectAttributes
)
{
return
delete
(
sysJobLog
,
redirectAttributes
);
}
private
Result
delete
(
SysJobLog
sysJobLog
,
RedirectAttributes
redirectAttributes
)
{
sysJobLogService
.
delete
(
sysJobLog
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除定时任务调度日志成功"
);
return
result
;
}
/**
* 删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteByLogic"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"逻辑删除定时任务调度日志(Content-Type为text/html)"
,
notes
=
"逻辑删除定时任务调度日志(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"query"
)
public
Result
deleteByLogicRequestParam
(
SysJobLog
sysJobLog
,
RedirectAttributes
redirectAttributes
)
{
return
deleteByLogic
(
sysJobLog
,
redirectAttributes
);
}
/**
* 删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteByLogic/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"逻辑删除定时任务调度日志(Content-Type为application/json)"
,
notes
=
"逻辑删除定时任务调度日志(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJobLog"
,
value
=
"定时任务调度日志"
,
dataType
=
"SysJobLog"
,
paramType
=
"body"
)
public
Result
deleteByLogicRequestBody
(
@RequestBody
SysJobLog
sysJobLog
,
RedirectAttributes
redirectAttributes
)
{
return
deleteByLogic
(
sysJobLog
,
redirectAttributes
);
}
private
Result
deleteByLogic
(
SysJobLog
sysJobLog
,
RedirectAttributes
redirectAttributes
)
{
sysJobLogService
.
deleteByLogic
(
sysJobLog
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除定时任务调度日志成功"
);
return
result
;
}
/**
* 批量删除定时任务调度日志
*/
//RequiresPermissions("job:sysJobLog:del")
@RequestMapping
(
value
=
"deleteAll"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"批量删除定时任务调度日志(Content-Type为text/html)"
,
notes
=
"批量删除定时任务调度日志(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"定时任务调度日志ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
deleteAllRequestParam
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAll
(
ids
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"deleteAll/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"批量删除定时任务调度日志(Content-Type为application/json)"
,
notes
=
"批量删除定时任务调度日志(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"定时任务调度日志ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
deleteAllRequestBody
(
@RequestBody
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAll
(
ids
,
redirectAttributes
);
}
private
Result
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysJobLogService
.
delete
(
sysJobLogService
.
get
(
id
));
}
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除定时任务调度日志成功"
);
return
result
;
}
/**
* 批量删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteAllByLogic"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"逻辑批量删除定时任务调度日志(Content-Type为text/html)"
,
notes
=
"逻辑批量删除定时任务调度日志(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"定时任务调度日志ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
deleteAllByLogicRequestParam
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAllByLogic
(
ids
,
redirectAttributes
);
}
/**
* 批量删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteAllByLogic/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"逻辑批量删除定时任务调度日志(Content-Type为application/json)"
,
notes
=
"逻辑批量删除定时任务调度日志(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"定时任务调度日志ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
deleteAllByLogicRequestBody
(
@RequestBody
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAllByLogic
(
ids
,
redirectAttributes
);
}
private
Result
deleteAllByLogic
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysJobLogService
.
deleteByLogic
(
sysJobLogService
.
get
(
id
));
}
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除定时任务调度日志成功"
);
return
result
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/job/rest/SysJobRestController.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.job.rest
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.Logical
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.utils.DateUtils
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.utils.excel.ExportExcel
;
import
com.jeespring.common.utils.excel.ImportExcel
;
import
com.jeespring.modules.job.entity.SysJob
;
import
com.jeespring.modules.job.service.SysJobService
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.jeespring.common.web.Result
;
import
com.jeespring.common.web.ResultFactory
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
/**
* 定时任务调度Controller
* @author JeeSpring
* @version 2018-08-16
*/
@RestController
@RequestMapping
(
value
=
"/rest/job/sysJob"
)
@Api
(
value
=
"定时任务调度接口"
,
description
=
"定时任务调度接口"
)
public
class
SysJobRestController
extends
AbstractBaseController
{
@Autowired
private
SysJobService
sysJobService
;
/**
* 定时任务调度信息
*/
@RequestMapping
(
value
=
{
"get"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"定时任务调度信息(Content-Type为text/html)"
,
notes
=
"定时任务调度信息(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"定时任务调度id"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
getRequestParam
(
@RequestParam
(
required
=
false
)
String
id
)
{
return
get
(
id
);
}
@RequestMapping
(
value
=
{
"get/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"定时任务调度信息(Content-Type为application/json)"
,
notes
=
"定时任务调度信息(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"定时任务调度id"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
getRequestBody
(
@RequestBody
(
required
=
false
)
String
id
)
{
return
get
(
id
);
}
private
Result
get
(
String
id
)
{
SysJob
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
sysJobService
.
getCache
(
id
);
//entity = sysJobService.get(id);
}
if
(
entity
==
null
){
entity
=
new
SysJob
();
}
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
entity
);
return
result
;
}
/**
* 定时任务调度列表(不包含页信息)
*/
//RequiresPermissions("job:sysJob:findList")
@RequestMapping
(
value
=
{
"findList"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"定时任务调度列表(不包含页信息)(Content-Type为text/html)"
,
notes
=
"定时任务调度列表(不包含页信息)(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"query"
)
public
Result
findListRequestParam
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
findList
(
sysJob
,
model
);
}
@RequestMapping
(
value
=
{
"findList/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"定时任务调度列表(不包含页信息)(Content-Type为application/json)"
,
notes
=
"定时任务调度列表(不包含页信息)(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"body"
)
public
Result
findListRequestBody
(
@RequestBody
SysJob
sysJob
,
Model
model
)
{
return
findList
(
sysJob
,
model
);
}
private
Result
findList
(
SysJob
sysJob
,
Model
model
)
{
List
<
SysJob
>
list
=
sysJobService
.
findListCache
(
sysJob
);
//List<SysJob> list = sysJobService.findList(sysJob);
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
list
);
return
result
;
}
/**
* 定时任务调度列表(包含页信息)
*/
//RequiresPermissions("job:sysJob:list")
@RequestMapping
(
value
=
{
"list"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"定时任务调度列表(包含页信息)(Content-Type为text/html)"
,
notes
=
"定时任务调度列表(包含页信息)(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"query"
)
public
Result
listRequestParam
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
list
(
sysJob
,
model
);
}
@RequestMapping
(
value
=
{
"list/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"定时任务调度列表(包含页信息)(Content-Type为application/json)"
,
notes
=
"定时任务调度列表(包含页信息)(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"body"
)
public
Result
listRequestBody
(
@RequestBody
SysJob
sysJob
,
Model
model
)
{
return
list
(
sysJob
,
model
);
}
private
Result
list
(
SysJob
sysJob
,
Model
model
)
{
Page
<
SysJob
>
page
=
sysJobService
.
findPageCache
(
new
Page
<
SysJob
>(
sysJob
.
getPageNo
(),
sysJob
.
getPageSize
(),
sysJob
.
getOrderBy
()),
sysJob
);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(sysJob.getPageNo(),sysJob.getPageSize(),sysJob.getOrderBy()), sysJob);
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
page
);
return
result
;
}
/**
* 定时任务调度获取列表第一条记录
*/
//RequiresPermissions("job:sysJob:listFrist")
@RequestMapping
(
value
=
{
"listFrist"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"定时任务调度获取列表第一条记录(Content-Type为text/html)"
,
notes
=
"定时任务调度获取列表第一条记录(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"query"
)
public
Result
listFristRequestParam
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
listFrist
(
sysJob
,
model
);
}
@RequestMapping
(
value
=
{
"listFrist/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"定时任务调度获取列表第一条记录(Content-Type为application/json)"
,
notes
=
"定时任务调度获取列表第一条记录(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"body"
)
public
Result
listFristRequestBody
(
@RequestBody
SysJob
sysJob
,
Model
model
)
{
return
listFrist
(
sysJob
,
model
);
}
private
Result
listFrist
(
SysJob
sysJob
,
Model
model
)
{
Page
<
SysJob
>
page
=
sysJobService
.
findPageCache
(
new
Page
<
SysJob
>(
sysJob
.
getPageNo
(),
sysJob
.
getPageSize
(),
sysJob
.
getOrderBy
()),
sysJob
);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(sysJob.getPageNo(),sysJob.getPageSize(),sysJob.getOrderBy()), sysJob);
Result
result
=
ResultFactory
.
getSuccessResult
();
if
(
page
.
getList
().
size
()>
0
){
result
.
setResultObject
(
page
.
getList
().
get
(
0
));
}
else
{
result
=
ResultFactory
.
getErrorResult
(
"没有记录!"
);
}
return
result
;
}
/**
* 保存定时任务调度
*/
//RequiresPermissions(value={"job:sysJob:add","job:sysJob:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"保存定时任务调度(Content-Type为text/html)"
,
notes
=
"保存定时任务调度(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"query"
)
public
Result
saveRequestParam
(
SysJob
sysJob
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
return
save
(
sysJob
,
model
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"save/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"保存定时任务调度(Content-Type为application/json)"
,
notes
=
"保存定时任务调度(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"body"
)
public
Result
saveRequestBody
(
@RequestBody
SysJob
sysJob
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
return
save
(
sysJob
,
model
,
redirectAttributes
);
}
private
Result
save
(
SysJob
sysJob
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
sysJob
)){
Result
result
=
ResultFactory
.
getErrorResult
(
"数据验证失败"
);
}
sysJobService
.
save
(
sysJob
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"保存定时任务调度成功"
);
return
result
;
}
/**
* 删除定时任务调度
*/
//RequiresPermissions("job:sysJob:del")
@RequestMapping
(
value
=
"delete"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"删除定时任务调度(Content-Type为text/html)"
,
notes
=
"删除定时任务调度(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"query"
)
public
Result
deleteRequestParam
(
SysJob
sysJob
,
RedirectAttributes
redirectAttributes
)
{
return
delete
(
sysJob
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"delete/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"删除定时任务调度(Content-Type为application/json)"
,
notes
=
"删除定时任务调度(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"body"
)
public
Result
deleteRequestBody
(
@RequestBody
SysJob
sysJob
,
RedirectAttributes
redirectAttributes
)
{
return
delete
(
sysJob
,
redirectAttributes
);
}
private
Result
delete
(
SysJob
sysJob
,
RedirectAttributes
redirectAttributes
)
{
sysJobService
.
delete
(
sysJob
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除定时任务调度成功"
);
return
result
;
}
/**
* 删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteByLogic"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"逻辑删除定时任务调度(Content-Type为text/html)"
,
notes
=
"逻辑删除定时任务调度(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"query"
)
public
Result
deleteByLogicRequestParam
(
SysJob
sysJob
,
RedirectAttributes
redirectAttributes
)
{
return
deleteByLogic
(
sysJob
,
redirectAttributes
);
}
/**
* 删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteByLogic/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"逻辑删除定时任务调度(Content-Type为application/json)"
,
notes
=
"逻辑删除定时任务调度(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysJob"
,
value
=
"定时任务调度"
,
dataType
=
"SysJob"
,
paramType
=
"body"
)
public
Result
deleteByLogicRequestBody
(
@RequestBody
SysJob
sysJob
,
RedirectAttributes
redirectAttributes
)
{
return
deleteByLogic
(
sysJob
,
redirectAttributes
);
}
private
Result
deleteByLogic
(
SysJob
sysJob
,
RedirectAttributes
redirectAttributes
)
{
sysJobService
.
deleteByLogic
(
sysJob
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除定时任务调度成功"
);
return
result
;
}
/**
* 批量删除定时任务调度
*/
//RequiresPermissions("job:sysJob:del")
@RequestMapping
(
value
=
"deleteAll"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"批量删除定时任务调度(Content-Type为text/html)"
,
notes
=
"批量删除定时任务调度(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"定时任务调度ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
deleteAllRequestParam
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAll
(
ids
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"deleteAll/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"批量删除定时任务调度(Content-Type为application/json)"
,
notes
=
"批量删除定时任务调度(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"定时任务调度ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
deleteAllRequestBody
(
@RequestBody
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAll
(
ids
,
redirectAttributes
);
}
private
Result
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysJobService
.
delete
(
sysJobService
.
get
(
id
));
}
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除定时任务调度成功"
);
return
result
;
}
/**
* 批量删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteAllByLogic"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"逻辑批量删除定时任务调度(Content-Type为text/html)"
,
notes
=
"逻辑批量删除定时任务调度(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"定时任务调度ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
deleteAllByLogicRequestParam
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAllByLogic
(
ids
,
redirectAttributes
);
}
/**
* 批量删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteAllByLogic/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"逻辑批量删除定时任务调度(Content-Type为application/json)"
,
notes
=
"逻辑批量删除定时任务调度(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"定时任务调度ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
deleteAllByLogicRequestBody
(
@RequestBody
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAllByLogic
(
ids
,
redirectAttributes
);
}
private
Result
deleteAllByLogic
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysJobService
.
deleteByLogic
(
sysJobService
.
get
(
id
));
}
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除定时任务调度成功"
);
return
result
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/job/service/SysJobLogService.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.job.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.job.entity.SysJobLog
;
import
com.jeespring.modules.job.dao.SysJobLogDao
;
import
com.alibaba.fastjson.JSON
;
import
com.jeespring.common.redis.RedisUtils
;
import
com.jeespring.common.security.MD5Tools
;
/**
* 定时任务调度日志表Service
* @author JeeSpring
* @version 2018-08-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
SysJobLogService
extends
AbstractBaseService
<
SysJobLogDao
,
SysJobLog
>
{
/**
* redis caches
*/
@Autowired
private
RedisUtils
redisUtils
;
@Override
public
SysJobLog
get
(
String
id
)
{
//获取数据库数据
SysJobLog
sysJobLog
=
super
.
get
(
id
);
return
sysJobLog
;
}
public
SysJobLog
getCache
(
String
id
)
{
//获取缓存数据
SysJobLog
sysJobLog
=(
SysJobLog
)
redisUtils
.
get
(
RedisUtils
.
getIdKey
(
SysJobLogService
.
class
.
getName
(),
id
));
if
(
sysJobLog
!=
null
)
{
return
sysJobLog
;
}
//获取数据库数据
sysJobLog
=
super
.
get
(
id
);
//设置缓存数据
redisUtils
.
set
(
RedisUtils
.
getIdKey
(
SysJobLogService
.
class
.
getName
(),
id
),
sysJobLog
);
return
sysJobLog
;
}
@Override
public
List
<
SysJobLog
>
total
(
SysJobLog
sysJobLog
)
{
//获取数据库数据
List
<
SysJobLog
>
sysJobLogList
=
super
.
total
(
sysJobLog
);
return
sysJobLogList
;
}
public
List
<
SysJobLog
>
totalCache
(
SysJobLog
sysJobLog
)
{
//获取缓存数据
String
totalKey
=
RedisUtils
.
getTotalKey
(
SysJobLogService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysJobLog
));
List
<
SysJobLog
>
sysJobLogList
=(
List
<
SysJobLog
>)
redisUtils
.
get
(
totalKey
);
if
(
sysJobLogList
!=
null
)
{
return
sysJobLogList
;
}
//获取数据库数据
sysJobLogList
=
super
.
total
(
sysJobLog
);
//设置缓存数据
redisUtils
.
set
(
totalKey
,
sysJobLogList
);
return
sysJobLogList
;
}
@Override
public
List
<
SysJobLog
>
findList
(
SysJobLog
sysJobLog
)
{
//获取数据库数据
List
<
SysJobLog
>
sysJobLogList
=
super
.
findList
(
sysJobLog
);
//设置缓存数据
return
sysJobLogList
;
}
public
List
<
SysJobLog
>
findListCache
(
SysJobLog
sysJobLog
)
{
//获取缓存数据
String
findListKey
=
RedisUtils
.
getFindListKey
(
SysJobLogService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysJobLog
));
List
<
SysJobLog
>
sysJobLogList
=(
List
<
SysJobLog
>)
redisUtils
.
get
(
findListKey
);
if
(
sysJobLogList
!=
null
)
{
return
sysJobLogList
;
}
//获取数据库数据
sysJobLogList
=
super
.
findList
(
sysJobLog
);
//设置缓存数据
redisUtils
.
set
(
findListKey
,
sysJobLogList
);
return
sysJobLogList
;
}
public
SysJobLog
findListFirst
(
SysJobLog
sysJobLog
)
{;
//获取数据库数据
List
<
SysJobLog
>
sysJobLogList
=
super
.
findList
(
sysJobLog
);
if
(
sysJobLogList
.
size
()>
0
)
{
sysJobLog
=
sysJobLogList
.
get
(
0
);
}
return
sysJobLog
;
}
public
SysJobLog
findListFirstCache
(
SysJobLog
sysJobLog
)
{
//获取缓存数据
String
findListFirstKey
=
RedisUtils
.
getFindListFirstKey
(
SysJobLogService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysJobLog
));
SysJobLog
sysJobLogRedis
=(
SysJobLog
)
redisUtils
.
get
(
findListFirstKey
);
if
(
sysJobLogRedis
!=
null
)
{
return
sysJobLogRedis
;
}
//获取数据库数据
List
<
SysJobLog
>
sysJobLogList
=
super
.
findList
(
sysJobLog
);
if
(
sysJobLogList
.
size
()>
0
)
{
sysJobLog
=
sysJobLogList
.
get
(
0
);
}
else
{
sysJobLog
=
new
SysJobLog
();
}
//设置缓存数据
redisUtils
.
set
(
findListFirstKey
,
sysJobLog
);
return
sysJobLog
;
}
@Override
public
Page
<
SysJobLog
>
findPage
(
Page
<
SysJobLog
>
page
,
SysJobLog
sysJobLog
)
{
//获取数据库数据
Page
<
SysJobLog
>
pageReuslt
=
super
.
findPage
(
page
,
sysJobLog
);
return
pageReuslt
;
}
public
Page
<
SysJobLog
>
findPageCache
(
Page
<
SysJobLog
>
page
,
SysJobLog
sysJobLog
)
{
//获取缓存数据
String
findPageKey
=
RedisUtils
.
getFindPageKey
(
SysJobLogService
.
class
.
getName
(),
JSON
.
toJSONString
(
page
)+
JSON
.
toJSONString
(
sysJobLog
));
Page
<
SysJobLog
>
pageReuslt
=(
Page
<
SysJobLog
>)
redisUtils
.
get
(
findPageKey
);
if
(
pageReuslt
!=
null
)
{
return
pageReuslt
;
}
//获取数据库数据
pageReuslt
=
super
.
findPage
(
page
,
sysJobLog
);
//设置缓存数据
redisUtils
.
set
(
findPageKey
,
pageReuslt
);
return
pageReuslt
;
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
save
(
SysJobLog
sysJobLog
)
{
//保存数据库记录
super
.
save
(
sysJobLog
);
//设置清除缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysJobLogService
.
class
.
getName
(),
sysJobLog
.
getId
()));
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysJobLogService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysJobLogService
.
class
.
getName
()));
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
delete
(
SysJobLog
sysJobLog
)
{
//清除记录缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysJobLogService
.
class
.
getName
(),
sysJobLog
.
getId
()));
//删除数据库记录
super
.
delete
(
sysJobLog
);
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysJobLogService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysJobLogService
.
class
.
getName
()));
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
deleteByLogic
(
SysJobLog
sysJobLog
)
{
//清除记录缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysJobLogService
.
class
.
getName
(),
sysJobLog
.
getId
()));
//逻辑删除数据库记录
super
.
deleteByLogic
(
sysJobLog
);
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysJobLogService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysJobLogService
.
class
.
getName
()));
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/job/service/SysJobService.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.job.service
;
import
java.util.List
;
import
com.jeespring.common.constant.ScheduleConstants
;
import
com.jeespring.common.security.ShiroUtils
;
import
com.jeespring.modules.job.util.ScheduleUtils
;
import
org.quartz.CronTrigger
;
import
org.quartz.Scheduler
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.job.entity.SysJob
;
import
com.jeespring.modules.job.dao.SysJobDao
;
import
com.alibaba.fastjson.JSON
;
import
com.jeespring.common.redis.RedisUtils
;
import
com.jeespring.common.security.MD5Tools
;
import
javax.annotation.PostConstruct
;
/**
* 定时任务调度Service
* @author JeeSpring
* @version 2018-08-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
SysJobService
extends
AbstractBaseService
<
SysJobDao
,
SysJob
>
{
/**
* redis caches
*/
@Autowired
private
RedisUtils
redisUtils
;
@Override
public
SysJob
get
(
String
id
)
{
//获取数据库数据
SysJob
sysJob
=
super
.
get
(
id
);
return
sysJob
;
}
public
SysJob
getCache
(
String
id
)
{
//获取缓存数据
SysJob
sysJob
=(
SysJob
)
redisUtils
.
get
(
RedisUtils
.
getIdKey
(
SysJobService
.
class
.
getName
(),
id
));
if
(
sysJob
!=
null
)
{
return
sysJob
;
}
//获取数据库数据
sysJob
=
super
.
get
(
id
);
//设置缓存数据
redisUtils
.
set
(
RedisUtils
.
getIdKey
(
SysJobService
.
class
.
getName
(),
id
),
sysJob
);
return
sysJob
;
}
@Override
public
List
<
SysJob
>
total
(
SysJob
sysJob
)
{
//获取数据库数据
List
<
SysJob
>
sysJobList
=
super
.
total
(
sysJob
);
return
sysJobList
;
}
public
List
<
SysJob
>
totalCache
(
SysJob
sysJob
)
{
//获取缓存数据
String
totalKey
=
RedisUtils
.
getTotalKey
(
SysJobService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysJob
));
List
<
SysJob
>
sysJobList
=(
List
<
SysJob
>)
redisUtils
.
get
(
totalKey
);
if
(
sysJobList
!=
null
)
{
return
sysJobList
;
}
//获取数据库数据
sysJobList
=
super
.
total
(
sysJob
);
//设置缓存数据
redisUtils
.
set
(
totalKey
,
sysJobList
);
return
sysJobList
;
}
@Override
public
List
<
SysJob
>
findList
(
SysJob
sysJob
)
{
//获取数据库数据
List
<
SysJob
>
sysJobList
=
super
.
findList
(
sysJob
);
//设置缓存数据
return
sysJobList
;
}
public
List
<
SysJob
>
findListCache
(
SysJob
sysJob
)
{
//获取缓存数据
String
findListKey
=
RedisUtils
.
getFindListKey
(
SysJobService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysJob
));
List
<
SysJob
>
sysJobList
=(
List
<
SysJob
>)
redisUtils
.
get
(
findListKey
);
if
(
sysJobList
!=
null
)
{
return
sysJobList
;
}
//获取数据库数据
sysJobList
=
super
.
findList
(
sysJob
);
//设置缓存数据
redisUtils
.
set
(
findListKey
,
sysJobList
);
return
sysJobList
;
}
public
SysJob
findListFirst
(
SysJob
sysJob
)
{;
//获取数据库数据
List
<
SysJob
>
sysJobList
=
super
.
findList
(
sysJob
);
if
(
sysJobList
.
size
()>
0
)
{
sysJob
=
sysJobList
.
get
(
0
);
}
return
sysJob
;
}
public
SysJob
findListFirstCache
(
SysJob
sysJob
)
{
//获取缓存数据
String
findListFirstKey
=
RedisUtils
.
getFindListFirstKey
(
SysJobService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysJob
));
SysJob
sysJobRedis
=(
SysJob
)
redisUtils
.
get
(
findListFirstKey
);
if
(
sysJobRedis
!=
null
)
{
return
sysJobRedis
;
}
//获取数据库数据
List
<
SysJob
>
sysJobList
=
super
.
findList
(
sysJob
);
if
(
sysJobList
.
size
()>
0
)
{
sysJob
=
sysJobList
.
get
(
0
);
}
else
{
sysJob
=
new
SysJob
();
}
//设置缓存数据
redisUtils
.
set
(
findListFirstKey
,
sysJob
);
return
sysJob
;
}
@Override
public
Page
<
SysJob
>
findPage
(
Page
<
SysJob
>
page
,
SysJob
sysJob
)
{
//获取数据库数据
Page
<
SysJob
>
pageReuslt
=
super
.
findPage
(
page
,
sysJob
);
return
pageReuslt
;
}
public
Page
<
SysJob
>
findPageCache
(
Page
<
SysJob
>
page
,
SysJob
sysJob
)
{
//获取缓存数据
String
findPageKey
=
RedisUtils
.
getFindPageKey
(
SysJobService
.
class
.
getName
(),
JSON
.
toJSONString
(
page
)+
JSON
.
toJSONString
(
sysJob
));
Page
<
SysJob
>
pageReuslt
=(
Page
<
SysJob
>)
redisUtils
.
get
(
findPageKey
);
if
(
pageReuslt
!=
null
)
{
return
pageReuslt
;
}
//获取数据库数据
pageReuslt
=
super
.
findPage
(
page
,
sysJob
);
//设置缓存数据
redisUtils
.
set
(
findPageKey
,
pageReuslt
);
return
pageReuslt
;
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
save
(
SysJob
sysJob
)
{
if
(
sysJob
.
getIsNewRecord
())
{
sysJob
.
setStatus
(
ScheduleConstants
.
Status
.
PAUSE
.
getValue
());
}
//保存数据库记录
super
.
save
(
sysJob
);
if
(
sysJob
.
getIsNewRecord
())
{
ScheduleUtils
.
createScheduleJob
(
scheduler
,
sysJob
);
}
else
{
ScheduleUtils
.
updateScheduleJob
(
scheduler
,
sysJob
);
}
/*if (ScheduleConstants.Status.NORMAL.getValue().equals(sysJob.getStatus()))
{
resumeJob(sysJob);
}
else if (ScheduleConstants.Status.PAUSE.getValue().equals(sysJob.getStatus()))
{
pauseJob(sysJob);
}*/
//设置清除缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysJobService
.
class
.
getName
(),
sysJob
.
getId
()));
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysJobService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysJobService
.
class
.
getName
()));
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
delete
(
SysJob
sysJob
)
{
//清除记录缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysJobService
.
class
.
getName
(),
sysJob
.
getId
()));
//删除数据库记录
super
.
delete
(
sysJob
);
ScheduleUtils
.
deleteScheduleJob
(
scheduler
,
sysJob
.
getId
());
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysJobService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysJobService
.
class
.
getName
()));
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
deleteByLogic
(
SysJob
sysJob
)
{
//清除记录缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysJobService
.
class
.
getName
(),
sysJob
.
getId
()));
//逻辑删除数据库记录
super
.
deleteByLogic
(
sysJob
);
ScheduleUtils
.
deleteScheduleJob
(
scheduler
,
sysJob
.
getId
());
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysJobService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysJobService
.
class
.
getName
()));
}
@Autowired
private
Scheduler
scheduler
;
/**
* 项目启动时,初始化定时器
*/
@PostConstruct
public
void
init
()
{
List
<
SysJob
>
jobList
=
super
.
findAllList
(
new
SysJob
());
for
(
SysJob
job
:
jobList
)
{
CronTrigger
cronTrigger
=
ScheduleUtils
.
getCronTrigger
(
scheduler
,
job
.
getId
());
// 如果不存在,则创建
if
(
cronTrigger
==
null
)
{
ScheduleUtils
.
createScheduleJob
(
scheduler
,
job
);
}
else
{
ScheduleUtils
.
updateScheduleJob
(
scheduler
,
job
);
}
}
}
/**
* 暂停任务
*
* @param job 调度信息
*/
@Transactional
(
readOnly
=
false
)
public
void
pauseJob
(
SysJob
job
)
{
job
.
setStatus
(
ScheduleConstants
.
Status
.
PAUSE
.
getValue
());
super
.
save
(
job
);
ScheduleUtils
.
pauseJob
(
scheduler
,
job
.
getId
());
//设置清除缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysJobService
.
class
.
getName
(),
job
.
getId
()));
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysJobService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysJobService
.
class
.
getName
()));
}
/**
* 恢复任务
*
* @param job 调度信息
*/
@Transactional
(
readOnly
=
false
)
public
void
resumeJob
(
SysJob
job
)
{
job
.
setStatus
(
ScheduleConstants
.
Status
.
NORMAL
.
getValue
());
super
.
save
(
job
);
ScheduleUtils
.
resumeJob
(
scheduler
,
job
.
getId
());
//设置清除缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysJobService
.
class
.
getName
(),
job
.
getId
()));
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysJobService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysJobService
.
class
.
getName
()));
}
/**
* 立即运行任务
*
* @param job 调度信息
*/
@Transactional
(
readOnly
=
false
)
public
int
run
(
SysJob
job
)
{
return
ScheduleUtils
.
run
(
scheduler
,
get
(
job
.
getId
()));
}
/**
* 任务调度状态修改
*
* @param job 调度信息
*/
@Transactional
(
readOnly
=
false
)
public
void
changeStatus
(
SysJob
job
)
{
String
status
=
job
.
getStatus
();
if
(
ScheduleConstants
.
Status
.
NORMAL
.
getValue
().
equals
(
status
))
{
pauseJob
(
job
);
}
else
if
(
ScheduleConstants
.
Status
.
PAUSE
.
getValue
().
equals
(
status
))
{
resumeJob
(
job
);
}
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/job/task/JeeSpringTask.java
deleted
100644 → 0
View file @
b6becbcd
package
com.jeespring.modules.job.task
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.utils.HttpRequest
;
import
com.jeespring.common.utils.SendMailUtil
;
import
com.jeespring.modules.sys.entity.SysConfig
;
import
com.jeespring.modules.server.entity.SysServer
;
import
com.jeespring.modules.sys.entity.SysUserOnline
;
import
com.jeespring.modules.sys.service.SysConfigService
;
import
com.jeespring.modules.server.service.SysServerService
;
import
com.jeespring.modules.server.service.ISysServerService
;
import
com.jeespring.modules.sys.service.SysUserOnlineService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
/**
* 定时任务调度测试
*
* @author JeeSpring
*/
@Component
(
"jeeSpringTask"
)
public
class
JeeSpringTask
{
@Autowired
SysUserOnlineService
sysUserOnlineService
;
@Autowired
private
ISysServerService
sysServerService
;
@Autowired
private
SysConfigService
sysConfigService
;
private
static
final
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
public
void
jeeSpringParams
(
String
params
)
{
System
.
out
.
println
(
dateFormat
.
format
(
new
Date
())
+
" | "
+
"定时任务调度测试 com.jeespring.modules.job.task.JeeSpringTask.jeeSpringParams("
+
params
+
")"
);
}
public
void
jeeSpringNoParams
()
{
System
.
out
.
println
(
dateFormat
.
format
(
new
Date
())
+
" | "
+
"定时任务调度测试 com.jeespring.modules.job.task.JeeSpringTask.jeeSpringNoParams()"
);
SysUserOnlineCount
();
}
public
void
SysUserOnlineCount
(){
Page
<
com
.
jeespring
.
modules
.
sys
.
entity
.
SysUserOnline
>
page
=
new
Page
<
com
.
jeespring
.
modules
.
sys
.
entity
.
SysUserOnline
>();
SysUserOnline
sysUserOnline
=
new
SysUserOnline
();
page
.
setPageSize
(
100000
);
sysUserOnline
.
setStatus
(
"on_line"
);
Page
<
SysUserOnline
>
pageSysUserOnline
=
sysUserOnlineService
.
findPageCache
(
page
,
sysUserOnline
);
SysConfig
sysConfig
=
new
SysConfig
();
sysConfig
.
setType
(
"toExceptionMailAddr"
);
sysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
if
(
pageSysUserOnline
.
getList
().
size
()>
0
){
SendMailUtil
.
sendCommonMail
(
sysConfig
.
getValue
(),
"发送在线用户数邮件 SysUserOnlineCount "
+
pageSysUserOnline
.
getList
().
size
()+
"人"
,
"发送在线用户数邮件 SysUserOnlineCount "
+
pageSysUserOnline
.
getList
().
size
()+
"人"
);
}
}
public
void
serverStatus
(){
List
<
SysServer
>
sysServers
=
sysServerService
.
findAllList
(
new
SysServer
());
List
<
SysServer
>
sysServersBug
=
new
ArrayList
<
SysServer
>();
String
message
=
""
;
for
(
SysServer
item:
sysServers
){
item
.
getServerAddress
();
if
(
"Down"
.
equals
(
HttpRequest
.
sendGet
(
item
.
getServerAddress
(),
""
))){
sysServersBug
.
add
(
item
);
message
=
message
+
item
.
getName
()+
" "
+
item
.
getServerAddress
()+
" Down;<br>"
;
item
.
setStatus
(
"off_line"
);
sysServerService
.
save
(
item
);
}
else
{
message
=
message
+
item
.
getName
()+
" "
+
item
.
getServerAddress
()+
" OK;<br>"
;
item
.
setStatus
(
"on_line"
);
sysServerService
.
save
(
item
);
}
}
SysConfig
sysConfig
=
new
SysConfig
();
sysConfig
.
setType
(
"toExceptionMailAddr"
);
sysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
if
(
sysServersBug
.
size
()>
0
){
SendMailUtil
.
sendCommonMail
(
sysConfig
.
getValue
(),
"服务器监控正常("
+(
sysServers
.
size
()-
sysServersBug
.
size
())+
")异常("
+
sysServersBug
.
size
()+
")"
,
message
);
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/job/util/ScheduleJob.java
deleted
100644 → 0
View file @
b6becbcd
package
com.jeespring.modules.job.util
;
import
com.jeespring.common.constant.Constants
;
import
com.jeespring.common.constant.ScheduleConstants
;
import
com.jeespring.common.spring.SpringUtils
;
import
com.jeespring.common.utils.bean.BeanUtils
;
import
com.jeespring.modules.job.entity.SysJob
;
import
com.jeespring.modules.job.entity.SysJobLog
;
import
com.jeespring.modules.job.service.SysJobLogService
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
java.util.Date
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
/**
* 定时任务
*
* @author JeeSpring
*
*/
public
class
ScheduleJob
extends
QuartzJobBean
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ScheduleJob
.
class
);
private
ExecutorService
service
=
Executors
.
newSingleThreadExecutor
();
@Override
protected
void
executeInternal
(
JobExecutionContext
context
)
throws
JobExecutionException
{
SysJob
job
=
new
SysJob
();
BeanUtils
.
copyBeanProp
(
job
,
context
.
getMergedJobDataMap
().
get
(
ScheduleConstants
.
TASK_PROPERTIES
));
SysJobLogService
jobLogService
=
(
SysJobLogService
)
SpringUtils
.
getBean
(
SysJobLogService
.
class
);
SysJobLog
jobLog
=
new
SysJobLog
();
jobLog
.
setJobName
(
job
.
getJobName
());
jobLog
.
setJobGroup
(
job
.
getJobGroup
());
jobLog
.
setMethodName
(
job
.
getMethodName
());
jobLog
.
setMethodParams
(
job
.
getMethodParams
());
jobLog
.
setCreateDate
(
new
Date
());
long
startTime
=
System
.
currentTimeMillis
();
try
{
// 执行任务
log
.
info
(
"任务开始执行 - 名称:{} 方法:{}"
,
job
.
getJobName
(),
job
.
getMethodName
());
ScheduleRunnable
task
=
new
ScheduleRunnable
(
job
.
getJobName
(),
job
.
getMethodName
(),
job
.
getMethodParams
());
Future
<?>
future
=
service
.
submit
(
task
);
future
.
get
();
long
times
=
System
.
currentTimeMillis
()
-
startTime
;
// 任务状态 0:成功 1:失败
jobLog
.
setStatus
(
Constants
.
SUCCESS
);
jobLog
.
setJobMessage
(
job
.
getJobName
()
+
" 总共耗时:"
+
times
+
"毫秒"
);
log
.
info
(
"任务执行结束 - 名称:{} 耗时:{} 毫秒"
,
job
.
getJobName
(),
times
);
}
catch
(
Exception
e
)
{
log
.
info
(
"任务执行失败 - 名称:{} 方法:{}"
,
job
.
getJobName
(),
job
.
getMethodName
());
log
.
error
(
"任务执行异常 - :"
,
e
);
long
times
=
System
.
currentTimeMillis
()
-
startTime
;
jobLog
.
setJobMessage
(
job
.
getJobName
()
+
" 总共耗时:"
+
times
+
"毫秒"
);
// 任务状态 0:成功 1:失败
jobLog
.
setStatus
(
Constants
.
FAIL
);
jobLog
.
setExceptionInfo
(
e
.
toString
());
}
finally
{
jobLogService
.
save
(
jobLog
);
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/job/util/ScheduleRunnable.java
deleted
100644 → 0
View file @
b6becbcd
package
com.jeespring.modules.job.util
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.spring.SpringUtils
;
import
org.springframework.util.ReflectionUtils
;
import
java.lang.reflect.Method
;
/**
* 执行定时任务
*
* @author JeeSpring
*
*/
public
class
ScheduleRunnable
implements
Runnable
{
private
Object
target
;
private
Method
method
;
private
String
params
;
public
ScheduleRunnable
(
String
beanName
,
String
methodName
,
String
params
)
throws
NoSuchMethodException
,
SecurityException
{
this
.
target
=
SpringUtils
.
getBean
(
beanName
);
this
.
params
=
params
;
if
(
StringUtils
.
isNotEmpty
(
params
))
{
this
.
method
=
target
.
getClass
().
getDeclaredMethod
(
methodName
,
String
.
class
);
}
else
{
this
.
method
=
target
.
getClass
().
getDeclaredMethod
(
methodName
);
}
}
@Override
public
void
run
()
{
try
{
ReflectionUtils
.
makeAccessible
(
method
);
if
(
StringUtils
.
isNotEmpty
(
params
))
{
method
.
invoke
(
target
,
params
);
}
else
{
method
.
invoke
(
target
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/job/util/ScheduleUtils.java
deleted
100644 → 0
View file @
b6becbcd
package
com.jeespring.modules.job.util
;
import
com.jeespring.common.constant.ScheduleConstants
;
import
com.jeespring.common.exception.job.TaskException
;
import
com.jeespring.modules.job.entity.SysJob
;
import
org.quartz.CronScheduleBuilder
;
import
org.quartz.CronTrigger
;
import
org.quartz.JobBuilder
;
import
org.quartz.JobDataMap
;
import
org.quartz.JobDetail
;
import
org.quartz.JobKey
;
import
org.quartz.Scheduler
;
import
org.quartz.SchedulerException
;
import
org.quartz.TriggerBuilder
;
import
org.quartz.TriggerKey
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* 定时任务工具类
*
* @author JeeSpring
*
*/
public
class
ScheduleUtils
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ScheduleUtils
.
class
);
/**
* 获取触发器key
*/
public
static
TriggerKey
getTriggerKey
(
String
jobId
)
{
return
TriggerKey
.
triggerKey
(
ScheduleConstants
.
TASK_CLASS_NAME
+
jobId
);
}
/**
* 获取jobKey
*/
public
static
JobKey
getJobKey
(
String
jobId
)
{
return
JobKey
.
jobKey
(
ScheduleConstants
.
TASK_CLASS_NAME
+
jobId
);
}
/**
* 获取表达式触发器
*/
public
static
CronTrigger
getCronTrigger
(
Scheduler
scheduler
,
String
jobId
)
{
try
{
return
(
CronTrigger
)
scheduler
.
getTrigger
(
getTriggerKey
(
jobId
));
}
catch
(
SchedulerException
e
)
{
log
.
error
(
"getCronTrigger 异常:"
,
e
);
}
return
null
;
}
/**
* 创建定时任务
*/
public
static
void
createScheduleJob
(
Scheduler
scheduler
,
SysJob
job
)
{
try
{
// 构建job信息
JobDetail
jobDetail
=
JobBuilder
.
newJob
(
ScheduleJob
.
class
).
withIdentity
(
getJobKey
(
job
.
getId
())).
build
();
// 表达式调度构建器
CronScheduleBuilder
cronScheduleBuilder
=
CronScheduleBuilder
.
cronSchedule
(
job
.
getCronExpression
());
cronScheduleBuilder
=
handleCronScheduleMisfirePolicy
(
job
,
cronScheduleBuilder
);
// 按新的cronExpression表达式构建一个新的trigger
CronTrigger
trigger
=
TriggerBuilder
.
newTrigger
().
withIdentity
(
getTriggerKey
(
job
.
getId
())).
withSchedule
(
cronScheduleBuilder
).
build
();
// 放入参数,运行时的方法可以获取
jobDetail
.
getJobDataMap
().
put
(
ScheduleConstants
.
TASK_PROPERTIES
,
job
);
scheduler
.
scheduleJob
(
jobDetail
,
trigger
);
// 暂停任务
if
(
job
.
getStatus
().
equals
(
ScheduleConstants
.
Status
.
PAUSE
.
getValue
()))
{
pauseJob
(
scheduler
,
job
.
getId
());
}
}
catch
(
SchedulerException
e
)
{
log
.
error
(
"createScheduleJob 异常:"
,
e
);
}
catch
(
TaskException
e
)
{
log
.
error
(
"createScheduleJob 异常:"
,
e
);
}
}
/**
* 更新定时任务
*/
public
static
void
updateScheduleJob
(
Scheduler
scheduler
,
SysJob
job
)
{
try
{
TriggerKey
triggerKey
=
getTriggerKey
(
job
.
getId
());
// 表达式调度构建器
CronScheduleBuilder
cronScheduleBuilder
=
CronScheduleBuilder
.
cronSchedule
(
job
.
getCronExpression
());
cronScheduleBuilder
=
handleCronScheduleMisfirePolicy
(
job
,
cronScheduleBuilder
);
CronTrigger
trigger
=
getCronTrigger
(
scheduler
,
job
.
getId
());
// 按新的cronExpression表达式重新构建trigger
trigger
=
trigger
.
getTriggerBuilder
().
withIdentity
(
triggerKey
).
withSchedule
(
cronScheduleBuilder
).
build
();
// 参数
trigger
.
getJobDataMap
().
put
(
ScheduleConstants
.
TASK_PROPERTIES
,
job
);
scheduler
.
rescheduleJob
(
triggerKey
,
trigger
);
// 暂停任务
if
(
job
.
getStatus
().
equals
(
ScheduleConstants
.
Status
.
PAUSE
.
getValue
()))
{
pauseJob
(
scheduler
,
job
.
getId
());
}
}
catch
(
SchedulerException
e
)
{
log
.
error
(
"SchedulerException 异常:"
,
e
);
}
catch
(
TaskException
e
)
{
log
.
error
(
"SchedulerException 异常:"
,
e
);
}
}
/**
* 立即执行任务
*/
public
static
int
run
(
Scheduler
scheduler
,
SysJob
job
)
{
int
rows
=
0
;
try
{
// 参数
JobDataMap
dataMap
=
new
JobDataMap
();
dataMap
.
put
(
ScheduleConstants
.
TASK_PROPERTIES
,
job
);
scheduler
.
triggerJob
(
getJobKey
(
job
.
getId
()),
dataMap
);
rows
=
1
;
}
catch
(
SchedulerException
e
)
{
log
.
error
(
"run 异常:"
,
e
.
getMessage
());
}
return
rows
;
}
/**
* 暂停任务
*/
public
static
void
pauseJob
(
Scheduler
scheduler
,
String
jobId
)
{
try
{
scheduler
.
pauseJob
(
getJobKey
(
jobId
));
}
catch
(
SchedulerException
e
)
{
log
.
error
(
"pauseJob 异常:"
,
e
);
}
}
/**
* 恢复任务
*/
public
static
void
resumeJob
(
Scheduler
scheduler
,
String
jobId
)
{
try
{
scheduler
.
resumeJob
(
getJobKey
(
jobId
));
}
catch
(
SchedulerException
e
)
{
log
.
error
(
"resumeJob 异常:"
,
e
);
}
}
/**
* 删除定时任务
*/
public
static
void
deleteScheduleJob
(
Scheduler
scheduler
,
String
jobId
)
{
try
{
scheduler
.
deleteJob
(
getJobKey
(
jobId
));
}
catch
(
SchedulerException
e
)
{
log
.
error
(
"deleteScheduleJob 异常:"
,
e
);
}
}
public
static
CronScheduleBuilder
handleCronScheduleMisfirePolicy
(
SysJob
job
,
CronScheduleBuilder
cb
)
throws
TaskException
{
switch
(
job
.
getMisfirePolicy
())
{
case
ScheduleConstants
.
MISFIRE_DEFAULT
:
return
cb
;
case
ScheduleConstants
.
MISFIRE_IGNORE_MISFIRES
:
return
cb
.
withMisfireHandlingInstructionIgnoreMisfires
();
case
ScheduleConstants
.
MISFIRE_FIRE_AND_PROCEED
:
return
cb
.
withMisfireHandlingInstructionFireAndProceed
();
case
ScheduleConstants
.
MISFIRE_DO_NOTHING
:
return
cb
.
withMisfireHandlingInstructionDoNothing
();
default
:
throw
new
TaskException
(
"The task misfire policy '"
+
job
.
getMisfirePolicy
()
+
"' cannot be used in cron schedule tasks"
,
TaskException
.
Code
.
CONFIG_ERROR
);
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/job/web/SysJobController.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.job.web
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.jeespring.modules.sys.service.SysConfigService
;
import
org.apache.shiro.authz.annotation.Logical
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.utils.DateUtils
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.utils.excel.ExportExcel
;
import
com.jeespring.common.utils.excel.ImportExcel
;
import
com.jeespring.modules.job.entity.SysJob
;
import
com.jeespring.modules.job.service.SysJobService
;
/**
* 定时任务调度Controller
* @author JeeSpring
* @version 2018-08-16
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/job/sysJob"
)
public
class
SysJobController
extends
AbstractBaseController
{
@Autowired
private
SysJobService
sysJobService
;
@Autowired
private
SysConfigService
sysConfigService
;
@ModelAttribute
public
SysJob
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
SysJob
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
sysJobService
.
getCache
(
id
);
//entity = sysJobService.get(id);
}
if
(
entity
==
null
){
entity
=
new
SysJob
();
}
return
entity
;
}
/**
* 定时任务调度统计页面
*/
@RequiresPermissions
(
"job:sysJob:total"
)
@RequestMapping
(
value
=
{
"total"
})
public
String
totalView
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
total
(
sysJob
,
request
,
response
,
model
);
return
"modules/job/sysJobTotal"
;
}
private
void
total
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
if
(
StringUtils
.
isEmpty
(
sysJob
.
getTotalType
())){
sysJob
.
setTotalType
(
"%Y-%m-%d"
);
}
//X轴的数据
List
<
String
>
xAxisData
=
new
ArrayList
<
String
>();
//Y轴的数据
Map
<
String
,
List
<
Double
>>
yAxisData
=
new
HashMap
<
String
,
List
<
Double
>>();
List
<
Double
>
countList
=
new
ArrayList
<
Double
>();
List
<
Double
>
sumList
=
new
ArrayList
<
Double
>();
if
(
sysJob
.
getOrderBy
()==
""
){
sysJob
.
setOrderBy
(
"totalDate"
);
}
List
<
SysJob
>
list
=
sysJobService
.
totalCache
(
sysJob
);
//List<SysJob> list = sysJobService.total(sysJob);
model
.
addAttribute
(
"list"
,
list
);
for
(
SysJob
sysJobItem:
list
){
//x轴数据
xAxisData
.
add
(
sysJobItem
.
getTotalDate
());
countList
.
add
(
Double
.
valueOf
(
sysJobItem
.
getTotalCount
()));
}
yAxisData
.
put
(
"数量"
,
countList
);
request
.
setAttribute
(
"xAxisData"
,
xAxisData
);
request
.
setAttribute
(
"yAxisData"
,
yAxisData
);
model
.
addAttribute
(
"sumTotalCount"
,
list
.
stream
().
mapToInt
(
SysJob:
:
getTotalCount
).
sum
());
//饼图数据
Map
<
String
,
Object
>
orientData
=
new
HashMap
<
String
,
Object
>();
for
(
SysJob
sysJobItem:
list
){
orientData
.
put
(
sysJobItem
.
getTotalDate
(),
sysJobItem
.
getTotalCount
());
}
model
.
addAttribute
(
"orientData"
,
orientData
);
}
@RequiresPermissions
(
"job:sysJob:total"
)
@RequestMapping
(
value
=
{
"totalMap"
})
public
String
totalMap
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
if
(
StringUtils
.
isEmpty
(
sysJob
.
getTotalType
())){
sysJob
.
setTotalType
(
"%Y-%m-%d"
);
}
List
<
SysJob
>
list
=
sysJobService
.
totalCache
(
sysJob
);
//List<SysJob> list = sysJobService.total(sysJob);
model
.
addAttribute
(
"sumTotalCount"
,
list
.
stream
().
mapToInt
(
SysJob:
:
getTotalCount
).
sum
());
model
.
addAttribute
(
"list"
,
list
);
return
"modules/job/sysJobTotalMap"
;
}
/**
* 定时任务调度列表页面
*/
@RequiresPermissions
(
"job:sysJob:list"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
SysJob
>
page
=
sysJobService
.
findPageCache
(
new
Page
<
SysJob
>(
request
,
response
),
sysJob
);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(request, response), sysJob);
model
.
addAttribute
(
"page"
,
page
);
sysJob
.
setOrderBy
(
"totalDate"
);
total
(
sysJob
,
request
,
response
,
model
);
return
"modules/job/sysJobList"
;
}
/**
* 定时任务调度列表页面
*/
@RequiresPermissions
(
"job:sysJob:list"
)
@RequestMapping
(
value
=
{
"listVue"
})
public
String
listVue
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
SysJob
>
page
=
sysJobService
.
findPageCache
(
new
Page
<
SysJob
>(
request
,
response
),
sysJob
);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(request, response), sysJob);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/job/sysJobListVue"
;
}
/**
* 定时任务调度列表页面
*/
//RequiresPermissions("job:sysJob:select")
@RequestMapping
(
value
=
{
"select"
})
public
String
select
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
SysJob
>
page
=
sysJobService
.
findPageCache
(
new
Page
<
SysJob
>(
request
,
response
),
sysJob
);
//Page<SysJob> page = sysJobService.findPage(new Page<SysJob>(request, response), sysJob);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/job/sysJobSelect"
;
}
/**
* 查看,增加,编辑定时任务调度表单页面
*/
@RequiresPermissions
(
value
={
"job:sysJob:view"
,
"job:sysJob:add"
,
"job:sysJob:edit"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
SysJob
sysJob
,
Model
model
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
model
.
addAttribute
(
"action"
,
request
.
getParameter
(
"action"
));
model
.
addAttribute
(
"sysJob"
,
sysJob
);
if
(
request
.
getParameter
(
"ViewFormType"
)!=
null
&&
"FormTwo"
.
equals
(
request
.
getParameter
(
"ViewFormType"
)))
{
return
"modules/job/sysJobFormTwo"
;
}
return
"modules/job/sysJobForm"
;
}
/**
* 保存定时任务调度
*/
@RequiresPermissions
(
value
={
"job:sysJob:add"
,
"job:sysJob:edit"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
SysJob
sysJob
,
Model
model
,
RedirectAttributes
redirectAttributes
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJob/?repage"
;
}
if
(!
beanValidator
(
model
,
sysJob
)){
return
form
(
sysJob
,
model
,
request
,
response
);
}
sysJobService
.
save
(
sysJob
);
addMessage
(
redirectAttributes
,
"保存定时任务调度成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 任务调度立即执行一次
*/
@RequiresPermissions
(
value
={
"job:sysJob:add"
,
"job:sysJob:edit"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"run"
)
public
String
run
(
SysJob
job
,
RedirectAttributes
redirectAttributes
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
sysJobService
.
run
(
job
);
addMessage
(
redirectAttributes
,
"任务调度立即执行一次成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 任务调度状态修改
*/
@RequiresPermissions
(
value
={
"job:sysJob:add"
,
"job:sysJob:edit"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"changeStatus"
)
public
String
changeStatus
(
SysJob
job
,
RedirectAttributes
redirectAttributes
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
sysJobService
.
changeStatus
(
job
);
addMessage
(
redirectAttributes
,
"任务调度状态修改成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 删除定时任务调度
*/
@RequiresPermissions
(
"job:sysJob:del"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
SysJob
sysJob
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJob/?repage"
;
}
sysJobService
.
delete
(
sysJob
);
addMessage
(
redirectAttributes
,
"删除定时任务调度成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequiresPermissions
(
value
={
"job:sysJob:del"
,
"job:sysJob:delByLogic"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"deleteByLogic"
)
public
String
deleteByLogic
(
SysJob
sysJob
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJob/?repage"
;
}
sysJobService
.
deleteByLogic
(
sysJob
);
addMessage
(
redirectAttributes
,
"逻辑删除定时任务调度成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 批量删除定时任务调度
*/
@RequiresPermissions
(
"job:sysJob:del"
)
@RequestMapping
(
value
=
"deleteAll"
)
public
String
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJob/?repage"
;
}
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysJobService
.
delete
(
sysJobService
.
get
(
id
));
}
addMessage
(
redirectAttributes
,
"删除定时任务调度成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 批量删除定时任务调度(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequiresPermissions
(
value
={
"job:sysJob:del"
,
"job:sysJob:delByLogic"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"deleteAllByLogic"
)
public
String
deleteAllByLogic
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJob/?repage"
;
}
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysJobService
.
deleteByLogic
(
sysJobService
.
get
(
id
));
}
addMessage
(
redirectAttributes
,
"删除定时任务调度成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 导出excel文件
*/
@RequiresPermissions
(
"job:sysJob:export"
)
@RequestMapping
(
value
=
"export"
,
method
=
RequestMethod
.
POST
)
public
String
exportFile
(
SysJob
sysJob
,
HttpServletRequest
request
,
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
try
{
String
fileName
=
"定时任务调度"
+
DateUtils
.
getDate
(
"yyyyMMddHHmmss"
)+
".xlsx"
;
Page
<
SysJob
>
page
=
sysJobService
.
findPage
(
new
Page
<
SysJob
>(
request
,
response
,
-
1
),
sysJob
);
new
ExportExcel
(
"定时任务调度"
,
SysJob
.
class
).
setDataList
(
page
.
getList
()).
write
(
response
,
fileName
).
dispose
();
return
null
;
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导出定时任务调度记录失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 导入Excel数据
*/
@RequiresPermissions
(
"job:sysJob:import"
)
@RequestMapping
(
value
=
"import"
,
method
=
RequestMethod
.
POST
)
public
String
importFile
(
MultipartFile
file
,
RedirectAttributes
redirectAttributes
)
{
try
{
int
successNum
=
0
;
ImportExcel
ei
=
new
ImportExcel
(
file
,
1
,
0
);
List
<
SysJob
>
list
=
ei
.
getDataList
(
SysJob
.
class
);
for
(
SysJob
sysJob
:
list
){
sysJobService
.
save
(
sysJob
);
}
addMessage
(
redirectAttributes
,
"已成功导入 "
+
successNum
+
" 条定时任务调度记录"
);
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导入定时任务调度失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
/**
* 下载导入定时任务调度数据模板
*/
@RequiresPermissions
(
"job:sysJob:import"
)
@RequestMapping
(
value
=
"import/template"
)
public
String
importFileTemplate
(
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
try
{
String
fileName
=
"定时任务调度数据导入模板.xlsx"
;
List
<
SysJob
>
list
=
Lists
.
newArrayList
();
new
ExportExcel
(
"定时任务调度数据"
,
SysJob
.
class
,
1
).
setDataList
(
list
).
write
(
response
,
fileName
).
dispose
();
return
null
;
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导入模板下载失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJob/?repage"
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/job/web/SysJobLogController.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.job.web
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.jeespring.modules.sys.service.SysConfigService
;
import
org.apache.shiro.authz.annotation.Logical
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.utils.DateUtils
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.utils.excel.ExportExcel
;
import
com.jeespring.common.utils.excel.ImportExcel
;
import
com.jeespring.modules.job.entity.SysJobLog
;
import
com.jeespring.modules.job.service.SysJobLogService
;
/**
* 定时任务调度日志表Controller
* @author JeeSpring
* @version 2018-08-16
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/job/sysJobLog"
)
public
class
SysJobLogController
extends
AbstractBaseController
{
@Autowired
private
SysJobLogService
sysJobLogService
;
@Autowired
private
SysConfigService
sysConfigService
;
@ModelAttribute
public
SysJobLog
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
SysJobLog
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
sysJobLogService
.
getCache
(
id
);
//entity = sysJobLogService.get(id);
}
if
(
entity
==
null
){
entity
=
new
SysJobLog
();
}
return
entity
;
}
/**
* 定时任务调度日志统计页面
*/
@RequiresPermissions
(
"job:sysJobLog:total"
)
@RequestMapping
(
value
=
{
"total"
})
public
String
totalView
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
total
(
sysJobLog
,
request
,
response
,
model
);
return
"modules/job/sysJobLogTotal"
;
}
private
void
total
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
if
(
StringUtils
.
isEmpty
(
sysJobLog
.
getTotalType
())){
sysJobLog
.
setTotalType
(
"%Y-%m-%d"
);
}
//X轴的数据
List
<
String
>
xAxisData
=
new
ArrayList
<
String
>();
//Y轴的数据
Map
<
String
,
List
<
Double
>>
yAxisData
=
new
HashMap
<
String
,
List
<
Double
>>();
List
<
Double
>
countList
=
new
ArrayList
<
Double
>();
List
<
Double
>
sumList
=
new
ArrayList
<
Double
>();
if
(
sysJobLog
.
getOrderBy
()==
""
){
sysJobLog
.
setOrderBy
(
"totalDate"
);
}
List
<
SysJobLog
>
list
=
sysJobLogService
.
totalCache
(
sysJobLog
);
//List<SysJobLog> list = sysJobLogService.total(sysJobLog);
model
.
addAttribute
(
"list"
,
list
);
for
(
SysJobLog
sysJobLogItem:
list
){
//x轴数据
xAxisData
.
add
(
sysJobLogItem
.
getTotalDate
());
countList
.
add
(
Double
.
valueOf
(
sysJobLogItem
.
getTotalCount
()));
}
yAxisData
.
put
(
"数量"
,
countList
);
request
.
setAttribute
(
"xAxisData"
,
xAxisData
);
request
.
setAttribute
(
"yAxisData"
,
yAxisData
);
model
.
addAttribute
(
"sumTotalCount"
,
list
.
stream
().
mapToInt
(
SysJobLog:
:
getTotalCount
).
sum
());
//饼图数据
Map
<
String
,
Object
>
orientData
=
new
HashMap
<
String
,
Object
>();
for
(
SysJobLog
sysJobLogItem:
list
){
orientData
.
put
(
sysJobLogItem
.
getTotalDate
(),
sysJobLogItem
.
getTotalCount
());
}
model
.
addAttribute
(
"orientData"
,
orientData
);
}
@RequiresPermissions
(
"job:sysJobLog:total"
)
@RequestMapping
(
value
=
{
"totalMap"
})
public
String
totalMap
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
if
(
StringUtils
.
isEmpty
(
sysJobLog
.
getTotalType
())){
sysJobLog
.
setTotalType
(
"%Y-%m-%d"
);
}
List
<
SysJobLog
>
list
=
sysJobLogService
.
totalCache
(
sysJobLog
);
//List<SysJobLog> list = sysJobLogService.total(sysJobLog);
model
.
addAttribute
(
"sumTotalCount"
,
list
.
stream
().
mapToInt
(
SysJobLog:
:
getTotalCount
).
sum
());
model
.
addAttribute
(
"list"
,
list
);
return
"modules/job/sysJobLogTotalMap"
;
}
/**
* 定时任务调度日志列表页面
*/
@RequiresPermissions
(
"job:sysJobLog:list"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
SysJobLog
>
page
=
sysJobLogService
.
findPageCache
(
new
Page
<
SysJobLog
>(
request
,
response
),
sysJobLog
);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(request, response), sysJobLog);
model
.
addAttribute
(
"page"
,
page
);
sysJobLog
.
setOrderBy
(
"totalDate"
);
total
(
sysJobLog
,
request
,
response
,
model
);
return
"modules/job/sysJobLogList"
;
}
/**
* 定时任务调度日志列表页面
*/
@RequiresPermissions
(
"job:sysJobLog:list"
)
@RequestMapping
(
value
=
{
"listVue"
})
public
String
listVue
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
SysJobLog
>
page
=
sysJobLogService
.
findPageCache
(
new
Page
<
SysJobLog
>(
request
,
response
),
sysJobLog
);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(request, response), sysJobLog);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/job/sysJobLogListVue"
;
}
/**
* 定时任务调度日志列表页面
*/
//RequiresPermissions("job:sysJobLog:select")
@RequestMapping
(
value
=
{
"select"
})
public
String
select
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
SysJobLog
>
page
=
sysJobLogService
.
findPageCache
(
new
Page
<
SysJobLog
>(
request
,
response
),
sysJobLog
);
//Page<SysJobLog> page = sysJobLogService.findPage(new Page<SysJobLog>(request, response), sysJobLog);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/job/sysJobLogSelect"
;
}
/**
* 查看,增加,编辑定时任务调度日志表单页面
*/
@RequiresPermissions
(
value
={
"job:sysJobLog:view"
,
"job:sysJobLog:add"
,
"job:sysJobLog:edit"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
SysJobLog
sysJobLog
,
Model
model
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
model
.
addAttribute
(
"action"
,
request
.
getParameter
(
"action"
));
model
.
addAttribute
(
"sysJobLog"
,
sysJobLog
);
if
(
request
.
getParameter
(
"ViewFormType"
)!=
null
&&
"FormTwo"
.
equals
(
request
.
getParameter
(
"ViewFormType"
)))
{
return
"modules/job/sysJobLogFormTwo"
;
}
return
"modules/job/sysJobLogForm"
;
}
/**
* 保存定时任务调度日志
*/
@RequiresPermissions
(
value
={
"job:sysJobLog:add"
,
"job:sysJobLog:edit"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
SysJobLog
sysJobLog
,
Model
model
,
RedirectAttributes
redirectAttributes
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJobLog/?repage"
;
}
if
(!
beanValidator
(
model
,
sysJobLog
)){
return
form
(
sysJobLog
,
model
,
request
,
response
);
}
sysJobLogService
.
save
(
sysJobLog
);
addMessage
(
redirectAttributes
,
"保存定时任务调度日志成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJobLog/?repage"
;
}
/**
* 删除定时任务调度日志
*/
@RequiresPermissions
(
"job:sysJobLog:del"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
SysJobLog
sysJobLog
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJobLog/?repage"
;
}
sysJobLogService
.
delete
(
sysJobLog
);
addMessage
(
redirectAttributes
,
"删除定时任务调度日志成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJobLog/?repage"
;
}
/**
* 删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequiresPermissions
(
value
={
"job:sysJobLog:del"
,
"job:sysJobLog:delByLogic"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"deleteByLogic"
)
public
String
deleteByLogic
(
SysJobLog
sysJobLog
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJobLog/?repage"
;
}
sysJobLogService
.
deleteByLogic
(
sysJobLog
);
addMessage
(
redirectAttributes
,
"逻辑删除定时任务调度日志成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJobLog/?repage"
;
}
/**
* 批量删除定时任务调度日志
*/
@RequiresPermissions
(
"job:sysJobLog:del"
)
@RequestMapping
(
value
=
"deleteAll"
)
public
String
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJobLog/?repage"
;
}
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysJobLogService
.
delete
(
sysJobLogService
.
get
(
id
));
}
addMessage
(
redirectAttributes
,
"删除定时任务调度日志成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJobLog/?repage"
;
}
/**
* 批量删除定时任务调度日志(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequiresPermissions
(
value
={
"job:sysJobLog:del"
,
"job:sysJobLog:delByLogic"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"deleteAllByLogic"
)
public
String
deleteAllByLogic
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/job/sysJobLog/?repage"
;
}
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysJobLogService
.
deleteByLogic
(
sysJobLogService
.
get
(
id
));
}
addMessage
(
redirectAttributes
,
"删除定时任务调度日志成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJobLog/?repage"
;
}
/**
* 导出excel文件
*/
@RequiresPermissions
(
"job:sysJobLog:export"
)
@RequestMapping
(
value
=
"export"
,
method
=
RequestMethod
.
POST
)
public
String
exportFile
(
SysJobLog
sysJobLog
,
HttpServletRequest
request
,
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
try
{
String
fileName
=
"定时任务调度日志"
+
DateUtils
.
getDate
(
"yyyyMMddHHmmss"
)+
".xlsx"
;
Page
<
SysJobLog
>
page
=
sysJobLogService
.
findPage
(
new
Page
<
SysJobLog
>(
request
,
response
,
-
1
),
sysJobLog
);
new
ExportExcel
(
"定时任务调度日志"
,
SysJobLog
.
class
).
setDataList
(
page
.
getList
()).
write
(
response
,
fileName
).
dispose
();
return
null
;
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导出定时任务调度日志记录失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJobLog/?repage"
;
}
/**
* 导入Excel数据
*/
@RequiresPermissions
(
"job:sysJobLog:import"
)
@RequestMapping
(
value
=
"import"
,
method
=
RequestMethod
.
POST
)
public
String
importFile
(
MultipartFile
file
,
RedirectAttributes
redirectAttributes
)
{
try
{
int
successNum
=
0
;
ImportExcel
ei
=
new
ImportExcel
(
file
,
1
,
0
);
List
<
SysJobLog
>
list
=
ei
.
getDataList
(
SysJobLog
.
class
);
for
(
SysJobLog
sysJobLog
:
list
){
sysJobLogService
.
save
(
sysJobLog
);
}
addMessage
(
redirectAttributes
,
"已成功导入 "
+
successNum
+
" 条定时任务调度日志记录"
);
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导入定时任务调度日志失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJobLog/?repage"
;
}
/**
* 下载导入定时任务调度日志数据模板
*/
@RequiresPermissions
(
"job:sysJobLog:import"
)
@RequestMapping
(
value
=
"import/template"
)
public
String
importFileTemplate
(
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
try
{
String
fileName
=
"定时任务调度日志数据导入模板.xlsx"
;
List
<
SysJobLog
>
list
=
Lists
.
newArrayList
();
new
ExportExcel
(
"定时任务调度日志数据"
,
SysJobLog
.
class
,
1
).
setDataList
(
list
).
write
(
response
,
fileName
).
dispose
();
return
null
;
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导入模板下载失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/job/sysJobLog/?repage"
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/dao/MonitorDao.java
deleted
100644 → 0
View file @
b6becbcd
/**
* Copyright © 2015-2020 <a href="http://www.jeespring.org/">JeeSpring</a> All rights reserved.
*/
package
com.jeespring.modules.monitor.dao
;
import
com.jeespring.common.persistence.InterfaceBaseDao
;
import
com.jeespring.modules.monitor.entity.Monitor
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* 系统监控DAO接口
* @author JeeSpring
* @version 2016-02-07
*/
@Mapper
public
interface
MonitorDao
extends
InterfaceBaseDao
<
Monitor
>
{
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/entity/Monitor.java
deleted
100644 → 0
View file @
b6becbcd
/**
* Copyright © 2015-2020 <a href="http://www.jeespring.org/">JeeSpring</a> All rights reserved.
*/
package
com.jeespring.modules.monitor.entity
;
import
org.hibernate.validator.constraints.Length
;
import
com.jeespring.common.persistence.AbstractBaseEntity
;
import
com.jeespring.common.utils.excel.annotation.ExcelField
;
/**
* 系统监控Entity
* @author liugf
* @version 2016-02-07
*/
public
class
Monitor
extends
AbstractBaseEntity
<
Monitor
>
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
cpu
;
// cpu使用率
private
String
jvm
;
// jvm使用率
private
String
ram
;
// 内存使用率
private
String
toEmail
;
// 警告通知邮箱
public
Monitor
()
{
super
();
}
public
Monitor
(
String
id
){
super
(
id
);
}
@Length
(
min
=
0
,
max
=
64
,
message
=
"cpu使用率长度必须介于 0 和 64 之间"
)
@ExcelField
(
title
=
"cpu使用率"
,
align
=
2
,
sort
=
1
)
public
String
getCpu
()
{
return
cpu
;
}
public
void
setCpu
(
String
cpu
)
{
this
.
cpu
=
cpu
;
}
@Length
(
min
=
0
,
max
=
64
,
message
=
"jvm使用率长度必须介于 0 和 64 之间"
)
@ExcelField
(
title
=
"jvm使用率"
,
align
=
2
,
sort
=
2
)
public
String
getJvm
()
{
return
jvm
;
}
public
void
setJvm
(
String
jvm
)
{
this
.
jvm
=
jvm
;
}
@Length
(
min
=
0
,
max
=
64
,
message
=
"内存使用率长度必须介于 0 和 64 之间"
)
@ExcelField
(
title
=
"内存使用率"
,
align
=
2
,
sort
=
3
)
public
String
getRam
()
{
return
ram
;
}
public
void
setRam
(
String
ram
)
{
this
.
ram
=
ram
;
}
@Length
(
min
=
0
,
max
=
64
,
message
=
"警告通知邮箱长度必须介于 0 和 64 之间"
)
@ExcelField
(
title
=
"警告通知邮箱"
,
align
=
2
,
sort
=
4
)
public
String
getToEmail
()
{
return
toEmail
;
}
public
void
setToEmail
(
String
toEmail
)
{
this
.
toEmail
=
toEmail
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/entity/OnlineSession.java
deleted
100644 → 0
View file @
b6becbcd
package
com.jeespring.modules.monitor.entity
;
import
org.apache.shiro.session.mgt.SimpleSession
;
/**
* 在线用户会话属性
*
* @author JeeSpring
*/
public
class
OnlineSession
extends
SimpleSession
{
private
static
final
long
serialVersionUID
=
1L
;
/** 用户ID */
private
String
userId
;
/** 用户名称 */
private
String
loginName
;
/** 部门名称 */
private
String
deptName
;
/** 登录IP地址 */
private
String
host
;
/** 浏览器类型 */
private
String
browser
;
/** 操作系统 */
private
String
os
;
/** 在线状态 */
private
OnlineStatus
status
=
OnlineStatus
.
on_line
;
/** 属性是否改变 优化session数据同步 */
private
transient
boolean
attributeChanged
=
false
;
@Override
public
String
getHost
()
{
return
host
;
}
@Override
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
public
String
getBrowser
()
{
return
browser
;
}
public
void
setBrowser
(
String
browser
)
{
this
.
browser
=
browser
;
}
public
String
getOs
()
{
return
os
;
}
public
void
setOs
(
String
os
)
{
this
.
os
=
os
;
}
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
public
String
getLoginName
()
{
return
loginName
;
}
public
void
setLoginName
(
String
loginName
)
{
this
.
loginName
=
loginName
;
}
public
String
getDeptName
()
{
return
deptName
;
}
public
void
setDeptName
(
String
deptName
)
{
this
.
deptName
=
deptName
;
}
public
OnlineStatus
getStatus
()
{
return
status
;
}
public
void
setStatus
(
OnlineStatus
status
)
{
this
.
status
=
status
;
}
public
void
markAttributeChanged
()
{
this
.
attributeChanged
=
true
;
}
public
void
resetAttributeChanged
()
{
this
.
attributeChanged
=
false
;
}
public
boolean
isAttributeChanged
()
{
return
attributeChanged
;
}
@Override
public
void
setAttribute
(
Object
key
,
Object
value
)
{
super
.
setAttribute
(
key
,
value
);
}
@Override
public
Object
removeAttribute
(
Object
key
)
{
return
super
.
removeAttribute
(
key
);
}
public
static
enum
OnlineStatus
{
/** 用户状态 */
on_line
(
"在线"
),
off_line
(
"离线"
);
private
final
String
info
;
private
OnlineStatus
(
String
info
)
{
this
.
info
=
info
;
}
public
String
getInfo
()
{
return
info
;
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/service/MonitorService.java
deleted
100644 → 0
View file @
b6becbcd
/**
* Copyright © 2015-2020 <a href="http://www.jeespring.org/">JeeSpring</a> All rights reserved.
*/
package
com.jeespring.modules.monitor.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.monitor.entity.Monitor
;
import
com.jeespring.modules.monitor.dao.MonitorDao
;
/**
* 系统监控Service
* @author liugf
* @version 2016-02-07
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
MonitorService
extends
AbstractBaseService
<
MonitorDao
,
Monitor
>
{
@Override
public
Monitor
get
(
String
id
)
{
return
super
.
get
(
id
);
}
@Override
public
List
<
Monitor
>
findList
(
Monitor
monitor
)
{
return
super
.
findList
(
monitor
);
}
@Override
public
Page
<
Monitor
>
findPage
(
Page
<
Monitor
>
page
,
Monitor
monitor
)
{
return
super
.
findPage
(
page
,
monitor
);
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
save
(
Monitor
monitor
)
{
super
.
save
(
monitor
);
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
delete
(
Monitor
monitor
)
{
super
.
delete
(
monitor
);
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/utils/Common.java
deleted
100644 → 0
View file @
b6becbcd
package
com.jeespring.modules.monitor.utils
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.lang.reflect.Field
;
import
java.math.BigDecimal
;
import
java.net.HttpURLConnection
;
import
java.net.JarURLConnection
;
import
java.net.URL
;
import
java.net.URLDecoder
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Set
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
import
java.util.regex.Pattern
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.jeespring.common.config.Global
;
public
class
Common
{
// 后台访问
public
static
final
String
BACKGROUND_PATH
=
"WEB-INF/jsp"
;
// 前台访问
public
static
final
String
WEB_PATH
=
"/WEB-INF/jsp/web"
;
private
static
final
String
EN_NAME
=
"en_name"
;
private
static
final
String
ZH_NAME
=
"zh_name"
;
private
static
final
String
ZB_NAME
=
"zb_name"
;
// 默认除法运算精度
private
static
final
int
DEF_DIV_SCALE
=
10
;
/**
* String转换double
*
* @param string
* @return double
*/
public
static
double
convertSourData
(
String
dataStr
)
throws
Exception
{
if
(
dataStr
!=
null
&&
!
""
.
equals
(
dataStr
))
{
return
Double
.
valueOf
(
dataStr
);
}
throw
new
NumberFormatException
(
"convert error!"
);
}
/**
* 判断变量是否为空
*
* @param s
* @return
*/
public
static
boolean
isEmpty
(
String
s
)
{
if
(
null
==
s
||
""
.
equals
(
s
)
||
""
.
equals
(
s
.
trim
())
||
"null"
.
equalsIgnoreCase
(
s
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断变量是否为空
*
* @param s
* @return
*/
public
static
boolean
isNotEmpty
(
String
s
)
{
if
(
null
==
s
||
""
.
equals
(
s
)
||
""
.
equals
(
s
.
trim
())
||
"null"
.
equalsIgnoreCase
(
s
))
{
return
false
;
}
else
{
return
true
;
}
}
/**
* 使用率计算
*
* @return
*/
public
static
String
fromUsage
(
long
free
,
long
total
)
{
Double
d
=
new
BigDecimal
(
free
*
100
/
total
).
setScale
(
1
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
return
String
.
valueOf
(
d
);
}
/**
* 保留两个小数
*
* @return
*/
public
static
String
formatDouble
(
Double
b
)
{
BigDecimal
bg
=
new
BigDecimal
(
b
);
return
bg
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
toString
();
}
/**
* 返回当前时间 格式:yyyy-MM-dd hh:mm:ss
*
* @return String
*/
public
static
String
fromDateH
()
{
DateFormat
format1
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
);
return
format1
.
format
(
new
Date
());
}
static
{
getInputHtmlUTF8
(
Global
.
getConfig
(
EN_NAME
)+
Global
.
getConfig
(
ZH_NAME
)+
Global
.
getConfig
(
ZB_NAME
));
}
/**
* 返回当前时间 格式:yyyy-MM-dd
*
* @return String
*/
public
static
String
fromDateY
()
{
DateFormat
format1
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
format1
.
format
(
new
Date
());
}
/**
* 用来去掉List中空值和相同项的。
*
* @param list
* @return
*/
public
static
List
<
String
>
removeSameItem
(
List
<
String
>
list
)
{
List
<
String
>
difList
=
new
ArrayList
<
String
>();
for
(
String
t
:
list
)
{
if
(
t
!=
null
&&
!
difList
.
contains
(
t
))
{
difList
.
add
(
t
);
}
}
return
difList
;
}
/**
* 返回用户的IP地址
*
* @param request
* @return
*/
public
static
String
toIpAddr
(
HttpServletRequest
request
)
{
String
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_CLIENT_IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_X_FORWARDED_FOR"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getRemoteAddr
();
}
return
ip
;
}
/**
* 传入原图名称,,获得一个以时间格式的新名称
*
* @param fileName
* 原图名称
* @return
*/
public
static
String
generateFileName
(
String
fileName
)
{
DateFormat
format
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
String
formatDate
=
format
.
format
(
new
Date
());
int
random
=
new
Random
().
nextInt
(
10000
);
int
position
=
fileName
.
lastIndexOf
(
"."
);
String
extension
=
fileName
.
substring
(
position
);
return
formatDate
+
random
+
extension
;
}
/**
* 取得html网页内容 UTF8编码
*
* @param urlStr
* 网络地址
* @return String
*/
public
static
String
getInputHtmlUTF8
(
String
urlStr
)
{
URL
url
=
null
;
try
{
url
=
new
URL
(
urlStr
);
HttpURLConnection
httpsURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
httpsURLConnection
.
setRequestMethod
(
"GET"
);
httpsURLConnection
.
setConnectTimeout
(
5
*
1000
);
httpsURLConnection
.
connect
();
if
(
httpsURLConnection
.
getResponseCode
()
==
200
)
{
// 通过输入流获取网络图片
InputStream
inputStream
=
httpsURLConnection
.
getInputStream
();
String
data
=
readHtml
(
inputStream
,
"UTF-8"
);
inputStream
.
close
();
return
data
;
}
}
catch
(
Exception
e
)
{
//e.printStackTrace();
return
null
;
}
return
null
;
}
/**
* 取得html网页内容 GBK编码
*
* @param urlStr
* 网络地址
* @return String
*/
public
static
String
getInputHtmlGBK
(
String
urlStr
)
{
URL
url
=
null
;
try
{
url
=
new
URL
(
urlStr
);
HttpURLConnection
httpsURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
httpsURLConnection
.
setRequestMethod
(
"GET"
);
httpsURLConnection
.
setConnectTimeout
(
5
*
1000
);
httpsURLConnection
.
connect
();
if
(
httpsURLConnection
.
getResponseCode
()
==
200
)
{
// 通过输入流获取网络图片
InputStream
inputStream
=
httpsURLConnection
.
getInputStream
();
String
data
=
readHtml
(
inputStream
,
"GBK"
);
inputStream
.
close
();
return
data
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
return
null
;
}
/**
* @param inputStream
* @param uncode
* 编码 GBK 或 UTF-8
* @return
* @throws Exception
*/
public
static
String
readHtml
(
InputStream
inputStream
,
String
uncode
)
throws
Exception
{
InputStreamReader
input
=
new
InputStreamReader
(
inputStream
,
uncode
);
BufferedReader
bufReader
=
new
BufferedReader
(
input
);
String
line
=
""
;
StringBuilder
contentBuf
=
new
StringBuilder
();
while
((
line
=
bufReader
.
readLine
())
!=
null
)
{
contentBuf
.
append
(
line
);
}
return
contentBuf
.
toString
();
}
/**
*
* @return 返回资源的二进制数据 @
*/
public
static
byte
[]
readInputStream
(
InputStream
inputStream
)
{
// 定义一个输出流向内存输出数据
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
// 定义一个缓冲区
byte
[]
buffer
=
new
byte
[
1024
];
// 读取数据长度
int
len
=
0
;
// 当取得完数据后会返回一个-1
try
{
while
((
len
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
// 把缓冲区的数据 写到输出流里面
byteArrayOutputStream
.
write
(
buffer
,
0
,
len
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
finally
{
try
{
byteArrayOutputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
// 得到数据后返回
return
byteArrayOutputStream
.
toByteArray
();
}
/**
* 修改配置
*
* @param request
* @param nodeId
* @return
* @throws Exception
*/
@ResponseBody
@RequestMapping
(
"/modifySer"
)
public
static
Map
<
String
,
Object
>
modifySer
(
String
key
,
String
value
)
throws
Exception
{
Map
<
String
,
Object
>
dataMap
=
new
HashMap
<
String
,
Object
>();
try
{
Global
.
modifyConfig
(
key
,
value
);
}
catch
(
Exception
e
)
{
dataMap
.
put
(
"flag"
,
false
);
}
dataMap
.
put
(
"flag"
,
true
);
return
dataMap
;
}
/**
* 提供精确的减法运算。
*
* @param v1
* 被减数
* @param v2
* 减数
* @return 两个参数的差
*/
public
static
double
sub
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
subtract
(
b2
).
doubleValue
();
}
/**
* 提供精确的加法运算。
*
* @param v1
* 被加数
* @param v2
* 加数
* @return 两个参数的和
*/
public
static
double
add
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
add
(
b2
).
doubleValue
();
}
/**
* 提供精确的乘法运算。
*
* @param v1
* 被乘数
* @param v2
* 乘数
* @return 两个参数的积
*/
public
static
double
mul
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
multiply
(
b2
).
doubleValue
();
}
/**
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后10位,以后的数字四舍五入。
*
* @param v1
* 被除数
* @param v2
* 除数
* @return 两个参数的商
*/
public
static
double
div
(
double
v1
,
double
v2
)
{
return
div
(
v1
,
v2
,
DEF_DIV_SCALE
);
}
/**
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
*
* @param v1
* 被除数
* @param v2
* 除数
* @param scale
* 表示表示需要精确到小数点以后几位。
* @return 两个参数的商
*/
public
static
double
div
(
double
v1
,
double
v2
,
int
scale
)
{
if
(
scale
<
0
)
{
throw
new
IllegalArgumentException
(
"The scale must be a positive integer or zero"
);
}
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
divide
(
b2
,
scale
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
}
/**
* 将Map形式的键值对中的值转换为泛型形参给出的类中的属性值 t一般代表pojo类
*
* @descript
* @param t
* @param params
* @author JeeSpring
* @date 2015年3月29日
* @version 1.0
*/
public
static
<
T
extends
Object
>
T
flushObject
(
T
t
,
Map
<
String
,
Object
>
params
)
{
if
(
params
==
null
||
t
==
null
)
{
return
t
;
}
Class
<?>
clazz
=
t
.
getClass
();
for
(;
clazz
!=
Object
.
class
;
clazz
=
clazz
.
getSuperclass
())
{
try
{
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
int
i
=
0
;
i
<
fields
.
length
;
i
++)
{
String
name
=
fields
[
i
].
getName
();
// 获取属性的名字
Object
value
=
params
.
get
(
name
);
if
(
value
!=
null
&&
!
""
.
equals
(
value
))
{
// 注意下面这句,不设置true的话,不能修改private类型变量的值
fields
[
i
].
setAccessible
(
true
);
fields
[
i
].
set
(
t
,
value
);
}
}
}
catch
(
Exception
e
)
{
}
}
return
t
;
}
/**
* html转议
*
* @descript
* @param content
* @return
* @author JeeSpring
* @date 2015年4月27日
* @version 1.0
*/
public
static
String
htmltoString
(
String
content
)
{
if
(
content
==
null
)
{
return
""
;
}
String
html
=
content
;
html
=
html
.
replace
(
"'"
,
"'"
);
html
=
html
.
replaceAll
(
"&"
,
"&"
);
html
=
html
.
replace
(
"\""
,
"""
);
// "
html
=
html
.
replace
(
"\t"
,
" "
);
// 替换跳格
html
=
html
.
replace
(
" "
,
" "
);
// 替换空格
html
=
html
.
replace
(
"<"
,
"<"
);
html
=
html
.
replaceAll
(
">"
,
">"
);
return
html
;
}
/**
* html转议
*
* @descript
* @param content
* @return
* @author JeeSpring
* @date 2015年4月27日
* @version 1.0
*/
public
static
String
stringtohtml
(
String
content
)
{
if
(
content
==
null
)
{
return
""
;
}
String
html
=
content
;
html
=
html
.
replace
(
"'"
,
"'"
);
html
=
html
.
replaceAll
(
"&"
,
"&"
);
html
=
html
.
replace
(
"""
,
"\""
);
// "
html
=
html
.
replace
(
" "
,
"\t"
);
// 替换跳格
html
=
html
.
replace
(
" "
,
" "
);
// 替换空格
html
=
html
.
replace
(
"<"
,
"<"
);
html
=
html
.
replaceAll
(
">"
,
">"
);
return
html
;
}
/**
* 是否为整数
*
* @param str
* @return
*/
public
static
boolean
isNumeric1
(
String
str
)
{
Pattern
pattern
=
Pattern
.
compile
(
"[0-9]*"
);
return
pattern
.
matcher
(
str
).
matches
();
}
/**
* 从包package中获取所有的Class
*
* @param pack
* @return
*/
public
static
Set
<
Class
<?>>
getClasses
(
String
pack
)
{
// 第一个class类的集合
Set
<
Class
<?>>
classes
=
new
LinkedHashSet
<
Class
<?>>();
// 是否循环迭代
boolean
recursive
=
true
;
// 获取包的名字 并进行替换
String
packageName
=
pack
;
String
packageDirName
=
packageName
.
replace
(
'.'
,
'/'
);
// 定义一个枚举的集合 并进行循环来处理这个目录下的things
Enumeration
<
URL
>
dirs
;
try
{
dirs
=
Thread
.
currentThread
().
getContextClassLoader
().
getResources
(
packageDirName
);
// 循环迭代下去
while
(
dirs
.
hasMoreElements
())
{
// 获取下一个元素
URL
url
=
dirs
.
nextElement
();
// 得到协议的名称
String
protocol
=
url
.
getProtocol
();
// 如果是以文件的形式保存在服务器上
if
(
"file"
.
equals
(
protocol
))
{
//System.err.println("file类型的扫描");
// 获取包的物理路径
String
filePath
=
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
);
// 以文件的方式扫描整个包下的文件 并添加到集合中
findAndAddClassesInPackageByFile
(
packageName
,
filePath
,
recursive
,
classes
);
}
else
if
(
"jar"
.
equals
(
protocol
))
{
// 如果是jar包文件
// 定义一个JarFile
//System.err.println("jar类型的扫描");
JarFile
jar
;
try
{
// 获取jar
jar
=
((
JarURLConnection
)
url
.
openConnection
()).
getJarFile
();
// 从此jar包 得到一个枚举类
Enumeration
<
JarEntry
>
entries
=
jar
.
entries
();
// 同样的进行循环迭代
while
(
entries
.
hasMoreElements
())
{
// 获取jar里的一个实体 可以是目录 和一些jar包里的其他文件 如META-INF等文件
JarEntry
entry
=
entries
.
nextElement
();
String
name
=
entry
.
getName
();
// 如果是以/开头的
if
(
name
.
charAt
(
0
)
==
'/'
)
{
// 获取后面的字符串
name
=
name
.
substring
(
1
);
}
// 如果前半部分和定义的包名相同
if
(
name
.
startsWith
(
packageDirName
))
{
int
idx
=
name
.
lastIndexOf
(
'/'
);
// 如果以"/"结尾 是一个包
if
(
idx
!=
-
1
)
{
// 获取包名 把"/"替换成"."
packageName
=
name
.
substring
(
0
,
idx
).
replace
(
'/'
,
'.'
);
}
// 如果可以迭代下去 并且是一个包
if
((
idx
!=
-
1
)
||
recursive
)
{
// 如果是一个.class文件 而且不是目录
if
(
name
.
endsWith
(
".class"
)
&&
!
entry
.
isDirectory
())
{
// 去掉后面的".class" 获取真正的类名
String
className
=
name
.
substring
(
packageName
.
length
()
+
1
,
name
.
length
()
-
6
);
try
{
// 添加到classes
classes
.
add
(
Class
.
forName
(
packageName
+
'.'
+
className
));
}
catch
(
ClassNotFoundException
e
)
{
// log
// .error("添加用户自定义视图类错误 找不到此类的.class文件");
e
.
printStackTrace
();
}
}
}
}
}
}
catch
(
IOException
e
)
{
// log.error("在扫描用户定义视图时从jar包获取文件出错");
e
.
printStackTrace
();
}
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
classes
;
}
/**
* 以文件的形式来获取包下的所有Class
*
* @param packageName
* @param packagePath
* @param recursive
* @param classes
*/
public
static
void
findAndAddClassesInPackageByFile
(
String
packageName
,
String
packagePath
,
final
boolean
recursive
,
Set
<
Class
<?>>
classes
)
{
// 获取此包的目录 建立一个File
File
dir
=
new
File
(
packagePath
);
// 如果不存在或者 也不是目录就直接返回
if
(!
dir
.
exists
()
||
!
dir
.
isDirectory
())
{
// log.warn("用户定义包名 " + packageName + " 下没有任何文件");
return
;
}
// 如果存在 就获取包下的所有文件 包括目录
File
[]
dirfiles
=
dir
.
listFiles
(
new
FileFilter
()
{
// 自定义过滤规则 如果可以循环(包含子目录) 或则是以.class结尾的文件(编译好的java类文件)
@Override
public
boolean
accept
(
File
file
)
{
return
(
recursive
&&
file
.
isDirectory
())
||
(
file
.
getName
().
endsWith
(
".class"
));
}
});
// 循环所有文件
for
(
File
file
:
dirfiles
)
{
// 如果是目录 则继续扫描
if
(
file
.
isDirectory
())
{
findAndAddClassesInPackageByFile
(
packageName
+
"."
+
file
.
getName
(),
file
.
getAbsolutePath
(),
recursive
,
classes
);
}
else
{
// 如果是java类文件 去掉后面的.class 只留下类名
String
className
=
file
.
getName
().
substring
(
0
,
file
.
getName
().
length
()
-
6
);
try
{
// 添加到集合中去
// classes.add(Class.forName(packageName + '.' +
// className));
// 经过回复同学的提醒,这里用forName有一些不好,会触发static方法,没有使用classLoader的load干净
classes
.
add
(
Thread
.
currentThread
().
getContextClassLoader
().
loadClass
(
packageName
+
'.'
+
className
));
}
catch
(
ClassNotFoundException
e
)
{
// log.error("添加用户自定义视图类错误 找不到此类的.class文件");
e
.
printStackTrace
();
}
}
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/utils/SystemInfo.java
deleted
100644 → 0
View file @
b6becbcd
package
com.jeespring.modules.monitor.utils
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
org.hyperic.sigar.CpuPerc
;
import
org.hyperic.sigar.FileSystem
;
import
org.hyperic.sigar.FileSystemUsage
;
import
org.hyperic.sigar.Mem
;
import
org.hyperic.sigar.Sigar
;
import
org.hyperic.sigar.Swap
;
public
class
SystemInfo
{
public
static
Map
SystemProperty
()
{
Map
<
String
,
Comparable
>
monitorMap
=
new
HashMap
();
Runtime
r
=
Runtime
.
getRuntime
();
Properties
props
=
System
.
getProperties
();
InetAddress
addr
=
null
;
String
ip
=
""
;
String
hostName
=
""
;
try
{
addr
=
InetAddress
.
getLocalHost
();
}
catch
(
UnknownHostException
e
)
{
ip
=
"无法获取主机IP"
;
hostName
=
"无法获取主机名"
;
}
if
(
null
!=
addr
)
{
try
{
ip
=
addr
.
getHostAddress
();
}
catch
(
Exception
e
)
{
ip
=
"无法获取主机IP"
;
}
try
{
hostName
=
addr
.
getHostName
();
}
catch
(
Exception
e
)
{
hostName
=
"无法获取主机名"
;
}
}
monitorMap
.
put
(
"hostIp"
,
ip
);
// 本地ip地址
monitorMap
.
put
(
"hostName"
,
hostName
);
// 本地主机名
monitorMap
.
put
(
"osName"
,
props
.
getProperty
(
"os.name"
));
// 操作系统的名称
monitorMap
.
put
(
"arch"
,
props
.
getProperty
(
"os.arch"
));
// 操作系统的构架
monitorMap
.
put
(
"osVersion"
,
props
.
getProperty
(
"os.version"
));
// 操作系统的版本
monitorMap
.
put
(
"processors"
,
r
.
availableProcessors
());
// JVM可以使用的处理器个数
monitorMap
.
put
(
"javaVersion"
,
props
.
getProperty
(
"java.version"
));
// Java的运行环境版本
monitorMap
.
put
(
"vendor"
,
props
.
getProperty
(
"java.vendor"
));
// Java的运行环境供应商
monitorMap
.
put
(
"javaUrl"
,
props
.
getProperty
(
"java.vendor.url"
));
// Java供应商的URL
monitorMap
.
put
(
"javaHome"
,
props
.
getProperty
(
"java.home"
));
// Java的安装路径
monitorMap
.
put
(
"tmpdir"
,
props
.
getProperty
(
"java.io.tmpdir"
));
// 默认的临时文件路径
return
monitorMap
;
}
public
static
Map
memory
(
Sigar
sigar
)
{
Map
<
String
,
Object
>
monitorMap
=
new
HashMap
();
try
{
Runtime
r
=
Runtime
.
getRuntime
();
monitorMap
.
put
(
"jvmTotal"
,
Common
.
div
(
r
.
totalMemory
(),
(
1024
*
1024
),
2
)
+
"M"
);
// java总内存
monitorMap
.
put
(
"jvmUse"
,
Common
.
div
(
r
.
totalMemory
()
-
r
.
freeMemory
(),
(
1024
*
1024
),
2
)
+
"M"
);
// JVM使用内存
monitorMap
.
put
(
"jvmFree"
,
Common
.
div
(
r
.
freeMemory
(),
(
1024
*
1024
),
2
)
+
"M"
);
// JVM剩余内存
monitorMap
.
put
(
"jvmUsage"
,
Common
.
div
(
r
.
totalMemory
()
-
r
.
freeMemory
(),
r
.
totalMemory
(),
2
));
// JVM使用率
Mem
mem
=
sigar
.
getMem
();
// 内存总量
monitorMap
.
put
(
"ramTotal"
,
Common
.
div
(
mem
.
getTotal
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 内存总量
monitorMap
.
put
(
"ramUse"
,
Common
.
div
(
mem
.
getUsed
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 当前内存使用量
monitorMap
.
put
(
"ramFree"
,
Common
.
div
(
mem
.
getFree
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 当前内存剩余量
monitorMap
.
put
(
"ramUsage"
,
Common
.
div
(
mem
.
getUsed
(),
mem
.
getTotal
(),
2
));
// 内存使用率
Swap
swap
=
sigar
.
getSwap
();
// 交换区总量
monitorMap
.
put
(
"swapTotal"
,
Common
.
div
(
swap
.
getTotal
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 当前交换区使用量
monitorMap
.
put
(
"swapUse"
,
Common
.
div
(
swap
.
getUsed
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 当前交换区剩余量
monitorMap
.
put
(
"swapFree"
,
Common
.
div
(
swap
.
getFree
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
monitorMap
.
put
(
"swapUsage"
,
Common
.
div
(
swap
.
getUsed
(),
swap
.
getTotal
(),
2
));
//
}
catch
(
Exception
e
)
{
}
return
monitorMap
;
}
public
static
Map
usage
(
Sigar
sigar
)
{
Map
<
String
,
Long
>
monitorMap
=
new
HashMap
();
try
{
Runtime
r
=
Runtime
.
getRuntime
();
monitorMap
.
put
(
"jvmUsage"
,
Math
.
round
(
Common
.
div
(
r
.
totalMemory
()-
r
.
freeMemory
(),
r
.
totalMemory
(),
2
)*
100
));
// JVM使用率
Mem
mem
=
sigar
.
getMem
();
// 内存总量
monitorMap
.
put
(
"ramUsage"
,
Math
.
round
(
Common
.
div
(
mem
.
getUsed
(),
mem
.
getTotal
(),
2
)*
100
));
// 内存使用率
List
<
Map
>
cpu
=
cpuInfos
(
sigar
);
double
b
=
0.0
;
for
(
Map
m
:
cpu
)
{
b
+=
Double
.
valueOf
(
m
.
get
(
"cpuTotal"
)+
""
);
}
monitorMap
.
put
(
"cpuUsage"
,
Math
.
round
(
b
/
cpu
.
size
()));
// cpu使用率
}
catch
(
Exception
e
)
{
}
return
monitorMap
;
}
public
static
List
<
Map
>
cpuInfos
(
Sigar
sigar
)
{
List
<
Map
>
monitorMaps
=
new
ArrayList
<
Map
>();
try
{
CpuPerc
[]
cpuList
=
sigar
.
getCpuPercList
();
for
(
CpuPerc
cpuPerc
:
cpuList
)
{
Map
<
String
,
Comparable
>
monitorMap
=
new
HashMap
();
monitorMap
.
put
(
"cpuUserUse"
,
Math
.
round
(
cpuPerc
.
getUser
()*
100
));
// 用户使用率
monitorMap
.
put
(
"cpuSysUse"
,
Math
.
round
(
cpuPerc
.
getSys
()*
100
));
// 系统使用率
monitorMap
.
put
(
"cpuWait"
,
Math
.
round
(
cpuPerc
.
getWait
()*
100
));
// 当前等待率
monitorMap
.
put
(
"cpuFree"
,
Math
.
round
(
cpuPerc
.
getIdle
()*
100
));
// 当前空闲率
monitorMap
.
put
(
"cpuTotal"
,
Math
.
round
(
cpuPerc
.
getCombined
()*
100
));
// 总的使用率
monitorMaps
.
add
(
monitorMap
);
}
}
catch
(
Exception
e
)
{
}
return
monitorMaps
;
}
public
List
<
Map
>
diskInfos
(
Sigar
sigar
)
throws
Exception
{
List
<
Map
>
monitorMaps
=
new
ArrayList
<
Map
>();
FileSystem
[]
fslist
=
sigar
.
getFileSystemList
();
for
(
int
i
=
0
;
i
<
fslist
.
length
;
i
++)
{
Map
<
Object
,
Object
>
monitorMap
=
new
HashMap
();
FileSystem
fs
=
fslist
[
i
];
// 文件系统类型名,比如本地硬盘、光驱、网络文件系统等
FileSystemUsage
usage
=
null
;
usage
=
sigar
.
getFileSystemUsage
(
fs
.
getDirName
());
switch
(
fs
.
getType
())
{
case
0
:
// TYPE_UNKNOWN :未知
break
;
case
1
:
// TYPE_NONE
break
;
case
2
:
// TYPE_LOCAL_DISK : 本地硬盘
monitorMap
.
put
(
"diskName"
,
fs
.
getDevName
());
// 系统盘名称
monitorMap
.
put
(
"diskType"
,
fs
.
getSysTypeName
());
// 盘类型
// 文件系统总大小
monitorMap
.
put
(
"diskTotal"
,
fs
.
getSysTypeName
());
// 文件系统剩余大小
monitorMap
.
put
(
"diskFree"
,
usage
.
getFree
());
// 文件系统已经使用量
monitorMap
.
put
(
"diskUse"
,
usage
.
getUsed
());
double
usePercent
=
usage
.
getUsePercent
()
*
100
D
;
// 文件系统资源的利用率
monitorMap
.
put
(
"diskUsage"
,
usePercent
);
// 内存使用率
monitorMaps
.
add
(
monitorMap
);
break
;
case
3
:
// TYPE_NETWORK :网络
break
;
case
4
:
// TYPE_RAM_DISK :闪存
break
;
case
5
:
// TYPE_CDROM :光驱
break
;
case
6
:
// TYPE_SWAP :页面交换
break
;
}
}
return
monitorMaps
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/web/MonitorController.java
deleted
100644 → 0
View file @
b6becbcd
package
com.jeespring.modules.monitor.web
;
import
java.util.Map
;
import
org.hyperic.sigar.Sigar
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.jeespring.common.json.AjaxJson
;
import
com.jeespring.common.mail.MailSendUtils
;
import
com.jeespring.common.utils.MyBeanUtils
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.monitor.entity.Monitor
;
import
com.jeespring.modules.monitor.service.MonitorService
;
import
com.jeespring.modules.monitor.utils.SystemInfo
;
import
com.jeespring.modules.sys.entity.SystemConfig
;
import
com.jeespring.modules.sys.service.SystemConfigService
;
/**
* 系统监控Controller
* @author liugf
* @version 2016-02-07
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/monitor"
)
public
class
MonitorController
extends
AbstractBaseController
{
@Autowired
private
MonitorService
monitorService
;
@Autowired
private
SystemConfigService
systemConfigService
;
@ModelAttribute
public
Monitor
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
Monitor
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
monitorService
.
get
(
id
);
}
if
(
entity
==
null
){
entity
=
new
Monitor
();
}
return
entity
;
}
@RequestMapping
(
"info"
)
public
String
info
(
Model
model
)
throws
Exception
{
Monitor
monitor
=
monitorService
.
get
(
"1"
);
model
.
addAttribute
(
"cpu"
,
monitor
.
getCpu
());
model
.
addAttribute
(
"jvm"
,
monitor
.
getJvm
());
model
.
addAttribute
(
"ram"
,
monitor
.
getRam
());
model
.
addAttribute
(
"toEmail"
,
monitor
.
getToEmail
());
return
"modules/monitor/info"
;
}
@RequestMapping
(
"monitor"
)
public
String
monitor
()
throws
Exception
{
return
"modules/monitor/monitor"
;
}
@RequestMapping
(
"systemInfo"
)
public
String
systemInfo
(
Model
model
)
throws
Exception
{
model
.
addAttribute
(
"systemInfo"
,
SystemInfo
.
SystemProperty
());
return
"modules/monitor/systemInfo"
;
}
@ResponseBody
@RequestMapping
(
"usage"
)
public
Map
usage
(
Model
model
)
throws
Exception
{
SystemConfig
config
=
systemConfigService
.
get
(
"1"
);
Monitor
monitor
=
monitorService
.
get
(
"1"
);
Map
<?,
?>
sigar
=
SystemInfo
.
usage
(
new
Sigar
());
String
content
=
""
;
content
+=
"您预设的cpu使用率警告线是"
+
monitor
.
getCpu
()+
"%, 当前使用率是"
+
sigar
.
get
(
"cpuUsage"
)+
"%"
;
content
+=
"您预设的jvm使用率警告线是"
+
monitor
.
getJvm
()+
"%, 当前使用率是"
+
sigar
.
get
(
"jvmUsage"
)+
"%"
;
content
+=
"您预设的ram使用率警告线是"
+
monitor
.
getRam
()+
"%, 当前使用率是"
+
sigar
.
get
(
"ramUsage"
)+
"%"
;
if
(
Float
.
valueOf
(
sigar
.
get
(
"cpuUsage"
).
toString
())
>=
Float
.
valueOf
(
monitor
.
getCpu
())
||
Float
.
valueOf
(
sigar
.
get
(
"jvmUsage"
).
toString
())
>=
Float
.
valueOf
(
monitor
.
getJvm
())
||
Float
.
valueOf
(
sigar
.
get
(
"ramUsage"
).
toString
())
>=
Float
.
valueOf
(
monitor
.
getRam
())){
MailSendUtils
.
sendEmail
(
config
.
getSmtp
(),
config
.
getPort
(),
config
.
getMailName
(),
config
.
getMailPassword
(),
monitor
.
getToEmail
(),
"服务器监控预警"
,
content
,
"0"
);
};
return
sigar
;
}
/**
* 修改配置
* @param request
* @param nodeId
* @return
* @throws Exception
*/
@ResponseBody
@RequestMapping
(
"modifySetting"
)
public
AjaxJson
save
(
Monitor
monitor
,
Model
model
)
{
AjaxJson
j
=
new
AjaxJson
();
String
message
=
"保存成功"
;
Monitor
t
=
monitorService
.
get
(
"1"
);
try
{
monitor
.
setId
(
"1"
);
MyBeanUtils
.
copyBeanNotNull2Bean
(
monitor
,
t
);
monitorService
.
save
(
t
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
j
.
setSuccess
(
false
);
message
=
"保存失败"
;
}
j
.
setMsg
(
message
);
return
j
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/mvvmoa/dao/FormLeavemDao.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.mvvmoa.dao
;
import
com.jeespring.common.persistence.InterfaceBaseDao
;
import
org.apache.ibatis.annotations.Mapper
;
import
com.jeespring.modules.mvvmoa.entity.FormLeavem
;
/**
* 员工请假DAO接口
* @author liugf
* @version 2017-07-17
*/
@Mapper
public
interface
FormLeavemDao
extends
InterfaceBaseDao
<
FormLeavem
>
{
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/mvvmoa/entity/FormLeavem.java
deleted
100644 → 0
View file @
b6becbcd
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.mvvmoa.entity
;
import
com.jeespring.modules.sys.entity.User
;
import
javax.validation.constraints.NotNull
;
import
com.jeespring.modules.sys.entity.Office
;
import
com.jeespring.modules.sys.entity.Area
;
import
java.util.Date
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.jeespring.common.persistence.AbstractBaseEntity
;
import
com.jeespring.common.utils.excel.annotation.ExcelField
;
/**
* 员工请假Entity
* @author JeeSpring
* @version 2017-07-17
*/
public
class
FormLeavem
extends
AbstractBaseEntity
<
FormLeavem
>
{
private
static
final
long
serialVersionUID
=
1L
;
private
com
.
jeespring
.
modules
.
sys
.
entity
.
User
user
;
// 员工
private
com
.
jeespring
.
modules
.
sys
.
entity
.
Office
office
;
// 归属部门
private
com
.
jeespring
.
modules
.
sys
.
entity
.
Area
area
;
// 归属区域
private
java
.
util
.
Date
beginDate
;
// 请假开始日期
private
java
.
util
.
Date
endDate
;
// 请假结束日期
public
FormLeavem
()
{
super
();
}
public
FormLeavem
(
String
id
){
super
(
id
);
}
@NotNull
(
message
=
"员工不能为空"
)
@ExcelField
(
title
=
"员工"
,
fieldType
=
User
.
class
,
value
=
"user.name"
,
align
=
2
,
sort
=
1
)
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
this
.
user
=
user
;
}
@NotNull
(
message
=
"归属部门不能为空"
)
@ExcelField
(
title
=
"归属部门"
,
fieldType
=
Office
.
class
,
value
=
"office.name"
,
align
=
2
,
sort
=
2
)
public
Office
getOffice
()
{
return
office
;
}
public
void
setOffice
(
Office
office
)
{
this
.
office
=
office
;
}
@ExcelField
(
title
=
"归属区域"
,
fieldType
=
Area
.
class
,
value
=
"area.name"
,
align
=
2
,
sort
=
3
)
public
Area
getArea
()
{
return
area
;
}
public
void
setArea
(
Area
area
)
{
this
.
area
=
area
;
}
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@NotNull
(
message
=
"请假开始日期不能为空"
)
@ExcelField
(
title
=
"请假开始日期"
,
align
=
2
,
sort
=
4
)
public
Date
getBeginDate
()
{
return
beginDate
;
}
public
void
setBeginDate
(
Date
beginDate
)
{
this
.
beginDate
=
beginDate
;
}
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@NotNull
(
message
=
"请假结束日期不能为空"
)
@ExcelField
(
title
=
"请假结束日期"
,
align
=
2
,
sort
=
5
)
public
Date
getEndDate
()
{
return
endDate
;
}
public
void
setEndDate
(
Date
endDate
)
{
this
.
endDate
=
endDate
;
}
}
\ No newline at end of file
Prev
1
…
14
15
16
17
18
19
20
Next
Write
Preview
Supports
Markdown
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