/*rand_string: 生成一个长度为n的随机字符。 注意这个n必须小于'abcdefghijklmnopqrstuvwxyz0123456789' 的长度*/
DROP FUNCTION IF EXISTS rand_string;
DELIMITER $$
CREATE FUNCTION rand_string(n INT)
RETURNS VARCHAR(255)
BEGIN
DECLARE chars_str varchar(100) DEFAULT 'abcdefghijklmnopqrstuvwxyz0123456789';
DECLARE return_str varchar(255) DEFAULT '';
DECLARE i INT DEFAULT 0;
WHILE i < n DO
SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*36 ),1));
SET i = i +1;
END WHILE;
RETURN return_str;
END $$
DELIMITER ;
/*SELECT rand_string(32); */ /*recordId*/
DROP FUNCTION IF EXISTS uuid_string;
DELIMITER $$
CREATE FUNCTION uuid_string()
RETURNS VARCHAR(255)
BEGIN
DECLARE return_str varchar(255) DEFAULT '';
DECLARE temp_str2 varchar(255) DEFAULT '';
DECLARE temp_str3 varchar(255) DEFAULT '';
DECLARE temp_str4 varchar(255) DEFAULT '';
DECLARE temp_str5 varchar(255) DEFAULT '';
DECLARE temp_str1 varchar(255) DEFAULT '_';
SET return_str = CONCAT(return_str,'uuid');
SET return_str = CONCAT(return_str,rand_string(8));
SET return_str = CONCAT(return_str,temp_str1);
SET return_str = CONCAT(return_str,rand_string(4));
SET return_str = CONCAT(return_str,temp_str1);
SET return_str = CONCAT(return_str,rand_string(4));
SET return_str = CONCAT(return_str,temp_str1);
SET return_str = CONCAT(return_str,rand_string(4));
SET return_str = CONCAT(return_str,temp_str1);
SET return_str = CONCAT(return_str,rand_string(12));
RETURN return_str;
END $$
DELIMITER ;
/*SELECT uuid_string();*//* alertName*/
set @dt = '2018-08-13 00:00:01';
drop procedure IF EXISTS u_head_and_low_pro;
delimiter //
create procedure u_head_and_low_pro()
begin
DECLARE n int DEFAULT 500000;
SET n = n -1;
WHILE n > 0 DO
SELECT n;
INSERT INTO alarmRecord.AlertRecord
(recordId, startStatus, disappearStatus, ackStatus, alertName, alertType, priority, message, description, startDatatimestamp, disappearedDatatimestamp, ackDatatimestamp, ackUserName, showName, displayName, objShowName, newValue)
VALUES(rand_string(32), 1, 1, 0, uuid_string(), 'gt', 1, '51 > 50',
'报警1',unix_timestamp(date_add(@dt, interval 60*n second))*1000,unix_timestamp(date_add(@dt, interval 1000*n second))*1000, NULL, NULL, 'alarm', 'zhizhi888_mirror.int_1_to_100_200ms',
'zhizhi888_mirror.int_1_to_100_200ms', '51');
set n = n - 1;
END WHILE;
end
//
CALL u_head_and_low_pro();