first commit

This commit is contained in:
zeaslity
2022-11-21 16:12:44 +08:00
commit 9ab310bc4a
246 changed files with 24402 additions and 0 deletions

33
server/.gitignore vendored Normal file
View File

@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

105
server/pom.xml Normal file
View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.wdd</groupId>
<artifactId>ProjectOctopus</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>server</name>
<description>server</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>io.wdd</groupId>
<artifactId>ProjectOctopus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<!--<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-influx</artifactId>
<scope>runtime</scope>
</dependency>-->
<!--mybatis-plus的依赖-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<!--<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.19</version>
</dependency>-->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
<!--<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,15 @@
package io.wdd.server;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("io.wdd.server.mapper")
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}

View File

@@ -0,0 +1,123 @@
package io.wdd.server.beans.po;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.cglib.core.Local;
/**
*
* @TableName app_info
*/
@TableName(value ="app_info")
@Data
public class AppInfoPO implements Serializable {
/**
*
*/
@TableId
private Long appId;
/**
*
*/
private String appName;
/**
*
*/
private String appInfo;
/**
*
*/
private String appVersion;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
*
*/
private String commont;
/**
* 0 alive || 1 deleted
*/
private Integer isDelete;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
AppInfoPO other = (AppInfoPO) that;
return (this.getAppId() == null ? other.getAppId() == null : this.getAppId().equals(other.getAppId()))
&& (this.getAppName() == null ? other.getAppName() == null : this.getAppName().equals(other.getAppName()))
&& (this.getAppInfo() == null ? other.getAppInfo() == null : this.getAppInfo().equals(other.getAppInfo()))
&& (this.getAppVersion() == null ? other.getAppVersion() == null : this.getAppVersion().equals(other.getAppVersion()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getCommont() == null ? other.getCommont() == null : this.getCommont().equals(other.getCommont()))
&& (this.getIsDelete() == null ? other.getIsDelete() == null : this.getIsDelete().equals(other.getIsDelete()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getAppId() == null) ? 0 : getAppId().hashCode());
result = prime * result + ((getAppName() == null) ? 0 : getAppName().hashCode());
result = prime * result + ((getAppInfo() == null) ? 0 : getAppInfo().hashCode());
result = prime * result + ((getAppVersion() == null) ? 0 : getAppVersion().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getCommont() == null) ? 0 : getCommont().hashCode());
result = prime * result + ((getIsDelete() == null) ? 0 : getIsDelete().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", appId=").append(appId);
sb.append(", appName=").append(appName);
sb.append(", appInfo=").append(appInfo);
sb.append(", appVersion=").append(appVersion);
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", commont=").append(commont);
sb.append(", isDelete=").append(isDelete);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,185 @@
package io.wdd.server.beans.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @TableName server_info
*/
@TableName(value = "server_info")
@Data
public class ServerInfoPO implements Serializable {
@TableField(exist = false)
private static final long serialVersionUID = 1L;
/**
* server primary key
*/
@TableId(type = IdType.AUTO)
private Long serverId;
/**
* server host name
*/
private String serverName;
/**
* server public ipv4
*/
private String serverIpPbV4;
/**
* server inner ipv4
*/
private String serverIpInV4;
/**
* server public ipv6
*/
private String serverIpPbV6;
/**
* server inner ipv6
*/
private String serverIpInV6;
/**
*
*/
private LocalDateTime registerTime;
/**
*
*/
private LocalDateTime expireTime;
/**
*
*/
private LocalDateTime updateTime;
/**
*
*/
private String location;
/**
*
*/
private String provider;
/**
* split by ,
*/
private String managePort;
/**
*
*/
private Integer cpuCore;
/**
*
*/
private String cpuBrand;
/**
*
*/
private String osInfo;
/**
*
*/
private String osKernelInfo;
/**
*
*/
private String comment;
/**
* 0 alive || 1 deleted
*/
private Integer isDelete;
/**
* optimistic lock for concurrent
*/
private Integer version;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
ServerInfoPO other = (ServerInfoPO) that;
return (this.getServerId() == null ? other.getServerId() == null : this.getServerId().equals(other.getServerId()))
&& (this.getServerName() == null ? other.getServerName() == null : this.getServerName().equals(other.getServerName()))
&& (this.getServerIpPbV4() == null ? other.getServerIpPbV4() == null : this.getServerIpPbV4().equals(other.getServerIpPbV4()))
&& (this.getServerIpInV4() == null ? other.getServerIpInV4() == null : this.getServerIpInV4().equals(other.getServerIpInV4()))
&& (this.getServerIpPbV6() == null ? other.getServerIpPbV6() == null : this.getServerIpPbV6().equals(other.getServerIpPbV6()))
&& (this.getServerIpInV6() == null ? other.getServerIpInV6() == null : this.getServerIpInV6().equals(other.getServerIpInV6()))
&& (this.getRegisterTime() == null ? other.getRegisterTime() == null : this.getRegisterTime().equals(other.getRegisterTime()))
&& (this.getExpireTime() == null ? other.getExpireTime() == null : this.getExpireTime().equals(other.getExpireTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getLocation() == null ? other.getLocation() == null : this.getLocation().equals(other.getLocation()))
&& (this.getProvider() == null ? other.getProvider() == null : this.getProvider().equals(other.getProvider()))
&& (this.getManagePort() == null ? other.getManagePort() == null : this.getManagePort().equals(other.getManagePort()))
&& (this.getCpuCore() == null ? other.getCpuCore() == null : this.getCpuCore().equals(other.getCpuCore()))
&& (this.getCpuBrand() == null ? other.getCpuBrand() == null : this.getCpuBrand().equals(other.getCpuBrand()))
&& (this.getOsInfo() == null ? other.getOsInfo() == null : this.getOsInfo().equals(other.getOsInfo()))
&& (this.getOsKernelInfo() == null ? other.getOsKernelInfo() == null : this.getOsKernelInfo().equals(other.getOsKernelInfo()))
&& (this.getComment() == null ? other.getComment() == null : this.getComment().equals(other.getComment()))
&& (this.getIsDelete() == null ? other.getIsDelete() == null : this.getIsDelete().equals(other.getIsDelete()))
&& (this.getVersion() == null ? other.getVersion() == null : this.getVersion().equals(other.getVersion()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getServerId() == null) ? 0 : getServerId().hashCode());
result = prime * result + ((getServerName() == null) ? 0 : getServerName().hashCode());
result = prime * result + ((getServerIpPbV4() == null) ? 0 : getServerIpPbV4().hashCode());
result = prime * result + ((getServerIpInV4() == null) ? 0 : getServerIpInV4().hashCode());
result = prime * result + ((getServerIpPbV6() == null) ? 0 : getServerIpPbV6().hashCode());
result = prime * result + ((getServerIpInV6() == null) ? 0 : getServerIpInV6().hashCode());
result = prime * result + ((getRegisterTime() == null) ? 0 : getRegisterTime().hashCode());
result = prime * result + ((getExpireTime() == null) ? 0 : getExpireTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getLocation() == null) ? 0 : getLocation().hashCode());
result = prime * result + ((getProvider() == null) ? 0 : getProvider().hashCode());
result = prime * result + ((getManagePort() == null) ? 0 : getManagePort().hashCode());
result = prime * result + ((getCpuCore() == null) ? 0 : getCpuCore().hashCode());
result = prime * result + ((getCpuBrand() == null) ? 0 : getCpuBrand().hashCode());
result = prime * result + ((getOsInfo() == null) ? 0 : getOsInfo().hashCode());
result = prime * result + ((getOsKernelInfo() == null) ? 0 : getOsKernelInfo().hashCode());
result = prime * result + ((getComment() == null) ? 0 : getComment().hashCode());
result = prime * result + ((getIsDelete() == null) ? 0 : getIsDelete().hashCode());
result = prime * result + ((getVersion() == null) ? 0 : getVersion().hashCode());
return result;
}
@Override
public String toString() {
String sb = getClass().getSimpleName() +
" [" +
"Hash = " + hashCode() +
", serverId=" + serverId +
", serverName=" + serverName +
", serverIpPbV4=" + serverIpPbV4 +
", serverIpInV4=" + serverIpInV4 +
", serverIpPbV6=" + serverIpPbV6 +
", serverIpInV6=" + serverIpInV6 +
", registerTime=" + registerTime +
", expireTime=" + expireTime +
", updateTime=" + updateTime +
", location=" + location +
", provider=" + provider +
", managePort=" + managePort +
", cpuCore=" + cpuCore +
", cpuBrand=" + cpuBrand +
", osInfo=" + osInfo +
", osKernelInfo=" + osKernelInfo +
", comment=" + comment +
", isDelete=" + isDelete +
", version=" + version +
", serialVersionUID=" + serialVersionUID +
"]";
return sb;
}
}

