186 array-map-fixed fidex

This commit is contained in:
2025-12-05 09:33:07 +03:00
parent 76ff672dee
commit 6fc908b6ef
7 changed files with 683 additions and 25 deletions
+68 -17
View File
@@ -105,7 +105,7 @@ arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //In
<cfset local.qCfsParam.value_list = getListFromState(currentState, local.qCfsParam.state_path)/>
</cfif>
<cfif local.qCfsParam.data_type EQ "map">
<cfif local.qCfsParam.data_type EQ "map" OR data_type EQ "map-fixed" OR data_type EQ "array-map-fixed">
<cfset processMap(local.qCfsParam)/><!--- query passed by reference --->
</cfif>
@@ -230,14 +230,24 @@ arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //In
<cfset CreateObject("component", "instance_operation_cfs_param_ls").checkParam(local.qCheck.svc_operation_cfs_param_id, arguments.paramValue, arguments.usrId, arguments.instanceOperationCfsParamUid)/>
</cffunction>
<cffunction name="processMap" returntype="void" access="public">
<cfargument name="qParam" type="query" required=true/>
<cfargument name="qParam" type="query" required=true/><!--- работаем с текущей строкой query. передача query это скорее колхоз, всего-то надо 4 понятных аргумента.
Конечно, то, что часть из них - id, не упрощает восприяие кода --->
<!--- Выполняем 2 задачи (*** вероятно, правильно их разделить по разным функциям)
- сформировать дескриптор
- замаскировать секреты --->
здесь могут использоваться 2 критерия: формат аргумента, array/struct, либо тип
<cfset var map={}/>
<cftry>
<cfset map=deserializeJson(arguments.qParam.param_value)/>
<cfif !isStruct(map)>
<cfset map={}/>
<cfset local.spContainer = {}/><!--- может быть map или array of map --->
<cfset local.spMapArray = []/>
<!--- мы хотим обработать и случай array-map-fixed --->
<cftry>
<cfset local.spContainer = deserializeJSON(arguments.qParam.param_value)/> <!--- а собственно зачем нам тут local? помогает чем-то? --->
<cfif (arguments.qParam.data_type EQ "array-map-fixed")>
<cfset local.spMapArray = isEmpty(local.spContainer) ? [] : local.spContainer />
<cfelse>
<cfset local.spMapArray = [local.spContainer]/>
</cfif>
<cfcatch type="any">
<cfrethrow/>
@@ -279,8 +289,8 @@ arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //In
order by sp.sort
</cfquery>
<cfset var mapDescriptor=structNew("linked")/>
<!--- формируем дескриптор --->
<cfset var mapDescriptor=structNew("linked")/>
<cfloop query="local.qSubparam">
<cfset structInsert(mapDescriptor, local.qSubparam.svc_operation_cfs_subparam,
{
@@ -299,13 +309,27 @@ arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //In
}, true
)
/>
<cfif local.qSubparam.is_sensitive AND structKeyExists(map,local.qSubparam.svc_operation_cfs_subparam)>
<cfset map["#local.qSubparam.svc_operation_cfs_subparam#"] = "********"/>
</cfif>
</cfloop>
</cfloop>
<cfloop index="local.i" from=1 to=#arrayLen(local.spMapArray)#><!--- *** искусственное оборачивание в массив вот для этого, не придумал ничего умнее
чтобы не дублировать цикл по субпараметрам. Сделано некрасиво, но работать должно.
Ну а как сделать? Если массив - делать цикл по массиву, а если map-сразу обрабатыввать map. При этом запрос к таблице сабпараметров не хочется делать лишний раз.
--->
<!--- может быть, лучше смотрелось бы arrayMap, но тут в ней будет цикл по query, и надо это делать в cfscript... строчек будет явно больше,
и в cfscript циклы по query какие-то я не помню ... кстати, вместо цикла по query можно наверно использовать structMap по контенту --->
<!--- интересная и неожиданная разница между циклом по массиву и циклом по индексу массива:
в первом случае возвращается копия элемента, во втором мы естественно имеем дело со ссылокой на элемент,
а нам сейчас нужно второе --->
<cfloop query="local.qSubparam">
<cfif local.qSubparam.is_sensitive AND structKeyExists(local.spMapArray[local.i],local.qSubparam.svc_operation_cfs_subparam)>
<cfset local.spMapArray[local.i]["#local.qSubparam.svc_operation_cfs_subparam#"] = "********"/>
</cfif>
</cfloop>
</cfloop>
<!--- *** проверку, что это не map-fixed, можно добавить здесь --->
<!--- чтобы не вставляли в параметр что попало --->
<!--- здесь мы не делаем цикл по массиву, поскольку не поддерживаем массив расширяемых map --->
<cfloop query="local.qInstSubparam">
<cfset structInsert(mapDescriptor, local.qInstSubparam.instance_operation_cfs_subparam,
{
@@ -315,13 +339,18 @@ arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //In
}, true
)
/>
<cfif local.qInstSubparam.is_sensitive AND structKeyExists(map,local.qInstSubparam.instance_operation_cfs_subparam)>
<cfset map["#local.qInstSubparam.instance_operation_cfs_subparam#"] = "********"/>
<cfif local.qInstSubparam.is_sensitive AND structKeyExists(local.spmap,local.qInstSubparam.instance_operation_cfs_subparam)>
<cfset local.spmap["#local.qInstSubparam.instance_operation_cfs_subparam#"] = "********"/>
</cfif>
</cfloop>
<cfset arguments.qParam.data_descriptor = mapDescriptor/>
<cfset arguments.qParam.param_value = serializeJson(map)/>
<cfset arguments.qParam.data_descriptor = mapDescriptor/>
<cfif (arguments.qParam.data_type EQ "array-map-fixed")>
<cfset arguments.qParam.param_value = serializeJson(local.spMapArray)/><!--- как есть --->
<cfelse>
<cfset arguments.qParam.param_value = serializeJson(local.spMapArray[1])/><!--- вытаскиваем из массива-обертки --->
</cfif>
</cffunction>
@@ -367,6 +396,28 @@ arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //In
<cfreturn valueList(local.qAvailableResourceRealm.resource_realm)/>
</cffunction>
<!--- <cffunction name="getKeysFromState" returnType="string" access="public">
<cfargument name="instance_uid" type="GUID"/>
<cfargument name="path"/>
<cfargument name="args" type="array" default=[]/>
<cfset var local={}/>
<cfquery name="local.qAvailableResourceRealm"><!--- *** distinct халява, но придумывать корректную формулировку времени мало --->
select distinct r.resource_realm, r.sort
from resource_realm r
join resource_realm_access a on
(r.resource_realm_id=a.resource_realm_id
AND (a.contract_id=<cfqueryparam cfsqltype="CF_SQL_INTEGER" value=#arguments.contractId# null=#!isValid("integer", arguments.contractId)#/>
OR a.contract_id=0) /*0 means access to any contract*/
AND a.is_enabled)
join svc s on r.resource_realm_type_id=s.resource_realm_type_id
where s.svc_id=<cfqueryparam cfsqltype="CF_SQL_INTEGER" value=#arguments.svcId# null=#!isValid("integer", arguments.svcId)#/>
order by r.sort, r.resource_realm
</cfquery> <!--- <cfdump var=#arguments#/> cfdump здесь провоцирует NPE --->
<cfreturn valueList(local.qAvailableResourceRealm.resource_realm)/>
</cffunction> --->
<!--- для вложенных справочников --->
<!--- дублировано: deck-tool/instance_operation.cfm --->