diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/App.java b/nladmin-system/src/main/java/org/nl/modules/mnt/domain/App.java deleted file mode 100644 index b06cfd32b..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/App.java +++ /dev/null @@ -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)); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/Database.java b/nladmin-system/src/main/java/org/nl/modules/mnt/domain/Database.java deleted file mode 100644 index 4243eb95c..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/Database.java +++ /dev/null @@ -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)); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/Deploy.java b/nladmin-system/src/main/java/org/nl/modules/mnt/domain/Deploy.java deleted file mode 100644 index 029d7a73b..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/Deploy.java +++ /dev/null @@ -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 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)); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/DeployHistory.java b/nladmin-system/src/main/java/org/nl/modules/mnt/domain/DeployHistory.java deleted file mode 100644 index 7a647218d..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/DeployHistory.java +++ /dev/null @@ -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)); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/ServerDeploy.java b/nladmin-system/src/main/java/org/nl/modules/mnt/domain/ServerDeploy.java deleted file mode 100644 index ad676d1fa..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/domain/ServerDeploy.java +++ /dev/null @@ -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); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/AppRepository.java b/nladmin-system/src/main/java/org/nl/modules/mnt/repository/AppRepository.java deleted file mode 100644 index a0fd97925..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/AppRepository.java +++ /dev/null @@ -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, JpaSpecificationExecutor { -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DatabaseRepository.java b/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DatabaseRepository.java deleted file mode 100644 index 08cedda73..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DatabaseRepository.java +++ /dev/null @@ -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, JpaSpecificationExecutor { -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DeployHistoryRepository.java b/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DeployHistoryRepository.java deleted file mode 100644 index a2b31369b..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DeployHistoryRepository.java +++ /dev/null @@ -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, JpaSpecificationExecutor { -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DeployRepository.java b/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DeployRepository.java deleted file mode 100644 index 6ae59645b..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/DeployRepository.java +++ /dev/null @@ -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, JpaSpecificationExecutor { -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/ServerDeployRepository.java b/nladmin-system/src/main/java/org/nl/modules/mnt/repository/ServerDeployRepository.java deleted file mode 100644 index 89c370170..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/repository/ServerDeployRepository.java +++ /dev/null @@ -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, JpaSpecificationExecutor { - - /** - * 根据IP查询 - * @param ip / - * @return / - */ - ServerDeploy findByIp(String ip); -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/AppController.java b/nladmin-system/src/main/java/org/nl/modules/mnt/rest/AppController.java deleted file mode 100644 index c5d75cb41..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/AppController.java +++ /dev/null @@ -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 query(AppQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(appService.queryAll(criteria,pageable),HttpStatus.OK); - } - - @Log("新增应用") - @ApiOperation(value = "新增应用") - @PostMapping - @SaCheckPermission("app:add") - public ResponseEntity create(@Validated @RequestBody App resources){ - appService.create(resources); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - @Log("修改应用") - @ApiOperation(value = "修改应用") - @PutMapping - @SaCheckPermission("app:edit") - public ResponseEntity update(@Validated @RequestBody App resources){ - appService.update(resources); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Log("删除应用") - @ApiOperation(value = "删除应用") - @DeleteMapping - @SaCheckPermission("app:del") - public ResponseEntity delete(@RequestBody Set ids){ - appService.delete(ids); - return new ResponseEntity<>(HttpStatus.OK); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DatabaseController.java b/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DatabaseController.java deleted file mode 100644 index cfde91a76..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DatabaseController.java +++ /dev/null @@ -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 query(DatabaseQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(databaseService.queryAll(criteria,pageable),HttpStatus.OK); - } - - @Log("新增数据库") - @ApiOperation(value = "新增数据库") - @PostMapping - @SaCheckPermission("database:add") - public ResponseEntity create(@Validated @RequestBody Database resources){ - databaseService.create(resources); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - @Log("修改数据库") - @ApiOperation(value = "修改数据库") - @PutMapping - @SaCheckPermission("database:edit") - public ResponseEntity update(@Validated @RequestBody Database resources){ - databaseService.update(resources); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Log("删除数据库") - @ApiOperation(value = "删除数据库") - @DeleteMapping - @SaCheckPermission("database:del") - public ResponseEntity delete(@RequestBody Set ids){ - databaseService.delete(ids); - return new ResponseEntity<>(HttpStatus.OK); - } - - @Log("测试数据库链接") - @ApiOperation(value = "测试数据库链接") - @PostMapping("/testConnect") - @SaCheckPermission("database:testConnect") - public ResponseEntity 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 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"); - } - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DeployController.java b/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DeployController.java deleted file mode 100644 index 38ac43749..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DeployController.java +++ /dev/null @@ -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 query(DeployQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(deployService.queryAll(criteria,pageable),HttpStatus.OK); - } - - @Log("新增部署") - @ApiOperation(value = "新增部署") - @PostMapping - @SaCheckPermission("deploy:add") - public ResponseEntity create(@Validated @RequestBody Deploy resources){ - deployService.create(resources); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - @Log("修改部署") - @ApiOperation(value = "修改部署") - @PutMapping - @SaCheckPermission("deploy:edit") - public ResponseEntity update(@Validated @RequestBody Deploy resources){ - deployService.update(resources); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Log("删除部署") - @ApiOperation(value = "删除部署") - @DeleteMapping - @SaCheckPermission("deploy:del") - public ResponseEntity delete(@RequestBody Set ids){ - deployService.delete(ids); - return new ResponseEntity<>(HttpStatus.OK); - } - - @Log("上传文件部署") - @ApiOperation(value = "上传文件部署") - @PostMapping(value = "/upload") - @SaCheckPermission("deploy:edit") - public ResponseEntity 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 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 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 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 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 stopServer(@Validated @RequestBody Deploy resources){ - String result = deployService.stopServer(resources); - return new ResponseEntity<>(result,HttpStatus.OK); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DeployHistoryController.java b/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DeployHistoryController.java deleted file mode 100644 index 30699c06b..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/DeployHistoryController.java +++ /dev/null @@ -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 query(DeployHistoryQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(deployhistoryService.queryAll(criteria,pageable),HttpStatus.OK); - } - - @Log("删除DeployHistory") - @ApiOperation(value = "删除部署历史") - @DeleteMapping - @SaCheckPermission("deployHistory:del") - public ResponseEntity delete(@RequestBody Set ids){ - deployhistoryService.delete(ids); - return new ResponseEntity<>(HttpStatus.OK); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/ServerDeployController.java b/nladmin-system/src/main/java/org/nl/modules/mnt/rest/ServerDeployController.java deleted file mode 100644 index 15b2df0bb..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/rest/ServerDeployController.java +++ /dev/null @@ -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 query(ServerDeployQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(serverDeployService.queryAll(criteria,pageable),HttpStatus.OK); - } - - @Log("新增服务器") - @ApiOperation(value = "新增服务器") - @PostMapping - @SaCheckPermission("serverDeploy:add") - public ResponseEntity create(@Validated @RequestBody ServerDeploy resources){ - serverDeployService.create(resources); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - @Log("修改服务器") - @ApiOperation(value = "修改服务器") - @PutMapping - @SaCheckPermission("serverDeploy:edit") - public ResponseEntity update(@Validated @RequestBody ServerDeploy resources){ - serverDeployService.update(resources); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Log("删除服务器") - @ApiOperation(value = "删除Server") - @DeleteMapping - @SaCheckPermission("serverDeploy:del") - public ResponseEntity delete(@RequestBody Set ids){ - serverDeployService.delete(ids); - return new ResponseEntity<>(HttpStatus.OK); - } - - @Log("测试连接服务器") - @ApiOperation(value = "测试连接服务器") - @PostMapping("/testConnect") - @SaCheckPermission("serverDeploy:add") - public ResponseEntity testConnect(@Validated @RequestBody ServerDeploy resources){ - return new ResponseEntity<>(serverDeployService.testConnect(resources),HttpStatus.CREATED); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/AppService.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/AppService.java deleted file mode 100644 index cac9fc34c..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/AppService.java +++ /dev/null @@ -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 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 ids); - - /** - * 导出数据 - * @param queryAll / - * @param response / - * @throws IOException / - */ - void download(List queryAll, HttpServletResponse response) throws IOException; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/DatabaseService.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/DatabaseService.java deleted file mode 100644 index 43f31b666..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/DatabaseService.java +++ /dev/null @@ -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 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 ids); - - /** - * 测试连接数据库 - * @param resources / - * @return / - */ - boolean testConnection(Database resources); - - /** - * 导出数据 - * @param queryAll / - * @param response / - * @throws IOException e - */ - void download(List queryAll, HttpServletResponse response) throws IOException; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/DeployHistoryService.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/DeployHistoryService.java deleted file mode 100644 index 6dd1ed65f..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/DeployHistoryService.java +++ /dev/null @@ -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 queryAll(DeployHistoryQueryCriteria criteria); - - /** - * 根据ID查询 - * @param id / - * @return / - */ - DeployHistoryDto findById(String id); - - /** - * 创建 - * @param resources / - */ - void create(DeployHistory resources); - - /** - * 删除 - * @param ids / - */ - void delete(Set ids); - - /** - * 导出数据 - * @param queryAll / - * @param response / - * @throws IOException / - */ - void download(List queryAll, HttpServletResponse response) throws IOException; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/DeployService.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/DeployService.java deleted file mode 100644 index df9e29a58..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/DeployService.java +++ /dev/null @@ -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 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 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 queryAll, HttpServletResponse response) throws IOException; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/ServerDeployService.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/ServerDeployService.java deleted file mode 100644 index 2e451e41a..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/ServerDeployService.java +++ /dev/null @@ -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 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 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 queryAll, HttpServletResponse response) throws IOException; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/AppDto.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/AppDto.java deleted file mode 100644 index 1d7298392..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/AppDto.java +++ /dev/null @@ -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; - -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/AppQueryCriteria.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/AppQueryCriteria.java deleted file mode 100644 index 2255c2182..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/AppQueryCriteria.java +++ /dev/null @@ -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 createTime; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DatabaseDto.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DatabaseDto.java deleted file mode 100644 index 4abffce5b..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DatabaseDto.java +++ /dev/null @@ -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; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DatabaseQueryCriteria.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DatabaseQueryCriteria.java deleted file mode 100644 index 1735a3d81..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DatabaseQueryCriteria.java +++ /dev/null @@ -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 createTime; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployDto.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployDto.java deleted file mode 100644 index 2ccb5fa5b..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployDto.java +++ /dev/null @@ -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 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); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployHistoryDto.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployHistoryDto.java deleted file mode 100644 index 6eb099c5a..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployHistoryDto.java +++ /dev/null @@ -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; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployHistoryQueryCriteria.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployHistoryQueryCriteria.java deleted file mode 100644 index 91d39d195..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployHistoryQueryCriteria.java +++ /dev/null @@ -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 deployDate; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployQueryCriteria.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployQueryCriteria.java deleted file mode 100644 index 85d2fa991..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/DeployQueryCriteria.java +++ /dev/null @@ -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 createTime; - -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/ServerDeployDto.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/ServerDeployDto.java deleted file mode 100644 index 5626c4568..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/ServerDeployDto.java +++ /dev/null @@ -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); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/ServerDeployQueryCriteria.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/ServerDeployQueryCriteria.java deleted file mode 100644 index 423e2a31c..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/dto/ServerDeployQueryCriteria.java +++ /dev/null @@ -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 createTime; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/AppServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/AppServiceImpl.java deleted file mode 100644 index aff695755..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/AppServiceImpl.java +++ /dev/null @@ -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 page = appRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); - return PageUtil.toPage(page.map(appMapper::toDto)); - } - - @Override - public List 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 ids) { - for (Long id : ids) { - appRepository.deleteById(id); - } - } - - @Override - public void download(List queryAll, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (AppDto appDto : queryAll) { - Map 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); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DatabaseServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DatabaseServiceImpl.java deleted file mode 100644 index 04cb2febb..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DatabaseServiceImpl.java +++ /dev/null @@ -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 page = databaseRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); - return PageUtil.toPage(page.map(databaseMapper::toDto)); - } - - @Override - public List 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 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 queryAll, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (DatabaseDto databaseDto : queryAll) { - Map 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); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DeployHistoryServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DeployHistoryServiceImpl.java deleted file mode 100644 index 3d311d9a8..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DeployHistoryServiceImpl.java +++ /dev/null @@ -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 page = deployhistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); - return PageUtil.toPage(page.map(deployhistoryMapper::toDto)); - } - - @Override - public List 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 ids) { - for (String id : ids) { - deployhistoryRepository.deleteById(id); - } - } - - @Override - public void download(List queryAll, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (DeployHistoryDto deployHistoryDto : queryAll) { - Map 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); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DeployServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DeployServiceImpl.java deleted file mode 100644 index 6b9f7b6aa..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/DeployServiceImpl.java +++ /dev/null @@ -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 page = deployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); - return PageUtil.toPage(page.map(deployMapper::toDto)); - } - - @Override - public List 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 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 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
目录:%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("
应用:").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 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("
应用:").append(app.getName()); - boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil); - if (result) { - sb.append("
正在运行"); - sendMsg(sb.toString(), MsgType.INFO); - } else { - sb.append("
已停止!"); - 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 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("
应用:").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 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("
应用:").append(app.getName()); - sendMsg("下发停止命令", MsgType.INFO); - //停止应用 - stopApp(app.getPort(), executeShellUtil); - sleep(1); - boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil); - if (result) { - sb.append("
关闭失败!"); - sendMsg(sb.toString(), MsgType.ERROR); - } else { - sb.append("
关闭成功!"); - 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("
应用:").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("
启动成功!"); - sendMsg(sb.toString(), MsgType.INFO); - } else { - sb.append("
启动失败!"); - sendMsg(sb.toString(), MsgType.ERROR); - } - } - - @Override - public void download(List queryAll, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (DeployDto deployDto : queryAll) { - Map map = new LinkedHashMap<>(); - map.put("应用名称", deployDto.getApp().getName()); - map.put("服务器", deployDto.getServers()); - map.put("部署日期", deployDto.getCreateTime()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/ServerDeployServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/ServerDeployServiceImpl.java deleted file mode 100644 index 83f5f6266..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/impl/ServerDeployServiceImpl.java +++ /dev/null @@ -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 page = serverDeployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); - return PageUtil.toPage(page.map(serverDeployMapper::toDto)); - } - - @Override - public List 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 ids) { - for (Long id : ids) { - serverDeployRepository.deleteById(id); - } - } - - @Override - public void download(List queryAll, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (ServerDeployDto deployDto : queryAll) { - Map 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); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/AppMapper.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/AppMapper.java deleted file mode 100644 index ed68a2c5d..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/AppMapper.java +++ /dev/null @@ -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 { - -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DatabaseMapper.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DatabaseMapper.java deleted file mode 100644 index 4af2bd396..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DatabaseMapper.java +++ /dev/null @@ -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 { - -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DeployHistoryMapper.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DeployHistoryMapper.java deleted file mode 100644 index 03cb5abcf..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DeployHistoryMapper.java +++ /dev/null @@ -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 { - -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DeployMapper.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DeployMapper.java deleted file mode 100644 index faf5de749..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/DeployMapper.java +++ /dev/null @@ -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 { - -} diff --git a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/ServerDeployMapper.java b/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/ServerDeployMapper.java deleted file mode 100644 index 53b4b557c..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/mnt/service/mapstruct/ServerDeployMapper.java +++ /dev/null @@ -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 { - -} diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java b/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java index 96b28ea2d..a414afb5a 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java @@ -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 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 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 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 emails = Arrays.asList(quartzJob.getEmail().split("[,,]")); +// emailVo.setTos(emails); +// return emailVo; +// } } diff --git a/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java b/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java index bb8b55fe2..97a783c50 100644 --- a/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java +++ b/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java @@ -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 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 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); +// } /** * 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误 diff --git a/nladmin-system/src/main/java/org/nl/modules/system/rest/VerifyController.java b/nladmin-system/src/main/java/org/nl/modules/system/rest/VerifyController.java deleted file mode 100644 index 41d794a88..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/system/rest/VerifyController.java +++ /dev/null @@ -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 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 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 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); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/system/service/VerifyService.java b/nladmin-system/src/main/java/org/nl/modules/system/service/VerifyService.java index 40e48db3d..c7d7d6e63 100644 --- a/nladmin-system/src/main/java/org/nl/modules/system/service/VerifyService.java +++ b/nladmin-system/src/main/java/org/nl/modules/system/service/VerifyService.java @@ -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); +//} diff --git a/nladmin-system/src/main/java/org/nl/modules/system/service/impl/VerifyServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/system/service/impl/VerifyServiceImpl.java deleted file mode 100644 index 3e5fcd791..000000000 --- a/nladmin-system/src/main/java/org/nl/modules/system/service/impl/VerifyServiceImpl.java +++ /dev/null @@ -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); - } - } -} diff --git a/nladmin-tools/src/main/java/org/nl/domain/AlipayConfig.java b/nladmin-tools/src/main/java/org/nl/domain/AlipayConfig.java deleted file mode 100644 index 54586781c..000000000 --- a/nladmin-tools/src/main/java/org/nl/domain/AlipayConfig.java +++ /dev/null @@ -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.domain; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * 支付宝配置类 - * @author Zheng Jie - * @date 2018-12-31 - */ -@Data -@Entity -@Table(name = "tool_alipay_config") -public class AlipayConfig implements Serializable { - - @Id - @Column(name = "config_id") - @ApiModelProperty(value = "ID", hidden = true) - private Long id; - - @NotBlank - @ApiModelProperty(value = "应用ID") - private String appId; - - @NotBlank - @ApiModelProperty(value = "商户私钥") - private String privateKey; - - @NotBlank - @ApiModelProperty(value = "支付宝公钥") - private String publicKey; - - @ApiModelProperty(value = "签名方式") - private String signType="RSA2"; - - @Column(name = "gateway_url") - @ApiModelProperty(value = "支付宝开放安全地址", hidden = true) - private String gatewayUrl = "https://openapi.alipaydev.com/gateway.do"; - - @ApiModelProperty(value = "编码", hidden = true) - private String charset= "utf-8"; - - @NotBlank - @ApiModelProperty(value = "异步通知地址") - private String notifyUrl; - - @NotBlank - @ApiModelProperty(value = "订单完成后返回的页面") - private String returnUrl; - - @ApiModelProperty(value = "类型") - private String format="JSON"; - - @NotBlank - @ApiModelProperty(value = "商户号") - private String sysServiceProviderId; - -} diff --git a/nladmin-tools/src/main/java/org/nl/domain/EmailConfig.java b/nladmin-tools/src/main/java/org/nl/domain/EmailConfig.java deleted file mode 100644 index d2d5860ab..000000000 --- a/nladmin-tools/src/main/java/org/nl/domain/EmailConfig.java +++ /dev/null @@ -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.domain; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * 邮件配置类,数据存覆盖式存入数据存 - * @author Zheng Jie - * @date 2018-12-26 - */ -@Entity -@Data -@Table(name = "tool_email_config") -public class EmailConfig implements Serializable { - - @Id - @Column(name = "config_id") - @ApiModelProperty(value = "ID", hidden = true) - private Long id; - - @NotBlank - @ApiModelProperty(value = "邮件服务器SMTP地址") - private String host; - - @NotBlank - @ApiModelProperty(value = "邮件服务器 SMTP 端口") - private String port; - - @NotBlank - @ApiModelProperty(value = "发件者用户名") - private String user; - - @NotBlank - @ApiModelProperty(value = "密码") - private String pass; - - @NotBlank - @ApiModelProperty(value = "收件人") - private String fromUser; -} diff --git a/nladmin-tools/src/main/java/org/nl/domain/vo/EmailVo.java b/nladmin-tools/src/main/java/org/nl/domain/vo/EmailVo.java deleted file mode 100644 index 9818ec7e1..000000000 --- a/nladmin-tools/src/main/java/org/nl/domain/vo/EmailVo.java +++ /dev/null @@ -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.domain.vo; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import java.util.List; - -/** - * 发送邮件时,接收参数的类 - * @author 郑杰 - * @date 2018/09/28 12:02:14 - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class EmailVo { - - /** 收件人,支持多个收件人 */ - @NotEmpty - private List tos; - - @NotBlank - private String subject; - - @NotBlank - private String content; -} diff --git a/nladmin-tools/src/main/java/org/nl/repository/AliPayRepository.java b/nladmin-tools/src/main/java/org/nl/repository/AliPayRepository.java deleted file mode 100644 index 0acf7693d..000000000 --- a/nladmin-tools/src/main/java/org/nl/repository/AliPayRepository.java +++ /dev/null @@ -1,26 +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.repository; - -import org.nl.domain.AlipayConfig; -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * @author Zheng Jie - * @date 2018-12-31 - */ -public interface AliPayRepository extends JpaRepository { -} diff --git a/nladmin-tools/src/main/java/org/nl/repository/EmailRepository.java b/nladmin-tools/src/main/java/org/nl/repository/EmailRepository.java deleted file mode 100644 index 3ac40829b..000000000 --- a/nladmin-tools/src/main/java/org/nl/repository/EmailRepository.java +++ /dev/null @@ -1,26 +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.repository; - -import org.nl.domain.EmailConfig; -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * @author Zheng Jie - * @date 2018-12-26 - */ -public interface EmailRepository extends JpaRepository { -} diff --git a/nladmin-tools/src/main/java/org/nl/rest/AliPayController.java b/nladmin-tools/src/main/java/org/nl/rest/AliPayController.java deleted file mode 100644 index d35e2d14d..000000000 --- a/nladmin-tools/src/main/java/org/nl/rest/AliPayController.java +++ /dev/null @@ -1,135 +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.rest; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.annotation.AnonymousAccess; -import org.nl.annotation.Log; -import org.nl.annotation.rest.AnonymousGetMapping; -import org.nl.domain.vo.TradeVo; -import org.nl.domain.AlipayConfig; -import org.nl.utils.AliPayStatusEnum; -import org.nl.utils.AlipayUtils; -import org.nl.service.AliPayService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import springfox.documentation.annotations.ApiIgnore; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.nio.charset.StandardCharsets; -import java.util.Map; - -/** - * @author Zheng Jie - * @date 2018-12-31 - */ -@Slf4j -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/aliPay") -@Api(tags = "工具:支付宝管理") -public class AliPayController { - - private final AlipayUtils alipayUtils; - private final AliPayService alipayService; - - @GetMapping - public ResponseEntity queryConfig() { - return new ResponseEntity<>(alipayService.find(), HttpStatus.OK); - } - - @Log("配置支付宝") - @ApiOperation("配置支付宝") - @PutMapping - public ResponseEntity updateConfig(@Validated @RequestBody AlipayConfig alipayConfig) { - alipayService.config(alipayConfig); - return new ResponseEntity<>(HttpStatus.OK); - } - - @Log("支付宝PC网页支付") - @ApiOperation("PC网页支付") - @PostMapping(value = "/toPayAsPC") - public ResponseEntity toPayAsPc(@Validated @RequestBody TradeVo trade) throws Exception { - AlipayConfig aliPay = alipayService.find(); - trade.setOutTradeNo(alipayUtils.getOrderCode()); - String payUrl = alipayService.toPayAsPc(aliPay, trade); - return ResponseEntity.ok(payUrl); - } - - @Log("支付宝手机网页支付") - @ApiOperation("手机网页支付") - @PostMapping(value = "/toPayAsWeb") - public ResponseEntity toPayAsWeb(@Validated @RequestBody TradeVo trade) throws Exception { - AlipayConfig alipay = alipayService.find(); - trade.setOutTradeNo(alipayUtils.getOrderCode()); - String payUrl = alipayService.toPayAsWeb(alipay, trade); - return ResponseEntity.ok(payUrl); - } - - @ApiIgnore - @AnonymousGetMapping("/return") - @ApiOperation("支付之后跳转的链接") - public ResponseEntity returnPage(HttpServletRequest request, HttpServletResponse response) { - AlipayConfig alipay = alipayService.find(); - response.setContentType("text/html;charset=" + alipay.getCharset()); - //内容验签,防止黑客篡改参数 - if (alipayUtils.rsaCheck(request, alipay)) { - //商户订单号 - String outTradeNo = new String(request.getParameter("out_trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - //支付宝交易号 - String tradeNo = new String(request.getParameter("trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - System.out.println("商户订单号" + outTradeNo + " " + "第三方交易号" + tradeNo); - - // 根据业务需要返回数据,这里统一返回OK - return new ResponseEntity<>("payment successful", HttpStatus.OK); - } else { - // 根据业务需要返回数据 - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); - } - } - - @ApiIgnore - @RequestMapping("/notify") - @AnonymousAccess - @ApiOperation("支付异步通知(要公网访问),接收异步通知,检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致,根据trade_status进行后续业务处理") - public ResponseEntity notify(HttpServletRequest request) { - AlipayConfig alipay = alipayService.find(); - Map parameterMap = request.getParameterMap(); - //内容验签,防止黑客篡改参数 - if (alipayUtils.rsaCheck(request, alipay)) { - //交易状态 - String tradeStatus = new String(request.getParameter("trade_status").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - // 商户订单号 - String outTradeNo = new String(request.getParameter("out_trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - //支付宝交易号 - String tradeNo = new String(request.getParameter("trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - //付款金额 - String totalAmount = new String(request.getParameter("total_amount").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - //验证 - if (tradeStatus.equals(AliPayStatusEnum.SUCCESS.getValue()) || tradeStatus.equals(AliPayStatusEnum.FINISHED.getValue())) { - // 验证通过后应该根据业务需要处理订单 - } - return new ResponseEntity<>(HttpStatus.OK); - } - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); - } -} diff --git a/nladmin-tools/src/main/java/org/nl/rest/EmailController.java b/nladmin-tools/src/main/java/org/nl/rest/EmailController.java deleted file mode 100644 index 92cb09dcd..000000000 --- a/nladmin-tools/src/main/java/org/nl/rest/EmailController.java +++ /dev/null @@ -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.rest; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import org.nl.annotation.Log; -import org.nl.domain.vo.EmailVo; -import org.nl.domain.EmailConfig; -import org.nl.service.EmailService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -/** - * 发送邮件 - * @author 郑杰 - * @date 2018/09/28 6:55:53 - */ -@RestController -@RequiredArgsConstructor -@RequestMapping("api/email") -@Api(tags = "工具:邮件管理") -public class EmailController { - - private final EmailService emailService; - - @GetMapping - public ResponseEntity queryConfig(){ - return new ResponseEntity<>(emailService.find(),HttpStatus.OK); - } - - @Log("配置邮件") - @PutMapping - @ApiOperation("配置邮件") - public ResponseEntity updateConfig(@Validated @RequestBody EmailConfig emailConfig) throws Exception { - emailService.config(emailConfig,emailService.find()); - return new ResponseEntity<>(HttpStatus.OK); - } - - @Log("发送邮件") - @PostMapping - @ApiOperation("发送邮件") - public ResponseEntity sendEmail(@Validated @RequestBody EmailVo emailVo){ - emailService.send(emailVo,emailService.find()); - return new ResponseEntity<>(HttpStatus.OK); - } -} diff --git a/nladmin-tools/src/main/java/org/nl/service/AliPayService.java b/nladmin-tools/src/main/java/org/nl/service/AliPayService.java deleted file mode 100644 index 028b0b2b7..000000000 --- a/nladmin-tools/src/main/java/org/nl/service/AliPayService.java +++ /dev/null @@ -1,57 +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.service; - -import org.nl.domain.vo.TradeVo; -import org.nl.domain.AlipayConfig; - -/** - * @author Zheng Jie - * @date 2018-12-31 - */ -public interface AliPayService { - - /** - * 查询配置 - * @return AlipayConfig - */ - AlipayConfig find(); - - /** - * 更新配置 - * @param alipayConfig 支付宝配置 - * @return AlipayConfig - */ - AlipayConfig config(AlipayConfig alipayConfig); - - /** - * 处理来自PC的交易请求 - * @param alipay 支付宝配置 - * @param trade 交易详情 - * @return String - * @throws Exception 异常 - */ - String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception; - - /** - * 处理来自手机网页的交易请求 - * @param alipay 支付宝配置 - * @param trade 交易详情 - * @return String - * @throws Exception 异常 - */ - String toPayAsWeb(AlipayConfig alipay, TradeVo trade) throws Exception; -} diff --git a/nladmin-tools/src/main/java/org/nl/service/EmailService.java b/nladmin-tools/src/main/java/org/nl/service/EmailService.java deleted file mode 100644 index 878dccf2a..000000000 --- a/nladmin-tools/src/main/java/org/nl/service/EmailService.java +++ /dev/null @@ -1,49 +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.service; - -import org.nl.domain.vo.EmailVo; -import org.nl.domain.EmailConfig; - -/** - * @author Zheng Jie - * @date 2018-12-26 - */ -public interface EmailService { - - /** - * 更新邮件配置 - * @param emailConfig 邮箱配置 - * @param old / - * @return / - * @throws Exception / - */ - EmailConfig config(EmailConfig emailConfig, EmailConfig old) throws Exception; - - /** - * 查询配置 - * @return EmailConfig 邮件配置 - */ - EmailConfig find(); - - /** - * 发送邮件 - * @param emailVo 邮件发送的内容 - * @param emailConfig 邮件配置 - * @throws Exception / - */ - void send(EmailVo emailVo, EmailConfig emailConfig); -} diff --git a/nladmin-tools/src/main/java/org/nl/service/impl/AliPayServiceImpl.java b/nladmin-tools/src/main/java/org/nl/service/impl/AliPayServiceImpl.java deleted file mode 100644 index ac81f0927..000000000 --- a/nladmin-tools/src/main/java/org/nl/service/impl/AliPayServiceImpl.java +++ /dev/null @@ -1,119 +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.service.impl; - -import com.alipay.api.AlipayClient; -import com.alipay.api.DefaultAlipayClient; -import com.alipay.api.request.AlipayTradePagePayRequest; -import com.alipay.api.request.AlipayTradeWapPayRequest; -import lombok.RequiredArgsConstructor; -import org.nl.domain.vo.TradeVo; -import org.nl.domain.AlipayConfig; -import org.nl.exception.BadRequestException; -import org.nl.repository.AliPayRepository; -import org.nl.service.AliPayService; -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.CachePut; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; - -/** - * @author Zheng Jie - * @date 2018-12-31 - */ -@Service -@RequiredArgsConstructor -@CacheConfig(cacheNames = "aliPay") -public class AliPayServiceImpl implements AliPayService { - - private final AliPayRepository alipayRepository; - - @Override - @Cacheable(key = "'config'") - public AlipayConfig find() { - Optional alipayConfig = alipayRepository.findById(1L); - return alipayConfig.orElseGet(AlipayConfig::new); - } - - @Override - @CachePut(key = "'config'") - @Transactional(rollbackFor = Exception.class) - public AlipayConfig config(AlipayConfig alipayConfig) { - alipayConfig.setId(1L); - return alipayRepository.save(alipayConfig); - } - - @Override - public String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception { - - if(alipay.getId() == null){ - throw new BadRequestException("请先添加相应配置,再操作"); - } - AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType()); - - // 创建API对应的request(电脑网页版) - AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); - - // 订单完成后返回的页面和异步通知地址 - request.setReturnUrl(alipay.getReturnUrl()); - request.setNotifyUrl(alipay.getNotifyUrl()); - // 填充订单参数 - request.setBizContent("{" + - " \"out_trade_no\":\""+trade.getOutTradeNo()+"\"," + - " \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," + - " \"total_amount\":"+trade.getTotalAmount()+"," + - " \"subject\":\""+trade.getSubject()+"\"," + - " \"body\":\""+trade.getBody()+"\"," + - " \"extend_params\":{" + - " \"sys_service_provider_id\":\""+alipay.getSysServiceProviderId()+"\"" + - " }"+ - " }");//填充业务参数 - // 调用SDK生成表单, 通过GET方式,口可以获取url - return alipayClient.pageExecute(request, "GET").getBody(); - - } - - @Override - public String toPayAsWeb(AlipayConfig alipay, TradeVo trade) throws Exception { - if(alipay.getId() == null){ - throw new BadRequestException("请先添加相应配置,再操作"); - } - AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType()); - - double money = Double.parseDouble(trade.getTotalAmount()); - double maxMoney = 5000; - if(money <= 0 || money >= maxMoney){ - throw new BadRequestException("测试金额过大"); - } - // 创建API对应的request(手机网页版) - AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); - request.setReturnUrl(alipay.getReturnUrl()); - request.setNotifyUrl(alipay.getNotifyUrl()); - request.setBizContent("{" + - " \"out_trade_no\":\""+trade.getOutTradeNo()+"\"," + - " \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," + - " \"total_amount\":"+trade.getTotalAmount()+"," + - " \"subject\":\""+trade.getSubject()+"\"," + - " \"body\":\""+trade.getBody()+"\"," + - " \"extend_params\":{" + - " \"sys_service_provider_id\":\""+alipay.getSysServiceProviderId()+"\"" + - " }"+ - " }"); - return alipayClient.pageExecute(request, "GET").getBody(); - } -} diff --git a/nladmin-tools/src/main/java/org/nl/service/impl/EmailServiceImpl.java b/nladmin-tools/src/main/java/org/nl/service/impl/EmailServiceImpl.java deleted file mode 100644 index 27a5b1c32..000000000 --- a/nladmin-tools/src/main/java/org/nl/service/impl/EmailServiceImpl.java +++ /dev/null @@ -1,105 +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.service.impl; - -import cn.hutool.extra.mail.Mail; -import cn.hutool.extra.mail.MailAccount; -import lombok.RequiredArgsConstructor; -import org.nl.domain.EmailConfig; -import org.nl.domain.vo.EmailVo; -import org.nl.exception.BadRequestException; -import org.nl.repository.EmailRepository; -import org.nl.service.EmailService; -import org.nl.utils.EncryptUtils; -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.CachePut; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; - -/** - * @author Zheng Jie - * @date 2018-12-26 - */ -@Service -@RequiredArgsConstructor -@CacheConfig(cacheNames = "email") -public class EmailServiceImpl implements EmailService { - - private final EmailRepository emailRepository; - - @Override - @CachePut(key = "'config'") - @Transactional(rollbackFor = Exception.class) - public EmailConfig config(EmailConfig emailConfig, EmailConfig old) throws Exception { - emailConfig.setId(1L); - if(!emailConfig.getPass().equals(old.getPass())){ - // 对称加密 - emailConfig.setPass(EncryptUtils.desEncrypt(emailConfig.getPass())); - } - return emailRepository.save(emailConfig); - } - - @Override - @Cacheable(key = "'config'") - public EmailConfig find() { - Optional emailConfig = emailRepository.findById(1L); - return emailConfig.orElseGet(EmailConfig::new); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void send(EmailVo emailVo, EmailConfig emailConfig){ - if(emailConfig.getId() == null){ - throw new BadRequestException("请先配置,再操作"); - } - // 封装 - MailAccount account = new MailAccount(); - // 设置用户 - String user = emailConfig.getFromUser().split("@")[0]; - account.setUser(user); - account.setHost(emailConfig.getHost()); - account.setPort(Integer.parseInt(emailConfig.getPort())); - account.setAuth(true); - try { - // 对称解密 - account.setPass(EncryptUtils.desDecrypt(emailConfig.getPass())); - } catch (Exception e) { - throw new BadRequestException(e.getMessage()); - } - account.setFrom(emailConfig.getUser()+"<"+emailConfig.getFromUser()+">"); - // ssl方式发送 - account.setSslEnable(true); - // 使用STARTTLS安全连接 - account.setStarttlsEnable(true); - String content = emailVo.getContent(); - // 发送 - try { - int size = emailVo.getTos().size(); - Mail.create(account) - .setTos(emailVo.getTos().toArray(new String[size])) - .setTitle(emailVo.getSubject()) - .setContent(content) - .setHtml(true) - //关闭session - .setUseGlobalSession(false) - .send(); - }catch (Exception e){ - throw new BadRequestException(e.getMessage()); - } - } -} diff --git a/nladmin-tools/src/main/java/org/nl/utils/AliPayStatusEnum.java b/nladmin-tools/src/main/java/org/nl/utils/AliPayStatusEnum.java deleted file mode 100644 index 4aa306684..000000000 --- a/nladmin-tools/src/main/java/org/nl/utils/AliPayStatusEnum.java +++ /dev/null @@ -1,46 +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.utils; - -/** - * 支付状态 - * @author zhengjie - * @date 2018/08/01 16:45:43 - */ -public enum AliPayStatusEnum { - - /** 交易成功 */ - FINISHED("TRADE_FINISHED"), - - /** 支付成功 */ - SUCCESS("TRADE_SUCCESS"), - - /** 交易创建 */ - BUYER_PAY("WAIT_BUYER_PAY"), - - /** 交易关闭 */ - CLOSED("TRADE_CLOSED"); - - private final String value; - - AliPayStatusEnum(String value) { - this.value = value; - } - - public String getValue() { - return value; - } -} diff --git a/nladmin-tools/src/main/java/org/nl/utils/AlipayUtils.java b/nladmin-tools/src/main/java/org/nl/utils/AlipayUtils.java deleted file mode 100644 index 93d92236c..000000000 --- a/nladmin-tools/src/main/java/org/nl/utils/AlipayUtils.java +++ /dev/null @@ -1,85 +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.utils; - -import com.alipay.api.AlipayApiException; -import com.alipay.api.internal.util.AlipaySignature; -import org.nl.domain.AlipayConfig; -import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletRequest; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * 支付宝工具类 - * @author zhengjie - * @date 2018/09/30 14:04:35 - */ -@Component -public class AlipayUtils { - - /** - * 生成订单号 - * @return String - */ - public String getOrderCode() { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - int a = (int)(Math.random() * 9000.0D) + 1000; - System.out.println(a); - Date date = new Date(); - String str = sdf.format(date); - String[] split = str.split("-"); - String s = split[0] + split[1] + split[2]; - String[] split1 = s.split(" "); - String s1 = split1[0] + split1[1]; - String[] split2 = s1.split(":"); - return split2[0] + split2[1] + split2[2] + a; - } - - /** - * 校验签名 - * @param request HttpServletRequest - * @param alipay 阿里云配置 - * @return boolean - */ - public boolean rsaCheck(HttpServletRequest request, AlipayConfig alipay){ - - // 获取支付宝POST过来反馈信息 - Map params = new HashMap<>(1); - Map requestParams = request.getParameterMap(); - for (Object o : requestParams.keySet()) { - String name = (String) o; - String[] values = requestParams.get(name); - String valueStr = ""; - for (int i = 0; i < values.length; i++) { - valueStr = (i == values.length - 1) ? valueStr + values[i] - : valueStr + values[i] + ","; - } - params.put(name, valueStr); - } - - try { - return AlipaySignature.rsaCheckV1(params, - alipay.getPublicKey(), - alipay.getCharset(), - alipay.getSignType()); - } catch (AlipayApiException e) { - return false; - } - } -} diff --git a/nladmin-ui/src/api/mnt/app.js b/nladmin-ui/src/api/mnt/app.js deleted file mode 100644 index 2a270544c..000000000 --- a/nladmin-ui/src/api/mnt/app.js +++ /dev/null @@ -1,27 +0,0 @@ -import request from '@/utils/request' - -export function add(data) { - return request({ - url: 'api/app', - method: 'post', - data - }) -} - -export function del(ids) { - return request({ - url: 'api/app', - method: 'delete', - data: ids - }) -} - -export function edit(data) { - return request({ - url: 'api/app', - method: 'put', - data - }) -} - -export default { add, edit, del } diff --git a/nladmin-ui/src/api/mnt/connect.js b/nladmin-ui/src/api/mnt/connect.js deleted file mode 100644 index 1bbe90be7..000000000 --- a/nladmin-ui/src/api/mnt/connect.js +++ /dev/null @@ -1,17 +0,0 @@ -import request from '@/utils/request' - -export function testDbConnect(data) { - return request({ - url: 'api/database/testConnect', - method: 'post', - data - }) -} - -export function testServerConnect(data) { - return request({ - url: 'api/serverDeploy/testConnect', - method: 'post', - data - }) -} diff --git a/nladmin-ui/src/api/mnt/database.js b/nladmin-ui/src/api/mnt/database.js deleted file mode 100644 index 91797fb99..000000000 --- a/nladmin-ui/src/api/mnt/database.js +++ /dev/null @@ -1,35 +0,0 @@ -import request from '@/utils/request' - -export function add(data) { - return request({ - url: 'api/database', - method: 'post', - data - }) -} - -export function del(ids) { - return request({ - url: 'api/database', - method: 'delete', - data: ids - }) -} - -export function edit(data) { - return request({ - url: 'api/database', - method: 'put', - data - }) -} - -export function testDbConnection(data) { - return request({ - url: 'api/database/testConnect', - method: 'post', - data - }) -} - -export default { add, edit, del, testDbConnection } diff --git a/nladmin-ui/src/api/mnt/deploy.js b/nladmin-ui/src/api/mnt/deploy.js deleted file mode 100644 index c1475ea2a..000000000 --- a/nladmin-ui/src/api/mnt/deploy.js +++ /dev/null @@ -1,77 +0,0 @@ -import request from '@/utils/request' - -export function add(data) { - return request({ - url: 'api/deploy', - method: 'post', - data - }) -} - -export function del(ids) { - return request({ - url: 'api/deploy', - method: 'delete', - data: ids - }) -} - -export function edit(data) { - return request({ - url: 'api/deploy', - method: 'put', - data - }) -} - -export function getApps() { - return request({ - url: 'api/app', - method: 'get' - }) -} - -export function getServers() { - return request({ - url: 'api/serverDeploy', - method: 'get' - }) -} - -/** - * 启动服务 - * @param data 选中行 - */ -export function startServer(data) { - return request({ - url: 'api/deploy/startServer', - method: 'post', - data - }) -} - -/** - * 停止服务 - * @param data 选中行 - */ -export function stopServer(data) { - return request({ - url: 'api/deploy/stopServer', - method: 'post', - data - }) -} - -/** - * 停止服务 - * @param data 选中行 - */ -export function serverStatus(data) { - return request({ - url: 'api/deploy/serverStatus', - method: 'post', - data - }) -} - -export default { add, edit, del, stopServer, serverStatus, startServer, getServers, getApps } diff --git a/nladmin-ui/src/api/mnt/deployHistory.js b/nladmin-ui/src/api/mnt/deployHistory.js deleted file mode 100644 index 30335e4ed..000000000 --- a/nladmin-ui/src/api/mnt/deployHistory.js +++ /dev/null @@ -1,21 +0,0 @@ -import request from '@/utils/request' - -export function del(ids) { - return request({ - url: 'api/deployHistory', - method: 'delete', - data: ids - }) -} - -/** - * 版本回退 - * @param data 选中行 - */ -export function reducte(data) { - return request({ - url: 'api/deploy/serverReduction', - method: 'post', - data - }) -} diff --git a/nladmin-ui/src/api/mnt/serverDeploy.js b/nladmin-ui/src/api/mnt/serverDeploy.js deleted file mode 100644 index e7961140e..000000000 --- a/nladmin-ui/src/api/mnt/serverDeploy.js +++ /dev/null @@ -1,27 +0,0 @@ -import request from '@/utils/request' - -export function add(data) { - return request({ - url: 'api/serverDeploy', - method: 'post', - data - }) -} - -export function del(ids) { - return request({ - url: 'api/serverDeploy', - method: 'delete', - data: ids - }) -} - -export function edit(data) { - return request({ - url: 'api/serverDeploy', - method: 'put', - data - }) -} - -export default { add, edit, del } diff --git a/nladmin-ui/src/api/tools/email.js b/nladmin-ui/src/api/tools/email.js deleted file mode 100644 index af030cb04..000000000 --- a/nladmin-ui/src/api/tools/email.js +++ /dev/null @@ -1,24 +0,0 @@ -import request from '@/utils/request' - -export function get() { - return request({ - url: 'api/email', - method: 'get' - }) -} - -export function update(data) { - return request({ - url: 'api/email', - data, - method: 'put' - }) -} - -export function send(data) { - return request({ - url: 'api/email', - data, - method: 'post' - }) -} diff --git a/nladmin-ui/src/components/YamlEdit/index.vue b/nladmin-ui/src/components/YamlEdit/index.vue deleted file mode 100644 index 83778f488..000000000 --- a/nladmin-ui/src/components/YamlEdit/index.vue +++ /dev/null @@ -1,81 +0,0 @@ -