3_sp_data_migration_wcmtemplateemploy.sql 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. DROP PROCEDURE IF EXISTS sp_data_migration_wcmtemplateemploy;
  2. DELIMITER $$
  3. CREATE PROCEDURE sp_data_migration_wcmtemplateemploy(IN prevTemplateEmployId BIGINT(20),
  4. IN templateEmployIdOffset BIGINT(20),
  5. IN templateIdOffset BIGINT(20),
  6. IN siteIdOffset BIGINT(20),
  7. IN channelIdOffset BIGINT(20))
  8. BEGIN
  9. DECLARE isover INT DEFAULT 0;
  10. DECLARE migr_table_name varchar(255) DEFAULT 'wcmtemplateemploy';
  11. DECLARE template_migr_table_name varchar(255) DEFAULT 'wcmtemplate';
  12. DECLARE site_migr_table_name varchar(255) DEFAULT 'wcmwebsite';
  13. DECLARE channel_migr_table_name varchar(255) DEFAULT 'wcmchannel';
  14. DECLARE f_TEMPLATEEMPLOYID int(11) DEFAULT '0';
  15. DECLARE f_EMPLOYERTYPE int(11) DEFAULT '0';
  16. DECLARE f_EMPLOYERID int(11) DEFAULT '0';
  17. DECLARE f_TEMPLATEID int(11) DEFAULT '0';
  18. DECLARE f_TEMPLATETYPE smallint(6) DEFAULT '0';
  19. DECLARE f_ISDEFAULT smallint(6) DEFAULT '0';
  20. DECLARE cur CURSOR FOR
  21. SELECT
  22. TEMPLATEEMPLOYID,
  23. EMPLOYERTYPE,
  24. EMPLOYERID,
  25. TEMPLATEID,
  26. TEMPLATETYPE,
  27. ISDEFAULT
  28. FROM wcmtemplateemploy
  29. ORDER BY TEMPLATEEMPLOYID asc;
  30. DECLARE CONTINUE HANDLER FOR NOT FOUND SET isover = 1;
  31. OPEN cur;
  32. FETCH cur INTO
  33. f_TEMPLATEEMPLOYID,
  34. f_EMPLOYERTYPE,
  35. f_EMPLOYERID,
  36. f_TEMPLATEID,
  37. f_TEMPLATETYPE,
  38. f_ISDEFAULT
  39. ;
  40. select concat('开始迁移 ', migr_table_name) info;
  41. WHILE isover= 0 DO
  42. # 断点续传
  43. IF (f_TEMPLATEEMPLOYID > prevTemplateEmployId)
  44. THEN
  45. SET @TEMPLATEEMPLOYID = f_TEMPLATEEMPLOYID;
  46. SET f_TEMPLATEEMPLOYID = f_TEMPLATEEMPLOYID + templateEmployIdOffset;
  47. SET @template_offset_num = ifnull((SELECT offset_num FROM data_migration_offset WHERE table_name = template_migr_table_name AND start_id < f_TEMPLATEID and end_id >= f_TEMPLATEID), templateIdOffset);
  48. SET f_TEMPLATEID = f_TEMPLATEID + @template_offset_num;
  49. IF (f_EMPLOYERTYPE = 103)
  50. THEN
  51. SET @site_offset_num = ifnull((SELECT offset_num FROM data_migration_offset WHERE table_name = site_migr_table_name AND start_id < f_EMPLOYERID and end_id >= f_EMPLOYERID), siteIdOffset);
  52. SET f_EMPLOYERID = f_EMPLOYERID + @site_offset_num;
  53. END IF ;
  54. IF (f_EMPLOYERTYPE = 101)
  55. THEN
  56. SET @channel_offset_num = ifnull((SELECT offset_num FROM data_migration_offset WHERE table_name = channel_migr_table_name AND start_id < f_EMPLOYERID and end_id >= f_EMPLOYERID), channelIdOffset);
  57. SET f_EMPLOYERID = f_EMPLOYERID + @channel_offset_num;
  58. END IF ;
  59. insert into trs_hycloud_iip.wcmtemplateemploy
  60. (
  61. TEMPLATEEMPLOYID,
  62. EMPLOYERTYPE,
  63. EMPLOYERID,
  64. TEMPLATEID,
  65. TEMPLATETYPE,
  66. ISDEFAULT
  67. )
  68. VALUES
  69. (
  70. f_TEMPLATEEMPLOYID,
  71. f_EMPLOYERTYPE,
  72. f_EMPLOYERID,
  73. f_TEMPLATEID,
  74. f_TEMPLATETYPE,
  75. f_ISDEFAULT
  76. );
  77. SET @log_sql = build_migration_log_sql(migr_table_name, @TEMPLATEEMPLOYID, now());
  78. prepare stmt from @log_sql;
  79. EXECUTE stmt;
  80. deallocate prepare stmt;
  81. call setOffset(migr_table_name, templateEmployIdOffset, prevTemplateEmployId, @TEMPLATEEMPLOYID);
  82. END IF ;
  83. FETCH cur INTO
  84. f_TEMPLATEEMPLOYID,
  85. f_EMPLOYERTYPE,
  86. f_EMPLOYERID,
  87. f_TEMPLATEID,
  88. f_TEMPLATETYPE,
  89. f_ISDEFAULT
  90. ;
  91. END WHILE;
  92. CLOSE cur;
  93. select concat('完成迁移 ', migr_table_name) info;
  94. END $$
  95. DELIMITER ;