Browse Source

Merge branch 'develop/v0.0.1' of http://git.kdan.cc:8865/Server_Service/java_compdf_background into develop/v0.0.1

wangPH 2 years ago
parent
commit
05d0fa269a

+ 38 - 10
background-user/src/main/java/cn/kdan/compdf/config/RabbitConfig.java

@@ -5,6 +5,9 @@ import org.springframework.amqp.core.Binding;
 import org.springframework.amqp.core.BindingBuilder;
 import org.springframework.amqp.core.Queue;
 import org.springframework.amqp.core.TopicExchange;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -15,6 +18,20 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 public class RabbitConfig {
 
+    /**
+     * 设置启动自动创建队列
+     * @param connectionFactory
+     * @return
+     */
+    @Bean
+    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
+        RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
+        rabbitAdmin.setAutoStartup(true);
+        return rabbitAdmin;
+    }
+    @Autowired
+    private RabbitAdmin rabbitAdmin;
+
     /**
      *  topics 交换机
      */
@@ -24,12 +41,14 @@ public class RabbitConfig {
         // 参数2:  消息是否持久
         // 参数3:  是否自动删除
         // 参数4:  其他配置
-        return new TopicExchange(RabbitMQEnum.BACKGROUND_EXCHANGE,true,false,null);
+        TopicExchange topicExchange = new TopicExchange(RabbitMQEnum.BACKGROUND_EXCHANGE, true, false, null);
+        rabbitAdmin.declareExchange(topicExchange);
+        return topicExchange;
     }
 
 
     /**
-     * API新队列
+     * API新队列
      */
     @Bean
     public Queue getAPIAddQueue(){
@@ -38,36 +57,45 @@ public class RabbitConfig {
         // 参数3: 这个队列是否让消费者多占
         // 参数4: 这个队列是否自动删除
         // 参数5:  这个队列的其他参数
-        return new Queue(RabbitMQEnum.BACKGROUND_API_ADD_QUEUE,true,false,false,null);
+        Queue queue = new Queue(RabbitMQEnum.BACKGROUND_API_ADD_QUEUE, true, false, false, null);
+        rabbitAdmin.declareQueue(queue);
+        return queue;
     }
     /**
      * API删除队列
      */
     @Bean
     public Queue getAPIDelQueue(){
-
-        return new Queue(RabbitMQEnum.BACKGROUND_API_DEL_QUEUE,true,false,false,null);
+        Queue queue = new Queue(RabbitMQEnum.BACKGROUND_API_DEL_QUEUE, true, false, false, null);
+        rabbitAdmin.declareQueue(queue);
+        return queue;
     }
     /**
-     * webhooks新队列
+     * webhooks新队列
      */
     @Bean
     public Queue getWebhooksAddQueue(){
-        return new Queue(RabbitMQEnum.BACKGROUND_WEBHOOKS_ADD_QUEUE,true,false,false,null);
+        Queue queue = new Queue(RabbitMQEnum.BACKGROUND_WEBHOOKS_ADD_QUEUE, true, false, false, null);
+        rabbitAdmin.declareQueue(queue);
+        return queue;
     }
     /**
      * webhooks删除队列
      */
     @Bean
     public Queue getWebhooksDelQueue(){
-        return new Queue(RabbitMQEnum.BACKGROUND_WEBHOOKS_DEL_QUEUE,true,false,false,null);
+        Queue queue = new Queue(RabbitMQEnum.BACKGROUND_WEBHOOKS_DEL_QUEUE, true, false, false, null);
+        rabbitAdmin.declareQueue(queue);
+        return queue;
     }
     /**
-     * webhooks删除队列
+     * webhooks编辑队列
      */
     @Bean
     public Queue getWebhooksUpdQueue(){
-        return new Queue(RabbitMQEnum.BACKGROUND_WEBHOOKS_UPD_QUEUE,true,false,false,null);
+        Queue queue = new Queue(RabbitMQEnum.BACKGROUND_WEBHOOKS_UPD_QUEUE, true, false, false, null);
+        rabbitAdmin.declareQueue(queue);
+        return queue;
     }
 
 

+ 0 - 20
background-user/src/main/java/cn/kdan/compdf/service/impl/BackgroundUserWebhookServiceImpl.java

@@ -145,16 +145,6 @@ public class BackgroundUserWebhookServiceImpl extends ServiceImpl<BackgroundUser
      */
     @Override
     public void addNewWebhook(AddNewWebhookDTO addNewWebhookDTO) {
-        // 参数校验
-        LambdaQueryWrapper<BackgroundUserProject> eq = new LambdaQueryWrapper<BackgroundUserProject>()
-                .eq(BackgroundUserProject::getUserId, addNewWebhookDTO.getUserId())
-                .eq(BackgroundUserProject::getId, addNewWebhookDTO.getProjectId());
-        BackgroundUserProject backgroundUserProject = backgroundUserProjectService.getOne(eq);
-        if (null == backgroundUserProject) {
-            log.error("新增webhook项目id错误:" + addNewWebhookDTO.getProjectId());
-            throw new BusinessException("parameter error");
-        }
-
         BackgroundUserWebhook backgroundUserWebhook = new BackgroundUserWebhook();
         BeanUtil.copyProperties(addNewWebhookDTO, backgroundUserWebhook);
         // 设置回调token
@@ -181,16 +171,6 @@ public class BackgroundUserWebhookServiceImpl extends ServiceImpl<BackgroundUser
 
     @Override
     public void editWebhook(EditWebhookDTO editWebhookDTO) {
-        // 参数校验
-        LambdaQueryWrapper<BackgroundUserProject> eq = new LambdaQueryWrapper<BackgroundUserProject>()
-                .eq(BackgroundUserProject::getUserId, editWebhookDTO.getUserId())
-                .eq(BackgroundUserProject::getId, editWebhookDTO.getProjectId());
-        BackgroundUserProject backgroundUserProject = backgroundUserProjectService.getOne(eq);
-        if (null == backgroundUserProject) {
-            log.error("编辑webhook项目id错误:" + editWebhookDTO.getProjectId());
-            throw new BusinessException("parameter error");
-        }
-
         BackgroundUserWebhook backgroundUserWebhook = new BackgroundUserWebhook();
         BeanUtil.copyProperties(editWebhookDTO, backgroundUserWebhook);
         this.baseMapper.updateById(backgroundUserWebhook);