This commit is contained in:
@@ -63,6 +63,8 @@ func (s *Service) logDeviceOperation(
|
|||||||
snapshot := deviceSnapshot(device)
|
snapshot := deviceSnapshot(device)
|
||||||
beforeContent := stripDeviceOperationMeta(beforeData)
|
beforeContent := stripDeviceOperationMeta(beforeData)
|
||||||
afterContent := stripDeviceOperationMeta(afterData)
|
afterContent := stripDeviceOperationMeta(afterData)
|
||||||
|
beforeContent = ensureDeviceOperationContentMap(beforeContent, beforeData)
|
||||||
|
afterContent = ensureDeviceOperationContentMap(afterContent, afterData)
|
||||||
enrichDeviceOperationContent(beforeContent, beforeData)
|
enrichDeviceOperationContent(beforeContent, beforeData)
|
||||||
enrichDeviceOperationContent(afterContent, afterData)
|
enrichDeviceOperationContent(afterContent, afterData)
|
||||||
params.BeforeData, params.AfterData = assetAuditSvc.WrapOperationContent(beforeContent, afterContent, snapshot)
|
params.BeforeData, params.AfterData = assetAuditSvc.WrapOperationContent(beforeContent, afterContent, snapshot)
|
||||||
@@ -95,6 +97,27 @@ func stripDeviceOperationMeta(data map[string]any) map[string]any {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ensureDeviceOperationContentMap(content map[string]any, raw map[string]any) map[string]any {
|
||||||
|
if content != nil || len(raw) == 0 {
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
if _, ok := raw["device"].(map[string]any); ok {
|
||||||
|
return make(map[string]any)
|
||||||
|
}
|
||||||
|
if _, ok := raw["card"].(map[string]any); ok {
|
||||||
|
return make(map[string]any)
|
||||||
|
}
|
||||||
|
switch raw["devices"].(type) {
|
||||||
|
case []map[string]any, []any:
|
||||||
|
return make(map[string]any)
|
||||||
|
}
|
||||||
|
switch raw["cards"].(type) {
|
||||||
|
case []map[string]any, []any:
|
||||||
|
return make(map[string]any)
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
func enrichDeviceOperationContent(content map[string]any, raw map[string]any) {
|
func enrichDeviceOperationContent(content map[string]any, raw map[string]any) {
|
||||||
if len(raw) == 0 {
|
if len(raw) == 0 {
|
||||||
return
|
return
|
||||||
@@ -133,6 +156,33 @@ func enrichDeviceOperationContent(content map[string]any, raw map[string]any) {
|
|||||||
content["device_virtual_nos"] = virtualNos
|
content["device_virtual_nos"] = virtualNos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch cardsRaw := raw["cards"].(type) {
|
||||||
|
case []map[string]any:
|
||||||
|
cardIDs, iccids := collectDeviceAuditCardReadableLists(cardsRaw)
|
||||||
|
if len(cardIDs) > 0 && content["card_ids"] == nil {
|
||||||
|
content["card_ids"] = cardIDs
|
||||||
|
}
|
||||||
|
if len(iccids) > 0 && content["iccids"] == nil {
|
||||||
|
content["iccids"] = iccids
|
||||||
|
}
|
||||||
|
case []any:
|
||||||
|
cards := make([]map[string]any, 0, len(cardsRaw))
|
||||||
|
for _, item := range cardsRaw {
|
||||||
|
cardMap, ok := item.(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cards = append(cards, cardMap)
|
||||||
|
}
|
||||||
|
cardIDs, iccids := collectDeviceAuditCardReadableLists(cards)
|
||||||
|
if len(cardIDs) > 0 && content["card_ids"] == nil {
|
||||||
|
content["card_ids"] = cardIDs
|
||||||
|
}
|
||||||
|
if len(iccids) > 0 && content["iccids"] == nil {
|
||||||
|
content["iccids"] = iccids
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeReadableDeviceFields(content map[string]any, device map[string]any) {
|
func mergeReadableDeviceFields(content map[string]any, device map[string]any) {
|
||||||
@@ -191,6 +241,20 @@ func collectDeviceReadableLists(devices []map[string]any) ([]any, []string) {
|
|||||||
return deviceIDs, virtualNos
|
return deviceIDs, virtualNos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func collectDeviceAuditCardReadableLists(cards []map[string]any) ([]any, []string) {
|
||||||
|
cardIDs := make([]any, 0, len(cards))
|
||||||
|
iccids := make([]string, 0, len(cards))
|
||||||
|
for _, card := range cards {
|
||||||
|
if id, ok := card["id"]; ok {
|
||||||
|
cardIDs = append(cardIDs, id)
|
||||||
|
}
|
||||||
|
if iccid := stringifyDeviceAuditValue(card["iccid"]); iccid != "" {
|
||||||
|
iccids = append(iccids, iccid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cardIDs, iccids
|
||||||
|
}
|
||||||
|
|
||||||
func stringifyDeviceAuditValue(v any) string {
|
func stringifyDeviceAuditValue(v any) string {
|
||||||
switch vv := v.(type) {
|
switch vv := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ func normalizeCardAuditPayload(beforeData, afterData map[string]any) (map[string
|
|||||||
}
|
}
|
||||||
beforeContent := stripCardOperationMeta(beforeData)
|
beforeContent := stripCardOperationMeta(beforeData)
|
||||||
afterContent := stripCardOperationMeta(afterData)
|
afterContent := stripCardOperationMeta(afterData)
|
||||||
|
beforeContent = ensureCardOperationContentMap(beforeContent, beforeData)
|
||||||
|
afterContent = ensureCardOperationContentMap(afterContent, afterData)
|
||||||
enrichCardOperationContent(beforeContent, beforeData)
|
enrichCardOperationContent(beforeContent, beforeData)
|
||||||
enrichCardOperationContent(afterContent, afterData)
|
enrichCardOperationContent(afterContent, afterData)
|
||||||
return assetAuditSvc.WrapOperationContent(beforeContent, afterContent, snapshot)
|
return assetAuditSvc.WrapOperationContent(beforeContent, afterContent, snapshot)
|
||||||
@@ -80,6 +82,24 @@ func stripCardOperationMeta(data map[string]any) map[string]any {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ensureCardOperationContentMap(content map[string]any, raw map[string]any) map[string]any {
|
||||||
|
if content != nil || len(raw) == 0 {
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
if _, ok := raw["card"].(map[string]any); ok {
|
||||||
|
return make(map[string]any)
|
||||||
|
}
|
||||||
|
if _, ok := raw["device"].(map[string]any); ok {
|
||||||
|
return make(map[string]any)
|
||||||
|
}
|
||||||
|
switch raw["cards"].(type) {
|
||||||
|
case []map[string]any, []any:
|
||||||
|
return make(map[string]any)
|
||||||
|
default:
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func enrichCardOperationContent(content map[string]any, raw map[string]any) {
|
func enrichCardOperationContent(content map[string]any, raw map[string]any) {
|
||||||
if len(raw) == 0 {
|
if len(raw) == 0 {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user