瀏覽代碼

event: 发情参加配种的

Yi 4 月之前
父節點
當前提交
2b2e486a60

+ 1 - 1
http/handler/pasture/prescription.go

@@ -157,7 +157,7 @@ func CreatedOrUpdatePrescription(c *gin.Context) {
 }
 
 func PrescriptionDetail(c *gin.Context) {
-	idStr := c.Query("id")
+	idStr := c.Param("id")
 	id, _ := strconv.ParseInt(idStr, 10, 64)
 	if err := valid.Validate(id, valid.Required); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)

+ 4 - 4
model/event_mating.go

@@ -38,7 +38,7 @@ func (e *EventMating) TableName() string {
 	return "event_mating"
 }
 
-func NewEventMating(cow *Cow, planDay int64) *EventMating {
+func NewEventMating(cow *Cow, planDay int64, exposeEstrusType pasturePb.ExposeEstrusType_Kind) *EventMating {
 	return &EventMating{
 		CowId:            cow.Id,
 		Lact:             cow.Lact,
@@ -49,7 +49,7 @@ func NewEventMating(cow *Cow, planDay int64) *EventMating {
 		PlanDay:          planDay,
 		EndDay:           planDay,
 		MatingResult:     pasturePb.MatingResult_Unknown,
-		ExposeEstrusType: pasturePb.ExposeEstrusType_Same_Time,
+		ExposeEstrusType: exposeEstrusType,
 		Status:           pasturePb.IsShow_No,
 	}
 }
@@ -78,10 +78,10 @@ func NewEventMating2(cow *Cow, req *pasturePb.EventMating, currentUser *SystemUs
 	}
 }
 
-func NewEventMatingList(cowList []*Cow, planDay int64) []*EventMating {
+func NewEventMatingList(cowList []*Cow, planDay int64, exposeEstrusType pasturePb.ExposeEstrusType_Kind) []*EventMating {
 	var matingList []*EventMating
 	for _, cow := range cowList {
-		matingList = append(matingList, NewEventMating(cow, planDay))
+		matingList = append(matingList, NewEventMating(cow, planDay, exposeEstrusType))
 	}
 	return matingList
 }

+ 29 - 2
module/backend/event_breed.go

@@ -163,7 +163,21 @@ func (s *StoreEntry) EstrusCreate(ctx context.Context, req *pasturePb.EventEstru
 	if err != nil {
 		return xerr.Custom("获取当前登录用户失败")
 	}
-	if err = s.DB.Create(estrusInfo).Error; err != nil {
+	if err = s.DB.Transaction(func(tx *gorm.DB) error {
+		if err = tx.Create(estrusInfo).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+
+		if estrusInfo.IsMating == pasturePb.IsShow_Ok {
+			cow, _ := s.GetCowInfoByCowId(ctx, int64(req.CowId))
+			newEventMating := model.NewEventMating(cow, estrusInfo.EstrusAt, estrusInfo.ExposeEstrusType)
+			if err = tx.Create(newEventMating).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
+
+		return nil
+	}); err != nil {
 		return xerr.WithStack(err)
 	}
 	return nil
@@ -171,14 +185,27 @@ func (s *StoreEntry) EstrusCreate(ctx context.Context, req *pasturePb.EventEstru
 
 func (s *StoreEntry) EstrusBatch(ctx context.Context, req *pasturePb.EventEstrusBatch) error {
 	estrusList := make([]*model.EventEstrus, 0)
+	eventMatingList := make([]*model.EventMating, 0)
 	for _, v := range req.Item {
 		estrusInfo, err := s.EventEstrusCheck(ctx, v)
 		if err != nil {
 			return xerr.Custom("获取当前登录用户失败")
 		}
 		estrusList = append(estrusList, estrusInfo)
+		cow, _ := s.GetCowInfoByCowId(ctx, int64(v.CowId))
+		eventMatingList = append(eventMatingList, model.NewEventMating(cow, estrusInfo.EstrusAt, estrusInfo.ExposeEstrusType))
 	}
-	if err := s.DB.Create(estrusList).Error; err != nil {
+	if err := s.DB.Transaction(func(tx *gorm.DB) error {
+		if err := tx.Create(estrusList).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+		if len(eventMatingList) > 0 {
+			if err := tx.Create(eventMatingList).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
+		return nil
+	}); err != nil {
 		return xerr.WithStack(err)
 	}
 	return nil

+ 1 - 1
module/backend/prescription.go

@@ -345,7 +345,7 @@ func (s *StoreEntry) PrescriptionDetail(ctx context.Context, id int64) (*pasture
 			Id:                   prescriptionData.Id,
 			Name:                 prescriptionData.Name,
 			ApplicableDiseaseIds: make([]int32, 0),
-			IsShow:               0,
+			IsShow:               prescriptionData.IsShow,
 			Remarks:              prescriptionData.Remarks,
 			DrugsList:            model.PrescriptionDrugsSlice(prescriptionDrugsList).ToPB(),
 		},

+ 1 - 1
module/crontab/work_cron.go

@@ -54,7 +54,7 @@ func (e *Entry) GenerateCalendarBySameTimePlan(cowList []*model.Cow, sameTime *m
 			calendarName = backend.CalendarTypeMap()[pasturePb.CalendarType_Mating]
 			calendarType = pasturePb.CalendarType_Mating
 			histCount = e.GetTowardTaiCowSum()
-			newEventMatingList = append(newEventMatingList, model.NewEventMatingList(newCowList, showDay.Unix())...)
+			newEventMatingList = append(newEventMatingList, model.NewEventMatingList(newCowList, showDay.Unix(), pasturePb.ExposeEstrusType_Same_Time)...)
 			newEventItemList = append(newEventItemList, model.NewEventItemList(newCowList, calendarType)...)
 		} else {
 			if collateNode.SameTimeType == pasturePb.SameTimeType_RnGH {