i.id, i.batch_id, i.tenant_id, CASE i.change_type WHEN 'REVOKE' THEN 'yichexiao' ELSE 'yishixiao' END operation, b.audit_id application_id, b.flow_id, b.task_id, i.source_row_id, i.file_id, i.business_version_id, i.source_file_id, i.source_version_id, i.document_id, i.file_version_id, i.folder_id, i.requested_at, b.approved_at, i.scheduled_at, b.actor_id, i.status, i.executed_at disabled_at, b.lease_token, b.attempts, b.last_error public.dms_approved_file_items i JOIN public.dms_approved_file_batches b ON b.tenant_id=i.tenant_id AND b.id=i.batch_id b.audit_type IN ('chexiao_shenqing','shixiao_shenqing') AND i.change_type IN ('REVOKE','INVALIDATE') public.dms_wenjian_chexiao_tiyipublic.dms_wenjian_shixiao_shenqing public.dms_wenjian_chexiao_tiyi_zixiangpublic.dms_wenjian_shixiao_shenqing_zixiang INSERT INTO public.dms_approved_file_items (id,batch_id,tenant_id,source_key,source_row_id,change_type,file_id,business_version_id,source_file_id,source_version_id, document_id,file_version_id,folder_id,requested_at,scheduled_at,status) VALUES (#{id,jdbcType=OTHER,typeHandler=jnpf.dmsDatabase.DmsUuidTypeHandler}, #{batchId,jdbcType=OTHER,typeHandler=jnpf.dmsDatabase.DmsUuidTypeHandler},#{tenantId}, CAST(#{batchId,jdbcType=OTHER,typeHandler=jnpf.dmsDatabase.DmsUuidTypeHandler} AS text) || ':' || #{sourceRowId},#{sourceRowId}, CASE WHEN #{operation}='yichexiao' THEN 'REVOKE' ELSE 'INVALIDATE' END, #{fileId},#{businessVersionId},#{sourceFileId},#{sourceVersionId}, #{documentId,jdbcType=OTHER,typeHandler=jnpf.dmsDatabase.DmsUuidTypeHandler}, #{fileVersionId,jdbcType=OTHER,typeHandler=jnpf.dmsDatabase.DmsUuidTypeHandler}, #{folderId,jdbcType=OTHER,typeHandler=jnpf.dmsDatabase.DmsUuidTypeHandler},#{requestedAt},#{scheduledAt},'WAITING') UPDATE public.dms_approved_file_batches b SET status=CASE WHEN p.remaining=0 THEN 'APPLIED' ELSE 'WAITING' END, scheduled_at=COALESCE(p.next_date,b.scheduled_at) FROM (SELECT count(*) total,count(*) FILTER (WHERE status<>'APPLIED') remaining, min(scheduled_at) FILTER (WHERE status<>'APPLIED') next_date FROM public.dms_approved_file_items WHERE tenant_id=#{tenantId} AND batch_id=#{id,jdbcType=OTHER,typeHandler=jnpf.dmsDatabase.DmsUuidTypeHandler} AND change_type IN ('REVOKE','INVALIDATE')) p WHERE b.tenant_id=#{tenantId} AND b.id=#{id,jdbcType=OTHER,typeHandler=jnpf.dmsDatabase.DmsUuidTypeHandler} AND b.audit_type IN ('chexiao_shenqing','shixiao_shenqing') AND b.lease_token=#{leaseToken} AND p.total>0