Browse Source

save the error message rather than throw one exception when the component related to the cmp_uuid in trade$goods does not exist

sunyj 8 years ago
parent
commit
8434c6718d
1 changed files with 15 additions and 3 deletions
  1. 15 3
      mall-search/init.sql

+ 15 - 3
mall-search/init.sql

@@ -284,9 +284,13 @@ CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_i` AFTER INSERT ON `trad
     declare v_data text default 'goId';
     declare v_priority int default 0;
 
-    if new.cmp_uuid then
+    if new.cmp_uuid is not null then
       set v_data='cmpId';
       select cmp_id into v_data_id from product$component where cmp_uuid=new.cmp_uuid;
+      if v_data_id is null then
+        set v_data=concat('cmp_uuid 没有关联的器件:', new.cmp_uuid);
+        set v_data_id=new.go_id;
+      end if;
     else
       set v_data_id=new.go_id;
     end if;
@@ -307,9 +311,13 @@ CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_u` AFTER UPDATE ON `trad
     declare v_data text default 'goId';
     declare v_priority int default 0;
 
-    if old.cmp_uuid then
+    if old.cmp_uuid is not null then
       set v_data='cmpId';
       select cmp_id into v_data_id from product$component where cmp_uuid=old.cmp_uuid;
+      if v_data_id is null then
+        set v_data=concat('cmp_uuid 没有关联的器件:', old.cmp_uuid);
+        set v_data_id=old.go_id;
+      end if;
     else
       set v_data_id=old.go_id;
     end if;
@@ -330,9 +338,13 @@ CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_d` AFTER DELETE ON `trad
     declare v_data text default 'goId';
     declare v_priority int default 0;
 
-    if old.cmp_uuid then
+    if old.cmp_uuid is not null then
       set v_data='cmpId';
       select cmp_id into v_data_id from product$component where cmp_uuid=old.cmp_uuid;
+      if v_data_id is null then
+        set v_data=concat('cmp_uuid 没有关联的器件:', old.cmp_uuid);
+        set v_data_id=old.go_id;
+      end if;
     else
       set v_data_id=old.go_id;
     end if;