1. 程式人生 > >增加出庫通知單統計事件

增加出庫通知單統計事件

ima from table fault nod star utf %d drop

use wms;


drop table if exists riv_outbound_notice_statistics;
-- 增加出庫通知單統計表
CREATE TABLE `riv_outbound_notice_statistics` (
`ONS_ID` int(10) NOT NULL AUTO_INCREMENT COMMENT ‘主鍵ID‘,
`BEGIN_TIME` datetime NOT NULL COMMENT ‘統計起始時間‘,
`END_TIME` datetime NOT NULL COMMENT ‘統計結束時間‘,
`ONH_TOTAL_QTY` bigint(19) NOT NULL COMMENT ‘出庫通知單總創建量‘,
`ONH_SHIPED_QTY` bigint(19) NOT NULL COMMENT ‘出庫通知單已發貨量‘,
PRIMARY KEY (`ONS_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=‘出庫通知單統計表‘;


drop procedure if exists pro_outbound_notice_statistics;
-- 增加出庫通知單統計函數
delimiter //
create procedure `pro_outbound_notice_statistics`()
begin

DECLARE create_notice_num VARCHAR(50);
DECLARE ship_notice_num VARCHAR(50);

DECLARE curtime VARCHAR(50);
DECLARE pretime VARCHAR(50);

DECLARE curday VARCHAR(50);
DECLARE curhour VARCHAR(50);

set curtime = CONCAT(DATE_FORMAT(now(),‘%Y-%m-%d %H‘),‘:00:00‘);
set pretime = date_sub(curtime, interval 1 hour);

SELECT count(1) INTO create_notice_num from riv_outbound_notice_h onh where onh.CREATE_TIME < curtime and onh.CREATE_TIME >= pretime;

SELECT count(1) INTO ship_notice_num from riv_outbound_notice_h onh where onh.ONH_STATUS = 90 and onh.ONH_SHIP_DATETIME < curtime and onh.ONH_SHIP_DATETIME >= pretime;


SELECT pretime,curtime ,create_notice_num,ship_notice_num;
insert into riv_outbound_notice_statistics(`BEGIN_TIME`, `END_TIME`,`ONH_TOTAL_QTY`, `ONH_SHIPED_QTY`) values(pretime, curtime, create_notice_num, ship_notice_num );
end//
delimiter ;


drop event if exists event_auto_outbound_notice_statistics;
set global event_scheduler=‘on‘;
-- 增加出庫通知單統計事件
CREATE EVENT `event_auto_outbound_notice_statistics`
ON SCHEDULE EVERY 1 HOUR STARTS ‘2017-11-10 00:00:00‘ ENDS ‘2018-01-01 00:00:00‘
ON COMPLETION NOT PRESERVE
ENABLE
DO
CALL pro_outbound_notice_statistics();

增加出庫通知單統計事件