mirror of https://github.com/veops/cmdb.git
feat(cmdb): 添加操作历史表的唯一值列 (Add unique value column to operation history table)
This commit is contained in:
parent
d0779d17fa
commit
179463e733
|
@ -10,6 +10,7 @@ from api.extensions import db
|
||||||
from api.lib.cmdb.cache import AttributeCache
|
from api.lib.cmdb.cache import AttributeCache
|
||||||
from api.lib.cmdb.cache import RelationTypeCache
|
from api.lib.cmdb.cache import RelationTypeCache
|
||||||
from api.lib.cmdb.const import OperateType
|
from api.lib.cmdb.const import OperateType
|
||||||
|
from api.lib.cmdb.cache import CITypeCache
|
||||||
from api.lib.cmdb.perms import CIFilterPermsCRUD
|
from api.lib.cmdb.perms import CIFilterPermsCRUD
|
||||||
from api.lib.cmdb.resp_format import ErrFormat
|
from api.lib.cmdb.resp_format import ErrFormat
|
||||||
from api.lib.perm.acl.cache import UserCache
|
from api.lib.perm.acl.cache import UserCache
|
||||||
|
@ -22,7 +23,7 @@ from api.models.cmdb import CITypeHistory
|
||||||
from api.models.cmdb import CITypeTrigger
|
from api.models.cmdb import CITypeTrigger
|
||||||
from api.models.cmdb import CITypeUniqueConstraint
|
from api.models.cmdb import CITypeUniqueConstraint
|
||||||
from api.models.cmdb import OperationRecord
|
from api.models.cmdb import OperationRecord
|
||||||
from api.lib.cmdb.utils import ValueTypeMap
|
from api.lib.cmdb.utils import TableMap
|
||||||
|
|
||||||
|
|
||||||
class AttributeHistoryManger(object):
|
class AttributeHistoryManger(object):
|
||||||
|
@ -60,23 +61,21 @@ class AttributeHistoryManger(object):
|
||||||
total = len(records)
|
total = len(records)
|
||||||
|
|
||||||
res = {}
|
res = {}
|
||||||
unique_set = {}
|
show_attr_set = {}
|
||||||
from api.lib.cmdb.ci import CIManager
|
show_attr_cache = {}
|
||||||
for record in records:
|
for record in records:
|
||||||
record_id = record.OperationRecord.id
|
record_id = record.OperationRecord.id
|
||||||
|
type_id = record.OperationRecord.type_id
|
||||||
ci_id = record.AttributeHistory.ci_id
|
ci_id = record.AttributeHistory.ci_id
|
||||||
if ci_id not in unique_set:
|
show_attr_set[ci_id] = None
|
||||||
ci = CIManager.get_by_id(ci_id)
|
|
||||||
if ci and hasattr(ci, 'ci_type') and ci.ci_type:
|
ci_type = CITypeCache.get(type_id)
|
||||||
unique_id = ci.ci_type.unique_id
|
if ci_type:
|
||||||
unique_ci_type = AttributeCache.get(unique_id).value_type
|
show_attr = show_attr_cache.setdefault(type_id, AttributeCache.get(ci_type.show_id or ci_type.unique_id))
|
||||||
value_table_name = ValueTypeMap.table_name.get(f"index_{unique_ci_type}")
|
attr_table = TableMap(attr=show_attr).table
|
||||||
value_table_list = getattr(ci, f"{value_table_name}.ci_id", None)
|
attr_record = attr_table.get_by(attr_id=show_attr.id, ci_id=ci_id, first=True, to_dict=False)
|
||||||
matched_items = [item for item in value_table_list if item.attr_id == unique_id] if value_table_list else []
|
show_attr_set[ci_id] = attr_record.value if attr_record else None
|
||||||
if matched_items:
|
|
||||||
unique_set[ci_id] = matched_items[0].value
|
|
||||||
else:
|
|
||||||
unique_set[ci_id] = None
|
|
||||||
attr_hist = record.AttributeHistory.to_dict()
|
attr_hist = record.AttributeHistory.to_dict()
|
||||||
attr_hist['attr'] = AttributeCache.get(attr_hist['attr_id'])
|
attr_hist['attr'] = AttributeCache.get(attr_hist['attr_id'])
|
||||||
if attr_hist['attr']:
|
if attr_hist['attr']:
|
||||||
|
@ -92,7 +91,7 @@ class AttributeHistoryManger(object):
|
||||||
|
|
||||||
if record_id not in res:
|
if record_id not in res:
|
||||||
record_dict = record.OperationRecord.to_dict()
|
record_dict = record.OperationRecord.to_dict()
|
||||||
record_dict['unique_value'] = unique_set.get(ci_id)
|
record_dict['show_attr_value'] = show_attr_set.get(ci_id)
|
||||||
record_dict["user"] = UserCache.get(record_dict.get("uid"))
|
record_dict["user"] = UserCache.get(record_dict.get("uid"))
|
||||||
if record_dict["user"]:
|
if record_dict["user"]:
|
||||||
record_dict['user'] = record_dict['user'].nickname
|
record_dict['user'] = record_dict['user'].nickname
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
</template>
|
</template>
|
||||||
</vxe-column>
|
</vxe-column>
|
||||||
<vxe-column field="type_id" width="100px" :title="$t('cmdb.ciType.ciType')"></vxe-column>
|
<vxe-column field="type_id" width="100px" :title="$t('cmdb.ciType.ciType')"></vxe-column>
|
||||||
<vxe-column field="unique_value" width="100px" :title="$t('cmdb.ciType.uniqueKey')"></vxe-column>
|
<vxe-column field="show_attr_value" width="100px" :title="$t('cmdb.ciType.show')"></vxe-column>
|
||||||
<vxe-column field="operate_type" width="89px" :title="$t('operation')">
|
<vxe-column field="operate_type" width="89px" :title="$t('operation')">
|
||||||
<template #header="{ column }">
|
<template #header="{ column }">
|
||||||
<span>{{ column.title }}</span>
|
<span>{{ column.title }}</span>
|
||||||
|
@ -315,7 +315,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mergeRowMethod({ row, _rowIndex, column, visibleData }) {
|
mergeRowMethod({ row, _rowIndex, column, visibleData }) {
|
||||||
const fields = ['created_at', 'user', 'type_id', 'unique_value']
|
const fields = ['created_at', 'user', 'type_id', 'show_attr_value']
|
||||||
const cellValue = row[column.property]
|
const cellValue = row[column.property]
|
||||||
const created_at = row['created_at']
|
const created_at = row['created_at']
|
||||||
if (column.property === 'created_at') {
|
if (column.property === 'created_at') {
|
||||||
|
@ -366,7 +366,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (column.property === 'unique_value') {
|
} else if (column.property === 'show_attr_value') {
|
||||||
if (cellValue && fields.includes(column.property)) {
|
if (cellValue && fields.includes(column.property)) {
|
||||||
const prevRow = visibleData[_rowIndex - 1]
|
const prevRow = visibleData[_rowIndex - 1]
|
||||||
let nextRow = visibleData[_rowIndex + 1]
|
let nextRow = visibleData[_rowIndex + 1]
|
||||||
|
|
Loading…
Reference in New Issue