feat 获取车辆cpu使用率 以及总数量
parent
79bac537c7
commit
7bff86090a
6
pom.xml
6
pom.xml
|
@ -156,6 +156,12 @@
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.12.0</version>
|
<version>3.12.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.13</version> <!-- 使用你需要的版本 -->
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.car;
|
package com.car;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@MapperScan
|
||||||
public class ZnCarApplication {
|
public class ZnCarApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -9,8 +9,17 @@ import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||||
import com.aliyun.tea.TeaException;
|
import com.aliyun.tea.TeaException;
|
||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
import com.car.demos.ConnectWeight;
|
import com.car.demos.ConnectWeight;
|
||||||
|
import com.car.demos.loadenter.Auth;
|
||||||
|
import com.car.demos.loadenter.Content;
|
||||||
|
import com.car.demos.loadenter.LoadEnterNumber;
|
||||||
import com.car.service.impl.ConnectServiceImpl;
|
import com.car.service.impl.ConnectServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
@ -18,7 +27,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -44,11 +53,14 @@ public class InitConnectWeight implements ApplicationRunner {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
|
connectService.loadCenterDel();
|
||||||
|
|
||||||
ArrayList<ConnectWeight> connectWeightList = new ArrayList<>();
|
ArrayList<ConnectWeight> connectWeightList = new ArrayList<>();
|
||||||
|
|
||||||
ArrayList<String> ipList = new ArrayList<>();
|
ArrayList<String> ipList = new ArrayList<>();
|
||||||
|
|
||||||
|
LoadEnterNumber loadEnterNumber = new LoadEnterNumber();
|
||||||
|
|
||||||
Client client = null;
|
Client client = null;
|
||||||
//获取阿里云客户端
|
//获取阿里云客户端
|
||||||
try {
|
try {
|
||||||
|
@ -94,15 +106,22 @@ public class InitConnectWeight implements ApplicationRunner {
|
||||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||||
}
|
}
|
||||||
//网关收集节点
|
//网关收集节点
|
||||||
int gatewayNum = 0;
|
int gatewayNum = ipList.size();
|
||||||
//数据解析结点数量
|
//数据解析结点数量
|
||||||
int dataNum=0;
|
int dataNum=0;
|
||||||
//整体负载率
|
//整体负载率
|
||||||
String overallLoad="";
|
String overallLoad="";
|
||||||
|
//总车辆
|
||||||
|
int connectEventSize =0;
|
||||||
|
|
||||||
|
//内存使用率
|
||||||
|
String memoryUseRate = null;
|
||||||
|
//cpu使用率
|
||||||
|
String cpuUsage = null;
|
||||||
|
|
||||||
//遍历所有ip,获取每一个服务的连接数
|
//遍历所有ip,获取每一个服务的连接数
|
||||||
for (String ip : ipList) {
|
for (String ip : ipList) {
|
||||||
//网关收集节点
|
//网关收集节点
|
||||||
gatewayNum = ip.length();
|
|
||||||
log.info("gatewayNum:{}", gatewayNum);
|
log.info("gatewayNum:{}", gatewayNum);
|
||||||
//fluxMq连接
|
//fluxMq连接
|
||||||
String url = "http://" + ip + ":8080/public/login";
|
String url = "http://" + ip + ":8080/public/login";
|
||||||
|
@ -144,52 +163,84 @@ public class InitConnectWeight implements ApplicationRunner {
|
||||||
log.info("响应是:{}", responseInfo.getBody());
|
log.info("响应是:{}", responseInfo.getBody());
|
||||||
|
|
||||||
JSONArray jsonArray = JSON.parseArray(responseInfo.getBody());
|
JSONArray jsonArray = JSON.parseArray(responseInfo.getBody());
|
||||||
|
|
||||||
if (jsonArray.size() > 0) {
|
if (jsonArray.size() > 0) {
|
||||||
JSONObject jsonObject = jsonArray.getJSONObject(0);
|
JSONObject jsonObject = jsonArray.getJSONObject(0);
|
||||||
// Integer connectSize = jsonObject.getJSONObject("mqttInfo").getJSONObject("runtimes").getInteger("mqtt.connect");
|
// Integer connectSize = jsonObject.getJSONObject("mqttInfo").getJSONObject("runtimes").getInteger("mqtt.connect");
|
||||||
Integer connectSize = Integer.valueOf(jsonObject.getJSONObject("mqttInfo").getString("connectSize"));
|
|
||||||
|
//获取内存使用率
|
||||||
|
JSONObject flowInfo = jsonObject.getJSONObject("jvmInfo");
|
||||||
|
//内存大小
|
||||||
|
String heapMaxSize = flowInfo.getString("heap-max");
|
||||||
|
//堆内存使用率
|
||||||
|
String heapUsedSize = flowInfo.getString("heap-used");
|
||||||
|
|
||||||
|
// 定义单位到字节的转换系数
|
||||||
|
final double GB_TO_BYTES = 1024 * 1024 * 1024; // 1 GB = 1024^3 bytes
|
||||||
|
final double MB_TO_BYTES = 1024 * 1024; // 1 MB = 1024^2 bytes
|
||||||
|
|
||||||
|
// 解析字符串并转换为字节
|
||||||
|
double maxHeapBytes = Double.parseDouble(heapMaxSize.substring(0, heapMaxSize.length() - 3)) * GB_TO_BYTES; // 去掉"GB"并转换
|
||||||
|
double usedHeapBytes = Double.parseDouble(heapUsedSize.substring(0, heapUsedSize.length() - 3)) * MB_TO_BYTES; // 去掉"MB"并转换
|
||||||
|
|
||||||
|
// 计算使用率(百分比)
|
||||||
|
double usagePercentage = (usedHeapBytes / maxHeapBytes) * 100;
|
||||||
|
//内存率
|
||||||
|
memoryUseRate=usagePercentage+"%";
|
||||||
|
|
||||||
|
//cpu
|
||||||
|
JSONObject cpuInfo = jsonObject.getJSONObject("cpuInfo");
|
||||||
|
String string = cpuInfo.getString("user");
|
||||||
|
cpuUsage =string;
|
||||||
|
|
||||||
|
|
||||||
|
//获取mqtt
|
||||||
|
JSONObject mqttInfo = jsonObject.getJSONObject("mqttInfo");
|
||||||
|
//连接数
|
||||||
|
Integer connectSize = Integer.valueOf(mqttInfo.getString("connectSize"));
|
||||||
|
//小车总连接数
|
||||||
|
connectEventSize = Integer.valueOf(mqttInfo.getString("connectEventSize"));
|
||||||
|
|
||||||
connectWeightList.add(new ConnectWeight(ip,100-connectSize));
|
connectWeightList.add(new ConnectWeight(ip,100-connectSize));
|
||||||
|
//权重值
|
||||||
|
Integer weightValue = 100 - connectSize;
|
||||||
|
|
||||||
log.info("链接数量:{}", connectSize);
|
log.info("链接数量:{}", connectSize);
|
||||||
} else {
|
} else {
|
||||||
log.info("得到的相应数据为null");
|
log.info("得到的相应数据为null");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
// //获取车辆列表
|
||||||
// Integer sum =0;
|
// String postList = "http://"+ip+":8080/mqtt/connection";
|
||||||
// for (ConnectWeight connectWeight : connectWeightList) {
|
|
||||||
// sum = sum + connectWeight.getWeightValue();
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
// int max = 0;
|
// HttpClient closeableHttpClient = HttpClients.createDefault();
|
||||||
// for (ConnectWeight connectWeight : connectWeightList) {
|
// HttpPost httpPost = new HttpPost(postList);
|
||||||
// log.info("权重值:{}",connectWeight.getWeightValue());
|
// JSONObject object = JSONObject.parseObject(result);
|
||||||
// Integer result = BigDecimal.valueOf(connectWeight.getWeightValue() * 100).divide(BigDecimal.valueOf(sum), 0, RoundingMode.DOWN).intValue();
|
// httpPost.addHeader("accessToken",object.getString("accessToken") ); // 设置请求头
|
||||||
// if (result > max){
|
|
||||||
// max = result;
|
// try {
|
||||||
// }
|
// HttpResponse response = closeableHttpClient.execute(httpPost);
|
||||||
// connectWeight.setWeightValue(result);
|
// Object o = restTemplate.postForObject(postList, response, Object.class);
|
||||||
// log.info("100次轮询次数:{}",result);
|
// log.info("响应是:{}", o);
|
||||||
// }
|
// JSONObject jsonObject = JSONObject.parseObject(response.toString());
|
||||||
//
|
// JSONArray content = jsonObject.getJSONArray("content");
|
||||||
// ArrayList<String> weightIpList = new ArrayList<>();
|
// for (int i = 0; i < content.size(); i++) {
|
||||||
//
|
// // 获取每个元素(JSONObject)
|
||||||
// //轮询出现次数
|
// JSONObject contentItem = content.getJSONObject(i);
|
||||||
// for (int i = 0; i <= max; i++) {
|
// // 获取state字段的值
|
||||||
// for (ConnectWeight connectWeight : connectWeightList) {
|
// int state = contentItem.getIntValue("state");
|
||||||
// if (connectWeight.getWeightValue() > i){
|
// if (state == 1) {
|
||||||
// weightIpList.add(connectWeight.getCarServerIp());
|
// // 如果state为1,则将当前对象添加到列表中
|
||||||
// }else if (connectWeight.getWeightValue() == max ){
|
// filteredContent.add(contentItem);
|
||||||
// weightIpList.add(connectWeight.getCarServerIp());
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// log.info("车辆列表:{}", response);
|
||||||
//
|
// } catch (IOException e) {
|
||||||
// //存入redis
|
// throw new RuntimeException(e);
|
||||||
// redisTemplate.delete("ips");
|
|
||||||
// for (String ip : weightIpList) {
|
|
||||||
// redisTemplate.opsForList().rightPush("ips",ip);
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
log.info("车辆在线是",connectEventSize);
|
||||||
|
|
||||||
//每个连接数的权重总和
|
//每个连接数的权重总和
|
||||||
Integer sum =0;
|
Integer sum =0;
|
||||||
|
@ -199,15 +250,27 @@ public class InitConnectWeight implements ApplicationRunner {
|
||||||
System.out.println("sum"+sum);
|
System.out.println("sum"+sum);
|
||||||
|
|
||||||
int max=0;
|
int max=0;
|
||||||
|
//权重总和
|
||||||
|
double sumOfWeights=0;
|
||||||
for (ConnectWeight connectWeight : connectWeightList) {
|
for (ConnectWeight connectWeight : connectWeightList) {
|
||||||
Integer result = BigDecimal.valueOf(connectWeight.getWeightValue() * 100).divide(BigDecimal.valueOf(sum), 0, RoundingMode.DOWN).intValue();
|
BigDecimal divide = BigDecimal.valueOf(connectWeight.getWeightValue() * 100).divide(BigDecimal.valueOf(sum), 0, RoundingMode.DOWN);
|
||||||
|
int result = divide.intValue();
|
||||||
if (result > max){
|
if (result > max){
|
||||||
max = result;
|
max = result;
|
||||||
}
|
}
|
||||||
connectWeight.setWeightValue(result);
|
connectWeight.setWeightValue(result);
|
||||||
System.out.println("100次轮询次数:{}"+result);
|
System.out.println("100次轮询次数:{}"+result);
|
||||||
|
sumOfWeights+=connectWeight.getWeightValue();
|
||||||
}
|
}
|
||||||
|
overallLoad =sumOfWeights/ipList.size()+"%";
|
||||||
|
log.info("总负载",overallLoad);
|
||||||
|
LoadEnterNumber build = LoadEnterNumber.builder()
|
||||||
|
.carSum(connectEventSize)
|
||||||
|
.gatewayNum(ipList.size())
|
||||||
|
.dataNum(dataNum)
|
||||||
|
.overallLoad(overallLoad)
|
||||||
|
.build();
|
||||||
|
connectService.LoadCenterAdd(build);
|
||||||
ArrayList<String> weightIpList = new ArrayList<>();
|
ArrayList<String> weightIpList = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i <= max; i++) {
|
for (int i = 0; i <= max; i++) {
|
||||||
|
@ -223,13 +286,25 @@ public class InitConnectWeight implements ApplicationRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 存入redis
|
// 存入redis
|
||||||
redisTemplate.delete("ips");
|
redisTemplate.delete("ips");
|
||||||
for (String ip : weightIpList) {
|
for (String ip : weightIpList) {
|
||||||
redisTemplate.opsForList().rightPush("ips",ip);
|
redisTemplate.opsForList().rightPush("ips",ip);
|
||||||
}
|
}
|
||||||
|
// List<Content> contents = new ArrayList<>();
|
||||||
|
// for (JSONObject jsonObject : filteredContent) {
|
||||||
|
// Content build = Content.builder()
|
||||||
|
// .cleanSession(jsonObject.getInteger("cleanSession"))
|
||||||
|
// .id(jsonObject.getInteger("id"))
|
||||||
|
// .clientPort(jsonObject.getInteger("clientPort"))
|
||||||
|
// .protocolType(jsonObject.getString("protocolType"))
|
||||||
|
// .version(jsonObject.getString("version"))
|
||||||
|
// .state(jsonObject.getInteger("state"))
|
||||||
|
// .connectTime(jsonObject.getDate("connectTime"))
|
||||||
|
// .auth(jsonObject.getJSONArray("auth").toJavaList(Auth.class))
|
||||||
|
// .build();
|
||||||
|
// contents.add(build);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.car.controller;
|
||||||
|
|
||||||
import com.car.demos.MqttServerModel;
|
import com.car.demos.MqttServerModel;
|
||||||
import com.car.demos.Result;
|
import com.car.demos.Result;
|
||||||
|
import com.car.demos.loadenter.LoadEnterNumber;
|
||||||
import com.car.demos.req.VehicleConnectionReq;
|
import com.car.demos.req.VehicleConnectionReq;
|
||||||
import com.car.service.ConnectService;
|
import com.car.service.ConnectService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -26,4 +27,24 @@ public class ConnectController {
|
||||||
public Result<MqttServerModel>getConnect(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
public Result<MqttServerModel>getConnect(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
||||||
return connectService.getConnect();
|
return connectService.getConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加负载中心总条数
|
||||||
|
* @param loadEnterNumber
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/LoadCenterAdd")
|
||||||
|
public Result LoadCenterAdd(@RequestBody LoadEnterNumber loadEnterNumber){
|
||||||
|
connectService.LoadCenterAdd(loadEnterNumber);
|
||||||
|
return Result.success("添加成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除负载中心总条数
|
||||||
|
*/
|
||||||
|
@PostMapping("/loadCenterDel")
|
||||||
|
public Result loadCenterDel(){
|
||||||
|
connectService.loadCenterDel();
|
||||||
|
return Result.success("删除成功");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.car.demos.loadenter;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户信息 Auth
|
||||||
|
*
|
||||||
|
* @author Yangle
|
||||||
|
* Date 2024/6/2 11:45
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
public class Auth {
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* 用户密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.car.demos.loadenter;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆详细信息 Content
|
||||||
|
*
|
||||||
|
* @author Yangle
|
||||||
|
* Date 2024/6/2 11:32
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
public class Content {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端id
|
||||||
|
*/
|
||||||
|
private Integer clientId;
|
||||||
|
/*
|
||||||
|
客户端地址
|
||||||
|
*/
|
||||||
|
private String clientIp;
|
||||||
|
|
||||||
|
private Integer clientPort;
|
||||||
|
private String protocolType;
|
||||||
|
private String nodeIp;
|
||||||
|
private String version;
|
||||||
|
private Integer keepalive;
|
||||||
|
private Integer cleanSession;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private Integer state;
|
||||||
|
/**
|
||||||
|
* 连接时间
|
||||||
|
*/
|
||||||
|
private Date connectTime;
|
||||||
|
|
||||||
|
private List<Auth> auth;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.car.demos.loadenter;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 负载中心数据总数量展示 loadEnterNumber
|
||||||
|
*
|
||||||
|
* @author Yangle
|
||||||
|
* Date 2024/6/2 11:29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
public class LoadEnterNumber {
|
||||||
|
|
||||||
|
/*
|
||||||
|
主键
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
/*
|
||||||
|
网关收集节点数量
|
||||||
|
*/
|
||||||
|
private Integer gatewayNum;
|
||||||
|
/*
|
||||||
|
数据解析节点数量
|
||||||
|
*/
|
||||||
|
private Integer dataNum;
|
||||||
|
/*
|
||||||
|
整体负载率
|
||||||
|
*/
|
||||||
|
private String overallLoad;
|
||||||
|
/*
|
||||||
|
车辆在线数量
|
||||||
|
*/
|
||||||
|
private Integer carSum;
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 车辆对象
|
||||||
|
// */
|
||||||
|
// private List<Content> contents;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.car.mapper;
|
||||||
|
|
||||||
|
import com.car.demos.loadenter.LoadEnterNumber;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConnerMapper
|
||||||
|
*
|
||||||
|
* @author Yangle
|
||||||
|
* Date 2024/6/2 11:52
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ConnerMapper {
|
||||||
|
void lodaCenterAdd(LoadEnterNumber loadEnterNumber);
|
||||||
|
|
||||||
|
void loadCenterDel();
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package com.car.service;
|
||||||
|
|
||||||
import com.car.demos.MqttServerModel;
|
import com.car.demos.MqttServerModel;
|
||||||
import com.car.demos.Result;
|
import com.car.demos.Result;
|
||||||
|
import com.car.demos.loadenter.LoadEnterNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆连接业务层 ConnectImpl
|
* 车辆连接业务层 ConnectImpl
|
||||||
|
@ -12,4 +13,8 @@ import com.car.demos.Result;
|
||||||
public interface ConnectService {
|
public interface ConnectService {
|
||||||
Result<MqttServerModel> getConnect();
|
Result<MqttServerModel> getConnect();
|
||||||
|
|
||||||
|
void LoadCenterAdd(LoadEnterNumber loadEnterNumber);
|
||||||
|
|
||||||
|
void loadCenterDel();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.aliyun.teaopenapi.models.Config;
|
||||||
import com.car.demos.MqttServerModel;
|
import com.car.demos.MqttServerModel;
|
||||||
import com.car.demos.Result;
|
import com.car.demos.Result;
|
||||||
|
|
||||||
|
import com.car.demos.loadenter.LoadEnterNumber;
|
||||||
|
import com.car.mapper.ConnerMapper;
|
||||||
import com.car.service.ConnectService;
|
import com.car.service.ConnectService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
@ -18,8 +20,8 @@ import org.springframework.stereotype.Service;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ConnectServiceImpl implements ConnectService {
|
public class ConnectServiceImpl implements ConnectService {
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private ConnerMapper connerMapper;
|
private ConnerMapper connerMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate redisTemplate;
|
private StringRedisTemplate redisTemplate;
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,6 +44,23 @@ public class ConnectServiceImpl implements ConnectService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加负载中心
|
||||||
|
* @param loadEnterNumber
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void LoadCenterAdd(LoadEnterNumber loadEnterNumber) {
|
||||||
|
connerMapper.lodaCenterAdd(loadEnterNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除负载中心
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void loadCenterDel() {
|
||||||
|
connerMapper.loadCenterDel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Client createClient() throws Exception {
|
public static Client createClient() throws Exception {
|
||||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||||
|
|
|
@ -14,7 +14,7 @@ spring:
|
||||||
matching-strategy: ant_path_matcher
|
matching-strategy: ant_path_matcher
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://115.159.211.196:3306/data_basete?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
|
url: jdbc:mysql://115.159.211.196:3306/zncar?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
|
||||||
username: root
|
username: root
|
||||||
password: yl@123
|
password: yl@123
|
||||||
druid:
|
druid:
|
||||||
|
@ -48,13 +48,13 @@ spring:
|
||||||
port: 6379
|
port: 6379
|
||||||
password: yl030509
|
password: yl030509
|
||||||
|
|
||||||
## mybatis
|
# mybatis
|
||||||
#mybatis:
|
mybatis:
|
||||||
# configuration:
|
configuration:
|
||||||
# map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
# mapper-locations: classpath*:mapper/*Mapper.xml
|
mapper-locations: classpath*:mapper/*Mapper.xml
|
||||||
# global-config:
|
global-config:
|
||||||
# db-config:
|
db-config:
|
||||||
# id-type: auto
|
id-type: auto
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?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="com.car.mapper.ConnerMapper">
|
||||||
|
|
||||||
|
<insert id="lodaCenterAdd">
|
||||||
|
INSERT INTO `zncar`.`load_enter_number`
|
||||||
|
( `gateway_num`, `data_num`, `overall_load`, `car_sum`)
|
||||||
|
VALUES ( #{gatewayNum}, #{dataNum}, #{overallLoad}, #{carSum});
|
||||||
|
</insert>
|
||||||
|
<delete id="loadCenterDel">
|
||||||
|
DELETE FROM `zncar`.`load_enter_number`
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue