p_data_migration_wcmtemplateemploy.sql 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. DROP PROCEDURE IF EXISTS p_data_migration_wcmtemplateemploy;
  2. DELIMITER $$
  3. CREATE PROCEDURE p_data_migration_wcmtemplateemploy(IN prevTemplateEmployId BIGINT(20),
  4. IN templateEmployIdOffset BIGINT(20),
  5. IN siteIdOffset BIGINT(20),
  6. IN channelIdOffset BIGINT(20))
  7. BEGIN
  8. DECLARE over INT DEFAULT 0;
  9. DECLARE f_TEMPLATEEMPLOYID int(11) DEFAULT '0';
  10. DECLARE f_EMPLOYERTYPE int(11) DEFAULT '0';
  11. DECLARE f_EMPLOYERID int(11) DEFAULT '0';
  12. DECLARE f_TEMPLATEID int(11) DEFAULT '0';
  13. DECLARE f_TEMPLATETYPE smallint(6) DEFAULT '0';
  14. DECLARE f_ISDEFAULT smallint(6) DEFAULT '0';
  15. DECLARE cur CURSOR FOR
  16. SELECT
  17. TEMPLATEEMPLOYID,
  18. EMPLOYERTYPE,
  19. EMPLOYERID,
  20. TEMPLATEID,
  21. TEMPLATETYPE,
  22. ISDEFAULT
  23. FROM v_wcm.wcmtemplateemploy
  24. ORDER BY TEMPLATEEMPLOYID asc;
  25. DECLARE CONTINUE HANDLER FOR NOT FOUND SET over = 1;
  26. OPEN cur;
  27. FETCH cur INTO
  28. f_TEMPLATEEMPLOYID,
  29. f_EMPLOYERTYPE,
  30. f_EMPLOYERID,
  31. f_TEMPLATEID,
  32. f_TEMPLATETYPE,
  33. f_ISDEFAULT
  34. ;
  35. WHILE over= 0 DO
  36. # 断点续传
  37. IF (f_TEMPLATEEMPLOYID > prevTemplateEmployId)
  38. THEN
  39. SET f_TEMPLATEEMPLOYID = f_TEMPLATEEMPLOYID + templateEmployIdOffset;
  40. SET f_TEMPLATEID = f_TEMPLATEID + baseTemplateId;
  41. IF (f_EMPLOYERTYPE = 103)
  42. THEN SET f_TEMPLATEID = f_TEMPLATEID + siteIdOffset;
  43. END IF ;
  44. IF (f_EMPLOYERTYPE = 101)
  45. THEN SET f_TEMPLATEID = f_TEMPLATEID + channelIdOffset;
  46. END IF ;
  47. insert into trs_hycloud_iip.wcmtemplateemploy
  48. (
  49. TEMPLATEEMPLOYID,
  50. EMPLOYERTYPE,
  51. EMPLOYERID,
  52. TEMPLATEID,
  53. TEMPLATETYPE,
  54. ISDEFAULT
  55. )
  56. VALUES
  57. (
  58. f_TEMPLATEEMPLOYID,
  59. f_EMPLOYERTYPE,
  60. f_EMPLOYERID,
  61. f_TEMPLATEID,
  62. f_TEMPLATETYPE,
  63. f_ISDEFAULT
  64. );
  65. SELECT CONCAT('成功迁移 wcmtemplateemploy[TEMPLATEEMPLOYID=', f_TEMPID, ']') ;
  66. END IF ;
  67. FETCH cur INTO
  68. f_TEMPLATEEMPLOYID,
  69. f_EMPLOYERTYPE,
  70. f_EMPLOYERID,
  71. f_TEMPLATEID,
  72. f_TEMPLATETYPE,
  73. f_ISDEFAULT
  74. ;
  75. END WHILE;
  76. CLOSE cur;
  77. SELECT '迁移 wcmtemplateemploy 完毕';
  78. END$$
  79. DELIMITER ;