<collection name="Tasks_(vw_cmj_calendar)" idField="id" replace="runtime">
<prototype>
<![CDATA[
SELECT
id,
created_date,
Module,
self_1,
self_2,
self_3,
taskDueDate,
subject,
executors as taskExecutor
FROM(
SELECT
resolution.id AS id,
rkkbase.created_date,
rkkbase.module AS Module,
'<id>' AS self_1,
':' AS self_2,
'</>' AS self_3,
(case
when resolution.CtrlDeadline is null then now()
when resolution.CtrlDeadline = '0001-01-01 00:00:00.000' then now()
else resolution.CtrlDeadline
end) as taskDueDate,
resolution.resolution as subject,
(
SELECT
DISTINCT coalesce(
string_agg(
'<id>' || substring(unid, 33, 48) || ':' || substring(unid, 1, 32)
|| '</><shortName>' || sname|| '</>'
, ','),
'<id></><shortName></>'
)
FROM(
SELECT
execbeard.cmjunid as unid,
execbeard.Orig_ShortName as sname
FROM
F_DP_TasksResolution_ec resexec
LEFT JOIN so_beard execbeard ON execbeard.id = resexec.executorcurr
WHERE
resexec.owner = resolution.id AND resexec.idx = 0
UNION
SELECT
execbeard.cmjunid as unid,
execbeard.Orig_ShortName as sname
FROM
F_DP_TasksResolution_EE resexec
LEFT JOIN so_beard execbeard ON execbeard.id = resexec.executorext
WHERE
resexec.owner = resolution.id AND resexec.idx = 0
) q
) AS executors
FROM f_dp_tasksresolution resolution
LEFT JOIN f_dp_rkkbase rkkbase ON rkkbase.id = resolution.id
LEFT JOIN SO_Beard execbeard ON execbeard.id = resolution.author
LEFT JOIN (SELECT soapp.id AS id,
soapp.id_type AS id_type,
soapp.beard AS beard,
soapp.beard_type AS beard_type,
CASE
WHEN soapp_plain.id IS NOT NULL THEN soapp_plain.post
ELSE soapp_head.post END AS post,
CASE
WHEN soapp_plain.id IS NOT NULL THEN soapp_plain.post_type
ELSE soapp_head.post_type END AS post_type
FROM so_appointment soapp
LEFT JOIN so_appointmentplain soapp_plain
ON soapp.id = soapp_plain.id AND
soapp.id_type = soapp_plain.id_type
LEFT JOIN so_appointmenthead soapp_head
ON soapp.id = soapp_head.id AND
soapp.id_type = soapp_head.id_type) author_app
ON execbeard.id = author_app.beard AND
execbeard.id_type = author_app.beard_type
LEFT JOIN so_post author_post
ON author_app.post = author_post.id AND
author_app.post_type = author_post.id_type
WHERE rkkbase.isdeleted != 1 AND resolution.ctrlDateExecution IS NULL
)s WHERE
1=1
::where-clause
]]>
</prototype>
<counting-prototype>
<![CDATA[
SELECT
COUNT(*)
FROM(
SELECT
resolution.id AS id,
rkkbase.created_date,
rkkbase.module AS Module,
'<id>' AS self_1,
':' AS self_2,
'</>' AS self_3,
(case
when resolution.CtrlDeadline is null then now()
when resolution.CtrlDeadline = '0001-01-01 00:00:00.000' then now()
else resolution.CtrlDeadline
end) as taskDueDate,
resolution.resolution as subject,
(
SELECT
DISTINCT coalesce(
string_agg(
'<id>' || substring(unid, 33, 48) || ':' || substring(unid, 1, 32)
|| '</><shortName>' || sname|| '</>'
, ','),
'<id></><shortName></>'
)
FROM(
SELECT
execbeard.cmjunid as unid,
execbeard.Orig_ShortName as sname
FROM
F_DP_TasksResolution_ec resexec
LEFT JOIN so_beard execbeard ON execbeard.id = resexec.executorcurr
WHERE
resexec.owner = resolution.id AND resexec.idx = 0
UNION
SELECT
execbeard.cmjunid as unid,
execbeard.Orig_ShortName as sname
FROM
F_DP_TasksResolution_EE resexec
LEFT JOIN so_beard execbeard ON execbeard.id = resexec.executorext
WHERE
resexec.owner = resolution.id AND resexec.idx = 0
) q
) AS executors
FROM f_dp_tasksresolution resolution
LEFT JOIN f_dp_rkkbase rkkbase ON rkkbase.id = resolution.id
LEFT JOIN SO_Beard execbeard ON execbeard.id = resolution.author
LEFT JOIN (SELECT soapp.id AS id,
soapp.id_type AS id_type,
soapp.beard AS beard,
soapp.beard_type AS beard_type,
CASE
WHEN soapp_plain.id IS NOT NULL THEN soapp_plain.post
ELSE soapp_head.post END AS post,
CASE
WHEN soapp_plain.id IS NOT NULL THEN soapp_plain.post_type
ELSE soapp_head.post_type END AS post_type
FROM so_appointment soapp
LEFT JOIN so_appointmentplain soapp_plain
ON soapp.id = soapp_plain.id AND
soapp.id_type = soapp_plain.id_type
LEFT JOIN so_appointmenthead soapp_head
ON soapp.id = soapp_head.id AND
soapp.id_type = soapp_head.id_type) author_app
ON execbeard.id = author_app.beard AND
execbeard.id_type = author_app.beard_type
LEFT JOIN so_post author_post
ON author_app.post = author_post.id AND
author_app.post_type = author_post.id_type
WHERE rkkbase.isdeleted != 1 AND resolution.ctrlDateExecution IS NULL
)s WHERE
1=1
::where-clause
]]>
</counting-prototype>
<filter name="MODULE">
<criteria placeholder="where-clause">
<![CDATA[
Module = {0}
]]>
</criteria>
</filter>
<filter name="created_date_partial"> <!-- Функционал фильра другой, но называть их по как хочется не разрешает схема валидации -->
<criteria placeholder="where-clause">
<![CDATA[
('б/д' ilike '%'||{0}||'%' and (created_date is null))
]]>
</criteria>
</filter>
<filter name="created_date">
<criteria placeholder="where-clause">
<![CDATA[
cast(created_date as date) = cast({0} as date)
]]>
</criteria>
</filter>
<filter name="taskDueDate_partial">
<criteria placeholder="where-clause">
<![CDATA[
(taskDueDate BETWEEN {0} AND {1})
]]>
</criteria>
</filter>
<filter name="taskDueDate">
<criteria placeholder="where-clause">
<![CDATA[
(taskDueDate BETWEEN {0} AND {1})
]]>
</criteria>
</filter>
<filter name="taskDueDate_GE">
<criteria placeholder="where-clause">
<![CDATA[
taskDueDate >= {0}
]]>
</criteria>
</filter>
<filter name="taskDueDate_L">
<criteria placeholder="where-clause">
<![CDATA[
taskDueDate < {0}
]]>
</criteria>
</filter>
<filter name="self">
<criteria placeholder="where-clause">
<![CDATA[
Module = {0} and id = {1}
]]>
</criteria>
</filter>
<filter name="subject">
<criteria placeholder="where-clause">
<![CDATA[
subject = {0}
]]>
</criteria>
</filter>
<filter name="subject_partial">
<criteria placeholder="where-clause">
<![CDATA[
subject iLIKE ('%'||{0}||'%')
]]>
</criteria>
</filter>
<filter name="personUnid">
<criteria placeholder="where-clause">
<![CDATA[
cast(substring({0}, 5, 12) AS INT) = personUnid
]]>
</criteria>
</filter>
<filter name="personUnid_partial">
<criteria placeholder="where-clause">
<![CDATA[
cast(substring({0}, 5, 12) AS INT) = personUnid
]]>
</criteria>
</filter>
</collection> |