p_data_migration_wcmtemplateemploy.sql 2.9 KB

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