View File

@@ -0,0 +1,51 @@
package io.wdd.server.beans.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.wdd.server.beans.po.AppInfoPO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder(toBuilder = true)
public class AppInfoVO {
private String appName;
/**
*
*/
private String appInfo;
/**
*
*/
private String appVersion;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
*
*/
private String commont;
}

View File

@@ -0,0 +1,121 @@
package io.wdd.server.beans.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import javax.annotation.Nullable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder(toBuilder = true)
public class ServerInfoVO {
/**
* server host name
*/
private String serverName;
/**
* server public ipv4
*/
private String serverIpPbV4;
/**
* server inner ipv4
*/
private String serverIpInV4;
/**
* server public ipv6
*/
private String serverIpPbV6;
/**
* server inner ipv6
*/
private String serverIpInV6;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime registerTime;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime expireTime;
/**
*
*/
private String location;
/**
*
*/
private String provider;
/**
*
*/
@Nullable
private Integer managePort;
/**
*
*/
private Integer cpuCore;
/**
*
*/
@Nullable
private String cpuBrand;
/**
*
*/
@Nullable
private String osInfo;
/**
*
*/
@Nullable
private String osKernelInfo;
/**
*
*/
@Nullable
private String comment;
/**
* server is deleted or not ?
*/
private Integer isDelete;
private Integer version;
}

