009 cfflush

This commit is contained in:
msyu
2025-10-04 22:46:10 +03:00
parent 1f1f88fc65
commit 6d47dfad0a
2 changed files with 60 additions and 52 deletions
+18 -18
View File
@@ -15,28 +15,27 @@
<cfset this.mappings = structNew() />
<cfset this.mappings["/mod"] = getDirectoryFromPath(getCurrentTemplatePath()) & "mod/" />
<cfset this.customTagPaths = expandPath(getDirectoryFromPath(getCurrentTemplatePath()) & "mod")/>
<cfset this.datasource = "rpt"/>
<!--- SSO --->
<cfset this.client_id = "payg-report.deck.nubes.ru"/>
<cfset this.auth_endpoint = "https://keycloak.nubes.ru/realms/cloud/protocol/openid-connect/auth" />
<cfset this.access_token_endpoint = "https://keycloak.nubes.ru/realms/cloud/protocol/openid-connect/token" />
<cfset this.idpCertUrl = "https://keycloak.nubes.ru/realms/cloud/protocol/openid-connect/certs" />
<cfset this.client_secret = createObject("java", "java.lang.System").getEnv("IDP_CLIENT_SECRET")/>
<!--- <cfset this.client_secret = this.client_secret ?: ""/> --->
<cfset this.datasource = "rpt"/>
<cfset this.defaultdatasource = this.datasource/>
<cfset request.DS = "#this.datasource#">
<cfset request.language="">
<cfset getDS(this.datasource)/>
<!--- кажется, нужно инициализировать датасорцы в псевдоконструкторе - onRequest не получается --->
<!--- *** проверить, что есть - если есть, не создавать --->
<!--- не тут-то было: так не работает --->
<!--- <cfif NOT structKeyExists(this.datasources,this.datasource)>
</cfif> --->
<!--- это работает с административно заданным датасорцем, хотя, казалось бы, не должно
(без окружения фунекция вернет пустую структуру). Видимо, административный датасорц обнаруживается раньше.
(без окружения функция вернет пустую структуру). Видимо, административный датасорц обнаруживается раньше.
Проверять на пустоту не хочется, чтобы не плодить в псевдоконструкторе переменные --->
<cfset this.datasources["#this.datasource#"]=getDS("#this.datasource#","ds_#this.datasource#")/>
<!--- <cfdump var=#variables#/> --->
@@ -48,7 +47,7 @@
hint="Fires when the application is first created.">
<!--- *** мы не проверяем срок жизни сертификата и его отзыв--->
Obtain idp certificate OnApplicationStart
<!--- Obtain idp certificate OnApplicationStart --->
<cfset application.idpCertificate = getIdpCertificate(this.idpCertUrl)/>
<cfreturn true />
@@ -79,7 +78,7 @@
<!--- global settings --->
<cfset request.RECORDS_PER_PAGE=500/>
<cfset request.APP_VERSION="0.00.008"/>
<cfset request.APP_VERSION="0.00.009"/>
<cfset request.STAND=getStand()/>
<!--- application constants --->
@@ -153,7 +152,7 @@
<!--- <cfoutput>onRequest:check for cert finished #(getTickCount()-request.startTickCount)#</cfoutput> --->
<cfset this.redirect_uri = "https://#CGI.SERVER_NAME#/#CGI.SCRIPT_NAME#" />
<cfset this.redirect_uri = "https://#CGI.SERVER_NAME##CGI.SCRIPT_NAME#" />
<cfinclude template="inc/functions.cfm"/>
@@ -339,22 +338,21 @@
<cffunction
name="getDS"
access="private"
returntype="struct"
returntype="void"
output="true"
hint="Configure data source from environment variables. Convention: data source name is an environment varialble prefix">
hint="Configure data source from environment variables (if datasource with the name provided already exists, does nothing). Convention: data source name is an environment varialble prefix">
<cfargument name="dsname" type="string" required="true"/>
<cfargument name="prefix" type="string" default=#dsname#/>
<cfset var ds={}/>
<cftry>
<cfquery name="qTestDs" datasource=#arguments.dsname#>
select 1;
</cfquery>
<cfcatch type="any">
<cfset system = createObject("java", "java.lang.System")/>
<cfset var ds={}/>
<cfset var system = createObject("java", "java.lang.System")/>
<cfloop list="class,connectionString,database,driver,dbdriver,host,port,type,url,username,password,bundleName,bundleVersion,connectionLimit,liveTimeout,validate" item="field"><!--- driver vs dbdriver --->
<cfset var value=system.getEnv("#arguments.prefix#_#field#")/>
@@ -368,8 +366,8 @@
<!--- test datasource (just to get exception if invalid) --->
<cftry>
<cfquery name="qTestDs" datasource=#ds#>
select 1;
<cfquery name="qTestDsNextTry" datasource=#ds#>
select 2;
</cfquery>
<cfcatch type="any">
@@ -379,10 +377,12 @@
<cfrethrow/>
</cfcatch>
</cftry>
<cfset this.datasources["#arguments.dsname#"]=#ds#/> <!--- Интересно, доступен ли здесь this --->
</cfcatch>
</cftry>
<!--- <cfdump var=#ds#/> --->
<cfreturn ds/>
<cfreturn/>
</cffunction>
<cfscript>
+39 -31
View File
@@ -14,6 +14,45 @@
<cfset tenant_wz_index=val(mid(request.auth.wz,3,5))/><!--- cut off WZ --->
<!--- looks like QoQ does not support join syntax, at least of Lucee 5.4--->
<cfif isDefined("output_xls")>
<layout:xml qRead=#qCharge# titleMap=#titleMap# filename="#pageInfo.entity#.xml"/>
<cfabort/>
</cfif><cfif isDefined("output_json")>
<layout:json qRead=#qCharge# titleMap=#titleMap# filename="#pageInfo.entity#.json"/>
<cfabort/>
</cfif><!---
---><layout:page section="header" pageInfo=#pageInfo#>
<layout:attribute name="title">
<cfoutput><b>Отчет по PAYG</b> #request.auth.wz#</cfoutput>
</layout:attribute>
<layout:attribute name="controls">
<!---skip filter link, filter is not implemented--->
<!---<layout:language_switch/>--->
</layout:attribute>
</layout:page>
<!--- Внимание! округление вверх при расчете метрик get, put S3. Расчетные суммы могут содержать погрешности округления, поэтому окончательный расчет стоимости (количество * цену) должен выполняться в бухгалтерской программе.
<b>Если у клиента больше 1 действующего допника с услугами PAYG, то данные в отчете могут быть замножены, в этом случае считать вручную</b> --->
<cfoutput>
<form method="post" action="">
Период с <input type="text" name="dt_start" value="#dateFormat(dt_start,'YYYY-MM-DD')#"/>
по <input type="text" name="dt_finish" value="#dateFormat(dt_finish,'YYYY-MM-DD')#"/>
<input type="submit" style="cursor:pointer;"/>
<!--- <input type="submit" name="DEBUG" value="DEBUG" style="cursor:pointer;"/> --->
</form>
<cfflush/>
<!--- Для начала выкатываем просто кусок каталога, не фильтруя по спеке (которой иногда нет) --->
<cfquery name="qSpec">
select * from (
@@ -266,37 +305,6 @@ FROM qSpec as s, qUnifiedMetric as m
WHERE m.wz=<cfqueryparam cfsqltype="cf_sql_varchar" value=#request.auth.wz#/> AND s.code=m.code
order by s.code
</cfquery>
<!--- looks like QoQ does not support join syntax, at least of Lucee 5.4--->
<cfif isDefined("output_xls")>
<layout:xml qRead=#qCharge# titleMap=#titleMap# filename="#pageInfo.entity#.xml"/>
<cfabort/>
</cfif><cfif isDefined("output_json")>
<layout:json qRead=#qCharge# titleMap=#titleMap# filename="#pageInfo.entity#.json"/>
<cfabort/>
</cfif><!---
---><layout:page section="header" pageInfo=#pageInfo#>
<layout:attribute name="title">
<cfoutput><b>Отчет по PAYG</b> #request.auth.wz#</cfoutput>
</layout:attribute>
<layout:attribute name="controls">
<!---skip filter link, filter is not implemented--->
<!---<layout:language_switch/>--->
</layout:attribute>
</layout:page>
<!--- Внимание! округление вверх при расчете метрик get, put S3. Расчетные суммы могут содержать погрешности округления, поэтому окончательный расчет стоимости (количество * цену) должен выполняться в бухгалтерской программе.
<b>Если у клиента больше 1 действующего допника с услугами PAYG, то данные в отчете могут быть замножены, в этом случае считать вручную</b> --->
<cfoutput>
<form method="post" action="">
Период с <input type="text" name="dt_start" value="#dateFormat(dt_start,'YYYY-MM-DD')#"/>
по <input type="text" name="dt_finish" value="#dateFormat(dt_finish,'YYYY-MM-DD')#"/>
<input type="submit" style="cursor:pointer;"/>
<!--- <input type="submit" name="DEBUG" value="DEBUG" style="cursor:pointer;"/> --->
</form>
Часов в периоде: <b>#hours#</b> Строк в отчете: <b>#qCharge.recordCount#</b><br/>
Актуальность данных:
VCD Computing: <b>#dateFormat(qComputingAge.dt_load,'YYYY-MM-DD')# #timeFormat(qComputingAge.dt_load,'HH:MM:SS')#</b>