server_five_liuyunhu
liuyunhu 2024-04-07 11:06:13 +08:00
parent e5c4c0b9a4
commit 0774e29edd
7 changed files with 29 additions and 22 deletions

View File

@ -1,2 +1,2 @@
com.couplet.remote.factory.RemoteVehicleFallbackFactory
com.couplet.remote.factory.RemoteVehicleFallbackFactory
com.couplet.remote.factory.RemoteTroubleFallbackFactory

View File

@ -15,10 +15,10 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableCustomConfig
@EnableCustomSwagger2
@EnableMyFeignClients(basePackages = ("com.couplet"))
@SpringBootApplication(scanBasePackages = {"com.couplet"})
@SpringBootApplication(scanBasePackages = {"com.couplet", "com.couplet.mq.remote","com.couplet.business.server.time"})
@EnableScheduling
public class CoupletBusinessApplication {
public static void main (String[] args) {
public static void main(String[] args) {
SpringApplication.run(CoupletBusinessApplication.class, args);
}

View File

@ -3,7 +3,6 @@ package com.couplet.business.server.time;
import com.couplet.business.server.service.VehicleService;
import com.couplet.common.domain.Vehicle;
import com.couplet.common.domain.request.VehicleListParams;
import com.couplet.common.redis.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
@ -30,31 +29,38 @@ public class Timer {
//判断车辆是否下线
@Scheduled(cron = "* * * * * *")
public void outLine() {
@Scheduled(cron = "0/1 * * * * *")
public void downLine() {
log.info("定时器启动");
//先查询车辆列表
List<Vehicle> list = vehicleService.list(new VehicleListParams(null, null, null, null));
for (Vehicle vehicle : list) {
//只针对已经上线的车辆
if (redis.hasKey(vehicle.getVin())) {
//如果vin的缓存 时间还剩一秒,则判断为已经下线
if (redis.getExpire(vehicle.getVin()) <= 3) {
log.info(vehicle.getVin() + "的车辆已经下线");
//执行修改下线状态的方法
Integer i = vehicleService.onOrOutLineByVIN(vehicle.getVin(), 0);
list.forEach(vehicle -> {
try {
//只针对已经上线的车辆
if (redis.hasKey(vehicle.getVin())) {
// if (0 == 1) {
// log.error("下线状态修改失败");
// }
//如果vin的缓存 时间还剩一秒,则判断为已经下线
if (redis.getExpire(vehicle.getVin()) <= 3) {
log.info(vehicle.getVin() + "的车辆已经下线");
log.info("下线状态修改成功");
//执行修改下线状态的方法
Integer i = vehicleService.onOrOutLineByVIN(vehicle.getVin(), 0);
if (0 == i) {
log.error("下线状态修改失败");
} else {
log.info("下线状态修改成功");
}
}
}
} catch (Exception e) {
log.error(e.getMessage());
}
}
});
}

View File

@ -16,9 +16,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -187,7 +187,7 @@ public class MqttMonitor {
//如果不存在这个车
if (0 == vehicles.size()) {
if (0 == vehicles.size() || null == vehicles) {
//将不属于自己系统的车辆存入缓存,便于提前进行拒绝提示
// redis.setCacheObject("不存在的车辆VIN" + start17, start17);
log.error("未找到vin码为" + start17 + "的车辆信息");

View File

@ -36,7 +36,7 @@ mqtt:
# broker: mqtt://115.159.47.13:1883
username:
password:
clientId: fluxmq
clientId: fluxMq
qos: 0
topic: test