Compare commits
12 Commits
f7143fede7
...
7d0d0418c6
Author | SHA1 | Date |
---|---|---|
|
7d0d0418c6 | |
|
7e0594185b | |
|
82bbab11db | |
|
b2a2a2bcb7 | |
|
4a005b3df0 | |
|
2e7169d5ed | |
|
3e73a8598a | |
|
26e1591f43 | |
|
e990dd304f | |
|
046b924c96 | |
|
daf43b843b | |
|
8fa84a4562 |
|
@ -2,7 +2,6 @@ package com.muyu.auth.controller;
|
|||
|
||||
import com.muyu.auth.form.LoginBody;
|
||||
import com.muyu.auth.form.RegisterBody;
|
||||
import com.muyu.auth.remote.RunCarConditionRemote;
|
||||
import com.muyu.auth.service.SysLoginService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.JwtUtils;
|
||||
|
@ -35,16 +34,12 @@ public class TokenController {
|
|||
@Autowired
|
||||
private SysLoginService sysLoginService;
|
||||
|
||||
@Resource
|
||||
private RunCarConditionRemote runCarCondition;
|
||||
|
||||
@PostMapping("login")
|
||||
public Result<?> login (@RequestBody LoginBody form) {
|
||||
// 用户登录
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword(),form.getFirmName());
|
||||
// 获取登录token
|
||||
Map<String, Object> token = tokenService.createToken(userInfo);
|
||||
runCarCondition.runCarCondition();
|
||||
return Result.success(token);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package com.muyu.auth.remote;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.auth.remote
|
||||
* @Project:cloud-server-8
|
||||
* @name:RunCarConditionRemote
|
||||
* @Date:2024/10/8 22:21
|
||||
*/
|
||||
@FeignClient(name = "cloud-electronic")
|
||||
public interface RunCarConditionRemote {
|
||||
|
||||
@GetMapping("/text")
|
||||
public void runCarCondition();
|
||||
}
|
|
@ -255,4 +255,14 @@ public class RedisService {
|
|||
public Collection<String> keys (final String pattern) {
|
||||
return redisTemplate.keys(pattern);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取使用的对象的次数
|
||||
// * @param key Redis键
|
||||
// * @param hKey Hash键
|
||||
// */
|
||||
// public void getNumber (final String key, final String hKey){
|
||||
// Object o = redisTemplate.opsForHash().get(key, hKey);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
<module>cloud-common-rabbit</module>
|
||||
<module>cloud-common-saas</module>
|
||||
<module>cloud-common-wechat</module>
|
||||
<module>cloud-common-cache</module>
|
||||
<module>cloud-common-kafka</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
<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>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<description>
|
||||
cloud-modules-car-gateway车辆网关模块
|
||||
</description>
|
||||
<artifactId>cloud-modules-car-gateway</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cloud-modules-car-gateway</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
<version>5.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.car;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car
|
||||
* @Project:cloud-server-8
|
||||
* @name:CloudCarGatewayApplication
|
||||
* @Date:2024/9/29 上午10:50
|
||||
*/
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class CloudCarGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudCarGatewayApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.muyu.car;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
public class MqttPublishSample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String topic = "vehicle";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://120.55.62.0:1883";
|
||||
String clientId = "JavaSample";
|
||||
|
||||
try {
|
||||
// 第三个参数为空,默认持久化策略
|
||||
MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setCleanSession(true);
|
||||
System.out.println("Connecting to broker: "+broker);
|
||||
sampleClient.connect(connOpts);
|
||||
sampleClient.subscribe(topic,0);
|
||||
sampleClient.setCallback(new MqttCallback() {
|
||||
// 连接丢失
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
|
||||
}
|
||||
// 连接成功
|
||||
@Override
|
||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
System.out.println(new String(mqttMessage.getPayload()));
|
||||
}
|
||||
// 接收信息
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch(MqttException me) {
|
||||
System.out.println("reason "+me.getReasonCode());
|
||||
System.out.println("msg "+me.getMessage());
|
||||
System.out.println("loc "+me.getLocalizedMessage());
|
||||
System.out.println("cause "+me.getCause());
|
||||
System.out.println("excep "+me);
|
||||
me.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.muyu.car.domain.api.req;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆连接请求参数
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.api.req
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleConnectionReq
|
||||
* @Date:2024/10/2 下午4:12
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VehicleConnectionReq {
|
||||
|
||||
/**
|
||||
* {
|
||||
* "vehicleVin": "VIN1234567894",
|
||||
* "timestamp": "11111",
|
||||
* "username": "你好",
|
||||
* "nonce": "33"
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* vin
|
||||
*/
|
||||
@JSONField(name = "vehicleVin")
|
||||
private String vehicleVin;
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private String timestamp;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@JSONField(name = "username")
|
||||
private String username;
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.car.domain.example;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 实例基础信息
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:ExampleInformation
|
||||
* @Date:2024/9/29 下午10:01
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ExampleInformation {
|
||||
|
||||
/**
|
||||
* 实例ID
|
||||
*/
|
||||
private String InstanceId;
|
||||
/**
|
||||
* 实例IP
|
||||
*/
|
||||
private String IpAddress;
|
||||
/**
|
||||
* 实例状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.car.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.model
|
||||
* @Project:cloud-server-8
|
||||
* @name:MqttServerModel
|
||||
* @Date:2024/10/7 下午6:40
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MqttServerModel {
|
||||
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.muyu.car.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.model
|
||||
* @Project:cloud-server-8
|
||||
* @name:Vehicle
|
||||
* @Date:2024/10/6 上午10:33
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VehicleInformation {
|
||||
|
||||
/**
|
||||
* 车辆ID
|
||||
*/
|
||||
private String carInformationId ;
|
||||
/**
|
||||
* 车辆唯一VIN
|
||||
*/
|
||||
private String carInformationVIN ;
|
||||
/**
|
||||
* 车牌号
|
||||
*/
|
||||
private String carInformationLicensePlate ;
|
||||
/**
|
||||
* 车辆品牌
|
||||
*/
|
||||
private String carInformationBrand ;
|
||||
/**
|
||||
* 车辆颜色
|
||||
*/
|
||||
private String carInformationColor ;
|
||||
/**
|
||||
* 车辆驾驶员
|
||||
*/
|
||||
private String carInformationDriver ;
|
||||
/**
|
||||
* 车检到期日期
|
||||
*/
|
||||
private String carInformationExamineEnddata ;
|
||||
/**
|
||||
* 车辆电机厂商
|
||||
*/
|
||||
private String carInformationMotorManufacturer ;
|
||||
/**
|
||||
* 车辆电机型号
|
||||
*/
|
||||
private String carInformationMotorModel ;
|
||||
/**
|
||||
* 车辆电池厂商
|
||||
*/
|
||||
private String carInformationBatteryManufacturer ;
|
||||
/**
|
||||
* 车辆电池型号
|
||||
*/
|
||||
private String carInformationBatteryModel ;
|
||||
/**
|
||||
* 车辆电子围栏外键ID
|
||||
*/
|
||||
private String carInformationFence ;
|
||||
/**
|
||||
* 车辆类型外键ID
|
||||
*/
|
||||
private String carInformationType ;
|
||||
/**
|
||||
* 是否重点车辆 (0否默认 1是 )
|
||||
*/
|
||||
private String carInformationFocus ;
|
||||
/**
|
||||
* 车辆策略id
|
||||
*/
|
||||
private String carStrategyId ;
|
||||
/**
|
||||
* 启用状态(1.在线 2.离线 3.已断开 4.待连接 5.维修中)
|
||||
*/
|
||||
private String carInformationState ;
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.muyu.car.domain.model.properties;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.model.properties
|
||||
* @Project:cloud-server-8
|
||||
* @name:MqttProperties
|
||||
* @Date:2024/10/6 下午8:24
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MqttProperties {
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 节点ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 上报级别
|
||||
*/
|
||||
private int qos = 0;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.car.domain.model.properties;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.model.properties
|
||||
* @Project:cloud-server-8
|
||||
* @name:MqttServerModel
|
||||
* @Date:2024/10/6 下午8:25
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MqttServerModel {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MqttServerModel.class);
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
public String getBroker () {
|
||||
log.info("broker: {}", broker);
|
||||
return broker.contains("tcp://") ? broker : "tcp://" + broker + ":1883";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.car.gateway.controller;
|
||||
|
||||
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||
import com.muyu.car.domain.model.MqttServerModel;
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
import com.muyu.car.gateway.service.VehicleInformationService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 车辆获取信息
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.controller
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformationController
|
||||
* @Date:2024/10/6 下午2:39
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/verify")
|
||||
public class VehicleInformationController {
|
||||
|
||||
@Autowired
|
||||
private VehicleInformationService vehicleInformationService;
|
||||
|
||||
@PostMapping("/vehicleConnection")
|
||||
public Result<MqttServerModel> getVehicleData(
|
||||
@Validated @RequestBody VehicleConnectionReq vehicleConnectionReq
|
||||
) {
|
||||
|
||||
return Result.success(vehicleInformationService.getVehicleData(vehicleConnectionReq));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.car.gateway.controller;
|
||||
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
import com.muyu.car.gateway.service.VehicleInstanceService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 车辆实例控制层
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.controller
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformation
|
||||
* @Date:2024/10/4 上午9:40
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/vehicle")
|
||||
public class VehicleInstanceController {
|
||||
|
||||
@Autowired private VehicleInstanceService vehicleInstanceService;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.car.gateway.mq;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.mq
|
||||
* @Project:cloud-server-8
|
||||
* @name:CreateExchange
|
||||
* @Date:2024/10/7 下午8:53
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class CreateExchange implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private ConnectionFactory connectionFactory;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
log.info("=====>开始创建交换机");
|
||||
|
||||
try {
|
||||
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
||||
|
||||
// 创建Fanout类型的交换机
|
||||
FanoutExchange exchange = new FanoutExchange("ONLINE_EXCHANGE", true, false);
|
||||
|
||||
rabbitAdmin.declareExchange(exchange);
|
||||
|
||||
// 创建队列
|
||||
Queue queue = new Queue("GO_ONLINE", true, false, false);
|
||||
|
||||
rabbitAdmin.declareQueue(queue);
|
||||
|
||||
// Fanout交换机绑定
|
||||
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange));
|
||||
|
||||
log.info("=====>交换机创建成功");
|
||||
log.info("=====>队列创建成功并绑定到交换机");
|
||||
}catch (Exception e) {
|
||||
log.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.car.gateway.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||
import com.muyu.car.domain.model.MqttServerModel;
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.service
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformationService
|
||||
* @Date:2024/10/6 下午2:40
|
||||
*/
|
||||
public interface VehicleInformationService{
|
||||
MqttServerModel getVehicleData(VehicleConnectionReq vehicleConnectionReq);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.muyu.car.gateway.service;
|
||||
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.service
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInstanceService
|
||||
* @Date:2024/10/6 上午10:05
|
||||
*/
|
||||
public interface VehicleInstanceService {
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package com.muyu.car.gateway.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||
import com.muyu.car.domain.model.MqttServerModel;
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
import com.muyu.car.gateway.service.VehicleInformationService;
|
||||
import com.muyu.car.mapper.VehicleInformationMapper;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.service.impl
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformationServiceImpl
|
||||
* @Date:2024/10/6 下午2:41
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VehicleInformationServiceImpl implements VehicleInformationService{
|
||||
|
||||
@Autowired private VehicleInformationMapper vehicleInformationMapper;
|
||||
|
||||
@Autowired private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public MqttServerModel getVehicleData(VehicleConnectionReq vehicleConnectionReq) {
|
||||
log.info("车辆连接请求:[{}]",vehicleConnectionReq);
|
||||
vehicleConnectionReq.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()+vehicleConnectionReq.getNonce());
|
||||
|
||||
List<String> selectVehicle =vehicleInformationMapper.selectVehicleVin(vehicleConnectionReq.getVehicleVin());
|
||||
if(selectVehicle.isEmpty()) {
|
||||
vehicleInformationMapper.addVehicleConnection(vehicleConnectionReq);
|
||||
log.info("车辆预上线成功");
|
||||
}else {
|
||||
log.info("车辆无法重复预上线");
|
||||
}
|
||||
|
||||
// 获取名为 "ipList" 的列表
|
||||
List<String> ipList = redisService.getCacheList("ipList");
|
||||
if (ipList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// 获取当前使用的索引位置
|
||||
String indexStr = redisService.getCacheObject("currentIndex");
|
||||
int index = indexStr!= null? Integer.parseInt(indexStr) : 0;
|
||||
String selectedIp = ipList.get(index);
|
||||
// 获取该 IP 的使用次数
|
||||
String countStr = redisService.getCacheMapValue("ipCounts", selectedIp);
|
||||
log.info("IP:[{}]车辆连接数:[{}]",selectedIp,countStr);
|
||||
int count = countStr!= null? Integer.parseInt(countStr) : 0;
|
||||
if (count < 12) {
|
||||
// 使用次数加一
|
||||
count++;
|
||||
redisService.setCacheMapValue("ipCounts", selectedIp, String.valueOf(count));
|
||||
// 更新索引
|
||||
index = (index + 1) % ipList.size();
|
||||
redisService.setCacheObject("currentIndex", String.valueOf(index));
|
||||
return new MqttServerModel("tcp://"+selectedIp.substring(1,selectedIp.length()-1)+":1883","vehicle");
|
||||
} else {
|
||||
// 如果使用次数达到 12 次,跳过该 IP 并更新索引
|
||||
index = (index + 1) % ipList.size();
|
||||
redisService.setCacheObject("currentIndex", String.valueOf(index));
|
||||
return getVehicleData(vehicleConnectionReq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.car.gateway.service.impl;
|
||||
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
import com.muyu.car.gateway.service.VehicleInstanceService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.service.impl
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInstanceServceImpl
|
||||
* @Date:2024/10/6 上午10:06
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.car.instance;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* 阿里云AccessKey ID Secret
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:CreateClient
|
||||
* @Date:2024/9/29 上午10:41
|
||||
*/
|
||||
@Component
|
||||
public class CreateClient {
|
||||
|
||||
/**
|
||||
* <b>description</b> :
|
||||
* <p>使用AK&SK初始化账号Client</p>
|
||||
* @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("LTAI5tFtQk1KbwRBXM5pHVWw")
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret("GLByUZqUqgR600eTpGmfb52ZT93mu9");
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package com.muyu.car.instance;
|
||||
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesResponseBody;
|
||||
import com.aliyun.tea.*;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 项目关闭清除实例
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:DelInstance
|
||||
* @Date:2024/9/29 上午10:42
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
@Tag(name = "程序停止删除实例")
|
||||
public class DelInstance implements DisposableBean {
|
||||
|
||||
public static void delInstance() throws Exception {
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
com.aliyun.ecs20140526.Client client = CreateClient.createClient();
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-hangzhou");
|
||||
//创建运行时选择对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||
|
||||
//获取实例列表
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
|
||||
|
||||
//提取实例ID集合
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
|
||||
list.add(instance.getInstanceId());
|
||||
}
|
||||
log.info("Instance IDs: " + list);
|
||||
// 创建删除实例请求对象,并设置请求参数
|
||||
com.aliyun.ecs20140526.models.DeleteInstancesRequest deleteInstancesRequest = new com.aliyun.ecs20140526.models.DeleteInstancesRequest()
|
||||
//设置地域ID,指定删除实例的地域
|
||||
.setRegionId("cn-hangzhou")
|
||||
// 设置DryRun为true,用于验证请求是否可以成功,但不实际执行删除操作
|
||||
.setDryRun(false)
|
||||
// 设置Force为true,表示即使实例有正在运行的任务,也强制删除实例
|
||||
.setForce(true)
|
||||
// 设置TerminateSubscription为true,表示删除按订阅付费的实例时终止订阅
|
||||
.setTerminateSubscription(true)
|
||||
.setInstanceId(list);
|
||||
|
||||
//创建运行时选项对象,用于配置运行时的选项参数
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
log.info("===============>开始执行删除实例方法");
|
||||
delInstance();
|
||||
// 连接到Redis服务器
|
||||
Jedis jedis = new Jedis("159.75.188.178", 6379);
|
||||
// 指定要删除的文件夹(命名空间)
|
||||
String namespace = "InstanceIdKey:";
|
||||
// 获取所有以namespace为前缀的键
|
||||
Set<String> keys = jedis.keys(namespace + "*");
|
||||
// 如果存在键,则删除它们
|
||||
if (keys.size() > 0) {
|
||||
jedis.del(keys.toArray(new String[0]));
|
||||
}
|
||||
// 关闭连接
|
||||
jedis.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.muyu.car.instance;
|
||||
|
||||
import com.aliyun.ecs20140526.models.*;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.muyu.car.domain.example.ExampleInformation;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 项目启动创建实例
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:GenerateInstance
|
||||
* @Date:2024/9/29 上午10:42
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
@Tag(name = "启动时创建实例")
|
||||
public class GenerateInstance implements ApplicationRunner {
|
||||
|
||||
@Autowired private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 启动自动创建实例
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<String> generateInstance() throws Exception {
|
||||
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
com.aliyun.ecs20140526.Client client = CreateClient.createClient();
|
||||
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest()
|
||||
// 设置地域ID
|
||||
.setRegionId("cn-hangzhou")
|
||||
// 设置镜像ID
|
||||
.setImageId("m-bp1hkxfctk751s62jqhq")
|
||||
// 设置实例类型
|
||||
.setInstanceType("ecs.t6-c1m1.large")
|
||||
// 设置安全组ID
|
||||
.setSecurityGroupId("sg-bp1a7fk8js5pn3fw9p2m")
|
||||
// 设置虚拟交换机ID
|
||||
.setVSwitchId("vsw-bp193np7r01vssqxhh24e")
|
||||
// 设置实例名称
|
||||
.setInstanceName("server-mqtt")
|
||||
// 设置实例付费类型为后付费按量付费
|
||||
.setInstanceChargeType("PostPaid")
|
||||
// 设置互联网最大出带宽为1 Mbps
|
||||
.setInternetMaxBandwidthOut(1)
|
||||
// 设置系统盘配置
|
||||
.setSystemDisk(systemDisk)
|
||||
// 设置主机名
|
||||
.setHostName("root")
|
||||
// 设置实例密码
|
||||
.setPassword("EightGroup123.")
|
||||
// 设置创建实例的数量
|
||||
.setAmount(2);
|
||||
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtime);
|
||||
// 获取body返回值对象
|
||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
// 得到实例ID数组
|
||||
for (String instance : body.getInstanceIdSets().getInstanceIdSet()) {
|
||||
list.add(instance);
|
||||
}
|
||||
log.info("实例ID:{}",list);
|
||||
return list;
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
List<String> InstanceIds = generateInstance();
|
||||
log.info("创建实例成功");
|
||||
log.info("正在加载实例");
|
||||
Thread.sleep(30000);
|
||||
List<ExampleInformation> exampleInformations = QueryInstance.queryInstance(InstanceIds);
|
||||
log.info("加载成功");
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
for (ExampleInformation exampleInformation : exampleInformations) {
|
||||
redisService.setCacheObject("InstanceIdKey:"+exampleInformation.getInstanceId(),exampleInformation);
|
||||
list.add(exampleInformation.getIpAddress());
|
||||
}
|
||||
redisService.setCacheList("ipList",list);
|
||||
log.info("实例信息:{}",exampleInformations);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.muyu.car.instance;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.muyu.car.domain.example.ExampleInformation;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 启动后查询实例信息
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.instance
|
||||
* @Project:cloud-server-8
|
||||
* @name:QueryInstance
|
||||
* @Date:2024/9/29 下午8:58
|
||||
*/
|
||||
@Log4j2
|
||||
public class QueryInstance {
|
||||
|
||||
public static List<ExampleInformation> queryInstance(List<String> instanceIds) throws Exception {
|
||||
com.aliyun.ecs20140526.Client client = CreateClient.createClient();
|
||||
|
||||
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
||||
.setInstanceIds(JSON.toJSONString(instanceIds))
|
||||
.setRegionId("cn-hangzhou");
|
||||
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
ArrayList<ExampleInformation> exampleInformations = new ArrayList<>();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
ExampleInformation exampleInformation = new ExampleInformation();
|
||||
exampleInformation.setInstanceId(instance.getInstanceId());
|
||||
log.info("实例ID:{}",exampleInformation.getInstanceId());
|
||||
exampleInformation.setStatus(instance.getStatus());
|
||||
log.info("实例状态:{}",exampleInformation.getStatus());
|
||||
exampleInformation.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
log.info("实例IP:{}",exampleInformation.getIpAddress());
|
||||
exampleInformations.add(exampleInformation);
|
||||
}
|
||||
log.info("实例信息:{}",exampleInformations);
|
||||
return exampleInformations;
|
||||
} 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);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.car.mapper;
|
||||
|
||||
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.mapper
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformationMapper
|
||||
* @Date:2024/10/6 下午2:19
|
||||
*/
|
||||
@Mapper
|
||||
public interface VehicleInformationMapper {
|
||||
void addVehicleConnection(VehicleConnectionReq vehicleConnectionReq);
|
||||
|
||||
List<String> selectVehicleVin(@Param("vehicleVin") String vehicleVin);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.muyu.car.util;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
@Log4j2
|
||||
public class MD5Util {
|
||||
|
||||
private static final Integer SALT_LENGTH = 12;
|
||||
|
||||
/**
|
||||
* 将指定byte数组转换成16进制字符串
|
||||
* @param b 字节数组
|
||||
* @return 返回结果字符串
|
||||
*/
|
||||
public static String byteToHexString(byte[] b) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte value : b) {
|
||||
String hex = Integer.toHexString(value & 0xFF);
|
||||
if (hex.length() == 1) {
|
||||
hex = '0' + hex;
|
||||
}
|
||||
hexString.append(hex.toUpperCase());
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得加密后的口令
|
||||
* @param str 需要加密的字符串
|
||||
* @return 加密后的字符串
|
||||
*/
|
||||
public static String encrypted (String str) {
|
||||
try {
|
||||
// 声明加密后的口令数组变量
|
||||
byte[] pwd = null;
|
||||
// 随机数生成器
|
||||
SecureRandom random = new SecureRandom();
|
||||
// 声明盐数组变量
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
// 将随机数放入盐变量中
|
||||
random.nextBytes(salt);
|
||||
|
||||
// 声明消息摘要对象
|
||||
MessageDigest md = null;
|
||||
// 创建消息摘要
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
// 将盐数据传入消息摘要对象
|
||||
md.update(salt);
|
||||
// 将口令的数据传给消息摘要对象
|
||||
md.update(str.getBytes(StandardCharsets.UTF_8));
|
||||
// 获得消息摘要的字节数组
|
||||
byte[] digest = md.digest();
|
||||
|
||||
// 因为要在口令的字节数组中存放盐,所以加上盐的字节长度
|
||||
pwd = new byte[digest.length + SALT_LENGTH];
|
||||
// 将盐的字节拷贝到生成的加密口令字节数组的前12个字节,以便在验证口令时取出盐
|
||||
System.arraycopy(salt, 0, pwd, 0, SALT_LENGTH);
|
||||
// 将消息摘要拷贝到加密口令字节数组从第13个字节开始的字节
|
||||
System.arraycopy(digest, 0, pwd, SALT_LENGTH, digest.length);
|
||||
// 将字节数组格式加密后的口令转化为16进制字符串格式的口令
|
||||
return byteToHexString(pwd);
|
||||
}catch (Exception exception){
|
||||
log.info("md5加密失败:[{}]", str, exception);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-car-gateway"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-wechat"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-wechat"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.@//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.car.mapper.VehicleInformationMapper">
|
||||
<insert id="addVehicleConnection">
|
||||
INSERT INTO `vehicle_connection` (`vin`, `timestamp`, `username`, `nonce`,`password`) VALUES (#{vehicleVin}, #{timestamp}, #{username}, #{nonce},#{password});
|
||||
</insert>
|
||||
<select id="selectVehicleVin" resultType="java.lang.String">
|
||||
select
|
||||
`vin`, `timestamp`, `username`, `nonce`,`password`
|
||||
from
|
||||
`vehicle_connection`
|
||||
where `vin` = #{vehicleVin}
|
||||
</select>
|
||||
</mapper>
|
|
@ -3,18 +3,19 @@ package com.muyu.enterprise.cache.car;
|
|||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.CarInformation;
|
||||
import com.muyu.domain.resp.CarFenceGroupResp;
|
||||
import com.muyu.domain.resp.CarInformationResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 查询车辆
|
||||
* 车辆缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheCarInformationService extends CacheAbsBasic<String, List<CarInformation>> {
|
||||
public class VehicleCacheCarInformationService extends CacheAbsBasic<String, List<CarInformationResp>> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarInformation:info:";
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.muyu.domain.req.CarInformationAddReq;
|
|||
import com.muyu.domain.req.CarInformationUpdReq;
|
||||
|
||||
/**
|
||||
* 修改车辆信息
|
||||
* 车辆管理修改缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
|
|
|
@ -1,23 +1,21 @@
|
|||
package com.muyu.enterprise.cache.car;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.req.CarInformationAddReq;
|
||||
import com.muyu.domain.resp.CarInformationResp;
|
||||
|
||||
import java.util.List;
|
||||
import com.muyu.domain.CarFence;
|
||||
import com.muyu.domain.CarType;
|
||||
|
||||
/**
|
||||
* 车辆基础信息列表缓存
|
||||
* 车辆类型表缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheCarInformationFenceRespService extends CacheAbsBasic<String, List<CarInformationResp>> {
|
||||
public class VehicleCacheCarTypeService extends CacheAbsBasic<String, CarType> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarInformationFenceResp:info:";
|
||||
return "CarType:info:";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.enterprise.cache.fault;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.FaultCode;
|
||||
import com.muyu.domain.resp.CarFenceResp;
|
||||
|
||||
/**
|
||||
* 故障码缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheFaultService extends CacheAbsBasic<String, FaultCode> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "FaultCode:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import com.muyu.domain.req.CarInformationAddReq;
|
|||
import com.muyu.domain.req.FaultCodeAddReq;
|
||||
|
||||
/**
|
||||
* 添加车辆信息
|
||||
* 添加故障码缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.enterprise.cache.fence;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.CarFence;
|
||||
import com.muyu.domain.resp.CarFenceResp;
|
||||
|
||||
/**
|
||||
* 电子围栏add缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheFenceAddService extends CacheAbsBasic<String, CarFence> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarFenceAdd:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -1,24 +1,24 @@
|
|||
package com.muyu.enterprise.cache.car;
|
||||
package com.muyu.enterprise.cache.fence;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.CarFence;
|
||||
import com.muyu.domain.CarInformation;
|
||||
import com.muyu.domain.resp.CarInformationResp;
|
||||
import com.muyu.domain.resp.CarFenceResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页查询车辆信息
|
||||
* 电子围栏缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheCarInformationRespService extends CacheAbsBasic<String, Page<CarInformationResp>> {
|
||||
public class VehicleCacheFenceService extends CacheAbsBasic<String, CarFenceResp> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarInformationResp:info:";
|
||||
return "CarFenceResp:info:";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,6 +1,8 @@
|
|||
com.muyu.enterprise.cache.car.VehicleCacheCarInformationService
|
||||
com.muyu.enterprise.cache.car.VehicleCacheCarInformationRespService
|
||||
com.muyu.enterprise.cache.car.VehicleCacheCarInformationAddService
|
||||
com.muyu.enterprise.cache.car.VehicleCacheCarInformationUpdService
|
||||
com.muyu.enterprise.cache.car.VehicleCacheCarInformationFenceRespService
|
||||
com.muyu.enterprise.cache.car.VehicleCacheCarTypeService
|
||||
com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService
|
||||
com.muyu.enterprise.cache.fence.VehicleCacheFenceService
|
||||
com.muyu.enterprise.cache.fence.VehicleCacheFenceAddService
|
||||
com.muyu.enterprise.cache.fault.VehicleCacheFaultService
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -25,6 +27,7 @@ public class CarFenceClazz {
|
|||
/**
|
||||
* 业务类型ID
|
||||
*/
|
||||
@TableId(value = "clazz_id",type = IdType.AUTO)
|
||||
private Integer clazzId;
|
||||
/**
|
||||
* 业务类型名称
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -25,6 +27,7 @@ public class CarFenceType {
|
|||
/**
|
||||
* 围栏类型ID
|
||||
*/
|
||||
@TableId(value = "type_id",type = IdType.AUTO)
|
||||
private Integer typeId;
|
||||
/**
|
||||
* 围栏类型名称
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -25,6 +27,7 @@ public class CarMessage {
|
|||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
@TableId(value = "message_type_id",type = IdType.AUTO)
|
||||
private Long messageTypeId;
|
||||
/**
|
||||
* 报文编码
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -26,7 +28,8 @@ public class CarType {
|
|||
/**
|
||||
* 车辆类型ID
|
||||
*/
|
||||
private long carTypeId;
|
||||
@TableId(value = "car_type_id",type = IdType.AUTO)
|
||||
private Long carTypeId;
|
||||
/**
|
||||
* 车辆类型名
|
||||
*/
|
||||
|
|
|
@ -36,7 +36,7 @@ public class FaultCode {
|
|||
*故障码Id
|
||||
*/
|
||||
@TableId(value = "faultcode_id",type = IdType.AUTO)
|
||||
private long faultcodeId;
|
||||
private Long faultcodeId;
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
|
@ -97,7 +97,7 @@ public class FaultCode {
|
|||
|
||||
public static FaultCode updfaultcode(FaultCodeUpdReq faultCodeUpdReq){
|
||||
return FaultCode.builder()
|
||||
.faultcodeId(0)
|
||||
.faultcodeId(0L)
|
||||
.messageTypeId(faultCodeUpdReq.getMessageTypeId())
|
||||
.faultcodeNumber(faultCodeUpdReq.getFaultcodeNumber())
|
||||
.faultGroup(faultCodeUpdReq.getFaultGroup())
|
||||
|
|
|
@ -23,25 +23,15 @@ import java.util.List;
|
|||
@Tag(name = "故障码,电子围栏,车辆,报文")
|
||||
public class FaultCodeCache {
|
||||
|
||||
/**
|
||||
* 电子围栏信息
|
||||
*/
|
||||
private List<CarFence> carFences;
|
||||
|
||||
/**
|
||||
* 故障标签信息
|
||||
*/
|
||||
private WarnStrategy warnStrategies;
|
||||
|
||||
/**
|
||||
* 车辆信息
|
||||
*/
|
||||
public List<CarInformation> carInformation;
|
||||
public CarInformation carInformation;
|
||||
|
||||
/**
|
||||
* 故障码信息
|
||||
*/
|
||||
private List<FaultCode> faultCode;
|
||||
private FaultCode faultCode;
|
||||
|
||||
/**
|
||||
* 故障标签
|
||||
|
|
|
@ -36,7 +36,7 @@ public class FaultCondition {
|
|||
* 故障规则表Id
|
||||
*/
|
||||
@TableId(value = "carcondition_id",type = IdType.AUTO)
|
||||
private long carconditionId;
|
||||
private Long carconditionId;
|
||||
/**
|
||||
* 车辆类型Id
|
||||
*/
|
||||
|
|
|
@ -32,7 +32,7 @@ public class FaultLabel {
|
|||
*自增主键
|
||||
*/
|
||||
@TableId(value = "message_type_id",type = IdType.AUTO)
|
||||
private long messageTypeId;
|
||||
private Long messageTypeId;
|
||||
/**
|
||||
*报文编码
|
||||
*/
|
||||
|
|
|
@ -34,7 +34,7 @@ public class FaultLog {
|
|||
* 故障日志Id
|
||||
*/
|
||||
@TableId(value = "log_id",type = IdType.AUTO)
|
||||
private long logId;
|
||||
private Long logId;
|
||||
/**
|
||||
* 故障码Id
|
||||
*/
|
||||
|
|
|
@ -26,7 +26,7 @@ public class FaultType {
|
|||
*故障类型Id
|
||||
*/
|
||||
@TableId(value = "faulttype_id",type = IdType.AUTO)
|
||||
private long faulttypeId;
|
||||
private Long faulttypeId;
|
||||
/**
|
||||
*故障类型名称
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.muyu.domain.req.FaultCodeAddReq;
|
||||
import com.muyu.domain.req.FirmPermissionAddReq;
|
||||
import com.muyu.domain.req.FirmPermissionUpdReq;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -24,7 +27,7 @@ public class FirmPermission {
|
|||
* 企业权限Id
|
||||
*/
|
||||
@TableId(value = "permission_id")
|
||||
private long permissionId;
|
||||
private Long permissionId;
|
||||
|
||||
/**
|
||||
* 权限等级
|
||||
|
@ -42,4 +45,22 @@ public class FirmPermission {
|
|||
private Integer carTypeNumber;
|
||||
|
||||
|
||||
public static FirmPermission addfirmpermission(FirmPermissionAddReq firmPermissionAddReq){
|
||||
return FirmPermission.builder()
|
||||
.permissionLevel(firmPermissionAddReq.getPermissionLevel())
|
||||
.carNumber(firmPermissionAddReq.getCarNumber())
|
||||
.carTypeNumber(firmPermissionAddReq.getCarTypeNumber())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static FirmPermission updfirmpermission(FirmPermissionUpdReq firmPermissionUpdReq){
|
||||
return FirmPermission.builder()
|
||||
.permissionId(firmPermissionUpdReq.getPermissionId())
|
||||
.permissionLevel(firmPermissionUpdReq.getPermissionLevel())
|
||||
.carNumber(firmPermissionUpdReq.getCarNumber())
|
||||
.carTypeNumber(firmPermissionUpdReq.getCarTypeNumber())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class Message {
|
|||
* id
|
||||
*/
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private long id;
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 发送者
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.domain.req;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 企业权限新增请求对象
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.domain.req
|
||||
* @Project:cloud-server-8
|
||||
* @name:FirmPermissionAddReq
|
||||
* @Date:2024/10/8 19:48
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Tag(name = "企业权限新增请求对象",description = "企业权限新增请求对象")
|
||||
public class FirmPermissionAddReq {
|
||||
|
||||
/**
|
||||
* 权限等级
|
||||
*/
|
||||
private String permissionLevel;
|
||||
|
||||
/**
|
||||
* 车辆数目
|
||||
*/
|
||||
private Integer carNumber;
|
||||
|
||||
/**
|
||||
* 车辆类型数目
|
||||
*/
|
||||
private Integer carTypeNumber;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.domain.req;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 企业权限修改请求对象
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.domain.req
|
||||
* @Project:cloud-server-8
|
||||
* @name:FirmPermissionUpdReq
|
||||
* @Date:2024/10/8 20:11
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Tag(name = "企业权限修改请求对象",description = "企业权限修改请求对象")
|
||||
public class FirmPermissionUpdReq {
|
||||
|
||||
/**
|
||||
* 企业权限Id
|
||||
*/
|
||||
@TableId(value = "permission_id")
|
||||
private long permissionId;
|
||||
/**
|
||||
* 权限等级
|
||||
*/
|
||||
private String permissionLevel;
|
||||
|
||||
/**
|
||||
* 车辆数目
|
||||
*/
|
||||
private Integer carNumber;
|
||||
|
||||
/**
|
||||
* 车辆类型数目
|
||||
*/
|
||||
private Integer carTypeNumber;
|
||||
|
||||
|
||||
}
|
|
@ -43,7 +43,8 @@ public class CarFenceController {
|
|||
@Validated @RequestBody CarFenceReq req
|
||||
){
|
||||
Page<CarFenceResp> connects = carFenceService.selectCarFence(req);
|
||||
log.info("查询数据:"+ connects);
|
||||
|
||||
log.info("查询数据:"+ connects);
|
||||
|
||||
return Result.success(
|
||||
connects, "操作成功"
|
||||
|
|
|
@ -35,32 +35,21 @@ public class CarInformationController {
|
|||
@Resource
|
||||
private CarInformationService carInformationService;
|
||||
private VehicleCacheCarInformationService vehicleCacheCarInformationService;
|
||||
private VehicleCacheCarInformationRespService vehicleCacheCarInformationRespService;
|
||||
private VehicleCacheCarInformationAddService vehicleCacheCarInformationAddService;
|
||||
private VehicleCacheCarInformationUpdService vehicleCacheCarInformationUpdService;
|
||||
private VehicleCacheCarInformationFenceRespService vehicleCacheCarInformationFenceRespService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询围栏业务信息
|
||||
* 查询车辆业务信息
|
||||
*/
|
||||
@PostMapping("/selectCarInformation")
|
||||
@Operation(summary = "查询数据",description = "查询数据")
|
||||
public Result<List<CarInformation>> selectConnect(){
|
||||
List<CarInformation> carFenceRespPage = vehicleCacheCarInformationService
|
||||
.get(vehicleCacheCarInformationService
|
||||
.keyPre()+ ObtainRootLogin
|
||||
.obtain());
|
||||
if (CollectionUtils.isEmpty(carFenceRespPage)) {
|
||||
return Result.success(carFenceRespPage);
|
||||
}
|
||||
List<CarInformation> connects = carInformationService.list()
|
||||
.stream()
|
||||
.map(CarInformation::carInformationBuilder)
|
||||
.toList();
|
||||
vehicleCacheCarInformationService.put(
|
||||
vehicleCacheCarInformationService.keyPre()+ObtainRootLogin.obtain()
|
||||
,connects);
|
||||
|
||||
return Result.success(
|
||||
connects, "操作成功"
|
||||
);
|
||||
|
@ -88,18 +77,14 @@ public class CarInformationController {
|
|||
@Operation(summary = "企业车辆管理列表")
|
||||
public Result<Page<CarInformationResp>> selectCarInformationList(@Validated @RequestBody CarInformationListReq carInformationListReq) {
|
||||
|
||||
Page<CarInformationResp> carFenceRespPage = vehicleCacheCarInformationRespService
|
||||
.get(vehicleCacheCarInformationRespService
|
||||
.keyPre()+ ObtainRootLogin
|
||||
.obtain());
|
||||
if (CollectionUtils.isEmpty(carFenceRespPage.getRecords())) {
|
||||
return Result.success(carFenceRespPage);
|
||||
}
|
||||
Page<CarInformationResp> pageInfo = carInformationService.selectCarInformationList(carInformationListReq);
|
||||
log.info("企业车辆管理列表查询",carInformationListReq,pageInfo);
|
||||
vehicleCacheCarInformationRespService.put(
|
||||
vehicleCacheCarInformationRespService.keyPre()+ObtainRootLogin.obtain()
|
||||
,pageInfo);
|
||||
List<CarInformationResp> records = pageInfo.getRecords();
|
||||
records.forEach(carInformation -> {
|
||||
vehicleCacheCarInformationService.put(
|
||||
vehicleCacheCarInformationService.keyPre()+carInformation.getCarInformationVIN()
|
||||
,records);
|
||||
});
|
||||
return Result.success(pageInfo);
|
||||
|
||||
}
|
||||
|
@ -116,7 +101,7 @@ public class CarInformationController {
|
|||
|
||||
vehicleCacheCarInformationAddService.put(
|
||||
vehicleCacheCarInformationAddService
|
||||
.keyPre()+ObtainRootLogin.obtain(), carInformationAddReq);
|
||||
.keyPre()+carInformationAddReq.getCarInformationVIN(), carInformationAddReq);
|
||||
return carInformationService.addCarInformation(carInformationAddReq)
|
||||
?Result.success("添加车辆成功")
|
||||
:Result.error(402,"添加车辆失败");
|
||||
|
@ -169,17 +154,8 @@ public class CarInformationController {
|
|||
@GetMapping("/selectCarInformationIdAndLicensePlate")
|
||||
@Operation(summary = "查询企业车辆 carInformationID 和 carInformationLicensePlate")
|
||||
public Result<List<CarInformationResp>> selectCarInformationIdAndLicensePlate(){
|
||||
List<CarInformationResp> carFenceRespPage = vehicleCacheCarInformationFenceRespService
|
||||
.get(vehicleCacheCarInformationFenceRespService
|
||||
.keyPre()+ ObtainRootLogin
|
||||
.obtain());
|
||||
if (CollectionUtils.isEmpty(carFenceRespPage)) {
|
||||
return Result.success(carFenceRespPage);
|
||||
}
|
||||
List<CarInformationResp> carInformations = carInformationService.selectBycarInformationIDAndLicensePlate();
|
||||
vehicleCacheCarInformationFenceRespService.put(
|
||||
vehicleCacheCarInformationFenceRespService.keyPre()+ObtainRootLogin.obtain()
|
||||
,carInformations);
|
||||
|
||||
return Result.success(carInformations);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
package com.muyu.server.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.CarInformation;
|
||||
import com.muyu.domain.CarType;
|
||||
import com.muyu.enterprise.cache.car.VehicleCacheCarTypeService;
|
||||
import com.muyu.server.service.CarInformationService;
|
||||
import com.muyu.server.service.CarTypeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 车辆类型控制层
|
||||
|
@ -23,10 +28,12 @@ import java.util.List;
|
|||
|
||||
@RequestMapping("/cartype")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
public class CarTypeController {
|
||||
|
||||
@Autowired
|
||||
private CarTypeService carTypeService;
|
||||
private final CarTypeService carTypeService;
|
||||
private final CarInformationService carInformationService;
|
||||
private final VehicleCacheCarTypeService vehicleCacheCarTypeService;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -38,7 +45,16 @@ public class CarTypeController {
|
|||
public Result carTypeList(){
|
||||
|
||||
List<CarType> data = carTypeService.selectcarType();
|
||||
|
||||
data.forEach(carType -> {
|
||||
List<CarInformation> list = carInformationService.list(new LambdaQueryWrapper<CarInformation>()
|
||||
.eq(CarInformation::getCarInformationType, carType.getCarTypeId()));
|
||||
list.forEach(carInformation -> {
|
||||
vehicleCacheCarTypeService
|
||||
.put(vehicleCacheCarTypeService
|
||||
.keyPre()+carInformation
|
||||
.getCarInformationVIN(),carType);
|
||||
});
|
||||
});
|
||||
return Result.success(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.muyu.domain.resp.FaultCodeTotalListResp;
|
|||
import com.muyu.server.service.FaultCodeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -25,11 +25,12 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
@RestController
|
||||
@RequestMapping("/faultcode")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "车辆故障码控制层",description = "从故障信息表中查询数据")
|
||||
public class FaultCodeController {
|
||||
|
||||
@Autowired
|
||||
private FaultCodeService faultCodeService;
|
||||
private final FaultCodeService faultCodeService;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -59,10 +59,7 @@ public class FaultConditionController {
|
|||
if (faultConditionList.size()>0){
|
||||
return Result.error("此车辆类型已存在所对应的故障规则,无需重新制定,可在原规则上进行修改");
|
||||
}
|
||||
boolean save = faultConditionService.save(FaultCondition.faultConditionadd(faultConditionAddReq));
|
||||
if (save){
|
||||
faultConditionService.RunCarCondition();
|
||||
}
|
||||
faultConditionService.save(FaultCondition.faultConditionadd(faultConditionAddReq));
|
||||
return Result.success(null,"规则制定成功");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package com.muyu.server.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.FirmPermission;
|
||||
import com.muyu.domain.req.FirmPermissionAddReq;
|
||||
import com.muyu.domain.req.FirmPermissionUpdReq;
|
||||
import com.muyu.domain.req.FirmUpdPermissionReq;
|
||||
import com.muyu.server.service.FirmPermissionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -29,10 +33,47 @@ public class FirmPermissionController {
|
|||
* @param firmUpdPermissionReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/updpermission")
|
||||
@PostMapping("/permissionupd")
|
||||
@Operation(summary = "修改权限分配",description = "修改权限分配")
|
||||
public Result updpermission(@RequestBody FirmUpdPermissionReq firmUpdPermissionReq){
|
||||
firmPermissionService.updpermission(firmUpdPermissionReq);
|
||||
return Result.success(null,"权限更改成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权限等级列表
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/permissionlist")
|
||||
@Operation(summary = "权限等级列表",description = "权限等级列表")
|
||||
public Result permissionlist(){
|
||||
return Result.success(firmPermissionService.permissionlist());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 企业权限新增
|
||||
* @param firmPermissionAddReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/addpermission")
|
||||
@Operation(summary = "企业权限新增",description = "企业权限新增")
|
||||
public Result addpermission(@RequestBody FirmPermissionAddReq firmPermissionAddReq){
|
||||
firmPermissionService.save(FirmPermission.addfirmpermission(firmPermissionAddReq));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 企业权限修改
|
||||
* @param firmPermissionUpdReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/updpermission")
|
||||
@Operation(summary = "企业权限修改",description = "企业权限修改")
|
||||
public Result updpermission(@RequestBody FirmPermissionUpdReq firmPermissionUpdReq){
|
||||
firmPermissionService.updateById(FirmPermission.updfirmpermission(firmPermissionUpdReq));
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,4 @@ public interface FaultConditionService extends IService<FaultCondition> {
|
|||
*/
|
||||
List<FaultCondition> saveFaultConditionList();
|
||||
|
||||
/**
|
||||
* 添加缓存
|
||||
*/
|
||||
void RunCarCondition();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
import com.muyu.domain.FirmPermission;
|
||||
import com.muyu.domain.req.FirmUpdPermissionReq;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 企业权限分配业务层
|
||||
* @Author:weiran
|
||||
|
@ -20,4 +22,10 @@ public interface FirmPermissionService extends IService<FirmPermission> {
|
|||
* @return
|
||||
*/
|
||||
void updpermission(FirmUpdPermissionReq firmUpdPermissionReq);
|
||||
|
||||
/**
|
||||
* 权限等级列表
|
||||
* @return
|
||||
*/
|
||||
List<FirmPermission> permissionlist();
|
||||
}
|
||||
|
|
|
@ -9,8 +9,11 @@ import com.muyu.domain.req.*;
|
|||
import com.muyu.domain.resp.CarFenceGroupResp;
|
||||
import com.muyu.domain.resp.CarFenceGroupsResp;
|
||||
import com.muyu.domain.resp.CarFenceResp;
|
||||
import com.muyu.enterprise.cache.fence.VehicleCacheFenceAddService;
|
||||
import com.muyu.enterprise.cache.fence.VehicleCacheFenceService;
|
||||
import com.muyu.server.mapper.CarFenceMapper;
|
||||
import com.muyu.server.service.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -28,6 +31,7 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
@AllArgsConstructor
|
||||
public class CarFenceServiceImpl
|
||||
extends ServiceImpl<CarFenceMapper, CarFence>
|
||||
implements CarFenceService {
|
||||
|
@ -44,6 +48,8 @@ public class CarFenceServiceImpl
|
|||
private CarMiddleSerivce carMiddleSerivce;
|
||||
@Autowired
|
||||
private CarInformationService carInformationService;
|
||||
private final VehicleCacheFenceService vehicleCacheFenceService;
|
||||
private final VehicleCacheFenceAddService vehicleCacheFenceAddService;
|
||||
/**
|
||||
* 查询围栏信息
|
||||
*/
|
||||
|
@ -83,8 +89,9 @@ public class CarFenceServiceImpl
|
|||
.toList();
|
||||
List<CarFence> carFenceList = carFencePage.getRecords();
|
||||
this.optimizeEntity(carFenceList,carFenceClazzList,carFenceTypeList);
|
||||
|
||||
//构建一个新的分页响应对象
|
||||
return new Page<>() {{
|
||||
Page<CarFenceResp> carFenceRespPage = new Page<>() {{
|
||||
//从查询结果中获取记录,并使用流式处理将每条记录转换为EtlDataScoreResp对象
|
||||
List<CarFenceResp> etlDataScoreRespList = carFencePage.getRecords().stream()
|
||||
//使用map操作将EtlDataScore对象转换为EtlDataScoreResp对象
|
||||
|
@ -100,6 +107,17 @@ public class CarFenceServiceImpl
|
|||
//设置分页响应中的每页记录数
|
||||
setSize(carFencePage.getSize());
|
||||
}};
|
||||
List<CarFenceResp> records = carFenceRespPage.getRecords();
|
||||
records.forEach(carFenceResp -> {
|
||||
List<CarInformation> list = carInformationService
|
||||
.list(new LambdaQueryWrapper<CarInformation>()
|
||||
.eq(CarInformation::getCarInformationFence, carFenceResp.getId()));
|
||||
list.forEach(carInformation -> {
|
||||
vehicleCacheFenceService.put(vehicleCacheFenceService.keyPre()+carInformation.getCarInformationVIN(),carFenceResp);
|
||||
});
|
||||
|
||||
});
|
||||
return carFenceRespPage;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,6 +136,12 @@ public class CarFenceServiceImpl
|
|||
carMiddleGroup.setFenceGroupId(carFenceGroup.getId());
|
||||
carMiddleGroupService.save(carMiddleGroup);
|
||||
});
|
||||
List<CarInformation> list = carInformationService
|
||||
.list(new LambdaQueryWrapper<CarInformation>()
|
||||
.eq(CarInformation::getCarInformationFence, carFence.getId()));
|
||||
list.forEach(carInformation -> {
|
||||
vehicleCacheFenceAddService.put(vehicleCacheFenceAddService.keyPre()+carInformation.getCarInformationVIN(),carFence);
|
||||
});
|
||||
return connects;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@ import com.muyu.domain.req.FaultCodeUpdReq;
|
|||
import com.muyu.domain.resp.FaultCodeListResp;
|
||||
import com.muyu.domain.resp.FaultCodeTotalListResp;
|
||||
import com.muyu.domain.resp.FaultConditionListResp;
|
||||
import com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService;
|
||||
import com.muyu.domain.resp.FaultConditionResp;
|
||||
import com.muyu.enterprise.cache.car.VehicleCacheCarInformationService;
|
||||
import com.muyu.enterprise.cache.fault.VehicleCacheFaultService;
|
||||
import com.muyu.server.mapper.FaultCodeMapper;
|
||||
import com.muyu.server.service.CarFenceService;
|
||||
import com.muyu.server.service.CarInformationService;
|
||||
|
@ -54,7 +56,7 @@ public class FaultCodeServiceImpl extends ServiceImpl<FaultCodeMapper, FaultCode
|
|||
long count = this.count(queryWrapper);
|
||||
|
||||
MPJLambdaWrapper<FaultCode> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.select(
|
||||
MPJLambdaWrapper<FaultCode> eq = wrapper.select(
|
||||
FaultCode::getFaultcodeId,
|
||||
FaultCode::getMessageTypeId,
|
||||
FaultCode::getFaultcodeNumber,
|
||||
|
@ -64,9 +66,9 @@ public class FaultCodeServiceImpl extends ServiceImpl<FaultCodeMapper, FaultCode
|
|||
.select(
|
||||
FaultLabel::getMessageTypeCode,
|
||||
FaultLabel::getMessageTypeName)
|
||||
.leftJoin(FaultLabel.class,FaultLabel::getMessageTypeId,FaultCode::getMessageTypeId)
|
||||
.leftJoin(FaultLabel.class, FaultLabel::getMessageTypeId, FaultCode::getMessageTypeId)
|
||||
.eq(StringUtils.isNotEmpty(faultCodeListReq.getFaultcodeNumber()),
|
||||
FaultCode::getFaultcodeNumber,faultCodeListReq.getFaultcodeNumber())
|
||||
FaultCode::getFaultcodeNumber, faultCodeListReq.getFaultcodeNumber())
|
||||
.eq(StringUtils.isNotEmpty(faultCodeListReq.getFaultBit()),
|
||||
FaultCode::getFaultBit, faultCodeListReq.getFaultBit());
|
||||
wrapper.last("LIMIT "+ ((faultCodeListReq.getPageNum()-1)*faultCodeListReq.getPageSize())+", "+faultCodeListReq.getPageSize());
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.muyu.server.service.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.domain.*;
|
||||
import com.muyu.domain.req.FaultConditionAddReq;
|
||||
import com.muyu.domain.req.FaultConditionListReq;
|
||||
|
@ -12,12 +11,11 @@ import com.muyu.domain.resp.FaultConditionTotalListResp;
|
|||
import com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService;
|
||||
import com.muyu.server.mapper.FaultConditionMapper;
|
||||
import com.muyu.server.service.*;
|
||||
import com.muyu.server.util.RunCarCondition;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -37,12 +35,12 @@ public class FaultConditionServiceImpl
|
|||
|
||||
@Autowired
|
||||
private FaultConditionMapper faultConditionMapper;
|
||||
private final VehicleCacheFaultCodeAddService vehicleCacheFaultCodeAddService;
|
||||
private final CarInformationService carInformationService;
|
||||
private final CarFenceService carFenceService;
|
||||
private final WarnStrategyService warnStrategyService;
|
||||
private final FaultCodeService faultCodeService;
|
||||
private final FaultLabelService faultLabelService;
|
||||
private final VehicleCacheFaultCodeAddService vehicleCacheFaultCodeAddService;
|
||||
|
||||
|
||||
|
||||
|
@ -74,9 +72,36 @@ public class FaultConditionServiceImpl
|
|||
}
|
||||
wrapper.last("LIMIT "+ ((faultConditionListReq.getPageNum()-1)*faultConditionListReq.getPageSize())+", "+faultConditionListReq.getPageSize());
|
||||
List<FaultConditionListResp> faultConditionListResps = faultConditionMapper.selectJoinList(FaultConditionListResp.class, wrapper);
|
||||
//添加故障车辆缓存
|
||||
this.CacheFault(faultConditionListResps);
|
||||
return FaultConditionTotalListResp.faultConditionTotalListResp(faultConditionListResps,count);
|
||||
}
|
||||
|
||||
private void CacheFault(@NotNull List<FaultConditionListResp> faultConditionListResps) {
|
||||
faultConditionListResps.forEach(faultConditionListResp -> {
|
||||
List<CarInformation> list = carInformationService
|
||||
.list(new LambdaQueryWrapper<CarInformation>()
|
||||
.eq(CarInformation::getCarInformationType, faultConditionListResp.getCarTypeId()));
|
||||
list.forEach(carInformation -> {
|
||||
List<FaultCode> list1 = faultCodeService.list(new LambdaQueryWrapper<FaultCode>()
|
||||
.eq(FaultCode::getFaultcodeId, faultConditionListResp.getMessageTypeId()));
|
||||
list1.forEach(faultCode -> {
|
||||
FaultCodeCache faultCodeCache = new FaultCodeCache();
|
||||
faultCodeCache.setCarInformation(carInformation);
|
||||
faultCodeCache.setFaultCode(faultCode);
|
||||
FaultLabel faultLabel = new FaultLabel();
|
||||
faultLabel.setMessageTypeId(faultConditionListResp.getMessageTypeId());
|
||||
faultLabel.setMessageTypeName(faultConditionListResp.getMessageTypeName());
|
||||
faultLabel.setMessageTypeCode(faultConditionListResp.getMessageTypeCode());
|
||||
faultCodeCache.setFaultLabels(faultLabel);
|
||||
vehicleCacheFaultCodeAddService.put(vehicleCacheFaultCodeAddService
|
||||
.keyPre()+carInformation
|
||||
.getCarInformationVIN(),faultCodeCache);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 故障规则添加 判断故障规则是否存在
|
||||
|
@ -90,6 +115,7 @@ public class FaultConditionServiceImpl
|
|||
queryWrapper.eq(FaultCondition::getCarTypeId,faultConditionAddReq.getCarTypeId())
|
||||
.eq(FaultCondition::getMessageTypeId,faultConditionAddReq.getMessageTypeId());
|
||||
List<FaultCondition> list = this.list(queryWrapper);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -98,67 +124,4 @@ public class FaultConditionServiceImpl
|
|||
List<FaultCondition> list = this.list();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加缓存
|
||||
*/
|
||||
@Override
|
||||
public void RunCarCondition() {
|
||||
List<FaultCondition> list = this.saveFaultConditionList();
|
||||
text(list, carInformationService, carFenceService, warnStrategyService, faultCodeService, faultLabelService, vehicleCacheFaultCodeAddService);
|
||||
}
|
||||
|
||||
public static void text(List<FaultCondition> list, CarInformationService carInformationService, CarFenceService carFenceService, WarnStrategyService warnStrategyService, FaultCodeService faultCodeService, FaultLabelService faultLabelService, VehicleCacheFaultCodeAddService vehicleCacheFaultCodeAddService) {
|
||||
list.forEach(faultCondition -> {
|
||||
List<CarInformation> carInformationList = carInformationService.selectCarInformation(faultCondition.getCarTypeId());
|
||||
carInformationList.forEach(carInformation -> {
|
||||
FaultCodeCache faultCodeCache = new FaultCodeCache();
|
||||
if (StringUtils.isNotNull(carInformation.getCarInformationFence())){
|
||||
faultCodeCache.setCarFences(carFenceService.CarFenceList(carInformation.getCarInformationFence()));
|
||||
}
|
||||
if (StringUtils.isNotNull(carInformation.getCarInformationState())) {
|
||||
faultCodeCache.setWarnStrategies(warnStrategyService
|
||||
.selectWarnStrategyById(Long.valueOf(carInformation.getCarInformationState())));
|
||||
}
|
||||
if (StringUtils.isNotNull(faultCondition.getMessageTypeId())) {
|
||||
faultCodeCache.setFaultCode(faultCodeService.faultCodeList(faultCondition.getMessageTypeId()));
|
||||
faultCodeCache.setFaultLabels(faultLabelService.faultLabelList(faultCondition.getMessageTypeId()));
|
||||
}
|
||||
ArrayList<CarInformation> carInformations = new ArrayList<>();
|
||||
carInformations.add(carInformation);
|
||||
faultCodeCache.setCarInformation(carInformations);
|
||||
vehicleCacheFaultCodeAddService.put(vehicleCacheFaultCodeAddService
|
||||
.keyPre()+carInformation
|
||||
.getCarInformationVIN(), faultCodeCache);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// private void faultCache(long messageTypeId, Long faulttypeId,String faultcodeNumber) {
|
||||
// FaultCodeCache faultCodeCache = new FaultCodeCache();
|
||||
//
|
||||
// //添加故障标签
|
||||
// faultCodeCache.getFaultLabels().addAll(faultLabelService.selectFaultCode(messageTypeId));
|
||||
//
|
||||
// //添加车辆
|
||||
// List<CarInformation> carInformationList = carInformationService.selectCarInformation(faulttypeId);
|
||||
// faultCodeCache.getCarInformation().addAll(carInformationList);
|
||||
//
|
||||
// //添加故障码
|
||||
// faultCodeCache.getFaultCode().addAll(this.list(new LambdaQueryWrapper<FaultCode>()
|
||||
// .eq(FaultCode::getFaultcodeNumber, faultcodeNumber))
|
||||
// .stream().map(FaultCode::faultCodeBuilder)
|
||||
// .toList());
|
||||
//
|
||||
// //添加围栏
|
||||
// ArrayList<CarFence> carFences1 = new ArrayList<>();
|
||||
// carInformationList.forEach(carInformation -> {
|
||||
// CarFence carFence = carFenceService.selectCarFenceList(carInformation.getCarInformationFence());
|
||||
// carFences1.add(carFence);
|
||||
// });
|
||||
// faultCodeCache.getCarFences().addAll(carFences1);
|
||||
// vehicleCacheFaultCodeAddService.put(vehicleCacheFaultCodeAddService.keyPre()
|
||||
// + ObtainRootLogin.obtain()
|
||||
// , faultCodeCache);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.server.service.impl;
|
|||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
|
@ -80,6 +81,9 @@ public class FirmManageServiceImpl extends ServiceImpl<FirmManageMapper, SysUser
|
|||
*/
|
||||
@Override
|
||||
public void updpermission(FirmUpdPermissionReq firmUpdPermissionReq, long permissionId) {
|
||||
|
||||
LambdaUpdateWrapper<Firm> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(Firm::getPermissionId, permissionId );
|
||||
updateWrapper.eq(Firm::getFirmId, firmUpdPermissionReq.getFirmId());
|
||||
firmService.update(updateWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||
public class FirmPermissionServiceImpl extends ServiceImpl<FirmPermissionMapper, FirmPermission> implements FirmPermissionService {
|
||||
@Autowired
|
||||
private FirmManageService firmManageService;
|
||||
|
||||
/**
|
||||
* 修改企业权限分配
|
||||
* @param firmUpdPermissionReq
|
||||
|
@ -41,4 +42,16 @@ public class FirmPermissionServiceImpl extends ServiceImpl<FirmPermissionMapper,
|
|||
//修改企业对应权限
|
||||
firmManageService.updpermission(firmUpdPermissionReq,permissionId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权限等级列表
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FirmPermission> permissionlist() {
|
||||
LambdaQueryWrapper<FirmPermission> queryWrapper = new LambdaQueryWrapper<>();
|
||||
List<FirmPermission> list = this.list(queryWrapper);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package com.muyu.server.util;
|
||||
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.domain.*;
|
||||
import com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService;
|
||||
import com.muyu.server.service.*;
|
||||
import com.muyu.server.service.impl.FaultConditionServiceImpl;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录存储redis缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.util
|
||||
* @Project:cloud-server-8
|
||||
* @name:RunCarCondition
|
||||
* @Date:2024/10/7 19:43
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class RunCarCondition {
|
||||
|
||||
private final VehicleCacheFaultCodeAddService vehicleCacheFaultCodeAddService;
|
||||
private final FaultConditionService faultConditionService;
|
||||
private final CarInformationService carInformationService;
|
||||
private final CarFenceService carFenceService;
|
||||
private final WarnStrategyService warnStrategyService;
|
||||
private final FaultCodeService faultCodeService;
|
||||
private final FaultLabelService faultLabelService;
|
||||
|
||||
@GetMapping("text")
|
||||
public void runCarCondition(){
|
||||
List<FaultCondition> list = faultConditionService.saveFaultConditionList();
|
||||
FaultConditionServiceImpl.text(list, carInformationService, carFenceService, warnStrategyService, faultCodeService, faultLabelService, vehicleCacheFaultCodeAddService);
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@
|
|||
<module>cloud-modules-gen</module>
|
||||
<module>cloud-modules-file</module>
|
||||
<module>cloud-modules-carData</module>
|
||||
<module>cloud-modules-car-gateway</module>
|
||||
<module>cloud-modules-protocolparsing</module>
|
||||
</modules>
|
||||
|
||||
|
|
Loading…
Reference in New Issue