单独用navicate新建函数, 函数无法保存,直接用脚本即可
create PROCEDURE proc_handleprisoner()
BEGIN
-- 根据信息员的在岗时间,如果超过此时间范围,自动设置为不是信息员
-- 考虑到一个犯人可能会多次担任信息员,所以不能因为第一次担任的时间过期了,就设置成否,要取最后一次时间为准
update fcp_prisoner f set f.pr_safe = '否' where EXISTS (
select * from (
select a.researcher_userid , max(a.researcher_end_time) as researcher_end_time
from t_xxy a group by researcher_userid
) b where f.pr_number = researcher_userid and NOW() > b.researcher_end_time
);
-- 根据耳目的在岗时间,如果超过此时间范围,自动设置为不是耳目
-- 考虑到一个犯人可能会多次担任信息员,所以不能因为第一次担任的时间过期了,就设置成否,要取最后一次时间为准
update fcp_prisoner f set f.uc_flag = '否' where EXISTS (
select * from (
select a.pr_no , max(a.edate) as edate
from t_undercover a group by pr_no
) b where f.pr_number = b.pr_no and NOW() > b.edate
);
END