代码优化

pull/302/head
Elune 2019-12-18 21:06:48 +08:00
parent 8c7217eb7a
commit 554aa58c40
24 changed files with 325 additions and 110 deletions

View File

@ -27,7 +27,7 @@ public class GlobalExceptionHandler {
*
*/
@ExceptionHandler(Throwable.class)
public ResponseEntity handleException(Throwable e){
public ResponseEntity<ApiError> handleException(Throwable e){
// 打印堆栈信息
log.error(ThrowableUtil.getStackTrace(e));
return buildResponseEntity(ApiError.error(e.getMessage()));
@ -37,7 +37,7 @@ public class GlobalExceptionHandler {
* BadCredentialsException
*/
@ExceptionHandler(BadCredentialsException.class)
public ResponseEntity badCredentialsException(BadCredentialsException e){
public ResponseEntity<ApiError> badCredentialsException(BadCredentialsException e){
// 打印堆栈信息
String message = "坏的凭证".equals(e.getMessage()) ? "用户名或密码不正确" : e.getMessage();
log.error(message);

View File

@ -134,7 +134,7 @@ public class GeneratorServiceImpl implements GeneratorService {
}
@Override
public ResponseEntity preview(GenConfig genConfig, List<ColumnInfo> columns) {
public ResponseEntity<Object> preview(GenConfig genConfig, List<ColumnInfo> columns) {
if(genConfig.getId() == null){
throw new BadRequestException("请先配置生成器");
}

View File

@ -25,7 +25,7 @@ public class ServerMonitorController {
private static final double GB = 1024*1024*1024.00;
@GetMapping
public ResponseEntity getServerInfo(){
public ResponseEntity<Object> getServerInfo(){
Map<String,Object> resultMap = new HashMap<>(8);
try {
CpuInfo[] infoList = sigar.getCpuInfoList();

View File

@ -3,8 +3,11 @@ package me.zhengjie.modules.mnt.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author zhanghouying
@ -46,6 +49,8 @@ public class Database implements Serializable {
@Column(name = "user_name",nullable = false)
private String userName;
@CreationTimestamp
private Timestamp createTime;
public void copy(Database source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));

View File

@ -12,6 +12,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;
/**
* @author zhanghouying
@ -28,11 +31,19 @@ public class AppController {
this.appService = appService;
}
@Log("导出应用数据")
@ApiOperation("导出应用数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('app:list')")
public void download(HttpServletResponse response, AppQueryCriteria criteria) throws IOException {
appService.download(appService.queryAll(criteria), response);
}
@Log("查询应用")
@ApiOperation(value = "查询应用")
@GetMapping
@PreAuthorize("@el.check('app:list')")
public ResponseEntity getApps(AppQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getApps(AppQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(appService.queryAll(criteria,pageable),HttpStatus.OK);
}
@ -40,7 +51,7 @@ public class AppController {
@ApiOperation(value = "新增应用")
@PostMapping
@PreAuthorize("@el.check('app:add')")
public ResponseEntity create(@Validated @RequestBody App resources){
public ResponseEntity<Object> create(@Validated @RequestBody App resources){
return new ResponseEntity<>(appService.create(resources),HttpStatus.CREATED);
}
@ -48,17 +59,17 @@ public class AppController {
@ApiOperation(value = "修改应用")
@PutMapping
@PreAuthorize("@el.check('app:edit')")
public ResponseEntity update(@Validated @RequestBody App resources){
public ResponseEntity<Object> update(@Validated @RequestBody App resources){
appService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除应用")
@ApiOperation(value = "删除应用")
@DeleteMapping(value = "/{id}")
@DeleteMapping
@PreAuthorize("@el.check('app:del')")
public ResponseEntity delete(@PathVariable Long id){
appService.delete(id);
return new ResponseEntity(HttpStatus.OK);
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
appService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -17,9 +17,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.Set;
/**
* @author zhanghouying
@ -38,11 +40,19 @@ public class DatabaseController {
this.databaseService = databaseService;
}
@Log("导出数据库数据")
@ApiOperation("导出数据库数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('database:list')")
public void download(HttpServletResponse response, DatabaseQueryCriteria criteria) throws IOException {
databaseService.download(databaseService.queryAll(criteria), response);
}
@Log("查询数据库")
@ApiOperation(value = "查询数据库")
@GetMapping
@PreAuthorize("@el.check('database:list')")
public ResponseEntity getDatabases(DatabaseQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getDatabases(DatabaseQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(databaseService.queryAll(criteria,pageable),HttpStatus.OK);
}
@ -50,7 +60,7 @@ public class DatabaseController {
@ApiOperation(value = "新增数据库")
@PostMapping
@PreAuthorize("@el.check('database:add')")
public ResponseEntity create(@Validated @RequestBody Database resources){
public ResponseEntity<Object> create(@Validated @RequestBody Database resources){
return new ResponseEntity<>(databaseService.create(resources),HttpStatus.CREATED);
}
@ -58,25 +68,25 @@ public class DatabaseController {
@ApiOperation(value = "修改数据库")
@PutMapping
@PreAuthorize("@el.check('database:edit')")
public ResponseEntity update(@Validated @RequestBody Database resources){
public ResponseEntity<Object> update(@Validated @RequestBody Database resources){
databaseService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除数据库")
@ApiOperation(value = "删除数据库")
@DeleteMapping(value = "/{id}")
@DeleteMapping
@PreAuthorize("@el.check('database:del')")
public ResponseEntity delete(@PathVariable String id){
databaseService.delete(id);
return new ResponseEntity(HttpStatus.OK);
public ResponseEntity<Object> delete(@RequestBody Set<String> ids){
databaseService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("测试数据库链接")
@ApiOperation(value = "测试数据库链接")
@PostMapping("/testConnect")
@PreAuthorize("@el.check('database:testConnect')")
public ResponseEntity testConnect(@Validated @RequestBody Database resources){
public ResponseEntity<Object> testConnect(@Validated @RequestBody Database resources){
return new ResponseEntity<>(databaseService.testConnection(resources),HttpStatus.CREATED);
}
@ -84,7 +94,7 @@ public class DatabaseController {
@ApiOperation(value = "执行SQL脚本")
@PostMapping(value = "/upload")
@PreAuthorize("@el.check('database:add')")
public ResponseEntity upload(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{
public ResponseEntity<Object> upload(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{
String id = request.getParameter("id");
DatabaseDto database = databaseService.findById(id);
String fileName = "";

View File

@ -16,10 +16,13 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* @author zhanghouying
@ -38,11 +41,19 @@ public class DeployController {
this.deployService = deployService;
}
@Log("导出部署数据")
@ApiOperation("导出部署数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('database:list')")
public void download(HttpServletResponse response, DeployQueryCriteria criteria) throws IOException {
deployService.download(deployService.queryAll(criteria), response);
}
@Log("查询部署")
@ApiOperation(value = "查询部署")
@GetMapping
@PreAuthorize("@el.check('deploy:list')")
public ResponseEntity getDeploys(DeployQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getDeploys(DeployQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(deployService.queryAll(criteria,pageable),HttpStatus.OK);
}
@ -50,7 +61,7 @@ public class DeployController {
@ApiOperation(value = "新增部署")
@PostMapping
@PreAuthorize("@el.check('deploy:add')")
public ResponseEntity create(@Validated @RequestBody Deploy resources){
public ResponseEntity<Object> create(@Validated @RequestBody Deploy resources){
return new ResponseEntity<>(deployService.create(resources),HttpStatus.CREATED);
}
@ -58,25 +69,25 @@ public class DeployController {
@ApiOperation(value = "修改部署")
@PutMapping
@PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity update(@Validated @RequestBody Deploy resources){
public ResponseEntity<Object> update(@Validated @RequestBody Deploy resources){
deployService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除部署")
@ApiOperation(value = "删除部署")
@DeleteMapping(value = "/{id}")
@DeleteMapping
@PreAuthorize("@el.check('deploy:del')")
public ResponseEntity delete(@PathVariable Long id){
deployService.delete(id);
return new ResponseEntity(HttpStatus.OK);
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
deployService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("上传文件部署")
@ApiOperation(value = "上传文件部署")
@PostMapping(value = "/upload")
@PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity upload(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{
public ResponseEntity<Object> upload(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{
Long id = Long.valueOf(request.getParameter("id"));
String fileName = "";
if(file != null){
@ -99,7 +110,7 @@ public class DeployController {
@ApiOperation(value = "系统还原")
@PostMapping(value = "/serverReduction")
@PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity serverReduction(@Validated @RequestBody DeployHistory resources){
public ResponseEntity<Object> serverReduction(@Validated @RequestBody DeployHistory resources){
String result = deployService.serverReduction(resources);
return new ResponseEntity<>(result,HttpStatus.OK);
}
@ -107,7 +118,7 @@ public class DeployController {
@ApiOperation(value = "服务运行状态")
@PostMapping(value = "/serverStatus")
@PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity serverStatus(@Validated @RequestBody Deploy resources){
public ResponseEntity<Object> serverStatus(@Validated @RequestBody Deploy resources){
String result = deployService.serverStatus(resources);
return new ResponseEntity<>(result,HttpStatus.OK);
}
@ -115,7 +126,7 @@ public class DeployController {
@ApiOperation(value = "启动服务")
@PostMapping(value = "/startServer")
@PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity startServer(@Validated @RequestBody Deploy resources){
public ResponseEntity<Object> startServer(@Validated @RequestBody Deploy resources){
String result = deployService.startServer(resources);
return new ResponseEntity<>(result,HttpStatus.OK);
}
@ -123,7 +134,7 @@ public class DeployController {
@ApiOperation(value = "停止服务")
@PostMapping(value = "/stopServer")
@PreAuthorize("@el.check('deploy:edit')")
public ResponseEntity stopServer(@Validated @RequestBody Deploy resources){
public ResponseEntity<Object> stopServer(@Validated @RequestBody Deploy resources){
String result = deployService.stopServer(resources);
return new ResponseEntity<>(result,HttpStatus.OK);
}

View File

@ -3,16 +3,16 @@ package me.zhengjie.modules.mnt.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.mnt.domain.DeployHistory;
import me.zhengjie.modules.mnt.service.DeployHistoryService;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;
/**
* @author zhanghouying
@ -29,20 +29,28 @@ public class DeployHistoryController {
this.deployhistoryService = deployhistoryService;
}
@Log("导出部署历史数据")
@ApiOperation("导出部署历史数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('deployHistory:list')")
public void download(HttpServletResponse response, DeployHistoryQueryCriteria criteria) throws IOException {
deployhistoryService.download(deployhistoryService.queryAll(criteria), response);
}
@Log("查询部署历史")
@ApiOperation(value = "查询部署历史")
@GetMapping
@PreAuthorize("@el.check('deployHistory:list')")
public ResponseEntity getDeployHistorys(DeployHistoryQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getDeployHistorys(DeployHistoryQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(deployhistoryService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("删除DeployHistory")
@ApiOperation(value = "删除部署历史")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('deployHistory:del')")
public ResponseEntity delete(@PathVariable String id){
deployhistoryService.delete(id);
return new ResponseEntity(HttpStatus.OK);
@DeleteMapping
@PreAuthorize("@el.check('deployHistory:del')")
public ResponseEntity<Object> delete(@RequestBody Set<String> ids){
deployhistoryService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -12,6 +12,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;
/**
* @author zhanghouying
@ -28,11 +31,19 @@ public class ServerDeployController {
this.serverDeployService = serverDeployService;
}
@Log("导出服务器数据")
@ApiOperation("导出服务器数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('serverDeploy:list')")
public void download(HttpServletResponse response, ServerDeployQueryCriteria criteria) throws IOException {
serverDeployService.download(serverDeployService.queryAll(criteria), response);
}
@Log("查询服务器")
@ApiOperation(value = "查询服务器")
@GetMapping
@PreAuthorize("@el.check('serverDeploy:list')")
public ResponseEntity getServers(ServerDeployQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getServers(ServerDeployQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(serverDeployService.queryAll(criteria,pageable),HttpStatus.OK);
}
@ -40,7 +51,7 @@ public class ServerDeployController {
@ApiOperation(value = "新增服务器")
@PostMapping
@PreAuthorize("@el.check('serverDeploy:add')")
public ResponseEntity create(@Validated @RequestBody ServerDeploy resources){
public ResponseEntity<Object> create(@Validated @RequestBody ServerDeploy resources){
return new ResponseEntity<>(serverDeployService.create(resources),HttpStatus.CREATED);
}
@ -48,26 +59,25 @@ public class ServerDeployController {
@ApiOperation(value = "修改服务器")
@PutMapping
@PreAuthorize("@el.check('serverDeploy:edit')")
public ResponseEntity update(@Validated @RequestBody ServerDeploy resources){
public ResponseEntity<Object> update(@Validated @RequestBody ServerDeploy resources){
serverDeployService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除服务器")
@ApiOperation(value = "删除Server")
@DeleteMapping(value = "/{id:.+}")
@DeleteMapping
@PreAuthorize("@el.check('serverDeploy:del')")
public ResponseEntity delete(@PathVariable Long id){
serverDeployService.delete(id);
return new ResponseEntity(HttpStatus.OK);
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
serverDeployService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("测试连接服务器")
@ApiOperation(value = "测试连接服务器")
@PostMapping("/testConnect")
@PreAuthorize("@el.check('serverDeploy:add')")
public ResponseEntity testConnect(@Validated @RequestBody ServerDeploy resources){
public ResponseEntity<Object> testConnect(@Validated @RequestBody ServerDeploy resources){
return new ResponseEntity<>(serverDeployService.testConnect(resources),HttpStatus.CREATED);
}
}

View File

@ -5,6 +5,11 @@ import me.zhengjie.modules.mnt.service.dto.AppDto;
import me.zhengjie.modules.mnt.service.dto.AppQueryCriteria;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Set;
/**
* @author zhanghouying
* @date 2019-08-24
@ -24,7 +29,7 @@ public interface AppService {
* @param criteria
* @return /
*/
Object queryAll(AppQueryCriteria criteria);
List<AppDto> queryAll(AppQueryCriteria criteria);
/**
* ID
@ -48,7 +53,14 @@ public interface AppService {
/**
*
* @param id /
* @param ids /
*/
void delete(Long id);
void delete(Set<Long> ids);
/**
*
* @param queryAll /
* @param response /
*/
void download(List<AppDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -5,6 +5,11 @@ import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Set;
/**
* @author ZhangHouYing
* @date 2019-08-24
@ -24,7 +29,7 @@ public interface DatabaseService {
* @param criteria
* @return /
*/
Object queryAll(DatabaseQueryCriteria criteria);
List<DatabaseDto> queryAll(DatabaseQueryCriteria criteria);
/**
* ID
@ -48,14 +53,21 @@ public interface DatabaseService {
/**
*
* @param id /
* @param ids /
*/
void delete(String id);
void delete(Set<String> ids);
/**
*
* @param resources
* @return
* @param resources /
* @return /
*/
boolean testConnection(Database resources);
/**
*
* @param queryAll /
* @param response /
*/
void download(List<DatabaseDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -5,6 +5,11 @@ import me.zhengjie.modules.mnt.service.dto.DeployHistoryDto;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Set;
/**
* @author zhanghouying
*/
@ -23,7 +28,7 @@ public interface DeployHistoryService {
* @param criteria
* @return /
*/
Object queryAll(DeployHistoryQueryCriteria criteria);
List<DeployHistoryDto> queryAll(DeployHistoryQueryCriteria criteria);
/**
* ID
@ -41,7 +46,14 @@ public interface DeployHistoryService {
/**
*
* @param id /
* @param ids /
*/
void delete(String id);
void delete(Set<String> ids);
/**
*
* @param queryAll /
* @param response /
*/
void download(List<DeployHistoryDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -6,6 +6,11 @@ import me.zhengjie.modules.mnt.service.dto.DeployDto;
import me.zhengjie.modules.mnt.service.dto.DeployQueryCriteria;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Set;
/**
* @author zhanghouying
* @date 2019-08-24
@ -25,7 +30,7 @@ public interface DeployService {
* @param criteria
* @return /
*/
Object queryAll(DeployQueryCriteria criteria);
List<DeployDto> queryAll(DeployQueryCriteria criteria);
/**
* ID
@ -50,9 +55,9 @@ public interface DeployService {
/**
*
* @param id /
* @param ids /
*/
void delete(Long id);
void delete(Set<Long> ids);
/**
*
@ -86,4 +91,11 @@ public interface DeployService {
* @return /
*/
String serverReduction(DeployHistory resources);
/**
*
* @param queryAll /
* @param response /
*/
void download(List<DeployDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -5,6 +5,11 @@ import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Set;
/**
* @author zhanghouying
* @date 2019-08-24
@ -24,7 +29,7 @@ public interface ServerDeployService {
* @param criteria
* @return /
*/
Object queryAll(ServerDeployQueryCriteria criteria);
List<ServerDeployDto> queryAll(ServerDeployQueryCriteria criteria);
/**
* ID
@ -48,9 +53,9 @@ public interface ServerDeployService {
/**
*
* @param id /
* @param ids /
*/
void delete(Long id);
void delete(Set<Long> ids);
/**
* IP
@ -61,8 +66,15 @@ public interface ServerDeployService {
/**
*
* @param resources
* @return
* @param resources /
* @return /
*/
Boolean testConnect(ServerDeploy resources);
/**
*
* @param queryAll /
* @param response /
*/
void download(List<ServerDeployDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -2,6 +2,7 @@ package me.zhengjie.modules.mnt.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
@ -36,4 +37,5 @@ public class DatabaseDto implements Serializable {
*/
private String userName;
private Timestamp createTime;
}

View File

@ -3,6 +3,9 @@ package me.zhengjie.modules.mnt.service.dto;
import lombok.Data;
import me.zhengjie.annotation.Query;
import java.sql.Timestamp;
import java.util.List;
/**
* @author zhanghouying
* @date 2019-08-24
@ -21,4 +24,7 @@ public class DatabaseQueryCriteria{
*/
@Query
private String jdbcUrl;
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> createTime;
}

View File

@ -6,6 +6,7 @@ import me.zhengjie.modules.mnt.service.AppService;
import me.zhengjie.modules.mnt.service.dto.AppDto;
import me.zhengjie.modules.mnt.service.dto.AppQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.AppMapper;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
@ -14,6 +15,9 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
/**
* @author zhanghouying
@ -39,7 +43,7 @@ public class AppServiceImpl implements AppService {
}
@Override
public Object queryAll(AppQueryCriteria criteria){
public List<AppDto> queryAll(AppQueryCriteria criteria){
return appMapper.toDto(appRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@ -67,7 +71,27 @@ public class AppServiceImpl implements AppService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
appRepository.deleteById(id);
public void delete(Set<Long> ids) {
for (Long id : ids) {
appRepository.deleteById(id);
}
}
@Override
public void download(List<AppDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (AppDto appDto : queryAll) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("应用名称", appDto.getName());
map.put("端口", appDto.getPort());
map.put("上传目录", appDto.getUploadPath());
map.put("部署目录", appDto.getDeployPath());
map.put("备份目录", appDto.getBackupPath());
map.put("启动脚本", appDto.getStartScript());
map.put("部署脚本", appDto.getDeployScript());
map.put("创建日期", appDto.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

View File

@ -9,6 +9,7 @@ import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.DatabaseMapper;
import me.zhengjie.modules.mnt.util.SqlUtils;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
@ -18,6 +19,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
/**
* @author zhanghouying
* @date 2019-08-24
@ -43,7 +48,7 @@ public class DatabaseServiceImpl implements DatabaseService {
}
@Override
public Object queryAll(DatabaseQueryCriteria criteria){
public List<DatabaseDto> queryAll(DatabaseQueryCriteria criteria){
return databaseMapper.toDto(databaseRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@ -72,8 +77,10 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(String id) {
databaseRepository.deleteById(id);
public void delete(Set<String> ids) {
for (String id : ids) {
databaseRepository.deleteById(id);
}
}
@Override
@ -84,6 +91,19 @@ public class DatabaseServiceImpl implements DatabaseService {
log.error(e.getMessage());
return false;
}
}
@Override
public void download(List<DatabaseDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (DatabaseDto databaseDto : queryAll) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("数据库名称", databaseDto.getName());
map.put("数据库连接地址", databaseDto.getJdbcUrl());
map.put("用户名", databaseDto.getUserName());
map.put("创建日期", databaseDto.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

View File

@ -7,6 +7,7 @@ import me.zhengjie.modules.mnt.service.DeployHistoryService;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDto;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.DeployHistoryMapper;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
@ -16,6 +17,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
/**
* @author zhanghouying
* @date 2019-08-24
@ -40,7 +45,7 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
}
@Override
public Object queryAll(DeployHistoryQueryCriteria criteria){
public List<DeployHistoryDto> queryAll(DeployHistoryQueryCriteria criteria){
return deployhistoryMapper.toDto(deployhistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@ -60,7 +65,24 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(String id) {
deployhistoryRepository.deleteById(id);
public void delete(Set<String> ids) {
for (String id : ids) {
deployhistoryRepository.deleteById(id);
}
}
@Override
public void download(List<DeployHistoryDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (DeployHistoryDto deployHistoryDto : queryAll) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("部署编号", deployHistoryDto.getDeployId());
map.put("应用名称", deployHistoryDto.getAppName());
map.put("部署IP", deployHistoryDto.getIp());
map.put("部署时间", deployHistoryDto.getDeployDate());
map.put("部署人员", deployHistoryDto.getDeployUser());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

View File

@ -12,30 +12,22 @@ import me.zhengjie.modules.mnt.repository.DeployRepository;
import me.zhengjie.modules.mnt.service.DeployHistoryService;
import me.zhengjie.modules.mnt.service.DeployService;
import me.zhengjie.modules.mnt.service.ServerDeployService;
import me.zhengjie.modules.mnt.service.dto.AppDto;
import me.zhengjie.modules.mnt.service.dto.DeployDto;
import me.zhengjie.modules.mnt.service.dto.DeployQueryCriteria;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import me.zhengjie.modules.mnt.service.dto.*;
import me.zhengjie.modules.mnt.service.mapper.DeployMapper;
import me.zhengjie.modules.mnt.util.ExecuteShellUtil;
import me.zhengjie.modules.mnt.util.ScpClientUtil;
import me.zhengjie.modules.mnt.websocket.MsgType;
import me.zhengjie.modules.mnt.websocket.SocketMsg;
import me.zhengjie.modules.mnt.websocket.WebSocketServer;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* @author zhanghouying
@ -99,8 +91,10 @@ public class DeployServiceImpl implements DeployService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
deployRepository.deleteById(id);
public void delete(Set<Long> ids) {
for (Long id : ids) {
deployRepository.deleteById(id);
}
}
@Override
@ -111,9 +105,8 @@ public class DeployServiceImpl implements DeployService {
/**
* @param fileSavePath
* @param id ID
* @return string
*/
private String deployApp(String fileSavePath, Long id) {
private void deployApp(String fileSavePath, Long id) {
DeployDto deploy = findById(id);
if (deploy == null) {
@ -169,7 +162,6 @@ public class DeployServiceImpl implements DeployService {
sendResultMsg(result, sb);
executeShellUtil.close();
}
return "部署结束";
}
private void sleep(int second) {
@ -400,4 +392,17 @@ public class DeployServiceImpl implements DeployService {
sendMsg(sb.toString(), MsgType.ERROR);
}
}
@Override
public void download(List<DeployDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (DeployDto deployDto : queryAll) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("应用名称", deployDto.getApp().getName());
map.put("服务器", deployDto.getServers());
map.put("部署日期", deployDto.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

View File

@ -7,6 +7,7 @@ import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.ServerDeployMapper;
import me.zhengjie.modules.mnt.util.ExecuteShellUtil;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
@ -15,6 +16,9 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
/**
* @author zhanghouying
@ -40,7 +44,7 @@ public class ServerDeployServiceImpl implements ServerDeployService {
}
@Override
public Object queryAll(ServerDeployQueryCriteria criteria){
public List<ServerDeployDto> queryAll(ServerDeployQueryCriteria criteria){
return serverDeployMapper.toDto(serverDeployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@ -89,7 +93,24 @@ public class ServerDeployServiceImpl implements ServerDeployService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
serverDeployRepository.deleteById(id);
public void delete(Set<Long> ids) {
for (Long id : ids) {
serverDeployRepository.deleteById(id);
}
}
@Override
public void download(List<ServerDeployDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (ServerDeployDto deployDto : queryAll) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("服务器名称", deployDto.getName());
map.put("服务器IP", deployDto.getIp());
map.put("端口", deployDto.getPort());
map.put("账号", deployDto.getAccount());
map.put("创建日期", deployDto.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

View File

@ -198,7 +198,7 @@ public class UserServiceImpl implements UserService {
public void download(List<UserDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (UserDto userDTO : queryAll) {
List roles = userDTO.getRoles().stream().map(RoleSmallDto::getName).collect(Collectors.toList());
List<String> roles = userDTO.getRoles().stream().map(RoleSmallDto::getName).collect(Collectors.toList());
Map<String,Object> map = new LinkedHashMap<>();
map.put("用户名", userDTO.getUsername());
map.put("头像", userDTO.getAvatar());

View File

@ -101,7 +101,7 @@ public class AliPayController {
@AnonymousAccess
@SuppressWarnings("all")
@ApiOperation("支付异步通知(要公网访问)接收异步通知检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致根据trade_status进行后续业务处理")
public ResponseEntity notify(HttpServletRequest request){
public ResponseEntity<Object> notify(HttpServletRequest request){
AlipayConfig alipay = alipayService.find();
Map<String, String[]> parameterMap = request.getParameterMap();
//内容验签,防止黑客篡改参数
@ -118,8 +118,8 @@ public class AliPayController {
if(tradeStatus.equals(AliPayStatusEnum.SUCCESS.getValue())||tradeStatus.equals(AliPayStatusEnum.FINISHED.getValue())){
// 验证通过后应该根据业务需要处理订单
}
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
return new ResponseEntity(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}

View File

@ -77,8 +77,8 @@ public class PictureController {
@ApiOperation("多选删除图片")
@PreAuthorize("@el.check('pictures:del')")
@DeleteMapping
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
pictureService.deleteAll(ids);
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
}