Дерево страниц
Skip to end of metadata
Go to start of metadata

Описаны наиболее востребованные блоки SQL-запросов

Статус

ГОТОВО

Раздел

SQL

Кастомный атрибут основных объектов

ЗначенияSQL - запрос

Текст

В запросе используется метка {storage-field name}, которая заменяется значением из атрибута storage-field
tn_field_string
select tfs."value" as v
from tn_field_string tfs
join tn_field tf on tf.id = tfs.id
where tf.owner = rkkbase.id and tf.owner_type = rkkbase.id_type and tf.cmjfield = '{storage-field name}'

Число

В запросе используется метка {storage-field name}, которая заменяется значением из атрибута storage-field
tn_field_decimal
select tfd."value" as v
from tn_field_decimal tfd
join tn_field tf on tf.id = tfd.id 
where tf.owner = rkkbase.id and tf.owner_type = rkkbase.id_type and tf.cmjfield = '{storage-field name}'

Дата

В запросе используется метка {storage-field name}, которая заменяется значением из атрибута storage-field
tn_field_dateonly
select tfs."value" as v
from tn_field_dateonly tfd
join tn_field tf on tf.id = tfd.id
where tf.owner = rkkbase.id and tf.owner_type = rkkbase.id_type and tf.cmjfield = '{storage-field name}'

Время

В запросе используется метка {storage-field name}, которая заменяется значением из атрибута storage-field
tn_field_timeonly
select tfs."value" as v
from tn_field_timeonly tft
join tn_field tf on tf.id = tft.id
where tf.owner = rkkbase.id and tf.owner_type = rkkbase.id_type and tf.cmjfield = '{storage-field name}'

Дата и время

В запросе используется метка {storage-field name}, которая заменяется значением из атрибута storage-field
tn_field_datetime
select tfs."value" as v
from tn_field_datetime tfdt
join tn_field tf on tf.id = tfdt.id
where tf.owner = rkkbase.id and tf.owner_type = rkkbase.id_type and tf.cmjfield = '{storage-field name}'

Субъект

В запросе используется метка {storage-field name}, которая заменяется значением из атрибута storage-field
tn_field_string
coalesce((select string_agg(SPLIT_PART(tfs.value, '%', 1),',') as v
 			from tn_field_string tfs
 			join tn_field tf on tf.id = tfs.id
 			where tf.owner = rkkbase.id and tf.owner_type = rkkbase.id_type 
			and tf.cmjfield = '{storage-field name}'),'Не указано')


Атрибут комплексного справочника

Все атрибуты комлескного справочника текстовые.

ЗначенияSQL - запрос

Текст

В запросе используется метка {storage-field name}, которая заменяется значением из атрибута storage-field
classifier_complex
(select title from classifier_complex where classifier_complex.id = (
      					select complex1.id
						from clscom_tag tag1
						left join clscom_to_tag to_tag1 on to_tag1.tag = tag1.id
						left join classifier_complex complex1 on complex1.id = to_tag1.classifier
						left join cls_typeComp typecom1 on typecom1.id = complex1.owner
						where tag1.schema = 'ComplectClassifierWP'
						and typecom1.alias = '{storage-field name}' and tag1.id = tag.id)) as Office


Идентификатор объектов (cmjunid)

Данную конструкцию нельзя использовать в разработке на SQL, так как она влияет на производительность. Используется только для анализа.

Конвертация cmjunid в id и id_type

ЗначенияSQL - запрос

Таблица

В запросе используется метка {table name}, которая заменяется на базовые таблицы: f_dp_rkk (РКК), f_dp_resolution (Резолюции), f_dp_execution (Исполнения)

select doti."name", 
  	map.notesunid,
	cmj_document.id, 
	cmj_document.id_type
from {table name} cmj_document 
join (
	select SUBSTRING(npm.punid FOR 16) as sochiunid, 
	npm.nunid as notesunid
	from nunid2punid_map npm) map on to_char(cast((cmj_document.id_type * 10^12) as bigint) + cmj_document.id, 'FM0000000000000000') = map.sochiunid
join domain_object_type_id doti on doti.id  = cmj_document.id_type

Получение резолюций и отчетов по cmjunid

ЗначенияSQL - запрос

Таблица

В запросе используется метка {cmjunid} и {table name}:
{cmjunid} заменяется значением из Id-документа (можно взять из JSON или URL); {table name} заменяется на базовые таблицы: f_dp_rkk (РКК), f_dp_contractrkk (Договоры)
select response.id,
	response.id_type,
	response.hierparent,
	response.hierparent_type,
	response.rkkid,
	response.authorbeard,
	map.notesunid
from
	(select res.id,
		res.id_type,
		res.hierparent,
		res.hierparent_type,
		beard.orig_shortname as authorbeard,
		res.hierroot as rkkid
	from f_dp_resolution res
	join f_dp_resltnbase resbase on res.id = resbase.id
	join so_beard beard on resbase.author = beard.id
		and resbase.author_type = beard.id_type
	union
	select report.id,
		report.id_type,
		report.hierparent,
		report.hierparent_type,
		beard.orig_shortname as authorbeard,
		report.hierroot as rkkid
	from f_dp_report report
	join so_beard beard on
		report.author = beard.id
		and report.author_type = beard.id_type
	) response
join (select SUBSTRING(npm.punid for 16) as sochiunid,
		npm.nunid as notesunid
	from nunid2punid_map npm) map on
	to_char(cast((response.id_type * 10 ^12) as bigint) + response.id, 'FM0000000000000000') = map.sochiunid
where
	response.rkkid =(select cmj_document.id
	from {table name} cmj_document
	join (select SUBSTRING(npm.punid for 16) as sochiunid,
			npm.nunid as notesunid
		from nunid2punid_map npm) map on
		to_char(cast((cmj_document.id_type * 10 ^12) as bigint) + cmj_document.id, 'FM0000000000000000') = map.sochiunid
	where map.notesunid = '{cmjunid}')