diff --git a/couplet-auth/src/main/resources/bootstrap.yml b/couplet-auth/src/main/resources/bootstrap.yml index 427f682..68c3c25 100644 --- a/couplet-auth/src/main/resources/bootstrap.yml +++ b/couplet-auth/src/main/resources/bootstrap.yml @@ -17,9 +17,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 # 共享配置 diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java index 8f1a275..ec9a53a 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java @@ -4,7 +4,9 @@ import com.couplet.common.core.constant.ServiceNameConstants; import com.couplet.common.core.domain.Result; import com.couplet.common.domain.Vehicle; import com.couplet.common.domain.VehicleMiddle; +import com.couplet.common.domain.request.VehicleListParams; import com.couplet.remote.factory.RemoteVehicleFallbackFactory; +import lombok.extern.java.Log; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; @@ -62,4 +64,7 @@ public interface RemoteVehicleService { @PostMapping("/vehicleAndLogo/queryByLogoIds/{vehicleId}") public Result> queryByLogoIds(@PathVariable("vehicleId") Long vehicleId); + @PostMapping("/list") + public Result list(@RequestBody VehicleListParams listParams); + } diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteVehicleFallbackFactory.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteVehicleFallbackFactory.java index 34ed01e..1cda3b4 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteVehicleFallbackFactory.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteVehicleFallbackFactory.java @@ -3,6 +3,7 @@ package com.couplet.remote.factory; import com.couplet.common.core.domain.Result; import com.couplet.common.domain.Vehicle; import com.couplet.common.domain.VehicleMiddle; +import com.couplet.common.domain.request.VehicleListParams; import com.couplet.remote.RemoteVehicleService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,6 +62,11 @@ public class RemoteVehicleFallbackFactory implements FallbackFactory> queryByLogoIds(Long vehicleId) { return Result.error("车辆服务调用失败:"+cause.getMessage()); } + + @Override + public Result list(VehicleListParams listParams) { + return Result.error("车辆服务调用失败:"+cause.getMessage()); + } }; } } diff --git a/couplet-gateway/src/main/resources/bootstrap.yml b/couplet-gateway/src/main/resources/bootstrap.yml index 091e68a..6dc39fe 100644 --- a/couplet-gateway/src/main/resources/bootstrap.yml +++ b/couplet-gateway/src/main/resources/bootstrap.yml @@ -15,9 +15,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 # 共享配置 diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java index 06fcf6a..5dd54a5 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java @@ -16,9 +16,10 @@ import com.couplet.common.domain.VehicleType; import com.couplet.common.domain.request.VehicleEditParams; import com.couplet.common.domain.request.VehicleInsertParams; import com.couplet.common.domain.request.VehicleListParams; -import com.couplet.mq.remote.RemoteFenceService; +import com.couplet.common.redis.service.RedisService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.util.List; @@ -36,10 +37,12 @@ public class VehicleServiceImpl extends ServiceImpl impl //车辆mapper @Autowired private VehicleMapper vehicleMapper; + @Autowired + private RedisService redis; //远程发送mq - @Autowired - private RemoteFenceService remoteFenceService; +// @Autowired +// private RemoteFenceService remoteFenceService; //车辆类型服务 @Autowired @@ -133,7 +136,7 @@ public class VehicleServiceImpl extends ServiceImpl impl String result = ""; if ((editParams.getLogoIds() == null || editParams.getLogoIds().isEmpty())) { - result = "未选择电子围栏"; + result = "未选择标识"; Result.error(result); } @@ -172,16 +175,16 @@ public class VehicleServiceImpl extends ServiceImpl impl vehicleAndLogoService.vehicleBindLogo(editParams.getVehicleId(), editParams.getLogoIds()); - //mq - List logoList = getBindLogoById(editParams.getVehicleId()); - if (0 != logoList.size()) { - String ids = ""; - for (Long l : logoList) { - ids = "," + l; - } - ids = ids.substring(1); - remoteFenceService.vehicleQueue(editParams.getVehicleId() + "-" + ids); - } +// //mq +// List logoList = getBindLogoById(editParams.getVehicleId()); +// if (0 != logoList.size()) { +// String ids = ""; +// for (Long l : logoList) { +// ids = "," + l; +// } +// ids = ids.substring(1); +// remoteFenceService.vehicleQueue(editParams.getVehicleId() + "-" + ids); +// } result = "编辑成功!"; @@ -201,7 +204,7 @@ public class VehicleServiceImpl extends ServiceImpl impl String result = ""; if ((insertParams.getLogoIds() == null || insertParams.getLogoIds().isEmpty())) { - result = "未选择电子围栏"; + result = "未选择标识"; Result.error(result); } @@ -251,16 +254,16 @@ public class VehicleServiceImpl extends ServiceImpl impl //执行添加电子围栏 int i = vehicleAndLogoService.vehicleBindLogo(vehicle.getVehicleId(), insertParams.getLogoIds()); - - List logoList = getBindLogoById(vehicle.getVehicleId()); - if (0 != logoList.size()) { - String ids = ""; - for (Long l : logoList) { - ids = "," + l; - } - ids = ids.substring(1); - remoteFenceService.vehicleQueue(vehicle.getVehicleId() + "-" + ids); - } +// +// List logoList = getBindLogoById(vehicle.getVehicleId()); +// if (0 != logoList.size()) { +// String ids = ""; +// for (Long l : logoList) { +// ids = "," + l; +// } +// ids = ids.substring(1); +// remoteFenceService.vehicleQueue(vehicle.getVehicleId() + "-" + ids); +// } result = "新增成功!"; @@ -334,4 +337,46 @@ public class VehicleServiceImpl extends ServiceImpl impl } + + @Scheduled(cron = "0/1 * * * * *") + public void aa() { + System.out.println("********************************************************"); + } + + //判断车辆是否下线 + @Scheduled(cron = "0/1 * * * * *") + public void downLine() { + log.info("定时器启动"); + //先查询车辆列表 + List list = this.list(new VehicleListParams(null, null, null, null)); + + + list.forEach(vehicle -> { + try { + //只针对已经上线的车辆 + if (redis.hasKey(vehicle.getVin())) { + + //如果vin的缓存 时间还剩一秒,则判断为已经下线 + if (redis.getExpire(vehicle.getVin()) <= 3) { + log.info(vehicle.getVin() + "的车辆已经下线"); + + //执行修改下线状态的方法 +// Integer i = this.onOrOutLineByVIN(vehicle.getVin() + "," + 0); + Integer i = this.onOrOutLineByVIN(vehicle.getVin() , 0); + + if (0 == i) { + log.error("下线状态修改失败"); + } else { + log.info("下线状态修改成功"); + } + + } + } + } catch (Exception e) { + log.error(e.getMessage()); + } + }); + + } + } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/time/Timer.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/time/Timer.java deleted file mode 100644 index c2c3925..0000000 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/time/Timer.java +++ /dev/null @@ -1,72 +0,0 @@ -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 lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @ProjectName: five-groups-couplet - * @Author: LiuYunHu - * @CreateTime: 2024/4/4 - * @Description: 车辆定时器 - */ -@Component -@Slf4j -public class Timer { - //redis - @Autowired - private StringRedisTemplate redis; - //查询车辆列表 - @Autowired - private VehicleService vehicleService; - - - @Scheduled(cron = "0/1 * * * * *") - public void aa() { - System.out.println("********************************************************"); - } - - //判断车辆是否下线 - @Scheduled(cron = "0/1 * * * * *") - public void downLine() { - log.info("定时器启动"); - - //先查询车辆列表 - List list = vehicleService.list(new VehicleListParams(null, null, null, null)); - - - list.forEach(vehicle -> { - try { - //只针对已经上线的车辆 - if (redis.hasKey(vehicle.getVin())) { - - //如果vin的缓存 时间还剩一秒,则判断为已经下线 - if (redis.getExpire(vehicle.getVin()) <= 3) { - log.info(vehicle.getVin() + "的车辆已经下线"); - - //执行修改下线状态的方法 - Integer i = vehicleService.onOrOutLineByVIN(vehicle.getVin(), 0); - - if (0 == i) { - log.error("下线状态修改失败"); - } else { - log.info("下线状态修改成功"); - } - - } - } - } catch (Exception e) { - log.error(e.getMessage()); - } - }); - - } - -} diff --git a/couplet-modules/couplet-system/src/main/resources/bootstrap.yml b/couplet-modules/couplet-system/src/main/resources/bootstrap.yml index d9315bd..91453d0 100644 --- a/couplet-modules/couplet-system/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-system/src/main/resources/bootstrap.yml @@ -15,9 +15,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 # 共享配置