Files
svc-api-x/v1/resources/user.cfc
T
2024-10-30 13:46:08 +03:00

74 lines
3.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<cfcomponent extends="taffy.core.resource" taffy:uri="/user">
<cfsilent>
<cfimport prefix="m" taglib="../lib"/>
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/><!---*** странно, почему мы его видим?---><!---вынести в апп?--->
</cfsilent>
<cffunction name="get" hint="Контрольная информация по текущему пользователю для проверки контекста. Предполагается использовать только для интеграционной отладки. Исключения перехватываются, всегда возвращается код 200, структура ответа при этом не предназначена для разбора">
<cftry>
<cfset var local={}/><!--- *** а точно нужно var? --->
<cfset var out=structNew("linked")/>
<cfset "out.usrId"=#ARGUMENTS.usrId#/>
<cfset "out.iamServiceUrl"=request.locateIamService()/>
<cfset "out.serviceLocationDurationMs"=getTickCount() - request.startTickCount/>
<cfquery name=local.qSpec>
select
<m:field_set titleMapOut="local.specTitleMap" lengthOut="local.fieldCount">
<m:field cfSqlType="CF_SQL_INTEGER">s.specification_id</m:field>
<m:field>s.specification</m:field>
<m:field>(select count(*) from specification_item i where i.specification_id=s.specification_id) as specification_item_count</m:field>
<m:field>c.contract_id</m:field>
<m:field>c.contract</m:field>
<m:field>to_char(c.dt_contract, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as dt_contract</m:field>
</m:field_set>
from specification s
join contract c on (s.contract_id=c.contract_id)
join usr u on (c.contragent_id=u.contragent_id)
where u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#ARGUMENTS.usrId#/><!--- *** undeclared --->
order by specification_id desc limit 1;
</cfquery>
<cfquery name="local.qRead" result="local.result">
select
<m:field_set titleMapOut="local.titleMap" lengthOut="local.fieldCount">
<m:field cfSqlType="CF_SQL_INTEGER">u.usr_id</m:field>
<m:field>u.login</m:field>
<m:field>k.contragent_id</m:field>
<m:field>k.contragent</m:field>
</m:field_set>
from usr u
left outer join contragent k on u.contragent_id=k.contragent_id
where u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#ARGUMENTS.usrId#/>
</cfquery>
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount- out.serviceLocationDurationMs/>
<cfset var resultSet=[]/>
<cfset "out.usr" = (local.qRead.recordCount GT 0) ? this.helper.appendRecord(structNew("linked"), "", local.titleMap, local.qRead, this.helper.snake2camel) : {}/>
<cfset "out.defaultSpecification" = (local.qSpec.recordCount GT 0) ? this.helper.appendRecord(structNew("linked"), "", local.specTitleMap, local.qSpec, this.helper.snake2camel) : {}/>
<cfset "out.runDurationMs"=getTickCount()-request.startTickCount/>
<!---<cfset "out.sql"=#local.result.sql#/>--->
<cfreturn representationOf(out)/>
<cfcatch type="any">
<cfreturn representationOf(cfcatch)/>
</cfcatch>
</cftry>
</cffunction>
<!--- <cffunction name="get" hint="проверка">
<cfreturn representationOf("Проверка связи")/>
</cffunction> --->
</cfcomponent>