代码优化

pull/214/head
dqjdda 2019-11-25 13:51:54 +08:00
parent 2853f394e7
commit 6d941c09ef
27 changed files with 212 additions and 354 deletions

View File

@ -13,7 +13,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>eladmin-monitor</artifactId> <artifactId>eladmin-monitor</artifactId>
<version>2.2</version> <version>2.3</version>
<name>客户端监控模块</name> <name>客户端监控模块</name>

View File

@ -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;
import java.util.Set; import java.util.Set;
/** /**
@ -37,6 +40,9 @@ public class Deploy implements Serializable {
@JoinTable(name = "mnt_deploy_server", joinColumns = {@JoinColumn(name = "deploy_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "server_id",referencedColumnName = "id")}) @JoinTable(name = "mnt_deploy_server", joinColumns = {@JoinColumn(name = "deploy_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "server_id",referencedColumnName = "id")})
private Set<ServerDeploy> deploys; private Set<ServerDeploy> deploys;
@CreationTimestamp
private Timestamp createTime;
public void copy(Deploy source){ public void copy(Deploy source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
} }

View File

@ -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
@ -37,8 +40,9 @@ public class DeployHistory implements Serializable {
/** /**
* *
*/ */
@Column(name = "deploy_date",nullable = false) @Column(name = "deploy_date")
private String deployDate; @CreationTimestamp
private Timestamp deployDate;
/** /**
* *

View File

@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author zhanghouying * @author zhanghouying
* @date 2019-08-24 * @date 2019-08-24
*/ */
public interface DatabaseRepository extends JpaRepository<Database, String>, JpaSpecificationExecutor { public interface DatabaseRepository extends JpaRepository<Database, String>, JpaSpecificationExecutor<Database> {
} }

View File

@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author zhanghouying * @author zhanghouying
* @date 2019-08-24 * @date 2019-08-24
*/ */
public interface DeployHistoryRepository extends JpaRepository<DeployHistory, String>, JpaSpecificationExecutor { public interface DeployHistoryRepository extends JpaRepository<DeployHistory, String>, JpaSpecificationExecutor<DeployHistory> {
} }

View File

@ -12,9 +12,5 @@ import org.springframework.data.jpa.repository.Query;
*/ */
public interface ServerDeployRepository extends JpaRepository<ServerDeploy, Long>, JpaSpecificationExecutor<ServerDeploy> { public interface ServerDeployRepository extends JpaRepository<ServerDeploy, Long>, 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); ServerDeploy findByIp(String ip);
} }

View File

