This commit is contained in:
shoopea 2019-12-29 21:00:54 +08:00
parent 1606340537
commit dcf879135a

View File

@ -8,7 +8,7 @@ import (
) )
func resetMsgParsingRules2() error { func resetMsgParsingRules2() error {
var rules []MessageParsingRule var rules, rules2 []MessageParsingRule
b, err := Asset("data/msg_rules.json") b, err := Asset("data/msg_rules.json")
logOnError(err, "resetMsgParsingRules2 : load data/msg_rules.json") logOnError(err, "resetMsgParsingRules2 : load data/msg_rules.json")
@ -18,22 +18,28 @@ func resetMsgParsingRules2() error {
err = json.Unmarshal(b, &rules) err = json.Unmarshal(b, &rules)
for k, _ := range rules { for k, r := range rules {
r := rules[k] r2 := MessageParsingRule{
Priority: r.Priority,
Description: r.Description,
Rule: r.Rule,
MsgType: r.MsgType
}
r.MsgTypeID64, err = codeObjSubTypeId(r.MsgType) r2.MsgTypeID64, err = codeObjSubTypeId(r2.MsgType)
logOnError(err, "resetMsgParsingRules2 : codeObjSubTypeId("+r.MsgType+")") logOnError(err, "resetMsgParsingRules2 : codeObjSubTypeId("+r2.MsgType+")")
if err != nil { if err != nil {
return err return err
} }
r.re, err = regexp.Compile(r.Rule) r2.re, err = regexp.Compile(r2.Rule)
logOnError(err, "resetMsgParsingRules2 : Compile("+r.Rule+")") logOnError(err, "resetMsgParsingRules2 : Compile("+r.Rule+")")
if err != nil { if err != nil {
return err return err
} }
b, _ := json.Marshal(r) b, _ := json.Marshal(r2)
log.Printf("Rule : %s\n", string(b)) log.Printf("Rule : %s\n", string(b))
rules2 = append(rules2, r2)
} }
_, err = db.Exec(`TRUNCATE TABLE msg_rules;`) _, err = db.Exec(`TRUNCATE TABLE msg_rules;`)
@ -49,17 +55,17 @@ func resetMsgParsingRules2() error {
return err return err
} }
defer stmt.Close() defer stmt.Close()
for _, r := range rules { for _, r2 := range rules2 {
b, err := json.Marshal(r) b, err := json.Marshal(r2)
log.Printf("Rule2 : %s\n", string(b)) log.Printf("Rule2 : %s\n", string(b))
_, err = stmt.Exec(r.Priority, r.MsgTypeID64, r.Description, r.Rule) _, err = stmt.Exec(r2.Priority, r2.MsgTypeID64, r2.Description, r2.Rule)
logOnError(err, "resetMsgParsingRules2 : insert statement "+r.Description) logOnError(err, "resetMsgParsingRules2 : insert statement "+r2.Description)
if err != nil { if err != nil {
return err return err
} else { } else {
log.Printf("Inserting : %d : %s => %s (%d)\n", r.Priority, r.Description, r.MsgType, r.MsgTypeID64) log.Printf("Inserting : %d : %s => %s (%d)\n", r2.Priority, r2.Description, r2.MsgType, r2.MsgTypeID64)
} }
} }