Различия

Здесь показаны различия между двумя версиями данной страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
расширенная.настройка:рассылка.уведомлений:push [2018/08/23 11:39]
a.korobka
расширенная.настройка:рассылка.уведомлений:push [2019/07/04 08:22] (текущий)
Строка 238: Строка 238:
 </​spoiler>​ </​spoiler>​
  
-<​spoiler|Скрипт+Скрипт ​выполняется раз в день и указан на [[:администрирование:скрипты:​фбд:Push - повторная явка|отдельной странице]]
-<code sql> +
-execute block +
-as +
--- константы +
-declare ttl int;   +
-declare day_delay int;   +
-declare cnt int;      +
-declare uid type of column doctor.dcode;​ +
--- данные пациента ​  +
-declare notify type of column clphones.notificationid;​  +
-declare pcode type of column clients.pcode;​ +
--- данные приема ​       +
-declare treatcode type of column treat.treatcode;​ +
-declare return_date date; +
-declare fjid type of column filials.jid;​ +
-declare filial type of column filials.filid;​ +
-declare fname type of column filials.shortname; ​  +
-declare depnum type of column departments.depnum;​ +
-declare depname type of column departments.depname;​ +
-declare dcode type of column doctor.dcode;​ +
-declare dname type of column doctor.dname;​  +
-declare dcode_send type of column doctor.dcode; ​  +
--- данные ​по услуге    +
-declare spec int; +
-declare schid type of column wschema.schid;​ +
-declare worktime int; +
-declare structid type of column wschema.structid;​ +
--- вставка ​сообщения +
-declare logid type of column sms_log.logid;​ +
-declare smsid type of column sms_logdet.smsid;​ +
-declare smstypeid type of column sms_log.smstypeid;​ +
-declare smsrefid type of column sms_log.smsrefid;​ +
-declare smsprofileid type of column sms_log.smsprofileid; ​  +
-declare pushtext type of column sms_log.smstext;​ +
-declare planbtime type of column sms_log.planbtime;​ +
-declare planftime type of column sms_log.planftime;​ +
--- процедура поиска +
-declare procedure prc_datelist +
-returns ( +
-  treatdate type of column paramsinfo.treatdate,​ +
-  treatcode type of column paramsinfo.treatcode,​ +
-  pcode type of column clients.pcode,​ +
-  dcode type of column doctor.dcode,​ +
-  return_date date +
-+
-as +
-declare txt type of column paramsinfo.valuetext;​ +
-declare p1 int; +
-declare tmp type of column paramsinfo.valuetext;​ +
--- +
-declare date_litera ttext16; +
-declare date_interv int; +
--- +
-begin +
-  for select lower(trim(valuetext)),​ treatdate, treatcode, pcode, dcode from paramsinfo p +
-       where p.codeparams in (990001860/​* повторная явка */,​990002043/​*гастро*/,​ +
-                              990001689/​*аллерг-1*/,​990001823/​*аллерг-2*/,​ +
-                              990001748/*невро*/,​640000067/​*берем*/,​ +
-                              990002216/​*офтальм*/) +
-         and p.ver_no = 0 +
-         and p.treatdate between current_date-370 and current_date +
-         and trim(valuetext)!=''​ +
-         and valuetext not like '%за результатами анализ%'​ +
-  into txt, treatdate, treatcode, pcode, dcode do +
-  begin +
-    return_date = null; +
-    date_interv = 0; +
-    -- +
-    while (position(' ​ ', txt)>0) do +
-    begin +
-      txt = replace(txt,​ ' ​ ', ' '); +
-    end +
- +
-    -- первым ​указано `через N период` +
-    if (position('​через ', txt)=1) then +
-    begin +
-      -- отсекаем 1е слово +
-      tmp = trim(substring(txt from 6)); +
-      -- иищем ​начало 2го слова +
-      p1 = position('​ ', tmp); +
-      if (p1>0) then +
-      begin +
-        begin +
-          date_interv = trim(substring(tmp from 1 for p1)); +
-          date_litera = trim(substring(tmp from p1 for 6)); +
-        end +
-        when any do begin end +
-      end +
-      -- +
-      if (date_interv>​0) then +
-      begin +
-        return_date = case when date_litera like 'год%' then dateadd(date_interv year to treatdate) +
-                           when date_litera like 'мес%' then dateadd(date_interv month to treatdate) +
-                           when date_litera like '​нед%'​ then dateadd(date_interv week to treatdate) +
-                           when date_litera like '​дн%' ​ then dateadd(date_interv day to treatdate) +
-                           when date_litera like '​ден%'​ then dateadd(date_interv day to treatdate) +
-                           else null end; +
-      end +
-    end +
- +
-    -- первой указана дата +
-    else +
-    begin +
-      --ret_date= current_date;​ +
-      tmp = substring(txt from 1 for 10); +
-      begin +
-        begin +
-          return_date = cast(tmp as date); +
-        end +
-        when any do begin end +
-      end +
- +
-      tmp = substring(txt from 1 for 8); +
-      if (return_date is null) then +
-      begin +
-        begin +
-          return_date = cast(tmp as date); +
-        end +
-        when any do begin end +
-      end +
- +
-    end +
-    -- +
-    if (return_date is not null) then +
-      suspend; +
-    -- +
-  end +
-end +
--- end prc_datelist +
--- +
-begin +
-  day_delay = 1; -- приглашать за 1 день минимум +
-  ttl = day_delay*24*60*60;​ -- напоминание ​держится (расчет на отправку сразу) +
-  uid = null;   +
-  -- филиал выполнения +
-  select first 1 f.filid, f.shortname,​ f.jid +
-    from repl$getgrpid g +
-    left join filials f on f.grpid=g.repl$grpid +
-    into filial, fname, fjid; +
-  -- поиск структуры +
-  select first 1 structid from pricestructure +
-   where bdate<​= ​:return_date order by bdate desc +
-    into structid; +
-  -- +
-  for select tx.pcode, tx.dcode, tx.return_date,​ tx.treatcode,​ cp.notificationid +
-        from prc_datelist tx +
-        left join clphones cp on cp.pcode=tx.pcode +
-       where tx.return_date between current_date+ :day_delay and current_date+1+ :​day_delay +
-         and coalesce(cp.isdeleted,​0)=0 and cp.phonetype=21 +
-  into pcode, dcode, return_date,​ treatcode, notify do +
-  begin +
-    pushtext = null;    +
-    schid = null; +
-    dcode_send = null; +
-    -- беру специализацию +
-    select first 1 ws.speccode from treat t +
-      join orderdet od on od.orderno=t.orderno +
-      join wschema ws on ws.schid=od.schcode +
-     where t.treatcode= :​treatcode +
-       and ws.consult=1 +
-      into spec; +
-    -- смотрю наличие записей к доктору +
-    select count(*) +
-      from doctor d +
-      left join USER$WEB__DOCTOR_WSCHEMA(d.dcode,​ null, :spec) u on 1=1 +
-      left join schedule s on s.workdate= :​return_date and s.dcode=d.dcode +
-     where d.filial= :​filial ​   +
-       and coalesce(d.locked,​0)=0 +
-       and u.avalue=1 +
-       and s.pcode= :pcode +
-      into cnt; +
-    ​-- готовлю сообщение +
-    if (cnt=0) then +
-    begin +
-      -- поиск услуги (повторной) +
-      select first 1 ws.schid +
-        from wschema ws +
-        left join get_pricebyid(:​return_date,​ 1, :filial, :fjid, 0, ws.schid) s on 1=1 +
-       where ws.structid= :structid and ws.speccode= :spec and ws.repconsult=1 ​ /* повторная ​*/ +
-         and s.sprice>​0 +
-       order by rand() +
-        into schid; +
-      if (schid is null) then   +
-        select first 1 ws.schid +
-          from wschema ws +
-          left join get_pricebyid(:​return_date,​ 1, :filial, :fjid, 0, ws.schid) s on 1=1 +
-         where ws.structid= :structid and ws.speccode= :spec and ws.consult=1 ​  /* первичная - повторной нет */ +
-           and s.sprice>​0 +
-         order by rand() +
-          into schid; +
-      -- поиск доктора, с учетом услуги +
-      select first 1 dcode, worktime from ( +
-             ​select d.dcode, coalesce(ws.worktime,​ dic.rekvint3) worktime, +
-                    (ds.endhour*60+ds.endmin) - (ds.beghour*60+ds.begmin) alltime, +
-                    (select sum(case when pcode>0 or nazndis=1 then (s.fhour*60+s.fmin)-(s.bhour*60+s.bmin) else 0 end ) +
-                       from schedule s left join shedmarks m on m.mrkid=s.tmstatus where s.schedident=ds.schedident) denytime +
-               from doctor d                           +
-               join doctshedule ds on ds.dcode=d.dcode and ds.wdate= :​return_date ​  +
-               join wschema ws on ws.schid= :schid +
-               left join USER$WEB__DOCTOR_WSCHEMA(d.dcode,​ ws.schid) u on 1=1 +
-               left join dicinfo dic on dic.refid=-10010011 and dic.dcode=d.dcode and dic.rekvint1=ws.schid +
-              where d.filial= :filial and coalesce(d.locked,​0)=0 and u.avalue=1) +
-       where alltime>​denytime /* есть время для записи */ +
-         and alltime-denytime > worktime +
-       order by case when :dcode = dcode then 0 else 1 end,  alltime-denytime desc, rand() +
-        into dcode_send, worktime; +
-      -- возможность формирования +
-      if (schid is not null and dcode_send is not null) then +
-      begin +
-        -- данные +
-        select d.dname, dep.depnum, dep.depname +
-          from doctor d +
-          left join departments dep on dep.depnum=d.depnum +
-         ​where ​ d.dcode= :​dcode_send +
-          into dname, depnum, depname; +
-        -- формирование текста +
-        pushtext = '​{"​to":"'​||notify||'","​time_to_leave":'​||ttl||',"​notification":​{';​ +
-        pushtext = pushtext||'"​title":"​Приглашение","​body":"​Приглашаем Вас на повторный прием к доктору.",';​ +
-        pushtext = pushtext||'"​sound":"​true","​tag":"​record"​},';​ +
-        pushtext = pushtext||'"​data":​{"​action":"​record",';​ +
-        pushtext = pushtext||'"​DCode":'​||dcode_send||',"​DName":"'​||dname||'",';​ +
-        pushtext = pushtext||'"​DepNum":'​||depnum||',"​DepName":"'​||depname||'",';​ +
-        pushtext = pushtext||'"​filial":'​||filial||',"​FName":"'​||fname||'",';​ +
-        pushtext = pushtext||'"​WorkDate":"'​||(select datestr from formatdate(:​return_date))||'",';​ +
-        pushtext = pushtext||'"​SchList":"'​||schid||'","​wtime":"'​||worktime||'",';​ +
-        pushtext = pushtext||'​}}';​ +
-        -- заполняем данные +
-        logid = gen_id(SMS_LOG_GEN,​ 1); +
-        smsid = gen_id(SMS_GEN,​ 1); +
-        smstypeid = 0; +
-        smsprofileid = 1; +
-        smsrefid = 70005; +
-        planbtime = dateadd(9 hour to cast(current_date as timestamp));​ +
-        planftime = dateadd(18 hour to cast(return_date as timestamp));​ +
-        -- вставляем запись +
-        insert into sms_log(logid,​smstypeid,​smsrefid,​smsprofileid,​filial,​ +
-                    createdate,​smstext,​pcode,​uid,​internalid,​planbtime,​planftime,​state) +
-             ​values(:​logid,​ :smstypeid, :smsrefid, :​smsprofileid,​ :filial, +
-                    current_timestamp,​ :pushtext, :pcode, :uid, :treatcode, :planbtime, :planftime, 0); +
-        insert into sms_logdet(smsid,​logid,​phonetype,​extsmsid,​phprefix,​phone,​state,​notificationid) +
-             ​values(:​smsid,​ :logid, 21, null, null, null, 0, :notify); +
-      end +
-      -- +
-    end +
-    -- +
-    suspend; +
-  end +
-end +
-</​code> ​     +
-</​spoiler> ​                      +
  
 ==== Результат исследования ==== ==== Результат исследования ====

расширенная.настройка/рассылка.уведомлений/push.1535013590.txt.gz · Последние изменения: 2018/08/23 11:39 — a.korobka