View File

@@ -0,0 +1,63 @@
package io.wdd.server.controller;
import io.wdd.common.R;
import io.wdd.server.beans.vo.AppInfoVO;
import io.wdd.server.coreService.CoreAppService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/app")
public class AppController {
@Resource
CoreAppService coreAppService;
@GetMapping("/all")
public R<List<AppInfoVO>> getAllAppInfo() {
return R.ok(coreAppService.getAppInfoAll());
}
@GetMapping("/single")
public R<AppInfoVO> getAppInfo(
@RequestParam(value = "appId", required = false) @Nullable Long appId,
@RequestParam(value = "appName", required = false) @Nullable String appName
) {
return R.ok(coreAppService.getAppInfo(appId, appName));
}
@PostMapping("/new")
public R createNewApp(
@RequestBody @Validated AppInfoVO appInfoVO) {
if (coreAppService.createAppInfo(appInfoVO)) {
return R.ok("App created successfully !");
}
return R.failed("App created failed !");
}
@PostMapping("/delete")
public R deleteApp(
@RequestParam(value = "appId") Long appId
){
if (coreAppService.deleteAppInfo(appId)) {
return R.ok("app delete successfully !");
}
return R.failed("App delete failed !");
}
}

View File

@@ -0,0 +1,75 @@
package io.wdd.server.controller;
import io.wdd.common.R;
import io.wdd.server.beans.po.ServerInfoPO;
import io.wdd.server.beans.vo.ServerInfoVO;
import io.wdd.server.coreService.CoreServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/server")
public class ServerController {
@Autowired
CoreServerService coreServerService;
@GetMapping("/all")
public R<List> getAllServerInfo() {
return R.ok(coreServerService.getServerInfoList());
}
@GetMapping("/allIncludeDelete")
public R<List> getAllServerInfoIncludeDelete() {
return R.ok(coreServerService.getServerInfoListIncludeDelete());
}
@PostMapping("/single")
public R getSingleServerInfo(
@RequestParam(value = "serverIPv4") @Nullable String ipv4,
@RequestParam(value = "serverName") @Nullable String serverName,
@RequestParam(value = "serverLocation") @Nullable String serverLocation
) {
return R.ok(coreServerService.getServerInfoSingle(serverName, ipv4, serverLocation));
}
@PostMapping("/newServer")
public R createServerInfo(@RequestBody @Validated ServerInfoVO serverInfoVO) {
if (coreServerService.createServerInfo(serverInfoVO)) {
return R.ok("Create Server Success !");
}
return R.failed("Create Server Failed !");
}
@PostMapping("/updateServerInfo")
public R updateServerInfo(@RequestBody ServerInfoPO serverInfoPO) {
if (coreServerService.updateServerInfo(serverInfoPO)) {
return R.ok("Server info update successfully !");
}
return R.failed("Server info update failed !");
}
@PostMapping("/deleteServer")
public R deleteServer(
@RequestParam(value = "serverId") @Nullable Long serverId,
@RequestParam(value = "serverName") @Nullable String serverName) {
if (coreServerService.deleteServer(serverId, serverName)) {
R.ok("Delete Server Successfully !");
}
return R.failed("Delete Server Failed !");
}
}

View File

