Browse Source

event: 批量孕检

Yi 4 months ago
parent
commit
44566c8a04

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20241114030036-e542467bac19
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20241115062856-467312aafe19
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eko/gocache v1.1.0

+ 2 - 2
go.sum

@@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
 cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20241114030036-e542467bac19 h1:Sk47RofjO+bwK2sLbUuvMupUVna4yQmRmTloICbO6JU=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20241114030036-e542467bac19/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241115062856-467312aafe19 h1:45rzK/vjqSDyvOV/Rkw6T9zTbTTWrb/ONmpa4FUrZMA=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241115062856-467312aafe19/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=

+ 16 - 11
http/handler/event/event_breed.go

@@ -93,25 +93,30 @@ func PregnantCheckEventList(c *gin.Context) {
 	ginutil.JSONResp(c, res)
 }
 
-func PregnantCheckEventCreate(c *gin.Context) {
-	var req pasturePb.EventPregnantCheck
+func PregnantCheckEventCreateBatch(c *gin.Context) {
+	var req pasturePb.EventPregnantCheckBatch
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
 	if err := valid.ValidateStruct(&req,
-		valid.Field(&req.CowId, valid.Required),
-		valid.Field(&req.PregnantCheckAt, valid.Required),
-		valid.Field(&req.PregnantCheckResult, valid.Required),
-		valid.Field(&req.PregnantCheckAt, valid.Required),
-		valid.Field(&req.OperationId, valid.Required),
+		valid.Field(&req.Item, valid.Required, valid.Each(valid.By(func(value interface{}) error {
+			item := value.(pasturePb.EventPregnantCheckRequest)
+			return valid.ValidateStruct(&item,
+				valid.Field(&item.CowId, valid.Required),
+				valid.Field(&item.PregnantCheckAt, valid.Required),
+				valid.Field(&item.PregnantCheckResult, valid.Required),
+				valid.Field(&item.PregnantCheckMethod, valid.Required),
+				valid.Field(&item.OperationId, valid.Required),
+			)
+		}))),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
-	if err := middleware.BackendOperation(c).OpsService.PregnantCheckCreate(c, &req); err != nil {
+	if err := middleware.BackendOperation(c).OpsService.PregnantCheckCreateBatch(c, &req); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return
 	}
@@ -271,8 +276,8 @@ func SameTimeList(c *gin.Context) {
 	ginutil.JSONResp(c, res)
 }
 
-func AbortionCreate(c *gin.Context) {
-	var req pasturePb.EventAbortionSlice
+func AbortionCreateBatch(c *gin.Context) {
+	var req pasturePb.EventAbortionBatch
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
@@ -294,7 +299,7 @@ func AbortionCreate(c *gin.Context) {
 		return
 	}
 
-	if err := middleware.BackendOperation(c).OpsService.AbortionCreateSlice(c, &req); err != nil {
+	if err := middleware.BackendOperation(c).OpsService.AbortionCreateBatch(c, &req); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return
 	}

+ 2 - 2
http/route/event_api.go

@@ -33,7 +33,7 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		eventRoute.POST("/calving/create", event.CalvingEventCreate)
 		// 孕检
 		eventRoute.POST("/pregnant/check/list", event.PregnantCheckEventList)
-		eventRoute.POST("/pregnant/check/create", event.PregnantCheckEventCreate)
+		eventRoute.POST("/pregnant/check/create/batch", event.PregnantCheckEventCreateBatch)
 		// 配种
 		eventRoute.POST("/mating/list", event.MatingEventList)
 		eventRoute.POST("/mating/create", event.MatingCreate)
@@ -46,7 +46,7 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 
 		// 流产
 		eventRoute.POST("/abortion/list", event.AbortionList)
-		eventRoute.POST("/abortion/create", event.AbortionCreate)
+		eventRoute.POST("/abortion/create/batch", event.AbortionCreateBatch)
 
 		// 发病
 		eventRoute.POST("/disease/create", event.CowDiseaseCreate)

+ 0 - 6
model/event_mating.go

@@ -240,9 +240,3 @@ type MultiFactorPregnancyRateChart struct {
 	PregnantRateMap map[string]map[string]string `json:"pregnantRateMap"`
 	KepMap          []string                     `json:"kepMap"`
 }
-
-type MatingTimes struct {
-	Mt            int32
-	CowId         int64
-	EventMatingId int64
-}

+ 43 - 1
model/event_pregnant_check.go

@@ -38,11 +38,15 @@ func (e *EventPregnantCheck) TableName() string {
 }
 
 func NewEventPregnantCheck(cow *Cow, penMap map[int32]*Pen, pregnantCheckName string) *EventPregnantCheck {
+	penName := ""
+	if pen, ok := penMap[cow.PenId]; ok {
+		penName = pen.Name
+	}
 	return &EventPregnantCheck{
 		CowId:             cow.Id,
 		CowType:           cow.CowType,
 		PenId:             cow.PenId,
-		PenName:           penMap[cow.PenId].Name,
+		PenName:           penName,
 		DayAge:            cow.GetDayAge(),
 		Lact:              int8(cow.Lact),
 		PlanDay:           util.TimeParseLocalUnix(time.Now().Format(LayoutDate2)),
@@ -64,6 +68,44 @@ func NewEventPregnantCheckList(cowList []*Cow, penMap map[int32]*Pen, pregnantCh
 	return res
 }
 
+type EventPregnantCheck2 struct {
+	Cow                 *Cow
+	OperationUser       *SystemUser
+	CurrentUser         *SystemUser
+	PregnantCheckAt     int64
+	PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind
+	PregnantCheckResult pasturePb.PregnantCheckResult_Kind
+	Remarks             string
+}
+
+func NewEventPregnantCheck2(req *EventPregnantCheck2, penMap map[int32]*Pen) *EventPregnantCheck {
+	penName := ""
+	if pen, ok := penMap[req.Cow.PenId]; ok {
+		penName = pen.Name
+	}
+	return &EventPregnantCheck{
+		CowId:               req.Cow.Id,
+		CowType:             req.Cow.CowType,
+		PenId:               req.Cow.PenId,
+		PenName:             penName,
+		DayAge:              req.Cow.GetDayAge(),
+		Lact:                int8(req.Cow.Lact),
+		PlanDay:             req.PregnantCheckAt,
+		RealityDay:          req.PregnantCheckAt,
+		EndDay:              req.PregnantCheckAt,
+		PregnantCheckResult: req.PregnantCheckResult,
+		PregnantCheckMethod: req.PregnantCheckMethod,
+		PregnantCheckName:   PregnantCheckForFirst,
+		BullId:              req.Cow.LastBullNumber,
+		Status:              pasturePb.IsShow_Ok,
+		OperationId:         req.OperationUser.Id,
+		OperationName:       req.OperationUser.Name,
+		Remarks:             req.Remarks,
+		MessageId:           req.CurrentUser.Id,
+		MessageName:         req.CurrentUser.Name,
+	}
+}
+
 type EventPregnantCheckSlice []*EventPregnantCheck
 
 func (e EventPregnantCheckSlice) ToPB(

+ 3 - 3
model/system_basic.go

@@ -19,9 +19,9 @@ var PregnantCheckNameKeyMap = map[string]string{
 	PregnantCheckForSecond: "复检",
 }
 
-var PregnantCheckNameValueMap = map[int64]string{
-	1: "PregnantCheckForFirst",
-	2: "PregnantCheckForSecond",
+var PregnantCheckNameValueMap = map[int32]string{
+	1: "pregnant_check_for_first",
+	2: "pregnant_check_for_second",
 }
 
 type SystemBasic struct {

+ 4 - 0
module/backend/calendar.go

@@ -285,6 +285,10 @@ func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.I
 		pref.Where("a.status = ?", req.Status)
 	}
 
+	if req.PregnantCheckName > 0 {
+		pref.Where("pregnant_check_name = ?", model.PregnantCheckNameValueMap[req.PregnantCheckName])
+	}
+
 	if err := pref.Order("id desc").
 		Count(&count).
 		Limit(int(pagination.PageSize)).

+ 105 - 362
module/backend/event_breed.go

@@ -2,7 +2,6 @@ package backend
 
 import (
 	"context"
-	"encoding/json"
 	"fmt"
 	"kpt-pasture/model"
 	"kpt-pasture/util"
@@ -131,10 +130,10 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
 	return nil
 }
 
-func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnantCheckEventResponse, error) {
-	pregnantCheckList := make([]*model.EventPregnantCheck, 0)
+func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EstrusEventResponse, error) {
+	estrusList := make([]*model.EventEstrus, 0)
 	var count int64 = 0
-	pref := s.DB.Table(new(model.EventPregnantCheck).TableName())
+	pref := s.DB.Table(new(model.EventEstrus).TableName())
 	if len(req.CowId) > 0 {
 		cowIds := strings.Split(req.CowId, ",")
 		pref.Where("cow_id IN ?", cowIds)
@@ -143,17 +142,15 @@ func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.Searc
 	if err := pref.Order("id desc").
 		Count(&count).Limit(int(pagination.PageSize)).
 		Offset(int(pagination.PageOffset)).
-		Find(&pregnantCheckList).Error; err != nil {
+		Find(&estrusList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
 
-	pregnantCheckResultMap := s.PregnantCheckResultMap()
-	pregnantCheckMethodMap := s.PregnantCheckMethodMap()
-	return &pasturePb.PregnantCheckEventResponse{
+	return &pasturePb.EstrusEventResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
-		Data: &pasturePb.SearchPregnantCheckData{
-			List:     model.EventPregnantCheckSlice(pregnantCheckList).ToPB(pregnantCheckResultMap, pregnantCheckMethodMap),
+		Data: &pasturePb.SearchEstrusData{
+			List:     model.EstrusSlice(estrusList).ToPB(),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,
@@ -161,131 +158,115 @@ func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.Searc
 	}, nil
 }
 
-func (s *StoreEntry) PregnantCheckCreate(ctx context.Context, req *pasturePb.EventPregnantCheck) error {
-	eventCheckModel, err := s.PregnantCheckCreateCheck(ctx, req)
+func (s *StoreEntry) EstrusCreate(ctx context.Context, req *pasturePb.EventEstrus) error {
+	if len(req.CowId) <= 0 {
+		return xerr.Custom("请选择相关牛只")
+	}
+	cowList, err := s.ParseCowIds(ctx, req.CowId)
 	if err != nil {
 		return xerr.WithStack(err)
 	}
+	estrusList := make([]*model.EventEstrus, 0)
+	currentUser, err := s.GetCurrentSystemUser(ctx)
+	if err != nil {
+		return xerr.Custom("获取当前登录用户失败")
+	}
 
-	// 更新怀孕牛只
-	updatePregnantCowIds := make([]int64, 0)
-	// 更新流产牛只
-	updateAbortCowIds := make([]int64, 0)
-	// 更新空怀牛只
-	updateEmptyCowIds := make([]int64, 0)
-
-	cowIds := make([]int64, 0)
-	for _, cow := range eventCheckModel.CowList {
-		itemEventPregnantCheck := &model.EventPregnantCheck{}
-		if err = s.DB.Model(new(model.EventPregnantCheck)).
-			Where("lact = ?", cow.Lact).
-			Where("cow_id = ?", cow.Id).
-			Order("id desc").
-			First(itemEventPregnantCheck).Error; err != nil {
+	for _, cow := range cowList {
+		operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
+		if err != nil {
 			return xerr.WithStack(err)
 		}
+		req.OperationName = operationUser.Name
+		estrusList = append(estrusList, model.NewEventEstrus(cow, currentUser, req))
+	}
 
-		if req.PregnantCheckResult == pasturePb.PregnantCheckResult_Pregnant {
-			updatePregnantCowIds = append(updatePregnantCowIds, cow.Id)
-		}
+	if err = s.DB.Create(estrusList).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}
 
-		if req.PregnantCheckResult == pasturePb.PregnantCheckResult_UnPregnant {
-			if itemEventPregnantCheck.PregnantCheckName == model.PregnantCheckForFirst {
-				updateAbortCowIds = append(updateAbortCowIds, cow.Id)
-			}
-			if itemEventPregnantCheck.PregnantCheckName == model.PregnantCheckForSecond {
-				updateEmptyCowIds = append(updateEmptyCowIds, cow.Id)
-			}
-		}
-		cowIds = append(cowIds, cow.Id)
+func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSameTime) error {
+	if _, err := s.GetSameTimeById(ctx, int64(req.SameTimeId)); err != nil {
+		return xerr.WithStack(err)
 	}
 
-	if err = s.DB.Transaction(func(tx *gorm.DB) error {
-		// 更新孕检事件表
-		if err = tx.Model(new(model.EventPregnantCheck)).
-			Where("id IN ?", cowIds).
-			Updates(map[string]interface{}{
-				"reality_day":           req.PregnantCheckAt,
-				"pregnant_check_result": req.PregnantCheckResult,
-				"pregnant_check_method": req.PregnantCheckMethod,
-				"operation_id":          eventCheckModel.OperationUser.Id,
-				"operation_name":        eventCheckModel.OperationUser.Name,
-				"message_id":            eventCheckModel.CurrentUser.Id,
-				"message_name":          eventCheckModel.CurrentUser.Name,
-				"remarks":               req.Remarks,
-				"is_pregnant":           req.PregnantCheckResult,
-			}).Error; err != nil {
+	drugs := &model.Drugs{}
+	var err error
+	if req.DrugsId > 0 {
+		if drugs, err = s.GetDrugsById(ctx, int64(req.DrugsId)); err != nil {
 			return xerr.WithStack(err)
 		}
-		// 更新牛只信息和配种事件表怀孕状态
-		if len(updatePregnantCowIds) > 0 {
-			if err = tx.Model(&model.Cow{}).
-				Where("cow_id IN ?", updatePregnantCowIds).
-				Updates(map[string]interface{}{
-					"breed_status":           pasturePb.BreedStatus_Pregnant,
-					"last_pregnant_check_at": req.PregnantCheckAt,
-					"is_pregnant":            pasturePb.IsShow_Ok,
-				}).Error; err != nil {
-				return xerr.WithStack(err)
-			}
+	}
+	operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
+	if err != nil {
+		return xerr.WithStack(err)
+	}
 
-			if err = tx.Model(&model.EventMating{}).Where("cow_id IN ?", updatePregnantCowIds).
-				Group("cow_id").Select("MAX(id) as id").
-				Updates(map[string]interface{}{
-					"mating_result":    pasturePb.MatingResult_Pregnant,
-					"mating_result_at": req.PregnantCheckAt,
-				}).Error; err != nil {
-				return xerr.WithStack(err)
-			}
+	if err = s.DB.Transaction(func(tx *gorm.DB) error {
+		if err = tx.Model(new(model.CowSameTime)).
+			Where("cow_id = ?", req.CowId).
+			Where("same_time_id = ?", req.SameTimeId).
+			Update("same_time_status", pasturePb.SameTimeStatus_In_Progress).Error; err != nil {
+			return xerr.WithStack(err)
 		}
-		// 更新牛只信息和配种事件表流产状态
-		if len(updateAbortCowIds) > 0 {
-			if err = tx.Model(&model.Cow{}).Where("cow_id IN ?", updateAbortCowIds).
-				Updates(map[string]interface{}{
-					"breed_status":           pasturePb.BreedStatus_Abort,
-					"last_pregnant_check_at": req.PregnantCheckAt,
-					"is_pregnant":            pasturePb.IsShow_Ok,
-				}).Error; err != nil {
-				return xerr.WithStack(err)
-			}
 
-			if err = tx.Model(&model.EventMating{}).Where("cow_id IN ?", updateAbortCowIds).
-				Group("cow_id").Select("MAX(id) as id").
-				Updates(map[string]interface{}{
-					"mating_result":    pasturePb.MatingResult_Abort,
-					"mating_result_at": req.PregnantCheckAt,
-				}).Error; err != nil {
-				return xerr.WithStack(err)
-			}
+		if err = tx.Model(new(model.EventCowSameTime)).
+			Where("cow_id = ?", req.CowId).
+			Where("same_time_id = ?", req.SameTimeId).
+			Where("same_time_type = ?", req.SameTimeType).
+			Updates(map[string]interface{}{
+				"status":         pasturePb.IsShow_Ok,
+				"drug_id":        drugs.Id,
+				"unit":           drugs.Unit,
+				"usage":          req.Usage,
+				"remarks":        req.Remarks,
+				"operation_id":   operationUser.Id,
+				"operation_name": operationUser.Name,
+			}).Error; err != nil {
+			return xerr.WithStack(err)
 		}
-		// 更新牛只信息和配种事件表空怀状态
-		if len(updateEmptyCowIds) > 0 {
-			if err = tx.Model(&model.Cow{}).Where("cow_id IN ?", updateEmptyCowIds).
-				Updates(map[string]interface{}{
-					"breed_status":           pasturePb.BreedStatus_Empty,
-					"last_pregnant_check_at": req.PregnantCheckAt,
-					"is_pregnant":            pasturePb.IsShow_Ok,
-				}).Error; err != nil {
-				return xerr.WithStack(err)
-			}
 
-			if err = tx.Model(&model.EventMating{}).Where("cow_id IN ?", updateEmptyCowIds).
-				Group("cow_id").Select("MAX(id) as id").
-				Updates(map[string]interface{}{
-					"mating_result":    pasturePb.MatingResult_Empty,
-					"mating_result_at": req.PregnantCheckAt,
-				}).Error; err != nil {
-				return xerr.WithStack(err)
-			}
-		}
 		return nil
 	}); err != nil {
 		return xerr.WithStack(err)
 	}
-
 	return nil
 }
 
+func (s *StoreEntry) SameTimeList(
+	ctx context.Context,
+	req *pasturePb.SearchEventRequest,
+	pagination *pasturePb.PaginationModel,
+) (*pasturePb.SearchSameTimeResponse, error) {
+	cowSameTimeList := make([]*model.EventCowSameTime, 0)
+	var count int64 = 0
+	pref := s.DB.Table(new(model.EventCowSameTime).TableName())
+	if req.CowId != "" {
+		cowIds := strings.Split(req.CowId, ",")
+		pref.Where("cow_id IN ?", cowIds)
+	}
+
+	if err := pref.Count(&count).
+		Limit(int(pagination.PageSize)).
+		Offset(int(pagination.PageOffset)).
+		Find(&cowSameTimeList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	return &pasturePb.SearchSameTimeResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SameTimeData{
+			List:     model.EventCowSameTimeSlice(cowSameTimeList).ToPB(),
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}
+
 func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingEventResponse, error) {
 	matingList := make([]*model.EventMating, 0)
 	var count int64 = 0
@@ -329,6 +310,10 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
 		return xerr.Custom("未找到冻精信息")
 	}
 
+	if frozenSemen.Quantity < req.FrozenSemenCount {
+		return xerr.Custom("冻精数量不足")
+	}
+
 	// 更新复配的牛只
 	matingReMatchIds := make([]int64, 0)
 	// 新建配种信息的牛只
@@ -338,7 +323,7 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
 	// 所有牛只
 	cowIds := make([]int64, 0)
 	// 需要更新配次的牛只
-	matingTimes := make([]*model.MatingTimes, 0)
+	matingTimes := make([]*MatingTimes, 0)
 	// 需要更新空怀的牛只
 	emptyCowIds := make([]int64, 0)
 
@@ -371,7 +356,7 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
 			eventMatingHistory.MatingResult == pasturePb.MatingResult_Unknown {
 			matingReMatchIds = append(matingReMatchIds, eventMatingHistory.Id)
 		} else {
-			matingTimes = append(matingTimes, &model.MatingTimes{
+			matingTimes = append(matingTimes, &MatingTimes{
 				Mt:            cow.MatingTimes + 1,
 				CowId:         cow.Id,
 				EventMatingId: eventMatingHistory.Id,
@@ -387,15 +372,14 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
 		cowIds = append(cowIds, cow.Id)
 	}
 
-	zaplog.Info("MatingCreate",
-		zap.Any("cowIds", cowIds),
-		zap.Any("updateMatingList", updateMatingList),
-		zap.Any("newMatingList", newMatingList),
-		zap.Any("matingReMatchIds", matingReMatchIds),
-		zap.Any("req", req),
-	)
-
 	if len(cowIds) != len(updateMatingList)+len(matingReMatchIds)+len(newMatingList) {
+		zaplog.Error("MatingCreate",
+			zap.Any("cowIds", cowIds),
+			zap.Any("updateMatingList", updateMatingList),
+			zap.Any("newMatingList", newMatingList),
+			zap.Any("matingReMatchIds", matingReMatchIds),
+			zap.Any("req", req),
+		)
 		return xerr.Custom("配种信息有误")
 	}
 
@@ -509,244 +493,3 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
 
 	return nil
 }
-
-func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EstrusEventResponse, error) {
-	estrusList := make([]*model.EventEstrus, 0)
-	var count int64 = 0
-	pref := s.DB.Table(new(model.EventEstrus).TableName())
-	if len(req.CowId) > 0 {
-		cowIds := strings.Split(req.CowId, ",")
-		pref.Where("cow_id IN ?", cowIds)
-	}
-
-	if err := pref.Order("id desc").
-		Count(&count).Limit(int(pagination.PageSize)).
-		Offset(int(pagination.PageOffset)).
-		Find(&estrusList).Error; err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	return &pasturePb.EstrusEventResponse{
-		Code:    http.StatusOK,
-		Message: "ok",
-		Data: &pasturePb.SearchEstrusData{
-			List:     model.EstrusSlice(estrusList).ToPB(),
-			Total:    int32(count),
-			PageSize: pagination.PageSize,
-			Page:     pagination.Page,
-		},
-	}, nil
-}
-
-func (s *StoreEntry) EstrusCreate(ctx context.Context, req *pasturePb.EventEstrus) error {
-	if len(req.CowId) <= 0 {
-		return xerr.Custom("请选择相关牛只")
-	}
-	cowList, err := s.ParseCowIds(ctx, req.CowId)
-	if err != nil {
-		return xerr.WithStack(err)
-	}
-	estrusList := make([]*model.EventEstrus, 0)
-	currentUser, err := s.GetCurrentSystemUser(ctx)
-	if err != nil {
-		return xerr.Custom("获取当前登录用户失败")
-	}
-
-	for _, cow := range cowList {
-		operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
-		if err != nil {
-			return xerr.WithStack(err)
-		}
-		req.OperationName = operationUser.Name
-		estrusList = append(estrusList, model.NewEventEstrus(cow, currentUser, req))
-	}
-
-	if err = s.DB.Create(estrusList).Error; err != nil {
-		return xerr.WithStack(err)
-	}
-	return nil
-}
-
-func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSameTime) error {
-	if _, err := s.GetSameTimeById(ctx, int64(req.SameTimeId)); err != nil {
-		return xerr.WithStack(err)
-	}
-
-	drugs := &model.Drugs{}
-	var err error
-	if req.DrugsId > 0 {
-		if drugs, err = s.GetDrugsById(ctx, int64(req.DrugsId)); err != nil {
-			return xerr.WithStack(err)
-		}
-	}
-	operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
-	if err != nil {
-		return xerr.WithStack(err)
-	}
-
-	if err = s.DB.Transaction(func(tx *gorm.DB) error {
-		if err = tx.Model(new(model.CowSameTime)).
-			Where("cow_id = ?", req.CowId).
-			Where("same_time_id = ?", req.SameTimeId).
-			Update("same_time_status", pasturePb.SameTimeStatus_In_Progress).Error; err != nil {
-			return xerr.WithStack(err)
-		}
-
-		if err = tx.Model(new(model.EventCowSameTime)).
-			Where("cow_id = ?", req.CowId).
-			Where("same_time_id = ?", req.SameTimeId).
-			Where("same_time_type = ?", req.SameTimeType).
-			Updates(map[string]interface{}{
-				"status":         pasturePb.IsShow_Ok,
-				"drug_id":        drugs.Id,
-				"unit":           drugs.Unit,
-				"usage":          req.Usage,
-				"remarks":        req.Remarks,
-				"operation_id":   operationUser.Id,
-				"operation_name": operationUser.Name,
-			}).Error; err != nil {
-			return xerr.WithStack(err)
-		}
-
-		return nil
-	}); err != nil {
-		return xerr.WithStack(err)
-	}
-	return nil
-}
-
-func (s *StoreEntry) SameTimeList(
-	ctx context.Context,
-	req *pasturePb.SearchEventRequest,
-	pagination *pasturePb.PaginationModel,
-) (*pasturePb.SearchSameTimeResponse, error) {
-	cowSameTimeList := make([]*model.EventCowSameTime, 0)
-	var count int64 = 0
-	pref := s.DB.Table(new(model.EventCowSameTime).TableName())
-	if req.CowId != "" {
-		cowIds := strings.Split(req.CowId, ",")
-		pref.Where("cow_id IN ?", cowIds)
-	}
-
-	if err := pref.Count(&count).
-		Limit(int(pagination.PageSize)).
-		Offset(int(pagination.PageOffset)).
-		Find(&cowSameTimeList).Error; err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	return &pasturePb.SearchSameTimeResponse{
-		Code:    http.StatusOK,
-		Message: "ok",
-		Data: &pasturePb.SameTimeData{
-			List:     model.EventCowSameTimeSlice(cowSameTimeList).ToPB(),
-			Total:    int32(count),
-			PageSize: pagination.PageSize,
-			Page:     pagination.Page,
-		},
-	}, nil
-
-}
-
-func (s *StoreEntry) AbortionCreate(ctx context.Context, req *pasturePb.EventAbortionRequest) error {
-	cow, err := s.GetCowInfoByCowId(ctx, int64(req.CowId))
-	if err != nil {
-		return xerr.WithStack(err)
-	}
-
-	systemUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
-	if err != nil {
-		return xerr.WithStack(err)
-	}
-
-	req.OperationName = systemUser.Name
-	abortionReasonsMap := s.AbortionReasonsMap()
-	newEventAbortion := model.NewEventAbortion(cow, req, abortionReasonsMap)
-
-	lastCowMating := &model.EventMating{}
-	if err = s.DB.Model(new(model.EventMating)).Where("cow_id = ?", cow.Id).
-		Where("mating_result = ?", pasturePb.MatingResult_Pregnant).
-		Order("id desc").First(lastCowMating).Error; err != nil {
-		return xerr.WithStack(err)
-	}
-
-	if err = s.DB.Transaction(func(tx *gorm.DB) error {
-		// 创建牛只流产事件数据
-		if err = tx.Create(newEventAbortion).Error; err != nil {
-			return xerr.WithStack(err)
-		}
-		// 更新牛只状态
-		if err = tx.Model(new(model.Cow)).Where("id = ?", req.CowId).
-			Updates(map[string]interface{}{
-				"is_pregnant":      pasturePb.IsShow_No,
-				"last_abortion_at": req.AbortionAt,
-				"breed_status":     pasturePb.BreedStatus_Abort,
-			}).Error; err != nil {
-			return xerr.WithStack(err)
-		}
-
-		// 更新最近一次配种结果为流产
-		if err = tx.Model(new(model.EventMating)).
-			Where("id = ?", lastCowMating.Id).
-			Updates(map[string]interface{}{
-				"mating_result":    pasturePb.MatingResult_Abort,
-				"mating_result_at": req.AbortionAt,
-			}).Error; err != nil {
-		}
-		return nil
-	}); err != nil {
-		return xerr.WithStack(err)
-	}
-
-	return nil
-}
-
-func (s *StoreEntry) AbortionCreateSlice(ctx context.Context, req *pasturePb.EventAbortionSlice) error {
-	if len(req.Item) <= 0 {
-		return xerr.WithStack(xerr.New("流产数据不能为空"))
-	}
-	errors := make(map[int32]error)
-	for _, v := range req.Item {
-		if err := s.AbortionCreate(ctx, v); err != nil {
-			errors[v.CowId] = err
-		}
-	}
-
-	if len(errors) > 0 {
-		b, _ := json.Marshal(errors)
-		return xerr.WithStack(xerr.Customf("部分流产数据创建失败: %s", string(b)))
-	}
-	return nil
-}
-
-func (s *StoreEntry) AbortionList(
-	ctx context.Context,
-	req *pasturePb.SearchEventRequest,
-	pagination *pasturePb.PaginationModel,
-) (*pasturePb.EventAbortionResponse, error) {
-	abortionList := make([]*model.EventAbortion, 0)
-	var count int64 = 0
-	pref := s.DB.Model(new(model.EventAbortion))
-	if len(req.CowId) > 0 {
-		cowIds := strings.Split(req.CowId, ",")
-		pref.Where("cow_id IN ?", cowIds)
-	}
-
-	if err := pref.Order("id desc").
-		Count(&count).Limit(int(pagination.PageSize)).
-		Offset(int(pagination.PageOffset)).
-		Find(&abortionList).Error; err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	return &pasturePb.EventAbortionResponse{
-		Code:    http.StatusOK,
-		Message: "ok",
-		Data: &pasturePb.EventAbortionData{
-			List:     model.AbortionSlice(abortionList).ToPB(),
-			Total:    int32(count),
-			PageSize: pagination.PageSize,
-			Page:     pagination.Page,
-		},
-	}, nil
-}

+ 254 - 0
module/backend/event_breed_abortion.go

@@ -0,0 +1,254 @@
+package backend
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"kpt-pasture/model"
+	"net/http"
+	"strings"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+	"gorm.io/gorm"
+)
+
+func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnantCheckEventResponse, error) {
+	pregnantCheckList := make([]*model.EventPregnantCheck, 0)
+	var count int64 = 0
+	pref := s.DB.Table(new(model.EventPregnantCheck).TableName())
+	if len(req.CowId) > 0 {
+		cowIds := strings.Split(req.CowId, ",")
+		pref.Where("cow_id IN ?", cowIds)
+	}
+
+	if err := pref.Order("id desc").
+		Count(&count).Limit(int(pagination.PageSize)).
+		Offset(int(pagination.PageOffset)).
+		Find(&pregnantCheckList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	pregnantCheckResultMap := s.PregnantCheckResultMap()
+	pregnantCheckMethodMap := s.PregnantCheckMethodMap()
+	return &pasturePb.PregnantCheckEventResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SearchPregnantCheckData{
+			List:     model.EventPregnantCheckSlice(pregnantCheckList).ToPB(pregnantCheckResultMap, pregnantCheckMethodMap),
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}
+
+func (s *StoreEntry) PregnantCheckCreateBatch(ctx context.Context, req *pasturePb.EventPregnantCheckBatch) error {
+	pregnantCheckBatchModelList, err := s.PregnantCheckCreateCheck(ctx, req)
+	if err != nil {
+		return xerr.WithStack(err)
+	}
+	currentUser, err := s.GetCurrentSystemUser(ctx)
+	if err != nil {
+		return xerr.Customf("获取当前用户失败: %s", err.Error())
+	}
+
+	penMap := s.PenMap(ctx)
+	// 新增孕检牛只
+	newEventPregnantCheckList := make([]*model.EventPregnantCheck, 0)
+	// 更新孕检牛只
+	newPregnantCheckBatchModelList := make([]*PregnantCheckBatchModel, 0)
+	for _, item := range pregnantCheckBatchModelList {
+		itemEventPregnantCheck, err := s.GetEventPregnantCheckIsExIstByCowId(ctx, item.Cow)
+		if err != nil {
+			return xerr.WithStack(err)
+		}
+
+		// 孕检清单里面没有的,需要新增孕检事件
+		eventCheckModel := model.NewEventPregnantCheck2(&model.EventPregnantCheck2{
+			Cow:                 item.Cow,
+			OperationUser:       item.OperationUser,
+			CurrentUser:         currentUser,
+			PregnantCheckAt:     int64(item.PregnantCheckAt),
+			PregnantCheckMethod: item.PregnantCheckMethod,
+			PregnantCheckResult: item.PregnantCheckResult,
+			Remarks:             item.Remarks,
+		}, penMap)
+		if itemEventPregnantCheck.Id <= 0 {
+			newEventPregnantCheckList = append(newEventPregnantCheckList, eventCheckModel)
+		} else {
+			item.EventPregnancyCheck = itemEventPregnantCheck
+			newPregnantCheckBatchModelList = append(newPregnantCheckBatchModelList, item)
+		}
+	}
+
+	if err = s.DB.Transaction(func(tx *gorm.DB) error {
+		// 新增孕检事件
+		if len(newEventPregnantCheckList) > 0 {
+			if err = tx.Create(newEventPregnantCheckList).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
+
+		for _, item := range newPregnantCheckBatchModelList {
+			breedStatus := pasturePb.BreedStatus_Pregnant
+			isPregnant := pasturePb.IsShow_Ok
+			if item.PregnantCheckResult == pasturePb.PregnantCheckResult_UnPregnant {
+				breedStatus = pasturePb.BreedStatus_Empty
+				isPregnant = pasturePb.IsShow_No
+			}
+
+			// 更新上一次配种结果数据,如何是复检无胎则更新为流产
+			if item.EventPregnancyCheck.PregnantCheckName == model.PregnantCheckForSecond {
+				breedStatus = pasturePb.BreedStatus_Abort
+			}
+
+			// 更新牛只基本信息
+			if err = tx.Model(&model.Cow{}).
+				Where("cow_id = ?", item.Cow.Id).
+				Updates(map[string]interface{}{
+					"breed_status":           breedStatus,
+					"last_pregnant_check_at": item.PregnantCheckAt,
+					"is_pregnant":            isPregnant,
+				}).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+
+			if err = tx.Model(new(model.EventMating)).
+				Where("id = (?)", fmt.Sprintf(`
+					SELECT id FROM event_mating where cow_id = %d AND status = %d ORDER BY id DESC LIMIT 1
+				`, item.Cow.Id, pasturePb.IsShow_Ok)).
+				Updates(map[string]interface{}{
+					"mating_result":    breedStatus,
+					"mating_result_at": item.PregnantCheckAt,
+				}).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+
+			// 更新孕检事件表
+			if err = tx.Model(new(model.EventPregnantCheck)).
+				Where("id = ?", item.EventPregnancyCheck.Id).
+				Updates(map[string]interface{}{
+					"reality_day":           item.PregnantCheckAt,
+					"pregnant_check_result": item.PregnantCheckResult,
+					"pregnant_check_method": item.PregnantCheckMethod,
+					"operation_id":          item.OperationUser.Id,
+					"operation_name":        item.OperationUser.Name,
+					"message_id":            currentUser.Id,
+					"message_name":          currentUser.Name,
+					"remarks":               item.Remarks,
+					"status":                pasturePb.IsShow_Ok,
+				}).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
+
+		return nil
+	}); err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}
+
+func (s *StoreEntry) AbortionCreate(ctx context.Context, req *pasturePb.EventAbortionRequest) error {
+	cow, err := s.GetCowInfoByCowId(ctx, int64(req.CowId))
+	if err != nil {
+		return xerr.WithStack(err)
+	}
+
+	systemUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
+	if err != nil {
+		return xerr.WithStack(err)
+	}
+
+	req.OperationName = systemUser.Name
+	abortionReasonsMap := s.AbortionReasonsMap()
+	newEventAbortion := model.NewEventAbortion(cow, req, abortionReasonsMap)
+
+	lastCowMating := &model.EventMating{}
+	if err = s.DB.Model(new(model.EventMating)).Where("cow_id = ?", cow.Id).
+		Where("mating_result = ?", pasturePb.MatingResult_Pregnant).
+		Order("id desc").First(lastCowMating).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+
+	if err = s.DB.Transaction(func(tx *gorm.DB) error {
+		// 创建牛只流产事件数据
+		if err = tx.Create(newEventAbortion).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+		// 更新牛只状态
+		if err = tx.Model(new(model.Cow)).Where("id = ?", req.CowId).
+			Updates(map[string]interface{}{
+				"is_pregnant":      pasturePb.IsShow_No,
+				"last_abortion_at": req.AbortionAt,
+				"breed_status":     pasturePb.BreedStatus_Abort,
+			}).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+
+		// 更新最近一次配种结果为流产
+		if err = tx.Model(new(model.EventMating)).
+			Where("id = ?", lastCowMating.Id).
+			Updates(map[string]interface{}{
+				"mating_result":    pasturePb.MatingResult_Abort,
+				"mating_result_at": req.AbortionAt,
+			}).Error; err != nil {
+		}
+		return nil
+	}); err != nil {
+		return xerr.WithStack(err)
+	}
+
+	return nil
+}
+
+func (s *StoreEntry) AbortionCreateBatch(ctx context.Context, req *pasturePb.EventAbortionBatch) error {
+	if len(req.Item) <= 0 {
+		return xerr.WithStack(xerr.New("流产数据不能为空"))
+	}
+	errors := make(map[int32]error)
+	for _, v := range req.Item {
+		if err := s.AbortionCreate(ctx, v); err != nil {
+			errors[v.CowId] = err
+		}
+	}
+
+	if len(errors) > 0 {
+		b, _ := json.Marshal(errors)
+		return xerr.WithStack(xerr.Customf("部分流产数据创建失败: %s", string(b)))
+	}
+	return nil
+}
+
+func (s *StoreEntry) AbortionList(
+	ctx context.Context,
+	req *pasturePb.SearchEventRequest,
+	pagination *pasturePb.PaginationModel,
+) (*pasturePb.EventAbortionResponse, error) {
+	abortionList := make([]*model.EventAbortion, 0)
+	var count int64 = 0
+	pref := s.DB.Model(new(model.EventAbortion))
+	if len(req.CowId) > 0 {
+		cowIds := strings.Split(req.CowId, ",")
+		pref.Where("cow_id IN ?", cowIds)
+	}
+
+	if err := pref.Order("id desc").
+		Count(&count).Limit(int(pagination.PageSize)).
+		Offset(int(pagination.PageOffset)).
+		Find(&abortionList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	return &pasturePb.EventAbortionResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.EventAbortionData{
+			List:     model.AbortionSlice(abortionList).ToPB(),
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}

+ 43 - 32
module/backend/event_check.go

@@ -8,13 +8,32 @@ import (
 	"gitee.com/xuyiping_admin/pkg/xerr"
 )
 
-type EventCheckModel struct {
+// EventCheckBatchModel 批量事件
+type EventCheckBatchModel struct {
 	CowList       []*model.Cow
 	CurrentUser   *model.SystemUser
 	OperationUser *model.SystemUser
 }
 
-func (s *StoreEntry) MatingCreateCheck(ctx context.Context, req *pasturePb.EventMating) (*EventCheckModel, error) {
+// PregnantCheckBatchModel 批量孕检
+type PregnantCheckBatchModel struct {
+	EventPregnancyCheck *model.EventPregnantCheck
+	Cow                 *model.Cow
+	OperationUser       *model.SystemUser
+	PregnantCheckAt     int32                              // 孕检日期
+	PregnantCheckResult pasturePb.PregnantCheckResult_Kind // 孕检结果
+	PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind // 孕检方式
+	Remarks             string
+}
+
+// MatingTimes 更新配次
+type MatingTimes struct {
+	Mt            int32
+	CowId         int64
+	EventMatingId int64
+}
+
+func (s *StoreEntry) MatingCreateCheck(ctx context.Context, req *pasturePb.EventMating) (*EventCheckBatchModel, error) {
 	if len(req.CowIds) <= 0 {
 		return nil, xerr.Custom("请选择相关牛只")
 	}
@@ -58,51 +77,43 @@ func (s *StoreEntry) MatingCreateCheck(ctx context.Context, req *pasturePb.Event
 			return nil, xerr.Customf("牛只: %d,当前状态为: %s,不能进行配种", cow.Id, cow.BreedStatus.String())
 		}
 	}
-	return &EventCheckModel{
+	return &EventCheckBatchModel{
 		CowList:       cowList,
 		CurrentUser:   currentUser,
 		OperationUser: operationUser,
 	}, nil
 }
 
-func (s *StoreEntry) PregnantCheckCreateCheck(ctx context.Context, req *pasturePb.EventPregnantCheck) (*EventCheckModel, error) {
-	if len(req.CowId) <= 0 {
+func (s *StoreEntry) PregnantCheckCreateCheck(ctx context.Context, req *pasturePb.EventPregnantCheckBatch) ([]*PregnantCheckBatchModel, error) {
+	if len(req.Item) <= 0 {
 		return nil, xerr.Custom("请选择相关牛只")
 	}
 
-	operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
-	if err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	currentUser, err := s.GetCurrentSystemUser(ctx)
-	if err != nil {
-		return nil, xerr.Customf("获取当前用户失败: %s", err.Error())
-	}
-
-	cowList, err := s.ParseCowIds(ctx, req.CowId)
-	if err != nil {
-		return nil, xerr.WithStack(err)
-	}
+	pregnantCheckBatchModelList := make([]*PregnantCheckBatchModel, 0)
+	for _, pregnantCheckData := range req.Item {
+		operationUser, err := s.GetSystemUserById(ctx, int64(pregnantCheckData.OperationId))
+		if err != nil {
+			return nil, xerr.WithStack(err)
+		}
+		cow, err := s.GetCowInfoByCowId(ctx, int64(pregnantCheckData.CowId))
+		if err != nil {
+			return nil, xerr.WithStack(err)
+		}
 
-	for _, cow := range cowList {
 		// 过滤掉没有配种状态的牛只
 		if cow.BreedStatus != pasturePb.BreedStatus_Breeding {
 			return nil, xerr.Customf("牛只: %d,当前状态为: %s,不能进行孕检", cow.Id, cow.BreedStatus.String())
 		}
 
-		if int64(req.PregnantCheckAt) < cow.LastMatingAt {
-			return nil, xerr.Customf("牛只: %d,最近一次配种时间: %d,不能小于本次孕检时间: %d", cow.Id, req.PregnantCheckAt)
-		}
-
-		if int64(req.PregnantCheckAt) < cow.LastCalvingAt {
-			return nil, xerr.Customf("牛只: %d,最近一次产犊时间: %d,不能小于本次孕检时间: %d", cow.Id, cow.LastCalvingAt, req.PregnantCheckAt)
-		}
+		pregnantCheckBatchModelList = append(pregnantCheckBatchModelList, &PregnantCheckBatchModel{
+			Cow:                 cow,
+			OperationUser:       operationUser,
+			PregnantCheckAt:     pregnantCheckData.PregnantCheckAt,
+			PregnantCheckMethod: pregnantCheckData.PregnantCheckMethod,
+			PregnantCheckResult: pregnantCheckData.PregnantCheckResult,
+			Remarks:             pregnantCheckData.Remarks,
+		})
 	}
 
-	return &EventCheckModel{
-		CowList:       cowList,
-		CurrentUser:   currentUser,
-		OperationUser: operationUser,
-	}, nil
+	return pregnantCheckBatchModelList, nil
 }

+ 2 - 2
module/backend/interface.go

@@ -162,7 +162,7 @@ type EventService interface {
 	CalvingCreate(ctx context.Context, req *pasturePb.EventCalving) error
 	// PregnantCheckList 孕检
 	PregnantCheckList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnantCheckEventResponse, error)
-	PregnantCheckCreate(ctx context.Context, req *pasturePb.EventPregnantCheck) error
+	PregnantCheckCreateBatch(ctx context.Context, req *pasturePb.EventPregnantCheckBatch) error
 	// MatingList 配种
 	MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingEventResponse, error)
 	MatingCreate(ctx context.Context, req *pasturePb.EventMating) error
@@ -172,7 +172,7 @@ type EventService interface {
 	// AbortionList 流产
 	AbortionList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventAbortionResponse, error)
 	AbortionCreate(ctx context.Context, req *pasturePb.EventAbortionRequest) error
-	AbortionCreateSlice(ctx context.Context, req *pasturePb.EventAbortionSlice) error
+	AbortionCreateBatch(ctx context.Context, req *pasturePb.EventAbortionBatch) error
 	// SameTimeCreate 同期
 	SameTimeCreate(ctx context.Context, req *pasturePb.EventSameTime) error
 	SameTimeList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchSameTimeResponse, error)

+ 18 - 0
module/backend/sql.go

@@ -329,3 +329,21 @@ func (s *StoreEntry) GetEventMatingIsExIstByCowId(
 	}
 	return newEventMating, nil
 }
+
+func (s *StoreEntry) GetEventPregnantCheckIsExIstByCowId(
+	ctx context.Context,
+	cow *model.Cow,
+) (*model.EventPregnantCheck, error) {
+	newEventPregnantCheck := &model.EventPregnantCheck{}
+	if err := s.DB.Model(new(model.EventMating)).
+		Where("cow_id = ?", cow.Id).
+		Where("lact = ?", cow.Lact).
+		Where("status = ?", pasturePb.IsShow_No).
+		Order("id desc").
+		First(newEventPregnantCheck).Error; err != nil {
+		if !errors.Is(err, gorm.ErrRecordNotFound) {
+			return nil, xerr.WithStack(err)
+		}
+	}
+	return newEventPregnantCheck, nil
+}