Explorar o código

event: 产犊清单

Yi hai 3 meses
pai
achega
037a5f5de5

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250208022155-41067ebaa17d
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250210061341-1e50fd31801b
 	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

+ 6 - 0
go.sum

@@ -151,6 +151,12 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250208021036-c6018bf8a9e2 h1:eFOdl5NV
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250208021036-c6018bf8a9e2/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250208022155-41067ebaa17d h1:2l7WoxgnJf/Jf6YzSUh+Cm+m65iQU2WWvSz5LQo7jjc=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250208022155-41067ebaa17d/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250210052401-c8bf761b13fe h1:MH7nK3YPH+pDUwVnxREVW/OhBXx6RdqnRWa9BwVV6ts=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250210052401-c8bf761b13fe/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250210055925-91dc2754eaec h1:LEPeYOmh+6q4gnwRcGNV6MCUPWjP4RmJl//ksBdH6Rs=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250210055925-91dc2754eaec/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250210061341-1e50fd31801b h1:j9YojtrHZoz0DT5zBeMdya5+l92c52rCfJjQ6pLuUvs=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250210061341-1e50fd31801b/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=

+ 2 - 2
http/route/event_api.go

@@ -38,8 +38,8 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		eventRoute.POST("/mating/list", event.MatingEventList)
 		eventRoute.POST("/mating/create", event.MatingCreate)
 		// 发情
-		eventRoute.POST("/estrus/list/", event.EstrusEventList)
-		eventRoute.POST("/estrus/mating/batch/", event.EstrusBatchMating)
+		eventRoute.POST("/estrus/list", event.EstrusEventList)
+		eventRoute.POST("/estrus/mating/batch", event.EstrusBatchMating)
 		// 同期
 		eventRoute.POST("/same/time/list", event.SameTimeList)
 		eventRoute.POST("/same/time/create", event.SameTimeCreate)

+ 3 - 1
model/calving_calf.go

