|
@@ -10,6 +10,7 @@ import (
|
|
|
"kpt-temporary-mqtt/util"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
var messagePubHandler golangMqtt.MessageHandler = func(client golangMqtt.Client, msg golangMqtt.Message) {
|
|
@@ -64,10 +65,22 @@ func (d *DataEventEntry) CreatMsgLog(msg []byte) {
|
|
|
if err != nil {
|
|
|
zaplog.Error("CreatMsgLog", zap.Any("err", err), zap.Any("msg", string(msg)))
|
|
|
}
|
|
|
+ if subMsgLog == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if subMsgLog.Imei == "" {
|
|
|
+ zaplog.Info("CreatMsgLog", zap.Any("msg", string(msg)), zap.Any("subMsgLog", subMsgLog))
|
|
|
+ }
|
|
|
+
|
|
|
+ defer func() {
|
|
|
+ if time.Now().Day()%15 == 0 {
|
|
|
+ d.DB.Model(new(model.SubMsgLog)).Where("created_at < ?", time.Now().AddDate(0, 0, -10).Unix()).Delete(new(model.SubMsgLog))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
|
|
|
- if err := d.DB.Table(new(model.SubMsgLog).TableName()).Create(subMsgLog).Error; err != nil {
|
|
|
- fmt.Println("msg", string(msg))
|
|
|
- fmt.Println("subMsgLog", subMsgLog)
|
|
|
+ if err = d.DB.Table(new(model.SubMsgLog).TableName()).Create(subMsgLog).Error; err != nil {
|
|
|
+ zaplog.Error("CreatMsgLog", zap.Any("err", err), zap.Any("msg", string(msg)), zap.Any("subMsgLog", subMsgLog))
|
|
|
}
|
|
|
}
|
|
|
|