diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/CoupletBusinessApplication.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/CoupletBusinessApplication.java index b4888a4..4fc051b 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/CoupletBusinessApplication.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/CoupletBusinessApplication.java @@ -15,7 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; @EnableCustomConfig @EnableCustomSwagger2 @EnableMyFeignClients(basePackages = ("com.couplet")) -@SpringBootApplication(scanBasePackages = {"com.couplet", "com.couplet.mq.remote","com.couplet.business.server.time"}) +@SpringBootApplication(scanBasePackages = {"com.couplet", "com.couplet.mq.remote"}) @EnableScheduling public class CoupletBusinessApplication { public static void main(String[] args) { 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 7968448..06fcf6a 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,6 +16,7 @@ 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 lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -36,6 +37,10 @@ public class VehicleServiceImpl extends ServiceImpl impl @Autowired private VehicleMapper vehicleMapper; + //远程发送mq + @Autowired + private RemoteFenceService remoteFenceService; + //车辆类型服务 @Autowired private VehicleTypeService vehicleTypeService; @@ -166,6 +171,19 @@ 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); + } + + result = "编辑成功!"; return result; @@ -234,6 +252,17 @@ 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); + } + + result = "新增成功!"; return result; @@ -256,7 +285,7 @@ public class VehicleServiceImpl extends ServiceImpl impl /* * @param userId: - * @return List + * @return List * @author 付凡芮 * @description 根据登入人id查询管理车辆 * @@ -304,4 +333,5 @@ public class VehicleServiceImpl extends ServiceImpl impl return this.list(queryWrapper); } + } 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 index 6c2c991..c2c3925 100644 --- 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 @@ -28,6 +28,11 @@ public class Timer { private VehicleService vehicleService; + @Scheduled(cron = "0/1 * * * * *") + public void aa() { + System.out.println("********************************************************"); + } + //判断车辆是否下线 @Scheduled(cron = "0/1 * * * * *") public void downLine() { diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java index f203824..5e789ec 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java @@ -27,15 +27,18 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem @Value("queueName") public String queueName; //队列名 - public static final String finByVinQueueName="finByVinQueueName"; - public static final String FENCE_QUEUE ="fenceQueue"; + public static final String finByVinQueueName = "finByVinQueueName"; + public static final String FENCE_QUEUE = "fenceQueue"; + public static final String vehicleQueue = "vehicleQueue"; //交换机 - public static final String VinExchangeName="vinExchangeName"; - public static final String FENCE_EXCHANGE="fenceExchange"; + public static final String VinExchangeName = "vinExchangeName"; + public static final String FENCE_EXCHANGE = "fenceExchange"; + public static final String vehicleQueueExchange = "vehicleQueueExchange"; //路由键 - public static final String VinRoutingKey="vinRoutingKey"; - public static final String FENCE_ROUTINGKEY="fenceRoutingKey"; + public static final String VinRoutingKey = "vinRoutingKey"; + public static final String FENCE_ROUTINGKEY = "fenceRoutingKey"; + public static final String VehicleQueue_ROUTINGKEY = "VehicleQueueRoutingKey"; //队列名 @@ -74,15 +77,23 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem public Queue queue() { return new Queue(queueName, true); } + @Bean("fenceQueue") public Queue queue2() { return new Queue(FENCE_QUEUE, true); } + @Bean("finByVinQueueName") public Queue finByVinQueueName() { return new Queue(finByVinQueueName, true); } + //当增删改车辆的时候,发送当前车辆的id到"vehicleQueue"队列 + @Bean("vehicleQueue") + public Queue vehicleQueue() { + return new Queue("vehicleQueue", true); + } + /* * @Author: LiuYunHu * @Date: 2024/3/29 21:26 @@ -100,11 +111,16 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem return new DirectExchange(FENCE_EXCHANGE); } - @Bean("vinExchangeName") + @Bean("vinExchangeName") public DirectExchange vinExchangeName() { return new DirectExchange(VinExchangeName); } + @Bean("vehicleQueueExchange") + public DirectExchange vehicleQueueExchange() { + return new DirectExchange("vehicleQueueExchange"); + } + /* * @Author: LiuYunHu @@ -152,11 +168,17 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem public Binding binding2() { return BindingBuilder.bind(queue2()).to(directExchange2()).with(FENCE_ROUTINGKEY); } + @Bean("vinRoutingKey") public Binding binding3() { return BindingBuilder.bind(finByVinQueueName()).to(vinExchangeName()).with(VinRoutingKey); } + @Bean("VehicleQueueRoutingKey") + public Binding binding4() { + return BindingBuilder.bind(vehicleQueue()).to(vehicleQueueExchange()).with(VehicleQueue_ROUTINGKEY); + } + /* * @Author: LiuYunHu * @Date: 2024/3/29 21:28 diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java index d7be058..f1921d2 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java @@ -90,4 +90,13 @@ public class MqController { }, new CorrelationData(IdUtils.randomUUID()) ); } + + @GetMapping("/vehicleQueue/{msg}") + public void vehicleQueue(@PathVariable("msg") String msg){ + rabbitTemplate.convertAndSend(RabbitMQConfig.vehicleQueueExchange, RabbitMQConfig.VehicleQueue_ROUTINGKEY, msg, message -> { + message.getMessageProperties().setMessageId(IdUtils.randomUUID()); + return message; + }, new CorrelationData(IdUtils.randomUUID()) + ); + } } diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/remote/RemoteFenceService.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/remote/RemoteFenceService.java index 38f0c95..57e9ce1 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/remote/RemoteFenceService.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/remote/RemoteFenceService.java @@ -4,6 +4,8 @@ import com.couplet.common.core.constant.ServiceNameConstants; import com.couplet.common.domain.request.FenceUpdateRequest; import com.couplet.mq.remote.factory.RemoteFenceFallbackFactory; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -16,4 +18,7 @@ public interface RemoteFenceService { @PostMapping("/mq/fenceQueue") public void fenceQueue(@RequestBody FenceUpdateRequest teRequest); + + @GetMapping("/mq/vehicleQueue/{msg}") + public void vehicleQueue(@PathVariable("msg") String msg); } diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/remote/factory/RemoteFenceFallbackFactory.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/remote/factory/RemoteFenceFallbackFactory.java index 24d5e0b..4db267a 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/remote/factory/RemoteFenceFallbackFactory.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/remote/factory/RemoteFenceFallbackFactory.java @@ -25,6 +25,11 @@ public class RemoteFenceFallbackFactory implements FallbackFactory