Browse Source

Merge branch 'feature/event' of http://192.168.1.8:3000/xuyiping/kpt-pasture into feature/event

Yi 1 month ago
parent
commit
3b8196c09e

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250210094803-e3d2418b887d
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250211015100-dc46b810edc2
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eclipse/paho.mqtt.golang v1.4.3

+ 4 - 0
go.sum

@@ -163,6 +163,10 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250210090018-576d00ffc2aa h1:x3Mcivrz
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250210090018-576d00ffc2aa/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250210094803-e3d2418b887d h1:Vi1UHWFH7HqPS/8Hwdlg/yErSojgUA76Teg76MhOPu8=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250210094803-e3d2418b887d/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250211014633-a13f8eeb1990 h1:gjJmp0kMT7p36nnb6zmioNA9nKxXkh0iCrX2txhHqWg=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250211014633-a13f8eeb1990/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250211015100-dc46b810edc2 h1:g6uOnX0e5rCEj/3inaIuwmxcAo8tCR4FIEpUnF4GAS0=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250211015100-dc46b810edc2/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b h1:w05MxH7yqveRlaRbxHhbif5YjPrJFodRPfOjYhXn7Zk=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 10 - 5
http/handler/event/event_breed.go

@@ -201,17 +201,22 @@ func EstrusEventList(c *gin.Context) {
 }
 
 func EstrusBatchMating(c *gin.Context) {
-	var req pasturePb.EventEstrus
+	var req pasturePb.EventNaturalEstrusBatch
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
 	if err := valid.ValidateStruct(&req,
-		valid.Field(&req.CowIds, valid.Required),
-		valid.Field(&req.BullNumber, valid.Required),
-		valid.Field(&req.OperationId, valid.Required),
-		valid.Field(&req.Quantity, valid.Required),
+		valid.Field(&req.Items, valid.Required, valid.Each(valid.By(func(value interface{}) error {
+			item := value.(pasturePb.EventNaturalEstrusItems)
+			return valid.ValidateStruct(&item,
+				valid.Field(&item.CowId, valid.Required),
+				valid.Field(&item.EstrusAt, valid.Required),
+				valid.Field(&item.IsMating, valid.Required),
+				valid.Field(&item.OperationId, valid.Required),
+			)
+		}))),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return

+ 3 - 3
model/cow.go

@@ -20,7 +20,7 @@ type Cow struct {
 	PenName             string                         `json:"penName"`             // 栏舍名称
 	Lact                int32                          `json:"lact"`                // 胎次
 	DayAge              int32                          `json:"dayAge"`              // 日龄
-	CalvingAge          int64                          `json:"calvingAge"`          // 产后天使
+	CalvingAge          int32                          `json:"calvingAge"`          // 产后天使
 	PregnancyAge        int32                          `json:"pregnancyAge"`        // 怀孕天数 孕检结果有阳性更新,产犊后至0
 	AdmissionAge        int32                          `json:"admissionAge"`        // 入场日龄
 	AbortionAge         int32                          `json:"abortionAge"`         // 流产天数
@@ -397,11 +397,11 @@ func (c *Cow) GetDayAge() int32 {
 }
 
 // GetCalvingAge 产后天数
-func (c *Cow) GetCalvingAge() int64 {
+func (c *Cow) GetCalvingAge() int32 {
 	if c.LastCalvingAt <= 0 {
 		return 0
 	}
-	return int64(math.Floor(float64(time.Now().Unix()-c.LastCalvingAt) / 86400))
+	return int32(math.Floor(float64(time.Now().Unix()-c.LastCalvingAt) / 86400))
 }
 
 // GetDaysPregnant 怀孕天数

+ 33 - 40
model/event_estrus.go

@@ -8,29 +8,27 @@ import (
 )
 
 type EventEstrus struct {
-	Id               int64                           `json:"id"`
-	PastureId        int64                           `json:"pastureId"`
-	CowId            int64                           `json:"cowId"`
-	NeckRingNumber   string                          `json:"neckRingNumber"`
-	EarNumber        string                          `json:"earNumber"`
-	Lact             int32                           `json:"lact"`
-	ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
-	EstrusStartDate  string                          `json:"estrusStartDate"`
-	ActiveDate       string                          `json:"activeDate"`
-	LastEstrusDate   string                          `json:"lastEstrusDate"`
-	Level            pasturePb.EstrusLevel_Kind      `json:"level"`
-	IsPeak           pasturePb.IsShow_Kind           `json:"isPeak"`
-	DayHigh          int32                           `json:"dayHigh"`
-	MaxHigh          int32                           `json:"maxHigh"`
-	CheckResult      pasturePb.CheckResult_Kind      `json:"checkResult"`
-	Remarks          string                          `json:"remarks"`
-	IsShow           pasturePb.IsShow_Kind           `json:"isShow"`
-	OperationId      int64                           `json:"operationId"`
-	OperationName    string                          `json:"operationName"`
-	MessageId        int64                           `json:"messageId"`
-	MessageName      string                          `json:"messageName"`
-	CreatedAt        int64                           `json:"createdAt"`
-	UpdatedAt        int64                           `json:"updatedAt"`
+	Id                  int64                           `json:"id"`
+	PastureId           int64                           `json:"pastureId"`
+	CowId               int64                           `json:"cowId"`
+	NeckRingNumber      string                          `json:"neckRingNumber"`
+	EarNumber           string                          `json:"earNumber"`
+	Lact                int32                           `json:"lact"`
+	DayAge              int32                           `json:"dayAge"`
+	CalvingAge          int32                           `json:"calvingAge"`
+	ExposeEstrusType    pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
+	LastEstrusDate      string                          `json:"lastEstrusDate"`
+	IsMating            pasturePb.IsShow_Kind           `json:"isMating"`
+	UnMatingReasonsKind pasturePb.UnMatingReasons_Kind  `json:"unMatingReasonsKind"`
+	UnMatingReasonsName string                          `json:"unMatingReasonsName"`
+	Remarks             string                          `json:"remarks"`
+	IsShow              pasturePb.IsShow_Kind           `json:"isShow"`
+	OperationId         int64                           `json:"operationId"`
+	OperationName       string                          `json:"operationName"`
+	MessageId           int64                           `json:"messageId"`
+	MessageName         string                          `json:"messageName"`
+	CreatedAt           int64                           `json:"createdAt"`
+	UpdatedAt           int64                           `json:"updatedAt"`
 }
 
 func (e *EventEstrus) TableName() string {
@@ -39,29 +37,25 @@ func (e *EventEstrus) TableName() string {
 
 func NewEventEstrus(
 	pastureId int64,
-	exposeEstrusType pasturePb.ExposeEstrusType_Kind,
-	level pasturePb.EstrusLevel_Kind,
-	checkResult pasturePb.CheckResult_Kind,
-	isShow, isPerk pasturePb.IsShow_Kind,
-	lastEstrusDate, activeDate string,
-	dayHigh, maxHigh int32,
 	cow *Cow,
+	exposeEstrusType pasturePb.ExposeEstrusType_Kind,
+	isShow pasturePb.IsShow_Kind,
+	operationUser, currentUser *SystemUser,
 ) *EventEstrus {
 	return &EventEstrus{
 		PastureId:        pastureId,
 		CowId:            cow.Id,
+		Lact:             cow.Lact,
+		DayAge:           cow.DayAge,
+		CalvingAge:       cow.CalvingAge,
 		NeckRingNumber:   cow.NeckRingNumber,
 		EarNumber:        cow.EarNumber,
-		Lact:             cow.Lact,
 		ExposeEstrusType: exposeEstrusType,
-		LastEstrusDate:   lastEstrusDate,
-		ActiveDate:       activeDate,
-		Level:            level,
 		IsShow:           isShow,
-		CheckResult:      checkResult,
-		DayHigh:          dayHigh,
-		MaxHigh:          maxHigh,
-		IsPeak:           isPerk,
+		OperationId:      operationUser.Id,
+		OperationName:    operationUser.Name,
+		MessageId:        currentUser.Id,
+		MessageName:      currentUser.Name,
 	}
 }
 
@@ -85,9 +79,8 @@ func (e EstrusSlice) ToPB(
 			Id:                     int32(v.Id),
 			CowId:                  int32(v.CowId),
 			EarNumber:              v.EarNumber,
-			DayAge:                 cowInfo.DayAge,
-			Lact:                   cowInfo.Lact,
-			Level:                  v.Level,
+			DayAge:                 v.DayAge,
+			Lact:                   v.Lact,
 			PenName:                cowInfo.PenName,
 			Status:                 v.IsShow,
 			CalvingAge:             int32(cowInfo.CalvingAge),

+ 50 - 0
model/neck_ring_estrus.go

@@ -0,0 +1,50 @@
+package model
+
+import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+
+type NeckRingEstrus struct {
+	Id               int64                           `json:"id"`
+	PastureId        int64                           `json:"pastureId"`
+	CowId            int64                           `json:"cowId"`
+	NeckRingNumber   string                          `json:"neckRingNumber"`
+	EarNumber        string                          `json:"earNumber"`
+	Lact             int32                           `json:"lact"`
+	ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
+	EstrusStartDate  string                          `json:"estrusStartDate"`
+	ActiveDate       string                          `json:"activeDate"`
+	LastEstrusDate   string                          `json:"lastEstrusDate"`
+	Level            pasturePb.EstrusLevel_Kind      `json:"level"`
+	IsPeak           pasturePb.IsShow_Kind           `json:"isPeak"`
+	DayHigh          int32                           `json:"dayHigh"`
+	MaxHigh          int32                           `json:"maxHigh"`
+	CheckResult      pasturePb.CheckResult_Kind      `json:"checkResult"`
+	Remarks          string                          `json:"remarks"`
+	IsShow           pasturePb.IsShow_Kind           `json:"isShow"`
+	CreatedAt        int64                           `json:"createdAt"`
+	UpdatedAt        int64                           `json:"updatedAt"`
+}
+
+func (n *NeckRingEstrus) TableName() string {
+	return "neck_ring_estrus"
+}
+
+func NewNeckRingEstrus(
+	pastureId int64,
+	cow *Cow,
+	exposeEstrusType pasturePb.ExposeEstrusType_Kind,
+	level pasturePb.EstrusLevel_Kind,
+	checkResult pasturePb.CheckResult_Kind,
+	isShow pasturePb.IsShow_Kind,
+) *NeckRingEstrus {
+	return &NeckRingEstrus{
+		PastureId:        pastureId,
+		CowId:            cow.Id,
+		NeckRingNumber:   cow.NeckRingNumber,
+		EarNumber:        cow.EarNumber,
+		Lact:             cow.Lact,
+		ExposeEstrusType: exposeEstrusType,
+		Level:            level,
+		IsShow:           isShow,
+		CheckResult:      checkResult,
+	}
+}

+ 0 - 0
model/health_warning.go → model/neck_ring_health_warning.go


+ 1 - 1
module/backend/cow.go

@@ -233,7 +233,7 @@ func (s *StoreEntry) BehaviorCurve(ctx context.Context, req *pasturePb.CowBehavi
 	}
 
 	// 发情数据
-	estrusList := make([]*model.EventEstrus, 0)
+	estrusList := make([]*model.NeckRingEstrus, 0)
 	if err = s.DB.Table(new(model.EventEstrus).TableName()).
 		Where("cow_id = ?", cowInfo.Id).
 		Where("pasture_id = ?", userModel.AppPasture.Id).

+ 1 - 1
module/backend/dashboard.go

@@ -44,7 +44,7 @@ func (s *StoreEntry) NeckRingWarning(ctx context.Context) (*pasturePb.IndexNeckR
 		return nil, xerr.WithStack(err)
 	}
 
-	estrusWarningCowList := make([]*model.EventEstrus, 0)
+	estrusWarningCowList := make([]*model.NeckRingEstrus, 0)
 	estrusWarningLevelItems := make(map[int32]int32)
 	if err = s.DB.Model(new(model.EventEstrus)).
 		Where("pasture_id = ?", userModel.AppPasture.Id).

+ 8 - 0
module/backend/enum_map.go

@@ -302,3 +302,11 @@ func (s *StoreEntry) BarnTypeMap() map[pasturePb.PenType_Kind]string {
 	}
 	return res
 }
+
+func (s *StoreEntry) UnMatingReasonsMap() map[pasturePb.UnMatingReasons_Kind]string {
+	res := make(map[pasturePb.UnMatingReasons_Kind]string)
+	for _, v := range s.UnMatingReasonsEnumList("") {
+		res[pasturePb.UnMatingReasons_Kind(v.Value)] = v.Label
+	}
+	return res
+}

+ 50 - 46
module/backend/event_breed.go

@@ -6,7 +6,6 @@ import (
 	"kpt-pasture/model"
 	"kpt-pasture/util"
 	"net/http"
-	"strconv"
 	"strings"
 	"time"
 
@@ -360,59 +359,79 @@ func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsR
 	}, nil
 }
 
-func (s *StoreEntry) EstrusBatchMating(ctx context.Context, req *pasturePb.EventEstrus) (err error) {
+func (s *StoreEntry) EstrusBatchMating(ctx context.Context, req *pasturePb.EventNaturalEstrusBatch) (err error) {
 	userModel, err := s.GetUserModel(ctx)
 	if err != nil {
 		return xerr.WithStack(err)
 	}
-	operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
-	if err != nil {
-		return xerr.Customf("该用户不存在: %d", req.OperationId)
-	}
-	req.OperationName = operationUser.Name
 
-	eventEstrusIds := make([]string, 0)
+	eventEstrusList := make([]*model.EventEstrus, 0)
 	eventMatingList := make([]*model.EventMating, 0)
-	cowIds := make([]int32, 0)
-	for _, cowId := range req.CowIds {
-		cowInfo := GetCowInfoByCowId(s.DB, int64(cowId))
-		if cowInfo == nil {
+	unMatingReasonsMap := s.UnMatingReasonsMap()
+	for _, item := range req.Items {
+		cowInfo, err := s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, int64(item.CowId))
+		if err != nil {
 			return xerr.Custom("牛只信息不存在")
 		}
 
-		newEventMating := model.NewEventMating(userModel.AppPasture.Id, cowInfo, time.Now().Unix(), pasturePb.ExposeEstrusType_Neck_Ring)
-		eventEstrus, ok, err := s.FindEventEstrusByCowId(ctx, userModel.AppPasture.Id, int64(cowId))
+		if cowInfo.Sex != pasturePb.Genders_Female {
+			return xerr.Custom("该牛只不是母牛")
+		}
+
+		existsEventEstrus, isExists, err := s.FindEventEstrusByCowId(ctx, userModel.AppPasture.Id, int64(item.CowId))
 		if err != nil {
 			return xerr.WithStack(err)
 		}
 
-		if !ok {
+		// 如果存在,并且是脖环揭发则跳过
+		if isExists && existsEventEstrus.ExposeEstrusType == pasturePb.ExposeEstrusType_Neck_Ring {
+			zaplog.Info("EventNaturalEstrusBatch", zap.Any("existsEventEstrus", existsEventEstrus), zap.Any("item", item))
 			continue
 		}
 
-		newEventMating.EventEstrusId = eventEstrus.Id
-		eventEstrusIds = append(eventEstrusIds, strconv.FormatInt(eventEstrus.Id, 10))
-		eventMatingList = append(eventMatingList, newEventMating)
-		cowIds = append(cowIds, cowId)
-	}
-	if len(eventMatingList) <= 0 {
-		return nil
+		operationUser, _ := s.GetSystemUserById(ctx, userModel.SystemUser.Id)
+		newEventEstrus := model.NewEventEstrus(
+			userModel.AppPasture.Id,
+			cowInfo,
+			pasturePb.ExposeEstrusType_Natural_Estrus,
+			pasturePb.IsShow_Ok,
+			operationUser,
+			userModel.SystemUser,
+		)
+		if item.IsMating == pasturePb.IsShow_Ok {
+			newEventEstrus.IsMating = pasturePb.IsShow_Ok
+			newEventMating := model.NewEventMating(userModel.AppPasture.Id, cowInfo, time.Now().Unix(), pasturePb.ExposeEstrusType_Natural_Estrus)
+			eventMatingList = append(eventMatingList, newEventMating)
+		} else {
+			newEventEstrus.IsMating = pasturePb.IsShow_No
+			newEventEstrus.UnMatingReasonsKind = item.UnMatingReasonsKind
+			newEventEstrus.UnMatingReasonsName = unMatingReasonsMap[item.UnMatingReasonsKind]
+		}
+		eventEstrusList = append(eventEstrusList, newEventEstrus)
 	}
 
+	// 记录事件日志
+	defer func() {
+		if err == nil {
+			if len(eventEstrusList) > 0 {
+				for _, v := range eventEstrusList {
+					cow, _ := s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, v.CowId)
+					cowLogs := s.SubmitEventLog(ctx, userModel.AppPasture.Id, cow, pasturePb.EventType_Estrus, v.ExposeEstrusType, v)
+					s.DB.Table(cowLogs.TableName()).Create(cowLogs)
+				}
+			}
+		}
+	}()
+
 	if err = s.DB.Transaction(func(tx *gorm.DB) error {
-		if len(eventEstrusIds) > 0 {
-			if err = tx.Model(new(model.EventEstrus)).
-				Where("id IN ?", eventEstrusIds).
-				Updates(map[string]interface{}{
-					"is_show":      pasturePb.IsShow_No,
-					"check_result": pasturePb.CheckResult_Correct,
-				}).Error; err != nil {
+		if len(eventMatingList) > 0 {
+			if err = tx.Model(new(model.EventMating)).Create(eventMatingList).Error; err != nil {
 				return xerr.WithStack(err)
 			}
 		}
 
-		if len(eventMatingList) > 0 {
-			if err = tx.Create(eventMatingList).Error; err != nil {
+		if len(eventEstrusList) > 0 {
+			if err = tx.Model(new(model.EventEstrus)).Create(eventEstrusList).Error; err != nil {
 				return xerr.WithStack(err)
 			}
 		}
@@ -420,21 +439,6 @@ func (s *StoreEntry) EstrusBatchMating(ctx context.Context, req *pasturePb.Event
 	}); err != nil {
 		return xerr.WithStack(err)
 	}
-
-	// 配种信息
-	eventMating := &pasturePb.EventMating{
-		CowIds:            cowIds,
-		FrozenSemenNumber: req.BullNumber,
-		FrozenSemenCount:  req.Quantity,
-		OperationId:       req.OperationId,
-		Remarks:           req.Remarks,
-		MatingAt:          req.MatingAt,
-		ExposeEstrusType:  pasturePb.ExposeEstrusType_Neck_Ring,
-	}
-	if err = s.MatingCreate(ctx, eventMating); err != nil {
-		zaplog.Error("EstrusBatchMating", zap.Any("MatingCreate", err), zap.Any("eventMating", eventMating))
-		return xerr.WithStack(err)
-	}
 	return nil
 }
 

+ 1 - 1
module/backend/event_check.go

@@ -149,7 +149,7 @@ func (s *StoreEntry) PregnantCheckDataCheck(ctx context.Context, req *pasturePb.
 
 		// 过滤掉没有配种状态的牛只
 		if cow.BreedStatus != pasturePb.BreedStatus_Breeding {
-			return nil, xerr.Customf("牛只: %d,当前状态为: %s,不能进行孕检", cow.Id, cow.BreedStatus.String())
+			return nil, xerr.Customf("牛只: %d 未参加配种,不能进行孕检", cow.Id)
 		}
 
 		itemEventPregnantCheck, ok, err := s.FindEventPregnantCheckIsExIstByCowId(ctx, cow)

+ 7 - 3
module/backend/event_cow_log.go

@@ -86,9 +86,13 @@ func (s *StoreEntry) SubmitEventLog(
 		}
 	case pasturePb.EventType_Estrus:
 		eventType = pasturePb.EventType_Mating // 发情配种批量提交
-		data := req.(*pasturePb.EventEstrus)
-		eventAt = int64(data.MatingAt)
-		desc = fmt.Sprintf("配种公牛: %s;发情揭发方式:%s;配种结果:未知", data.BullNumber, s.ExposeEstrusTypeMap()[pasturePb.ExposeEstrusType_Neck_Ring])
+		data := req.(*pasturePb.EventNaturalEstrusItems)
+		eventAt = int64(data.EstrusAt)
+		isMating := "是"
+		if data.IsMating == pasturePb.IsShow_Ok {
+			isMating = "否"
+		}
+		desc = fmt.Sprintf("发情揭发方式:%s;是否配种:%s;", s.ExposeEstrusTypeMap()[exposeEstrusType], isMating)
 		operationUser.Id = int64(data.OperationId)
 		operationUser.Name = data.OperationName
 		remarks = data.Remarks

+ 1 - 1
module/backend/interface.go

@@ -173,7 +173,7 @@ type EventService interface {
 	MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventMatingResponse, error)
 	MatingCreate(ctx context.Context, req *pasturePb.EventMating) error
 	// EstrusBatchMating 发情批量处理配种
-	EstrusBatchMating(ctx context.Context, req *pasturePb.EventEstrus) error
+	EstrusBatchMating(ctx context.Context, req *pasturePb.EventNaturalEstrusBatch) error
 	// AbortionList 流产
 	AbortionList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventAbortionResponse, error)
 	AbortionCreate(ctx context.Context, req *pasturePb.EventAbortionRequest) error

+ 13 - 11
module/crontab/neck_ring_estrus.go

@@ -90,7 +90,7 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday) (err error) {
 		neckActiveHabitMap[habit.CowId] = append(neckActiveHabitMap[habit.CowId], habit)
 	}
 
-	eventEstrusList := make([]*model.EventEstrus, 0)
+	neckRingEstrusList := make([]*model.NeckRingEstrus, 0)
 	for cowId, cowHabitList := range neckActiveHabitMap {
 		// 最近3天最大发情记录,小于该变化趋势的不再插入
 		before3Data := e.GetBeforeThreeDaysCowEstrus(cowId, nowTime.AddDate(0, 0, -2).Format(model.LayoutTime))
@@ -154,16 +154,18 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday) (err error) {
 				zap.Any("cowInfo", cowInfo),
 				zap.Any("cowHabitList", cowHabitList),
 			)
-			newEstrus := model.NewEventEstrus(
-				pastureId, pasturePb.ExposeEstrusType_Neck_Ring, level, checkResult, isShow,
-				isPeak, lastEstrusDate, activeDate, dayHigh, maxHigh, cowInfo,
-			)
-			eventEstrusList = append(eventEstrusList, newEstrus)
+			newNeckRingEstrus := model.NewNeckRingEstrus(pastureId, cowInfo, pasturePb.ExposeEstrusType_Neck_Ring, level, checkResult, isShow)
+			newNeckRingEstrus.LastEstrusDate = lastEstrusDate
+			newNeckRingEstrus.ActiveDate = activeDate
+			newNeckRingEstrus.DayHigh = dayHigh
+			newNeckRingEstrus.MaxHigh = maxHigh
+			newNeckRingEstrus.IsPeak = isPeak
+			neckRingEstrusList = append(neckRingEstrusList, newNeckRingEstrus)
 		}
 	}
-	if len(eventEstrusList) > 0 {
-		if err = e.DB.Model(new(model.EventEstrus)).Create(eventEstrusList).Error; err != nil {
-			zaplog.Error("CowEstrusWarningNew", zap.Any("eventEstrusList", eventEstrusList), zap.Any("err", err))
+	if len(neckRingEstrusList) > 0 {
+		if err = e.DB.Model(new(model.NeckRingEstrus)).Create(neckRingEstrusList).Error; err != nil {
+			zaplog.Error("CowEstrusWarningNew", zap.Any("eventEstrusList", neckRingEstrusList), zap.Any("err", err))
 		}
 	}
 
@@ -176,7 +178,7 @@ func (e *Entry) CowEstrusWarning(pastureId int64, xToday *XToday) (err error) {
 // UpdateEstrusStartDate 更新发情开始时间数据
 func (e *Entry) UpdateEstrusStartDate(pastureId int64, xToday time.Time) (err error) {
 	beforeEventEstrus := make([]*EstrusStartData, 0)
-	if err = e.DB.Model(new(model.EventEstrus)).
+	if err = e.DB.Model(new(model.NeckRingEstrus)).
 		Select("cow_id,MIN(estrus_start_date) as estrus_start_date").
 		Where("active_date BETWEEN  ? AND  ?", xToday.Add(-24*time.Hour).Format(model.LayoutTime), xToday.Format(model.LayoutTime)).
 		Where("estrus_start_date != ?", "").
@@ -187,7 +189,7 @@ func (e *Entry) UpdateEstrusStartDate(pastureId int64, xToday time.Time) (err er
 	}
 	if len(beforeEventEstrus) > 0 {
 		for _, v := range beforeEventEstrus {
-			if err = e.DB.Model(new(model.EventEstrus)).
+			if err = e.DB.Model(new(model.NeckRingEstrus)).
 				Where("cow_id = ?", v.CowId).
 				Where("active_date >= ? AND <= ?", xToday.Add(-1*time.Hour).Format(model.LayoutTime), xToday.Add(24*time.Hour).Format(model.LayoutTime)).
 				Update("estrus_start_date", v.EstrusStartDate).Error; err != nil {