23279 логи почты

This commit is contained in:
mirzakaev_tf 2024-11-22 10:39:40 +05:00
parent 54ff9c2221
commit fc20209598
9 changed files with 342 additions and 221 deletions

View File

@ -175,7 +175,7 @@
limit 1 limit 1
) )
``` ```
<!-- ### Примеры запросов ### Примеры запросов
#### Просроченные документы #### Просроченные документы
@ -226,6 +226,8 @@
??? note "Запрос" ??? note "Запрос"
![alt text](media/image-24.png)
Основной запрос: Основной запрос:
Итоговая выборка: Итоговая выборка:
@ -299,6 +301,8 @@
??? note "Запрос" ??? note "Запрос"
![alt text](media/image-25.png)
Основной запрос: Основной запрос:
Итоговая выборка: Итоговая выборка:
@ -333,6 +337,8 @@
??? note "Запрос" ??? note "Запрос"
![alt text](media/image-26.png)
Основной запрос: Основной запрос:
Итоговая выборка: Итоговая выборка:
@ -366,6 +372,8 @@
??? note "Запрос" ??? note "Запрос"
![alt text](media/image-27.png)
Основной запрос: Основной запрос:
```sql ```sql
@ -603,6 +611,8 @@
??? note "Запрос" ??? note "Запрос"
![alt text](media/image-29.png)
Основной запрос: Основной запрос:
```sql ```sql
@ -1235,4 +1245,103 @@
join comdoc."VFilials" f on p."COrg" = f."VCode" join comdoc."VFilials" f on p."COrg" = f."VCode"
where now()::date between coalesce(p."BeginDate",'19700101') and coalesce(p."EndDate",'20700101') where now()::date between coalesce(p."BeginDate",'19700101') and coalesce(p."EndDate",'20700101')
; ;
``` --> ```
#### Аналитическая форма по расписанию задач
??? note "Запрос"
![alt text](media/image-28.png)
Основной запрос:
```sql
INSERT INTO "tmp_calcWithBaseParams_for_documentStatusJournalProc"( "DocCode" )
select null;
```
Итоговая выборка:
```sql
insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName", "DocName", "DocumentDate",
"AnyColumnA" , "AnyColumnB" , "AnyColumnC" , "AnyColumnD" , "AnyColumnE",
"AnyColumnF", "AnyColumnG", "AnyColumnH", "AnyColumnI", "AnyColumnJ")
select dd."Id", 'task'::text, 'taskForm'::text, ('Шедулер' || dd."Name")::text, 'Планировщик задач ' ||dd."Name" , dd."CDate"::date,
dd."Name" as "AnyColumnA" , dd."Description" as "AnyColumnB" ,
dd."Minutes" as "AnyColumnC" , dd."Hours" as "AnyColumnD" , dd."Days" as "AnyColumnE" , dd."Months" as "AnyColumnF" , dd."DaysOfTheWeek" as "AnyColumnG" ,dd. "Note" as "AnyColumnH" ,dd. "TypeTask" as "AnyColumnI"
, sum(comdoc."datediff"('minute',j."TimeStart" , j."TimeEnd"))/ count(j."Id") as "AnyColumnJ"
from (
select t."Id", t."Name", t."Description",
sh."Crontab",
max(case when s."VCode" = 1 then s."PartString" else '' end) as "Minutes",
max(case when s."VCode" = 2 then s."PartString" else '' end) as "Hours",
max(case when s."VCode" = 3 then s."PartString" else '' end) as "Days",
max(case when s."VCode" = 4 then s."PartString" else '' end) as "Months",
max(case when s."VCode" = 5 then s."PartString" else '' end) as "DaysOfTheWeek",
'по гринвичу' as "Note", 'Шедулер' as "TypeTask", t."CDate"
from lex."Task" t
join lex."Schedule" sh on t."Id" = sh."Parent"
LEFT JOIN LATERAL comdoc."LexStringToListNew"(replace(sh."Crontab",' ','Ё'),'Ё',0) s on true
join (select 1 as "VCode", 'мин.' as "Name"
union all
select 2 as "VCode", 'часы' as "Name"
union all
select 3 as "VCode", 'день' as "Name"
union all
select 4 as "VCode", 'месяц' as "Name"
union all
select 5 as "VCode", 'дни недели' as "Name"
) d on s."VCode" = d."VCode"
-- inner join lex."StepJournalEntryDetail" s on j."Id" = s."PCode"
where coalesce(t."Toggle",false) = true
group by t."Id", t."Name", t."Description", sh."Crontab", t."CDate"
)dd
left join lex."TaskJournalEntry" j on dd."Id" = j."TaskId" and j."TimeStart">= now()::date - '1 month'::interval and j."TimeEnd" is not null
--where j."TimeStart">= now()::date - '1 month'::interval and j."TimeEnd" is not null
group by dd."Id", dd."Name", dd."Description", dd."Crontab", "Minutes", "Hours", "Days", "Months", "DaysOfTheWeek", "Note", "TypeTask", dd."CDate"
union all
select t."VCode", 'NotificationLexemaDirectory'::text, 'NotificationLexemaDirectoryForm'::text , '', ( 'Задачи планировщика ' ||t."TaskName") ::text, t."CDate"::date,
t."TaskName" as "AnyColumnA" , null::text as "AnyColumnB" ,
t."Minutes" as "AnyColumnC" , t."Hours" as "AnyColumnD" , t."Days" as "AnyColumnE" , t."Months" as "AnyColumnF" , t."DaysOfTheWeek" as "AnyColumnG" ,'серверное время' as "AnyColumnH" ,'Задачи планировщика' as "AnyColumnI",
null::int as "AnyColumnJ"
from dfd."NotificationLexemaDirectory" t
where coalesce(t."Included",false) = true;
```
#### Логи отправки почты и СМС
Необходимо дополнительно настроить [задачу планировщика](../Функции%20планировщика%20задач/#переносогов_отправки_почты_и_смс_в_таблицу_sendlog)
??? note "Запрос"
![alt text](media/image-30.png)
Основной запрос:
```sql
INSERT INTO "tmp_calcWithBaseParams_for_documentStatusJournalProc"( "DocCode")
select 1 from dfd."OutgoingEmailLog" where 1 = 1
limit 1;
```
Итоговая выборка:
```sql
do $myQ$
declare _str text;
begin
_str := '
insert into "tmp_finresult"("AnyColumnA", "AnyColumnB", "AnyColumnC", "AnyColumnD", "AnyColumnE", "AnyColumnF", "AnyColumnG", "AnyColumnH", "AnyColumnI", "AnyColumnJ", "AnyColumnK", "AnyColumnL", "AnyColumnM")
select p."Level", p."type", p."To", p."Subject", p."Body", p."Cc", p."Bcc", p."phones", p."text", p."errorText",
to_char(p."CDateLog",''DD.MM.YYYY hh:mi'') as "CDateLog", p."CUserLog", p."CHostLog"
from comdoc."SendLog" p
where coalesce( p."CDateLog"::date,'_bdate'::date) between '_bdate'::date and '_edate'::date
order by p."CDateLog" desc'
_topcount ;
execute _str;
end;
$myQ$;
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -255,16 +255,18 @@ search:
### Документы, не пришедшие из 1с ### Документы, не пришедшие из 1с
```sql ??? Задача
with "no1c"
as ```sql
(select r."COrgName" , 'таб.№ ' || r."NumTab"|| ' ' || r."Workers" as "Workers" ,r."PostWorkers" , with "no1c"
as
(select r."COrgName" , 'таб.№ ' || r."NumTab"|| ' ' || r."Workers" as "Workers" ,r."PostWorkers" ,
r."name1c" || ' По заявлению № ' || r."DocumentNumber" || ' от ' || to_char( "DocumentDate"::date, 'DD.MM.YYYY') as "name1c" r."name1c" || ' По заявлению № ' || r."DocumentNumber" || ' от ' || to_char( "DocumentDate"::date, 'DD.MM.YYYY') as "name1c"
, l."link_txt" || '#/view/'|| r."TypeName" ||'Form' ||'/' || r."VCode" as "link" , l."link_txt" || '#/view/'|| r."TypeName" ||'Form' ||'/' || r."VCode" as "link"
from odata."getExchange1CGuidsRegistry"(null, null, (now()::date+ '-45 day'::interval)::date , (now()::date+ '-3 day'::interval)::Date , null) r from odata."getExchange1CGuidsRegistry"(null, null, (now()::date+ '-45 day'::interval)::date , (now()::date+ '-3 day'::interval)::Date , null) r
cross join (select "LocationProtocol" || '//' || "LocationHostName" as "link_txt" from comdoc."DocflowSettings") l cross join (select "LocationProtocol" || '//' || "LocationHostName" as "link_txt" from comdoc."DocflowSettings") l
where where
coalesce( "DeletionMark",'false') = 'false ' and coalesce( "DeletionMark",'false') = 'false ' and
r."VCode" is not null and r."VCode" is not null and
r."DFS_VCode" is null and r."DFS_VCode" is null and
r."guid" is not null and r."guid" is not null and
@ -281,20 +283,20 @@ coalesce( "DeletionMark",'false') = 'false ' and
r. "DocumentDate" <= now()::date+ '-3 day'::interval r. "DocumentDate" <= now()::date+ '-3 day'::interval
) )
insert into "#forInsNotification" ("DocflowUser", "txt", "Link", "DocType", "DocName", "DocSubject", "IdWorker") insert into "#forInsNotification" ("DocflowUser", "txt", "Link", "DocType", "DocName", "DocSubject", "IdWorker")
select distinct 'Personnel' as "DocflowUser" , select distinct 'Personnel' as "DocflowUser" ,
--rlU."DocflowUser" , --rlU."DocflowUser" ,
'Следующие документы не пришли на подписание из 1С : <br/>' || 'Следующие документы не пришли на подписание из 1С : <br/>' ||
replace( replace(
replace(replace( replace(replace(
'<table style = "border-collapse:collapse"> '<table style = "border-collapse:collapse">
<tr> <tr>
<th style="text-align:center; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Организация</th> <th style="text-align:center; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Организация</th>
<th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Работник</th> <th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Работник</th>
<th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Должность</th> <th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Должность</th>
<th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Документ</th> <th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Документ</th>
</tr>'|| </tr>'||
(SELECT DISTINCT string_agg(x."Body", '') (SELECT DISTINCT string_agg(x."Body", '')
FROM(select '<tr><td style="text-align:center; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black">'|| coalesce(p2."COrgName",'')||'</td> FROM(select '<tr><td style="text-align:center; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black">'|| coalesce(p2."COrgName",'')||'</td>
<td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black;">'||coalesce(p2."Workers",'')||'</td> <td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black;">'||coalesce(p2."Workers",'')||'</td>
<td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black;">'||coalesce(p2."PostWorkers",'')||'</td> <td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black;">'||coalesce(p2."PostWorkers",'')||'</td>
@ -304,46 +306,47 @@ replace(replace(
</tr>' as "Body" from "no1c" p2 </tr>' as "Body" from "no1c" p2
order by p2."COrgName", p2."Workers" ) x)||'</table>' order by p2."COrgName", p2."Workers" ) x)||'</table>'
,'&lt;','<'),'&gt;','>'), ,'&lt;','<'),'&gt;','>'),
'&amp;','&') as txt, '&amp;','&') as txt,
null::bigint as "link", 'Первичный документ', 'Первичный документ', null::bigint as "link", 'Первичный документ', 'Первичный документ',
'Информационное сообщение о документах, не пришедших из 1С', 'Информационное сообщение о документах, не пришедших из 1С',
null::bigint as "IdWorker" null::bigint as "IdWorker"
from "no1c" dd from "no1c" dd
/*join comdoc."ReadListGroup" rl on rl."Name" = 'Кадровики для рассылки документов, не пришедших из 1С' /*join comdoc."ReadListGroup" rl on rl."Name" = 'Кадровики для рассылки документов, не пришедших из 1С'
and rl."DocTypes" ilike '%NotificationLexema%' and rl."DocTypes" ilike '%NotificationLexema%'
join comdoc."ReadListGroupUsers" rlU on rl."VCode" = rlU."PCode"*/ join comdoc."ReadListGroupUsers" rlU on rl."VCode" = rlU."PCode"*/
--group by rlU."DocflowUser" --group by rlU."DocflowUser"
```
```
### Задача по изменению фамилии в карточке пользователя + склонение в карточке физического лица ### Задача по изменению фамилии в карточке пользователя + склонение в карточке физического лица
```sql ??? Задача
do $$
begin ```sql
IF NOT comdoc."isTableExists"('#fio', 'temp') THEN do $$
begin
IF NOT comdoc."isTableExists"('#fio', 'temp') THEN
CREATE TEMP TABLE "#fio"("Id" bigint, "OldFam" text, "OldName" text, "OldOtch" text, CREATE TEMP TABLE "#fio"("Id" bigint, "OldFam" text, "OldName" text, "OldOtch" text,
"IdPerson" bigint, "NewFam" varchar(255), "NewName" varchar(255), "NewOtch" varchar(255), "UserName" varchar(255), "Code" varchar(2550) "IdPerson" bigint, "NewFam" varchar(255), "NewName" varchar(255), "NewOtch" varchar(255), "UserName" varchar(255), "Code" varchar(2550)
) ON COMMIT DROP; ) ON COMMIT DROP;
END IF; END IF;
insert into "#fio" insert into "#fio"
select m."Id",m."LastName", m."FirstName", m."MiddleName", per."VCode", per."Family", per."Name", per."Father", m."UserName" , c."Code" select m."Id",m."LastName", m."FirstName", m."MiddleName", per."VCode", per."Family", per."Name", per."Father", m."UserName" , c."Code"
from lex."UserMeta" m from lex."UserMeta" m
join rp."RP_PersonContact" c on c."IdTypeContact" = 6 and m."UserName" = c."Code" join rp."RP_PersonContact" c on c."IdTypeContact" = 6 and m."UserName" = c."Code"
join rp."RP_Person" per on per."VCode" = c."Pcode" join rp."RP_Person" per on per."VCode" = c."Pcode"
where (lower(coalesce(m."LastName",''))<> lower(coalesce(per."Family",'')) or lower(coalesce(m."FirstName",''))<> lower(coalesce(per."Name",'')) where (lower(coalesce(m."LastName",''))<> lower(coalesce(per."Family",'')) or lower(coalesce(m."FirstName",''))<> lower(coalesce(per."Name",''))
or lower(coalesce(m."MiddleName",''))<>lower(coalesce(per."Father",''))) or lower(coalesce(m."MiddleName",''))<>lower(coalesce(per."Father",'')))
and (select count(a."Pc") from (select distinct c."Pcode" as "Pc" from rp."RP_PersonContact" c and (select count(a."Pc") from (select distinct c."Pcode" as "Pc" from rp."RP_PersonContact" c
join rp."RP_Person" per on per."VCode" = c."Pcode" join rp."RP_Person" per on per."VCode" = c."Pcode"
where c."Code" =m."UserName")a) =1; where c."Code" =m."UserName")a) =1;
update lex."UserMeta" m set "LastName" = q."NewFam", "FirstName" = q."NewName", "MiddleName" = q."NewOtch" update lex."UserMeta" m set "LastName" = q."NewFam", "FirstName" = q."NewName", "MiddleName" = q."NewOtch"
from "#fio" q from "#fio" q
where q."Id" = m."Id"; where q."Id" = m."Id";
update rp."RP_Person" per set "Note" = case when per."Note" is not null then per."Note" ||' update rp."RP_Person" per set "Note" = case when per."Note" is not null then per."Note" ||'
' else '' end ||to_char(now(),'DD.MM.YYYY') ' else '' end ||to_char(now(),'DD.MM.YYYY')
|| (select ' изменено ФИО с '||coalesce(f."OldFam",'')||' '||coalesce(f."OldName",'')||' '||coalesce(f."OldOtch",'')||' на ' || (select ' изменено ФИО с '||coalesce(f."OldFam",'')||' '||coalesce(f."OldName",'')||' '||coalesce(f."OldOtch",'')||' на '
||coalesce(f."NewFam",'')||' '||coalesce(f."NewName",'')||' '||coalesce(f."NewOtch",'')from "#fio" f where f."IdPerson" = per."VCode" limit 1), ||coalesce(f."NewFam",'')||' '||coalesce(f."NewName",'')||' '||coalesce(f."NewOtch",'')from "#fio" f where f."IdPerson" = per."VCode" limit 1),
"FNFAccusative" = comdoc."Lexsklon"(per."Family", per."Name", per."Father", case when per."Sex" = 1 then 'Ж' else 'M' end, 1), "FNFAccusative" = comdoc."Lexsklon"(per."Family", per."Name", per."Father", case when per."Sex" = 1 then 'Ж' else 'M' end, 1),
@ -353,37 +356,41 @@ update rp."RP_Person" per set "Note" = case when per."Note" is not null then per
where per."VCode" = q."IdPerson"; where per."VCode" = q."IdPerson";
end; end;
$$; $$;
``` ```
### Оповещение о необходимости замены паспорта ### Оповещение о необходимости замены паспорта
```sql ??? Задача
insert into "#forInsNotification" ("DocflowUser", "txt", "Link", "DocType", "DocName", "DocSubject", "IdWorker")
select distinct pc."Code" , '<font size="3"> <b>Настоящим сообщаем, что приближается срок замены паспорта </b> <br/>' || '</font>' , ```sql
insert into "#forInsNotification" ("DocflowUser", "txt", "Link", "DocType", "DocName", "DocSubject", "IdWorker")
select distinct pc."Code" , '<font size="3"> <b>Настоящим сообщаем, что приближается срок замены паспорта </b> <br/>' || '</font>' ,
null::bigint as "link", '', '', null::bigint as "link", '', '',
'Инф. сообщение о замене паспорта', 'Инф. сообщение о замене паспорта',
w."VCode" as "IdWorker" w."VCode" as "IdWorker"
from rp."RP_Person" p from rp."RP_Person" p
join rp."RP_Worker" w on p."VCode" = w."IdPerson" join rp."RP_Worker" w on p."VCode" = w."IdPerson"
left join rp."RP_WorkerMove" wm on w."VCode" = wm."IdWorker" and now() between coalesce(wm."DateBeg", '20010101') and coalesce(wm."DateEnd", '20700101') left join rp."RP_WorkerMove" wm on w."VCode" = wm."IdWorker" and now() between coalesce(wm."DateBeg", '20010101') and coalesce(wm."DateEnd", '20700101')
left join comdoc."Department" dep on wm."IdDepartment" = dep."VCode" left join comdoc."Department" dep on wm."IdDepartment" = dep."VCode"
left join rp."RP_Post" post on wm."IdPost" = post."VCode" left join rp."RP_Post" post on wm."IdPost" = post."VCode"
left join rp."RP_PersonContact" pc on p."VCode" = pc."Pcode" and pc."IdTypeContact" = 6 left join rp."RP_PersonContact" pc on p."VCode" = pc."Pcode" and pc."IdTypeContact" = 6
LEFT JOIN LATERAL comdoc."getAccountingConstantValues"(w."COrg", 'СЭД_Уведомления_Сообщения_оамене_паспорта', NULL) cv on true LEFT JOIN LATERAL comdoc."getAccountingConstantValues"(w."COrg", 'СЭД_Уведомления_Сообщения_оамене_паспорта', NULL) cv on true
where ( where (
now() between p."DateBirth" - (coalesce(cv."valueConst",30) || ' day')::interval + (date_part('year',age(p."DateBirth"))+1 || 'year')::interval and now() between p."DateBirth" - (coalesce(cv."valueConst",30) || ' day')::interval + (date_part('year',age(p."DateBirth"))+1 || 'year')::interval and
p."DateBirth" + (date_part('year',age(p."DateBirth"))+1 || 'year')::interval and p."DateBirth" + (date_part('year',age(p."DateBirth"))+1 || 'year')::interval and
date_part('year',age(p."DateBirth" - (coalesce(cv."valueConst",30) || ' day')::interval ))::int in (20,45) date_part('year',age(p."DateBirth" - (coalesce(cv."valueConst",30) || ' day')::interval ))::int in (20,45)
) or w."VCode" = 53 ) or w."VCode" = 53
``` ```
### Оповещение о списке работников, которые не создали заявление об отпуске из уведомления ### Оповещение о списке работников, которые не создали заявление об отпуске из уведомления
```sql ??? Задача
with list as (
select ud."VCode", ud."IdWorker", atr."Value" as "Vacation", to_char(atrD."DateValue",'DD.MM.YYYY') as "DateBeg" , f."Name" as "COrgName" ```sql
with list as (
select ud."VCode", ud."IdWorker", atr."Value" as "Vacation", to_char(atrD."DateValue",'DD.MM.YYYY') as "DateBeg" , f."Name" as "COrgName"
from dfd."UniversalDocument" AS ud from dfd."UniversalDocument" AS ud
join dfd."DocumentConstructor" dc on ud."DocumentCategory" = dc."VCode" join dfd."DocumentConstructor" dc on ud."DocumentCategory" = dc."VCode"
join dfd."DocumentSubtype" ds on dc."DocumentSubtype" = ds."VCode" join dfd."DocumentSubtype" ds on dc."DocumentSubtype" = ds."VCode"
@ -393,7 +400,7 @@ select ud."VCode", ud."IdWorker", atr."Value" as "Vacation", to_char(atrD."DateV
join dfd."DocumentAdditionalAttribute" atrD on ud."VCode" = atrD."PCode" join dfd."DocumentAdditionalAttribute" atrD on ud."VCode" = atrD."PCode"
join dfd."DocumentCategoryAttributeType" atrtypeD on atrD."CategoryAttributeType" = atrtypeD."VCode" and ud."DocumentCategory" = atrtypeD."PCode" and join dfd."DocumentCategoryAttributeType" atrtypeD on atrD."CategoryAttributeType" = atrtypeD."VCode" and ud."DocumentCategory" = atrtypeD."PCode" and
atrtypeD."AttributeType" = 'Date' and atrtypeD."ColumnName" = '#bdate#' atrtypeD."AttributeType" = 'Date' and atrtypeD."ColumnName" = '#bdate#'
join comdoc."VFilials" f on ud."COrg" = f."VCode" join comdoc."VFilials" f on ud."COrg" = f."VCode"
where ud."TypeName" = 'NotificationLexema' and where ud."TypeName" = 'NotificationLexema' and
ds."InternalName" = 'NotificationVacation' and ds."InternalName" = 'NotificationVacation' and
not exists (select 1 not exists (select 1
@ -405,44 +412,46 @@ join comdoc."VFilials" f on ud."COrg" = f."VCode"
where es."TypeName" = 'EmployeeStatement' ) and where es."TypeName" = 'EmployeeStatement' ) and
atrD."DateValue" > now()::date ) atrD."DateValue" > now()::date )
insert into "#forInsNotification" ( "txt", "txtSMS", "txtTelegram") insert into "#forInsNotification" ( "txt", "txtSMS", "txtTelegram")
select null as "txt", null as "txtSMS", null as "txtTelegram" select null as "txt", null as "txtSMS", null as "txtTelegram"
from (select ('<table><tr><th align="left">Организация</th><th align="left">Сотрудник</th><th align="left">Отпуск</th></tr>' || from (select ('<table><tr><th align="left">Организация</th><th align="left">Сотрудник</th><th align="left">Отпуск</th></tr>' ||
(SELECT DISTINCT string_agg(x."link", '') (SELECT DISTINCT string_agg(x."link", '')
FROM ( SELECT '<tr><td>' || coalesce(l."COrgName",'') || '</td><td>' || coalesce(r."NameFull",'') || '</td>' || FROM ( SELECT '<tr><td>' || coalesce(l."COrgName",'') || '</td><td>' || coalesce(r."NameFull",'') || '</td>' ||
'<td>' || coalesce(l."Vacation", '') || ' ' || l."DateBeg" || '</td>' '<td>' || coalesce(l."Vacation", '') || ' ' || l."DateBeg" || '</td>'
||'</tr>' as "link" ||'</tr>' as "link"
FROM list l FROM list l
join rp."RP_Worker" r on l."IdWorker" = r."VCode") AS x) || '</table>' join rp."RP_Worker" r on l."IdWorker" = r."VCode") AS x) || '</table>'
) ::text as "data") d ) ::text as "data") d
``` ```
таблица.столбец | описание | # для шаблона таблица.столбец | описание | # для шаблона
----------------|----------|-------------- ----------------|----------|--------------
d."data" | Список | #query_list# d."data" | Список | #query_list#
### Отсутствие планового графика отпусков по подразделению ### Отсутствие планового графика отпусков по подразделению
```sql ??? Задача
with "chiefStruct" as
(select * from vac."SendingLateApplicationNotice"()) ```sql
insert into "#forInsNotification" ("DocflowUser","CopyTo", "txt") with "chiefStruct" as
select /*main."ChiefLogin"*/ 'Loginovasa@lexema.ru', (select DISTINCT string_agg(coalesce(ch."ChiefLogin",''),', ') from "chiefStruct" ch (select * from vac."SendingLateApplicationNotice"())
insert into "#forInsNotification" ("DocflowUser","CopyTo", "txt")
select /*main."ChiefLogin"*/ 'Loginovasa@lexema.ru', (select DISTINCT string_agg(coalesce(ch."ChiefLogin",''),', ') from "chiefStruct" ch
where ch."IdWorker" = main."Chief" and main."ChiefLogin"<>coalesce(ch."ChiefLogin",'')), where ch."IdWorker" = main."Chief" and main."ChiefLogin"<>coalesce(ch."ChiefLogin",'')),
'Добрый день, ' || '<b>'||RTRIM(coalesce(du."FirstName",'') || ' ' || coalesce(du."MiddleName",''))||'</b>' || 'Добрый день, ' || '<b>'||RTRIM(coalesce(du."FirstName",'') || ' ' || coalesce(du."MiddleName",''))||'</b>' ||
'. <br><br>' || '. <br><br>' ||
'<br> По следующим сотрудникам не сформированы заявки на отпуск на '||main."planYear"::text||' год:'|| '<br> По следующим сотрудникам не сформированы заявки на отпуск на '||main."planYear"::text||' год:'||
'<br><br>' || '<br><br>' ||
replace( replace(
replace(replace( replace(replace(
'<table style = "border-collapse:collapse"> '<table style = "border-collapse:collapse">
<tr> <tr>
<th style="text-align:center; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Организация</th> <th style="text-align:center; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Организация</th>
<th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Подразделение</th> <th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Подразделение</th>
<th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Работник</th> <th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Работник</th>
<th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Должность</th> <th style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black; border-top: 1px solid black">Должность</th>
</tr>'|| </tr>'||
(SELECT DISTINCT string_agg(x."link", '') (SELECT DISTINCT string_agg(x."link", '')
FROM(select '<tr><td style="text-align:center; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black">'||fil||'</td> FROM(select '<tr><td style="text-align:center; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black">'||fil||'</td>
<td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black">'||dep||'</td> <td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black">'||dep||'</td>
<td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black;">'||fio||'</td> <td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black;">'||fio||'</td>
@ -455,25 +464,20 @@ replace(replace(
left join comdoc."VFilials" f on w."COrg" = f."VCode" left join comdoc."VFilials" f on w."COrg" = f."VCode"
where coalesce(p2."ChiefLogin",'') = coalesce(main."ChiefLogin",'')) qw where coalesce(p2."ChiefLogin",'') = coalesce(main."ChiefLogin",'')) qw
order by fil, "dep", fio ) as x)||'</table>' order by fil, "dep", fio ) as x)||'</table>'
,'&lt;','<'),'&gt;','>'), ,'&lt;','<'),'&gt;','>'),
'&amp;','&') as "Body" '&amp;','&') as "Body"
from "chiefStruct" main from "chiefStruct" main
inner join comdoc."DocflowUser" du on main."ChiefLogin" = du."UserName" inner join comdoc."DocflowUser" du on main."ChiefLogin" = du."UserName"
group by main."Chief", coalesce(du."FirstName",''), coalesce(du."MiddleName",''), main."ChiefLogin", main."planYear"; group by main."Chief", coalesce(du."FirstName",''), coalesce(du."MiddleName",''), main."ChiefLogin", main."planYear";
``` ```
### Смена организации по умолчанию при смене основного места работы
```sql
call dfd."updateUsersDefaultOrganization" (null, 'Admin;EVIvaschenko')
/* 1 - коды исключен физ лиц через ;
2 - логины исключения через ; */
```
### Создание отзывов доверенностей МЧД по уволенным ### Создание отзывов доверенностей МЧД по уволенным
```sql ??? Задача
with res as (select * , ```sql
with res as (select * ,
'<tr> '<tr>
<td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black;">'|| <td style="text-align:center; border-right: 1px solid black; border-bottom: 1px solid black;">'||
'<a href="' || '<a href="' ||
@ -485,14 +489,22 @@ with res as (select * ,
join comdoc."DocflowDocumentSettings" se on r."TypeName" = se."DocType" join comdoc."DocflowDocumentSettings" se on r."TypeName" = se."DocType"
) )
insert into "#forInsNotification" ("DocflowUser", "txt") insert into "#forInsNotification" ("DocflowUser", "txt")
select d."DocflowUser", null as "txt" select d."DocflowUser", null as "txt"
from (select distinct r."DocflowUser", (select string_agg(coalesce(r1."ref_link",''),'') from (select distinct r."DocflowUser", (select string_agg(coalesce(r1."ref_link",''),'')
from res r1 where r."DocflowUser" = r1."DocflowUser") as list from res r1 where r."DocflowUser" = r1."DocflowUser") as list
from res r from res r
) d ) d
``` ```
таблица.столбец | описание | # для шаблона таблица.столбец | описание | # для шаблона
----------------|----------|-------------- ----------------|----------|--------------
d.list | Список документов | #query_list# d.list | Список документов | #query_list#
### Перенос логов отправки почты и СМС в таблицу SendLog
??? Задача
```sql
call comdoc."PostToSendLog"();
```