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