删除不要的模块
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.base.BaseEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name="mnt_app")
|
||||
public class App extends BaseEntity implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "app_id")
|
||||
@ApiModelProperty(value = "ID", hidden = true)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "端口")
|
||||
private int port;
|
||||
|
||||
@ApiModelProperty(value = "上传路径")
|
||||
private String uploadPath;
|
||||
|
||||
@ApiModelProperty(value = "部署路径")
|
||||
private String deployPath;
|
||||
|
||||
@ApiModelProperty(value = "备份路径")
|
||||
private String backupPath;
|
||||
|
||||
@ApiModelProperty(value = "启动脚本")
|
||||
private String startScript;
|
||||
|
||||
@ApiModelProperty(value = "部署脚本")
|
||||
private String deployScript;
|
||||
|
||||
public void copy(App source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.base.BaseEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name="mnt_database")
|
||||
public class Database extends BaseEntity implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "db_id")
|
||||
@ApiModelProperty(value = "ID", hidden = true)
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "数据库名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "数据库连接地址")
|
||||
private String jdbcUrl;
|
||||
|
||||
@ApiModelProperty(value = "数据库密码")
|
||||
private String pwd;
|
||||
|
||||
@ApiModelProperty(value = "用户名")
|
||||
private String userName;
|
||||
|
||||
public void copy(Database source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.NotFound;
|
||||
import org.hibernate.annotations.NotFoundAction;
|
||||
import org.nl.base.BaseEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name="mnt_deploy")
|
||||
public class Deploy extends BaseEntity implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "deploy_id")
|
||||
@ApiModelProperty(value = "ID", hidden = true)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToMany
|
||||
@ApiModelProperty(name = "服务器", hidden = true)
|
||||
@JoinTable(name = "mnt_deploy_server",
|
||||
joinColumns = {@JoinColumn(name = "deploy_id",referencedColumnName = "deploy_id")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "server_id",referencedColumnName = "server_id")})
|
||||
private Set<ServerDeploy> deploys;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "app_id")
|
||||
@ApiModelProperty(value = "应用编号")
|
||||
@NotFound(action= NotFoundAction.IGNORE)
|
||||
private App app;
|
||||
|
||||
public void copy(Deploy source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name="mnt_deploy_history")
|
||||
public class DeployHistory implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "history_id")
|
||||
@ApiModelProperty(value = "ID", hidden = true)
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "应用名称")
|
||||
private String appName;
|
||||
|
||||
@ApiModelProperty(value = "IP")
|
||||
private String ip;
|
||||
|
||||
@CreationTimestamp
|
||||
@ApiModelProperty(value = "部署时间")
|
||||
private Timestamp deployDate;
|
||||
|
||||
@ApiModelProperty(value = "部署者")
|
||||
private String deployUser;
|
||||
|
||||
@ApiModelProperty(value = "部署ID")
|
||||
private Long deployId;
|
||||
|
||||
public void copy(DeployHistory source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.base.BaseEntity;
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name="mnt_server")
|
||||
public class ServerDeploy extends BaseEntity implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "server_id")
|
||||
@ApiModelProperty(value = "ID", hidden = true)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "服务器名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "IP")
|
||||
private String ip;
|
||||
|
||||
@ApiModelProperty(value = "端口")
|
||||
private Integer port;
|
||||
|
||||
@ApiModelProperty(value = "账号")
|
||||
private String account;
|
||||
|
||||
@ApiModelProperty(value = "密码")
|
||||
private String password;
|
||||
|
||||
public void copy(ServerDeploy source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ServerDeploy that = (ServerDeploy) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.repository;
|
||||
|
||||
import org.nl.modules.mnt.domain.App;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
public interface AppRepository extends JpaRepository<App, Long>, JpaSpecificationExecutor<App> {
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.repository;
|
||||
|
||||
import org.nl.modules.mnt.domain.Database;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
public interface DatabaseRepository extends JpaRepository<Database, String>, JpaSpecificationExecutor<Database> {
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.repository;
|
||||
|
||||
import org.nl.modules.mnt.domain.DeployHistory;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
public interface DeployHistoryRepository extends JpaRepository<DeployHistory, String>, JpaSpecificationExecutor<DeployHistory> {
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.repository;
|
||||
|
||||
import org.nl.modules.mnt.domain.Deploy;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
public interface DeployRepository extends JpaRepository<Deploy, Long>, JpaSpecificationExecutor<Deploy> {
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.repository;
|
||||
|
||||
import org.nl.modules.mnt.domain.ServerDeploy;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
public interface ServerDeployRepository extends JpaRepository<ServerDeploy, Long>, JpaSpecificationExecutor<ServerDeploy> {
|
||||
|
||||
/**
|
||||
* 根据IP查询
|
||||
* @param ip /
|
||||
* @return /
|
||||
*/
|
||||
ServerDeploy findByIp(String ip);
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.rest;
|
||||
|
||||
import org.nl.annotation.Log;
|
||||
import org.nl.modules.mnt.service.dto.AppQueryCriteria;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.mnt.domain.App;
|
||||
import org.nl.modules.mnt.service.AppService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
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
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "运维:应用管理")
|
||||
@RequestMapping("/api/app")
|
||||
public class AppController {
|
||||
|
||||
private final AppService appService;
|
||||
|
||||
@ApiOperation("导出应用数据")
|
||||
@GetMapping(value = "/download")
|
||||
@SaCheckPermission("app:list")
|
||||
public void download(HttpServletResponse response, AppQueryCriteria criteria) throws IOException {
|
||||
appService.download(appService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询应用")
|
||||
@GetMapping
|
||||
@SaCheckPermission("app:list")
|
||||
public ResponseEntity<Object> query(AppQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(appService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增应用")
|
||||
@ApiOperation(value = "新增应用")
|
||||
@PostMapping
|
||||
@SaCheckPermission("app:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody App resources){
|
||||
appService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改应用")
|
||||
@ApiOperation(value = "修改应用")
|
||||
@PutMapping
|
||||
@SaCheckPermission("app:edit")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody App resources){
|
||||
appService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除应用")
|
||||
@ApiOperation(value = "删除应用")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("app:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
||||
appService.delete(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.rest;
|
||||
|
||||
import org.nl.annotation.Log;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.modules.mnt.service.dto.DatabaseQueryCriteria;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.mnt.domain.Database;
|
||||
import org.nl.modules.mnt.service.DatabaseService;
|
||||
import org.nl.modules.mnt.service.dto.DatabaseDto;
|
||||
import org.nl.modules.mnt.util.SqlUtils;
|
||||
import org.nl.utils.FileUtil;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
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
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Api(tags = "运维:数据库管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/database")
|
||||
public class DatabaseController {
|
||||
|
||||
private final String fileSavePath = FileUtil.getTmpDirPath()+"/";
|
||||
private final DatabaseService databaseService;
|
||||
|
||||
@ApiOperation("导出数据库数据")
|
||||
@GetMapping(value = "/download")
|
||||
@SaCheckPermission("database:list")
|
||||
public void download(HttpServletResponse response, DatabaseQueryCriteria criteria) throws IOException {
|
||||
databaseService.download(databaseService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询数据库")
|
||||
@GetMapping
|
||||
@SaCheckPermission("database:list")
|
||||
public ResponseEntity<Object> query(DatabaseQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(databaseService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增数据库")
|
||||
@ApiOperation(value = "新增数据库")
|
||||
@PostMapping
|
||||
@SaCheckPermission("database:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody Database resources){
|
||||
databaseService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改数据库")
|
||||
@ApiOperation(value = "修改数据库")
|
||||
@PutMapping
|
||||
@SaCheckPermission("database:edit")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody Database resources){
|
||||
databaseService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除数据库")
|
||||
@ApiOperation(value = "删除数据库")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("database:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> ids){
|
||||
databaseService.delete(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("测试数据库链接")
|
||||
@ApiOperation(value = "测试数据库链接")
|
||||
@PostMapping("/testConnect")
|
||||
@SaCheckPermission("database:testConnect")
|
||||
public ResponseEntity<Object> testConnect(@Validated @RequestBody Database resources){
|
||||
return new ResponseEntity<>(databaseService.testConnection(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("执行SQL脚本")
|
||||
@ApiOperation(value = "执行SQL脚本")
|
||||
@PostMapping(value = "/upload")
|
||||
@SaCheckPermission("database:add")
|
||||
public ResponseEntity<Object> upload(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{
|
||||
String id = request.getParameter("id");
|
||||
DatabaseDto database = databaseService.findById(id);
|
||||
String fileName;
|
||||
if(database != null){
|
||||
fileName = file.getOriginalFilename();
|
||||
File executeFile = new File(fileSavePath+fileName);
|
||||
FileUtil.del(executeFile);
|
||||
file.transferTo(executeFile);
|
||||
String result = SqlUtils.executeFile(database.getJdbcUrl(), database.getUserName(), database.getPwd(), executeFile);
|
||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
||||
}else{
|
||||
throw new BadRequestException("Database not exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.rest;
|
||||
|
||||
import org.nl.annotation.Log;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.mnt.domain.Deploy;
|
||||
import org.nl.modules.mnt.domain.DeployHistory;
|
||||
import org.nl.modules.mnt.service.DeployService;
|
||||
import org.nl.modules.mnt.service.dto.DeployQueryCriteria;
|
||||
import org.nl.utils.FileUtil;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
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
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "运维:部署管理")
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/deploy")
|
||||
public class DeployController {
|
||||
|
||||
private final String fileSavePath = FileUtil.getTmpDirPath()+"/";
|
||||
private final DeployService deployService;
|
||||
|
||||
|
||||
@ApiOperation("导出部署数据")
|
||||
@GetMapping(value = "/download")
|
||||
@SaCheckPermission("database:list")
|
||||
public void download(HttpServletResponse response, DeployQueryCriteria criteria) throws IOException {
|
||||
deployService.download(deployService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询部署")
|
||||
@GetMapping
|
||||
@SaCheckPermission("deploy:list")
|
||||
public ResponseEntity<Object> query(DeployQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(deployService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增部署")
|
||||
@ApiOperation(value = "新增部署")
|
||||
@PostMapping
|
||||
@SaCheckPermission("deploy:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody Deploy resources){
|
||||
deployService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改部署")
|
||||
@ApiOperation(value = "修改部署")
|
||||
@PutMapping
|
||||
@SaCheckPermission("deploy:edit")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody Deploy resources){
|
||||
deployService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除部署")
|
||||
@ApiOperation(value = "删除部署")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("deploy:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
||||
deployService.delete(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("上传文件部署")
|
||||
@ApiOperation(value = "上传文件部署")
|
||||
@PostMapping(value = "/upload")
|
||||
@SaCheckPermission("deploy:edit")
|
||||
public ResponseEntity<Object> upload(@RequestBody MultipartFile file, HttpServletRequest request)throws Exception{
|
||||
Long id = Long.valueOf(request.getParameter("id"));
|
||||
String fileName = "";
|
||||
if(file != null){
|
||||
fileName = file.getOriginalFilename();
|
||||
File deployFile = new File(fileSavePath+fileName);
|
||||
FileUtil.del(deployFile);
|
||||
file.transferTo(deployFile);
|
||||
//文件下一步要根据文件名字来
|
||||
deployService.deploy(fileSavePath+fileName ,id);
|
||||
}else{
|
||||
System.out.println("没有找到相对应的文件");
|
||||
}
|
||||
System.out.println("文件上传的原名称为:"+ Objects.requireNonNull(file).getOriginalFilename());
|
||||
Map<String,Object> map = new HashMap<>(2);
|
||||
map.put("errno",0);
|
||||
map.put("id",fileName);
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
@Log("系统还原")
|
||||
@ApiOperation(value = "系统还原")
|
||||
@PostMapping(value = "/serverReduction")
|
||||
@SaCheckPermission("deploy:edit")
|
||||
public ResponseEntity<Object> serverReduction(@Validated @RequestBody DeployHistory resources){
|
||||
String result = deployService.serverReduction(resources);
|
||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
||||
}
|
||||
@Log("服务运行状态")
|
||||
@ApiOperation(value = "服务运行状态")
|
||||
@PostMapping(value = "/serverStatus")
|
||||
@SaCheckPermission("deploy:edit")
|
||||
public ResponseEntity<Object> serverStatus(@Validated @RequestBody Deploy resources){
|
||||
String result = deployService.serverStatus(resources);
|
||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
||||
}
|
||||
@Log("启动服务")
|
||||
@ApiOperation(value = "启动服务")
|
||||
@PostMapping(value = "/startServer")
|
||||
@SaCheckPermission("deploy:edit")
|
||||
public ResponseEntity<Object> startServer(@Validated @RequestBody Deploy resources){
|
||||
String result = deployService.startServer(resources);
|
||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
||||
}
|
||||
@Log("停止服务")
|
||||
@ApiOperation(value = "停止服务")
|
||||
@PostMapping(value = "/stopServer")
|
||||
@SaCheckPermission("deploy:edit")
|
||||
public ResponseEntity<Object> stopServer(@Validated @RequestBody Deploy resources){
|
||||
String result = deployService.stopServer(resources);
|
||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.rest;
|
||||
|
||||
import org.nl.annotation.Log;
|
||||
import org.nl.modules.mnt.service.dto.DeployHistoryQueryCriteria;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.mnt.service.DeployHistoryService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "运维:部署历史管理")
|
||||
@RequestMapping("/api/deployHistory")
|
||||
public class DeployHistoryController {
|
||||
|
||||
private final DeployHistoryService deployhistoryService;
|
||||
|
||||
@ApiOperation("导出部署历史数据")
|
||||
@GetMapping(value = "/download")
|
||||
@SaCheckPermission("deployHistory:list")
|
||||
public void download(HttpServletResponse response, DeployHistoryQueryCriteria criteria) throws IOException {
|
||||
deployhistoryService.download(deployhistoryService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询部署历史")
|
||||
@GetMapping
|
||||
@SaCheckPermission("deployHistory:list")
|
||||
public ResponseEntity<Object> query(DeployHistoryQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(deployhistoryService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("删除DeployHistory")
|
||||
@ApiOperation(value = "删除部署历史")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("deployHistory:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> ids){
|
||||
deployhistoryService.delete(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.rest;
|
||||
|
||||
import org.nl.annotation.Log;
|
||||
import org.nl.modules.mnt.domain.ServerDeploy;
|
||||
import org.nl.modules.mnt.service.ServerDeployService;
|
||||
import org.nl.modules.mnt.service.dto.ServerDeployQueryCriteria;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
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
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "运维:服务器管理")
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/serverDeploy")
|
||||
public class ServerDeployController {
|
||||
|
||||
private final ServerDeployService serverDeployService;
|
||||
|
||||
@ApiOperation("导出服务器数据")
|
||||
@GetMapping(value = "/download")
|
||||
@SaCheckPermission("serverDeploy:list")
|
||||
public void download(HttpServletResponse response, ServerDeployQueryCriteria criteria) throws IOException {
|
||||
serverDeployService.download(serverDeployService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询服务器")
|
||||
@GetMapping
|
||||
@SaCheckPermission("serverDeploy:list")
|
||||
public ResponseEntity<Object> query(ServerDeployQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(serverDeployService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增服务器")
|
||||
@ApiOperation(value = "新增服务器")
|
||||
@PostMapping
|
||||
@SaCheckPermission("serverDeploy:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody ServerDeploy resources){
|
||||
serverDeployService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改服务器")
|
||||
@ApiOperation(value = "修改服务器")
|
||||
@PutMapping
|
||||
@SaCheckPermission("serverDeploy:edit")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody ServerDeploy resources){
|
||||
serverDeployService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除服务器")
|
||||
@ApiOperation(value = "删除Server")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("serverDeploy:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
||||
serverDeployService.delete(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("测试连接服务器")
|
||||
@ApiOperation(value = "测试连接服务器")
|
||||
@PostMapping("/testConnect")
|
||||
@SaCheckPermission("serverDeploy:add")
|
||||
public ResponseEntity<Object> testConnect(@Validated @RequestBody ServerDeploy resources){
|
||||
return new ResponseEntity<>(serverDeployService.testConnect(resources),HttpStatus.CREATED);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service;
|
||||
|
||||
import org.nl.modules.mnt.domain.App;
|
||||
import org.nl.modules.mnt.service.dto.AppDto;
|
||||
import org.nl.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
|
||||
*/
|
||||
public interface AppService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object queryAll(AppQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<AppDto> queryAll(AppQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
AppDto findById(Long id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
*/
|
||||
void create(App resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(App resources);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids /
|
||||
*/
|
||||
void delete(Set<Long> ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param queryAll /
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<AppDto> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service;
|
||||
|
||||
import org.nl.modules.mnt.domain.Database;
|
||||
import org.nl.modules.mnt.service.dto.DatabaseDto;
|
||||
import org.nl.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
|
||||
*/
|
||||
public interface DatabaseService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object queryAll(DatabaseQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<DatabaseDto> queryAll(DatabaseQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
DatabaseDto findById(String id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
*/
|
||||
void create(Database resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(Database resources);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids /
|
||||
*/
|
||||
void delete(Set<String> ids);
|
||||
|
||||
/**
|
||||
* 测试连接数据库
|
||||
* @param resources /
|
||||
* @return /
|
||||
*/
|
||||
boolean testConnection(Database resources);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param queryAll /
|
||||
* @param response /
|
||||
* @throws IOException e
|
||||
*/
|
||||
void download(List<DatabaseDto> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service;
|
||||
|
||||
import org.nl.modules.mnt.domain.DeployHistory;
|
||||
import org.nl.modules.mnt.service.dto.DeployHistoryDto;
|
||||
import org.nl.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
|
||||
*/
|
||||
public interface DeployHistoryService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object queryAll(DeployHistoryQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<DeployHistoryDto> queryAll(DeployHistoryQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
DeployHistoryDto findById(String id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
*/
|
||||
void create(DeployHistory resources);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids /
|
||||
*/
|
||||
void delete(Set<String> ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param queryAll /
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<DeployHistoryDto> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service;
|
||||
|
||||
import org.nl.modules.mnt.domain.Deploy;
|
||||
import org.nl.modules.mnt.domain.DeployHistory;
|
||||
import org.nl.modules.mnt.service.dto.DeployDto;
|
||||
import org.nl.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
|
||||
*/
|
||||
public interface DeployService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object queryAll(DeployQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<DeployDto> queryAll(DeployQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
DeployDto findById(Long id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
*/
|
||||
void create(Deploy resources);
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(Deploy resources);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids /
|
||||
*/
|
||||
void delete(Set<Long> ids);
|
||||
|
||||
/**
|
||||
* 部署文件到服务器
|
||||
* @param fileSavePath 文件路径
|
||||
* @param appId 应用ID
|
||||
*/
|
||||
void deploy(String fileSavePath, Long appId);
|
||||
|
||||
/**
|
||||
* 查询部署状态
|
||||
* @param resources /
|
||||
* @return /
|
||||
*/
|
||||
String serverStatus(Deploy resources);
|
||||
/**
|
||||
* 启动服务
|
||||
* @param resources /
|
||||
* @return /
|
||||
*/
|
||||
String startServer(Deploy resources);
|
||||
/**
|
||||
* 停止服务
|
||||
* @param resources /
|
||||
* @return /
|
||||
*/
|
||||
String stopServer(Deploy resources);
|
||||
|
||||
/**
|
||||
* 停止服务
|
||||
* @param resources /
|
||||
* @return /
|
||||
*/
|
||||
String serverReduction(DeployHistory resources);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param queryAll /
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<DeployDto> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service;
|
||||
|
||||
import org.nl.modules.mnt.domain.ServerDeploy;
|
||||
import org.nl.modules.mnt.service.dto.ServerDeployDto;
|
||||
import org.nl.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
|
||||
*/
|
||||
public interface ServerDeployService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object queryAll(ServerDeployQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<ServerDeployDto> queryAll(ServerDeployQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id /
|
||||
* @return /
|
||||
*/
|
||||
ServerDeployDto findById(Long id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
*/
|
||||
void create(ServerDeploy resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(ServerDeploy resources);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids /
|
||||
*/
|
||||
void delete(Set<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据IP查询
|
||||
* @param ip /
|
||||
* @return /
|
||||
*/
|
||||
ServerDeployDto findByIp(String ip);
|
||||
|
||||
/**
|
||||
* 测试登录服务器
|
||||
* @param resources /
|
||||
* @return /
|
||||
*/
|
||||
Boolean testConnect(ServerDeploy resources);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param queryAll /
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<ServerDeployDto> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.base.BaseDTO;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class AppDto extends BaseDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 应用编号
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 应用名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 上传目录
|
||||
*/
|
||||
private String uploadPath;
|
||||
|
||||
/**
|
||||
* 部署目录
|
||||
*/
|
||||
private String deployPath;
|
||||
|
||||
/**
|
||||
* 备份目录
|
||||
*/
|
||||
private String backupPath;
|
||||
|
||||
/**
|
||||
* 启动脚本
|
||||
*/
|
||||
private String startScript;
|
||||
|
||||
/**
|
||||
* 部署脚本
|
||||
*/
|
||||
private String deployScript;
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.annotation.Query;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class AppQueryCriteria{
|
||||
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.base.BaseDTO;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DatabaseDto extends BaseDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 数据库连接地址
|
||||
*/
|
||||
private String jdbcUrl;
|
||||
|
||||
/**
|
||||
* 数据库密码
|
||||
*/
|
||||
private String pwd;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.annotation.Query;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class DatabaseQueryCriteria{
|
||||
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 精确
|
||||
*/
|
||||
@Query
|
||||
private String jdbcUrl;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.base.BaseDTO;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DeployDto extends BaseDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 部署编号
|
||||
*/
|
||||
private String id;
|
||||
|
||||
private AppDto app;
|
||||
|
||||
/**
|
||||
* 服务器
|
||||
*/
|
||||
private Set<ServerDeployDto> deploys;
|
||||
|
||||
private String servers;
|
||||
|
||||
/**
|
||||
* 服务状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
public String getServers() {
|
||||
if(CollectionUtil.isNotEmpty(deploys)){
|
||||
return deploys.stream().map(ServerDeployDto::getName).collect(Collectors.joining(","));
|
||||
}
|
||||
return servers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DeployDto deployDto = (DeployDto) o;
|
||||
return Objects.equals(id, deployDto.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class DeployHistoryDto implements Serializable {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 应用名称
|
||||
*/
|
||||
private String appName;
|
||||
|
||||
/**
|
||||
* 部署IP
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 部署时间
|
||||
*/
|
||||
private Timestamp deployDate;
|
||||
|
||||
/**
|
||||
* 部署人员
|
||||
*/
|
||||
private String deployUser;
|
||||
|
||||
/**
|
||||
* 部署编号
|
||||
*/
|
||||
private Long deployId;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.annotation.Query;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class DeployHistoryQueryCriteria{
|
||||
|
||||
/**
|
||||
* 精确
|
||||
*/
|
||||
@Query(blurry = "appName,ip,deployUser")
|
||||
private String blurry;
|
||||
|
||||
@Query
|
||||
private Long deployId;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> deployDate;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.annotation.Query;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class DeployQueryCriteria{
|
||||
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
@Query(type = Query.Type.INNER_LIKE, propName = "name", joinName = "app")
|
||||
private String appName;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.base.BaseDTO;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ServerDeployDto extends BaseDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String ip;
|
||||
|
||||
private Integer port;
|
||||
|
||||
private String account;
|
||||
|
||||
private String password;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ServerDeployDto that = (ServerDeployDto) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.annotation.Query;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Data
|
||||
public class ServerDeployQueryCriteria{
|
||||
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
@Query(blurry = "name,ip,account")
|
||||
private String blurry;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.mnt.domain.App;
|
||||
import org.nl.modules.mnt.repository.AppRepository;
|
||||
import org.nl.modules.mnt.service.AppService;
|
||||
import org.nl.modules.mnt.service.dto.AppDto;
|
||||
import org.nl.modules.mnt.service.dto.AppQueryCriteria;
|
||||
import org.nl.modules.mnt.service.mapstruct.AppMapper;
|
||||
import org.nl.utils.FileUtil;
|
||||
import org.nl.utils.PageUtil;
|
||||
import org.nl.utils.QueryHelp;
|
||||
import org.nl.utils.ValidationUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AppServiceImpl implements AppService {
|
||||
|
||||
private final AppRepository appRepository;
|
||||
private final AppMapper appMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(AppQueryCriteria criteria, Pageable pageable){
|
||||
Page<App> page = appRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(appMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppDto> queryAll(AppQueryCriteria criteria){
|
||||
return appMapper.toDto(appRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppDto findById(Long id) {
|
||||
App app = appRepository.findById(id).orElseGet(App::new);
|
||||
ValidationUtil.isNull(app.getId(),"App","id",id);
|
||||
return appMapper.toDto(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(App resources) {
|
||||
verification(resources);
|
||||
appRepository.save(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(App resources) {
|
||||
verification(resources);
|
||||
App app = appRepository.findById(resources.getId()).orElseGet(App::new);
|
||||
ValidationUtil.isNull(app.getId(),"App","id",resources.getId());
|
||||
app.copy(resources);
|
||||
appRepository.save(app);
|
||||
}
|
||||
|
||||
private void verification(App resources){
|
||||
String opt = "/opt";
|
||||
String home = "/home";
|
||||
/* if (!(resources.getUploadPath().startsWith(opt) || resources.getUploadPath().startsWith(home))) {
|
||||
throw new BadRequestException("文件只能上传在opt目录或者home目录 ");
|
||||
}
|
||||
if (!(resources.getDeployPath().startsWith(opt) || resources.getDeployPath().startsWith(home))) {
|
||||
throw new BadRequestException("文件只能部署在opt目录或者home目录 ");
|
||||
}
|
||||
if (!(resources.getBackupPath().startsWith(opt) || resources.getBackupPath().startsWith(home))) {
|
||||
throw new BadRequestException("文件只能备份在opt目录或者home目录 ");
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.modules.mnt.domain.Database;
|
||||
import org.nl.modules.mnt.repository.DatabaseRepository;
|
||||
import org.nl.modules.mnt.service.DatabaseService;
|
||||
import org.nl.modules.mnt.service.dto.DatabaseDto;
|
||||
import org.nl.modules.mnt.service.dto.DatabaseQueryCriteria;
|
||||
import org.nl.modules.mnt.service.mapstruct.DatabaseMapper;
|
||||
import org.nl.modules.mnt.util.SqlUtils;
|
||||
import org.nl.utils.FileUtil;
|
||||
import org.nl.utils.PageUtil;
|
||||
import org.nl.utils.QueryHelp;
|
||||
import org.nl.utils.ValidationUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DatabaseServiceImpl implements DatabaseService {
|
||||
|
||||
private final DatabaseRepository databaseRepository;
|
||||
private final DatabaseMapper databaseMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(DatabaseQueryCriteria criteria, Pageable pageable){
|
||||
Page<Database> page = databaseRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(databaseMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DatabaseDto> queryAll(DatabaseQueryCriteria criteria){
|
||||
return databaseMapper.toDto(databaseRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseDto findById(String id) {
|
||||
Database database = databaseRepository.findById(id).orElseGet(Database::new);
|
||||
ValidationUtil.isNull(database.getId(),"Database","id",id);
|
||||
return databaseMapper.toDto(database);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(Database resources) {
|
||||
resources.setId(IdUtil.simpleUUID());
|
||||
databaseRepository.save(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Database resources) {
|
||||
Database database = databaseRepository.findById(resources.getId()).orElseGet(Database::new);
|
||||
ValidationUtil.isNull(database.getId(),"Database","id",resources.getId());
|
||||
database.copy(resources);
|
||||
databaseRepository.save(database);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<String> ids) {
|
||||
for (String id : ids) {
|
||||
databaseRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testConnection(Database resources) {
|
||||
try {
|
||||
return SqlUtils.testConnection(resources.getJdbcUrl(), resources.getUserName(), resources.getPwd());
|
||||
} catch (Exception e) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.mnt.domain.DeployHistory;
|
||||
import org.nl.modules.mnt.repository.DeployHistoryRepository;
|
||||
import org.nl.modules.mnt.service.DeployHistoryService;
|
||||
import org.nl.modules.mnt.service.dto.DeployHistoryDto;
|
||||
import org.nl.modules.mnt.service.dto.DeployHistoryQueryCriteria;
|
||||
import org.nl.modules.mnt.service.mapstruct.DeployHistoryMapper;
|
||||
import org.nl.utils.FileUtil;
|
||||
import org.nl.utils.PageUtil;
|
||||
import org.nl.utils.QueryHelp;
|
||||
import org.nl.utils.ValidationUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeployHistoryServiceImpl implements DeployHistoryService {
|
||||
|
||||
private final DeployHistoryRepository deployhistoryRepository;
|
||||
private final DeployHistoryMapper deployhistoryMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(DeployHistoryQueryCriteria criteria, Pageable pageable){
|
||||
Page<DeployHistory> page = deployhistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(deployhistoryMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeployHistoryDto> queryAll(DeployHistoryQueryCriteria criteria){
|
||||
return deployhistoryMapper.toDto(deployhistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployHistoryDto findById(String id) {
|
||||
DeployHistory deployhistory = deployhistoryRepository.findById(id).orElseGet(DeployHistory::new);
|
||||
ValidationUtil.isNull(deployhistory.getId(),"DeployHistory","id",id);
|
||||
return deployhistoryMapper.toDto(deployhistory);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(DeployHistory resources) {
|
||||
resources.setId(IdUtil.simpleUUID());
|
||||
deployhistoryRepository.save(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,431 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.modules.mnt.domain.App;
|
||||
import org.nl.modules.mnt.domain.Deploy;
|
||||
import org.nl.modules.mnt.domain.DeployHistory;
|
||||
import org.nl.modules.mnt.domain.ServerDeploy;
|
||||
import org.nl.modules.mnt.repository.DeployRepository;
|
||||
import org.nl.modules.mnt.service.DeployHistoryService;
|
||||
import org.nl.modules.mnt.service.DeployService;
|
||||
import org.nl.modules.mnt.service.ServerDeployService;
|
||||
import org.nl.modules.mnt.service.dto.AppDto;
|
||||
import org.nl.modules.mnt.service.dto.DeployDto;
|
||||
import org.nl.modules.mnt.service.dto.DeployQueryCriteria;
|
||||
import org.nl.modules.mnt.service.dto.ServerDeployDto;
|
||||
import org.nl.modules.mnt.service.mapstruct.DeployMapper;
|
||||
import org.nl.modules.mnt.util.ExecuteShellUtil;
|
||||
import org.nl.modules.mnt.util.ScpClientUtil;
|
||||
import org.nl.modules.mnt.websocket.MsgType;
|
||||
import org.nl.modules.mnt.websocket.SocketMsg;
|
||||
import org.nl.modules.mnt.websocket.WebSocketServer;
|
||||
|
||||
import org.nl.utils.*;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeployServiceImpl implements DeployService {
|
||||
|
||||
private final String FILE_SEPARATOR = "/";
|
||||
private final DeployRepository deployRepository;
|
||||
private final DeployMapper deployMapper;
|
||||
private final ServerDeployService serverDeployService;
|
||||
private final DeployHistoryService deployHistoryService;
|
||||
/**
|
||||
* 循环次数
|
||||
*/
|
||||
private final Integer count = 30;
|
||||
|
||||
|
||||
@Override
|
||||
public Object queryAll(DeployQueryCriteria criteria, Pageable pageable) {
|
||||
Page<Deploy> page = deployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
||||
return PageUtil.toPage(page.map(deployMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeployDto> queryAll(DeployQueryCriteria criteria) {
|
||||
return deployMapper.toDto(deployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeployDto findById(Long id) {
|
||||
Deploy deploy = deployRepository.findById(id).orElseGet(Deploy::new);
|
||||
ValidationUtil.isNull(deploy.getId(), "Deploy", "id", id);
|
||||
return deployMapper.toDto(deploy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(Deploy resources) {
|
||||
deployRepository.save(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Deploy resources) {
|
||||
Deploy deploy = deployRepository.findById(resources.getId()).orElseGet(Deploy::new);
|
||||
ValidationUtil.isNull(deploy.getId(), "Deploy", "id", resources.getId());
|
||||
deploy.copy(resources);
|
||||
deployRepository.save(deploy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Set<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
deployRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deploy(String fileSavePath, Long id) {
|
||||
deployApp(fileSavePath, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileSavePath 本机路径
|
||||
* @param id ID
|
||||
*/
|
||||
private void deployApp(String fileSavePath, Long id) {
|
||||
|
||||
DeployDto deploy = findById(id);
|
||||
if (deploy == null) {
|
||||
sendMsg("部署信息不存在", MsgType.ERROR);
|
||||
throw new BadRequestException("部署信息不存在");
|
||||
}
|
||||
AppDto app = deploy.getApp();
|
||||
if (app == null) {
|
||||
sendMsg("包对应应用信息不存在", MsgType.ERROR);
|
||||
throw new BadRequestException("包对应应用信息不存在");
|
||||
}
|
||||
int port = app.getPort();
|
||||
//这个是服务器部署路径
|
||||
String uploadPath = app.getUploadPath();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String msg;
|
||||
Set<ServerDeployDto> deploys = deploy.getDeploys();
|
||||
for (ServerDeployDto deployDTO : deploys) {
|
||||
String ip = deployDTO.getIp();
|
||||
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip);
|
||||
//判断是否第一次部署
|
||||
boolean flag = checkFile(executeShellUtil, app);
|
||||
//第一步要确认服务器上有这个目录
|
||||
executeShellUtil.execute("mkdir -p " + app.getUploadPath());
|
||||
executeShellUtil.execute("mkdir -p " + app.getBackupPath());
|
||||
executeShellUtil.execute("mkdir -p " + app.getDeployPath());
|
||||
//上传文件
|
||||
msg = String.format("登陆到服务器:%s", ip);
|
||||
ScpClientUtil scpClientUtil = getScpClientUtil(ip);
|
||||
log.info(msg);
|
||||
sendMsg(msg, MsgType.INFO);
|
||||
msg = String.format("上传文件到服务器:%s<br>目录:%s下,请稍等...", ip, uploadPath);
|
||||
sendMsg(msg, MsgType.INFO);
|
||||
scpClientUtil.putFile(fileSavePath, uploadPath);
|
||||
if (flag) {
|
||||
sendMsg("停止原来应用", MsgType.INFO);
|
||||
//停止应用
|
||||
stopApp(port, executeShellUtil);
|
||||
sendMsg("备份原来应用", MsgType.INFO);
|
||||
//备份应用
|
||||
backupApp(executeShellUtil, ip, app.getDeployPath()+FILE_SEPARATOR, app.getName(), app.getBackupPath()+FILE_SEPARATOR, id);
|
||||
}
|
||||
sendMsg("部署应用", MsgType.INFO);
|
||||
//部署文件,并启动应用
|
||||
String deployScript = app.getDeployScript();
|
||||
executeShellUtil.execute(deployScript);
|
||||
sleep(3);
|
||||
sendMsg("应用部署中,请耐心等待部署结果,或者稍后手动查看部署状态", MsgType.INFO);
|
||||
int i = 0;
|
||||
boolean result = false;
|
||||
// 由于启动应用需要时间,所以需要循环获取状态,如果超过30次,则认为是启动失败
|
||||
while (i++ < count){
|
||||
result = checkIsRunningStatus(port, executeShellUtil);
|
||||
if(result){
|
||||
break;
|
||||
}
|
||||
// 休眠6秒
|
||||
sleep(6);
|
||||
}
|
||||
sb.append("服务器:").append(deployDTO.getName()).append("<br>应用:").append(app.getName());
|
||||
sendResultMsg(result, sb);
|
||||
executeShellUtil.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void sleep(int second) {
|
||||
try {
|
||||
Thread.sleep(second * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
private void backupApp(ExecuteShellUtil executeShellUtil, String ip, String fileSavePath, String appName, String backupPath, Long id) {
|
||||
String deployDate = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
backupPath += appName + FILE_SEPARATOR + deployDate + "\n";
|
||||
sb.append("mkdir -p ").append(backupPath);
|
||||
sb.append("mv -f ").append(fileSavePath);
|
||||
sb.append(appName).append(" ").append(backupPath);
|
||||
log.info("备份应用脚本:" + sb.toString());
|
||||
executeShellUtil.execute(sb.toString());
|
||||
//还原信息入库
|
||||
DeployHistory deployHistory = new DeployHistory();
|
||||
deployHistory.setAppName(appName);
|
||||
deployHistory.setDeployUser(SecurityUtils.getCurrentUsername());
|
||||
deployHistory.setIp(ip);
|
||||
deployHistory.setDeployId(id);
|
||||
deployHistoryService.create(deployHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停App
|
||||
*
|
||||
* @param port 端口
|
||||
* @param executeShellUtil /
|
||||
*/
|
||||
private void stopApp(int port, ExecuteShellUtil executeShellUtil) {
|
||||
//发送停止命令
|
||||
executeShellUtil.execute(String.format("lsof -i :%d|grep -v \"PID\"|awk '{print \"kill -9\",$2}'|sh", port));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定端口程序是否在运行
|
||||
*
|
||||
* @param port 端口
|
||||
* @param executeShellUtil /
|
||||
* @return true 正在运行 false 已经停止
|
||||
*/
|
||||
private boolean checkIsRunningStatus(int port, ExecuteShellUtil executeShellUtil) {
|
||||
String result = executeShellUtil.executeForResult(String.format("fuser -n tcp %d", port));
|
||||
return result.indexOf("/tcp:")>0;
|
||||
}
|
||||
|
||||
private void sendMsg(String msg, MsgType msgType) {
|
||||
try {
|
||||
WebSocketServer.sendInfo(new SocketMsg(msg, msgType), "deploy");
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serverStatus(Deploy resources) {
|
||||
Set<ServerDeploy> serverDeploys = resources.getDeploys();
|
||||
App app = resources.getApp();
|
||||
for (ServerDeploy serverDeploy : serverDeploys) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(serverDeploy.getIp());
|
||||
sb.append("服务器:").append(serverDeploy.getName()).append("<br>应用:").append(app.getName());
|
||||
boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil);
|
||||
if (result) {
|
||||
sb.append("<br>正在运行");
|
||||
sendMsg(sb.toString(), MsgType.INFO);
|
||||
} else {
|
||||
sb.append("<br>已停止!");
|
||||
sendMsg(sb.toString(), MsgType.ERROR);
|
||||
}
|
||||
log.info(sb.toString());
|
||||
executeShellUtil.close();
|
||||
}
|
||||
return "执行完毕";
|
||||
}
|
||||
|
||||
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDto appDTO) {
|
||||
String result = executeShellUtil.executeForResult("find " + appDTO.getDeployPath() + " -name " + appDTO.getName());
|
||||
return result.indexOf(appDTO.getName())>0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动服务
|
||||
* @param resources /
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public String startServer(Deploy resources) {
|
||||
Set<ServerDeploy> deploys = resources.getDeploys();
|
||||
App app = resources.getApp();
|
||||
for (ServerDeploy deploy : deploys) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(deploy.getIp());
|
||||
//为了防止重复启动,这里先停止应用
|
||||
stopApp(app.getPort(), executeShellUtil);
|
||||
sb.append("服务器:").append(deploy.getName()).append("<br>应用:").append(app.getName());
|
||||
sendMsg("下发启动命令", MsgType.INFO);
|
||||
executeShellUtil.execute(app.getStartScript());
|
||||
sleep(3);
|
||||
sendMsg("应用启动中,请耐心等待启动结果,或者稍后手动查看运行状态", MsgType.INFO);
|
||||
int i = 0;
|
||||
boolean result = false;
|
||||
// 由于启动应用需要时间,所以需要循环获取状态,如果超过30次,则认为是启动失败
|
||||
while (i++ < count){
|
||||
result = checkIsRunningStatus(app.getPort(), executeShellUtil);
|
||||
if(result){
|
||||
break;
|
||||
}
|
||||
// 休眠6秒
|
||||
sleep(6);
|
||||
}
|
||||
sendResultMsg(result, sb);
|
||||
log.info(sb.toString());
|
||||
executeShellUtil.close();
|
||||
}
|
||||
return "执行完毕";
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止服务
|
||||
* @param resources /
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
public String stopServer(Deploy resources) {
|
||||
Set<ServerDeploy> deploys = resources.getDeploys();
|
||||
App app = resources.getApp();
|
||||
for (ServerDeploy deploy : deploys) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(deploy.getIp());
|
||||
sb.append("服务器:").append(deploy.getName()).append("<br>应用:").append(app.getName());
|
||||
sendMsg("下发停止命令", MsgType.INFO);
|
||||
//停止应用
|
||||
stopApp(app.getPort(), executeShellUtil);
|
||||
sleep(1);
|
||||
boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil);
|
||||
if (result) {
|
||||
sb.append("<br>关闭失败!");
|
||||
sendMsg(sb.toString(), MsgType.ERROR);
|
||||
} else {
|
||||
sb.append("<br>关闭成功!");
|
||||
sendMsg(sb.toString(), MsgType.INFO);
|
||||
}
|
||||
log.info(sb.toString());
|
||||
executeShellUtil.close();
|
||||
}
|
||||
return "执行完毕";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serverReduction(DeployHistory resources) {
|
||||
Long deployId = resources.getDeployId();
|
||||
Deploy deployInfo = deployRepository.findById(deployId).orElseGet(Deploy::new);
|
||||
String deployDate = DateUtil.format(resources.getDeployDate(), DatePattern.PURE_DATETIME_PATTERN);
|
||||
App app = deployInfo.getApp();
|
||||
if (app == null) {
|
||||
sendMsg("应用信息不存在:" + resources.getAppName(), MsgType.ERROR);
|
||||
throw new BadRequestException("应用信息不存在:" + resources.getAppName());
|
||||
}
|
||||
String backupPath = app.getBackupPath()+FILE_SEPARATOR;
|
||||
backupPath += resources.getAppName() + FILE_SEPARATOR + deployDate;
|
||||
//这个是服务器部署路径
|
||||
String deployPath = app.getDeployPath();
|
||||
String ip = resources.getIp();
|
||||
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip);
|
||||
String msg;
|
||||
|
||||
msg = String.format("登陆到服务器:%s", ip);
|
||||
log.info(msg);
|
||||
sendMsg(msg, MsgType.INFO);
|
||||
sendMsg("停止原来应用", MsgType.INFO);
|
||||
//停止应用
|
||||
stopApp(app.getPort(), executeShellUtil);
|
||||
//删除原来应用
|
||||
sendMsg("删除应用", MsgType.INFO);
|
||||
executeShellUtil.execute("rm -rf " + deployPath + FILE_SEPARATOR + resources.getAppName());
|
||||
//还原应用
|
||||
sendMsg("还原应用", MsgType.INFO);
|
||||
executeShellUtil.execute("cp -r " + backupPath + "/. " + deployPath);
|
||||
sendMsg("启动应用", MsgType.INFO);
|
||||
executeShellUtil.execute(app.getStartScript());
|
||||
sendMsg("应用启动中,请耐心等待启动结果,或者稍后手动查看启动状态", MsgType.INFO);
|
||||
int i = 0;
|
||||
boolean result = false;
|
||||
// 由于启动应用需要时间,所以需要循环获取状态,如果超过30次,则认为是启动失败
|
||||
while (i++ < count){
|
||||
result = checkIsRunningStatus(app.getPort(), executeShellUtil);
|
||||
if(result){
|
||||
break;
|
||||
}
|
||||
// 休眠6秒
|
||||
sleep(6);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("服务器:").append(ip).append("<br>应用:").append(resources.getAppName());
|
||||
sendResultMsg(result, sb);
|
||||
executeShellUtil.close();
|
||||
return "";
|
||||
}
|
||||
|
||||
private ExecuteShellUtil getExecuteShellUtil(String ip) {
|
||||
ServerDeployDto serverDeployDTO = serverDeployService.findByIp(ip);
|
||||
if (serverDeployDTO == null) {
|
||||
sendMsg("IP对应服务器信息不存在:" + ip, MsgType.ERROR);
|
||||
throw new BadRequestException("IP对应服务器信息不存在:" + ip);
|
||||
}
|
||||
return new ExecuteShellUtil(ip, serverDeployDTO.getAccount(), serverDeployDTO.getPassword(),serverDeployDTO.getPort());
|
||||
}
|
||||
|
||||
private ScpClientUtil getScpClientUtil(String ip) {
|
||||
ServerDeployDto serverDeployDTO = serverDeployService.findByIp(ip);
|
||||
if (serverDeployDTO == null) {
|
||||
sendMsg("IP对应服务器信息不存在:" + ip, MsgType.ERROR);
|
||||
throw new BadRequestException("IP对应服务器信息不存在:" + ip);
|
||||
}
|
||||
return ScpClientUtil.getInstance(ip, serverDeployDTO.getPort(), serverDeployDTO.getAccount(), serverDeployDTO.getPassword());
|
||||
}
|
||||
|
||||
private void sendResultMsg(boolean result, StringBuilder sb) {
|
||||
if (result) {
|
||||
sb.append("<br>启动成功!");
|
||||
sendMsg(sb.toString(), MsgType.INFO);
|
||||
} else {
|
||||
sb.append("<br>启动失败!");
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.mnt.domain.ServerDeploy;
|
||||
import org.nl.modules.mnt.repository.ServerDeployRepository;
|
||||
import org.nl.modules.mnt.service.ServerDeployService;
|
||||
import org.nl.modules.mnt.service.dto.ServerDeployDto;
|
||||
import org.nl.modules.mnt.service.dto.ServerDeployQueryCriteria;
|
||||
import org.nl.modules.mnt.service.mapstruct.ServerDeployMapper;
|
||||
import org.nl.modules.mnt.util.ExecuteShellUtil;
|
||||
import org.nl.utils.FileUtil;
|
||||
import org.nl.utils.PageUtil;
|
||||
import org.nl.utils.QueryHelp;
|
||||
import org.nl.utils.ValidationUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ServerDeployServiceImpl implements ServerDeployService {
|
||||
|
||||
private final ServerDeployRepository serverDeployRepository;
|
||||
private final ServerDeployMapper serverDeployMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(ServerDeployQueryCriteria criteria, Pageable pageable){
|
||||
Page<ServerDeploy> page = serverDeployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(serverDeployMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServerDeployDto> queryAll(ServerDeployQueryCriteria criteria){
|
||||
return serverDeployMapper.toDto(serverDeployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerDeployDto findById(Long id) {
|
||||
ServerDeploy server = serverDeployRepository.findById(id).orElseGet(ServerDeploy::new);
|
||||
ValidationUtil.isNull(server.getId(),"ServerDeploy","id",id);
|
||||
return serverDeployMapper.toDto(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerDeployDto findByIp(String ip) {
|
||||
ServerDeploy deploy = serverDeployRepository.findByIp(ip);
|
||||
return serverDeployMapper.toDto(deploy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean testConnect(ServerDeploy resources) {
|
||||
ExecuteShellUtil executeShellUtil = null;
|
||||
try {
|
||||
executeShellUtil = new ExecuteShellUtil(resources.getIp(), resources.getAccount(), resources.getPassword(),resources.getPort());
|
||||
return executeShellUtil.execute("ls")==0;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}finally {
|
||||
if (executeShellUtil != null) {
|
||||
executeShellUtil.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(ServerDeploy resources) {
|
||||
serverDeployRepository.save(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(ServerDeploy resources) {
|
||||
ServerDeploy serverDeploy = serverDeployRepository.findById(resources.getId()).orElseGet(ServerDeploy::new);
|
||||
ValidationUtil.isNull( serverDeploy.getId(),"ServerDeploy","id",resources.getId());
|
||||
serverDeploy.copy(resources);
|
||||
serverDeployRepository.save(serverDeploy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.mapstruct;
|
||||
|
||||
import org.nl.base.BaseMapper;
|
||||
import org.nl.modules.mnt.domain.App;
|
||||
import org.nl.modules.mnt.service.dto.AppDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface AppMapper extends BaseMapper<AppDto, App> {
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.mapstruct;
|
||||
|
||||
import org.nl.base.BaseMapper;
|
||||
import org.nl.modules.mnt.domain.Database;
|
||||
import org.nl.modules.mnt.service.dto.DatabaseDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface DatabaseMapper extends BaseMapper<DatabaseDto, Database> {
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.mapstruct;
|
||||
|
||||
import org.nl.base.BaseMapper;
|
||||
import org.nl.modules.mnt.domain.DeployHistory;
|
||||
import org.nl.modules.mnt.service.dto.DeployHistoryDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface DeployHistoryMapper extends BaseMapper<DeployHistoryDto, DeployHistory> {
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.mapstruct;
|
||||
|
||||
import org.nl.base.BaseMapper;
|
||||
import org.nl.modules.mnt.domain.Deploy;
|
||||
import org.nl.modules.mnt.service.dto.DeployDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {AppMapper.class, ServerDeployMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface DeployMapper extends BaseMapper<DeployDto, Deploy> {
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.mnt.service.mapstruct;
|
||||
|
||||
import org.nl.base.BaseMapper;
|
||||
import org.nl.modules.mnt.domain.ServerDeploy;
|
||||
import org.nl.modules.mnt.service.dto.ServerDeployDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author zhanghouying
|
||||
* @date 2019-08-24
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface ServerDeployMapper extends BaseMapper<ServerDeployDto, ServerDeploy> {
|
||||
|
||||
}
|
||||
@@ -16,28 +16,21 @@
|
||||
package org.nl.modules.quartz.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.template.Template;
|
||||
import cn.hutool.extra.template.TemplateConfig;
|
||||
import cn.hutool.extra.template.TemplateEngine;
|
||||
import cn.hutool.extra.template.TemplateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.config.thread.ThreadPoolExecutorUtil;
|
||||
import org.nl.domain.vo.EmailVo;
|
||||
import org.nl.modules.quartz.domain.QuartzJob;
|
||||
import org.nl.modules.quartz.domain.QuartzLog;
|
||||
import org.nl.modules.quartz.repository.QuartzLogRepository;
|
||||
import org.nl.modules.quartz.service.QuartzJobService;
|
||||
import org.nl.service.EmailService;
|
||||
import org.nl.utils.RedisUtils;
|
||||
import org.nl.utils.SpringContextHolder;
|
||||
import org.nl.utils.StringUtils;
|
||||
import org.nl.utils.ThrowableUtil;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* 参考人人开源,https://gitee.com/renrenio/renren-security
|
||||
@@ -112,29 +105,29 @@ public class ExecutionJob extends QuartzJobBean {
|
||||
//更新状态
|
||||
quartzJobService.updateIsPause(quartzJob);
|
||||
}
|
||||
if (quartzJob.getEmail() != null) {
|
||||
EmailService emailService = SpringContextHolder.getBean(EmailService.class);
|
||||
// 邮箱报警
|
||||
EmailVo emailVo = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e));
|
||||
emailService.send(emailVo, emailService.find());
|
||||
}
|
||||
// if (quartzJob.getEmail() != null) {
|
||||
// EmailService emailService = SpringContextHolder.getBean(EmailService.class);
|
||||
// // 邮箱报警
|
||||
// EmailVo emailVo = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e));
|
||||
// emailService.send(emailVo, emailService.find());
|
||||
// }
|
||||
} finally {
|
||||
log.info(logDto.toString());
|
||||
quartzLogRepository.save(logDto);
|
||||
}
|
||||
}
|
||||
|
||||
private EmailVo taskAlarm(QuartzJob quartzJob, String msg) {
|
||||
EmailVo emailVo = new EmailVo();
|
||||
emailVo.setSubject("定时任务【" + quartzJob.getJobName() + "】执行失败,请尽快处理!");
|
||||
Map<String, Object> data = new HashMap<>(16);
|
||||
data.put("task", quartzJob);
|
||||
data.put("msg", msg);
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
Template template = engine.getTemplate("email/taskAlarm.ftl");
|
||||
emailVo.setContent(template.render(data));
|
||||
List<String> emails = Arrays.asList(quartzJob.getEmail().split("[,,]"));
|
||||
emailVo.setTos(emails);
|
||||
return emailVo;
|
||||
}
|
||||
// private EmailVo taskAlarm(QuartzJob quartzJob, String msg) {
|
||||
// EmailVo emailVo = new EmailVo();
|
||||
// emailVo.setSubject("定时任务【" + quartzJob.getJobName() + "】执行失败,请尽快处理!");
|
||||
// Map<String, Object> data = new HashMap<>(16);
|
||||
// data.put("task", quartzJob);
|
||||
// data.put("msg", msg);
|
||||
// TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
// Template template = engine.getTemplate("email/taskAlarm.ftl");
|
||||
// emailVo.setContent(template.render(data));
|
||||
// List<String> emails = Arrays.asList(quartzJob.getEmail().split("[,,]"));
|
||||
// emailVo.setTos(emails);
|
||||
// return emailVo;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -27,14 +27,16 @@ import org.nl.config.RsaProperties;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.modules.system.domain.User;
|
||||
import org.nl.modules.system.domain.vo.UserPassVo;
|
||||
import org.nl.modules.system.service.*;
|
||||
import org.nl.modules.system.service.DataService;
|
||||
import org.nl.modules.system.service.DeptService;
|
||||
import org.nl.modules.system.service.RoleService;
|
||||
import org.nl.modules.system.service.UserService;
|
||||
import org.nl.modules.system.service.dto.RoleSmallDto;
|
||||
import org.nl.modules.system.service.dto.UserDto;
|
||||
import org.nl.modules.system.service.dto.UserQueryCriteria;
|
||||
import org.nl.utils.PageUtil;
|
||||
import org.nl.utils.RsaUtils;
|
||||
import org.nl.utils.SecurityUtils;
|
||||
import org.nl.utils.enums.CodeEnum;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -66,7 +68,7 @@ public class UserController {
|
||||
private final DataService dataService;
|
||||
private final DeptService deptService;
|
||||
private final RoleService roleService;
|
||||
private final VerifyService verificationCodeService;
|
||||
// private final VerifyService verificationCodeService;
|
||||
|
||||
@ApiOperation("导出用户数据")
|
||||
@GetMapping(value = "/download")
|
||||
@@ -172,19 +174,19 @@ public class UserController {
|
||||
return new ResponseEntity<>(userService.updateAvatar(avatar), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("修改邮箱")
|
||||
@ApiOperation("修改邮箱")
|
||||
@PostMapping(value = "/updateEmail/{code}")
|
||||
public ResponseEntity<Object> updateEmail(@PathVariable String code,@RequestBody User user) throws Exception {
|
||||
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,user.getPassword());
|
||||
UserDto userDto = userService.findByName(SecurityUtils.getCurrentUsername());
|
||||
// if(!passwordEncoder.matches(password, userDto.getPassword())){
|
||||
// throw new BadRequestException("密码错误");
|
||||
// }
|
||||
verificationCodeService.validated(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey() + user.getEmail(), code);
|
||||
userService.updateEmail(userDto.getUsername(),user.getEmail());
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
// @Log("修改邮箱")
|
||||
// @ApiOperation("修改邮箱")
|
||||
// @PostMapping(value = "/updateEmail/{code}")
|
||||
// public ResponseEntity<Object> updateEmail(@PathVariable String code,@RequestBody User user) throws Exception {
|
||||
// String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,user.getPassword());
|
||||
// UserDto userDto = userService.findByName(SecurityUtils.getCurrentUsername());
|
||||
//// if(!passwordEncoder.matches(password, userDto.getPassword())){
|
||||
//// throw new BadRequestException("密码错误");
|
||||
//// }
|
||||
// verificationCodeService.validated(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey() + user.getEmail(), code);
|
||||
// userService.updateEmail(userDto.getUsername(),user.getEmail());
|
||||
// return new ResponseEntity<>(HttpStatus.OK);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.system.rest;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.domain.vo.EmailVo;
|
||||
import org.nl.service.EmailService;
|
||||
import org.nl.modules.system.service.VerifyService;
|
||||
import org.nl.utils.enums.CodeBiEnum;
|
||||
import org.nl.utils.enums.CodeEnum;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-26
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/code")
|
||||
@Api(tags = "系统:验证码管理")
|
||||
public class VerifyController {
|
||||
|
||||
private final VerifyService verificationCodeService;
|
||||
private final EmailService emailService;
|
||||
|
||||
@PostMapping(value = "/resetEmail")
|
||||
@ApiOperation("重置邮箱,发送验证码")
|
||||
public ResponseEntity<Object> resetEmail(@RequestParam String email){
|
||||
EmailVo emailVo = verificationCodeService.sendEmail(email, CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey());
|
||||
emailService.send(emailVo,emailService.find());
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/email/resetPass")
|
||||
@ApiOperation("重置密码,发送验证码")
|
||||
public ResponseEntity<Object> resetPass(@RequestParam String email){
|
||||
EmailVo emailVo = verificationCodeService.sendEmail(email, CodeEnum.EMAIL_RESET_PWD_CODE.getKey());
|
||||
emailService.send(emailVo,emailService.find());
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/validated")
|
||||
@ApiOperation("验证码验证")
|
||||
public ResponseEntity<Object> validated(@RequestParam String email, @RequestParam String code, @RequestParam Integer codeBi){
|
||||
CodeBiEnum biEnum = CodeBiEnum.find(codeBi);
|
||||
switch (Objects.requireNonNull(biEnum)){
|
||||
case ONE:
|
||||
verificationCodeService.validated(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey() + email ,code);
|
||||
break;
|
||||
case TWO:
|
||||
verificationCodeService.validated(CodeEnum.EMAIL_RESET_PWD_CODE.getKey() + email ,code);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,41 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.system.service;
|
||||
|
||||
import org.nl.domain.vo.EmailVo;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-26
|
||||
*/
|
||||
public interface VerifyService {
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
* @param email /
|
||||
* @param key /
|
||||
* @return /
|
||||
*/
|
||||
EmailVo sendEmail(String email, String key);
|
||||
|
||||
|
||||
/**
|
||||
* 验证
|
||||
* @param code /
|
||||
* @param key /
|
||||
*/
|
||||
void validated(String key, String code);
|
||||
}
|
||||
///*
|
||||
// * Copyright 2019-2020 Zheng Jie
|
||||
// *
|
||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// * you may not use this file except in compliance with the License.
|
||||
// * You may obtain a copy of the License at
|
||||
// *
|
||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * Unless required by applicable law or agreed to in writing, software
|
||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// * See the License for the specific language governing permissions and
|
||||
// * limitations under the License.
|
||||
// */
|
||||
//package org.nl.modules.system.service;
|
||||
//
|
||||
//import org.nl.domain.vo.EmailVo;
|
||||
//
|
||||
///**
|
||||
// * @author Zheng Jie
|
||||
// * @date 2018-12-26
|
||||
// */
|
||||
//public interface VerifyService {
|
||||
//
|
||||
// /**
|
||||
// * 发送验证码
|
||||
// * @param email /
|
||||
// * @param key /
|
||||
// * @return /
|
||||
// */
|
||||
// EmailVo sendEmail(String email, String key);
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 验证
|
||||
// * @param code /
|
||||
// * @param key /
|
||||
// */
|
||||
// void validated(String key, String code);
|
||||
//}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.extra.template.Template;
|
||||
import cn.hutool.extra.template.TemplateConfig;
|
||||
import cn.hutool.extra.template.TemplateEngine;
|
||||
import cn.hutool.extra.template.TemplateUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.domain.vo.EmailVo;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.modules.system.service.VerifyService;
|
||||
import org.nl.utils.RedisUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-26
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class VerifyServiceImpl implements VerifyService {
|
||||
|
||||
@Value("${code.expiration}")
|
||||
private Long expiration;
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public EmailVo sendEmail(String email, String key) {
|
||||
EmailVo emailVo;
|
||||
String content;
|
||||
String redisKey = key + email;
|
||||
// 如果不存在有效的验证码,就创建一个新的
|
||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||
Template template = engine.getTemplate("email/email.ftl");
|
||||
Object oldCode = redisUtils.get(redisKey);
|
||||
if(oldCode == null){
|
||||
String code = RandomUtil.randomNumbers (6);
|
||||
// 存入缓存
|
||||
if(!redisUtils.set(redisKey, code, expiration)){
|
||||
throw new BadRequestException("服务异常,请联系网站负责人");
|
||||
}
|
||||
content = template.render(Dict.create().set("code",code));
|
||||
emailVo = new EmailVo(Collections.singletonList(email),"EL-ADMIN后台管理系统",content);
|
||||
// 存在就再次发送原来的验证码
|
||||
} else {
|
||||
content = template.render(Dict.create().set("code",oldCode));
|
||||
emailVo = new EmailVo(Collections.singletonList(email),"EL-ADMIN后台管理系统",content);
|
||||
}
|
||||
return emailVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validated(String key, String code) {
|
||||
Object value = redisUtils.get(key);
|
||||
if(value == null || !value.toString().equals(code)){
|
||||
throw new BadRequestException("无效验证码");
|
||||
} else {
|
||||
redisUtils.del(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user