2 Commits 5df53dab86 ... c446c5d975

Author SHA1 Message Date
  Yi c446c5d975 system: userDepth update 3 months ago
  Yi 5df53dab86 system: userDepth update 3 months ago
2 changed files with 22 additions and 3 deletions
  1. 3 2
      model/neck_ring.go
  2. 19 1
      module/crontab/cow_neck_ring_error.go

+ 3 - 2
model/neck_ring.go

@@ -104,7 +104,8 @@ type NeckRingModel struct {
 }
 
 type NeckRingStats struct {
+	Status      pasturePb.IsShow_Kind
 	ErrorKind   pasturePb.NeckRingNumberError_Kind
-	ErrorReason string `json:"error_reason"`
-	Describe    string `json:"describe"`
+	ErrorReason string
+	Describe    string
 }

+ 19 - 1
module/crontab/cow_neck_ring_error.go

@@ -57,10 +57,12 @@ func (e *Entry) CowNeckRingError(pastureId int64) {
 	updateNeckRingMap := make(map[int64]*model.NeckRingStats)
 	errorMap := e.NeckRingErrorMap()
 	for _, neckRing := range neckRingList {
+		var info bool
 		// 佩戴后无信号
 		c1 := e.NeckRingErrorOfNoSignal(pastureId, neckRing, int64(habitMinId), yesterday)
 		if c1 > 0 {
 			updateNeckRingMap[neckRing.Id] = &model.NeckRingStats{
+				Status:      pasturePb.IsShow_No,
 				ErrorKind:   c1,
 				ErrorReason: errorMap[c1],
 				Describe:    "",
@@ -71,6 +73,7 @@ func (e *Entry) CowNeckRingError(pastureId int64) {
 		c2 := e.NeckRingErrorOfSuspectedFallOffAndLowBattery(pastureId, neckRing, int64(habitMinId), yesterday)
 		if c2 > 0 {
 			updateNeckRingMap[neckRing.Id] = &model.NeckRingStats{
+				Status:      pasturePb.IsShow_No,
 				ErrorKind:   c2,
 				ErrorReason: errorMap[c2],
 				Describe:    "",
@@ -81,6 +84,7 @@ func (e *Entry) CowNeckRingError(pastureId int64) {
 		c3 := e.NeckRingErrorOfReceivingLess(pastureId, neckRing, int64(habitMinId), int64(originalMinId), yesterday)
 		if c3 > 0 {
 			updateNeckRingMap[neckRing.Id] = &model.NeckRingStats{
+				Status:      pasturePb.IsShow_No,
 				ErrorKind:   c3,
 				ErrorReason: errorMap[c3],
 				Describe:    "",
@@ -91,11 +95,25 @@ func (e *Entry) CowNeckRingError(pastureId int64) {
 		c4 := e.NeckRingErrorOfDataLatency(pastureId, neckRing, int64(habitMinId), yesterday)
 		if c4 > 0 {
 			updateNeckRingMap[neckRing.Id] = &model.NeckRingStats{
+				Status:      pasturePb.IsShow_No,
 				ErrorKind:   c4,
 				ErrorReason: errorMap[c4],
 				Describe:    "",
 			}
 		}
+
+		if c1 > 0 || c2 > 0 || c3 > 0 || c4 > 0 {
+			info = true
+		}
+
+		if !info {
+			updateNeckRingMap[neckRing.Id] = &model.NeckRingStats{
+				Status:      pasturePb.IsShow_Ok,
+				ErrorKind:   0,
+				ErrorReason: "",
+				Describe:    "",
+			}
+		}
 	}
 
 	if len(updateNeckRingMap) > 0 {
@@ -103,7 +121,7 @@ func (e *Entry) CowNeckRingError(pastureId int64) {
 			if err := e.DB.Model(new(model.NeckRing)).
 				Where("id = ?", id).
 				Updates(map[string]interface{}{
-					"status":       pasturePb.IsShow_No,
+					"status":       v.Status,
 					"error_kind":   v.ErrorKind,
 					"error_reason": v.ErrorReason,
 					"describe":     v.Describe,