package model import ( "math" "strconv" "strings" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type NeckRingOriginal struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` Uuid string `json:"uuid"` NeckRingNumber string `json:"neckRingNumber"` // 脖环号 (对应老表字段EID1) ActiveDate string `json:"activeDate"` // 采集时间-天(YYYY-MM-DD对应老表字段heatdate) Hours int32 `json:"hours"` // 采集时间-小时(hours) Frameid int32 `json:"frameid"` // 采集时长(对应老表frameid) Rumina int32 `json:"rumina"` // 反刍时长(rumaina) Intake int32 `json:"intake"` // 采食时长(intake) Inactive int32 `json:"inactive"` // 静止时间(inactive) Gasp int32 `json:"gasp"` // 喘息时长(Other) High int32 `json:"high"` // 活动量(activitys) Active int32 `json:"active"` // 运动时长(High) Other int32 `json:"other"` // 其他时长 FirmwareVersion int32 `json:"firmwareVersion"` // 固件版本(对应老表Version) HardwareVersion int32 `json:"hardwareVersion"` // 硬件版本 Remain int32 `json:"remain"` // 脖环剩余数据量,57之后为上一次上报结果 Voltage int32 `json:"voltage"` // 电池电压 RestartReason int32 `json:"restartReason"` // 脖环重启原因 (对应老表HIB) Upper int32 `json:"upper"` // 脖环正向比例发射功率 ActiveDateType pasturePb.ActiveTimeType_Kind `json:"ActiveDateTimeType"` IsShow pasturePb.IsShow_Kind `json:"isShow"` Imei string `json:"imei"` // 4G模组IMEI(imei) ReceiveNumber string `json:"receiveNumber"` // 接收器编号 CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (n *NeckRingOriginal) TableName() string { return "neck_ring_original" } var ( AvgHours = int32(6) JoinKey = "/" ) func (n *NeckRingOriginal) IsAvgHours() { if n.ActiveDateType == pasturePb.ActiveTimeType_Two_Hours { n.Remain *= AvgHours n.Inactive *= AvgHours n.Active *= AvgHours n.Intake *= AvgHours n.Other *= AvgHours n.Gasp *= AvgHours n.High *= AvgHours n.High = int32(math.Min(1800, float64(n.Other))) } } type NeckRingOriginalMerge struct { Rumina int32 Inactive int32 Active int32 Intake int32 Other int32 High int32 Gasp int32 ActiveDateType pasturePb.ActiveTimeType_Kind } func (n *NeckRingOriginalMerge) IsMageData(data *NeckRingOriginal) { n.Rumina += data.Rumina n.Inactive += data.Inactive n.Active += data.Active n.Intake += data.Intake n.Other += data.Other n.Gasp += data.Gasp n.High += data.High } func (n *NeckRingOriginalMerge) SumAvg() { n.Rumina = n.Rumina / AvgHours * AvgHours n.Inactive = n.Inactive / AvgHours * AvgHours n.Active = n.Active / AvgHours * AvgHours n.Intake = n.Intake / AvgHours * AvgHours n.Other = n.Other / AvgHours * AvgHours n.Gasp = n.Gasp / AvgHours * AvgHours n.High = n.High / AvgHours * AvgHours } type NeckRingOriginalMap map[string]*NeckRingOriginalMerge func (n NeckRingOriginalMap) ForMatData() []*NeckActiveHabit { res := make([]*NeckActiveHabit, 0) for key, v := range n { keyStrList := strings.Split(key, JoinKey) if len(keyStrList) != 3 { continue } neckRingNumber := keyStrList[0] activeDate := keyStrList[1] frameId := keyStrList[2] frameIdInt, _ := strconv.Atoi(frameId) res = append(res, NewNeckActiveHabit(int32(frameIdInt), activeDate, neckRingNumber, v)) } return res }