2023-01-25 11:49:21 +08:00
|
|
|
// Package queues
|
|
|
|
// @Link https://github.com/bufanyun/hotgo
|
2023-02-23 17:53:04 +08:00
|
|
|
// @Copyright Copyright (c) 2023 HotGo CLI
|
2023-01-25 11:49:21 +08:00
|
|
|
// @Author Ms <133814250@qq.com>
|
|
|
|
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
|
|
|
package queues
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2023-07-20 18:01:10 +08:00
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
2023-01-25 11:49:21 +08:00
|
|
|
"hotgo/internal/consts"
|
|
|
|
"hotgo/internal/library/queue"
|
|
|
|
"hotgo/internal/model/entity"
|
|
|
|
"hotgo/internal/service"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2023-02-26 14:18:22 +08:00
|
|
|
queue.RegisterConsumer(ServeLog)
|
2023-01-25 11:49:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ServeLog 登录日志
|
|
|
|
var ServeLog = &qServeLog{}
|
|
|
|
|
|
|
|
type qServeLog struct{}
|
|
|
|
|
2023-02-26 14:18:22 +08:00
|
|
|
// GetTopic 主题
|
|
|
|
func (q *qServeLog) GetTopic() string {
|
2023-01-25 11:49:21 +08:00
|
|
|
return consts.QueueServeLogTopic
|
|
|
|
}
|
|
|
|
|
2023-02-26 14:18:22 +08:00
|
|
|
// Handle 处理消息
|
2023-06-25 19:22:08 +08:00
|
|
|
func (q *qServeLog) Handle(ctx context.Context, mqMsg queue.MqMsg) error {
|
2023-01-25 11:49:21 +08:00
|
|
|
var data entity.SysServeLog
|
2023-06-25 19:22:08 +08:00
|
|
|
if err := json.Unmarshal(mqMsg.Body, &data); err != nil {
|
2023-09-06 17:28:16 +08:00
|
|
|
g.Dump("ServeLog Handle Unmarshal err:", err)
|
2023-06-25 19:22:08 +08:00
|
|
|
return nil
|
2023-01-25 11:49:21 +08:00
|
|
|
}
|
2023-06-25 19:22:08 +08:00
|
|
|
|
|
|
|
if err := service.SysServeLog().RealWrite(ctx, data); err != nil {
|
2023-09-06 17:28:16 +08:00
|
|
|
g.Dump("ServeLog Handle Write err:", err)
|
2023-07-20 18:01:10 +08:00
|
|
|
return nil
|
2023-06-25 19:22:08 +08:00
|
|
|
}
|
|
|
|
return nil
|
2023-01-25 11:49:21 +08:00
|
|
|
}
|