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
Eladmin
Commits
554aa58c
Commit
554aa58c
authored
Dec 18, 2019
by
Elune
Browse files
代码优化
parent
8c7217eb
Changes
24
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java
View file @
554aa58c
...
...
@@ -27,7 +27,7 @@ public class GlobalExceptionHandler {
* 处理所有不可知的异常
*/
@ExceptionHandler
(
Throwable
.
class
)
public
ResponseEntity
handleException
(
Throwable
e
){
public
ResponseEntity
<
ApiError
>
handleException
(
Throwable
e
){
// 打印堆栈信息
log
.
error
(
ThrowableUtil
.
getStackTrace
(
e
));
return
buildResponseEntity
(
ApiError
.
error
(
e
.
getMessage
()));
...
...
@@ -37,7 +37,7 @@ public class GlobalExceptionHandler {
* BadCredentialsException
*/
@ExceptionHandler
(
BadCredentialsException
.
class
)
public
ResponseEntity
badCredentialsException
(
BadCredentialsException
e
){
public
ResponseEntity
<
ApiError
>
badCredentialsException
(
BadCredentialsException
e
){
// 打印堆栈信息
String
message
=
"坏的凭证"
.
equals
(
e
.
getMessage
())
?
"用户名或密码不正确"
:
e
.
getMessage
();
log
.
error
(
message
);
...
...
eladmin-generator/src/main/java/me/zhengjie/service/impl/GeneratorServiceImpl.java
View file @
554aa58c
...
...
@@ -134,7 +134,7 @@ public class GeneratorServiceImpl implements GeneratorService {
}
@Override
public
ResponseEntity
preview
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
)
{
public
ResponseEntity
<
Object
>
preview
(
GenConfig
genConfig
,
List
<
ColumnInfo
>
columns
)
{
if
(
genConfig
.
getId
()
==
null
){
throw
new
BadRequestException
(
"请先配置生成器"
);
}
...
...
eladmin-monitor/src/main/java/me/zhengjie/res/ServerMonitorController.java
View file @
554aa58c
...
...
@@ -25,7 +25,7 @@ public class ServerMonitorController {
private
static
final
double
GB
=
1024
*
1024
*
1024.00
;
@GetMapping
public
ResponseEntity
getServerInfo
(){
public
ResponseEntity
<
Object
>
getServerInfo
(){
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<>(
8
);
try
{
CpuInfo
[]
infoList
=
sigar
.
getCpuInfoList
();
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/Database.java
View file @
554aa58c
...
...
@@ -3,8 +3,11 @@ package me.zhengjie.modules.mnt.domain;
import
lombok.Data
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
org.hibernate.annotations.CreationTimestamp
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @author zhanghouying
...
...
@@ -46,6 +49,8 @@ public class Database implements Serializable {
@Column
(
name
=
"user_name"
,
nullable
=
false
)
private
String
userName
;
@CreationTimestamp
private
Timestamp
createTime
;
public
void
copy
(
Database
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java
View file @
554aa58c
...
...
@@ -12,6 +12,9 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.Set
;
/**
* @author zhanghouying
...
...
@@ -28,11 +31,19 @@ public class AppController {
this
.
appService
=
appService
;
}
@Log
(
"导出应用数据"
)
@ApiOperation
(
"导出应用数据"
)
@GetMapping
(
value
=
"/download"
)
@PreAuthorize
(
"@el.check('app:list')"
)
public
void
download
(
HttpServletResponse
response
,
AppQueryCriteria
criteria
)
throws
IOException
{
appService
.
download
(
appService
.
queryAll
(
criteria
),
response
);
}
@Log
(
"查询应用"
)
@ApiOperation
(
value
=
"查询应用"
)
@GetMapping
@PreAuthorize
(
"@el.check('app:list')"
)
public
ResponseEntity
getApps
(
AppQueryCriteria
criteria
,
Pageable
pageable
){
public
ResponseEntity
<
Object
>
getApps
(
AppQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
appService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
...
...
@@ -40,7 +51,7 @@ public class AppController {
@ApiOperation
(
value
=
"新增应用"
)
@PostMapping
@PreAuthorize
(
"@el.check('app:add')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
App
resources
){
public
ResponseEntity
<
Object
>
create
(
@Validated
@RequestBody
App
resources
){
return
new
ResponseEntity
<>(
appService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
...
...
@@ -48,17 +59,17 @@ public class AppController {
@ApiOperation
(
value
=
"修改应用"
)
@PutMapping
@PreAuthorize
(
"@el.check('app:edit')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
App
resources
){
public
ResponseEntity
<
Object
>
update
(
@Validated
@RequestBody
App
resources
){
appService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
<>
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除应用"
)
@ApiOperation
(
value
=
"删除应用"
)
@DeleteMapping
(
value
=
"/{id}"
)
@DeleteMapping
@PreAuthorize
(
"@el.check('app:del')"
)
public
ResponseEntity
delete
(
@
PathVariable
Long
id
){
appService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
public
ResponseEntity
<
Object
>
delete
(
@
RequestBody
Set
<
Long
>
id
s
){
appService
.
delete
(
id
s
);
return
new
ResponseEntity
<>
(
HttpStatus
.
OK
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DatabaseController.java
View file @
554aa58c
...
...
@@ -17,9 +17,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Set
;
/**
* @author zhanghouying
...
...
@@ -38,11 +40,19 @@ public class DatabaseController {
this
.
databaseService
=
databaseService
;
}
@Log
(
"导出数据库数据"
)
@ApiOperation
(
"导出数据库数据"
)
@GetMapping
(
value
=
"/download"
)
@PreAuthorize
(
"@el.check('database:list')"
)
public
void
download
(
HttpServletResponse
response
,
DatabaseQueryCriteria
criteria
)
throws
IOException
{
databaseService
.
download
(
databaseService
.
queryAll
(
criteria
),
response
);
}
@Log
(
"查询数据库"
)
@ApiOperation
(
value
=
"查询数据库"
)
@GetMapping
@PreAuthorize
(
"@el.check('database:list')"
)
public
ResponseEntity
getDatabases
(
DatabaseQueryCriteria
criteria
,
Pageable
pageable
){
public
ResponseEntity
<
Object
>
getDatabases
(
DatabaseQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
databaseService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
...
...
@@ -50,7 +60,7 @@ public class DatabaseController {
@ApiOperation
(
value
=
"新增数据库"
)
@PostMapping
@PreAuthorize
(
"@el.check('database:add')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
Database
resources
){
public
ResponseEntity
<
Object
>
create
(
@Validated
@RequestBody
Database
resources
){
return
new
ResponseEntity
<>(
databaseService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
...
...
@@ -58,25 +68,25 @@ public class DatabaseController {
@ApiOperation
(
value
=
"修改数据库"
)
@PutMapping
@PreAuthorize
(
"@el.check('database:edit')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
Database
resources
){
public
ResponseEntity
<
Object
>
update
(
@Validated
@RequestBody
Database
resources
){
databaseService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
<>
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除数据库"
)
@ApiOperation
(
value
=
"删除数据库"
)
@DeleteMapping
(
value
=
"/{id}"
)
@DeleteMapping
@PreAuthorize
(
"@el.check('database:del')"
)
public
ResponseEntity
delete
(
@
PathVariable
String
id
){
databaseService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
public
ResponseEntity
<
Object
>
delete
(
@
RequestBody
Set
<
String
>
id
s
){
databaseService
.
delete
(
id
s
);
return
new
ResponseEntity
<>
(
HttpStatus
.
OK
);
}
@Log
(
"测试数据库链接"
)
@ApiOperation
(
value
=
"测试数据库链接"
)
@PostMapping
(
"/testConnect"
)
@PreAuthorize
(
"@el.check('database:testConnect')"
)
public
ResponseEntity
testConnect
(
@Validated
@RequestBody
Database
resources
){
public
ResponseEntity
<
Object
>
testConnect
(
@Validated
@RequestBody
Database
resources
){
return
new
ResponseEntity
<>(
databaseService
.
testConnection
(
resources
),
HttpStatus
.
CREATED
);
}
...
...
@@ -84,7 +94,7 @@ public class DatabaseController {
@ApiOperation
(
value
=
"执行SQL脚本"
)
@PostMapping
(
value
=
"/upload"
)
@PreAuthorize
(
"@el.check('database:add')"
)
public
ResponseEntity
upload
(
@RequestBody
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
public
ResponseEntity
<
Object
>
upload
(
@RequestBody
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
String
id
=
request
.
getParameter
(
"id"
);
DatabaseDto
database
=
databaseService
.
findById
(
id
);
String
fileName
=
""
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java
View file @
554aa58c
...
...
@@ -16,10 +16,13 @@ import org.springframework.validation.annotation.Validated;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Set
;
/**
* @author zhanghouying
...
...
@@ -38,11 +41,19 @@ public class DeployController {
this
.
deployService
=
deployService
;
}
@Log
(
"导出部署数据"
)
@ApiOperation
(
"导出部署数据"
)
@GetMapping
(
value
=
"/download"
)
@PreAuthorize
(
"@el.check('database:list')"
)
public
void
download
(
HttpServletResponse
response
,
DeployQueryCriteria
criteria
)
throws
IOException
{
deployService
.
download
(
deployService
.
queryAll
(
criteria
),
response
);
}
@Log
(
"查询部署"
)
@ApiOperation
(
value
=
"查询部署"
)
@GetMapping
@PreAuthorize
(
"@el.check('deploy:list')"
)
public
ResponseEntity
getDeploys
(
DeployQueryCriteria
criteria
,
Pageable
pageable
){
public
ResponseEntity
<
Object
>
getDeploys
(
DeployQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
deployService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
...
...
@@ -50,7 +61,7 @@ public class DeployController {
@ApiOperation
(
value
=
"新增部署"
)
@PostMapping
@PreAuthorize
(
"@el.check('deploy:add')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
Deploy
resources
){
public
ResponseEntity
<
Object
>
create
(
@Validated
@RequestBody
Deploy
resources
){
return
new
ResponseEntity
<>(
deployService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
...
...
@@ -58,25 +69,25 @@ public class DeployController {
@ApiOperation
(
value
=
"修改部署"
)
@PutMapping
@PreAuthorize
(
"@el.check('deploy:edit')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
Deploy
resources
){
public
ResponseEntity
<
Object
>
update
(
@Validated
@RequestBody
Deploy
resources
){
deployService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
<>
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除部署"
)
@ApiOperation
(
value
=
"删除部署"
)
@DeleteMapping
(
value
=
"/{id}"
)
@DeleteMapping
@PreAuthorize
(
"@el.check('deploy:del')"
)
public
ResponseEntity
delete
(
@
PathVariable
Long
id
){
deployService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
public
ResponseEntity
<
Object
>
delete
(
@
RequestBody
Set
<
Long
>
id
s
){
deployService
.
delete
(
id
s
);
return
new
ResponseEntity
<>
(
HttpStatus
.
OK
);
}
@Log
(
"上传文件部署"
)
@ApiOperation
(
value
=
"上传文件部署"
)
@PostMapping
(
value
=
"/upload"
)
@PreAuthorize
(
"@el.check('deploy:edit')"
)
public
ResponseEntity
upload
(
@RequestBody
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
public
ResponseEntity
<
Object
>
upload
(
@RequestBody
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
Long
id
=
Long
.
valueOf
(
request
.
getParameter
(
"id"
));
String
fileName
=
""
;
if
(
file
!=
null
){
...
...
@@ -99,7 +110,7 @@ public class DeployController {
@ApiOperation
(
value
=
"系统还原"
)
@PostMapping
(
value
=
"/serverReduction"
)
@PreAuthorize
(
"@el.check('deploy:edit')"
)
public
ResponseEntity
serverReduction
(
@Validated
@RequestBody
DeployHistory
resources
){
public
ResponseEntity
<
Object
>
serverReduction
(
@Validated
@RequestBody
DeployHistory
resources
){
String
result
=
deployService
.
serverReduction
(
resources
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
...
...
@@ -107,7 +118,7 @@ public class DeployController {
@ApiOperation
(
value
=
"服务运行状态"
)
@PostMapping
(
value
=
"/serverStatus"
)
@PreAuthorize
(
"@el.check('deploy:edit')"
)
public
ResponseEntity
serverStatus
(
@Validated
@RequestBody
Deploy
resources
){
public
ResponseEntity
<
Object
>
serverStatus
(
@Validated
@RequestBody
Deploy
resources
){
String
result
=
deployService
.
serverStatus
(
resources
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
...
...
@@ -115,7 +126,7 @@ public class DeployController {
@ApiOperation
(
value
=
"启动服务"
)
@PostMapping
(
value
=
"/startServer"
)
@PreAuthorize
(
"@el.check('deploy:edit')"
)
public
ResponseEntity
startServer
(
@Validated
@RequestBody
Deploy
resources
){
public
ResponseEntity
<
Object
>
startServer
(
@Validated
@RequestBody
Deploy
resources
){
String
result
=
deployService
.
startServer
(
resources
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
...
...
@@ -123,7 +134,7 @@ public class DeployController {
@ApiOperation
(
value
=
"停止服务"
)
@PostMapping
(
value
=
"/stopServer"
)
@PreAuthorize
(
"@el.check('deploy:edit')"
)
public
ResponseEntity
stopServer
(
@Validated
@RequestBody
Deploy
resources
){
public
ResponseEntity
<
Object
>
stopServer
(
@Validated
@RequestBody
Deploy
resources
){
String
result
=
deployService
.
stopServer
(
resources
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java
View file @
554aa58c
...
...
@@ -3,16 +3,16 @@ package me.zhengjie.modules.mnt.rest;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.modules.mnt.domain.DeployHistory
;
import
me.zhengjie.modules.mnt.service.DeployHistoryService
;
import
me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.Set
;
/**
* @author zhanghouying
...
...
@@ -29,20 +29,28 @@ public class DeployHistoryController {
this
.
deployhistoryService
=
deployhistoryService
;
}
@Log
(
"导出部署历史数据"
)
@ApiOperation
(
"导出部署历史数据"
)
@GetMapping
(
value
=
"/download"
)
@PreAuthorize
(
"@el.check('deployHistory:list')"
)
public
void
download
(
HttpServletResponse
response
,
DeployHistoryQueryCriteria
criteria
)
throws
IOException
{
deployhistoryService
.
download
(
deployhistoryService
.
queryAll
(
criteria
),
response
);
}
@Log
(
"查询部署历史"
)
@ApiOperation
(
value
=
"查询部署历史"
)
@GetMapping
@PreAuthorize
(
"@el.check('deployHistory:list')"
)
public
ResponseEntity
getDeployHistorys
(
DeployHistoryQueryCriteria
criteria
,
Pageable
pageable
){
public
ResponseEntity
<
Object
>
getDeployHistorys
(
DeployHistoryQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
deployhistoryService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
@Log
(
"删除DeployHistory"
)
@ApiOperation
(
value
=
"删除部署历史"
)
@DeleteMapping
(
value
=
"/{id}"
)
@PreAuthorize
(
"
hasAnyRole
('deployHistory:del')"
)
public
ResponseEntity
delete
(
@
PathVariable
String
id
){
deployhistoryService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
@DeleteMapping
@PreAuthorize
(
"
@el.check
('deployHistory:del')"
)
public
ResponseEntity
<
Object
>
delete
(
@
RequestBody
Set
<
String
>
id
s
){
deployhistoryService
.
delete
(
id
s
);
return
new
ResponseEntity
<>
(
HttpStatus
.
OK
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/ServerDeployController.java
View file @
554aa58c
...
...
@@ -12,6 +12,9 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.Set
;
/**
* @author zhanghouying
...
...
@@ -28,11 +31,19 @@ public class ServerDeployController {
this
.
serverDeployService
=
serverDeployService
;
}
@Log
(
"导出服务器数据"
)
@ApiOperation
(
"导出服务器数据"
)
@GetMapping
(
value
=
"/download"
)
@PreAuthorize
(
"@el.check('serverDeploy:list')"
)
public
void
download
(
HttpServletResponse
response
,
ServerDeployQueryCriteria
criteria
)
throws
IOException
{
serverDeployService
.
download
(
serverDeployService
.
queryAll
(
criteria
),
response
);
}
@Log
(
"查询服务器"
)
@ApiOperation
(
value
=
"查询服务器"
)
@GetMapping
@PreAuthorize
(
"@el.check('serverDeploy:list')"
)
public
ResponseEntity
getServers
(
ServerDeployQueryCriteria
criteria
,
Pageable
pageable
){
public
ResponseEntity
<
Object
>
getServers
(
ServerDeployQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
serverDeployService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
...
...
@@ -40,7 +51,7 @@ public class ServerDeployController {
@ApiOperation
(
value
=
"新增服务器"
)
@PostMapping
@PreAuthorize
(
"@el.check('serverDeploy:add')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
ServerDeploy
resources
){
public
ResponseEntity
<
Object
>
create
(
@Validated
@RequestBody
ServerDeploy
resources
){
return
new
ResponseEntity
<>(
serverDeployService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
...
...
@@ -48,26 +59,25 @@ public class ServerDeployController {
@ApiOperation
(
value
=
"修改服务器"
)
@PutMapping
@PreAuthorize
(
"@el.check('serverDeploy:edit')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
ServerDeploy
resources
){
public
ResponseEntity
<
Object
>
update
(
@Validated
@RequestBody
ServerDeploy
resources
){
serverDeployService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
<>
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除服务器"
)
@ApiOperation
(
value
=
"删除Server"
)
@DeleteMapping
(
value
=
"/{id:.+}"
)
@DeleteMapping
@PreAuthorize
(
"@el.check('serverDeploy:del')"
)
public
ResponseEntity
delete
(
@
PathVariable
Long
id
){
serverDeployService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
public
ResponseEntity
<
Object
>
delete
(
@
RequestBody
Set
<
Long
>
id
s
){
serverDeployService
.
delete
(
id
s
);
return
new
ResponseEntity
<>
(
HttpStatus
.
OK
);
}
@Log
(
"测试连接服务器"
)
@ApiOperation
(
value
=
"测试连接服务器"
)
@PostMapping
(
"/testConnect"
)
@PreAuthorize
(
"@el.check('serverDeploy:add')"
)
public
ResponseEntity
testConnect
(
@Validated
@RequestBody
ServerDeploy
resources
){
public
ResponseEntity
<
Object
>
testConnect
(
@Validated
@RequestBody
ServerDeploy
resources
){
return
new
ResponseEntity
<>(
serverDeployService
.
testConnect
(
resources
),
HttpStatus
.
CREATED
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/AppService.java
View file @
554aa58c
...
...
@@ -5,6 +5,11 @@ import me.zhengjie.modules.mnt.service.dto.AppDto;
import
me.zhengjie.modules.mnt.service.dto.AppQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author zhanghouying
* @date 2019-08-24
...
...
@@ -24,7 +29,7 @@ public interface AppService {
* @param criteria 条件
* @return /
*/
Object
queryAll
(
AppQueryCriteria
criteria
);
List
<
AppDto
>
queryAll
(
AppQueryCriteria
criteria
);
/**
* 根据ID查询
...
...
@@ -48,7 +53,14 @@ public interface AppService {
/**
* 删除
* @param id /
* @param ids /
*/
void
delete
(
Set
<
Long
>
ids
);
/**
* 导出数据
* @param queryAll /
* @param response /
*/
void
d
elete
(
Long
id
)
;
void
d
ownload
(
List
<
AppDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DatabaseService.java
View file @
554aa58c
...
...
@@ -5,6 +5,11 @@ import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import
me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author ZhangHouYing
* @date 2019-08-24
...
...
@@ -24,7 +29,7 @@ public interface DatabaseService {
* @param criteria 条件
* @return /
*/
Object
queryAll
(
DatabaseQueryCriteria
criteria
);
List
<
DatabaseDto
>
queryAll
(
DatabaseQueryCriteria
criteria
);
/**
* 根据ID查询
...
...
@@ -48,14 +53,21 @@ public interface DatabaseService {
/**
* 删除
* @param id /
* @param id
s
/
*/
void
delete
(
String
id
);
void
delete
(
Set
<
String
>
id
s
);
/**
* 测试连接数据库
* @param resources
* @return
* @param resources
/
* @return
/
*/
boolean
testConnection
(
Database
resources
);
/**
* 导出数据
* @param queryAll /
* @param response /
*/
void
download
(
List
<
DatabaseDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployHistoryService.java
View file @
554aa58c
...
...
@@ -5,6 +5,11 @@ import me.zhengjie.modules.mnt.service.dto.DeployHistoryDto;
import
me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author zhanghouying
*/
...
...
@@ -23,7 +28,7 @@ public interface DeployHistoryService {
* @param criteria 条件
* @return /
*/
Object
queryAll
(
DeployHistoryQueryCriteria
criteria
);
List
<
DeployHistoryDto
>
queryAll
(
DeployHistoryQueryCriteria
criteria
);
/**
* 根据ID查询
...
...
@@ -41,7 +46,14 @@ public interface DeployHistoryService {
/**
* 删除
* @param id /
* @param ids /
*/
void
delete
(
Set
<
String
>
ids
);
/**
* 导出数据
* @param queryAll /
* @param response /
*/
void
d
elete
(
String
id
)
;
void
d
ownload
(
List
<
DeployHistoryDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployService.java
View file @
554aa58c
...
...
@@ -6,6 +6,11 @@ import me.zhengjie.modules.mnt.service.dto.DeployDto;
import
me.zhengjie.modules.mnt.service.dto.DeployQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author zhanghouying
* @date 2019-08-24
...
...
@@ -25,7 +30,7 @@ public interface DeployService {
* @param criteria 条件
* @return /
*/
Object
queryAll
(
DeployQueryCriteria
criteria
);
List
<
DeployDto
>
queryAll
(
DeployQueryCriteria
criteria
);
/**
* 根据ID查询
...
...
@@ -50,9 +55,9 @@ public interface DeployService {
/**
* 删除
* @param id /
* @param id
s
/
*/
void
delete
(
Long
id
);
void
delete
(
Set
<
Long
>
id
s
);
/**
* 部署文件到服务器
...
...
@@ -86,4 +91,11 @@ public interface DeployService {
* @return /
*/
String
serverReduction
(
DeployHistory
resources
);
/**
* 导出数据
* @param queryAll /
* @param response /
*/
void
download
(
List
<
DeployDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/ServerDeployService.java
View file @
554aa58c
...
...
@@ -5,6 +5,11 @@ import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import
me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author zhanghouying
* @date 2019-08-24
...
...
@@ -24,7 +29,7 @@ public interface ServerDeployService {
* @param criteria 条件
* @return /
*/
Object
queryAll
(
ServerDeployQueryCriteria
criteria
);
List
<
ServerDeployDto
>
queryAll
(
ServerDeployQueryCriteria
criteria
);
/**
* 根据ID查询
...
...
@@ -48,9 +53,9 @@ public interface ServerDeployService {
/**
* 删除
* @param id /
* @param id
s
/
*/
void
delete
(
Long
id
);
void
delete
(
Set
<
Long
>
id
s
);
/**
* 根据IP查询
...
...
@@ -61,8 +66,15 @@ public interface ServerDeployService {
/**
* 测试登录服务器
* @param resources
* @return
* @param resources
/
* @return
/
*/
Boolean
testConnect
(
ServerDeploy
resources
);
/**
* 导出数据
* @param queryAll /
* @param response /
*/
void
download
(
List
<
ServerDeployDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DatabaseDto.java
View file @
554aa58c
...
...
@@ -2,6 +2,7 @@ package me.zhengjie.modules.mnt.service.dto;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
...
...
@@ -36,4 +37,5 @@ public class DatabaseDto implements Serializable {
*/
private
String
userName
;
private
Timestamp
createTime
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DatabaseQueryCriteria.java
View file @
554aa58c
...
...
@@ -3,6 +3,9 @@ package me.zhengjie.modules.mnt.service.dto;
import
lombok.Data
;
import
me.zhengjie.annotation.Query
;
import
java.sql.Timestamp
;
import
java.util.List
;
/**
* @author zhanghouying
* @date 2019-08-24
...
...
@@ -21,4 +24,7 @@ public class DatabaseQueryCriteria{
*/
@Query
private
String
jdbcUrl
;
@Query
(
type
=
Query
.
Type
.
BETWEEN
)
private
List
<
Timestamp
>
createTime
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/AppServiceImpl.java
View file @
554aa58c
...
...
@@ -6,6 +6,7 @@ import me.zhengjie.modules.mnt.service.AppService;
import
me.zhengjie.modules.mnt.service.dto.AppDto
;
import
me.zhengjie.modules.mnt.service.dto.AppQueryCriteria
;
import
me.zhengjie.modules.mnt.service.mapper.AppMapper
;
import
me.zhengjie.utils.FileUtil
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
...
...
@@ -14,6 +15,9 @@ import org.springframework.data.domain.Pageable;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.*
;
/**
* @author zhanghouying
...
...
@@ -39,7 +43,7 @@ public class AppServiceImpl implements AppService {
}
@Override
public
Object
queryAll
(
AppQueryCriteria
criteria
){
public
List
<
AppDto
>
queryAll
(
AppQueryCriteria
criteria
){
return
appMapper
.
toDto
(
appRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
...
...
@@ -67,7 +71,27 @@ public class AppServiceImpl implements AppService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
appRepository
.
deleteById
(
id
);
public
void
delete
(
Set
<
Long
>
ids
)
{
for
(
Long
id
:
ids
)
{
appRepository
.
deleteById
(
id
);
}
}
@Override
public
void
download
(
List
<
AppDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
for
(
AppDto
appDto
:
queryAll
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"应用名称"
,
appDto
.
getName
());
map
.
put
(
"端口"
,
appDto
.
getPort
());
map
.
put
(
"上传目录"
,
appDto
.
getUploadPath
());
map
.
put
(
"部署目录"
,
appDto
.
getDeployPath
());
map
.
put
(
"备份目录"
,
appDto
.
getBackupPath
());
map
.
put
(
"启动脚本"
,
appDto
.
getStartScript
());
map
.
put
(
"部署脚本"
,
appDto
.
getDeployScript
());
map
.
put
(
"创建日期"
,
appDto
.
getCreateTime
());
list
.
add
(
map
);
}
FileUtil
.
downloadExcel
(
list
,
response
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DatabaseServiceImpl.java
View file @
554aa58c
...
...
@@ -9,6 +9,7 @@ import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import
me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria
;
import
me.zhengjie.modules.mnt.service.mapper.DatabaseMapper
;
import
me.zhengjie.modules.mnt.util.SqlUtils
;
import
me.zhengjie.utils.FileUtil
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
...
...
@@ -18,6 +19,10 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.*
;
/**
* @author zhanghouying
* @date 2019-08-24
...
...
@@ -43,7 +48,7 @@ public class DatabaseServiceImpl implements DatabaseService {
}
@Override
public
Object
queryAll
(
DatabaseQueryCriteria
criteria
){
public
List
<
DatabaseDto
>
queryAll
(
DatabaseQueryCriteria
criteria
){
return
databaseMapper
.
toDto
(
databaseRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
...
...
@@ -72,8 +77,10 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
String
id
)
{
databaseRepository
.
deleteById
(
id
);
public
void
delete
(
Set
<
String
>
ids
)
{
for
(
String
id
:
ids
)
{
databaseRepository
.
deleteById
(
id
);
}
}
@Override
...
...
@@ -84,6 +91,19 @@ public class DatabaseServiceImpl implements DatabaseService {
log
.
error
(
e
.
getMessage
());
return
false
;
}
}
@Override
public
void
download
(
List
<
DatabaseDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
for
(
DatabaseDto
databaseDto
:
queryAll
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"数据库名称"
,
databaseDto
.
getName
());
map
.
put
(
"数据库连接地址"
,
databaseDto
.
getJdbcUrl
());
map
.
put
(
"用户名"
,
databaseDto
.
getUserName
());
map
.
put
(
"创建日期"
,
databaseDto
.
getCreateTime
());
list
.
add
(
map
);
}
FileUtil
.
downloadExcel
(
list
,
response
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployHistoryServiceImpl.java
View file @
554aa58c
...
...
@@ -7,6 +7,7 @@ import me.zhengjie.modules.mnt.service.DeployHistoryService;
import
me.zhengjie.modules.mnt.service.dto.DeployHistoryDto
;
import
me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria
;
import
me.zhengjie.modules.mnt.service.mapper.DeployHistoryMapper
;
import
me.zhengjie.utils.FileUtil
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
...
...
@@ -16,6 +17,10 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.*
;
/**
* @author zhanghouying
* @date 2019-08-24
...
...
@@ -40,7 +45,7 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
}
@Override
public
Object
queryAll
(
DeployHistoryQueryCriteria
criteria
){
public
List
<
DeployHistoryDto
>
queryAll
(
DeployHistoryQueryCriteria
criteria
){
return
deployhistoryMapper
.
toDto
(
deployhistoryRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
...
...
@@ -60,7 +65,24 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
String
id
)
{
deployhistoryRepository
.
deleteById
(
id
);
public
void
delete
(
Set
<
String
>
ids
)
{
for
(
String
id
:
ids
)
{
deployhistoryRepository
.
deleteById
(
id
);
}
}
@Override
public
void
download
(
List
<
DeployHistoryDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
for
(
DeployHistoryDto
deployHistoryDto
:
queryAll
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"部署编号"
,
deployHistoryDto
.
getDeployId
());
map
.
put
(
"应用名称"
,
deployHistoryDto
.
getAppName
());
map
.
put
(
"部署IP"
,
deployHistoryDto
.
getIp
());
map
.
put
(
"部署时间"
,
deployHistoryDto
.
getDeployDate
());
map
.
put
(
"部署人员"
,
deployHistoryDto
.
getDeployUser
());
list
.
add
(
map
);
}
FileUtil
.
downloadExcel
(
list
,
response
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java
View file @
554aa58c
...
...
@@ -12,30 +12,22 @@ import me.zhengjie.modules.mnt.repository.DeployRepository;
import
me.zhengjie.modules.mnt.service.DeployHistoryService
;
import
me.zhengjie.modules.mnt.service.DeployService
;
import
me.zhengjie.modules.mnt.service.ServerDeployService
;
import
me.zhengjie.modules.mnt.service.dto.AppDto
;
import
me.zhengjie.modules.mnt.service.dto.DeployDto
;
import
me.zhengjie.modules.mnt.service.dto.DeployQueryCriteria
;
import
me.zhengjie.modules.mnt.service.dto.ServerDeployDto
;
import
me.zhengjie.modules.mnt.service.dto.*
;
import
me.zhengjie.modules.mnt.service.mapper.DeployMapper
;
import
me.zhengjie.modules.mnt.util.ExecuteShellUtil
;
import
me.zhengjie.modules.mnt.util.ScpClientUtil
;
import
me.zhengjie.modules.mnt.websocket.MsgType
;
import
me.zhengjie.modules.mnt.websocket.SocketMsg
;
import
me.zhengjie.modules.mnt.websocket.WebSocketServer
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.SecurityUtils
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.utils.*
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.*
;
/**
* @author zhanghouying
...
...
@@ -99,8 +91,10 @@ public class DeployServiceImpl implements DeployService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
deployRepository
.
deleteById
(
id
);
public
void
delete
(
Set
<
Long
>
ids
)
{
for
(
Long
id
:
ids
)
{
deployRepository
.
deleteById
(
id
);
}
}
@Override
...
...
@@ -111,9 +105,8 @@ public class DeployServiceImpl implements DeployService {
/**
* @param fileSavePath 本机路径
* @param id ID
* @return string
*/
private
String
deployApp
(
String
fileSavePath
,
Long
id
)
{
private
void
deployApp
(
String
fileSavePath
,
Long
id
)
{
DeployDto
deploy
=
findById
(
id
);
if
(
deploy
==
null
)
{
...
...
@@ -169,7 +162,6 @@ public class DeployServiceImpl implements DeployService {
sendResultMsg
(
result
,
sb
);
executeShellUtil
.
close
();
}
return
"部署结束"
;
}
private
void
sleep
(
int
second
)
{
...
...
@@ -400,4 +392,17 @@ public class DeployServiceImpl implements DeployService {
sendMsg
(
sb
.
toString
(),
MsgType
.
ERROR
);
}
}
@Override
public
void
download
(
List
<
DeployDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
for
(
DeployDto
deployDto
:
queryAll
)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
map
.
put
(
"应用名称"
,
deployDto
.
getApp
().
getName
());
map
.
put
(
"服务器"
,
deployDto
.
getServers
());
map
.
put
(
"部署日期"
,
deployDto
.
getCreateTime
());
list
.
add
(
map
);
}
FileUtil
.
downloadExcel
(
list
,
response
);
}
}
Prev
1
2
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