-- 创建消息表
drop table if exists lucene$message;
create table lucene$message(
    me_id bigint not null primary key auto_increment,
    me_table_name varchar(64) not null,
    me_method_type varchar(6) not null,
    me_data_id int not null,
    me_data text,
    me_priority int default 0,
    me_retry_count int default 0,
    me_create_time datetime not null
);

-- 创建消息历史表
drop table if exists lucene$message_history;
create table lucene$message_history(
    mh_id bigint not null primary key auto_increment,
    mh_dequeue_time datetime not null,
    me_id bigint not null,
    me_table_name varchar(64) not null,
    me_method_type varchar(6) not null,
    me_data_id int not null,
    me_data text,
    me_priority int default 0,
    me_create_time datetime not null
);

-- 创建存储过程 入队消息
drop procedure if exists enqueue_lucene_message;
delimiter $$
create procedure enqueue_lucene_message(in v_table_name varchar(64), v_method_type varchar(6), v_data_id int, v_data text, v_priority int)
begin
	insert into lucene$message (me_table_name, me_method_type, me_data_id, me_data, me_priority, me_create_time) values(v_table_name, v_method_type, v_data_id, v_data, v_priority, sysdate());
end;$$
delimiter ;

-- 创建存储过程 出队消息
drop procedure if exists dequeue_lucene_message;
delimiter $$
create procedure dequeue_lucene_message(in v_id bigint)
begin
	insert into lucene$message_history (mh_dequeue_time, me_id, me_table_name, me_method_type, me_data_id, me_data, me_priority, me_create_time) select sysdate(), me_id, me_table_name, me_method_type, me_data_id, me_data, me_priority, me_create_time from lucene$message where me_id = v_id;
	delete from lucene$message where me_id = v_id;
end;$$
delimiter ;

-- ----------------------------
-- Triggers structure for table product$brand
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_brand_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_brand_i` AFTER INSERT ON `product$brand` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$brand';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.br_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$brand
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_brand_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_brand_u` AFTER UPDATE ON `product$brand` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$brand';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.br_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$brand
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_brand_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_brand_d` AFTER DELETE ON `product$brand` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$brand';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.br_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$component
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_component_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_component_i` AFTER INSERT ON `product$component` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=new.cmp_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='v$product$cmpgoods';
    set v_data='cmpId';
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$component
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_component_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_component_u` AFTER UPDATE ON `product$component` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=old.cmp_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='v$product$cmpgoods';
    set v_data='cmpId';
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$component
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_component_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_component_d` AFTER DELETE ON `product$component` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=old.cmp_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='v$product$cmpgoods';
    set v_data='cmpId';
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$kind
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_kind_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_kind_i` AFTER INSERT ON `product$kind` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$kind';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.ki_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$kind
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_kind_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_kind_u` AFTER UPDATE ON `product$kind` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$kind';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.ki_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$kind
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_kind_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_kind_d` AFTER DELETE ON `product$kind` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$kind';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.ki_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$propertyvalue
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_propertyvalue_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_propertyvalue_i` AFTER INSERT ON `product$propertyvalue` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=new.pv_componentid;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$propertyvalue
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_propertyvalue_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_propertyvalue_u` AFTER UPDATE ON `product$propertyvalue` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=old.pv_componentid;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$propertyvalue
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_propertyvalue_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_propertyvalue_d` AFTER DELETE ON `product$propertyvalue` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=old.pv_componentid;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$pcb
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_pcb_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_pcb_i` AFTER INSERT ON `product$pcb` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'pcb_goods';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default 'pcbId';
    declare v_priority int default 0;

    set v_data_id=new.pcb_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$pcb
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_pcb_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_pcb_u` AFTER UPDATE ON `product$pcb` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'pcb_goods';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default 'pcbId';
    declare v_priority int default 0;

    set v_data_id=old.pcb_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;
