

update security_person t1
set t1.comTaskFlag = '1',
update_time=NOW()
where EXISTS(
select 1 from com_task_per t2,com_task t3
where t1.id = t2.perId and t2.comTaskId = t3.comTaskId
and t2.active = true and t3.taskStatus in ('0','1','6')
) and IFNULL(comTaskFlag,'0') ='0';

update security_person t1
set t1.comTaskFlag = '0',
update_time=NOW()
where not EXISTS(
select 1 from com_task_per t2,com_task t3
where t1.id = t2.perId and t2.comTaskId = t3.comTaskId
and t2.active = true and t3.taskStatus in ('0','1','6')
)and comTaskFlag = '1';

update com_task_per set active = true ,updateTime = createTime;