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
468a092d
Commit
468a092d
authored
Nov 24, 2019
by
dqjdda
Browse files
代码优化
parent
88477d18
Changes
16
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/ServerAccount.java
deleted
100644 → 0
View file @
88477d18
package
me.zhengjie.modules.mnt.domain
;
import
lombok.Data
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
javax.persistence.*
;
import
java.io.Serializable
;
/**
* @author zhanghouying
* @date 2019-08-24
*/
@Entity
@Data
@Table
(
name
=
"mnt_server_account"
)
public
class
ServerAccount
implements
Serializable
{
/**
* 编号
*/
@Id
@Column
(
name
=
"id"
)
private
String
id
;
/**
* 名称
*/
@Column
(
name
=
"name"
)
private
String
name
;
/**
* 账号
*/
@Column
(
name
=
"account"
)
private
String
account
;
/**
* 密码
*/
@Column
(
name
=
"password"
)
private
String
password
;
public
void
copy
(
ServerAccount
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/ServerDeploy.java
View file @
468a092d
...
...
@@ -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
...
...
@@ -19,14 +22,21 @@ public class ServerDeploy implements Serializable {
* 服务器IP
*/
@Id
@
Column
(
name
=
"id"
)
private
Stri
ng
id
;
@
GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Lo
ng
id
;
/**
* 服务器账号
*/
@Column
(
name
=
"account_id"
)
private
String
accountId
;
private
String
name
;
private
String
ip
;
private
Integer
port
;
private
String
account
;
private
String
password
;
@CreationTimestamp
private
Timestamp
createTime
;
public
void
copy
(
ServerDeploy
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/ServerAccountRepository.java
deleted
100644 → 0
View file @
88477d18
package
me.zhengjie.modules.mnt.repository
;
import
me.zhengjie.modules.mnt.domain.ServerAccount
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
/**
* @author zhanghouying
* @date 2019-08-24
*/
public
interface
ServerAccountRepository
extends
JpaRepository
<
ServerAccount
,
String
>,
JpaSpecificationExecutor
{
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/ServerDeployRepository.java
View file @
468a092d
...
...
@@ -10,9 +10,11 @@ import org.springframework.data.jpa.repository.Query;
* @author zhanghouying
* @date 2019-08-24
*/
public
interface
ServerDeployRepository
extends
JpaRepository
<
ServerDeploy
,
Stri
ng
>,
JpaSpecificationExecutor
{
public
interface
ServerDeployRepository
extends
JpaRepository
<
ServerDeploy
,
Lo
ng
>,
JpaSpecificationExecutor
<
ServerDeploy
>
{
@Modifying
@Query
(
value
=
"update mnt_server set account_id = null where account_id = ?1"
,
nativeQuery
=
true
)
void
changeByAccount
(
String
id
);
ServerDeploy
findByIp
(
String
ip
);
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/ServerAccountController.java
deleted
100644 → 0
View file @
88477d18
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.ServerAccount
;
import
me.zhengjie.modules.mnt.service.dto.ServerAccountQueryCriteria
;
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.*
;
/**
* @author zhanghouying
* @date 2019-08-24
*/
@Api
(
tags
=
"服务器账号管理"
)
@RestController
@RequestMapping
(
"/api/serverAccount"
)
public
class
ServerAccountController
{
@Autowired
private
me
.
zhengjie
.
modules
.
mnt
.
service
.
ServerAccountService
ServerAccountService
;
@Log
(
"查询ServerAccount"
)
@ApiOperation
(
value
=
"查询ServerAccount"
)
@GetMapping
@PreAuthorize
(
"@el.check('serverAccount:list')"
)
public
ResponseEntity
getServerAccounts
(
ServerAccountQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
(
ServerAccountService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
@Log
(
"新增ServerAccount"
)
@ApiOperation
(
value
=
"新增ServerAccount"
)
@PostMapping
@PreAuthorize
(
"@el.check('serverAccount:add')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
ServerAccount
resources
){
return
new
ResponseEntity
(
ServerAccountService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
@Log
(
"修改ServerAccount"
)
@ApiOperation
(
value
=
"修改ServerAccount"
)
@PutMapping
@PreAuthorize
(
"@el.check('serverAccount:edit')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
ServerAccount
resources
){
ServerAccountService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除ServerAccount"
)
@ApiOperation
(
value
=
"删除ServerAccount"
)
@DeleteMapping
(
value
=
"/{id}"
)
@PreAuthorize
(
"@el.check('serverAccount:del')"
)
public
ResponseEntity
delete
(
@PathVariable
String
id
){
ServerAccountService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/ServerDeployController.java
View file @
468a092d
...
...
@@ -55,7 +55,7 @@ public class ServerDeployController {
@ApiOperation
(
value
=
"删除Server"
)
@DeleteMapping
(
value
=
"/{id:.+}"
)
@PreAuthorize
(
"@el.check('serverDeploy:del')"
)
public
ResponseEntity
delete
(
@PathVariable
Stri
ng
id
){
public
ResponseEntity
delete
(
@PathVariable
Lo
ng
id
){
serverDeployService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/ServerAccountService.java
deleted
100644 → 0
View file @
88477d18
package
me.zhengjie.modules.mnt.service
;
import
me.zhengjie.modules.mnt.domain.ServerAccount
;
import
me.zhengjie.modules.mnt.service.dto.ServerAccountDTO
;
import
me.zhengjie.modules.mnt.service.dto.ServerAccountQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
/**
* @author zhanghouying
* @date 2019-08-24
*/
public
interface
ServerAccountService
{
/**
* queryAll 分页
* @param criteria
* @param pageable
* @return
*/
Object
queryAll
(
ServerAccountQueryCriteria
criteria
,
Pageable
pageable
);
/**
* queryAll 不分页
* @param criteria
* @return
*/
public
Object
queryAll
(
ServerAccountQueryCriteria
criteria
);
/**
* findById
* @param id
* @return
*/
ServerAccountDTO
findById
(
String
id
);
/**
* create
* @param resources
* @return
*/
ServerAccountDTO
create
(
ServerAccount
resources
);
/**
* update
* @param resources
*/
void
update
(
ServerAccount
resources
);
/**
* delete
* @param id
*/
void
delete
(
String
id
);
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/ServerDeployService.java
View file @
468a092d
...
...
@@ -31,7 +31,7 @@ public interface ServerDeployService {
* @param id
* @return
*/
ServerDeployDTO
findById
(
Stri
ng
id
);
ServerDeployDTO
findById
(
Lo
ng
id
);
/**
* create
...
...
@@ -50,5 +50,7 @@ public interface ServerDeployService {
* delete
* @param id
*/
void
delete
(
String
id
);
void
delete
(
Long
id
);
ServerDeployDTO
findByIp
(
String
ip
);
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/ServerAccountDTO.java
deleted
100644 → 0
View file @
88477d18
package
me.zhengjie.modules.mnt.service.dto
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @author zhanghouying
* @date 2019-08-24
*/
@Data
public
class
ServerAccountDTO
implements
Serializable
{
/**
* 编号
*/
private
String
id
;
/**
* 名称
*/
private
String
name
;
/**
* 账号
*/
private
String
account
;
/**
* 密码
*/
private
String
password
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/ServerAccountQueryCriteria.java
deleted
100644 → 0
View file @
88477d18
package
me.zhengjie.modules.mnt.service.dto
;
import
lombok.Data
;
import
me.zhengjie.annotation.Query
;
/**
* @author zhanghouying
* @date 2019-08-24
*/
@Data
public
class
ServerAccountQueryCriteria
{
/**
* 模糊
*/
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
name
;
/**
* 模糊
*/
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
account
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/ServerDeployDTO.java
View file @
468a092d
package
me.zhengjie.modules.mnt.service.dto
;
import
lombok.Data
;
import
me.zhengjie.modules.mnt.service.ServerAccountService
;
import
me.zhengjie.modules.mnt.service.ServerDeployService
;
import
me.zhengjie.utils.SpringContextHolder
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
...
...
@@ -15,26 +12,17 @@ import java.io.Serializable;
@Data
public
class
ServerDeployDTO
implements
Serializable
{
/**
* 服务器IP
*/
private
String
id
;
/**
* 服务器账号
*/
private
String
accountId
;
/**
* 账号名称
*/
private
String
accountName
;
public
String
getAccountName
()
{
if
(
accountId
!=
null
){
ServerAccountService
serverAccountService
=
SpringContextHolder
.
getBean
(
ServerAccountService
.
class
);
return
serverAccountService
.
findById
(
accountId
).
getName
();
}
return
accountName
;
}
private
Long
id
;
private
String
name
;
private
String
ip
;
private
Integer
port
;
private
String
account
;
private
String
password
;
private
Timestamp
createTime
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/ServerDeployQueryCriteria.java
View file @
468a092d
...
...
@@ -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
...
...
@@ -13,7 +16,9 @@ public class ServerDeployQueryCriteria{
/**
* 模糊
*/
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
id
;
@Query
(
blurry
=
"name,ip,account"
)
private
String
blurry
;
@Query
(
type
=
Query
.
Type
.
BETWEEN
)
private
List
<
Timestamp
>
createTime
;
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java
View file @
468a092d
...
...
@@ -59,13 +59,9 @@ public class DeployServiceImpl implements DeployService {
@Autowired
private
DeployHistoryService
deployHistoryService
;
@Autowired
private
ServerAccountService
serverAccountService
;
@Autowired
private
DatabaseService
databaseService
;
@Override
public
Object
queryAll
(
DeployQueryCriteria
criteria
,
Pageable
pageable
)
{
Page
<
Deploy
>
page
=
deployRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
...
...
@@ -243,7 +239,6 @@ public class DeployServiceImpl implements DeployService {
}
}
@Override
public
String
serverStatus
(
Deploy
resources
)
{
String
ip
=
resources
.
getIp
();
...
...
@@ -264,7 +259,6 @@ public class DeployServiceImpl implements DeployService {
return
"执行完毕"
;
}
private
boolean
checkFile
(
ExecuteShellUtil
executeShellUtil
,
AppDTO
appDTO
)
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"find "
);
...
...
@@ -301,11 +295,8 @@ public class DeployServiceImpl implements DeployService {
return
"执行完毕"
;
}
;
/**
* 停止服务
*
* @param resources
* @return
*/
...
...
@@ -333,8 +324,6 @@ public class DeployServiceImpl implements DeployService {
return
"执行完毕"
;
}
;
@Override
public
String
serverReduction
(
DeployHistory
resources
)
{
String
deployId
=
resources
.
getDeployId
();
...
...
@@ -385,34 +374,21 @@ public class DeployServiceImpl implements DeployService {
}
private
ExecuteShellUtil
getExecuteShellUtil
(
String
ip
)
{
ServerDeployDTO
serverDeployDTO
=
serverDeployService
.
findByI
d
(
ip
);
ServerDeployDTO
serverDeployDTO
=
serverDeployService
.
findByI
p
(
ip
);
if
(
serverDeployDTO
==
null
)
{
sendMsg
(
"IP对应服务器信息不存在:"
+
ip
,
MsgType
.
ERROR
);
throw
new
BadRequestException
(
"IP对应服务器信息不存在:"
+
ip
);
}
String
accountId
=
serverDeployDTO
.
getAccountId
();
ServerAccountDTO
serverAccountDTO
=
serverAccountService
.
findById
(
accountId
);
if
(
serverAccountDTO
==
null
)
{
sendMsg
(
"IP对账号信息不存在:"
+
ip
,
MsgType
.
ERROR
);
throw
new
BadRequestException
(
"IP对账号信息不存在:"
+
ip
);
}
return
new
ExecuteShellUtil
(
ip
,
serverAccountDTO
.
getAccount
(),
serverAccountDTO
.
getPassword
());
return
new
ExecuteShellUtil
(
ip
,
serverDeployDTO
.
getAccount
(),
serverDeployDTO
.
getPassword
());
}
private
ScpClientUtil
getScpClientUtil
(
String
ip
)
{
ServerDeployDTO
serverDeployDTO
=
serverDeployService
.
findByI
d
(
ip
);
ServerDeployDTO
serverDeployDTO
=
serverDeployService
.
findByI
p
(
ip
);
if
(
serverDeployDTO
==
null
)
{
sendMsg
(
"IP对应服务器信息不存在:"
+
ip
,
MsgType
.
ERROR
);
throw
new
BadRequestException
(
"IP对应服务器信息不存在:"
+
ip
);
}
String
accountId
=
serverDeployDTO
.
getAccountId
();
ServerAccountDTO
serverAccountDTO
=
serverAccountService
.
findById
(
accountId
);
if
(
serverAccountDTO
==
null
)
{
sendMsg
(
"IP对账号信息不存在:"
+
ip
,
MsgType
.
ERROR
);
throw
new
BadRequestException
(
"IP对账号信息不存在:"
+
ip
);
}
return
ScpClientUtil
.
getInstance
(
ip
,
22
,
serverAccountDTO
.
getAccount
(),
serverAccountDTO
.
getPassword
());
return
ScpClientUtil
.
getInstance
(
ip
,
serverDeployDTO
.
getPort
(),
serverDeployDTO
.
getAccount
(),
serverDeployDTO
.
getPassword
());
}
public
void
sendResultMsg
(
boolean
result
,
StringBuilder
sb
)
{
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerAccountServiceImpl.java
deleted
100644 → 0
View file @
88477d18
package
me.zhengjie.modules.mnt.service.impl
;
import
cn.hutool.core.util.IdUtil
;
import
me.zhengjie.modules.mnt.domain.ServerAccount
;
import
me.zhengjie.modules.mnt.repository.ServerAccountRepository
;
import
me.zhengjie.modules.mnt.repository.ServerDeployRepository
;
import
me.zhengjie.modules.mnt.service.ServerAccountService
;
import
me.zhengjie.modules.mnt.service.dto.ServerAccountDTO
;
import
me.zhengjie.modules.mnt.service.dto.ServerAccountQueryCriteria
;
import
me.zhengjie.modules.mnt.service.mapper.ServerAccountMapper
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
import
org.hibernate.mapping.IdGenerator
;
import
org.springframework.beans.factory.annotation.Autowired
;
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
java.util.Optional
;
/**
* @author zhanghouying
* @date 2019-08-24
*/
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
ServerAccountServiceImpl
implements
ServerAccountService
{
@Autowired
private
ServerAccountRepository
serverAccountRepository
;
@Autowired
private
ServerDeployRepository
serverDeployRepository
;
@Autowired
private
ServerAccountMapper
serverAccountMapper
;
@Override
public
Object
queryAll
(
ServerAccountQueryCriteria
criteria
,
Pageable
pageable
){
Page
<
ServerAccount
>
page
=
serverAccountRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
serverAccountMapper:
:
toDto
));
}
@Override
public
Object
queryAll
(
ServerAccountQueryCriteria
criteria
){
return
serverAccountMapper
.
toDto
(
serverAccountRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
@Override
public
ServerAccountDTO
findById
(
String
id
)
{
Optional
<
ServerAccount
>
ServerAccount
=
serverAccountRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
ServerAccount
,
"ServerAccount"
,
"id"
,
id
);
return
serverAccountMapper
.
toDto
(
ServerAccount
.
get
());
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
ServerAccountDTO
create
(
ServerAccount
resources
)
{
resources
.
setId
(
IdUtil
.
getSnowflake
(
0
,
0
).
toString
());
return
serverAccountMapper
.
toDto
(
serverAccountRepository
.
save
(
resources
));
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
ServerAccount
resources
)
{
Optional
<
ServerAccount
>
optionalServerAccount
=
serverAccountRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalServerAccount
,
"ServerAccount"
,
"id"
,
resources
.
getId
());
ServerAccount
ServerAccount
=
optionalServerAccount
.
get
();
ServerAccount
.
copy
(
resources
);
serverAccountRepository
.
save
(
ServerAccount
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
String
id
)
{
serverAccountRepository
.
deleteById
(
id
);
serverDeployRepository
.
changeByAccount
(
id
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerDeployServiceImpl.java
View file @
468a092d
...
...
@@ -46,12 +46,18 @@ public class ServerDeployServiceImpl implements ServerDeployService {
}
@Override
public
ServerDeployDTO
findById
(
Stri
ng
id
)
{
public
ServerDeployDTO
findById
(
Lo
ng
id
)
{
Optional
<
ServerDeploy
>
server
=
serverDeployRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
server
,
"ServerDeploy"
,
"id"
,
id
);
return
serverDeployMapper
.
toDto
(
server
.
get
());
}
@Override
public
ServerDeployDTO
findByIp
(
String
ip
)
{
ServerDeploy
deploy
=
serverDeployRepository
.
findByIp
(
ip
);
return
serverDeployMapper
.
toDto
(
deploy
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
ServerDeployDTO
create
(
ServerDeploy
resources
)
{
...
...
@@ -70,7 +76,7 @@ public class ServerDeployServiceImpl implements ServerDeployService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Stri
ng
id
)
{
public
void
delete
(
Lo
ng
id
)
{
serverDeployRepository
.
deleteById
(
id
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/mapper/ServerAccountMapper.java
deleted
100644 → 0
View file @
88477d18
package
me.zhengjie.modules.mnt.service.mapper
;
import
me.zhengjie.base.BaseMapper
;
import
me.zhengjie.modules.mnt.domain.ServerAccount
;
import
me.zhengjie.modules.mnt.service.dto.ServerAccountDTO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
/**
* @author zhanghouying
* @date 2019-08-24
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
ServerAccountMapper
extends
BaseMapper
<
ServerAccountDTO
,
ServerAccount
>
{
}
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