Commit 554aa58c authored by Elune's avatar Elune
Browse files

代码优化

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