@@ -16,6 +16,7 @@ type CalvingCalf struct {
 	IsLive        pasturePb.IsShow_Kind  `json:"isLive"`
 	IsAdoption    pasturePb.IsShow_Kind  `json:"isAdoption"`
 	PenId         int32                  `json:"penId"`
+	PenName       string                 `json:"penName"`
 	WeaningAt     int64                  `json:"weaningAt"`
 	CurrentWeight int64                  `json:"currentWeight"`
 	Remarks       string                 `json:"remarks"`
@@ -27,7 +28,7 @@ func (e *CalvingCalf) TableName() string {
 	return "calving_calf"
 }
 
-func NewEventCalvingCalf(pastureId, motherId, calvingId, calvingAt int64, req *pasturePb.CalfItem) *CalvingCalf {
+func NewEventCalvingCalf(pastureId, motherId, calvingId, calvingAt int64, penMap map[int32]*Pen, req *pasturePb.CalfItem) *CalvingCalf {
 	isAdoption := req.IsAdoption
 	if req.IsLive == pasturePb.IsShow_No {
 		isAdoption = pasturePb.IsShow_No
@@ -39,6 +40,7 @@ func NewEventCalvingCalf(pastureId, motherId, calvingId, calvingAt int64, req *p
 		CowId:         int64(req.CowId),
 		BirthAt:       calvingAt,
 		PenId:         req.PenId,
+		PenName:       penMap[req.PenId].Name,
 		BirthWeight:   int64(req.Weight * 1000),
 		CurrentWeight: int64(req.Weight * 1000),
 		Sex:           req.Sex,

+ 1 - 0
model/cow.go

@@ -356,6 +356,7 @@ func NewCalfCow(motherId int64, fatherNumber string, calf *CalvingCalf) *Cow {
 		Sex:             calf.Sex,
 		EarNumber:       calf.EarNumber,
 		PenId:           calf.PenId,
+		PenName:         calf.PenName,
 		CowType:         pasturePb.CowType_Lactating_Calf, // 哺乳犊牛
 		BreedStatus:     pasturePb.BreedStatus_UnBreed,    // 未配
 		CowKind:         calf.CowKind,                     // 牛只品种

+ 3 - 0
model/event_abortion.go

@@ -10,6 +10,7 @@ type EventAbortion struct {
 	Id                  int64                          `json:"id"`
 	PastureId           int64                          `json:"pastureId"`
 	CowId               int64                          `json:"cowId"`
+	EarNumber           string                         `json:"earNumber"`
 	Lact                int32                          `json:"lact"`
 	CowType             pasturePb.CowType_Kind         `json:"cowType"`
 	DayAge              int32                          `json:"dayAge"`
@@ -35,6 +36,7 @@ func NewEventAbortion(pastureId int64, cow *Cow, req *pasturePb.EventAbortionReq
 	return &EventAbortion{
 		PastureId:           pastureId,
 		CowId:               cow.Id,
+		EarNumber:           cow.EarNumber,
 		Lact:                cow.Lact,
 		CowType:             cow.CowType,
 		PregnantAge:         cow.GetDaysPregnant(),
@@ -59,6 +61,7 @@ func (a AbortionSlice) ToPB() []*pasturePb.EventAbortionRequest {
 		res[i] = &pasturePb.EventAbortionRequest{
 			Id:                  int32(v.Id),
 			CowId:               int32(v.CowId),
+			EarNumber:           v.EarNumber,
 			DayAge:              v.DayAge,
 			Lact:                v.Lact,
 			AbortionAt:          int32(v.AbortionAt),

+ 3 - 0
model/event_cow_disease.go

@@ -10,6 +10,7 @@ type EventCowDisease struct {
 	Id                    int64                       `json:"id"`
 	PastureId             int64                       `json:"pastureId"`
 	CowId                 int64                       `json:"cowId"`
+	EarNumber             string                      `json:"earNumber"`
 	CowType               pasturePb.CowType_Kind      `json:"cowType"`
 	Lact                  int32                       `json:"lact"`
 	DayAge                int32                       `json:"dayAge"`
@@ -78,6 +79,7 @@ func NewEventCowDisease(pastureId int64, cow *Cow, disease *Disease, req *pastur
 	return &EventCowDisease{
 		PastureId:       pastureId,
 		CowId:           cow.Id,
+		EarNumber:       cow.EarNumber,
 		CowType:         cow.CowType,
 		Lact:            cow.Lact,
 		DayAge:          cow.DayAge,
@@ -108,6 +110,7 @@ func (e EventCowDiseaseSlice) ToPB(healthStatusMap map[pasturePb.HealthStatus_Ki
 		res[i] = &pasturePb.EventCowDisease{
 			Id:               int32(v.Id),
 			CowId:            int32(v.CowId),
+			EarNumber:        v.EarNumber,
 			Lact:             v.Lact,
 			DayAge:           v.DayAge,
 			DiseaseId:        v.DiseaseId,

+ 4 - 0
model/event_cow_same_time.go

@@ -10,6 +10,7 @@ type EventCowSameTime struct {
 	Id            int64                       `json:"id"`
 	PastureId     int64                       `json:"pastureId"`
 	CowId         int64                       `json:"cowId"`
+	EarNumber     string                      `json:"earNumber"`
 	CowType       pasturePb.CowType_Kind      `json:"cowType"`
 	PenId         int32                       `json:"penId"`
 	PenName       string                      `json:"penName"`
@@ -53,6 +54,7 @@ func NewEventCowSameTime(pastureId int64, cow *Cow, planTime int64, sameTime *Sa
 	return &EventCowSameTime{
 		PastureId:    pastureId,
 		CowId:        cow.Id,
+		EarNumber:    cow.EarNumber,
 		Lact:         cow.Lact,
 		CowType:      cow.CowType,
 		PenId:        cow.PenId,
@@ -76,6 +78,7 @@ func NewEventCowSameTimeList(pastureId int64, cowList []*Cow, sameTime *SameTime
 type SameTimeItemBody struct {
 	Id              int64                       `json:"id"`
 	CowId           int64                       `json:"cowId"`
+	EarNumber       string                      `json:"earNumber"`
 	BreedStatus     pasturePb.BreedStatus_Kind  `json:"breedStatus"`
 	BreedStatusName string                      `json:"breedStatusName"`
 	CowType         pasturePb.CowType_Kind      `json:"cowType"`
@@ -119,6 +122,7 @@ func (s SameTimeBodySlice) ToPB(
 		res[i] = &pasturePb.SameTimeItems{
 			Id:               int32(v.Id),
 			CowId:            int32(v.CowId),
+			EarNumber:        v.EarNumber,
 			BreedStatus:      v.BreedStatus,
 			BreedStatusName:  breedStatusMap[v.BreedStatus],
 			PenName:          penName,

+ 8 - 5
model/event_estrus.go

@@ -10,8 +10,9 @@ import (
 type EventEstrus struct {
 	Id               int64                           `json:"id"`
 	PastureId        int64                           `json:"pastureId"`
-	NeckRingNumber   string                          `json:"neckRingNumber"`
 	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"`
@@ -48,8 +49,9 @@ func NewEventEstrus(
 ) *EventEstrus {
 	return &EventEstrus{
 		PastureId:        pastureId,
-		NeckRingNumber:   cow.NeckRingNumber,
 		CowId:            cow.Id,
+		NeckRingNumber:   cow.NeckRingNumber,
+		EarNumber:        cow.EarNumber,
 		Lact:             cow.Lact,
 		ExposeEstrusType: exposeEstrusType,
 		LastEstrusDate:   lastEstrusDate,
@@ -75,13 +77,14 @@ func (e EstrusSlice) ToPB(
 		cowInfo := getCowInfo(dB, v.CowId)
 		lastEventLog := getCowLastEvent(dB, v.CowId, pasturePb.EventCategory_Breed)
 		planDay, optimumMatingTime := "", ""
-		lastBreedEvnetDetails := ""
+		lastBreedEventDetails := ""
 		if lastEventLog != nil {
-			lastBreedEvnetDetails = fmt.Sprintf("%s %s", lastEventLog.EventTypeName, lastEventLog.EventDescription)
+			lastBreedEventDetails = fmt.Sprintf("%s %s", lastEventLog.EventTypeName, lastEventLog.EventDescription)
 		}
 		res[i] = &pasturePb.EstrusItems{
 			Id:                     int32(v.Id),
 			CowId:                  int32(v.CowId),
+			EarNumber:              v.EarNumber,
 			DayAge:                 cowInfo.DayAge,
 			Lact:                   cowInfo.Lact,
 			Level:                  v.Level,
@@ -92,7 +95,7 @@ func (e EstrusSlice) ToPB(
 			MatingTimes:            cowInfo.MatingTimes,
 			OptimumMatingStartTime: optimumMatingTime,
 			OptimumMatingEndTime:   optimumMatingTime,
-			LastBreedEvnetDetails:  lastBreedEvnetDetails,
+			LastBreedEventDetails:  lastBreedEventDetails,
 		}
 	}
 	return res

+ 3 - 0
model/event_immunization_plan.go

@@ -11,6 +11,7 @@ type EventImmunizationPlan struct {
 	Id            int64                  `json:"id"`
 	PastureId     int64                  `json:"pastureId"`
 	CowId         int64                  `json:"cowId"`
+	EarNumber     string                 `json:"earNumber"`
 	Lact          int32                  `json:"lact"`
 	DayAge        int32                  `json:"dayAge"`
 	CowType       pasturePb.CowType_Kind `json:"cowType"`
@@ -46,6 +47,7 @@ func NewCowImmunizationPlan(cow *Cow, pen *Pen, immunizationPlan *ImmunizationPl
 	return &EventImmunizationPlan{
 		PastureId: immunizationPlan.PastureId,
 		CowId:     cow.Id,
+		EarNumber: cow.EarNumber,
 		Lact:      cow.Lact,
 		DayAge:    cow.DayAge,
 		CowKind:   cow.CowKind,
@@ -77,6 +79,7 @@ func (I EventImmunizationPlanSlice) ToPB() []*pasturePb.ImmunizationItems {
 		res[i] = &pasturePb.ImmunizationItems{
 			Id:               int32(v.Id),
 			CowId:            int32(v.CowId),
+			EarNumber:        v.EarNumber,
 			PenId:            v.PenId,
 			Lact:             v.Lact,
 			PenName:          v.PenName,

+ 6 - 1
model/event_item.go

@@ -9,7 +9,9 @@ import (
 
 type EventItem struct {
 	Id            int64                       `json:"id"`
+	PastureId     int64                       `json:"pastureId"`
 	CowId         int64                       `json:"cowId"`
+	EarNumber     string                      `json:"earNumber"`
 	PenId         int32                       `json:"penId"`
 	Lact          int32                       `json:"lact"`
 	CalendarType  pasturePb.CalendarType_Kind `json:"calendarType"`
@@ -31,7 +33,9 @@ func (e *EventItem) TableName() string {
 
 func NewEventItem(cow *Cow, calendarType pasturePb.CalendarType_Kind) *EventItem {
 	return &EventItem{
+		PastureId:    cow.PastureId,
 		CowId:        cow.Id,
+		EarNumber:    cow.EarNumber,
 		PenId:        cow.PenId,
 		Lact:         cow.Lact,
 		CalendarType: calendarType,
@@ -60,6 +64,8 @@ func (e EventItemSlice) ToPB(penMap map[int32]*Pen, calendarType map[pasturePb.C
 		}
 		res[i] = &pasturePb.CalendarToDoList{
 			Id:               int32(v.Id),
+			CowId:            int32(v.CowId),
+			EarNumber:        v.EarNumber,
 			Lact:             v.Lact,
 			CalendarType:     v.CalendarType,
 			CalendarTypeName: calendarType[v.CalendarType],
@@ -68,7 +74,6 @@ func (e EventItemSlice) ToPB(penMap map[int32]*Pen, calendarType map[pasturePb.C
 			RealityDay:       time.Unix(v.RealityDay, 0).Format(LayoutDate2),
 			IsFinish:         v.IsFinish,
 			IsExpire:         v.IsExpire,
-			CowId:            int32(v.CowId),
 			PenName:          penName,
 			Remarks:          v.Remarks,
 		}

+ 6 - 2
model/event_mating.go

@@ -11,6 +11,7 @@ type EventMating struct {
 	Id                int64                           `json:"id"`
 	PastureId         int64                           `json:"pastureId"`
 	CowId             int64                           `json:"cowId"`
+	EarNumber         string                          `json:"earNumber"`
 	DayAge            int32                           `json:"dayAge"`
 	Lact              int32                           `json:"lact"`
 	PenId             int32                           `json:"penId"`
@@ -103,6 +104,7 @@ func NewEventMating(pastureId int64, cow *Cow, planDay int64, exposeEstrusType p
 	return &EventMating{
 		PastureId:        pastureId,
 		CowId:            cow.Id,
+		EarNumber:        cow.EarNumber,
 		Lact:             cow.Lact,
 		PenId:            cow.PenId,
 		PenName:          cow.PenName,
@@ -122,6 +124,7 @@ func NewEventMatingNaturalEstrus(pastureId int64, cow *Cow, req *pasturePb.Event
 	return &EventMating{
 		PastureId:         pastureId,
 		CowId:             cow.Id,
+		EarNumber:         cow.EarNumber,
 		Lact:              cow.Lact,
 		DayAge:            cow.GetDayAge(),
 		CowType:           cow.CowType,
@@ -160,8 +163,9 @@ func (e EventMatingSlice) ToPB(exposeEstrusTypeMap map[pasturePb.ExposeEstrusTyp
 		res[i] = &pasturePb.SearchMatingList{
 			Id:                   int32(v.Id),
 			CowId:                int32(v.CowId),
-			DayAge:               int32(v.DayAge),
-			Lact:                 int32(v.Lact),
+			EarNumber:            v.EarNumber,
+			DayAge:               v.DayAge,
+			Lact:                 v.Lact,
 			CalvingAge:           v.CalvingAge,
 			PlanDay:              time.Unix(v.PlanDay, 0).Format(LayoutDate2),
 			RealityDay:           time.Unix(v.RealityDay, 0).Format(LayoutDate2),

+ 59 - 26
module/backend/calendar.go

@@ -100,15 +100,15 @@ func (s *StoreEntry) CalendarTableDetail(
 	req *pasturePb.CalendarTableRequest,
 	pagination *pasturePb.PaginationModel,
 ) (interface{}, error) {
-	if req.Start != time.Now().Format(model.LayoutDate2) {
-		return nil, xerr.Custom("只能获取当天的数据")
-	}
-
 	userModel, err := s.GetUserModel(ctx)
 	if err != nil {
 		return nil, xerr.WithStack(err)
 	}
 
+	if req.Start != time.Now().Format(model.LayoutDate2) {
+		return nil, xerr.Custom("只能获取当天的数据")
+	}
+
 	newCalendar := &model.Calendar{}
 	if err = s.DB.Model(&model.Calendar{}).
 		Where("calendar_type = ?", req.CalendarType).
@@ -156,11 +156,15 @@ func (s *StoreEntry) getCalendarCowList(
 }
 
 func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.ImmunizationItemsResponse, error) {
+	userModel, err := s.GetUserModel(ctx)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
 	eventImmunizationPlanList := make([]*model.EventImmunizationPlan, 0)
 	count := int64(0)
 	pref := s.DB.Model(&model.EventImmunizationPlan{}).
 		Where("status = ?", pasturePb.IsShow_No).
-		Where("pasture_id = ?", req.PastureId)
+		Where("pasture_id = ?", userModel.AppPasture.Id)
 	if req.StartDay != "" {
 		dateTime := util.TimeParseLocalUnix(req.StartDay)
 		pref.Where("plan_day >= ?", dateTime)
@@ -187,7 +191,7 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
 		pref.Where("status = ?", req.Status)
 	}
 
-	if err := pref.Order("id desc").
+	if err = pref.Order("id desc").
 		Count(&count).
 		Limit(int(pagination.PageSize)).
 		Offset(int(pagination.PageOffset)).
@@ -206,6 +210,7 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
 			Header: map[string]string{
 				"id":                   "编号",
 				"cowId":                "牛号",
+				"earNumber":            "耳标号",
 				"penName":              "栏舍",
 				"dayAge":               "日龄",
 				"planDay":              "免疫开始时间",
@@ -219,13 +224,18 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
 }
 
 func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SameTimeItemResponse, error) {
+	userModel, err := s.GetUserModel(ctx)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
 	sameTimeBodyList := make([]*model.SameTimeItemBody, 0)
 	count := int64(0)
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCowSameTime).TableName())).
-		Select("a.id,a.cow_id,a.pen_name,a.status,a.same_time_type,b.breed_status,a.same_time_name,b.cow_type,b.day_age,b.calving_age,b.abortion_age,b.last_calving_at,b.last_abortion_at").
+		Select(`a.id,a.cow_id,a.ear_number,a.pen_name,a.status,a.same_time_type,b.breed_status,a.same_time_name,
+		b.cow_type,b.day_age,b.calving_age,b.abortion_age,b.last_calving_at,b.last_abortion_at`).
 		Joins("left join cow as b on a.cow_id = b.id").
 		Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
-		Where("a.pasture_id = ?", req.PastureId).
+		Where("a.pasture_id = ?", userModel.AppPasture.Id).
 		Where("a.status = ?", pasturePb.IsShow_No)
 
 	if req.EndDay != "" {
@@ -245,7 +255,7 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
 		pref.Where("a.status = ?", pasturePb.IsShow_No)
 	}
 
-	if err := pref.Order("a.id desc").Count(&count).
+	if err = pref.Order("a.id desc").Count(&count).
 		Limit(int(pagination.PageSize)).
 		Offset(int(pagination.PageOffset)).
 		Order("id desc").
@@ -265,6 +275,7 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
 			Header: map[string]string{
 				"id":               "编号",
 				"cowId":            "牛号",
+				"earNumber":        "耳标号",
 				"breedStatusName":  "繁殖状态",
 				"cowTypeName":      "牛只类型",
 				"penName":          "栏舍",
@@ -285,13 +296,17 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
 }
 
 func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyCheckItemsResponse, error) {
+	userModel, err := s.GetUserModel(ctx)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
 	newPregnancyCheckItems := make([]*pasturePb.PregnancyCheckItems, 0)
 	var count int64
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventPregnantCheck).TableName())).
-		Select("a.id,a.cow_id,a.pen_id,a.status,b.breed_status,b.cow_type,b.day_age,b.calving_age,b.abortion_age,a.bull_id").
+		Select("a.id,a.cow_id,a.ear_number,a.pen_id,a.status,b.breed_status,b.cow_type,b.day_age,b.calving_age,b.abortion_age,a.bull_id").
 		Joins("left join cow as b on a.cow_id = b.id").
 		Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
-		Where("a.pasture_id = ?", req.PastureId).
+		Where("a.pasture_id = ?", userModel.AppPasture.Id).
 		Where("a.status = ?", pasturePb.IsShow_No)
 
 	if req.EndDay != "" {
@@ -330,6 +345,7 @@ func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.I
 			Header: map[string]string{
 				"id":              "编号",
 				"cowId":           "牛号",
+				"ear_number":      "耳标号",
 				"cowTypeName":     "牛只类型",
 				"penName":         "栏舍",
 				"lact":            "胎次",
@@ -349,16 +365,20 @@ func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.I
 }
 
 func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.WeaningItemsResponse, error) {
+	userModel, err := s.GetUserModel(ctx)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
 	weaningItems := make([]*pasturePb.WeaningItems, 0)
 	count := int64(0)
-
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventWeaning).TableName())).
 		Select("a.*,b.day_age,c.name as pen_name").
 		Joins("left join cow as b on a.cow_id = b.id").
 		Joins("left join pen as c on a.before_pen_id = c.id").
 		Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
-		Where("a.pasture_id = ?", req.PastureId).
-		Where("a.status = ?", pasturePb.IsShow_No)
+		Where("a.status = ?", pasturePb.IsShow_No).
+		Where("a.pasture_id = ?", userModel.AppPasture.Id)
 
 	if req.EndDay != "" {
 		dateTime := util.TimeParseLocalEndUnix(req.EndDay)
@@ -369,7 +389,7 @@ func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsReq
 		pref.Where("a.status = ?", req.Status)
 	}
 
-	if err := pref.Order("a.id desc").Count(&count).
+	if err = pref.Order("a.id desc").Count(&count).
 		Limit(int(pagination.PageSize)).
 		Offset(int(pagination.PageOffset)).
 		Find(&weaningItems).Error; err != nil {
@@ -384,12 +404,13 @@ func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsReq
 			Page:     pagination.Page,
 			PageSize: pagination.PageSize,
 			Header: map[string]string{
-				"id":      "编号",
-				"cowId":   "牛号",
-				"penName": "栏舍",
-				"planDay": "断奶日期",
-				"dayAge":  "日龄",
-				"status":  "状态",
+				"id":         "编号",
+				"cowId":      "牛号",
+				"ear_number": "耳标号",
+				"penName":    "栏舍",
+				"planDay":    "断奶日期",
+				"dayAge":     "日龄",
+				"status":     "状态",
 			},
 			List: weaningItems,
 		},
@@ -397,13 +418,18 @@ func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsReq
 }
 
 func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingItemsResponse, error) {
+	userModel, err := s.GetUserModel(ctx)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
 	matingItems := make([]*pasturePb.MatingItems, 0)
 	count := int64(0)
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventMating).TableName())).
-		Select("a.id,a.cow_id,a.status,b.breed_status,b.cow_type,b.pen_id,b.day_age,b.calving_age,b.abortion_age,c.name as pen_name").
+		Select(`a.id,a.cow_id,a.status,a.ear_number,b.breed_status,b.cow_type,b.pen_id,b.day_age,
+		b.calving_age,b.abortion_age,c.name as pen_name`).
 		Joins("left join cow as b on a.cow_id = b.id").
 		Joins("left join pen as c on a.pen_id = c.id").
-		Where("").
+		Where("a.pasture_id = ?", userModel.AppPasture.Id).
 		Where("a.status = ?", pasturePb.IsShow_No)
 
 	if req.EndDay != "" {
@@ -419,7 +445,7 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
 		pref.Where("a.status = ?", req.Status)
 	}
 
-	if err := pref.Order("a.id desc").
+	if err = pref.Order("a.id desc").
 		Count(&count).
 		Limit(int(pagination.PageSize)).
 		Offset(int(pagination.PageOffset)).
@@ -437,6 +463,7 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
 			Header: map[string]string{
 				"id":              "编号",
 				"cowId":           "牛号",
+				"earNumber":       "耳标号",
 				"breedStatusName": "繁殖状态",
 				"cowTypeName":     "牛只类型",
 				"penName":         "栏舍",
@@ -452,13 +479,18 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
 }
 
 func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingItemsResponse, error) {
+	userModel, err := s.GetUserModel(ctx)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
 	calvingItems := make([]*pasturePb.CalvingItems, 0)
 	count := int64(0)
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCalving).TableName())).
-		Select(`a.id,a.cow_id,a.status,b.breed_status,b.pen_id,DATE_FORMAT(FROM_UNIXTIME(last_mating_at), '%Y-%m-%d') AS mating_at_format,
+		Select(`a.id,a.cow_id,a.ear_number,a.status,b.breed_status,b.pen_id,DATE_FORMAT(FROM_UNIXTIME(last_mating_at), '%Y-%m-%d') AS mating_at_format,
 		b.day_age,b.last_bull_number as bull_id,DATEDIFF(NOW(),FROM_UNIXTIME(last_mating_at)) AS mating_age,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day`).
 		Joins("left join cow as b on a.cow_id = b.id").
-		Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission)
+		Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
+		Where("a.pasture_id = ?", userModel.AppPasture.Id)
 
 	if req.EndDay != "" {
 		dateTime := util.TimeParseLocalEndUnix(req.EndDay)
@@ -496,6 +528,7 @@ func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsReq
 			Header: map[string]string{
 				"id":              "编号",
 				"cowId":           "牛号",
+				"earNumber":       "耳标号",
 				"breedStatusName": "繁殖状态",
 				"penName":         "栏舍",
 				"lact":            "胎次",

+ 10 - 7
module/backend/event_breed.go

@@ -30,7 +30,8 @@ func (s *StoreEntry) CalvingList(ctx context.Context, req *pasturePb.SearchEvent
 		Select(`a.*,b.name as pen_name,c.name as staff_member_name`).
 		Joins(fmt.Sprintf("JOIN %s AS b on a.pen_id = b.id", new(model.Pen).TableName())).
 		Joins(fmt.Sprintf("JOIN %s AS c on a.operation_id = c.id", new(model.SystemUser).TableName())).
-		Where("a.pasture_id = ?", userModel.AppPasture.Id)
+		Where("a.pasture_id = ?", userModel.AppPasture.Id).Where("a.status = ?", pasturePb.IsShow_No)
+
 	if len(req.CowId) > 0 {
 		cowIds := strings.Split(req.CowId, ",")
 		pref.Where("a.cow_id IN ?", cowIds)
@@ -84,6 +85,8 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
 	}
 	req.OperationName = operationUser.Name
 
+	penMap := s.PenMap(ctx, userModel.AppPasture.Id)
+
 	// 记录牛只事件日志
 	defer func() {
 		if err == nil {
@@ -125,7 +128,7 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
 				continue
 			}
 			// 犊牛信息
-			newCalvingCalf := model.NewEventCalvingCalf(userModel.AppPasture.Id, int64(req.CowId), newEventCalving.Id, int64(req.CalvingAt), v)
+			newCalvingCalf := model.NewEventCalvingCalf(userModel.AppPasture.Id, int64(req.CowId), newEventCalving.Id, int64(req.CalvingAt), penMap, v)
 			// 留养犊牛
 			newCow := model.NewCalfCow(cow.Id, cow.LastBullNumber, newCalvingCalf)
 			if err = tx.Create(newCow).Error; err != nil {
@@ -310,7 +313,7 @@ func (s *StoreEntry) SameTimeList(
 	}, nil
 }
 
-func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EstrusItemsResponse, error) {
+func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventEstrusResponse, error) {
 	userModel, err := s.GetUserModel(ctx)
 	if err != nil {
 		return nil, xerr.WithStack(err)
@@ -345,7 +348,7 @@ func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsR
 
 	getCowInfoByCowId := GetCowInfoByCowId
 	getCowLastEvent := GetCowLastEvent
-	return &pasturePb.EstrusItemsResponse{
+	return &pasturePb.EventEstrusResponse{
 		Code: http.StatusOK,
 		Msg:  "ok",
 		Data: &pasturePb.EstrusItemsData{
@@ -435,7 +438,7 @@ func (s *StoreEntry) EstrusBatchMating(ctx context.Context, req *pasturePb.Event
 	return nil
 }
 
-func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingEventResponse, error) {
+func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventMatingResponse, error) {
 	userModel, err := s.GetUserModel(ctx)
 	if err != nil {
 		return nil, xerr.WithStack(err)
@@ -445,7 +448,7 @@ func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventR
 	var count int64 = 0
 	pref := s.DB.Model(new(model.EventMating)).
 		Where("mating_result > ?", pasturePb.MatingResult_Invalid).
-		Where("status = ?", pasturePb.IsShow_No).
+		Where("status = ?", pasturePb.IsShow_Ok).
 		Where("pasture_id = ?", userModel.AppPasture.Id)
 	if len(req.CowId) > 0 {
 		cowIds := strings.Split(req.CowId, ",")
@@ -460,7 +463,7 @@ func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventR
 	}
 
 	exposeEstrusTypeMap := s.ExposeEstrusTypeMap()
-	return &pasturePb.MatingEventResponse{
+	return &pasturePb.EventMatingResponse{
 		Code: http.StatusOK,
 		Msg:  "ok",
 		Data: &pasturePb.SearchMatingData{

+ 2 - 2
module/backend/event_breed_more.go

@@ -16,7 +16,7 @@ import (
 	"gorm.io/gorm"
 )
 
-func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnantCheckEventResponse, error) {
+func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventPregnantCheckResponse, error) {
 	userModel, err := s.GetUserModel(ctx)
 	if err != nil {
 		return nil, xerr.Custom("当前用户信息错误,请退出重新登录")
@@ -40,7 +40,7 @@ func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.Searc
 
 	pregnantCheckResultMap := s.PregnantCheckResultMap()
 	pregnantCheckMethodMap := s.PregnantCheckMethodMap()
-	return &pasturePb.PregnantCheckEventResponse{
+	return &pasturePb.EventPregnantCheckResponse{
 		Code: http.StatusOK,
 		Msg:  "ok",
 		Data: &pasturePb.SearchPregnantCheckData{

+ 5 - 5
module/backend/interface.go

@@ -167,10 +167,10 @@ type EventService interface {
 	CalvingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchLavingEventResponse, error)
 	CalvingCreate(ctx context.Context, req *pasturePb.EventCalving) error
 	// PregnantCheckList 孕检
-	PregnantCheckList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnantCheckEventResponse, error)
+	PregnantCheckList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventPregnantCheckResponse, error)
 	PregnantCheckCreateBatch(ctx context.Context, req *pasturePb.EventPregnantCheckBatch) error
 	// MatingList 配种
-	MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingEventResponse, error)
+	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
@@ -274,15 +274,15 @@ type WorkService interface {
 	CalendarToDoList(ctx context.Context, req *pasturePb.CalendarToDoRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalendarToDoResponse, error)
 	CalendarTableDetail(ctx context.Context, req *pasturePb.CalendarTableRequest, pagination *pasturePb.PaginationModel) (interface{}, error)
 
-	// ImmunisationCowList 清单相关
-	ImmunisationCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.ImmunizationItemsResponse, error)
+	// SameTimeCowList 清单相关
 	SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SameTimeItemResponse, error)
+	ImmunisationCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.ImmunizationItemsResponse, error)
 	PregnancyCheckCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyCheckItemsResponse, error)
 	WeaningCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.WeaningItemsResponse, error)
 	MatingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingItemsResponse, error)
 	CalvingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingItemsResponse, error)
 	CowDiseaseList(ctx context.Context, req *pasturePb.SearchEventCowTreatmentRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowDiseaseResponse, error)
-	EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EstrusItemsResponse, error)
+	EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventEstrusResponse, error)
 }
 
 type TestService interface {

+ 1 - 1
module/crontab/cow_cron.go

@@ -172,7 +172,7 @@ func (e *Entry) ImmunizationPlan() error {
 			pref.Where("a.admission_age = ?", plan.Value)
 		case pasturePb.ImmunizationConditions_Other_Vaccine_After:
 			if plan.ImmunizationPlanId > 0 {
-				pref.Joins("INNER JOIN event_immunization_plan as b ON b.immunization_plan_id = ? ", plan.ImmunizationPlanId).
+				pref.Joins("INNER JOIN event_immunization_plan as b ON b.plan_id = ? ", plan.ImmunizationPlanId).
 					Where("b.cow_id = a.id").
 					Where("DATE_ADD(b.reality_day, INTERVAL ? DAY) = ?", plan.Value, time.Now().Format(model.LayoutDate2)).
 					Where("b.status = ?", pasturePb.IsShow_Ok)