mirror of https://github.com/elunez/eladmin
代码优化
parent
88477d18b2
commit
468a092d21
|
@ -1,46 +0,0 @@
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,8 +3,11 @@ package me.zhengjie.modules.mnt.domain;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.bean.copier.CopyOptions;
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhanghouying
|
* @author zhanghouying
|
||||||
|
@ -19,14 +22,21 @@ public class ServerDeploy implements Serializable {
|
||||||
* 服务器IP
|
* 服务器IP
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "id")
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private String id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
private String name;
|
||||||
* 服务器账号
|
|
||||||
*/
|
private String ip;
|
||||||
@Column(name = "account_id")
|
|
||||||
private String accountId;
|
private Integer port;
|
||||||
|
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
private Timestamp createTime;
|
||||||
|
|
||||||
public void copy(ServerDeploy source){
|
public void copy(ServerDeploy source){
|
||||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
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 {
|
|
||||||
}
|
|
|
@ -10,9 +10,11 @@ import org.springframework.data.jpa.repository.Query;
|
||||||
* @author zhanghouying
|
* @author zhanghouying
|
||||||
* @date 2019-08-24
|
* @date 2019-08-24
|
||||||
*/
|
*/
|
||||||
public interface ServerDeployRepository extends JpaRepository<ServerDeploy, String>, JpaSpecificationExecutor {
|
public interface ServerDeployRepository extends JpaRepository<ServerDeploy, Long>, JpaSpecificationExecutor<ServerDeploy> {
|
||||||
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Query(value = "update mnt_server set account_id = null where account_id = ?1", nativeQuery = true)
|
@Query(value = "update mnt_server set account_id = null where account_id = ?1", nativeQuery = true)
|
||||||
void changeByAccount(String id);
|
void changeByAccount(String id);
|
||||||
|
|
||||||
|
ServerDeploy findByIp(String ip);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -55,7 +55,7 @@ public class ServerDeployController {
|
||||||
@ApiOperation(value = "删除Server")
|
@ApiOperation(value = "删除Server")
|
||||||
@DeleteMapping(value = "/{id:.+}")
|
@DeleteMapping(value = "/{id:.+}")
|
||||||
@PreAuthorize("@el.check('serverDeploy:del')")
|
@PreAuthorize("@el.check('serverDeploy:del')")
|
||||||
public ResponseEntity delete(@PathVariable String id){
|
public ResponseEntity delete(@PathVariable Long id){
|
||||||
serverDeployService.delete(id);
|
serverDeployService.delete(id);
|
||||||
return new ResponseEntity(HttpStatus.OK);
|
return new ResponseEntity(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
|
@ -31,7 +31,7 @@ public interface ServerDeployService {
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerDeployDTO findById(String id);
|
ServerDeployDTO findById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create
|
* create
|
||||||
|
@ -50,5 +50,7 @@ public interface ServerDeployService {
|
||||||
* delete
|
* delete
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
void delete(String id);
|
void delete(Long id);
|
||||||
|
|
||||||
|
ServerDeployDTO findByIp(String ip);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,11 +1,8 @@
|
||||||
package me.zhengjie.modules.mnt.service.dto;
|
package me.zhengjie.modules.mnt.service.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
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.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,26 +12,17 @@ import java.io.Serializable;
|
||||||
@Data
|
@Data
|
||||||
public class ServerDeployDTO implements Serializable {
|
public class ServerDeployDTO implements Serializable {
|
||||||
|
|
||||||
/**
|
private Long id;
|
||||||
* 服务器IP
|
|
||||||
*/
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/**
|
private String name;
|
||||||
* 服务器账号
|
|
||||||
*/
|
|
||||||
private String accountId;
|
|
||||||
|
|
||||||
/**
|
private String ip;
|
||||||
* 账号名称
|
|
||||||
*/
|
|
||||||
private String accountName;
|
|
||||||
|
|
||||||
public String getAccountName() {
|
private Integer port;
|
||||||
if(accountId != null){
|
|
||||||
ServerAccountService serverAccountService = SpringContextHolder.getBean(ServerAccountService.class);
|
private String account;
|
||||||
return serverAccountService.findById(accountId).getName();
|
|
||||||
}
|
private String password;
|
||||||
return accountName;
|
|
||||||
}
|
private Timestamp createTime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@ package me.zhengjie.modules.mnt.service.dto;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import me.zhengjie.annotation.Query;
|
import me.zhengjie.annotation.Query;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhanghouying
|
* @author zhanghouying
|
||||||
* @date 2019-08-24
|
* @date 2019-08-24
|
||||||
|
@ -13,7 +16,9 @@ public class ServerDeployQueryCriteria{
|
||||||
/**
|
/**
|
||||||
* 模糊
|
* 模糊
|
||||||
*/
|
*/
|
||||||
@Query(type = Query.Type.INNER_LIKE)
|
@Query(blurry = "name,ip,account")
|
||||||
private String id;
|
private String blurry;
|
||||||
|
|
||||||
|
@Query(type = Query.Type.BETWEEN)
|
||||||
|
private List<Timestamp> createTime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,13 +59,9 @@ public class DeployServiceImpl implements DeployService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DeployHistoryService deployHistoryService;
|
private DeployHistoryService deployHistoryService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ServerAccountService serverAccountService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DatabaseService databaseService;
|
private DatabaseService databaseService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object queryAll(DeployQueryCriteria criteria, Pageable pageable) {
|
public Object queryAll(DeployQueryCriteria criteria, Pageable pageable) {
|
||||||
Page<Deploy> page = deployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), 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
|
@Override
|
||||||
public String serverStatus(Deploy resources) {
|
public String serverStatus(Deploy resources) {
|
||||||
String ip = resources.getIp();
|
String ip = resources.getIp();
|
||||||
|
@ -264,7 +259,6 @@ public class DeployServiceImpl implements DeployService {
|
||||||
return "执行完毕";
|
return "执行完毕";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDTO appDTO) {
|
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDTO appDTO) {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append("find ");
|
sb.append("find ");
|
||||||
|
@ -301,11 +295,8 @@ public class DeployServiceImpl implements DeployService {
|
||||||
return "执行完毕";
|
return "执行完毕";
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止服务
|
* 停止服务
|
||||||
*
|
|
||||||
* @param resources
|
* @param resources
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -333,8 +324,6 @@ public class DeployServiceImpl implements DeployService {
|
||||||
return "执行完毕";
|
return "执行完毕";
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String serverReduction(DeployHistory resources) {
|
public String serverReduction(DeployHistory resources) {
|
||||||
String deployId = resources.getDeployId();
|
String deployId = resources.getDeployId();
|
||||||
|
@ -385,34 +374,21 @@ public class DeployServiceImpl implements DeployService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExecuteShellUtil getExecuteShellUtil(String ip) {
|
private ExecuteShellUtil getExecuteShellUtil(String ip) {
|
||||||
ServerDeployDTO serverDeployDTO = serverDeployService.findById(ip);
|
ServerDeployDTO serverDeployDTO = serverDeployService.findByIp(ip);
|
||||||
if (serverDeployDTO == null) {
|
if (serverDeployDTO == null) {
|
||||||
sendMsg("IP对应服务器信息不存在:" + ip, MsgType.ERROR);
|
sendMsg("IP对应服务器信息不存在:" + ip, MsgType.ERROR);
|
||||||
throw new BadRequestException("IP对应服务器信息不存在:" + ip);
|
throw new BadRequestException("IP对应服务器信息不存在:" + ip);
|
||||||
}
|
}
|
||||||
String accountId = serverDeployDTO.getAccountId();
|
return new ExecuteShellUtil(ip, serverDeployDTO.getAccount(), serverDeployDTO.getPassword());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ScpClientUtil getScpClientUtil(String ip) {
|
private ScpClientUtil getScpClientUtil(String ip) {
|
||||||
ServerDeployDTO serverDeployDTO = serverDeployService.findById(ip);
|
ServerDeployDTO serverDeployDTO = serverDeployService.findByIp(ip);
|
||||||
if (serverDeployDTO == null) {
|
if (serverDeployDTO == null) {
|
||||||
sendMsg("IP对应服务器信息不存在:" + ip, MsgType.ERROR);
|
sendMsg("IP对应服务器信息不存在:" + ip, MsgType.ERROR);
|
||||||
throw new BadRequestException("IP对应服务器信息不存在:" + ip);
|
throw new BadRequestException("IP对应服务器信息不存在:" + ip);
|
||||||
}
|
}
|
||||||
String accountId = serverDeployDTO.getAccountId();
|
return ScpClientUtil.getInstance(ip, serverDeployDTO.getPort(), serverDeployDTO.getAccount(), serverDeployDTO.getPassword());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendResultMsg(boolean result, StringBuilder sb) {
|
public void sendResultMsg(boolean result, StringBuilder sb) {
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -46,12 +46,18 @@ public class ServerDeployServiceImpl implements ServerDeployService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerDeployDTO findById(String id) {
|
public ServerDeployDTO findById(Long id) {
|
||||||
Optional<ServerDeploy> server = serverDeployRepository.findById(id);
|
Optional<ServerDeploy> server = serverDeployRepository.findById(id);
|
||||||
ValidationUtil.isNull(server,"ServerDeploy","id",id);
|
ValidationUtil.isNull(server,"ServerDeploy","id",id);
|
||||||
return serverDeployMapper.toDto(server.get());
|
return serverDeployMapper.toDto(server.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerDeployDTO findByIp(String ip) {
|
||||||
|
ServerDeploy deploy = serverDeployRepository.findByIp(ip);
|
||||||
|
return serverDeployMapper.toDto(deploy);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ServerDeployDTO create(ServerDeploy resources) {
|
public ServerDeployDTO create(ServerDeploy resources) {
|
||||||
|
@ -70,7 +76,7 @@ public class ServerDeployServiceImpl implements ServerDeployService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(String id) {
|
public void delete(Long id) {
|
||||||
serverDeployRepository.deleteById(id);
|
serverDeployRepository.deleteById(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
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> {
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue