40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model"
|
|
)
|
|
|
|
func appDiagnosisApplyNetworkBlock(info *model.AppDiagnosisInfoItem, raw json.RawMessage) bool {
|
|
var data struct {
|
|
NetBlockStatus *string `json:"netBlockStatus"`
|
|
NetBlockTypes []struct {
|
|
BlockType string `json:"blockType"`
|
|
BlockTypeName string `json:"blockTypeName"`
|
|
} `json:"netBlockTypes"`
|
|
}
|
|
if err := json.Unmarshal(raw, &data); err != nil || data.NetBlockStatus == nil {
|
|
return false
|
|
}
|
|
status := strings.TrimSpace(*data.NetBlockStatus)
|
|
if status != "0" && status != "1" {
|
|
return false
|
|
}
|
|
info.NetBlockStatus = appDiagnosisStringPtr(status)
|
|
info.NetBlockReason = nil
|
|
if status == "1" {
|
|
names := make([]string, 0, len(data.NetBlockTypes))
|
|
seen := make(map[string]bool)
|
|
for _, item := range data.NetBlockTypes {
|
|
name := strings.TrimSpace(item.BlockTypeName)
|
|
if item.BlockType != "0" && name != "" && !seen[name] {
|
|
names = append(names, name)
|
|
seen[name] = true
|
|
}
|
|
}
|
|
info.NetBlockReason = appDiagnosisStringPtr(strings.Join(names, "、"))
|
|
}
|
|
return true
|
|
}
|