008 notifications
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@
|
||||
|
||||
//variables.framework.docs={};
|
||||
variables.framework.docs.APIName="Deck API";
|
||||
variables.framework.docs.APIVersion="0.006";
|
||||
variables.framework.docs.APIVersion="0.008";
|
||||
|
||||
variables.framework.globalHeaders = structNew();
|
||||
variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location";
|
||||
|
||||
@@ -50,7 +50,8 @@
|
||||
left outer join contragent k on (d.contragent_id=k.contragent_id)
|
||||
left outer join svc v on (e.service_id=v.svc_id)
|
||||
where e.instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>
|
||||
</cfquery>
|
||||
AND s.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/><!--- access protection --->
|
||||
</cfquery> <!--- *** правильнее при попытке доступа к чужому инстансу (НСД) выбрасывать 403, а тут будет 404 --->
|
||||
|
||||
<cfif local.qInstance.recordCount EQ 0>
|
||||
<cfreturn representationOf(this.helper.formatMessage("Not Found")).withStatus(404)/>
|
||||
@@ -98,6 +99,7 @@
|
||||
where o.instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>
|
||||
order by status.version
|
||||
</cfquery>
|
||||
<!--- *** А тут у нас не получится, что только операции с состояниями? Или в неправильном порядке? --->
|
||||
<!--- ?Добавить параметры к операции --->
|
||||
<!--- Разобраться в отличии текущей от последней. Может, нужна только одна? --->
|
||||
|
||||
|
||||
@@ -62,16 +62,35 @@
|
||||
<m:field>i.quantity</m:field>
|
||||
<m:field>i.price</m:field>
|
||||
<m:field>v.svc</m:field>
|
||||
<m:field>(select operation from instance_state st join instance_operation io on (st.instance_operation_uid=io.instance_operation_uid) where st.instance_uid=e.instance_uid order by version desc limit 1) as operation</m:field>
|
||||
<m:field>(select instance_operation_uid::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_operation_uid</m:field>
|
||||
<!--- <m:field>(select operation from instance_state st join instance_operation io on (st.instance_operation_uid=io.instance_operation_uid) where st.instance_uid=e.instance_uid order by version desc limit 1) as operation</m:field>
|
||||
<m:field>(select instance_operation_uid::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_operation_uid</m:field> --->
|
||||
|
||||
<m:field>(select io.operation from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as last_operation</m:field>
|
||||
<m:field>(select io.instance_operation_uid::text from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as last_operation_uid</m:field>
|
||||
<m:field>(select io.submit_result from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as submit_result</m:field>
|
||||
<m:field>(select io.submit_result from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as submit_result</m:field><!--- *** последняя операция может быть неуспешной, и даже не отправленой --->
|
||||
<m:field>(select to_char(io.dt_start, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as operation_dt_start</m:field>
|
||||
<m:field>(select to_char(io.dt_finish, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as operation_dt_finish</m:field>
|
||||
<m:field>(select extract('epoch' from coalesce(io.dt_finish,CURRENT_TIMESTAMP)- io.dt_start) from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as duration</m:field>
|
||||
<m:field formatter=#function(x){return (deserializeJson(x))}#>(select instance_data::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_data</m:field>
|
||||
<m:field>(select st.instance_state_uid::text from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as instance_state_uid</m:field>
|
||||
<m:field>(select st.is_test from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as is_test</m:field>
|
||||
<m:field>(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as is_deleted</m:field>
|
||||
<m:field>(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as suspended</m:field>
|
||||
<m:field>(select st.instance_data->>'grafanaUrl' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) as grafana_url</m:field>
|
||||
<m:field>(
|
||||
case
|
||||
when
|
||||
(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'deleted'
|
||||
when
|
||||
(select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'true' then 'suspended'
|
||||
when
|
||||
(select st.instance_data->>'isDeleted' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' AND (select st.instance_data->>'suspended' from instance_state st where st.instance_uid=e.instance_uid order by version desc limit 1) = 'false' then 'running'
|
||||
when
|
||||
not exists (select * from instance_operation o where o.instance_uid=e.instance_uid) then 'not configured'
|
||||
when
|
||||
not exists (select * from instance_state st where st.instance_uid=e.instance_uid) then 'not created'
|
||||
else null end
|
||||
) as explained_status</m:field><!--- ******** (сделать тест кейсы) еще ситуация, когда не завершена операция create, но есть первый стейт --->
|
||||
<m:field>(select max(version) from instance_state st where st.instance_uid=e.instance_uid) as version</m:field>
|
||||
</m:field_set>
|
||||
|
||||
@@ -80,9 +99,9 @@
|
||||
join specification s on (i.specification_id=s.specification_id)
|
||||
join contract d on (s.contract_id=d.contract_id)
|
||||
join contragent k on (d.contragent_id=k.contragent_id)
|
||||
join usr u on (k.contragent_id=u.contragent_id)
|
||||
join svc v on (e.service_id=v.svc_id)
|
||||
where u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.usrId#/>
|
||||
where s.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/><!--- *** make project entity --->
|
||||
<!--- u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.usrId#/> --->
|
||||
<m:filter_build filter=#filter#/>
|
||||
order by <m:order_build sortCollection=#this.helper.parseNumericOrder(local.titleMap, arguments.orderBy)# fieldCount=0/><!---no sort length limit--->
|
||||
limit #maxrows#
|
||||
@@ -95,9 +114,10 @@
|
||||
join specification s on (i.specification_id=s.specification_id)
|
||||
join contract d on (s.contract_id=d.contract_id)
|
||||
join contragent k on (d.contragent_id=k.contragent_id)
|
||||
join usr u on (k.contragent_id=u.contragent_id)
|
||||
--join usr u on (k.contragent_id=u.contragent_id)
|
||||
join svc v on (e.service_id=v.svc_id)
|
||||
where u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.usrId#/>
|
||||
where s.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
|
||||
<!--- u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.usrId#/> --->
|
||||
</cfquery>
|
||||
|
||||
<cfset var out=structNew("linked")/>
|
||||
|
||||
@@ -47,10 +47,11 @@
|
||||
join specification s on (i.specification_id=s.specification_id)
|
||||
join contract d on (s.contract_id=d.contract_id)
|
||||
join contragent k on (d.contragent_id=k.contragent_id)
|
||||
join usr u on (k.contragent_id=u.contragent_id)
|
||||
<!--- join usr u on (k.contragent_id=u.contragent_id) --->
|
||||
join svc v on (e.service_id=v.svc_id)
|
||||
where u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.usrId#/>
|
||||
AND o.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#" null=#!isValid('guid',arguments.instanceOperationUid)#/>
|
||||
AND s.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
|
||||
</cfquery>
|
||||
<cfif local.qIinstanceOperation.recordCount EQ 0>
|
||||
<cfreturn representationOf(this.helper.formatMessage("Not Found")).withStatus(404)/>
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
join instance e on (io.instance_uid=e.instance_uid)
|
||||
join specification_item si on (e.specification_item_id=si.specification_item_id``)
|
||||
where iop.instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
|
||||
AND si.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
|
||||
</cfquery>
|
||||
|
||||
<cfif local.qRead.recordCount EQ 0>
|
||||
|
||||
@@ -58,8 +58,12 @@
|
||||
<m:field title="svc_operation_cfs_param">sop.svc_operation_cfs_param</m:field>
|
||||
</m:field_set>
|
||||
from instance_operation_cfs_param iop
|
||||
join instance_operation io on (iop.instance_operation_uid=io.instance_operation_uid)
|
||||
join instance e on (io.instance_uid=e.instance_uid)
|
||||
join specification_item si on (e.specification_item_id=si.specification_item_id)
|
||||
join svc_operation_cfs_param sop on (iop.svc_operation_cfs_param_id=sop.svc_operation_cfs_param_id)
|
||||
where iop.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#" null=#!isValid('guid',arguments.instanceOperationUid)#/>
|
||||
AND si.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
|
||||
<m:filter_build filter=#filter#/>
|
||||
order by <m:order_build sortCollection=#this.helper.parseNumericOrder(local.titleMap, arguments.orderBy)# fieldCount=0/><!---no sort length limit--->
|
||||
limit #maxrows#
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
<cfcomponent extends="taffy.core.resource" taffy:uri="/notifications">
|
||||
|
||||
<cfsilent>
|
||||
<cfimport prefix="m" taglib="../lib"/>
|
||||
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/><!---*** странно, почему мы его видим?---><!---вынести в апп?--->
|
||||
</cfsilent>
|
||||
|
||||
<!---спецификация полей, пригодных для фильтрации (?и сортировки)--->
|
||||
<cfset this.fieldsSpec={
|
||||
dt_created={prefix="s", type="date"},
|
||||
dt_updated={prefix="s", type="date"},
|
||||
svc_id={prefix="s", type="integer"},
|
||||
svc={prefix="s", type="string"}
|
||||
}
|
||||
/>
|
||||
|
||||
|
||||
|
||||
<cffunction name="get" hint="Список уведомлений">
|
||||
<cfargument name="pageSize" type="string" hint="type:integer" default="100"/>
|
||||
<cfargument name="page" type="string" hint="type:integer" default="1"/>
|
||||
<cfargument name="orderBy" type="string" hint="type:string, description:comma-separated list of fields to sort by, example:fld1.ASC,fld2.DESC,fld3.ASC" default=""/>
|
||||
|
||||
<cfset local={}/>
|
||||
|
||||
<!---parse and validate request parameters--->
|
||||
<cftry>
|
||||
<cfset this.helper.validateField(arguments, "pageSize", "integer")/>
|
||||
<cfset this.helper.validateField(arguments, "page", "integer")/>
|
||||
|
||||
<!---мы мирно игнорируем поля, отсутствующие в спецификации, что позволяет не делать исключения для orderBy и т.п.--->
|
||||
<cfset var filter=this.helper.parseFilterParams(this.fieldsSpec)/>
|
||||
<!--- <cfset var order=this.helper.parseOrderBy(this.fieldsSpec, arguments.orderBy)/> --->
|
||||
|
||||
<cfcatch type="invalidParamValue"><cfreturn representationOf("Проверка связи 3")>
|
||||
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
||||
</cfcatch>
|
||||
<cfcatch type="any">
|
||||
<cfreturn representationOf(cfcatch)/>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
|
||||
<cfset var out={}/>
|
||||
<cfset var maxrows=arguments.pageSize*arguments.page/>
|
||||
<cfset var startrow=arguments.pageSize*(arguments.page-1)+1/>
|
||||
|
||||
<cfset request.locateIamService()/>
|
||||
|
||||
<cfquery name="local.qRead" result="local.result">
|
||||
select
|
||||
<m:field_set titleMapOut="local.titleMap" lengthOut="local.fieldCount">
|
||||
<m:field>n.notification_uid</m:field>
|
||||
<m:field>n.notification</m:field>
|
||||
<m:field>n.descr</m:field>
|
||||
<m:field>n.descr</m:field>
|
||||
<m:field>to_char(s.dt_show_from, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as dt_show_from</m:field>
|
||||
<m:field>to_char(s.dt_show_to, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as dt_show_to</m:field>
|
||||
<m:field>to_char(s.dt_created, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as dt_created</m:field>
|
||||
<m:field>to_char(s.dt_updated, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as dt_updated</m:field>
|
||||
</m:field_set>
|
||||
from notification n
|
||||
where 1=1 <m:filter_build filter=#filter#/>
|
||||
AND (n.dt_show_from <= CURRENT_TIMESTAMP OR n.dt_show_from IS NULL)
|
||||
AND (n.dt_show_to >= CURRENT_TIMESTAMP OR n.dt_show_to IS NULL)
|
||||
AND (n.companyId = <cfqueryparam cfsqltype="cf_sql_other" value=#arguments.companyId#/> OR n.companyId IS NULL)
|
||||
order by dt_show_from desc
|
||||
<!--- <m:order_build sortCollection=#this.helper.parseNumericOrder(local.titleMap, arguments.orderBy)# fieldCount=0/>--->
|
||||
limit #maxrows#
|
||||
</cfquery>
|
||||
|
||||
|
||||
<cfquery name="local.qTotal">
|
||||
select count(*) as cnt
|
||||
from notification n
|
||||
where 1=1 <m:filter_build filter=#filter#/>
|
||||
AND (n.dt_show_from <= CURRENT_TIMESTAMP OR n.dt_show_from IS NULL)
|
||||
AND (n.dt_show_to >= CURRENT_TIMESTAMP OR n.dt_show_to IS NULL)
|
||||
AND (n.companyId = <cfqueryparam cfsqltype="cf_sql_other" value=#arguments.companyId#/> OR n.companyId IS NULL)
|
||||
order by dt_show_from desc
|
||||
</cfquery>
|
||||
|
||||
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
|
||||
<cfset "out.total"=#local.qTotal.cnt#/>
|
||||
|
||||
<cfset var resultSet=[]/>
|
||||
<cfloop query=#local.qRead# startRow=#startrow#>
|
||||
<cfset var rec={}/>
|
||||
<cfset this.helper.appendRecord(rec, "", local.titleMap, local.qRead, this.helper.snake2camel)/>
|
||||
<cfset arrayAppend(resultSet, rec)/>
|
||||
</cfloop>
|
||||
|
||||
<cfset "out.results"=#resultSet#/>
|
||||
<cfset "out.pageSize"=#arguments.pageSize#/>
|
||||
<cfset "out.page"=#arguments.page#/>
|
||||
<cfset "out.orderBy"=#arguments.orderBy#/>
|
||||
<cfset "out.size"=#arrayLen(resultSet)#/>
|
||||
<cfset "out.runDurationMs"=getTickCount()-request.startTickCount/>
|
||||
<!---<cfset "out.sql"=#local.result.sql#/>--->
|
||||
<cfreturn representationOf(out)/>
|
||||
|
||||
</cffunction>
|
||||
|
||||
<!--- <cffunction name="get" hint="проверка">
|
||||
<cfreturn representationOf("Проверка связи")/>
|
||||
</cffunction> --->
|
||||
|
||||
</cfcomponent>
|
||||
Reference in New Issue
Block a user