@@ -0,0 +1,24 @@
package io.wdd.server.coreService;
import io.wdd.server.beans.vo.AppInfoVO;
import java.util.List;
public interface CoreAppService {
AppInfoVO getAppInfo(Long appId, String appName);
List<AppInfoVO> getAppInfoAll();
boolean createAppInfo(AppInfoVO appInfoVO);
boolean updateAppInfo(AppInfoVO appInfoVO);
boolean deleteAppInfo(Long appId);
}

View File

@@ -0,0 +1,21 @@
package io.wdd.server.coreService;
import io.wdd.server.beans.po.ServerInfoPO;
import io.wdd.server.beans.vo.ServerInfoVO;
import java.util.List;
public interface CoreServerService {
List<ServerInfoPO> getServerInfoSingle(String serverName, String ipv4, String serverLocation);
List<ServerInfoVO> getServerInfoList();
List<ServerInfoVO> getServerInfoListIncludeDelete();
boolean createServerInfo(ServerInfoVO serverInfoVO);
boolean updateServerInfo(ServerInfoPO serverInfoPO);
boolean deleteServer(Long serverId, String serverName);
}

View File

@@ -0,0 +1,63 @@
package io.wdd.server.coreService.impl;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import io.wdd.server.beans.po.AppInfoPO;
import io.wdd.server.beans.vo.AppInfoVO;
import io.wdd.server.coreService.CoreAppService;
import io.wdd.server.service.AppInfoService;
import io.wdd.server.utils.EntityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class CoreAppServiceImpl implements CoreAppService {
@Resource
AppInfoService appInfoService;
@Override
public AppInfoVO getAppInfo(Long appId, String appName) {
List<AppInfoPO> appInfoPOList = new LambdaQueryChainWrapper<AppInfoPO>(appInfoService.getBaseMapper())
.eq(appId != null, AppInfoPO::getAppId, appId)
.eq(StringUtils.isNoneEmpty(appName), AppInfoPO::getAppName, appName)
.list();
List<AppInfoVO> appInfoPVOList = EntityUtils.cvToTarget(appInfoPOList, AppInfoVO.class);
return appInfoPVOList.get(0);
}
@Override
public List<AppInfoVO> getAppInfoAll() {
return EntityUtils.cvToTarget(appInfoService.list(), AppInfoVO.class);
}
@Override
public boolean createAppInfo(AppInfoVO appInfoVO) {
return appInfoService.save(
EntityUtils.cvToTarget(appInfoVO,AppInfoPO.class)
);
}
@Override
public boolean updateAppInfo(AppInfoVO appInfoVO) {
return appInfoService.updateById(
EntityUtils.cvToTarget(appInfoVO,AppInfoPO.class)
);
}
@Override
public boolean deleteAppInfo(Long appId) {
return appInfoService.removeById(appId);
}
}

View File

