svc_default

This commit is contained in:
msyu
2024-11-15 16:00:40 +03:00
parent 43eca3da56
commit 34e914fd7e
4 changed files with 140 additions and 9 deletions
+52 -5
View File
@@ -155,14 +155,18 @@
<cfargument name="displayName" type="string" required=true hint="type:string"/>
<cfargument name="serviceId" type="string" required=true hint="type:integer"/>
<cfargument name="descr" type="string" required=false default="" hint="type:varchar (no cleanup here!)"/>
<!--- <cfargument name="instanceUid" type="string" required=false default="" hint="type:guid)"/> --->
<!--- <cfargument name="usrUid" type="string" required=true hint="type:guid"/>
<cfargument name="companyUid" type="string" required=true hint="type:guid"/> --->
<!--- оказывается, их можно и не декларировать --->
<cfset local={}/>
<cfset local.instanceUid=#createGUID()#/>
<!--- <cfdump var=#arguments#/><cfabort/> --->
<!--- <cfif structKeyExists(arguments,"instanceUid")>
<cfset local.instanceUid=arguments.instanceUid/>
<cfelse> --->
<cfset local.instanceUid=#createGUID()#/>
<!--- </cfif> --->
<cftry>
<cfset this.helper.keyExistsAndValid(arguments, "serviceId", "integer")/>
@@ -214,19 +218,22 @@
/>
</cffunction>
<cffunction name="checkDisplayName">
<cfargument name="displayName" required=true/>
<cfargument name="usrId" type="numeric" required=true/>
<cfargument name="instanceUid" type="guid" required=true/>
<cfset var display_name=trim(lcase(arguments.displayName))/>
<cfset var local={}/>
<cfset var display_name=trim(lcase(arguments.displayName))/>
<cfif len(display_name) LT 3>
<cfthrow type="InvalidParamValue" message="Instance Display Name too short" detail="Имя должно быть не короче 3 символов"/>
<cfelseif len(display_name) GT 80>
<cfthrow type="InvalidParamValue" message="Instance Display Name too long" detail="Имя должно быть не длиннее 80 символов"/>
<cfelse>
<cfquery name="qUniqueDisplayName">
<cfquery name="local.qUniqueDisplayName">
select count(*) as cnt from instance e
join specification_item i on (e.specification_item_id=i.specification_item_id)
join specification s on (i.specification_id=s.specification_id)
@@ -237,10 +244,50 @@
AND lower(e.display_name)=lower(<cfqueryparam cfsqltype="cf_sql_varchar" value=#arguments.displayName#/>)
AND e.instance_uid <> <cfqueryparam cfsqltype="cf_sql_other" value=#arguments.instanceUid#/>
</cfquery>
<cfif qUniqueDisplayName.cnt GT 0>
<cfif local.qUniqueDisplayName.cnt GT 0>
<cfthrow type="InvalidParamValue" message="Instance Display Name not unique" detail="Имя экземпляра должно быть уникальным в рамках договора"/>
</cfif>
</cfif>
</cffunction>
<cffunction name="generateDefaultName" returnType="string">
<!--- *** Это некорректно, потому что имя может содержать пробелы и т.п. --->
<!--- *** Неуклюже и медленно --->
<!--- Эти валидации и генерации занимают удивительно много рабочего времени --->
<cfargument name="service_id" type="numeric"/>
<cfargument name="usr_id" type="numeric"/>
<cfset var local={}/>
<cfquery name="local.qSvc">
select svc from svc where svc_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.service_id#/>
</cfquery>
<cfquery name="local.qInst">
select display_name
from instance e
join specification_item i on (e.specification_item_id=i.specification_item_id)
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)
where u.usr_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.usr_id#/>
AND lower(e.display_name) like lower(<cfqueryparam cfsqltype="cf_sql_varchar" value="#local.qSvc.svc#%"/>)
AND service_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.service_id#/>
</cfquery>
<cfset var prefixLen=len(local.qSvc.svc)+1/>
<cfset var i=1/>
<cfloop query="local.qInst">
<cfif len(local.qInst.display_name) GT prefixLen>
<cfset var suffix=right(local.qInst.display_name, len(local.qInst.display_name)-prefixLen)/>
<cfif isValid("integer",suffix)>
<cfset i=(i GT int(suffix))?i:int(suffix)/>
</cfif>
</cfif>
</cfloop>
<cfreturn "#local.qSvc.svc#-#i+1#"/>
</cffunction>
</cfcomponent>