174 lines
7.2 KiB
Plaintext
174 lines
7.2 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"}
|
|
}
|
|
/>
|
|
|
|
<!--- предполагается показывать букмарки только "настоящим" клиентам, поэтому используем contragent_id как признак своих--->
|
|
|
|
<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> <!--- отладка на время проблемы 404 --->
|
|
|
|
|
|
<!---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(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 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)
|
|
<!--- , modifier_id --->
|
|
limit #maxrows#
|
|
</cfquery>
|
|
<!--- <cfdump var=#local.qRead#/><cfabort/> --->
|
|
|
|
|
|
|
|
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
|
|
<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={}/>
|
|
<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");
|
|
}
|
|
//request.plain2htm = plain2htm;
|
|
|
|
function htm2plain(s) {
|
|
return replaceNoCase(s, '<br/>', '#chr(13)##chr(10)#', "ALL");
|
|
}
|
|
//request.htm2plain = htm2plain;
|
|
|
|
function cleanHtm(s) {
|
|
return replaceList(s, '<,>,"', '<,>,"');
|
|
}
|
|
//request.cleanHtm = cleanHtm;
|
|
</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> |