From eafb5f053a56078eccea00ebb16d5dfe4017734e Mon Sep 17 00:00:00 2001 From: pycook Date: Mon, 26 Aug 2024 22:31:58 +0800 Subject: [PATCH] fix(api): custom dashboard for enum type --- cmdb-api/api/lib/cmdb/cache.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmdb-api/api/lib/cmdb/cache.py b/cmdb-api/api/lib/cmdb/cache.py index ae6efbb..6ce0aa6 100644 --- a/cmdb-api/api/lib/cmdb/cache.py +++ b/cmdb-api/api/lib/cmdb/cache.py @@ -379,10 +379,17 @@ class CMDBCounterCache(object): other_filter = "{}".format(other_filter) if other_filter else '' if custom['options'].get('ret') == 'cis': + enum_map = {} + for _attr_id in attr_ids: + _attr = AttributeCache.get(_attr_id) + if _attr: + enum_map[_attr.alias] = AttributeManager.get_enum_map(_attr_id) + query = "_type:({}),{}".format(";".join(map(str, type_ids)), other_filter) s = search(query, fl=attr_ids, ret_key='alias', count=100) try: cis, _, _, _, _, _ = s.search() + cis = [{k: (enum_map.get(k) or {}).get(v, v) for k, v in ci.items()} for ci in cis] except SearchError as e: current_app.logger.error(e) return @@ -431,7 +438,7 @@ class CMDBCounterCache(object): # level = 3 enum_map3 = AttributeManager.get_enum_map(attr_ids[2]) for v1 in origin_result: - if not isinstance(result[v1], dict): + if not isinstance(result[enum_map1.get(v1, v1)], dict): continue for v2 in origin_result[v1]: query = "_type:({}),{},{}:{},{}:{}".format(";".join(map(str, type_ids)), other_filter,