MySQL每日执行
drop event if exists upload_deadline; DELIMITER $$ create event upload_deadline on schedule every 1 day starts timestamp '2017-03-30 02:00:00' #on schedule every 1 SECOND do # 开始该计划任务要做的事 begin -- do something 编写你的计划任务要做的事 -- 计算执行比例(执行额/总投放额) -- 认领期限为0表示未认领,如果认领期限大于0,已认领或已合作,开始每日累加 -- 如果是未合作,认领时间大于7天,将认领状态设为已释放状态2,释放期限设为0,将现在用户ID设为老用户ID,并抹去现在用户ID -- 如果是已合作,合作大于30天,合作费用为0,将合作状态设为未认领0,将认领状态设为已释放状态2,释放期限设为0,将现在用户ID设为老用户ID,并抹去现在用户ID -- 如果是已合作,合作大于30天,客户月投放额大于50万,月度执行比例低于30%,将合作状态设为未认领0,将认领状态设为已释放状态2,释放期限设为0,将现在用户ID设为老用户ID,并抹去现在用户ID -- 释放状态为2,表示已释放,开始每日累加 -- 如果大于3就设置为未释放状态0,释放期限也设为0 UPDATE `customer` set proportion=collaborate_cost/this_month_cost where collaborate_cost!=0 and this_month_cost!=0; UPDATE `customer` set claim_deadline=claim_deadline+1 where claim_deadline>0 and (claim_state=1 or collaborate_state=1); UPDATE `customer` set claim_deadline=0,claim_state=2,relieve_collaborate_time=now(),release_deadline=0,old_userId=now_userId,now_userId=0 where claim_state=1 and collaborate_state=0 and claim_deadline>7; UPDATE `customer` set claim_deadline=0,claim_state=2,relieve_collaborate_time=now(),release_deadline=0,old_userId=now_userId,now_userId=0, collaborate_state=0 where collaborate_state=1 and claim_deadline>30 and collaborate_cost=0; UPDATE `customer` set claim_deadline=0,claim_state=2,relieve_collaborate_time=now(),release_deadline=0,old_userId=now_userId,now_userId=0, collaborate_state=0 where collaborate_state=1 and claim_deadline>30 and this_month_cost>500000 and proportion<0.3; UPDATE `customer` set release_deadline=release_deadline+1 where claim_state=2; UPDATE `customer` set release_deadline=0,claim_state=0 where release_deadline>3; -- 结束计划任务 end $$ DELIMITER ;
每8小时执行一次
drop event if exists upload_Ratio_headlines; DELIMITER $$ create event upload_Ratio_headlines on schedule every 8 hour -- starts timestamp '2017-04-22 08:00:00' #on schedule every 1 SECOND do # 开始该计划任务要做的事 begin -- do something 编写你的计划任务要做的事 -- 计算阅读率 UPDATE `interior_gzh_account` set read_ratio=read_count/fans; -- 计算总价 UPDATE `interior_gzh_account` set headlines=fans*xiaoshuo/10000; -- 结束计划任务 end $$ DELIMITER ;
-----------------------------------------------------------------------------