3_sp_data_migration_wcmtemplateemploy.sql 2.9 KB

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