Files
svc-api-x/v1/resources/catalog_service_ls.cfc

168 lines
6.7 KiB
Plaintext

<cfcomponent extends="taffy.core.resource" taffy:uri="/service-catalog/services">
<cfsilent>
<cfimport prefix="m" taglib="../lib"/>
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/>
</cfsilent>
<!--- Спецификация полей, пригодных для фильтрации и сортировки --->
<cfset this.fieldsSpec={
service_id={prefix="s", type="cf_sql_integer"}
,business_line_id={prefix="s", type="cf_sql_integer"}
,business_line={prefix="s", type="cf_sql_varchar"}
,area_id={prefix="s", type="cf_sql_integer"}
,area={prefix="s", type="cf_sql_varchar"}
,area_code={prefix="s", type="cf_sql_varchar"}
,analytic_code={prefix="s", type="cf_sql_varchar"}
,abstract_service_id={prefix="s", type="cf_sql_integer"}
,abstract_service={prefix="s", type="cf_sql_varchar"}
,abstract_service_code={prefix="s", type="cf_sql_varchar"}
,abstract_service_status_id={prefix="s", type="cf_sql_integer"}
,abstract_service_status={prefix="s", type="cf_sql_varchar"}
,service_code={prefix="s", type="cf_sql_varchar"}
,service={prefix="s", type="cf_sql_varchar"}
,modifier={prefix="s", type="cf_sql_varchar"}
,modifier_code={prefix="s", type="cf_sql_varchar"}
,measure_id={prefix="s", type="cf_sql_integer"}
,service_status_id={prefix="s", type="cf_sql_integer"}
,service_status={prefix="s", type="cf_sql_varchar"}
,measure_short={prefix="s", type="cf_sql_varchar"}
,sort={prefix="s", type="cf_sql_integer"}
,vat_perc={prefix="s", type="cf_sql_integer"}
,vat_free={prefix="s", type="cf_sql_bit"}
,vat_rate={prefix="s", type="cf_sql_numeric"}
,capacity_legend={prefix="s", type="cf_sql_integer"}
,commercial_note={prefix="s", type="cf_sql_varchar"}
,is_published={prefix="s", type="cf_sql_bit"}
}
/>
<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 var local={}/>
<cftry>
<!--- Разбор и проверка параметров запроса --->
<cftry>
<cfset this.helper.validateField(arguments, "pageSize", "integer")/>
<cfset this.helper.validateField(arguments, "page", "integer")/>
<!--- Поля вне спецификации игнорируются, чтобы не добавлять отдельные исключения для orderBy и похожих параметров. --->
<cfset var filter=this.helper.parseFilterParams(this.fieldsSpec)/>
<cfcatch type="invalidParamValue">
<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/>
<cfquery name="local.qRead" result="local.result">
select
<m:field_set titleMapOut="local.titleMap" lengthOut="local.fieldCount">
<m:field title="service_id">service_id</m:field>
<m:field title="business_line_id">business_line_id</m:field>
<m:field title="business_line">business_line</m:field>
<m:field title="area_id">area_id</m:field>
<m:field title="area">area</m:field>
<m:field title="area_code">area_code</m:field>
<m:field title="analytic_code">analytic_code</m:field>
<m:field title="abstract_service_id">abstract_service_id</m:field>
<m:field title="abstract_service">abstract_service</m:field>
<m:field title="abstract_service_code">abstract_service_code</m:field>
<m:field title="abstract_service_status_id">abstract_service_status_id</m:field>
<m:field title="abstract_service_status">abstract_service_status</m:field>
<m:field title="service_code">service_code</m:field>
<m:field title="service">service</m:field>
<m:field title="modifier">modifier</m:field>
<m:field title="modifier_code">modifier_code</m:field>
<m:field title="measure_id">measure_id</m:field>
<m:field title="service_status_id">service_status_id</m:field>
<m:field title="service_status">service_status</m:field>
<m:field title="measure_short">measure_short</m:field>
<m:field title="sort">sort</m:field>
<m:field title="vat_perc">vat_perc</m:field>
<m:field title="vat_free">vat_free</m:field>
<m:field title="vat_rate">vat_rate</m:field>
<m:field title="capacity_legend">capacity_legend</m:field>
<m:field title="commercial_note">commercial_note</m:field>
<m:field title="is_published">is_published</m:field>
<m:field title="dt_load">dt_load</m:field>
</m:field_set>
from service_catalog.service s
where 1=1 <m:filter_build filter=#filter#/>
order by analytic_code
, abstract_service
, service_id
, coalesce(sort,0)
limit #maxrows#
</cfquery>
<cfquery name="local.qTotal">
select count(*) as cnt
from service_catalog.service s
</cfquery>
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
<cfset "out.total"=#local.qTotal.cnt#/>
<cfset "out.resultSetSize"=#local.qRead.recordCount#/>
<cfset "out.pageSize"=#arguments.pageSize*1#/>
<cfset "out.page"=#arguments.page*1#/>
<cfset "out.orderBy"=#arguments.orderBy#/>
<cfset var resultCollection=[]/>
<cfloop query=#local.qRead# startRow=#startrow# endRow=#(startrow+maxrows-1)#>
<cfset var rec=structNew("linked")/>
<cfset this.helper.appendRecord(rec, "", local.titleMap, local.qRead, this.helper.snake2camel)/>
<cfset arrayAppend(resultCollection, rec)/>
</cfloop>
<cfset "out.size"=#arrayLen(resultCollection)#/>
<cfset "out.results"=#resultCollection#/>
<cfset "out.runDurationMs"=getTickCount()-request.startTickCount/>
<cfreturn representationOf(out)/>
<cfcatch type="any">
<cfreturn representationOf(cfcatch)/>
</cfcatch>
</cftry>
</cffunction>
<cfscript>
function plain2htm(s) {
return replace(replace(s, chr(13),'',"ALL"),chr(10),'<br/>', "ALL");
}
function htm2plain(s) {
return replaceNoCase(s, '<br/>', '#chr(13)##chr(10)#', "ALL");
}
function cleanHtm(s) {
return replaceList(s, '<,>,"', '&lt;,&gt;,&quot;');
}
</cfscript>
<cffunction name="plain2HtmClean">
<cfargument name="s" type="string"/>
<cfreturn plain2htm(cleanHtm(s))/>
</cffunction>
<cffunction name="cleanInput">
<cfargument name="s" type="string"/>
<cfreturn htmlEditFormat(s)/>
</cffunction>
</cfcomponent>