@ -6,7 +6,6 @@ import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.mnt.domain.App; import me.zhengjie.modules.mnt.domain.App;
import me.zhengjie.modules.mnt.service.AppService; import me.zhengjie.modules.mnt.service.AppService;
import me.zhengjie.modules.mnt.service.dto.AppQueryCriteria; import me.zhengjie.modules.mnt.service.dto.AppQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -23,31 +22,30 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/api/app") @RequestMapping("/api/app")
public class AppController { public class AppController {
@Autowired private final AppService appService;
private AppService appService;
public AppController(AppService appService){ public AppController(AppService appService){
this.appService = this.appService; this.appService = appService;
} }
@Log("查询App") @Log("查询应用")
@ApiOperation(value = "查询App") @ApiOperation(value = "查询应用")
@GetMapping @GetMapping
@PreAuthorize("@el.check('app:list')") @PreAuthorize("@el.check('app:list')")
public ResponseEntity getApps(AppQueryCriteria criteria, Pageable pageable){ public ResponseEntity getApps(AppQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(appService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(appService.queryAll(criteria,pageable),HttpStatus.OK);
} }
@Log("新增App") @Log("新增应用")
@ApiOperation(value = "新增App") @ApiOperation(value = "新增应用")
@PostMapping @PostMapping
@PreAuthorize("@el.check('app:add')") @PreAuthorize("@el.check('app:add')")
public ResponseEntity create(@Validated @RequestBody App resources){ public ResponseEntity create(@Validated @RequestBody App resources){
return new ResponseEntity(appService.create(resources),HttpStatus.CREATED); return new ResponseEntity<>(appService.create(resources),HttpStatus.CREATED);
} }
@Log("修改App") @Log("修改应用")
@ApiOperation(value = "修改App") @ApiOperation(value = "修改应用")
@PutMapping @PutMapping
@PreAuthorize("@el.check('app:edit')") @PreAuthorize("@el.check('app:edit')")
public ResponseEntity update(@Validated @RequestBody App resources){ public ResponseEntity update(@Validated @RequestBody App resources){
@ -55,8 +53,8 @@ public class AppController {
return new ResponseEntity(HttpStatus.NO_CONTENT); return new ResponseEntity(HttpStatus.NO_CONTENT);
} }
@Log("删除App") @Log("删除应用")
@ApiOperation(value = "删除App") @ApiOperation(value = "删除应用")
@DeleteMapping(value = "/{id}") @DeleteMapping(value = "/{id}")
@PreAuthorize("@el.check('app:del')") @PreAuthorize("@el.check('app:del')")
public ResponseEntity delete(@PathVariable Long id){ public ResponseEntity delete(@PathVariable Long id){

View File

@ -6,7 +6,6 @@ import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.mnt.domain.Database; import me.zhengjie.modules.mnt.domain.Database;
import me.zhengjie.modules.mnt.service.DatabaseService; import me.zhengjie.modules.mnt.service.DatabaseService;
import me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria; import me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -23,27 +22,30 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/api/database") @RequestMapping("/api/database")
public class DatabaseController { public class DatabaseController {
@Autowired private final DatabaseService databaseService;
private DatabaseService databaseService;
@Log("查询Database") public DatabaseController(DatabaseService databaseService) {
@ApiOperation(value = "查询Database") this.databaseService = databaseService;
}
@Log("查询数据库")
@ApiOperation(value = "查询数据库")
@GetMapping @GetMapping
@PreAuthorize("@el.check('database:list')") @PreAuthorize("@el.check('database:list')")
public ResponseEntity getDatabases(DatabaseQueryCriteria criteria, Pageable pageable){ public ResponseEntity getDatabases(DatabaseQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(databaseService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(databaseService.queryAll(criteria,pageable),HttpStatus.OK);
} }
@Log("新增Database") @Log("新增数据库")
@ApiOperation(value = "新增Database") @ApiOperation(value = "新增数据库")
@PostMapping @PostMapping
@PreAuthorize("@el.check('database:add')") @PreAuthorize("@el.check('database:add')")
public ResponseEntity create(@Validated @RequestBody Database resources){ public ResponseEntity create(@Validated @RequestBody Database resources){
return new ResponseEntity(databaseService.create(resources),HttpStatus.CREATED); return new ResponseEntity<>(databaseService.create(resources),HttpStatus.CREATED);
} }
@Log("修改Database") @Log("修改数据库")
@ApiOperation(value = "修改Database") @ApiOperation(value = "修改数据库")
@PutMapping @PutMapping
@PreAuthorize("@el.check('database:edit')") @PreAuthorize("@el.check('database:edit')")
public ResponseEntity update(@Validated @RequestBody Database resources){ public ResponseEntity update(@Validated @RequestBody Database resources){
@ -51,8 +53,8 @@ public class DatabaseController {
return new ResponseEntity(HttpStatus.NO_CONTENT); return new ResponseEntity(HttpStatus.NO_CONTENT);
} }
@Log("删除Database") @Log("删除数据库")
@ApiOperation(value = "删除Database") @ApiOperation(value = "删除数据库")
@DeleteMapping(value = "/{id}") @DeleteMapping(value = "/{id}")
@PreAuthorize("@el.check('database:del')") @PreAuthorize("@el.check('database:del')")
public ResponseEntity delete(@PathVariable String id){ public ResponseEntity delete(@PathVariable String id){

View File

@ -8,7 +8,6 @@ import me.zhengjie.modules.mnt.domain.DeployHistory;
import me.zhengjie.modules.mnt.service.DeployService; import me.zhengjie.modules.mnt.service.DeployService;
import me.zhengjie.modules.mnt.service.dto.DeployQueryCriteria; import me.zhengjie.modules.mnt.service.dto.DeployQueryCriteria;
import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -16,12 +15,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* @author zhanghouying * @author zhanghouying
@ -34,27 +32,30 @@ public class DeployController {
private String fileSavePath = System.getProperty("java.io.tmpdir"); private String fileSavePath = System.getProperty("java.io.tmpdir");
@Autowired private final DeployService deployService;
private DeployService deployService;
@Log("查询Deploy") public DeployController(DeployService deployService) {
@ApiOperation(value = "查询Deploy") this.deployService = deployService;
}
@Log("查询部署")
@ApiOperation(value = "查询部署")
@GetMapping @GetMapping
@PreAuthorize("@el.check('deploy:list')") @PreAuthorize("@el.check('deploy:list')")
public ResponseEntity getDeploys(DeployQueryCriteria criteria, Pageable pageable){ public ResponseEntity getDeploys(DeployQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(deployService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(deployService.queryAll(criteria,pageable),HttpStatus.OK);
} }
@Log("新增Deploy") @Log("新增部署")
@ApiOperation(value = "新增Deploy") @ApiOperation(value = "新增部署")
@PostMapping @PostMapping
@PreAuthorize("@el.check('deploy:add')") @PreAuthorize("@el.check('deploy:add')")
public ResponseEntity create(@Validated @RequestBody Deploy resources){ public ResponseEntity create(@Validated @RequestBody Deploy resources){
return new ResponseEntity(deployService.create(resources),HttpStatus.CREATED); return new ResponseEntity<>(deployService.create(resources),HttpStatus.CREATED);
} }
@Log("修改Deploy") @Log("修改部署")
@ApiOperation(value = "修改Deploy") @ApiOperation(value = "修改部署")
@PutMapping @PutMapping
@PreAuthorize("@el.check('deploy:edit')") @PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity update(@Validated @RequestBody Deploy resources){ public ResponseEntity update(@Validated @RequestBody Deploy resources){
@ -62,8 +63,8 @@ public class DeployController {
return new ResponseEntity(HttpStatus.NO_CONTENT); return new ResponseEntity(HttpStatus.NO_CONTENT);
} }
@Log("删除Deploy") @Log("删除部署")
@ApiOperation(value = "删除Deploy") @ApiOperation(value = "删除部署")
@DeleteMapping(value = "/{id}") @DeleteMapping(value = "/{id}")
@PreAuthorize("@el.check('deploy:del')") @PreAuthorize("@el.check('deploy:del')")
public ResponseEntity delete(@PathVariable Long id){ public ResponseEntity delete(@PathVariable Long id){
@ -71,11 +72,11 @@ public class DeployController {
return new ResponseEntity(HttpStatus.OK); return new ResponseEntity(HttpStatus.OK);
} }
@Log("上传文件Deploy") @Log("上传文件部署")
@ApiOperation(value = "上传文件Deploy") @ApiOperation(value = "上传文件部署")
@PostMapping(value = "/upload") @PostMapping(value = "/upload")
@PreAuthorize("@el.check('deploy:edit')") @PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity upload(@RequestBody MultipartFile file, HttpServletRequest request, HttpServletResponse response)throws Exception{ public ResponseEntity upload(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{
Long id = Long.valueOf(request.getParameter("id")); Long id = Long.valueOf(request.getParameter("id"));
String fileName = ""; String fileName = "";
if(file != null){ if(file != null){
@ -88,42 +89,42 @@ public class DeployController {
}else{ }else{
System.out.println("没有找到相对应的文件"); System.out.println("没有找到相对应的文件");
} }
System.out.println("文件上传的原名称为:"+file.getOriginalFilename()); System.out.println("文件上传的原名称为:"+ Objects.requireNonNull(file).getOriginalFilename());
Map map = new HashMap(2); Map<String,Object> map = new HashMap<>(2);
map.put("errno",0); map.put("errno",0);
map.put("id",fileName); map.put("id",fileName);
return new ResponseEntity(map,HttpStatus.OK); return new ResponseEntity<>(map,HttpStatus.OK);
} }
@Log("系统还原") @Log("系统还原")
@ApiOperation(value = "系统还原") @ApiOperation(value = "系统还原")
@PostMapping(value = "/serverReduction") @PostMapping(value = "/serverReduction")
@PreAuthorize("@el.check('deploy:edit')") @PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity serverReduction(@Validated @RequestBody DeployHistory resources, HttpServletRequest request, HttpServletResponse response)throws Exception{ public ResponseEntity serverReduction(@Validated @RequestBody DeployHistory resources){
String result = deployService.serverReduction(resources); String result = deployService.serverReduction(resources);
return new ResponseEntity(result,HttpStatus.OK); return new ResponseEntity<>(result,HttpStatus.OK);
} }
@Log("服务运行状态") @Log("服务运行状态")
@ApiOperation(value = "服务运行状态") @ApiOperation(value = "服务运行状态")
@PostMapping(value = "/serverStatus") @PostMapping(value = "/serverStatus")
@PreAuthorize("@el.check('deploy:edit')") @PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity serverStatus(@Validated @RequestBody Deploy resources, HttpServletRequest request, HttpServletResponse response)throws Exception{ public ResponseEntity serverStatus(@Validated @RequestBody Deploy resources){
String result = deployService.serverStatus(resources); String result = deployService.serverStatus(resources);
return new ResponseEntity(result,HttpStatus.OK); return new ResponseEntity<>(result,HttpStatus.OK);
} }
@Log("启动服务") @Log("启动服务")
@ApiOperation(value = "启动服务") @ApiOperation(value = "启动服务")
@PostMapping(value = "/startServer") @PostMapping(value = "/startServer")
@PreAuthorize("@el.check('deploy:edit')") @PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity startServer(@Validated @RequestBody Deploy resources, HttpServletRequest request, HttpServletResponse response)throws Exception{ public ResponseEntity startServer(@Validated @RequestBody Deploy resources){
String result = deployService.startServer(resources); String result = deployService.startServer(resources);
return new ResponseEntity(result,HttpStatus.OK); return new ResponseEntity<>(result,HttpStatus.OK);
} }
@Log("停止服务") @Log("停止服务")
@ApiOperation(value = "停止服务") @ApiOperation(value = "停止服务")
@PostMapping(value = "/stopServer") @PostMapping(value = "/stopServer")
@PreAuthorize("@el.check('deploy:edit')") @PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity stopServer(@Validated @RequestBody Deploy resources, HttpServletRequest request, HttpServletResponse response)throws Exception{ public ResponseEntity stopServer(@Validated @RequestBody Deploy resources){
String result = deployService.stopServer(resources); String result = deployService.stopServer(resources);
return new ResponseEntity(result,HttpStatus.OK); return new ResponseEntity<>(result,HttpStatus.OK);
} }
} }

View File

@ -23,19 +23,22 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/api/deployHistory") @RequestMapping("/api/deployHistory")
public class DeployHistoryController { public class DeployHistoryController {
@Autowired private final DeployHistoryService deployhistoryService;
private DeployHistoryService deployhistoryService;
@Log("查询DeployHistory") public DeployHistoryController(DeployHistoryService deployhistoryService) {
@ApiOperation(value = "查询DeployHistory") this.deployhistoryService = deployhistoryService;
}
@Log("查询部署历史")
@ApiOperation(value = "查询部署历史")
@GetMapping @GetMapping
@PreAuthorize("@el.check('deployHistory:list')") @PreAuthorize("@el.check('deployHistory:list')")
public ResponseEntity getDeployHistorys(DeployHistoryQueryCriteria criteria, Pageable pageable){ public ResponseEntity getDeployHistorys(DeployHistoryQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(deployhistoryService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(deployhistoryService.queryAll(criteria,pageable),HttpStatus.OK);
} }
@Log("删除DeployHistory") @Log("删除DeployHistory")
@ApiOperation(value = "删除DeployHistory") @ApiOperation(value = "删除部署历史")
@DeleteMapping(value = "/{id}") @DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('deployHistory:del')") @PreAuthorize("hasAnyRole('deployHistory:del')")
public ResponseEntity delete(@PathVariable String id){ public ResponseEntity delete(@PathVariable String id){

View File

@ -6,7 +6,6 @@ import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.mnt.domain.ServerDeploy; import me.zhengjie.modules.mnt.domain.ServerDeploy;
import me.zhengjie.modules.mnt.service.ServerDeployService; import me.zhengjie.modules.mnt.service.ServerDeployService;
import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria; import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -18,32 +17,35 @@ import org.springframework.web.bind.annotation.*;
* @author zhanghouying * @author zhanghouying
* @date 2019-08-24 * @date 2019-08-24
*/ */
@Api(tags = "服务器部署管理") @Api(tags = "服务器管理")
@RestController @RestController
@RequestMapping("/api/serverDeploy") @RequestMapping("/api/serverDeploy")
public class ServerDeployController { public class ServerDeployController {
@Autowired private final ServerDeployService serverDeployService;
private ServerDeployService serverDeployService;
@Log("查询Server") public ServerDeployController(ServerDeployService serverDeployService) {
@ApiOperation(value = "查询Server") this.serverDeployService = serverDeployService;
}
@Log("查询服务器")
@ApiOperation(value = "查询服务器")
@GetMapping @GetMapping
@PreAuthorize("@el.check('serverDeploy:list')") @PreAuthorize("@el.check('serverDeploy:list')")
public ResponseEntity getServers(ServerDeployQueryCriteria criteria, Pageable pageable){ public ResponseEntity getServers(ServerDeployQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(serverDeployService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(serverDeployService.queryAll(criteria,pageable),HttpStatus.OK);
} }
@Log("新增Server") @Log("新增服务器")
@ApiOperation(value = "新增Server") @ApiOperation(value = "新增服务器")
@PostMapping @PostMapping
@PreAuthorize("@el.check('serverDeploy:add')") @PreAuthorize("@el.check('serverDeploy:add')")
public ResponseEntity create(@Validated @RequestBody ServerDeploy resources){ public ResponseEntity create(@Validated @RequestBody ServerDeploy resources){
return new ResponseEntity(serverDeployService.create(resources),HttpStatus.CREATED); return new ResponseEntity<>(serverDeployService.create(resources),HttpStatus.CREATED);
} }
@Log("修改Server") @Log("修改服务器")
@ApiOperation(value = "修改Server") @ApiOperation(value = "修改服务器")
@PutMapping @PutMapping
@PreAuthorize("@el.check('serverDeploy:edit')") @PreAuthorize("@el.check('serverDeploy:edit')")
public ResponseEntity update(@Validated @RequestBody ServerDeploy resources){ public ResponseEntity update(@Validated @RequestBody ServerDeploy resources){
@ -51,7 +53,7 @@ public class ServerDeployController {
return new ResponseEntity(HttpStatus.NO_CONTENT); return new ResponseEntity(HttpStatus.NO_CONTENT);
} }
@Log("删除Server") @Log("删除服务器")
@ApiOperation(value = "删除Server") @ApiOperation(value = "删除Server")
@DeleteMapping(value = "/{id:.+}") @DeleteMapping(value = "/{id:.+}")
@PreAuthorize("@el.check('serverDeploy:del')") @PreAuthorize("@el.check('serverDeploy:del')")

View File

@ -11,44 +11,15 @@ import org.springframework.data.domain.Pageable;
*/ */
public interface AppService { public interface AppService {
/**
* queryAll
* @param criteria
* @param pageable
* @return
*/
Object queryAll(AppQueryCriteria criteria, Pageable pageable); Object queryAll(AppQueryCriteria criteria, Pageable pageable);
/** Object queryAll(AppQueryCriteria criteria);
* queryAll
* @param criteria
* @return
*/
public Object queryAll(AppQueryCriteria criteria);
/**
* findById
* @param id
* @return
*/
AppDTO findById(Long id); AppDTO findById(Long id);
/**
* create
* @param resources
* @return
*/
AppDTO create(App resources); AppDTO create(App resources);
/**
* update
* @param resources
*/
void update(App resources); void update(App resources);
/**
* delete
* @param id
*/
void delete(Long id); void delete(Long id);
} }

View File

@ -6,49 +6,20 @@ import me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
/** /**
* @author: ZhangHouYing * @author ZhangHouYing
* @date 2019-08-24 * @date 2019-08-24
*/ */
public interface DatabaseService { public interface DatabaseService {
/**
* queryAll
* @param criteria
* @param pageable
* @return
*/
Object queryAll(DatabaseQueryCriteria criteria, Pageable pageable); Object queryAll(DatabaseQueryCriteria criteria, Pageable pageable);
/** Object queryAll(DatabaseQueryCriteria criteria);
* queryAll
* @param criteria
* @return
*/
public Object queryAll(DatabaseQueryCriteria criteria);
/**
* findById
* @param id
* @return
*/
DatabaseDTO findById(String id); DatabaseDTO findById(String id);
/**
* create
* @param resources
* @return
*/
DatabaseDTO create(Database resources); DatabaseDTO create(Database resources);
/**
* update
* @param resources
*/
void update(Database resources); void update(Database resources);
/**
* delete
* @param id
*/
void delete(String id); void delete(String id);
} }

View File

@ -5,45 +5,15 @@ import me.zhengjie.modules.mnt.service.dto.DeployHistoryDTO;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria; import me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
/**
*
* @author: ZhangHouYing
* @date 2019-08-24
*/
public interface DeployHistoryService { public interface DeployHistoryService {
/**
* queryAll
* @param criteria
* @param pageable
* @return
*/
Object queryAll(DeployHistoryQueryCriteria criteria, Pageable pageable); Object queryAll(DeployHistoryQueryCriteria criteria, Pageable pageable);
/** Object queryAll(DeployHistoryQueryCriteria criteria);
* queryAll
* @param criteria
* @return
*/
public Object queryAll(DeployHistoryQueryCriteria criteria);
/**
* findById
* @param id
* @return
*/
DeployHistoryDTO findById(String id); DeployHistoryDTO findById(String id);
/**
* create
* @param resources
* @return
*/
DeployHistoryDTO create(DeployHistory resources); DeployHistoryDTO create(DeployHistory resources);
/**
* delete
* @param id
*/
void delete(String id); void delete(String id);
} }

View File

@ -12,81 +12,49 @@ import org.springframework.data.domain.Pageable;
*/ */
public interface DeployService { public interface DeployService {
/**
* queryAll
* @param criteria
* @param pageable
* @return
*/
Object queryAll(DeployQueryCriteria criteria, Pageable pageable); Object queryAll(DeployQueryCriteria criteria, Pageable pageable);
/** Object queryAll(DeployQueryCriteria criteria);
* queryAll
* @param criteria
* @return
*/
public Object queryAll(DeployQueryCriteria criteria);
/**
* findById
* @param id
* @return
*/
DeployDTO findById(Long id); DeployDTO findById(Long id);
/**
* create
* @CacheEvict(allEntries = true)
* @param resources
* @return
*/
DeployDTO create(Deploy resources); DeployDTO create(Deploy resources);
/**
* update
* @CacheEvict(allEntries = true)
* @param resources
*/
void update(Deploy resources); void update(Deploy resources);
/**
* delete
* @CacheEvict(allEntries = true)
* @param id
*/
void delete(Long id); void delete(Long id);
/** /**
* *
* @param fileSavePath * @param fileSavePath
* @param appId * @param appId ID
* @return * @return /
*/ */
public String deploy(String fileSavePath, Long appId); String deploy(String fileSavePath, Long appId);
/** /**
* *
* @param resources * @param resources /
* @return * @return /
*/ */
public String serverStatus(Deploy resources); String serverStatus(Deploy resources);
/** /**
* *
* @param resources * @param resources /
* @return * @return /
*/ */
public String startServer(Deploy resources); String startServer(Deploy resources);
/** /**
* *
* @param resources * @param resources /
* @return * @return /
*/ */
public String stopServer(Deploy resources); String stopServer(Deploy resources);
/** /**
* *
* @param resources * @param resources /
* @return * @return /
*/ */
public String serverReduction(DeployHistory resources); String serverReduction(DeployHistory resources);
} }

View File

@ -11,45 +11,16 @@ import org.springframework.data.domain.Pageable;
*/ */
public interface ServerDeployService { public interface ServerDeployService {
/**
* queryAll
* @param criteria
* @param pageable
* @return
*/
Object queryAll(ServerDeployQueryCriteria criteria, Pageable pageable); Object queryAll(ServerDeployQueryCriteria criteria, Pageable pageable);
/** Object queryAll(ServerDeployQueryCriteria criteria);
* queryAll
* @param criteria
* @return
*/
public Object queryAll(ServerDeployQueryCriteria criteria);
/**
* findById
* @param id
* @return
*/
ServerDeployDTO findById(Long id); ServerDeployDTO findById(Long id);
/**
* create
* @param resources
* @return
*/
ServerDeployDTO create(ServerDeploy resources); ServerDeployDTO create(ServerDeploy resources);
/**
* update
* @param resources
*/
void update(ServerDeploy resources); void update(ServerDeploy resources);
/**
* delete
* @param id
*/
void delete(Long id); void delete(Long id);
ServerDeployDTO findByIp(String ip); ServerDeployDTO findByIp(String ip);

View File

@ -16,7 +16,7 @@ public class AppDTO implements Serializable {
/** /**
* *
*/ */
private String id; private Long id;
/** /**
* *

View File

@ -1,8 +1,11 @@
package me.zhengjie.modules.mnt.service.dto; package me.zhengjie.modules.mnt.service.dto;
import cn.hutool.core.collection.CollectionUtil;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
/** /**
@ -24,9 +27,19 @@ public class DeployDTO implements Serializable {
*/ */
private Set<ServerDeployDTO> deploys; private Set<ServerDeployDTO> deploys;
private String servers;
/** /**
* *
*/ */
private String status; private String status;
private Timestamp createTime;
public String getServers() {
if(CollectionUtil.isNotEmpty(deploys)){
return deploys.stream().map(ServerDeployDTO::getName).collect(Collectors.joining(","));
}
return servers;
}
} }

View File

@ -2,6 +2,7 @@ package me.zhengjie.modules.mnt.service.dto;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Timestamp;
/** /**
@ -29,7 +30,7 @@ public class DeployHistoryDTO implements Serializable {
/** /**
* *
*/ */
private String deployDate; private Timestamp deployDate;
/** /**
* *

View File

@ -2,6 +2,8 @@ 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
@ -15,4 +17,7 @@ public class DeployHistoryQueryCriteria{
*/ */
@Query(blurry = "appName,ip,deployUser,deployId") @Query(blurry = "appName,ip,deployUser,deployId")
private String blurry; private String blurry;
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> deployDate;
} }

View File

@ -2,6 +2,8 @@ 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
@ -13,13 +15,10 @@ public class DeployQueryCriteria{
/** /**
* *
*/ */
@Query(type = Query.Type.EQUAL) @Query(type = Query.Type.INNER_LIKE, propName = "name", joinName = "app")
private String appId; private String appName;
/** @Query(type = Query.Type.BETWEEN)
* private List<Timestamp> createTime;
*/
@Query(type = Query.Type.INNER_LIKE)
private String ip;
} }

View File

@ -14,7 +14,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/** /**
* @author zhanghouying * @author zhanghouying
@ -46,9 +45,9 @@ public class AppServiceImpl implements AppService {
@Override @Override
public AppDTO findById(Long id) { public AppDTO findById(Long id) {
Optional<App> app = appRepository.findById(id); App app = appRepository.findById(id).orElseGet(App::new);
ValidationUtil.isNull(app,"App","id",id); ValidationUtil.isNull(app.getId(),"App","id",id);
return appMapper.toDto(app.get()); return appMapper.toDto(app);
} }
@Override @Override
@ -60,11 +59,10 @@ public class AppServiceImpl implements AppService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(App resources) { public void update(App resources) {
Optional<App> optionalApp = appRepository.findById(resources.getId()); App app = appRepository.findById(resources.getId()).orElseGet(App::new);
ValidationUtil.isNull( optionalApp,"App","id",resources.getId()); ValidationUtil.isNull(app.getId(),"App","id",resources.getId());
App App = optionalApp.get(); app.copy(resources);
App.copy(resources); appRepository.save(app);
appRepository.save(App);
} }
@Override @Override

View File

@ -16,8 +16,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/** /**
* @author zhanghouying * @author zhanghouying
* @date 2019-08-24 * @date 2019-08-24
@ -48,9 +46,9 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override @Override
public DatabaseDTO findById(String id) { public DatabaseDTO findById(String id) {
Optional<Database> database = databaseRepository.findById(id); Database database = databaseRepository.findById(id).orElseGet(Database::new);
ValidationUtil.isNull(database,"Database","id",id); ValidationUtil.isNull(database.getId(),"Database","id",id);
return databaseMapper.toDto(database.get()); return databaseMapper.toDto(database);
} }
@Override @Override
@ -63,9 +61,8 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(Database resources) { public void update(Database resources) {
Optional<Database> optionalDatabase = databaseRepository.findById(resources.getId()); Database database = databaseRepository.findById(resources.getId()).orElseGet(Database::new);
ValidationUtil.isNull( optionalDatabase,"Database","id",resources.getId()); ValidationUtil.isNull(database.getId(),"Database","id",resources.getId());
Database database = optionalDatabase.get();
database.copy(resources); database.copy(resources);
databaseRepository.save(database); databaseRepository.save(database);
} }

View File

@ -10,15 +10,12 @@ import me.zhengjie.modules.mnt.service.mapper.DeployHistoryMapper;
import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp; import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/** /**
* @author zhanghouying * @author zhanghouying
* @date 2019-08-24 * @date 2019-08-24
@ -27,11 +24,14 @@ import java.util.Optional;
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class DeployHistoryServiceImpl implements DeployHistoryService { public class DeployHistoryServiceImpl implements DeployHistoryService {
@Autowired private final DeployHistoryRepository deployhistoryRepository;
private DeployHistoryRepository deployhistoryRepository;
@Autowired private final DeployHistoryMapper deployhistoryMapper;
private DeployHistoryMapper deployhistoryMapper;
public DeployHistoryServiceImpl(DeployHistoryRepository deployhistoryRepository, DeployHistoryMapper deployhistoryMapper) {
this.deployhistoryRepository = deployhistoryRepository;
this.deployhistoryMapper = deployhistoryMapper;
}
@Override @Override
public Object queryAll(DeployHistoryQueryCriteria criteria, Pageable pageable){ public Object queryAll(DeployHistoryQueryCriteria criteria, Pageable pageable){
@ -46,9 +46,9 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
@Override @Override
public DeployHistoryDTO findById(String id) { public DeployHistoryDTO findById(String id) {
Optional<DeployHistory> deployhistory = deployhistoryRepository.findById(id); DeployHistory deployhistory = deployhistoryRepository.findById(id).orElseGet(DeployHistory::new);
ValidationUtil.isNull(deployhistory,"DeployHistory","id",id); ValidationUtil.isNull(deployhistory.getId(),"DeployHistory","id",id);
return deployhistoryMapper.toDto(deployhistory.get()); return deployhistoryMapper.toDto(deployhistory);
} }
@Override @Override

View File

@ -2,7 +2,6 @@ package me.zhengjie.modules.mnt.service.impl;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.mnt.domain.App; import me.zhengjie.modules.mnt.domain.App;
@ -22,18 +21,16 @@ import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp; import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.SecurityUtils; import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
/** /**
@ -47,23 +44,21 @@ public class DeployServiceImpl implements DeployService {
private final String FILE_SEPARATOR = File.separatorChar + ""; private final String FILE_SEPARATOR = File.separatorChar + "";
@Autowired private final DeployRepository deployRepository;
private DeployRepository deployRepository;
@Autowired private final DeployMapper deployMapper;
private DeployMapper deployMapper;
@Autowired private final ServerDeployService serverDeployService;
private AppService appService;
@Autowired private final DeployHistoryService deployHistoryService;
private ServerDeployService serverDeployService;
@Autowired public DeployServiceImpl(DeployRepository deployRepository, DeployMapper deployMapper, ServerDeployService serverDeployService, DeployHistoryService deployHistoryService) {
private DeployHistoryService deployHistoryService; this.deployRepository = deployRepository;
this.deployMapper = deployMapper;
this.serverDeployService = serverDeployService;
this.deployHistoryService = deployHistoryService;
}
@Autowired
private DatabaseService databaseService;
@Override @Override
public Object queryAll(DeployQueryCriteria criteria, Pageable pageable) { public Object queryAll(DeployQueryCriteria criteria, Pageable pageable) {
@ -78,9 +73,9 @@ public class DeployServiceImpl implements DeployService {
@Override @Override
public DeployDTO findById(Long id) { public DeployDTO findById(Long id) {
Optional<Deploy> Deploy = deployRepository.findById(id); Deploy Deploy = deployRepository.findById(id).orElseGet(Deploy::new);
ValidationUtil.isNull(Deploy, "Deploy", "id", id); ValidationUtil.isNull(Deploy.getId(), "Deploy", "id", id);
return deployMapper.toDto(Deploy.get()); return deployMapper.toDto(Deploy);
} }
@Override @Override
@ -92,9 +87,8 @@ public class DeployServiceImpl implements DeployService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(Deploy resources) { public void update(Deploy resources) {
Optional<Deploy> optionalDeploy = deployRepository.findById(resources.getId()); Deploy Deploy = deployRepository.findById(resources.getId()).orElseGet(Deploy::new);
ValidationUtil.isNull(optionalDeploy, "Deploy", "id", resources.getId()); ValidationUtil.isNull(Deploy.getId(), "Deploy", "id", resources.getId());
Deploy Deploy = optionalDeploy.get();
Deploy.copy(resources); Deploy.copy(resources);
deployRepository.save(Deploy); deployRepository.save(Deploy);
} }
@ -112,8 +106,8 @@ public class DeployServiceImpl implements DeployService {
/** /**
* @param fileSavePath * @param fileSavePath
* @param id * @param id ID
* @return * @return string
*/ */
private String deployApp(String fileSavePath, Long id) { private String deployApp(String fileSavePath, Long id) {
@ -131,7 +125,7 @@ public class DeployServiceImpl implements DeployService {
//这个是服务器部署路径 //这个是服务器部署路径
String uploadPath = app.getUploadPath(); String uploadPath = app.getUploadPath();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String msg = ""; String msg;
Set<ServerDeployDTO> deploys = deploy.getDeploys(); Set<ServerDeployDTO> deploys = deploy.getDeploys();
for (ServerDeployDTO deployDTO : deploys) { for (ServerDeployDTO deployDTO : deploys) {
String ip = deployDTO.getIp(); String ip = deployDTO.getIp();
@ -199,7 +193,6 @@ public class DeployServiceImpl implements DeployService {
//还原信息入库 //还原信息入库
DeployHistory deployHistory = new DeployHistory(); DeployHistory deployHistory = new DeployHistory();
deployHistory.setAppName(appName); deployHistory.setAppName(appName);
deployHistory.setDeployDate(deployDate);
deployHistory.setDeployUser(SecurityUtils.getUsername()); deployHistory.setDeployUser(SecurityUtils.getUsername());
deployHistory.setIp(ip); deployHistory.setIp(ip);
deployHistory.setDeployId(id); deployHistory.setDeployId(id);
@ -209,9 +202,8 @@ public class DeployServiceImpl implements DeployService {
/** /**
* App * App
* *
* @param port * @param port
* @param executeShellUtil * @param executeShellUtil /
* @return
*/ */
private void stopApp(int port, ExecuteShellUtil executeShellUtil) { private void stopApp(int port, ExecuteShellUtil executeShellUtil) {
//发送停止命令 //发送停止命令
@ -222,17 +214,13 @@ public class DeployServiceImpl implements DeployService {
/** /**
* *
* *
* @param port * @param port
* @param executeShellUtil * @param executeShellUtil /
* @return true false * @return true false
*/ */
private boolean checkIsRunningStatus(int port, ExecuteShellUtil executeShellUtil) { private boolean checkIsRunningStatus(int port, ExecuteShellUtil executeShellUtil) {
String statusResult = executeShellUtil.executeForResult(String.format("fuser -n tcp %d", port)); String statusResult = executeShellUtil.executeForResult(String.format("fuser -n tcp %d", port));
if ("".equals(statusResult.trim())) { return !"".equals(statusResult.trim());
return false;
} else {
return true;
}
} }
private void sendMsg(String msg, MsgType msgType) { private void sendMsg(String msg, MsgType msgType) {
@ -265,20 +253,17 @@ public class DeployServiceImpl implements DeployService {
} }
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDTO appDTO) { private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDTO appDTO) {
StringBuffer sb = new StringBuffer(); String sb = "find " +
sb.append("find "); appDTO.getDeployPath() +
sb.append(appDTO.getDeployPath()); " -name " +
sb.append(" -name "); appDTO.getName();
sb.append(appDTO.getName()); return executeShellUtil.executeShell(sb);
boolean flag = executeShellUtil.executeShell(sb.toString());
return flag;
} }
/** /**
* *
* * @param resources /
* @param resources * @return /
* @return
*/ */
@Override @Override
public String startServer(Deploy resources) { public String startServer(Deploy resources) {
@ -303,15 +288,15 @@ public class DeployServiceImpl implements DeployService {
/** /**
* *
* @param resources * @param resources /
* @return * @return /
*/ */
@Override @Override
public String stopServer(Deploy resources) { public String stopServer(Deploy resources) {
Set<ServerDeploy> deploys = resources.getDeploys(); Set<ServerDeploy> deploys = resources.getDeploys();
App app = resources.getApp(); App app = resources.getApp();
for (ServerDeploy deploy : deploys) { for (ServerDeploy deploy : deploys) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(deploy.getIp()); ExecuteShellUtil executeShellUtil = getExecuteShellUtil(deploy.getIp());
sb.append("服务器:").append(deploy.getName()).append("<br>应用:").append(app.getName()); sb.append("服务器:").append(deploy.getName()).append("<br>应用:").append(app.getName());
sendMsg("下发停止命令", MsgType.INFO); sendMsg("下发停止命令", MsgType.INFO);
@ -334,8 +319,8 @@ public class DeployServiceImpl implements DeployService {
@Override @Override
public String serverReduction(DeployHistory resources) { public String serverReduction(DeployHistory resources) {
Long deployId = resources.getDeployId(); Long deployId = resources.getDeployId();
Deploy deployInfo = deployRepository.findById(deployId).get(); Deploy deployInfo = deployRepository.findById(deployId).orElseGet(Deploy::new);
String deployDate = resources.getDeployDate(); Timestamp deployDate = resources.getDeployDate();
App app = deployInfo.getApp(); App app = deployInfo.getApp();
if (app == null) { if (app == null) {
sendMsg("应用信息不存在:" + resources.getAppName(), MsgType.ERROR); sendMsg("应用信息不存在:" + resources.getAppName(), MsgType.ERROR);
@ -350,7 +335,7 @@ public class DeployServiceImpl implements DeployService {
String deployPath = app.getDeployPath(); String deployPath = app.getDeployPath();
String ip = resources.getIp(); String ip = resources.getIp();
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip); ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip);
String msg = ""; String msg;
msg = String.format("登陆到服务器:%s", ip); msg = String.format("登陆到服务器:%s", ip);
log.info(msg); log.info(msg);
@ -398,7 +383,7 @@ public class DeployServiceImpl implements DeployService {
return ScpClientUtil.getInstance(ip, serverDeployDTO.getPort(), serverDeployDTO.getAccount(), serverDeployDTO.getPassword()); return ScpClientUtil.getInstance(ip, serverDeployDTO.getPort(), serverDeployDTO.getAccount(), serverDeployDTO.getPassword());
} }
public void sendResultMsg(boolean result, StringBuilder sb) { private void sendResultMsg(boolean result, StringBuilder sb) {
if (result) { if (result) {
sb.append("<br>启动成功!"); sb.append("<br>启动成功!");
sendMsg(sb.toString(), MsgType.INFO); sendMsg(sb.toString(), MsgType.INFO);

View File

@ -15,8 +15,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/** /**
* @author zhanghouying * @author zhanghouying
* @date 2019-08-24 * @date 2019-08-24
@ -47,9 +45,9 @@ public class ServerDeployServiceImpl implements ServerDeployService {
@Override @Override
public ServerDeployDTO findById(Long id) { public ServerDeployDTO findById(Long id) {
Optional<ServerDeploy> server = serverDeployRepository.findById(id); ServerDeploy server = serverDeployRepository.findById(id).orElseGet(ServerDeploy::new);
ValidationUtil.isNull(server,"ServerDeploy","id",id); ValidationUtil.isNull(server.getId(),"ServerDeploy","id",id);
return serverDeployMapper.toDto(server.get()); return serverDeployMapper.toDto(server);
} }
@Override @Override
@ -67,9 +65,8 @@ public class ServerDeployServiceImpl implements ServerDeployService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(ServerDeploy resources) { public void update(ServerDeploy resources) {
Optional<ServerDeploy> optionalServer = serverDeployRepository.findById(resources.getId()); ServerDeploy serverDeploy = serverDeployRepository.findById(resources.getId()).orElseGet(ServerDeploy::new);
ValidationUtil.isNull( optionalServer,"ServerDeploy","id",resources.getId()); ValidationUtil.isNull( serverDeploy.getId(),"ServerDeploy","id",resources.getId());
ServerDeploy serverDeploy = optionalServer.get();
serverDeploy.copy(resources); serverDeploy.copy(resources);
serverDeployRepository.save(serverDeploy); serverDeployRepository.save(serverDeploy);
} }

View File

@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author zhanghouying * @author zhanghouying
* @date 2019-08-24 * @date 2019-08-24
*/ */
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE) @Mapper(componentModel = "spring",uses = {AppMapper.class, ServerDeployMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface DeployMapper extends BaseMapper<DeployDTO, Deploy> { public interface DeployMapper extends BaseMapper<DeployDTO, Deploy> {
} }