Parcourir la source

calving: 留养犊牛

ping il y a 10 mois
Parent
commit
cf03ae8be7

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240521091607-ad013b639fe0
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240522153423-c5213c1ab719
 	gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/getsentry/sentry-go v0.23.0

+ 4 - 0
go.sum

@@ -46,6 +46,10 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240521083839-0e1283556e66 h1:5ZWXi7XV
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240521083839-0e1283556e66/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240521091607-ad013b639fe0 h1:bfdyAcAfrWDcRJYp3Ym7NPeoLwLPUAestp5YL74Hvbo=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240521091607-ad013b639fe0/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240522132434-29109fbe0da6 h1:dITVurOHAMEjbvm430iEw/1WT0TayCxchYNSt5QTjVI=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240522132434-29109fbe0da6/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240522153423-c5213c1ab719 h1:v3a2H1upuU+UNWeIsgkIHpeCkL7Xze69ZO9ldhmaBOk=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240522153423-c5213c1ab719/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015 h1:dfb5dRd57L2HKjdwLT93UFmPYFPOmEl56gtZmqcNnaE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015/go.mod h1:Fk4GYI/v0IK3XFrm1Gn+VkgCz5Y7mfswD5hsTJYOG6A=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 7 - 1
http/handler/config/config.go

@@ -21,7 +21,13 @@ func BarnTypeOptions(c *gin.Context) {
 }
 
 func BarnListOptions(c *gin.Context) {
-	res, err := middleware.Dependency(c).StoreEventHub.OpsService.BarnListOptions(c)
+	penTypeStr := c.Query("pen_type")
+	penTypeId, _ := strconv.Atoi(penTypeStr)
+	if err := valid.Validate(penTypeId, valid.Required, valid.Min(-1)); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.BarnListOptions(c, penTypeId)
 	if err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return

+ 1 - 1
model/barn.go

@@ -45,7 +45,7 @@ func (p PenSlice) ToPB(configBarnTypes []*ConfigPenType) []*pasturePb.SearchBarn
 			Name:              v.Name,
 			IsShow:            v.IsShow,
 			Remarks:           v.Remarks,
-			BarnTypeId:        int32(v.PenType),
+			BarnTypeId:        v.PenType,
 			BarnTypeName:      barnTypeName,
 			Lengths:           v.Lengths,
 			Widths:            v.Widths,

+ 22 - 4
model/cow.go

@@ -21,8 +21,8 @@ type Cow struct {
 	BirthWeight         int64                  `json:"birth_weight"`
 	CurrentWeight       int64                  `json:"current_weight"`
 	SourceId            int32                  `json:"source_id"`
-	FatherId            int32                  `json:"father_id"`
-	MotherId            int32                  `json:"mother_id"`
+	FatherId            int64                  `json:"father_id"`
+	MotherId            int64                  `json:"mother_id"`
 	IsRemove            pasturePb.IsShow_Kind  `json:"is_remove"`
 	IsPregnant          pasturePb.IsShow_Kind  `json:"is_pregnant"`
 	Status              int32                  `json:"status"`
@@ -63,8 +63,8 @@ func NewCow(req *pasturePb.SearchEnterData) *Cow {
 		BreedStatusId:       req.BreedStatusId,
 		KindId:              req.CowKindId,
 		SourceId:            req.CowSourceId,
-		FatherId:            req.FatherId,
-		MotherId:            req.MotherId,
+		FatherId:            int64(req.FatherId),
+		MotherId:            int64(req.MotherId),
 		IsRemove:            pasturePb.IsShow_Ok,
 		IsPregnant:          isPregnant,
 		Status:              status,
@@ -76,6 +76,24 @@ func NewCow(req *pasturePb.SearchEnterData) *Cow {
 	}
 }
 
+func NewCalfCow(motherId, fatherId int64, calf *EventCalvingCalf) *Cow {
+	return &Cow{
+		Sex:           calf.Sex,
+		EarNumber:     calf.EarNumber,
+		PenId:         int64(calf.PenId),
+		TypeId:        6, // 哺乳犊牛 todo 改成enum
+		BreedStatusId: 1, // 未配  todo 改成enum
+		KindId:        1, // 荷斯坦 todo 改成enum
+		BirthWeight:   calf.Weight,
+		SourceId:      2, // 产犊方式 todo 改成enum
+		FatherId:      fatherId,
+		MotherId:      motherId,
+		IsRemove:      pasturePb.IsShow_Ok,
+		IsPregnant:    pasturePb.IsShow_No,
+		Status:        6, // 哺乳犊牛  todo 改成enum
+	}
+}
+
 func (c *Cow) GetDayAge() int32 {
 	return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
 }

+ 44 - 45
model/event_calving.go

@@ -3,22 +3,22 @@ package model
 import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
 type EventCalving struct {
-	Id                   int64                       `json:"int_64"`
-	CowId                int64                       `json:"cow_id"`
-	EarNumber            string                      `json:"ear_number"`
-	Lact                 int32                       `json:"lact"`
-	DayAge               int32                       `json:"day_age"`
-	PenId                int32                       `json:"pen_id"`
-	CalvingAt            int64                       `json:"calving_at"`
-	ChildNumber          int8                        `json:"child_number"`
-	BullId               int64                       `json:"bull_id"`
-	DaysPregnant         int32                       `json:"days_pregnant"`
-	CalvingLevel         pasturePb.CalvingLevel_Kind `json:"calving_level"`
-	IsInducingChildbirth pasturePb.IsShow_Kind       `json:"is_inducing_childbirth"`
-	StaffMemberId        int64                       `json:"staff_member_id"`
-	Remarks              string                      `json:"remarks"`
-	CreatedAt            int64                       `json:"created_at"`
-	UpdatedAt            int64                       `json:"updated_at"`
+	Id             int64                         `json:"int_64"`
+	CowId          int64                         `json:"cow_id"`
+	EarNumber      string                        `json:"ear_number"`
+	Lact           int32                         `json:"lact"`
+	DayAge         int32                         `json:"day_age"`
+	PenId          int32                         `json:"pen_id"`
+	CalvingAt      int64                         `json:"calving_at"`
+	ChildNumber    int8                          `json:"child_number"`
+	BullId         int64                         `json:"bull_id"`
+	DaysPregnant   int32                         `json:"days_pregnant"`
+	CalvingLevel   pasturePb.CalvingLevel_Kind   `json:"calving_level"`
+	StaffMemberId  int64                         `json:"staff_member_id"`
+	DystociaReason pasturePb.DystociaReason_Kind `json:"dystocia_reason"`
+	Remarks        string                        `json:"remarks"`
+	CreatedAt      int64                         `json:"created_at"`
+	UpdatedAt      int64                         `json:"updated_at"`
 }
 
 func (e *EventCalving) TableName() string {
@@ -27,19 +27,19 @@ func (e *EventCalving) TableName() string {
 
 func NewEventCalving(cow *Cow, req *pasturePb.CalvingEventRequest) *EventCalving {
 	return &EventCalving{
-		CowId:                cow.Id,
-		EarNumber:            cow.EarNumber,
-		Lact:                 cow.Lact,
-		DayAge:               cow.GetDayAge(),
-		PenId:                int32(cow.PenId),
-		CalvingAt:            int64(req.CalvingAt),
-		BullId:               cow.LastBullId,
-		CalvingLevel:         req.CalvingLevel,
-		DaysPregnant:         cow.GetDaysPregnant(),
-		ChildNumber:          int8(req.ChildNumber),
-		IsInducingChildbirth: req.IsInducingChildbirth,
-		Remarks:              req.Remarks,
-		StaffMemberId:        int64(req.StaffMemberId),
+		CowId:          cow.Id,
+		EarNumber:      cow.EarNumber,
+		Lact:           cow.Lact,
+		DayAge:         cow.GetDayAge(),
+		PenId:          int32(cow.PenId),
+		CalvingAt:      int64(req.CalvingAt),
+		BullId:         cow.LastBullId,
+		CalvingLevel:   req.CalvingLevel,
+		DystociaReason: req.DystociaReason,
+		DaysPregnant:   cow.GetDaysPregnant(),
+		ChildNumber:    int8(req.ChildNumber),
+		Remarks:        req.Remarks,
+		StaffMemberId:  int64(req.StaffMemberId),
 	}
 }
 
@@ -73,22 +73,21 @@ func (e EventCalvingListSlice) ToPB(req []*EventCalvingCalf) []*pasturePb.Search
 			})
 		}
 		list = append(list, &pasturePb.SearchLavingList{
-			Id:                   int32(item.Id),
-			CowId:                int32(item.CowId),
-			Lact:                 item.Lact,
-			PenId:                item.PenId,
-			PenName:              item.PenName,
-			CalvingAt:            int32(item.CalvingAt),
-			ChildNumber:          int32(item.ChildNumber),
-			DaysPregnant:         item.DaysPregnant,
-			IsInducingChildbirth: item.IsInducingChildbirth,
-			StaffMemberId:        int32(item.StaffMemberId),
-			StaffMemberName:      item.StaffMemberName,
-			CalvingLevel:         item.CalvingLevel,
-			Remarks:              item.Remarks,
-			CreatedAt:            int32(item.CreatedAt),
-			UpdatedAt:            int32(item.UpdatedAt),
-			CalfItemList:         CalfItemList,
+			Id:              int32(item.Id),
+			CowId:           int32(item.CowId),
+			Lact:            item.Lact,
+			PenId:           item.PenId,
+			PenName:         item.PenName,
+			CalvingAt:       int32(item.CalvingAt),
+			ChildNumber:     int32(item.ChildNumber),
+			DaysPregnant:    item.DaysPregnant,
+			StaffMemberId:   int32(item.StaffMemberId),
+			StaffMemberName: item.StaffMemberName,
+			CalvingLevel:    item.CalvingLevel,
+			Remarks:         item.Remarks,
+			CreatedAt:       int32(item.CreatedAt),
+			UpdatedAt:       int32(item.UpdatedAt),
+			CalfItemList:    CalfItemList,
 		})
 	}
 	return list

