products.sql 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. -- ----------------------------
  2. -- Triggers structure for table products
  3. -- ----------------------------
  4. DROP TRIGGER IF EXISTS `sync$products_i`;
  5. delimiter ;;
  6. CREATE DEFINER = `root`@`%` TRIGGER `sync$products_i` AFTER INSERT ON `products` FOR EACH ROW begin
  7. declare v_table_name varchar(64) default 'products';
  8. declare v_method_type varchar(6) default 'insert';
  9. declare v_data_key text;
  10. declare v_data text;
  11. declare v_priority int default 1;
  12. set v_data_key=concat('{"pr_id": ', new.pr_id, '}');
  13. select concat(
  14. concat('{'),
  15. -- varchar
  16. concat('"pr_title": ', case when new.pr_title is null then 'null' else concat('"', replace(new.pr_title, '"', '\\"'), '"') end),
  17. concat(',"pr_code": ', case when new.pr_code is null then 'null' else concat('"', replace(new.pr_code, '"', '\\"'), '"') end),
  18. concat(',"pr_spec": ', case when new.pr_spec is null then 'null' else concat('"', replace(new.pr_spec, '"', '\\"'), '"') end),
  19. concat(',"pr_unit": ', case when new.pr_unit is null then 'null' else concat('"', replace(new.pr_unit, '"', '\\"'), '"') end),
  20. concat(',"pr_brand": ', case when new.pr_brand is null then 'null' else concat('"', replace(new.pr_brand, '"', '\\"'), '"') end),
  21. concat(',"pr_cmpcode": ', case when new.pr_cmpcode is null then 'null' else concat('"', replace(new.pr_cmpcode, '"', '\\"'), '"') end),
  22. concat(',"pr_cmpuuid": ', case when new.pr_cmpuuid is null then 'null' else concat('"', replace(new.pr_cmpuuid, '"', '\\"'), '"') end),
  23. concat(',"pr_sourceapp": ', case when new.pr_sourceapp is null then 'null' else concat('"', replace(new.pr_sourceapp, '"', '\\"'), '"') end),
  24. concat(',"pr_kind": ', case when new.pr_kind is null then 'null' else concat('"', replace(new.pr_kind, '"', '\\"'), '"') end),
  25. concat(',"pr_kinden": ', case when new.pr_kinden is null then 'null' else concat('"', replace(new.pr_kinden, '"', '\\"'), '"') end),
  26. concat(',"pr_pbrand": ', case when new.pr_pbrand is null then 'null' else concat('"', replace(new.pr_pbrand, '"', '\\"'), '"') end),
  27. concat(',"pr_pbranden": ', case when new.pr_pbranden is null then 'null' else concat('"', replace(new.pr_pbranden, '"', '\\"'), '"') end),
  28. concat(',"pr_pbranduuid": ', case when new.pr_pbranduuid is null then 'null' else concat('"', replace(new.pr_pbranduuid, '"', '\\"'), '"') end),
  29. concat(',"pr_pcmpcode": ', case when new.pr_pcmpcode is null then 'null' else concat('"', replace(new.pr_pcmpcode, '"', '\\"'), '"') end),
  30. concat(',"pr_attachment": ', case when new.pr_attachment is null then 'null' else concat('"', replace(new.pr_attachment, '"', '\\"'), '"') end),
  31. concat(',"pr_encapsulation": ', case when new.pr_encapsulation is null then 'null' else concat('"', replace(new.pr_encapsulation, '"', '\\"'), '"') end),
  32. concat(',"pr_packaging": ', case when new.pr_packaging is null then 'null' else concat('"', replace(new.pr_packaging, '"', '\\"'), '"') end),
  33. concat(',"pr_cmpimg": ', case when new.pr_cmpimg is null then 'null' else concat('"', replace(new.pr_cmpimg, '"', '\\"'), '"') end),
  34. concat(',"pr_goodsnover": ', case when new.pr_goodsnover is null then 'null' else concat('"', replace(new.pr_goodsnover, '"', '\\"'), '"') end),
  35. concat(',"pr_goodstaxno": ', case when new.pr_goodstaxno is null then 'null' else concat('"', replace(new.pr_goodstaxno, '"', '\\"'), '"') end),
  36. concat(',"pr_taxpre": ', case when new.pr_taxpre is null then 'null' else concat('"', replace(new.pr_taxpre, '"', '\\"'), '"') end),
  37. concat(',"pr_taxprecon": ', case when new.pr_taxprecon is null then 'null' else concat('"', replace(new.pr_taxprecon, '"', '\\"'), '"') end),
  38. -- bit(1), smallint(6), int(11), bigint(20), double
  39. concat(',"pr_enuu": ', case when new.pr_enuu is null then 'null' else new.pr_enuu end),
  40. concat(',"pr_useruu": ', case when new.pr_useruu is null then 'null' else new.pr_useruu end),
  41. concat(',"pr_minpack": ', case when new.pr_minpack is null then 'null' else new.pr_minpack end),
  42. concat(',"pr_minorder": ', case when new.pr_minorder is null then 'null' else new.pr_minorder end),
  43. concat(',"pr_leadtime": ', case when new.pr_leadtime is null then 'null' else new.pr_leadtime end),
  44. concat(',"pr_ltinstock": ', case when new.pr_ltinstock is null then 'null' else new.pr_ltinstock end),
  45. concat(',"pr_reserve": ', case when new.pr_reserve is null then 'null' else new.pr_reserve end),
  46. concat(',"pr_price": ', case when new.pr_price is null then 'null' else new.pr_price end),
  47. concat(',"pr_sourceid": ', case when new.pr_sourceid is null then 'null' else new.pr_sourceid end),
  48. concat(',"pr_kindid": ', case when new.pr_kindid is null then 'null' else new.pr_kindid end),
  49. concat(',"pr_pbrandid": ', case when new.pr_pbrandid is null then 'null' else new.pr_pbrandid end),
  50. concat(',"pr_issale": ', case when new.pr_issale is null then 'null' else new.pr_issale end),
  51. concat(',"pr_ispurchase": ', case when new.pr_ispurchase is null then 'null' else new.pr_ispurchase end),
  52. concat(',"pr_isshow": ', case when new.pr_isshow is null then 'null' else new.pr_isshow end),
  53. concat(',"pr_ispubsale": ', case when new.pr_ispubsale is null then 'null' else new.pr_ispubsale end),
  54. concat(',"pr_standard": ', case when new.pr_standard is null then 'null' else new.pr_standard end),
  55. concat(',"pr_matchstatus": ', case when new.pr_matchstatus is null then 'null' else new.pr_matchstatus end),
  56. concat(',"pr_matchsize": ', case when new.pr_matchsize is null then 'null' else new.pr_matchsize end),
  57. concat(',"pr_downloadstatus": ', case when new.pr_downloadstatus is null then 'null' else new.pr_downloadstatus end),
  58. concat(',"pr_maxdelivery": ', case when new.pr_maxdelivery is null then 'null' else new.pr_maxdelivery end),
  59. concat(',"pr_mindelivery": ', case when new.pr_mindelivery is null then 'null' else new.pr_mindelivery end),
  60. concat(',"pr_isbreakup": ', case when new.pr_isbreakup is null then 'null' else new.pr_isbreakup end),
  61. -- datetime
  62. concat(',"pr_erpdate": ', case when new.pr_erpdate is null then 'null' else concat('"', replace(new.pr_erpdate, '"', '\\"'), '"') end),
  63. concat(',"pr_create_time": ', case when new.pr_create_time is null then 'null' else concat('"', replace(new.pr_create_time, '"', '\\"'), '"') end),
  64. concat(',"pr_tostandard": ', case when new.pr_tostandard is null then 'null' else concat('"', replace(new.pr_tostandard, '"', '\\"'), '"') end),
  65. concat(',"pr_manufacturedate": ', case when new.pr_manufacturedate is null then 'null' else concat('"', replace(new.pr_manufacturedate, '"', '\\"'), '"') end),
  66. -- text
  67. -- json
  68. concat('}')
  69. ) into v_data;
  70. call sync$enqueue_message(v_table_name, v_method_type, v_data_key, v_data, v_priority);
  71. end
  72. ;;
  73. delimiter ;
  74. -- ----------------------------
  75. -- Triggers structure for table products
  76. -- ----------------------------
  77. DROP TRIGGER IF EXISTS `sync$products_u`;
  78. delimiter ;;
  79. CREATE DEFINER = `root`@`%` TRIGGER `sync$products_u` AFTER UPDATE ON `products` FOR EACH ROW begin
  80. declare v_table_name varchar(64) default 'products';
  81. declare v_method_type varchar(6) default 'update';
  82. declare v_data_key text;
  83. declare v_data text;
  84. declare v_priority int default 1;
  85. set v_data_key=concat('{"pr_id": ', old.pr_id, '}');
  86. select concat(
  87. concat('{'),
  88. -- varchar
  89. concat('"pr_title": ', case when new.pr_title is null then 'null' else concat('"', replace(new.pr_title, '"', '\\"'), '"') end),
  90. concat(',"pr_code": ', case when new.pr_code is null then 'null' else concat('"', replace(new.pr_code, '"', '\\"'), '"') end),
  91. concat(',"pr_spec": ', case when new.pr_spec is null then 'null' else concat('"', replace(new.pr_spec, '"', '\\"'), '"') end),
  92. concat(',"pr_unit": ', case when new.pr_unit is null then 'null' else concat('"', replace(new.pr_unit, '"', '\\"'), '"') end),
  93. concat(',"pr_brand": ', case when new.pr_brand is null then 'null' else concat('"', replace(new.pr_brand, '"', '\\"'), '"') end),
  94. concat(',"pr_cmpcode": ', case when new.pr_cmpcode is null then 'null' else concat('"', replace(new.pr_cmpcode, '"', '\\"'), '"') end),
  95. concat(',"pr_cmpuuid": ', case when new.pr_cmpuuid is null then 'null' else concat('"', replace(new.pr_cmpuuid, '"', '\\"'), '"') end),
  96. concat(',"pr_sourceapp": ', case when new.pr_sourceapp is null then 'null' else concat('"', replace(new.pr_sourceapp, '"', '\\"'), '"') end),
  97. concat(',"pr_kind": ', case when new.pr_kind is null then 'null' else concat('"', replace(new.pr_kind, '"', '\\"'), '"') end),
  98. concat(',"pr_kinden": ', case when new.pr_kinden is null then 'null' else concat('"', replace(new.pr_kinden, '"', '\\"'), '"') end),
  99. concat(',"pr_pbrand": ', case when new.pr_pbrand is null then 'null' else concat('"', replace(new.pr_pbrand, '"', '\\"'), '"') end),
  100. concat(',"pr_pbranden": ', case when new.pr_pbranden is null then 'null' else concat('"', replace(new.pr_pbranden, '"', '\\"'), '"') end),
  101. concat(',"pr_pbranduuid": ', case when new.pr_pbranduuid is null then 'null' else concat('"', replace(new.pr_pbranduuid, '"', '\\"'), '"') end),
  102. concat(',"pr_pcmpcode": ', case when new.pr_pcmpcode is null then 'null' else concat('"', replace(new.pr_pcmpcode, '"', '\\"'), '"') end),
  103. concat(',"pr_attachment": ', case when new.pr_attachment is null then 'null' else concat('"', replace(new.pr_attachment, '"', '\\"'), '"') end),
  104. concat(',"pr_encapsulation": ', case when new.pr_encapsulation is null then 'null' else concat('"', replace(new.pr_encapsulation, '"', '\\"'), '"') end),
  105. concat(',"pr_packaging": ', case when new.pr_packaging is null then 'null' else concat('"', replace(new.pr_packaging, '"', '\\"'), '"') end),
  106. concat(',"pr_cmpimg": ', case when new.pr_cmpimg is null then 'null' else concat('"', replace(new.pr_cmpimg, '"', '\\"'), '"') end),
  107. concat(',"pr_goodsnover": ', case when new.pr_goodsnover is null then 'null' else concat('"', replace(new.pr_goodsnover, '"', '\\"'), '"') end),
  108. concat(',"pr_goodstaxno": ', case when new.pr_goodstaxno is null then 'null' else concat('"', replace(new.pr_goodstaxno, '"', '\\"'), '"') end),
  109. concat(',"pr_taxpre": ', case when new.pr_taxpre is null then 'null' else concat('"', replace(new.pr_taxpre, '"', '\\"'), '"') end),
  110. concat(',"pr_taxprecon": ', case when new.pr_taxprecon is null then 'null' else concat('"', replace(new.pr_taxprecon, '"', '\\"'), '"') end),
  111. -- bit(1), smallint(6), int(11), bigint(20), double
  112. concat(',"pr_enuu": ', case when new.pr_enuu is null then 'null' else new.pr_enuu end),
  113. concat(',"pr_useruu": ', case when new.pr_useruu is null then 'null' else new.pr_useruu end),
  114. concat(',"pr_minpack": ', case when new.pr_minpack is null then 'null' else new.pr_minpack end),
  115. concat(',"pr_minorder": ', case when new.pr_minorder is null then 'null' else new.pr_minorder end),
  116. concat(',"pr_leadtime": ', case when new.pr_leadtime is null then 'null' else new.pr_leadtime end),
  117. concat(',"pr_ltinstock": ', case when new.pr_ltinstock is null then 'null' else new.pr_ltinstock end),
  118. concat(',"pr_reserve": ', case when new.pr_reserve is null then 'null' else new.pr_reserve end),
  119. concat(',"pr_price": ', case when new.pr_price is null then 'null' else new.pr_price end),
  120. concat(',"pr_sourceid": ', case when new.pr_sourceid is null then 'null' else new.pr_sourceid end),
  121. concat(',"pr_kindid": ', case when new.pr_kindid is null then 'null' else new.pr_kindid end),
  122. concat(',"pr_pbrandid": ', case when new.pr_pbrandid is null then 'null' else new.pr_pbrandid end),
  123. concat(',"pr_issale": ', case when new.pr_issale is null then 'null' else new.pr_issale end),
  124. concat(',"pr_ispurchase": ', case when new.pr_ispurchase is null then 'null' else new.pr_ispurchase end),
  125. concat(',"pr_isshow": ', case when new.pr_isshow is null then 'null' else new.pr_isshow end),
  126. concat(',"pr_ispubsale": ', case when new.pr_ispubsale is null then 'null' else new.pr_ispubsale end),
  127. concat(',"pr_standard": ', case when new.pr_standard is null then 'null' else new.pr_standard end),
  128. concat(',"pr_matchstatus": ', case when new.pr_matchstatus is null then 'null' else new.pr_matchstatus end),
  129. concat(',"pr_matchsize": ', case when new.pr_matchsize is null then 'null' else new.pr_matchsize end),
  130. concat(',"pr_downloadstatus": ', case when new.pr_downloadstatus is null then 'null' else new.pr_downloadstatus end),
  131. concat(',"pr_maxdelivery": ', case when new.pr_maxdelivery is null then 'null' else new.pr_maxdelivery end),
  132. concat(',"pr_mindelivery": ', case when new.pr_mindelivery is null then 'null' else new.pr_mindelivery end),
  133. concat(',"pr_isbreakup": ', case when new.pr_isbreakup is null then 'null' else new.pr_isbreakup end),
  134. -- datetime
  135. concat(',"pr_erpdate": ', case when new.pr_erpdate is null then 'null' else concat('"', replace(new.pr_erpdate, '"', '\\"'), '"') end),
  136. concat(',"pr_create_time": ', case when new.pr_create_time is null then 'null' else concat('"', replace(new.pr_create_time, '"', '\\"'), '"') end),
  137. concat(',"pr_tostandard": ', case when new.pr_tostandard is null then 'null' else concat('"', replace(new.pr_tostandard, '"', '\\"'), '"') end),
  138. concat(',"pr_manufacturedate": ', case when new.pr_manufacturedate is null then 'null' else concat('"', replace(new.pr_manufacturedate, '"', '\\"'), '"') end),
  139. -- text
  140. -- json
  141. concat('}')
  142. ) into v_data;
  143. call sync$enqueue_message(v_table_name, v_method_type, v_data_key, v_data, v_priority);
  144. end
  145. ;;
  146. delimiter ;
  147. -- ----------------------------
  148. -- Triggers structure for table products
  149. -- ----------------------------
  150. DROP TRIGGER IF EXISTS `sync$products_d`;
  151. delimiter ;;
  152. CREATE DEFINER = `root`@`%` TRIGGER `sync$products_d` AFTER DELETE ON `products` FOR EACH ROW begin
  153. declare v_table_name varchar(64) default 'products';
  154. declare v_method_type varchar(6) default 'delete';
  155. declare v_data_key text;
  156. declare v_data text;
  157. declare v_priority int default 1;
  158. set v_data_key=concat('{"pr_id": ', old.pr_id, '}');
  159. call sync$enqueue_message(v_table_name, v_method_type, v_data_key, v_data, v_priority);
  160. end
  161. ;;
  162. delimiter ;