package vo
|
|
import (
|
"encoding/json"
|
"strings"
|
"vamicro/push-service/models"
|
)
|
|
type EventPushVo struct {
|
Id string `json:"id"`
|
Name string `json:"name"`
|
PushType int `json:"push_type"`
|
TimeStart string `json:"time_start"`
|
TimeEnd string `json:"time_end"`
|
IsSatisfyAll bool `json:"is_satisfy_all"`
|
RuleText string `json:"rule_text"`
|
Enable bool `json:"enable"`
|
LinkType string `json:"link_type"`
|
LinkDevice string `json:"link_device"`
|
|
IpPorts []EventPushServerPortVo `json:"ip_ports"`
|
Urls []EventUrlVo `json:"urls"`
|
Rules []models.EventPushRule `json:"rules"`
|
|
FiltRename map[string]string `json:"filtRename"`
|
PushSet []PushSetMenu `json:"push_set"`
|
}
|
|
type PushSetMenu struct {
|
Id string `json:"id"`
|
Name string `json:"name"`
|
Checked bool `json:"checked"`
|
Alias string `json:"alias"`
|
Children []PushSetMenu `json:"children"`
|
}
|
|
type EventPushServerPortVo struct {
|
ServerIp string `json:"server_ip"`
|
Port int `json:"port"`
|
Enable bool `json:"enable"`
|
}
|
|
type EventUrlVo struct {
|
Url string `json:"url"`
|
ServerIp string `json:"server_ip"`
|
Port int `json:"port"`
|
Enable bool `json:"enable"`
|
}
|
|
func (epv *EventPushVo) SetFiltRename() {
|
epv.FiltRename = make(map[string]string)
|
if epv.PushSet != nil {
|
for _, set := range epv.PushSet {
|
if set.Children != nil {
|
for _, child := range set.Children {
|
if child.Checked {
|
prefix := ""
|
idx := strings.LastIndex(child.Id, ".")
|
if idx > -1 {
|
prefix = child.Id[:idx+1]
|
}
|
epv.FiltRename[child.Id] = prefix + child.Alias
|
}
|
}
|
}
|
}
|
}
|
}
|
|
func (epv *EventPushVo) CopyToEventPush() models.EventPush {
|
d, _ := json.Marshal(epv.PushSet)
|
return models.EventPush{
|
Id: epv.Id,
|
Name: epv.Name,
|
TimeStart: epv.TimeStart,
|
TimeEnd: epv.TimeEnd,
|
IsSatisfyAll: epv.IsSatisfyAll,
|
RuleText: epv.RuleText,
|
Enable: epv.Enable,
|
PushType: epv.PushType,
|
LinkType: epv.LinkType,
|
LinkDevice: epv.LinkDevice,
|
PushSet: string(d),
|
}
|
}
|
|
func (epv *EventPushVo) CopyFromEventPush(epE *models.EventPush) {
|
epv.Id = epE.Id
|
epv.Name = epE.Name
|
epv.TimeStart = epE.TimeStart
|
epv.TimeEnd = epE.TimeEnd
|
epv.IsSatisfyAll = epE.IsSatisfyAll
|
epv.PushType = epE.PushType
|
epv.RuleText = epE.RuleText
|
epv.Enable = epE.Enable
|
epv.LinkType = epE.LinkType
|
epv.LinkDevice = epE.LinkDevice
|
if epE.PushSet != "" {
|
var set []PushSetMenu
|
if err := json.Unmarshal([]byte(epE.PushSet), &set); err == nil {
|
epv.PushSet = set
|
} else {
|
epv.PushSet = make([]PushSetMenu, 0)
|
}
|
} else {
|
epv.PushSet = make([]PushSetMenu, 0)
|
}
|
}
|
|
type KeyValueVo struct {
|
Value string `json:"value"`
|
Name string `json:"name"`
|
}
|