feat():重构springboot项目

master
Saisai Liu 2024-05-29 08:46:28 +08:00
commit 71f54f1488
24 changed files with 860 additions and 0 deletions

38
.gitignore vendored 100644
View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore vendored 100644
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

14
.idea/misc.xml 100644
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

77
pom.xml 100644
View File

@ -0,0 +1,77 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mobai</groupId>
<artifactId>car_load</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.15</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- rabbitMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.46</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- 阿里api-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>ecs20140526</artifactId>
<version>5.1.8</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,7 @@
package com.mobai;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

View File

@ -0,0 +1,13 @@
package com.mobai;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@Log4j2
@SpringBootApplication
public class TrainLoadApplication {
public static void main(String[] args) {
SpringApplication.run(TrainLoadApplication.class);
}
}

View File

@ -0,0 +1,28 @@
package com.mobai.controller;
import com.mobai.domain.Result;
import com.mobai.service.FluxGetInfoService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName FluxGetInfo
* @Description
* @Author SaiSai.Liu
* @Date 2024/5/28 22:00
*/
@RestController
@Log4j2
@RequestMapping("fluxmq")
public class FluxGetInfoController {
@Autowired
private FluxGetInfoService fluxGetInfoService;
@GetMapping("getInfo")
public Result getInfo(){
return fluxGetInfoService.getInfo();
}
}

View File

@ -0,0 +1,56 @@
// ApifoxModel.java
package com.mobai.domain;
@lombok.Data
public class ApifoxModel {
/**
* ID
*/
private String clusterId;
/**
* CPU使
*/
private CPUInfo cpuInfo;
/**
*
*/
private FlowInfo flowInfo;
/**
* HTTP
*/
private String httpUrl;
/**
* JVM使
*/
private JVMInfo jvmInfo;
/**
* MQTT
*/
private MqttInfo mqttInfo;
/**
* MQTTS
*/
private String mqttsUrl;
/**
* MQTT
*/
private String mqttUrl;
/**
*
*/
private String nodeName;
/**
*
*/
private String startJvmTime;
/**
*
*/
private String version;
/**
* websocket
*/
private String websocketUrl;
}

View File

@ -0,0 +1,25 @@
package com.mobai.domain;
@lombok.Data
public class CPUInfo {
/**
* CPU
*/
private long cpuNum;
/**
* 使
*/
private String cSys;
/**
*
*/
private String idle;
/**
* I/O
*/
private String iowait;
/**
* 使
*/
private String user;
}

View File

@ -0,0 +1,12 @@
package com.mobai.domain;
/**
* @ClassName Constants
* @Description
* @Author SaiSai.Liu
* @Date 2024/5/28 22:05
*/
public class Constants {
public static final int SUCCESS = 200;
public static final int FAIL = 500;
}

View File

@ -0,0 +1,28 @@
package com.mobai.domain;
/**
*
*/
@lombok.Data
public class FlowInfo {
/**
*
*/
private String lastReadThroughput;
/**
*
*/
private String lastWriteThroughput;
/**
*
*/
private String readBytesHistory;
/**
*
*/
private String realWriteBytes;
/**
*
*/
private String writeBytesHistory;
}

View File

@ -0,0 +1,56 @@
package com.mobai.domain;
/**
* JVM使
*/
@lombok.Data
public class JVMInfo {
/**
* ()
*/
private String fileDescriptors;
/**
*
*/
private String heapCommit;
/**
*
*/
private String heapInit;
/**
*
*/
private String heapMax;
/**
* 使
*/
private String heapUsed;
/**
* JAVA
*/
private String jdkHome;
/**
* JDK
*/
private String jdkVersion;
/**
*
*/
private String noHeapCommit;
/**
*
*/
private String noHeapInit;
/**
*
*/
private String noHeapMax;
/**
* 使
*/
private String noHeapUsed;
/**
* 线
*/
private long threadCount;
}

View File

