Pārlūkot izejas kodu

处理排菜监听数据cate为0报空指针的问题

王先生 2 gadi atpakaļ
vecāks
revīzija
256a8d8067

+ 7 - 1
eladmin-system/src/main/java/me/zhengjie/config/rabbitmq/test/ListenerTemplate.java

@@ -2,11 +2,13 @@ package me.zhengjie.config.rabbitmq.test;
 
 import cn.hutool.core.lang.Snowflake;
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alipay.api.domain.OrderItem;
+import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.config.rabbitmq.cuisine.CuisineProduce;
 import me.zhengjie.config.rabbitmq.order.OrderProduce;
 import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
@@ -33,6 +35,7 @@ import java.sql.Timestamp;
 import java.util.UUID;
 
 @Component
+@Slf4j
 public class ListenerTemplate {
     @Autowired
     DmDayPcRepository dmDayPcRepository;
@@ -70,6 +73,9 @@ public class ListenerTemplate {
                 dmDayPc.setState(attendance.getString("state"));
                 dmDayPc.setName(attendance.getString("name"));
                 DmFoodCate cate = dmFoodCateRepository.findByCateId(attendance.getInteger("cate"));
+                if (ObjectUtil.isNull(cate)){
+                    continue;
+                }
                 cate.setCateId(attendance.getInteger("cate"));
                 dmDayPc.setCate(cate);
                 dmDayPc.setPid(attendance.getLong("pid"));
@@ -96,7 +102,7 @@ public class ListenerTemplate {
                 dmFoodRepository.save(dmFood);
             }
         }catch (Exception ex){
-            ex.printStackTrace();
+            log.error("订阅信息失败错误原因:{}", ex.getMessage());
         }
     }