+ 8 - 5
model/event_calving_calf.go

@@ -12,7 +12,7 @@ type EventCalvingCalf struct {
 	Weight     int64                  `json:"weight"`
 	IsLive     pasturePb.IsShow_Kind  `json:"is_live"`
 	IsAdoption pasturePb.IsShow_Kind  `json:"is_adoption"`
-	PenId      int64                  `json:"pen_id"`
+	PenId      int32                  `json:"pen_id"`
 	Remarks    string                 `json:"remarks"`
 	CreatedAt  int64                  `json:"created_at"`
 	UpdatedAt  int64                  `json:"updated_at"`
@@ -25,16 +25,19 @@ func (e *EventCalvingCalf) TableName() string {
 func NewEventCalvingCalf(motherId, calvingId int64, req *pasturePb.CalvingEventRequest) []*EventCalvingCalf {
 	calvingCalfList := make([]*EventCalvingCalf, 0)
 	for _, v := range req.CalfItemList {
+		isAdoption := v.IsAdoption
+		if v.IsLive == pasturePb.IsShow_No {
+			isAdoption = pasturePb.IsShow_No
+		}
 		calvingCalfList = append(calvingCalfList, &EventCalvingCalf{
-			CowId:      0,  // TODO: cowId
-			EarNumber:  "", // TODO: 耳号
+			EarNumber:  v.EarNumber,
 			CalvingId:  calvingId,
-			PenId:      0, // TODO:  penId
+			PenId:      v.PenId,
 			Weight:     int64(v.Weight * 100),
 			Sex:        v.Sex,
 			MotherId:   motherId,
 			Remarks:    v.Remarks,
-			IsAdoption: v.IsAdoption,
+			IsAdoption: isAdoption,
 			IsLive:     v.IsLive,
 		})
 	}

+ 33 - 5
module/backend/config_data.go

@@ -23,10 +23,11 @@ func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOpti
 	}, nil
 }
 
-func (s *StoreEntry) BarnListOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
+func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int) (*pasturePb.ConfigOptionsListResponse, error) {
 	penList := make([]*model.Pen, 0)
 	if err := s.DB.Table(new(model.Pen).TableName()).
 		Where("is_delete = ?", pasturePb.IsShow_Ok).
+		Where("pen_type = ?", penType).
 		Find(&penList).Error; err != nil {
 		return nil, err
 	}
@@ -160,12 +161,39 @@ func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName st
 				Label:    "自然分娩",
 				Disabled: true,
 			}, &pasturePb.ConfigOptionsList{
-				Value:    int32(pasturePb.CalvingLevel_Artificial_Midwifery_UnUse),
-				Label:    "人工助产-未使用医疗器械",
+				Value:    int32(pasturePb.CalvingLevel_Artificial_Midwifery1),
+				Label:    "人工助产(1-2人)",
 				Disabled: true,
 			}, &pasturePb.ConfigOptionsList{
-				Value:    int32(pasturePb.CalvingLevel_Artificial_Midwifery_Use),
-				Label:    "人工助产-使用医疗器械",
+				Value:    int32(pasturePb.CalvingLevel_Artificial_Midwifery2),
+				Label:    "人工助产(3人以上)",
+				Disabled: true,
+			}, &pasturePb.ConfigOptionsList{
+				Value:    int32(pasturePb.CalvingLevel_Caesarean),
+				Label:    "剖腹产",
+				Disabled: true,
+			})
+	case "dystociaReason":
+		configOptions = append(configOptions,
+			&pasturePb.ConfigOptionsList{
+				Value:    int32(pasturePb.DystociaReason_Malposition),
+				Label:    "胎位不正",
+				Disabled: true,
+			}, &pasturePb.ConfigOptionsList{
+				Value:    int32(pasturePb.DystociaReason_Fetal_Overgrowth),
+				Label:    "胎儿过大",
+				Disabled: true,
+			}, &pasturePb.ConfigOptionsList{
+				Value:    int32(pasturePb.DystociaReason_Uterine_Atony),
+				Label:    "子宫收缩无力",
+				Disabled: true,
+			}, &pasturePb.ConfigOptionsList{
+				Value:    int32(pasturePb.DystociaReason_Pelvic_Stenosis),
+				Label:    "盆骨狭小",
+				Disabled: true,
+			}, &pasturePb.ConfigOptionsList{
+				Value:    int32(pasturePb.DystociaReason_Sub_Health),
+				Label:    "母牛亚健康状态",
 				Disabled: true,
 			})
 	}