@ -0,0 +1,52 @@
package com.mobai.domain;
/**
* MQTT
*/
@lombok.Data
public class MqttInfo {
/**
*
*/
private long closeEventSize;
/**
*
*/
private long connectEventSize;
/**
*
*/
private long connectSize;
/**
*
*/
private long disconnectEventSize;
/**
*
*/
private long publishEventSize;
/**
*
*/
private long publishRetryEventSize;
/**
*
*/
private long retainSize;
/**
*
*/
private long subscribeEventSize;
/**
*
*/
private long subscribeSize;
/**
*
*/
private long topicSize;
/**
*
*/
private long unSubscribeEventSize;
}

View File

@ -0,0 +1,89 @@
package com.mobai.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
*
*
* @author muyu
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
/**
*
*/
public static final int SUCCESS = Constants.SUCCESS;
/**
*
*/
public static final int FAIL = Constants.FAIL;
private static final long serialVersionUID = 1L;
private int code;
private String msg;
private T data;
public static <T> Result<T> success () {
return restResult(null, SUCCESS, null);
}
public static <T> Result<T> success (T data) {
return restResult(data, SUCCESS, null);
}
public static <T> Result<T> success (T data, String msg) {
return restResult(data, SUCCESS, msg);
}
public static <T> Result<T> error () {
return restResult(null, FAIL, null);
}
public static <T> Result<T> error (String msg) {
return restResult(null, FAIL, msg);
}
public static <T> Result<T> error (T data) {
return restResult(data, FAIL, null);
}
public static <T> Result<T> error (T data, String msg) {
return restResult(data, FAIL, msg);
}
public static <T> Result<T> error (int code, String msg) {
return restResult(null, code, msg);
}
public static <T> Result<T> warn (int code, String msg) {
return restResult(null, code, msg);
}
private static <T> Result<T> restResult (T data, int code, String msg) {
return Result.<T>builder()
.code(code)
.data(data)
.msg(msg)
.build();
}
public static <T> Boolean isError (Result<T> ret) {
return !isSuccess(ret);
}
public static <T> Boolean isSuccess (Result<T> ret) {
return Result.SUCCESS == ret.getCode();
}
}

View File

@ -0,0 +1,34 @@
package com.mobai.mq.fluxmq;
import okhttp3.*;
import java.io.IOException;
/**
* @ClassName FluxMqInit
* @Description
* @Author SaiSai.Liu
* @Date 2024/5/27 9:57
*/
public class FluxMqInit {
public Response loginFluxMq(){
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"username\": \"fluxmq\",\r\n \"password\": \"fluxmq\"\r\n}");
Request request = new Request.Builder()
.url("http://fluxmq.muyu.icu/public/login")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
throw new RuntimeException(e);
}
return response;
}
}

View File

@ -0,0 +1,35 @@
package com.mobai.mq.rabbitmq;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* @ClassName Custom
* @Description
* @Author SaiSai.Liu
* @Date 2024/5/26 15:25
*/
@Component
public class Custom {
@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "send_sms_queue"),
exchange = @Exchange(value = "null",type = ExchangeTypes.DIRECT)))
public void mqCustom(Object data, Message message, Channel channel){
System.out.println(data.toString());
try {
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,55 @@
// This file is auto-generated, don't edit it. Thanks.
package com.mobai.openApi;
import com.aliyun.tea.TeaException;
public class CreateInstance {
/**
* 使AK&SKClient
* @return Client
* @throws Exception
*/
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378657.html。
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId("LTAI5tKaz3hHJ8pkgF7iem8b")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("CApa5sl414bKC8GwD8uBtINuT26Ocj");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs.cn-zhangjiakou.aliyuncs.com";
return new com.aliyun.ecs20140526.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.ecs20140526.Client client = CreateInstance.createClient();
com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest()
.setRegionId("cn-zhangjiakou")
.setLaunchTemplateName("basic_model")
.setLaunchTemplateId("lt-8vb71bkyjwcqmcd98ah4");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// 复制代码运行请自行打印 API 的返回值
client.runInstancesWithOptions(runInstancesRequest, runtime);
} catch (TeaException error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
// System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
System.out.println("实例创建成功");
}
}

View File

@ -0,0 +1,82 @@
// This file is auto-generated, don't edit it. Thanks.
package com.mobai.openApi;
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
import com.aliyun.tea.TeaException;
import lombok.extern.log4j.Log4j2;
import java.util.ArrayList;
import java.util.List;
@Log4j2
public class SelectInstences {
/**
* 使AK&SKClient
*
* @return Client
* @throws Exception
*/
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378657.html。
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId("LTAI5t7vsLXtqTJKve7JipnX")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("AIyMaSTKQtsB1V5sVqlNAGbQzxgXnS");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs.cn-zhangjiakou.aliyuncs.com";
return new com.aliyun.ecs20140526.Client(config);
}
public static void main(String[] args_) throws Exception {
List<String> ips = new ArrayList<>();
List<String> args = java.util.Arrays.asList(args_);
com.aliyun.ecs20140526.Client client = SelectInstences.createClient();
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
// .setImageId("m-8vb8qnidv34yj3nbirhc")
.setRegionId("cn-zhangjiakou");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// 复制代码运行请自行打印 API 的返回值
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = describeInstancesResponse.getBody().getInstances();
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instance =
instances.getInstance();
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance inst : instance) {
List<String> ipAddress = inst
.getPublicIpAddress()
.getIpAddress();
if (ipAddress.isEmpty()){
continue;
}else {
ipAddress.forEach(ip -> ips.add(ip));
}
}
log.info("当前实例ip为{}", ips);
} catch (TeaException error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
if (error.getData() == null) {
System.out.println("error.getData()为空");
} else {
System.out.println(error.getData().get("Recommend"));
}
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}

