
as
declare variable F_RESULT D_PRIZNAK;
declare variable F_PR_ERR D_INTEGER; --DECLARE VARIABLE FSEANS_STATUS TYPE OF D_INTEGER;

declare variable EXEC_BLOCK_32_7 type of column EXEC_BLOCKS.EXEC_BLOCKS_TEXT;
declare variable EXEC_32_7_OUTPUT type of D_BIGINT;
begin
  /*
    TIM130324 17:00
  */

  -- APP_EVENT_AIU_FOR_APP_TASK_10: ТРИГГЕР ОБРАБОТКИ ЗАПИСИ СОБЫТИЯ APP_EVENT
  --  (СОЗДАНИЕ, РЕДАКТИРОВАНИЕ, УДАЛЕНИЕ APP_TASK)

  --0. ДЛЯ ПОЧТОВОГО СЕРВЕРА НИЧЕГО НЕ ДЕЛАЕМ
  if (exists(select 1
             from PARSRV A
             where A.PARSRV_VID = 1)) then
    exit;

  --  IF (UPDATING AND (NEW.APP_EVENT_DEL = 1)
  --    AND (NEW.APP_EVENT_DEL IS DISTINCT FROM OLD.APP_EVENT_DEL)) THEN
  --  BEGIN
  --    UPDATE APP_TASK A
  --    SET A.APP_TASK_DEL = 1
  --    WHERE A.ID_APP_TASK = NEW.ID_APP_EVENT;
  --    EXIT;
  --  END
  --УТОЧНИТЬ, ДЛЯ КАКИХ APP_EVENT НЕ НУЖНО СОЗДАВАТЬ APP_TASK!!!
  if (inserting or
      --    (
      updating
      --      AND
      --      (
      --          (NEW.APP_EVENT_DT IS DISTINCT FROM OLD.APP_EVENT_DT)
      --      OR  (NEW.APP_EVENT_TEXT IS DISTINCT FROM OLD.APP_EVENT_TEXT)
      --      OR  (NEW.APP_EVENT_PARAM IS DISTINCT FROM OLD.APP_EVENT_PARAM)
      --      OR  (NEW.APP_EVENT_DATA IS DISTINCT FROM OLD.APP_EVENT_DATA)
      --      OR  (NEW.APP_EVENT_DEL IS DISTINCT FROM OLD.APP_EVENT_DEL)
      --      OR  (NEW.APP_EVENT_CH IS DISTINCT FROM OLD.APP_EVENT_CH)
      --      /* УТОЧНИТЬ !!!
      --      OR  (NEW.APP_EVENT_ID_SOTR IS DISTINCT FROM OLD.APP_EVENT_ID_SOTR)
      --      OR  (NEW.APP_EVENT_ID_REC IS DISTINCT FROM OLD.APP_EVENT_ID_REC)
      --      OR  (NEW.APP_EVENT_VID IS DISTINCT FROM OLD.APP_EVENT_VID)
      --      OR  (NEW.APP_EVENT_TIP IS DISTINCT FROM OLD.APP_EVENT_TIP)
      --      */
      --      )
      --    )
      ) then
  begin
--    if (new.APP_EVENT_VID in (8676, 8677, 8678)) then
--    begin

      --ПЕРЕСЧЕТ ТС В APP_TASK
      select OUT_RESULT, OUT_PR_ERR
      from APP_TASK_WORK(new.ID_APP_EVENT) --ID_APP_EVENT
      into :F_RESULT, :F_PR_ERR;
      --ФОРМИРОВАНИЕ ЗАПИСЕЙ В APP_PARAM
      select OUT_RESULT, OUT_PR_ERR
      from APP_PARAM_WORK(new.ID_APP_EVENT) --ID_APP_EVENT
      into :F_RESULT, :F_PR_ERR;
--    end
--
--    else
--    if (new.APP_EVENT_VID in (8795, 8797)) then
--    begin

      select E.EXEC_BLOCKS_TEXT
      from EXEC_BLOCKS E
      where E.EXEC_BLOCKS_VID = 32 and
            E.EXEC_BLOCKS_TIP = 7 and
            E.EXEC_BLOCKS_DEL = 0 rows 1 to 1
      into :EXEC_BLOCK_32_7;

      if (:EXEC_BLOCK_32_7 is not null) then
      begin

        execute statement(:EXEC_BLOCK_32_7)(IN_ID_APP_EVENT := new.ID_APP_EVENT)
            into :EXEC_32_7_OUTPUT;
      end
--    end
  end
end