From 669eaec34f3a473badd67506e54db9d09876ea4c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Sep 2026 18:22:17 +0300 Subject: [PATCH] 089 xl json dates, gpu fixes --- Application.cfc | 3 ++- deal.cfm | 6 ++--- gpu_ls.cfm | 34 ++++++++++++++++++------ inc/functions.cfm | 25 ++++++++++++++++++ layout/json.cfm | 63 +++++++++++++++++++++++++++++++++++++++++--- test_storage_rpt.cfm | 2 +- vm_gpu_rpt.cfm | 5 ++-- 7 files changed, 119 insertions(+), 19 deletions(-) diff --git a/Application.cfc b/Application.cfc index dea3149..e3081d4 100644 --- a/Application.cfc +++ b/Application.cfc @@ -15,6 +15,7 @@ + @@ -87,7 +88,7 @@ - + diff --git a/deal.cfm b/deal.cfm index cca2371..7935483 100644 --- a/deal.cfm +++ b/deal.cfm @@ -54,7 +54,7 @@ k.__name as contragent ,k.id_klienta as wz ,k.__index as contragent_index - ,d."_plannedDueDate" as _plannedDueDate + ,d."__createdAt" ,d."__index" as deal_index ,s.status @@ -131,12 +131,12 @@ -
+
Статус
diff --git a/gpu_ls.cfm b/gpu_ls.cfm index c6c6ffa..c5aae3b 100644 --- a/gpu_ls.cfm +++ b/gpu_ls.cfm @@ -8,21 +8,39 @@ + - - -select obj_uuid, obj_id, client_id as WZ, vcd, org, org_vdc, vcenter, gpu, dt_load, dt_load_ts, org_status, cluster as clus, is_template + +select + + obj_uuid::text as obj_uuid + obj_id + client_id as WZ + vcd + org + org_vdc + vcenter + gpu::text as gpu + dt_load + dt_load_ts + org_status + cluster as clus + is_template + (1=1) as t1 + (1=0) as t2 + (1=null) as t3 + from gpu.vm order by client_id - + - + - + @@ -45,7 +63,7 @@ order by client_id -#qGPU.recordCount# +#qRead.recordCount# @@ -62,7 +80,7 @@ order by client_id - + diff --git a/inc/functions.cfm b/inc/functions.cfm index 5e92d70..419cac2 100644 --- a/inc/functions.cfm +++ b/inc/functions.cfm @@ -311,6 +311,29 @@ public string function formatJsonString(str) { } request.formatJsonString = formatJsonString; //нужна еще функция, которая сериализует структуру как pretty printed json. См. https://github.com/bennadel/JsonSerializer.cfc (все не совсем просто, например, не заранее не определен формат даты) + +/** +* @hint Приводит поле резалтсета к булевому типу, пригодному для сериализации в json, вместо null возвращает false. +*/ +boolean function castToBoolSimple(any x) { + if ( !structKeyExists( arguments, "x" ) || isNull( arguments.x ) ) { + return false; + } + // 2. Handle empty strings, empty arrays, or empty structs + if ( isSimpleValue( arguments.x ) && trim( arguments.x ) == "" ) { + return false; + } + if ( isArray( arguments.x ) && arrayIsEmpty( arguments.x ) ) { + return false; + } + if ( isStruct( arguments.x ) && structIsEmpty( arguments.x ) ) { + return false; + } + // 3. Fall back to standard CFML truthy evaluation + return isBoolean( arguments.x ) && arguments.x ? true : false; +} +request.castToBoolSimple=castToBoolSimple; + @@ -361,3 +384,5 @@ request.formatJsonString = formatJsonString; + + diff --git a/layout/json.cfm b/layout/json.cfm index 47ebf3b..81d90a1 100644 --- a/layout/json.cfm +++ b/layout/json.cfm @@ -67,7 +67,7 @@ - //copy fields to structure, renaming fields, this preserves data type + @@ -76,9 +76,9 @@ - + - + @@ -96,4 +96,59 @@ type="application/json" />#query2json(ATTRIBUTES.qRead,ATTRIBUTES.convertSnakeToCamel)# - \ No newline at end of file + + + + +public string function customJson(required any data) { + return serializeJson(formatDatesToIso(arguments.data)); +} + +private any function formatDatesToIso(required any input) { + // 1. Handle Dates (Strict verification using isValid and checking underlying type) + // Lucee dates are typically objects (java.util.Date / java.time). + // This prevents strings like "12345" or "Yes" from being treated as dates. + if (isDate(arguments.input) && (isObject(arguments.input) || !isValid("integer", arguments.input))) { + return dateTimeFormat(arguments.input, "iso8601"); + } + + // 2. Handle Structs (Preserve case-sensitivity using [:] syntax) + if (isStruct(arguments.input)) { + var newStruct = [Ordered: true]; // Lucee/CF literal for preserving key case + for (var key in arguments.input) { + newStruct[key] = formatDatesToIso(arguments.input[key]); + } + return newStruct; + } + + // 3. Handle Arrays + if (isArray(arguments.input)) { + var newArray = []; + for (var item in arguments.input) { + arrayAppend(newArray, formatDatesToIso(item)); + } + return newArray; + } + + // 4. Handle Queries + if (isQuery(arguments.input)) { + var queryArray = []; + var columns = arguments.input.getColumnNames(); // Returns correct case array + + loop query="arguments.input" { + var rowStruct = [Ordered: true]; + loop array="#columns#" index="col" { + // Safely grab cell using row coordinates + rowStruct[col] = formatDatesToIso(arguments.input[col][arguments.input.currentRow]); + } + arrayAppend(queryArray, rowStruct); + } + return queryArray; + } + + // 5. Return everything else untouched (Strings, Numbers, Booleans, etc.) + return arguments.input; +} + \ No newline at end of file diff --git a/test_storage_rpt.cfm b/test_storage_rpt.cfm index 6402844..d9228d4 100644 --- a/test_storage_rpt.cfm +++ b/test_storage_rpt.cfm @@ -219,7 +219,7 @@ ORDER BY - + diff --git a/vm_gpu_rpt.cfm b/vm_gpu_rpt.cfm index 80bf328..7ae8994 100644 --- a/vm_gpu_rpt.cfm +++ b/vm_gpu_rpt.cfm @@ -89,9 +89,10 @@ GPU-VM Power State: class="e
- + - + +(перед выгрузкой отчета на произвольную дату просмотрите его в браузере)
#WZ# #obj_uuid# b err">#dateFormat(dt_end_of_test,"YYYY-MM-DD")# #deal##deal_status# [#status_id#]#deal_status# [#status_id#] #additional_agreement# #contract# (#contract_id#)