View File

@ -0,0 +1,15 @@
package com.mobai.service;
import com.mobai.domain.Result;
/**
* @ClassName FluxGetInfoService
* @Description
* @Author SaiSai.Liu
* @Date 2024/5/28 22:01
*/
public interface FluxGetInfoService {
Result getInfo();
}

View File

@ -0,0 +1,63 @@
package com.mobai.service;
import com.mobai.domain.Result;
import okhttp3.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
/**
* @ClassName FluxGetInfoServiceImpl
* @Description
* @Author SaiSai.Liu
* @Date 2024/5/28 22:01
*/
@Service
public class FluxGetInfoServiceImpl implements FluxGetInfoService {
@Override
public Result getInfo() {
String url = "http://39.98.50.223:8080/public/";
//响应体
Response response = null;
//登录
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"username\": \"fluxmq\",\r\n \"password\": \"fluxmq\"\r\n}");
RestTemplate restTemplate = new RestTemplate();
Request request = null;
request = new Request.Builder()
.url(url+"login")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
.addHeader("Content-Type", "application/json")
.build();
try {
response = client.newCall(request).execute();
System.out.println(response);
} catch (IOException e) {
throw new RuntimeException(e);
}
//获取信息
// OkHttpClient client = new OkHttpClient().newBuilder()
// .build();
// MediaType mediaType = MediaType.parse("text/plain");
// RequestBody body = RequestBody.create(mediaType, "");
request = new Request.Builder()
.url(url + "cluster")
.method("GET", null)
.addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
.addHeader("Accesstoken", response.header("accesstoken"))
.build();
try {
response = client.newCall(request).execute();
System.out.println(response);
} catch (IOException e) {
throw new RuntimeException(e);
}
return Result.success(response);
}
}

View File

@ -0,0 +1,30 @@
import okhttp3.*;
import java.io.IOException;
/**
* @ClassName LoginTest
* @Description
* @Author SaiSai.Liu
* @Date 2024/5/28 15:37
*/
public class LoginTest {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"username\": \"fluxmq\",\r\n \"password\": \"fluxmq\"\r\n}");
Request request = new Request.Builder()
.url("http://fluxmq.muyu.icu/public/login")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
.addHeader("Content-Type", "application/json")
.build();
try {
Response response = client.newCall(request).execute();
System.out.println(response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,31 @@
import okhttp3.*;
import java.io.IOException;
/**
* @ClassName TestGet
* @Description
* @Author SaiSai.Liu
* @Date 2024/5/28 15:34
*/
public class TestGet {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("http://39.98.50.223:8080/public/cluster")
.method("GET", null)
.addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
.addHeader("Accesstoken", "")
.build();
try {
Response response = client.newCall(request).execute();
System.out.println(response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}