+ 14 - 0
module/backend/event.go

@@ -286,14 +286,28 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.CalvingEv
 		return xerr.WithStack(err)
 	}
 	if err = s.DB.Transaction(func(tx *gorm.DB) error {
+		// 母牛信息
 		newCalving := model.NewEventCalving(cow, req)
 		if err = tx.Create(newCalving).Error; err != nil {
 			return xerr.WithStack(err)
 		}
+		// 犊牛信息
 		newCalvingCalfList := model.NewEventCalvingCalf(cow.Id, newCalving.Id, req)
+		for _, v := range newCalvingCalfList {
+			if v.IsLive == pasturePb.IsShow_No || v.IsAdoption == pasturePb.IsShow_No {
+				continue
+			}
+			// 留养犊牛
+			newCow := model.NewCalfCow(cow.Id, cow.LastBullId, v)
+			if err = tx.Create(newCow).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+			v.CowId = newCow.Id
+		}
 		if err = tx.Create(newCalvingCalfList).Error; err != nil {
 			return xerr.WithStack(err)
 		}
+
 		return nil
 	}); err != nil {
 		return xerr.WithStack(err)

+ 1 - 1
module/backend/interface.go

@@ -109,7 +109,7 @@ type PastureManageService interface {
 //go:generate mockgen -destination mock/ConfigDataService.go -package kptservicemock kpt-pasture/module/backend ConfigDataService
 type ConfigDataService interface {
 	BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
-	BarnListOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
+	BarnListOptions(ctx context.Context, penType int) (*pasturePb.ConfigOptionsListResponse, error)
 	BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)

+ 1 - 1
module/backend/pasture_manage.go

@@ -59,7 +59,7 @@ func (s *StoreEntry) CreateOrUpdateBarn(ctx context.Context, req *pasturePb.Sear
 	}).Assign(map[string]interface{}{
 		"name":               req.Name,
 		"remarks":            req.Remarks,
-		"barn_type":          req.BarnTypeId,
+		"pen_type":           req.BarnTypeId,
 		"lengths":            req.Lengths,
 		"widths":             req.Widths,
 		"doctrinal_capacity": req.DoctrinalCapacity,