-- ----------------------------
-- Triggers structure for table product$pcb
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_pcb_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_pcb_d` AFTER DELETE ON `product$pcb` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'pcb_goods';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default 'pcbId';
    declare v_priority int default 0;

    set v_data_id=old.pcb_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$goods
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_trade_goods_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_i` AFTER INSERT ON `trade$goods` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$cmpgoods';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default 'goId';
    declare v_priority int default 1;

    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;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='pcb_goods';
    if new.go_productid is not null then
      set v_data='pcbId';
      set v_data_id = null;
      select pcb_id into v_data_id from product$pcb where pcb_productid=new.go_productid;
      if v_data_id is null then
        set v_data=concat('go_productid 没有关联的 PCB：', new.go_productid);
        set v_data_id=new.go_id;
      end if;
    else
      set v_data_id=new.go_id;
    end if;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$goods
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_trade_goods_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_u` AFTER UPDATE ON `trade$goods` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$cmpgoods';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default 'goId';
    declare v_priority int default 0;

    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;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='pcb_goods';
    if old.go_productid is not null then
      set v_data='pcbId';
      set v_data_id = null;
      select pcb_id into v_data_id from product$pcb where pcb_productid=old.go_productid;
      if v_data_id is null then
        set v_data=concat('go_productid 没有关联的 PCB：', old.go_productid);
        set v_data_id=old.go_id;
      end if;
    else
      set v_data_id=old.go_id;
    end if;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$goods
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_trade_goods_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_d` AFTER DELETE ON `trade$goods` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$cmpgoods';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default 'goId';
    declare v_priority int default 0;

    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;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='pcb_goods';
    if old.go_productid is not null then
      set v_data='pcbId';
      set v_data_id = null;
      select pcb_id into v_data_id from product$pcb where pcb_productid=old.go_productid;
      if v_data_id is null then
        set v_data=concat('go_productid 没有关联的 PCB：', old.go_productid);
        set v_data_id=old.go_id;
      end if;
    else
      set v_data_id=old.go_id;
    end if;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_i` AFTER INSERT ON `trade$invoice_fmor` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_u` AFTER UPDATE ON `trade$invoice_fmor` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_d` AFTER DELETE ON `trade$invoice_fmor` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_dt_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_dt_i` AFTER INSERT ON `trade$invoice_fmor_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_dt_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_dt_u` AFTER UPDATE ON `trade$invoice_fmor_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_dt_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_dt_d` AFTER DELETE ON `trade$invoice_fmor_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_i` AFTER INSERT ON `trade$invoice_fmpu` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_u` AFTER UPDATE ON `trade$invoice_fmpu` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_d` AFTER DELETE ON `trade$invoice_fmpu` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_dt_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_dt_i` AFTER INSERT ON `trade$invoice_fmpu_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_dt_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_dt_u` AFTER UPDATE ON `trade$invoice_fmpu_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_dt_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_dt_d` AFTER DELETE ON `trade$invoice_fmpu_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_i` AFTER INSERT ON `trade$order` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_u` AFTER UPDATE ON `trade$order` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_d` AFTER DELETE ON `trade$order` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_dt_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_dt_i` AFTER INSERT ON `trade$order_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.order_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_dt_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_dt_u` AFTER UPDATE ON `trade$order_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.order_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_dt_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_dt_d` AFTER DELETE ON `trade$order_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.order_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_i` AFTER INSERT ON `trade$purchase` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_u` AFTER UPDATE ON `trade$purchase` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_d` AFTER DELETE ON `trade$purchase` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_dt_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_dt_i` AFTER INSERT ON `trade$purchase_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.purchase_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_dt_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_dt_u` AFTER UPDATE ON `trade$purchase_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.purchase_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_dt_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_dt_d` AFTER DELETE ON `trade$purchase_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.purchase_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;


-- 2018年5月22日 20:01:19 dongbw 
-- ----------------------------
-- Triggers structure for table v$product$private
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_product_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_product_i` AFTER INSERT ON `products` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$private';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.pr_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table v$product$private
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_product_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_product_u` AFTER UPDATE ON `products` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$private';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.pr_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table v$product$private
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_product_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_product_d` AFTER DELETE ON `products` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$private';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.pr_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- 物料私有属性新增、更新、删除时也需要更新物料索引 dongbw 2018年5月28日 16:13:46
-- ----------------------------
-- Triggers structure for table product$private
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_product_private_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_product_private_i` AFTER INSERT ON `product$private` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$private';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.pr_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$private
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_product_private_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_product_private_u` AFTER UPDATE ON `product$private` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$private';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.pr_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$private
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_product_private_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_product_private_d` AFTER DELETE ON `product$private` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$private';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.pr_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;