|
@@ -1,12 +1,15 @@
|
|
|
package mqtt
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"kpt-pasture/model"
|
|
|
"kpt-pasture/util"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
|
|
|
+ pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
+
|
|
|
"gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
"go.uber.org/zap"
|
|
@@ -82,7 +85,7 @@ func (e *Entry) NeckRingHandle(data []byte) {
|
|
|
|
|
|
func (e *Entry) CreatedData(DSMLog *DataInsertNeckRingLog) error {
|
|
|
if err := e.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
- if len(DSMLog.NeckRingUnRegisterData) > 0 {
|
|
|
+ if len(DSMLog.NeckRingErrorData) > 0 {
|
|
|
if err := e.DB.Create(DSMLog.NeckRingErrorData).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -280,3 +283,38 @@ func (e *Entry) MsgDataFormat(msg []byte) *model.NeckRingOriginal {
|
|
|
Nccid: nccId,
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func (e *Entry) MsgDataFormat2(msg []byte) *model.NeckRingOriginal {
|
|
|
+ neckLog := &Behavior{}
|
|
|
+ if err := json.Unmarshal(msg, neckLog); err != nil {
|
|
|
+ zaplog.Error("MsgDataFormat", zap.Any("err", err), zap.Any("msg", string(msg)))
|
|
|
+ }
|
|
|
+ if neckLog.Imei != "" {
|
|
|
+ // 存储到数据库
|
|
|
+ activeDate, hours := util.GetNeckRingActiveTimer(neckLog.FrameId)
|
|
|
+ voltage, _ := strconv.ParseInt(strconv.FormatInt(int64(neckLog.BAT), 16), 10, 64)
|
|
|
+ activeDateTimeType := pasturePb.ActiveTimeType_Twenty_Minutes
|
|
|
+ if neckLog.FrameId%10 == 8 {
|
|
|
+ activeDateTimeType = pasturePb.ActiveTimeType_Two_Hours
|
|
|
+ }
|
|
|
+ return &model.NeckRingOriginal{
|
|
|
+ Uuid: neckLog.UUID,
|
|
|
+ Imei: neckLog.ECowId,
|
|
|
+ ActiveDate: activeDate,
|
|
|
+ Hours: int32(hours),
|
|
|
+ FrameId: neckLog.FrameId,
|
|
|
+ Rumina: neckLog.RuMina,
|
|
|
+ Intake: neckLog.Intake,
|
|
|
+ Inactive: neckLog.Inactive,
|
|
|
+ Other: neckLog.Other,
|
|
|
+ High: neckLog.Activitys,
|
|
|
+ Active: neckLog.High,
|
|
|
+ Voltage: int32(voltage),
|
|
|
+ Version: neckLog.Sver,
|
|
|
+ Remain: neckLog.Remain,
|
|
|
+ ReceiveNumber: neckLog.Imei,
|
|
|
+ ActiveDateType: activeDateTimeType,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|