小车上线

master
xiaohuang 2024-06-20 21:45:59 +08:00
parent 5dd0571824
commit 5b56363dde
14 changed files with 160 additions and 45 deletions

View File

@ -1,6 +1,6 @@
# Tomcat
server:
port: 9211
port: 9212
# Spring
spring:
rabbitmq:

View File

@ -17,6 +17,6 @@ import java.util.List;
public interface RemoteBusinessService {
@GetMapping("/entinfo/listAll")
@GetMapping("entinfo/listAll")
public List<Entinfo> listAll();
}

View File

@ -22,8 +22,6 @@ public class RemoteBusinessFallbackFactory implements FallbackFactory<RemoteBusi
public RemoteBusinessService create (Throwable throwable) {
log.error("用户服务调用失败:{}", throwable.getMessage());
return new RemoteBusinessService(){
@Override
public List<Entinfo> listAll() {
return null;

View File

@ -71,12 +71,6 @@
<groupId>com.muyu</groupId>
<artifactId>muyu-common-datasource</artifactId>
</dependency>
<!-- 企业依赖-->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-business</artifactId>
<version>3.6.3</version>
</dependency>
<!-- muyu Common DataScope -->
<dependency>
<groupId>com.muyu</groupId>

View File

@ -45,20 +45,7 @@ public class ManyDataSource {
@Autowired
private RemoteBusinessService remoteBusinessService;
// @Autowired
// private EntInfoFeign entInfoFeign;
// @PostConstruct
// public void init() {
// new Thread(() -> {
// try {
// Thread.sleep(10000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// }).start();
// }
//调用注解 添加队列名称
@RabbitListener(queuesToDeclare = {@Queue(name = "muyu-vehicle-exchange")})
@ -111,27 +98,6 @@ public class ManyDataSource {
}};
List<Entinfo> list = remoteBusinessService.listAll();
databaseNameList.addAll(list);
// List<String> entinfo = redisTemplate.opsForList().range("entinfo", 0, -1);
// entinfo.forEach(string -> {
// Entinfo entInfo = JSON.parseObject(String.valueOf(string), Entinfo.class);
// databaseNameList.add(entInfo);
// });
// List<Entinfo> entinfos = entInfoFeign.listAll();
// databaseNameList.addAll(entinfos);
// if(SecurityUtils.getLoginUser() == null){
// return databaseNameList;
// }else{
// Long storeId = SecurityUtils.getLoginUser().getUserid();
// SysUser sysUser = remoteUserService.selectByUserId(storeId);
// String s = redisService.getCacheObject(String.valueOf(sysUser.getUserType()));
// EntInfo entInfo = JSON.parseObject(s, EntInfo.class);
// databaseNameList.add(entInfo);
// return databaseNameList;
// }
return databaseNameList;
}

View File

@ -0,0 +1,10 @@
package com.muyu.vehicle.mapper;
/**
* FaultCodeMapper
*
* @author xiaohuang
* Date 2024/6/20 17:16
*/
public interface FaultCodeMapper {
}

View File

@ -0,0 +1,11 @@
package com.muyu.vehicle.mapper;
/**
* FaultRecordMapper
*
* @author xiaohuang
* Date 2024/6/20 17:17
*/
public interface FaultRecordMapper {
}

View File

@ -0,0 +1,95 @@
package com.muyu.vehicle.rabbitmq.producer;
import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* VehicleProducer
*
* @author xiaohuang
* Date 2024/6/20 15:56
*/
@Component
@Log4j2
public class VehicleProducer {
@Autowired
private RedisTemplate<String,String> redisTemplate;
//调用注解,添加队列名称
@RabbitListener(queuesToDeclare = {@Queue(name = "zhiLian-vehicle-start")})
public void smsConfigStart(String msg, Message message, Channel channel){
//获取消息的id
String messageId = message.getMessageProperties().getMessageId();
try {
Long count = redisTemplate.opsForSet().add("messageId", messageId);
if (count==1) {
log.info("开始消费:{}", msg);
//判断车辆属于哪个企业
//选择数据源,切换数据源
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
log.info("消费成功!数据源为:{}", message);
}
} catch (IOException e) {
log.info("消费失败");
try {
channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
log.info("回退成功");
} catch (IOException ex) {
log.info("回退失败");
}
throw new RuntimeException(e);
}
}
@RabbitListener(queuesToDeclare = {@Queue(name = "zhiLian-vehicle-ent")})
public void smsConfigEnt(String msg, Message message, Channel channel){
//获取消息的id
String messageId = message.getMessageProperties().getMessageId();
try {
//提那家消费id到redis set集合中,
Long count = redisTemplate.opsForSet().add("messageId", messageId);
//成功
if (count == 1 ) {
log.info("开始消费:{}", msg);
//确认消费
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
log.info("消费成功");
}
} catch (Exception e) {
//删除队列id
log.info("消费失败");
try {
channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
log.info("消费失败");
}catch (IOException ex){
log.info("消费异常");
}
}
}
}

View File

@ -0,0 +1,10 @@
package com.muyu.vehicle.service;
/**
* FaultCodeService
*
* @author xiaohuang
* Date 2024/6/20 17:12
*/
public interface FaultCodeService {
}

View File

@ -0,0 +1,10 @@
package com.muyu.vehicle.service;
/**
* FaultRecordService
*
* @author xiaohuang
* Date 2024/6/20 17:12
*/
public interface FaultRecordService {
}

View File

@ -0,0 +1,10 @@
package com.muyu.vehicle.service.impl;
/**
* FaultCodeServicelmpl
*
* @author xiaohuang
* Date 2024/6/20 17:13
*/
public class FaultCodeServicelmpl {
}

View File

@ -0,0 +1,10 @@
package com.muyu.vehicle.service.impl;
/**
* FaultRecordServicelmpl
*
* @author xiaohuang
* Date 2024/6/20 17:15
*/
public class FaultRecordServicelmpl {
}

View File

@ -1,6 +1,6 @@
# Tomcat
server:
port: 9212
port: 9213
# Spring
spring:

View File

@ -225,6 +225,7 @@
<module>muyu-iotdb</module>
<module>muyu-vehicle</module>
<module>muyu-cloud-datasource</module>
</modules>
<packaging>pom</packaging>