优化代码第三次

dev.car.gateway
冷调 2024-10-10 16:08:01 +08:00
parent 6b571dfddc
commit 35fa5b2ed9
21 changed files with 182 additions and 186 deletions

View File

@ -7,18 +7,19 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-10-07-21:51 * @ Date2024-10-07-21:51
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Log4j2 @Log4j2
@Component @Component
public class DeleteSample implements DisposableBean { public class DeleteSample implements DisposableBean {
@Autowired @Autowired
private AliYunEcsService aliYunEcsService; private AliYunEcsService aliYunEcsService;
@Override @Override
public void destroy() { public void destroy() {
try { try {

View File

@ -21,7 +21,7 @@ import java.util.List;
*/ */
@Log4j2 @Log4j2
@Component @Component
public class Sample implements ApplicationRunner{ public class Sample implements ApplicationRunner {
@Autowired @Autowired
private AliYunEcsService aliYunEcsService; private AliYunEcsService aliYunEcsService;
@ -46,7 +46,7 @@ public class Sample implements ApplicationRunner{
throw new RuntimeException(e); throw new RuntimeException(e);
} }
List<AliInstance> aliInstances = aliYunEcsService.selectInstance(list); List<AliInstance> aliInstances = aliYunEcsService.selectInstance(list);
log.info("================查询实例信息成功:{}",aliInstances); log.info("================查询实例信息成功:{}", aliInstances);
} }
// @Override // @Override

View File

@ -7,12 +7,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-17-15:00 * @ Date2024-09-17-15:00
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Log4j2 @Log4j2
@EnableCustomConfig @EnableCustomConfig

View File

@ -19,29 +19,49 @@ import org.springframework.context.annotation.Configuration;
@Log4j2 @Log4j2
@Configuration @Configuration
public class RabbitmqConfig { public class RabbitmqConfig {
// 日志 /**
*
*/
private static final Logger logger = LoggerFactory.getLogger(RabbitmqConfig.class); private static final Logger logger = LoggerFactory.getLogger(RabbitmqConfig.class);
/**
*
*/
public static final String QUEUE_INFORM_EMAIL = "queue_inform_email";
/**
*
*/
public static final String QUEUE_INFORM_SMS = "queue_inform_sms";
/** /**
* *
*/ */
public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform"; public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";
/** /**
* key * 线vin
*/
public static final String QUEUE_INFORM_EMAIL = "queue_inform_email";
/**
*
*/
public static final String QUEUE_INFORM_SMS = "queue_inform_sms";
/**
* 线vin
*/
public static final String QUEUE_INFORM_SEND = "queue_inform_send";
/**
* saas
*/
public static final String QUEUE_INFORM_SAAS = "queue_inform_saas";
/**
* key 线
*/ */
public static final String ROUTINGKEY_EMAIL = "inform.#.email.#"; public static final String ROUTINGKEY_EMAIL = "inform.#.email.#";
/** /**
* key * key
*/ */
public static final String ROUTINGKEY_SMS = "inform.#.sms.#"; public static final String ROUTINGKEY_SMS = "inform.#.sms.#";
/**
* key 线
*/
public static final String ROUTINGKEY_SEND = "inform.#.send.#";
/**
* key saas
*/
public static final String ROUTINGKEY_SAAS = "inform.#.saas.#";
/** /**
* , * ,
@ -58,7 +78,9 @@ public class RabbitmqConfig {
} }
} }
// 声明QUEUE_INFORM_EMAIL队列 /**
* QUEUE_INFORM_EMAIL
*/
@Bean(QUEUE_INFORM_EMAIL) @Bean(QUEUE_INFORM_EMAIL)
public Queue queueInformEmail() { public Queue queueInformEmail() {
try { try {
@ -71,7 +93,9 @@ public class RabbitmqConfig {
} }
} }
// 声明QUEUE_INFORM_SMS队列 /**
* QUEUE_INFORM_SMS
*/
@Bean(QUEUE_INFORM_SMS) @Bean(QUEUE_INFORM_SMS)
public Queue queueInformSms() { public Queue queueInformSms() {
try { try {
@ -84,17 +108,82 @@ public class RabbitmqConfig {
} }
} }
//ROUTINGKEY_EMAIL队列绑定交换机指定routingKey /**
* QUEUE_INFORM_SEND
*/
@Bean(QUEUE_INFORM_SEND)
public Queue queueInformSend() {
try {
Queue queue = new Queue(QUEUE_INFORM_SEND);
log.info("创建的队列为: {}", QUEUE_INFORM_SEND);
return queue;
} catch (Exception e) {
log.error("创建该: {} 队列失败", QUEUE_INFORM_SEND, e);
throw e;
}
}
/**
* QUEUE_INFORM_SAAS
*/
@Bean(QUEUE_INFORM_SAAS)
public Queue queueInformSaas() {
try {
Queue queue = new Queue(QUEUE_INFORM_SAAS);
log.info("创建的队列为: {}", QUEUE_INFORM_SAAS);
return queue;
} catch (Exception e) {
log.error("创建该: {} 队列失败", QUEUE_INFORM_SAAS, e);
throw e;
}
}
/**
* QUEUE_INFORM_EMAILroutingKey ROUTINGKEY_EMAIL
*
* @param queue QUEUE_INFORM_EMAIL
* @param exchange EXCHANGE_TOPICS_INFORM
*/
@Bean @Bean
public Binding bindingQueueInformEmail(@Qualifier(QUEUE_INFORM_EMAIL) Queue queue, public Binding bindingQueueInformEmail(@Qualifier(QUEUE_INFORM_EMAIL) Queue queue,
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) { @Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs(); return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();
} }
//ROUTINGKEY_SMS队列绑定交换机指定routingKey /**
* QUEUE_INFORM_SMS routingKey ROUTINGKEY_SMS
*
* @param queue QUEUE_INFORM_SMS
* @param exchange EXCHANGE_TOPICS_INFORM
*/
@Bean @Bean
public Binding bindingRoutingKeySms(@Qualifier(QUEUE_INFORM_SMS) Queue queue, public Binding bindingRoutingKeySms(@Qualifier(QUEUE_INFORM_SMS) Queue queue,
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) { @Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs(); return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
} }
/**
* QUEUE_INFORM_SENDroutingKey ROUTINGKEY_SEND
*
* @param queue QUEUE_INFORM_SEND
* @param exchange EXCHANGE_TOPICS_INFORM
*/
@Bean
public Binding bindingRoutingKeySend(@Qualifier(QUEUE_INFORM_SEND) Queue queue,
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SEND).noargs();
}
/**
* QUEUE_INFORM_SAASroutingKey ROUTINGKEY_SAAS
*
* @param queue QUEUE_INFORM_SAAS
* @param exchange EXCHANGE_TOPICS_INFORM
*/
@Bean
public Binding bindingRoutingKeySaas(@Qualifier(QUEUE_INFORM_SAAS) Queue queue,
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SAAS).noargs();
}
} }

View File

@ -13,12 +13,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-26-20:14 * @ Date2024-09-26-20:14
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Log4j2 @Log4j2
@RestController @RestController
@ -30,12 +30,13 @@ public class CarOneClickOperationController {
/** /**
* http * http
*
* @param vehicleConnectionReq * @param vehicleConnectionReq
* @return * @return
*/ */
@PostMapping("/receiveMsg/connect") @PostMapping("/receiveMsg/connect")
public Result<MqttServerModel> receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){ public Result<MqttServerModel> receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq) {
log.info(">"+vehicleConnectionReq); log.info("======================" + vehicleConnectionReq);
return carOneClickOperationService.getConnect(vehicleConnectionReq); return carOneClickOperationService.getConnect(vehicleConnectionReq);
} }

View File

@ -6,12 +6,12 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-30-9:33 * @ Date2024-09-30-9:33
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Data @Data
@Builder @Builder
@ -19,7 +19,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
public class AliInstance { public class AliInstance {
/** /**
*ID * ID
*/ */
private String instanceId; private String instanceId;
/** /**

View File

@ -5,12 +5,12 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-28-16:37 * @ Date2024-09-28-16:37
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor

View File

@ -5,12 +5,12 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-10-04-15:16 * @ Date2024-10-04-15:16
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor

View File

@ -1,93 +0,0 @@
package com.muyu.car.gateway.domain;
/**
*
*
* @author ruoyi
*/
public class HttpStatus {
/**
*
*/
public static final int SUCCESS = 200;
/**
*
*/
public static final int CREATED = 201;
/**
*
*/
public static final int ACCEPTED = 202;
/**
*
*/
public static final int NO_CONTENT = 204;
/**
*
*/
public static final int MOVED_PERM = 301;
/**
*
*/
public static final int SEE_OTHER = 303;
/**
*
*/
public static final int NOT_MODIFIED = 304;
/**
*
*/
public static final int BAD_REQUEST = 400;
/**
*
*/
public static final int UNAUTHORIZED = 401;
/**
* 访
*/
public static final int FORBIDDEN = 403;
/**
*
*/
public static final int NOT_FOUND = 404;
/**
* http
*/
public static final int BAD_METHOD = 405;
/**
*
*/
public static final int CONFLICT = 409;
/**
*
*/
public static final int UNSUPPORTED_TYPE = 415;
/**
*
*/
public static final int ERROR = 500;
/**
*
*/
public static final int NOT_IMPLEMENTED = 501;
/**
*
*/
public static final int WARN = 601;
}

View File

@ -9,23 +9,23 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-27-20:56 * @ Date2024-09-27-20:56
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Data @Data
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@TableName(value="server_config") @TableName(value = "server_config")
public class ServerConfig { public class ServerConfig {
/** /**
* *
*/ */
@TableId(value = "id",type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private Long id; private Long id;
/** /**
* id * id

View File

@ -5,12 +5,12 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-10-06-11:05 * @ Date2024-10-06-11:05
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor

View File

@ -5,12 +5,12 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-10-03-10:10 * @ Date2024-10-03-10:10
* @ Version1.0 * @ Version1.0
* @ Descriptionvin * @ Descriptionvin
* @author Lenovo
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor

View File

@ -6,12 +6,12 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-10-03-10:12 * @ Date2024-10-03-10:12
* @ Version1.0 * @ Version1.0
* @ DescriptionMqtt * @ DescriptionMqtt
* @author Lenovo
*/ */
@Data @Data
@Builder @Builder

View File

@ -6,12 +6,12 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-10-03-10:04 * @ Date2024-10-03-10:04
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Data @Data
@Builder @Builder

View File

@ -6,12 +6,12 @@ import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-26-15:53 * @ Date2024-09-26-15:53
* @ Version1.0 * @ Version1.0
* @ DescriptionAli * @ DescriptionAli
* @author Lenovo
*/ */
@Data @Data
@SuperBuilder @SuperBuilder

View File

@ -6,12 +6,12 @@ import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-26-20:15 * @ Date2024-09-26-20:15
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Mapper @Mapper
public interface CarOneClickOperationMapper { public interface CarOneClickOperationMapper {

View File

@ -5,17 +5,18 @@ import com.muyu.car.gateway.domain.req.VehicleConnectionReq;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-26-20:15 * @ Date2024-09-26-20:15
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
public interface CarOneClickOperationService { public interface CarOneClickOperationService {
/** /**
* *
*
* @param vehicleConnectionReq * @param vehicleConnectionReq
* @return * @return
*/ */

View File

@ -12,7 +12,6 @@ import com.muyu.common.redis.service.RedisService;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -22,12 +21,12 @@ import static com.muyu.car.gateway.config.RabbitmqConfig.EXCHANGE_TOPICS_INFORM;
import static com.muyu.car.gateway.config.RabbitmqConfig.ROUTINGKEY_SMS; import static com.muyu.car.gateway.config.RabbitmqConfig.ROUTINGKEY_SMS;
/** /**
* @author Lenovo
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
* @ AuthorCHX * @ AuthorCHX
* @ Date2024-09-26-20:16 * @ Date2024-09-26-20:16
* @ Version1.0 * @ Version1.0
* @ Description * @ Description
* @author Lenovo
*/ */
@Log4j2 @Log4j2
@Service @Service
@ -44,16 +43,13 @@ public class CarOneClickOperationServiceImpl implements CarOneClickOperationServ
/** /**
* *
*
* @param vehicleConnectionReq * @param vehicleConnectionReq
* @return * @return
*/ */
@Override @Override
public Result<MqttServerModel> getConnect(VehicleConnectionReq vehicleConnectionReq) { public Result<MqttServerModel> getConnect(VehicleConnectionReq vehicleConnectionReq) {
log.info("车辆连接请求:{}",vehicleConnectionReq.toString()); log.info("车辆连接请求:{}", vehicleConnectionReq.toString());
// // 使用交换机发送消息 给事件系统发
// rabbitTemplate.convertAndSend("exchange_topics_inform","inform.#.email.#",vehicleConnectionReq.getVehicleVin());
// log.info("发送消息成功:{}",vehicleConnectionReq.getVehicleVin());
VehicleConnection vehicleConnection = new VehicleConnection(); VehicleConnection vehicleConnection = new VehicleConnection();
//车辆vin //车辆vin
@ -61,23 +57,22 @@ public class CarOneClickOperationServiceImpl implements CarOneClickOperationServ
//用户名 //用户名
vehicleConnection.setUsername(vehicleConnectionReq.getUsername()); vehicleConnection.setUsername(vehicleConnectionReq.getUsername());
//密码(vin+时间戳+随机数) //密码(vin+时间戳+随机数)
vehicleConnection.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()+vehicleConnectionReq.getNonce()); vehicleConnection.setPassword(vehicleConnectionReq.getVehicleVin() + vehicleConnectionReq.getTimestamp() + vehicleConnectionReq.getNonce());
//查询有没有这辆车的vin码 //查询有没有这辆车的vin码
List<String> selectVehicle = carOneClickOperationMapper.selectByVehicleVin(vehicleConnectionReq.getVehicleVin()); List<String> selectVehicle = carOneClickOperationMapper.selectByVehicleVin(vehicleConnectionReq.getVehicleVin());
if(selectVehicle.isEmpty()){ if (selectVehicle.isEmpty()) {
//添加连接信息 //添加连接信息
carOneClickOperationMapper.addConnect(vehicleConnection); carOneClickOperationMapper.addConnect(vehicleConnection);
log.info("车辆上线成功"); log.info("车辆上线成功");
}else { } else {
throw new RuntimeException("车辆无法重复上线"); throw new RuntimeException("车辆无法重复上线");
} }
//先判断vin码 //先判断vin码
HashOperations<String, String, String> hashOps = redisTemplate.opsForHash(); if (redisService.hasKey(vehicleConnectionReq.getVehicleVin())) {
String vinIp = hashOps.get("oneVinIp", vehicleConnectionReq.getVehicleVin()); log.error("=============车辆:{}已经绑定过了", vehicleConnectionReq.getVehicleVin());
if(vinIp!=null){ throw new RuntimeException("=============车辆已经绑定过了");
throw new RuntimeException("车辆绑定ip失败已经存在");
} }
MqttProperties mqttProperties = new MqttProperties(); MqttProperties mqttProperties = new MqttProperties();
List<VehicleConnection> vehicleVin = selectByVehicleVin(vehicleConnectionReq.getVehicleVin()); List<VehicleConnection> vehicleVin = selectByVehicleVin(vehicleConnectionReq.getVehicleVin());
@ -89,43 +84,44 @@ public class CarOneClickOperationServiceImpl implements CarOneClickOperationServ
mqttProperties.setTopic("vehicle"); mqttProperties.setTopic("vehicle");
mqttProperties.setQos(0); mqttProperties.setQos(0);
//判断redis有没有count键 //判断redis有没有count键
if(redisTemplate.hasKey("oneCount")){ if (redisTemplate.hasKey("oneCount")) {
//取出count //取出count
Integer count = Integer.valueOf(redisTemplate.opsForValue().get("oneCount")); Integer count = Integer.valueOf(redisTemplate.opsForValue().get("oneCount"));
if(count == 1){ if (count == 1) {
redisTemplate.opsForValue().set("oneCount",String.valueOf(0)); redisTemplate.opsForValue().set("oneCount", String.valueOf(0));
}else { } else {
redisTemplate.opsForValue().set("oneCount",String.valueOf(count+1)); redisTemplate.opsForValue().set("oneCount", String.valueOf(count + 1));
} }
//根据游标count获取服务IP //根据游标count获取服务IP
// String ip = redisTemplate.opsForList().index("ipList", count); // String ip = redisTemplate.opsForList().index("ipList", count);
Object ipList = redisService.redisTemplate.opsForList().index("oneIpList", count); Object ipList = redisService.redisTemplate.opsForList().index("oneIpList", count);
log.info("=========================oneIpList:"+ipList); log.info("=========================oneIpList:" + ipList);
//关联车辆和服务 //关联车辆和服务
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(),ipList.toString())); this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(), ipList.toString()));
//响应信息 //响应信息
log.info("车辆:{}",vehicleConnectionReq.getVehicleVin()+"绑定成功:{}",ipList); log.info("车辆:{}", vehicleConnectionReq.getVehicleVin() + "绑定成功:{}", ipList);
mqttProperties.setBroker("tcp://"+ipList+":1883"); mqttProperties.setBroker("tcp://" + ipList + ":1883");
// 使用交换机发送消息 // 使用交换机发送消息
rabbitTemplate.convertAndSend(EXCHANGE_TOPICS_INFORM,ROUTINGKEY_SMS,mqttProperties); rabbitTemplate.convertAndSend(EXCHANGE_TOPICS_INFORM, ROUTINGKEY_SMS, mqttProperties);
log.info("============================发送消息成功:{}",mqttProperties); log.info("============================发送消息成功:{}", mqttProperties);
return Result.success(new MqttServerModel("tcp://"+ipList+":1883","vehicle")); return Result.success(new MqttServerModel("tcp://" + ipList + ":1883", "vehicle"));
}else { } else {
redisTemplate.opsForValue().set("oneCount",String.valueOf(0)); redisTemplate.opsForValue().set("oneCount", String.valueOf(0));
//根据游标count获取服务器Ip //根据游标count获取服务器Ip
Object ipList = redisService.redisTemplate.opsForList().index("oneIpList", 0); Object ipList = redisService.redisTemplate.opsForList().index("oneIpList", 0);
//关联车辆和服务 //关联车辆和服务
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(),ipList.toString())); this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(), ipList.toString()));
//响应信息 //响应信息
log.info("车辆:{}",vehicleConnectionReq.getVehicleVin(),"与:{}绑定成功",ipList); log.info("车辆:{}", vehicleConnectionReq.getVehicleVin(), "与:{}绑定成功", ipList);
mqttProperties.setBroker("tcp://"+ipList+":1883"); mqttProperties.setBroker("tcp://" + ipList + ":1883");
// 使用交换机发送消息 // 使用交换机发送消息
rabbitTemplate.convertAndSend(EXCHANGE_TOPICS_INFORM,ROUTINGKEY_SMS,mqttProperties); rabbitTemplate.convertAndSend(EXCHANGE_TOPICS_INFORM, ROUTINGKEY_SMS, mqttProperties);
log.info("============================发送消息成功:{}",mqttProperties); log.info("============================发送消息成功:{}", mqttProperties);
return Result.success(new MqttServerModel("tcp://"+ipList+":1883","vehicle")); return Result.success(new MqttServerModel("tcp://" + ipList + ":1883", "vehicle"));
} }
} }
/** /**
* IPredis * IPredis
*/ */
@ -133,11 +129,12 @@ public class CarOneClickOperationServiceImpl implements CarOneClickOperationServ
if (vinIp == null || vinIp.getVin() == null || vinIp.getVin().isEmpty() || vinIp.getIp() == null || vinIp.getIp().isEmpty()) { if (vinIp == null || vinIp.getVin() == null || vinIp.getVin().isEmpty() || vinIp.getIp() == null || vinIp.getIp().isEmpty()) {
throw new IllegalArgumentException("vin 或 ip 不能为空或无效"); throw new IllegalArgumentException("vin 或 ip 不能为空或无效");
} }
redisTemplate.opsForHash().put("oneVinIp", vinIp.getVin(), vinIp.getIp()); redisService.setCacheObject(vinIp.getVin(), vinIp.getIp());
} }
/** /**
* *
*
* @param vehicleVin vin * @param vehicleVin vin
* @return * @return
*/ */

View File

@ -1,6 +1,6 @@
# Tomcat # Tomcat
server: server:
port: 12900 port: 10099
# nacos线上地址 # nacos线上地址
nacos: nacos:

View File

@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.car.gateway.mapper.CarOneClickOperationMapper"> <mapper namespace="com.muyu.car.gateway.mapper.CarOneClickOperationMapper">
<insert id="addConnect"> <insert id="addConnect">
insert into car_one_click_operation insert into car_one_click_operation
(vehicle_vin,user_name,password) (vin, user_name, password)
values values (#{vehicleVin}, #{username}, #{password})
(#{vehicleVin},#{username},#{password})
</insert> </insert>
<select id="selectByVehicleVin" resultType="java.lang.String"> <select id="selectByVehicleVin" resultType="java.lang.String">
select vehicle_vin from car_one_click_operation where vehicle_vin = #{vehicleVin} select vin
from car_one_click_operation
where vin = #{vehicleVin}
</select> </select>
<select id="getMqttServerModel" resultType="com.muyu.car.gateway.domain.VehicleConnection"> <select id="getMqttServerModel" resultType="com.muyu.car.gateway.domain.VehicleConnection">
select select vin vehicleVin,
vehicle_vin,user_name,password user_name,
from password
car_one_click_operation from car_one_click_operation
where where vin = #{vehicleVin}
vehicle_vin = #{vehicleVin}
</select> </select>

View File

@ -76,7 +76,7 @@ public class WarnLogs {
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId()) .append("id", getId())
.append("vin", getVin()) .append("vin", getVehicleVin())
.append("warnRuleId", getWarnRuleId()) .append("warnRuleId", getWarnRuleId())
.append("startTime", getStartTime()) .append("startTime", getStartTime())
.append("endTime", getEndTime()) .append("endTime", getEndTime())