1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
| delimiter //
DROP PROCEDURE IF EXISTS function_test; CREATE PROCEDURE function_test(event_arr varchar(150),retry_arr varchar(150),task_source_idVal INT,rand_time varchar(25)) BEGIN
DECLARE event_arr_tmp varchar(150); DECLARE retry_arr_tmp varchar(150); DECLARE eventVal varchar(150); DECLARE retryVal varchar(150); DECLARE i INT default 0; DECLARE random_task_id INT DEFAULT 0; DECLARE task_name_val_arr varchar(1000) default 'mt_daily,' 'mt_monthly,' 'mt_b2b_monthly,' 'returns_daily,' 'returns_monthly,' 'mt_summary_monthly,' 'deal,' 'deal_result,' 'inventory_age,' 'vat_monthly,' 'business_daily,' 'bank_card,' 'box_upload,' 'box_download,' 'order_shoot,' 'balance_daily,' 'balance_quarterly,' 'account_status,' 'feedback_daily,' 'request_review,' 'storage_free_monthly,' 'storage_mon_monthly,' 'referenceid,' 'amazon_rank,' 'amazon_rating,' 'walmart_rank,' 'get_boss_positions_by_search,' 'get_boss_positions_by_company,' 'get_boss_position_detail,' 'balance_monthly';
DECLARE task_name_val varchar(1000);
select 1 + (RAND() * 31) into random_task_id; SET task_name_val = SUBSTRING_INDEX(task_name_val_arr, ',', random_task_id); SET task_name_val = SUBSTRING_INDEX(task_name_val, ',', -1);
SET event_arr_tmp=event_arr; SET retry_arr_tmp=retry_arr; WHILE event_arr_tmp != '' DO SET eventVal = SUBSTRING_INDEX(event_arr_tmp, ',', 1); SET retryVal = SUBSTRING_INDEX(retry_arr_tmp, ',', 1); INSERT INTO atc_task_logs(task_source_id, event, result_hash_key, task_name, retry_times, created_time) VALUES (task_source_idVal, eventVal, 0, task_name_val, retryVal, rand_time);
select date_add(rand_time, interval 1 second) into rand_time;
IF LOCATE(',', event_arr_tmp) > 0 THEN SET event_arr_tmp = SUBSTRING(event_arr_tmp, LOCATE(',', event_arr_tmp) + 1); ELSE SET event_arr_tmp = ''; END IF;
IF LOCATE(',', retry_arr_tmp) > 0 THEN SET retry_arr_tmp = SUBSTRING(retry_arr_tmp, LOCATE(',', retry_arr_tmp) + 1); ELSE SET retry_arr_tmp = ''; END IF; END WHILE;
end //
DROP PROCEDURE IF EXISTS proc_batch_insert; CREATE PROCEDURE proc_batch_insert()
BEGIN DECLARE event_arr1 varchar(150) DEFAULT '1,2,3,4'; DECLARE event_arr2 varchar(150) DEFAULT '1,2,3,5,1,2,3,4'; DECLARE event_arr3 varchar(150) DEFAULT '1,2,3,5,1,2,3,5,1,2,3,4'; DECLARE event_arr4 varchar(150) DEFAULT '1,2,3,5,1,2,3,5,1,2,3,5,1,2,3,4'; DECLARE event_arr5 varchar(150) DEFAULT '1,2,3,5,1,2,3,5,1,2,3,5,1,2,3,5,1,2,3,4'; DECLARE event_arr6 varchar(150) DEFAULT '1,2,3,5,1,2,3,5,1,2,3,5,1,2,3,5,1,2,3,5';
DECLARE retry_arr1 varchar(150) DEFAULT '1,1,1,1'; DECLARE retry_arr2 varchar(150) DEFAULT '1,1,1,1,2,2,2,2'; DECLARE retry_arr3 varchar(150) DEFAULT '1,1,1,1,2,2,2,2,3,3,3,3'; DECLARE retry_arr4 varchar(150) DEFAULT '1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4'; DECLARE retry_arr5 varchar(150) DEFAULT '1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5'; DECLARE retry_arr6 varchar(150) DEFAULT '1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5';
DECLARE event_arr varchar(150); DECLARE retry_arr varchar(150) ;
DECLARE task_source_idVal INT; DECLARE i INT default 0;
DECLARE arr_index_probability_distribution varchar(1000) default '1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,4,4,5,6,' '1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,' '1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,' '1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,' '1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,';
DECLARE arr_index_key INT DEFAULT 0; DECLARE rand_time varchar(25) ; DECLARE arr_value_value varchar(1000);
SET task_source_idVal = 3000001;
WHILE task_source_idVal <= 4000000 DO
select 1 + (RAND() * 101) into arr_index_key;
SELECT FROM_UNIXTIME( FLOOR((@s := UNIX_TIMESTAMP('2021-10-19 23:59:56')) + RAND() * (UNIX_TIMESTAMP('2021-10-14 23:59:59') - @s + 1) )) into rand_time ;
SET arr_value_value = SUBSTRING_INDEX(arr_index_probability_distribution, ',', arr_index_key); SET arr_value_value = SUBSTRING_INDEX(arr_value_value, ',', -1);
CASE arr_value_value WHEN '1' THEN SET event_arr = event_arr1; SET retry_arr = retry_arr1; WHEN '2' THEN SET event_arr = event_arr2; SET retry_arr = retry_arr2; WHEN '3' THEN SET event_arr = event_arr3; SET retry_arr = retry_arr3; WHEN '4' THEN SET event_arr = event_arr4; SET retry_arr = retry_arr4; WHEN '5' THEN SET event_arr = event_arr5; SET retry_arr = retry_arr5; WHEN '6' THEN SET event_arr = event_arr6; SET retry_arr = retry_arr6; ELSE BEGIN END; END CASE;
call function_test(event_arr,retry_arr,task_source_idVal,rand_time); SET task_source_idVal = task_source_idVal + 1;
SET i = i+1;
END WHILE; END; // delimiter ; call proc_batch_insert();
|