-- 通过流程实例id,删除运行中的任务和历史相关数据
CREATE OR REPLACE FUNCTION public.f_delete_act_data_by_processid(_processid text)
RETURNS void
LANGUAGE plpgsql
AS $function$
begin
delete from act_ru_actinst where proc_inst_id_ =_processId;
delete from act_ru_identitylink where proc_inst_id_ =_processId;
delete from act_ru_task where proc_inst_id_ =_processId;
delete from act_ru_variable where proc_inst_id_ =_processId;
delete from act_ru_execution where proc_inst_id_ =_processId;
delete from act_hi_actinst where proc_inst_id_ =_processId ;
delete from act_hi_comment where proc_inst_id_ =_processId ;
delete from act_hi_identitylink where proc_inst_id_ =_processId ;
delete from act_hi_procinst where proc_inst_id_ =_processId ;
delete from act_hi_taskinst where proc_inst_id_ =_processId ;
delete from act_hi_varinst where proc_inst_id_ =_processId ;
end;
$function$
;
-- 通过项目id,删除项目,及关联的任务,任务日志,流程等相关数据
CREATE OR REPLACE FUNCTION public.f_delete_project_all_by_id(_projectid integer)
RETURNS integer
LANGUAGE plpgsql
AS $function$
begin
-- 先删除流程信息,掉上面自定义函数的函数
execute format('select f_delete_act_data_by_processId(process_id) from base_task_info
where project_id ='||_projectId||' and process_id is not null');
-- 再删除业务信息
execute format( 'delete from base_task_log where project_id ='||_projectId||' ') ;
execute format( 'delete from base_task_info where project_id ='||_projectId||' ') ;
execute format( 'delete from base_project_info where id ='||_projectId||' ') ;
return 1;
end;
$function$
;