1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package cabinet_pkg
- import (
- "dy-admin/internal/pcmserver/bus/model"
- "dy-admin/internal/pcmserver/global"
- "go.uber.org/zap"
- "dy-admin/pkg/log"
- "encoding/hex"
- )
- type MsgLog struct {
- CabinetID int
- MsgType uint8
- MsgName string
- Message []byte
- }
- var deviceLogChan chan *MsgLog
- func RunDeviceLogGoroutine() {
- deviceLogChan = make(chan *MsgLog, 2048)
- go run()
- }
- func run() {
- for {
- select {
- case msgLog := <-deviceLogChan:
- if msgLog == nil {
- log.Warnf("msgLog is nil")
- continue
- }
- createDeviceLog(msgLog.CabinetID, msgLog.MsgType, msgLog.MsgName, msgLog.Message)
- }
- }
- }
- func createDeviceLog(cabinetId int, msgType uint8, msgName string, message []byte) {
- err := global.DB.Create(&model.DeviceLog{
- CabinetID: cabinetId,
- MsgType: msgType,
- MsgName: msgName,
- Message: hex.EncodeToString(message),
- }).Error
- if err != nil {
- log.Warn("create device log err", zap.Error(err))
- }
- return
- }
- func createConnectLog(ip string, msg string) {
- err := global.DB.Create(&model.ConnectLog{
- IP: ip,
- Msg: msg,
- }).Error
- if err != nil {
- log.Warn("create connect log err", zap.Error(err))
- }
- return
- }
|