@@ -0,0 +1,104 @@
package io.wdd.server.coreService.impl;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import io.wdd.server.beans.po.ServerInfoPO;
import io.wdd.server.beans.vo.ServerInfoVO;
import io.wdd.server.coreService.CoreServerService;
import io.wdd.server.service.ServerInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class CoreServerServiceImpl implements CoreServerService {
@Autowired
ServerInfoService serverInfoService;
@Override
public List<ServerInfoPO> getServerInfoSingle(String serverName, String ipv4, String serverLocation) {
// ignore if deleted !
return new LambdaQueryChainWrapper<>(serverInfoService.getBaseMapper())
.eq(StringUtils.isNoneEmpty(serverName), ServerInfoPO::getServerName, serverName)
.eq(StringUtils.isNoneEmpty(ipv4), ServerInfoPO::getServerIpPbV4, ipv4)
.eq(StringUtils.isNoneEmpty(serverLocation), ServerInfoPO::getLocation, serverLocation)
.list();
}
@Override
public List<ServerInfoVO> getServerInfoList() {
List<ServerInfoPO> serverInfoPOWithOutDelete = serverInfoService.list();
return covertServerPOtoVO(serverInfoPOWithOutDelete);
}
@Override
public List<ServerInfoVO> getServerInfoListIncludeDelete() {
return this.covertServerPOtoVO(serverInfoService.getAll());
}
@Override
public boolean createServerInfo(ServerInfoVO serverInfoVO) {
ServerInfoPO serverInfoPO = new ServerInfoPO();
BeanUtils.copyProperties(serverInfoVO, serverInfoPO);
return serverInfoService.save(serverInfoPO);
}
@Override
public boolean updateServerInfo(ServerInfoPO serverInfoPO) {
if (serverInfoPO.getServerId() == null) {
return false;
}
return new LambdaUpdateChainWrapper<>(serverInfoService.getBaseMapper())
.eq(ServerInfoPO::getServerId, serverInfoPO.getServerId())
.update(serverInfoPO);
}
@Override
public boolean deleteServer(Long serverId, String serverName) {
if (serverId == null && StringUtils.isBlank(serverName)) {
return false;
}
// set isDelete = 1
return new LambdaUpdateChainWrapper<>(serverInfoService.getBaseMapper())
.eq(serverId != null, ServerInfoPO::getServerId, serverId)
.eq(StringUtils.isNoneEmpty(serverName), ServerInfoPO::getServerName, serverName)
.set(ServerInfoPO::getIsDelete, 1)
.update();
}
private List<ServerInfoVO> covertServerPOtoVO(List<ServerInfoPO> serverInfoPOList){
if (null == serverInfoPOList || serverInfoPOList.size() == 0) {
return Collections.emptyList();
}
return serverInfoPOList.stream().map(serverInfoPO -> {
ServerInfoVO serverInfoVO = new ServerInfoVO();
BeanUtils.copyProperties(serverInfoPO, serverInfoVO);
return serverInfoVO;
}
).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,189 @@
package io.wdd.server.handler;
import com.google.common.collect.Maps;
import io.wdd.common.R;
import io.wdd.common.ResultStat;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.*;
/**
* 自定义 全局异常处理类
* 全局处理响应数据的全局处理类继承ResponseBodyAdvice接口重写其中的方法
* (带有@RequestMapping注解的方法上抛出的异常都会拦截在此统一处理并统一返回数据格式
*/
@RestControllerAdvice
@Slf4j(topic = "Global Exception")
public class GlobalExceptionHandler {
@Autowired
private MyMessageSource messageSource;
/**
* 全局异常拦截方法
* 这里拦截此异常,将异常中的信息提取返回有效信息!
*
* @param e SpringBoot参数校验(valid)过程中,检验失败会产生此异常,在此处拦截
* @return
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
public R<Object> MethodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
// 从异常对象中拿到ObjectError对象获取所有的错误信息
List<ObjectError> objectError = e.getBindingResult().getAllErrors();
// 然后提取错误提示信息进行返回
HashMap<Integer, String> errorMap = new HashMap<>();
objectError.forEach(objectError1 -> errorMap.put(objectError.indexOf(objectError1), objectError1.getDefaultMessage()));
// 使用标准化返回体返回数据
return R.resetResult(ResultStat.VALIDATE_FAILED.getCode(), ResultStat.VALIDATE_FAILED.getDescription(), errorMap);
//return errorMap;
}
/**
* @param exception 参数类型错误,拦截器
* @return
*/
@ExceptionHandler(value = MethodArgumentTypeMismatchException.class)
public Object methodArgumentNotValidException(MethodArgumentTypeMismatchException exception) {
//按需重新封装需要返回的错误信息
Map<String, String> invalidMap = new LinkedHashMap(99);
//解析原错误信息,封装后返回,此处返回非法的字段名称,原始值,错误信息
invalidMap.put(exception.getParameter().getParameterName(), ResultStat.PARAM_ERROR.getDescription());
R<Map<String, String>> vo = new R<>();
vo.setCode(ResultStat.PARAM_ERROR.getCode());
vo.setMsg(getLocaleMsg(ResultStat.PARAM_ERROR.getDescription()));
vo.setData(invalidMap);
log.debug(exception.getMessage(), exception);
return vo;
}
/**
* 拦截数据库异常
*
* @param exception 数据库异常
* @return
*/
@ExceptionHandler(value = {SQLException.class, DuplicateKeyException.class})
public R<String> sqlExceptionHandler(SQLException exception) {
R<String> vo = new R<>();
vo.setCode(ResultStat.PARAM_ERROR.getCode());
vo.setMsg(getLocaleMsg(ResultStat.PARAM_ERROR.getDescription()));
if (exception instanceof SQLIntegrityConstraintViolationException) {
vo.setData("Data already exsit ! 操作失败!");
} else {
vo.setData("数据库异常,操作失败!");
}
log.debug(exception.getMessage(), exception);
return vo;
}
@ExceptionHandler(MyRuntimeException.class)
public R<Object> interceptMyRuntimeE(MyRuntimeException exception) {
R<Object> R = new R<>();
ResultStat status = exception.getStatus();
if (status != null) {
R.setMsg(getLocaleMsg(exception.getMessage(), exception.getParams()));
R.setCode(status.getCode());
R.setData(exception.getData());
} else {
R.setCode(ResultStat.FAILED.getCode());
R.setMsg(getLocaleMsg(exception.getMessage(), exception.getParams()));
R.setData(null);
}
return R;
}
// /**
// *
// * 统一Spring Security的认证错误
// * */
// @ExceptionHandler(value = BadCredentialsException.class)
// public R<Object> badCredentialsException(BadCredentialsException exception){
//
// log.error(exception.getDescription());
//
// return R.failed(ResultStat.USER_AUTH_FAILED);
// }
/**
* validate 验证错误handle
*/
@ExceptionHandler(value = BindException.class)
public Object bindExceptionHandler(BindException exception) {
//按需重新封装需要返回的错误信息
Map<String, String> invalidMap = Maps.newLinkedHashMap();
//解析原错误信息,封装后返回,此处返回非法的字段名称,原始值,错误信息
if (exception != null) {
List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
fieldErrors.stream().sorted(Comparator.comparing(FieldError::getCode)).forEach(error -> {
String defaultMessage = error.getDefaultMessage();
String finalMessage = defaultMessage;
if (defaultMessage != null && defaultMessage.startsWith("{") && defaultMessage.endsWith("}")) {
finalMessage = messageSource.getMessage(defaultMessage.substring(1, defaultMessage.length() - 1));
}
if (StringUtils.isNotEmpty(invalidMap.get(error.getField()))) {
invalidMap.put(error.getField(),
invalidMap.get(error.getField()) + "," + finalMessage);
} else {
invalidMap.put(error.getField(), finalMessage);
}
});
}
R<Map<String, String>> vo = new R<>();
vo.setCode(ResultStat.VALIDATE_FAILED.getCode());
vo.setMsg(getLocaleMsg(ResultStat.VALIDATE_FAILED.getDescription()));
vo.setData(invalidMap);
log.debug(exception.getMessage(), exception);
return vo;
}
/**
* 默认异常统一处理 Exception
*/
@ExceptionHandler(value = Exception.class)
public Object exceptionHandel(Exception e) {
return getResponseVO(e, getLocaleMsg("系统错误,请联系管理员"));
}
private Object getResponseVO(Exception e, String msg) {
R<String> R = new R<>();
R.setCode(ResultStat.FAILED.getCode());
R.setMsg(msg);
R.setMsg(e.getMessage());
log.error(e.getMessage(), e);
return R;
}
private String getLocaleMsg(String msgCode, Object... params) {
return messageSource.getMessage(msgCode, params);
}
}

View File

@@ -0,0 +1,36 @@
package io.wdd.server.handler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@Component
@Slf4j
public class MyBatisAutoInsertInterceptor implements MetaObjectHandler {
/**
* mybatis will inject and deal with some field defined down there
* @param metaObject
*/
@Override
public void insertFill(MetaObject metaObject) {
log.info("MyBaitsPlus start to insert manually !");
this.strictInsertFill(metaObject, "registerTime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
this.strictInsertFill(metaObject, "create_time", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
}
@Override
public void updateFill(MetaObject metaObject) {
log.info("MyBaitsPlus start to update manually !");
this.strictInsertFill(metaObject, "updateTime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
this.strictInsertFill(metaObject, "update_time", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
}
}

View File

@@ -0,0 +1,69 @@
package io.wdd.server.handler;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Locale;
@Component
public class MyMessageSource {
@Resource
private MessageSource messageSource;
public MyMessageSource() {
}
public String getMessage(String code, Object... params) {
return this.getMessage(code, (Object[])null, params);
}
public String getMessageIgnoreMissMatch(String code, Object... params) {
Locale locale = LocaleContextHolder.getLocale();
String message = this.messageSource.getMessage(code, (Object[])null, code, locale);
return this.parse(message, true, params);
}
public String getMessage(String code, Object[] args, Object... params) {
return this.getMessage(code, args, code, params);
}
public String getMessage(String code, Object[] args, String defaultMessage, Object... params) {
Locale locale = LocaleContextHolder.getLocale();
String message = this.messageSource.getMessage(code, args, defaultMessage, locale);
return this.parse(message, false, params);
}
private String parse(String s, boolean ingoreParamsMissMath, Object... params) {
if (s == null) {
return null;
} else if (params == null) {
return s;
} else {
String[] splits = s.split("\\{}", -1);
if (splits.length != params.length + 1) {
if (ingoreParamsMissMath) {
return s;
} else {
throw new IllegalArgumentException("The number of parameters is inconsistent with the parameter value");
}
} else if (splits.length == 1) {
return s;
} else {
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < splits.length; ++i) {
String split = splits[i];
stringBuilder.append(split);
if (i < params.length) {
stringBuilder.append(params[i]);
}
}
return stringBuilder.toString();
}
}
}
}

View File

@@ -0,0 +1,43 @@
package io.wdd.server.handler;
import io.wdd.common.ResultStat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MyRuntimeException extends RuntimeException {
private Object data;
private ResultStat status;
private Object[] params;
public MyRuntimeException(String msg) {
super(msg);
}
public MyRuntimeException(String msg, Object... params) {
super(msg);
this.params = params;
}
public MyRuntimeException(ResultStat status, Object data, String msg, Object... params) {
super(msg == null ? status.getDescription() : msg);
this.data = data;
this.status = status;
this.params = params;
}
public MyRuntimeException(Throwable cause) {
super(cause);
}
public MyRuntimeException(Throwable cause, String msg) {
super(msg, cause);
}
}

View File

@@ -0,0 +1,18 @@
package io.wdd.server.mapper;
import io.wdd.server.beans.po.AppInfoPO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author wdd
* @description 针对表【app_info】的数据库操作Mapper
* @createDate 2022-11-20 16:49:20
* @Entity io.wdd.server.beans.po.AppInfoPO
*/
public interface AppInfoMapper extends BaseMapper<AppInfoPO> {
}

View File

@@ -0,0 +1,21 @@
package io.wdd.server.mapper;
import io.wdd.server.beans.po.ServerInfoPO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
/**
* @author wdd
* @description 针对表【server_info】的数据库操作Mapper
* @createDate 2022-11-20 16:16:52
* @Entity io.wdd.server.beans.po.ServerInfoPO
*/
public interface ServerInfoMapper extends BaseMapper<ServerInfoPO> {
List<ServerInfoPO> getAll();
}

View File

@@ -0,0 +1,13 @@
package io.wdd.server.service;
import io.wdd.server.beans.po.AppInfoPO;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author wdd
* @description 针对表【app_info】的数据库操作Service
* @createDate 2022-11-20 16:49:20
*/
public interface AppInfoService extends IService<AppInfoPO> {
}

View File

@@ -0,0 +1,20 @@
package io.wdd.server.service;
import io.wdd.server.beans.po.ServerInfoPO;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author wdd
* @description 针对表【server_info】的数据库操作Service
* @createDate 2022-11-20 16:16:52
*/
public interface ServerInfoService extends IService<ServerInfoPO> {
/**
* @return all servers include delete servers
*/
List<ServerInfoPO> getAll();
}

View File

@@ -0,0 +1,22 @@
package io.wdd.server.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.wdd.server.beans.po.AppInfoPO;
import io.wdd.server.service.AppInfoService;
import io.wdd.server.mapper.AppInfoMapper;
import org.springframework.stereotype.Service;
/**
* @author wdd
* @description 针对表【app_info】的数据库操作Service实现
* @createDate 2022-11-20 16:49:20
*/
@Service
public class AppInfoServiceImpl extends ServiceImpl<AppInfoMapper, AppInfoPO>
implements AppInfoService{
}

View File

@@ -0,0 +1,29 @@
package io.wdd.server.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.wdd.server.beans.po.ServerInfoPO;
import io.wdd.server.service.ServerInfoService;
import io.wdd.server.mapper.ServerInfoMapper;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author wdd
* @description 针对表【server_info】的数据库操作Service实现
* @createDate 2022-11-20 16:16:52
*/
@Service
public class ServerInfoServiceImpl extends ServiceImpl<ServerInfoMapper, ServerInfoPO>
implements ServerInfoService{
@Override
public List<ServerInfoPO> getAll() {
return this.baseMapper.getAll();
}
}

View File

@@ -0,0 +1,59 @@
package io.wdd.server.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.stream.Collectors;
@Component
@Slf4j(topic = "Bean Type Convert")
public class EntityUtils<T, S> {
public static <T, S> T cvToTarget(S source, Class<T> clazz) {
T t = null;
try {
t = clazz.getDeclaredConstructor().newInstance();
BeanUtils.copyProperties(source, t);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
log.warn("bean type convert error {}", clazz);
}
return t;
}
public static <T, S> List<T> cvToTarget(List<S> source, Class<T> clazz) {
return source.stream().map(
s -> {
T t = null;
try {
t = clazz.getDeclaredConstructor().newInstance();
BeanUtils.copyProperties(s, t);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
log.warn("bean type convert error {}", clazz);
}
return t;
}
).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,6 @@
package io.wdd.server.utils;
public class MyBatisPlusGenerator {
}

View File

@@ -0,0 +1,55 @@
server:
port: 9999
spring:
rabbitmq:
host: 127.0.0.1
port: 35672
username: boge
password: boge14@Level5
redis:
host: 127.0.0.1
port: 36379
database: 0
password: boge14@Level5
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:33306/wdd_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
username: root
password: boge14@Level5
type: com.zaxxer.hikari.HikariDataSource
hikari:
minimum-idle: 3
# 空闲连接存活最大时间默认60000010分钟
idle-timeout: 180000
# 连接池最大连接数默认是10
maximum-pool-size: 5
# 此属性控制从池返回的连接的默认自动提交行为,默认值true
auto-commit: true
connection-test-query: SELECT 1
mybatis-plus:
type-aliases-package: io.wdd.server.beans.po
global-config:
db-column-underline: true
db-config:
# modify ethe id strategy
id-type: assign_id
# logic delete field globally
logicDeleteField: isDelete
logic-not-delete-value: 0
logic-delete-value: 1
configuration:
# 希望知道所有的sql是怎么执行的, 配置输出日志
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 数据库下划线--实体类也是下划线 需要为false
map-underscore-to-camel-case: true
# 一级缓存的 缓存级别默认为 session如果要关闭一级缓存可以设置为 statement
local-cache-scope: session
# 是否开启二级缓存
cache-enabled: false
# 默认地址为 classpath*:/mapper/**/*.xml
# mapper-locations: classpath*:/real-mappers/**/*.xml

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.wdd.server.mapper.AppInfoMapper">
<resultMap id="BaseResultMap" type="io.wdd.server.beans.po.AppInfoPO">
<id property="appId" column="app_id" jdbcType="BIGINT"/>
<result property="appName" column="app_name" jdbcType="VARCHAR"/>
<result property="appInfo" column="app_info" jdbcType="VARCHAR"/>
<result property="appVersion" column="app_version" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="commont" column="commont" jdbcType="VARCHAR"/>
<result property="isDelete" column="is_delete" jdbcType="TINYINT"/>
</resultMap>
<sql id="Base_Column_List">
app_id,app_name,app_info,
app_version,create_time,update_time,
commont,is_delete
</sql>
</mapper>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.wdd.server.mapper.ServerInfoMapper">
<resultMap id="BaseResultMap" type="io.wdd.server.beans.po.ServerInfoPO">
<id property="serverId" column="server_id" jdbcType="BIGINT"/>
<result property="serverName" column="server_name" jdbcType="VARCHAR"/>
<result property="serverIpPbV4" column="server_ip_pb_v4" jdbcType="VARCHAR"/>
<result property="serverIpInV4" column="server_ip_in_v4" jdbcType="VARCHAR"/>
<result property="serverIpPbV6" column="server_ip_pb_v6" jdbcType="VARCHAR"/>
<result property="serverIpInV6" column="server_ip_in_v6" jdbcType="VARCHAR"/>
<result property="registerTime" column="register_time" jdbcType="TIMESTAMP"/>
<result property="expireTime" column="expire_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="location" column="location" jdbcType="VARCHAR"/>
<result property="provider" column="provider" jdbcType="VARCHAR"/>
<result property="managePort" column="manage_port" jdbcType="VARCHAR"/>
<result property="cpuCore" column="cpu_core" jdbcType="INTEGER"/>
<result property="cpuBrand" column="cpu_brand" jdbcType="VARCHAR"/>
<result property="osInfo" column="os_info" jdbcType="VARCHAR"/>
<result property="osKernelInfo" column="os_kernel_info" jdbcType="VARCHAR"/>
<result property="comment" column="comment" jdbcType="VARCHAR"/>
<result property="isDelete" column="is_delete" jdbcType="TINYINT"/>
<result property="version" column="version" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
server_id,server_name,server_ip_pb_v4,
server_ip_in_v4,server_ip_pb_v6,server_ip_in_v6,
register_time,expire_time,update_time,
location,provider,manage_port,
cpu_core,cpu_brand,os_info,
os_kernel_info,comment,is_delete,
version
</sql>
<select id="getAll" resultType="io.wdd.server.beans.po.ServerInfoPO">
select
<include refid="Base_Column_List"></include>
from
server_info
</select>
</mapper>

View File

@@ -0,0 +1,13 @@
package io.wdd.server;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ServerApplicationTests {
@Test
void contextLoads() {
}
}