فهرست منبع

event: 发情和发病优化

Yi 3 ماه پیش
والد
کامیت
cfbece487e

+ 1 - 1
go.mod

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

+ 4 - 0
go.sum

@@ -40,6 +40,10 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20241128102506-727966a0f004 h1:0kHmrqRN
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241128102506-727966a0f004/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241203073346-ba8687d6c8de h1:dIATo9IIIOfcQaSISrclzRF0piVoy7bydeG0psN1Lt0=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241203073346-ba8687d6c8de/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241204014219-67b3a86c6073 h1:9lzMO1lwmQfgGRmpZkTLHjGcmU3hc6+uMOgEuPiyuuo=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241204014219-67b3a86c6073/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241204021755-ac6c028d07a3 h1:05zSqGf+j1PFXULInvcc610amPNWH+CJk9Jd9h/kHhs=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241204021755-ac6c028d07a3/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=

+ 29 - 0
http/handler/event/event_breed.go

@@ -227,6 +227,35 @@ func EstrusCreate(c *gin.Context) {
 		Data: &operationPb.Success{Success: true},
 	})
 }
+
+func EstrusBatch(c *gin.Context) {
+	var req pasturePb.EventEstrusBatch
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.Item, valid.Required, valid.Each(valid.By(func(value interface{}) error {
+			item := value.(pasturePb.EventEstrus)
+			return valid.ValidateStruct(&item,
+				valid.Field(&item.CowId, valid.Required),
+				valid.Field(&item.OperationId, valid.Required),
+				valid.Field(&item.IsMathing, valid.Required),
+				valid.Field(&item.UnMatingReasons, valid.Required),
+			)
+		}))),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.EstrusBatch(c, &req); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}
 func SameTimeCreate(c *gin.Context) {
 	var req pasturePb.EventSameTime
 	if err := ginutil.BindProto(c, &req); err != nil {

+ 1 - 0
http/route/event_api.go

@@ -40,6 +40,7 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		// 发情
 		eventRoute.POST("/estrus/list", event.EstrusEventList)
 		eventRoute.POST("/estrus/create", event.EstrusCreate)
+		eventRoute.POST("/estrus/batch", event.EstrusBatch)
 		// 同期
 		eventRoute.POST("/same/time/list", event.SameTimeList)
 		eventRoute.POST("/same/time/create", event.SameTimeCreate)

+ 0 - 0
http/route/work.go → http/route/work_api.go


+ 44 - 37
model/event_estrus.go

@@ -3,37 +3,42 @@ package model
 import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
 type EventEstrus struct {
-	Id            int64  `json:"id"`
-	CowId         int64  `json:"cowId"`
-	DayAge        int32  `json:"dayAge"`
-	Lact          int8   `json:"lact"`
-	LactationDays int32  `json:"lactationDays"`
-	EstrusAt      int64  `json:"estrusAt"`
-	Remarks       string `json:"remarks"`
-	OperationId   int64  `json:"operationId"`
-	OperationName string `json:"operationName"`
-	MessageId     int64  `json:"messageId"`
-	MessageName   string `json:"messageName"`
-	CreatedAt     int64  `json:"createdAt"`
-	UpdatedAt     int64  `json:"updatedAt"`
+	Id                  int64                          `json:"id"`
+	CowId               int64                          `json:"cowId"`
+	DayAge              int32                          `json:"dayAge"`
+	Lact                int8                           `json:"lact"`
+	LactationDays       int32                          `json:"lactationDays"`
+	EstrusAt            int64                          `json:"estrusAt"`
+	UnMatingReasons     pasturePb.UnMatingReasons_Kind `json:"unMatingReasons"`
+	UnMatingReasonsName string                         `json:"unMatingReasonsName"`
+	IsMating            pasturePb.IsShow_Kind          `json:"isMating"`
+	Remarks             string                         `json:"remarks"`
+	OperationId         int64                          `json:"operationId"`
+	OperationName       string                         `json:"operationName"`
+	MessageId           int64                          `json:"messageId"`
+	MessageName         string                         `json:"messageName"`
+	CreatedAt           int64                          `json:"createdAt"`
+	UpdatedAt           int64                          `json:"updatedAt"`
 }
 
 func (e *EventEstrus) TableName() string {
 	return "event_estrus"
 }
 
-func NewEventEstrus(cow *Cow, currentUser *SystemUser, req *pasturePb.EventEstrus) *EventEstrus {
+func NewEventEstrus(cow *Cow, currentUser *SystemUser, operation *SystemUser, req *pasturePb.EventEstrus) *EventEstrus {
 	return &EventEstrus{
-		CowId:         cow.Id,
-		DayAge:        cow.GetDayAge(),
-		Lact:          int8(cow.Lact),
-		LactationDays: cow.GetLactationDays(),
-		EstrusAt:      int64(req.EstrusAt),
-		Remarks:       req.Remarks,
-		MessageId:     currentUser.Id,
-		MessageName:   currentUser.Name,
-		OperationId:   int64(req.OperationId),
-		OperationName: req.OperationName,
+		CowId:           cow.Id,
+		DayAge:          cow.GetDayAge(),
+		Lact:            int8(cow.Lact),
+		LactationDays:   cow.GetLactationDays(),
+		EstrusAt:        int64(req.EstrusAt),
+		Remarks:         req.Remarks,
+		IsMating:        req.IsMathing,
+		UnMatingReasons: req.UnMatingReasons,
+		MessageId:       currentUser.Id,
+		MessageName:     currentUser.Name,
+		OperationId:     operation.Id,
+		OperationName:   operation.Name,
 	}
 }
 
@@ -43,19 +48,21 @@ func (e EstrusSlice) ToPB() []*pasturePb.SearchEstrusList {
 	res := make([]*pasturePb.SearchEstrusList, len(e))
 	for i, v := range e {
 		res[i] = &pasturePb.SearchEstrusList{
-			Id:            int32(v.Id),
-			CowId:         int32(v.CowId),
-			DayAge:        v.DayAge,
-			Lact:          int32(v.Lact),
-			EstrusAt:      int32(v.EstrusAt),
-			LactationDays: v.LactationDays,
-			MessengerId:   int32(v.MessageId),
-			MessengerName: v.MessageName,
-			Remarks:       v.Remarks,
-			OperationId:   int32(v.OperationId),
-			OperationName: v.OperationName,
-			CreatedAt:     int32(v.CreatedAt),
-			UpdatedAt:     int32(v.UpdatedAt),
+			Id:                  int32(v.Id),
+			CowId:               int32(v.CowId),
+			DayAge:              v.DayAge,
+			Lact:                int32(v.Lact),
+			EstrusAt:            int32(v.EstrusAt),
+			IsMathing:           v.IsMating,
+			UnMatingReasonsName: v.UnMatingReasonsName,
+			LactationDays:       v.LactationDays,
+			MessengerId:         int32(v.MessageId),
+			MessengerName:       v.MessageName,
+			Remarks:             v.Remarks,
+			OperationId:         int32(v.OperationId),
+			OperationName:       v.OperationName,
+			CreatedAt:           int32(v.CreatedAt),
+			UpdatedAt:           int32(v.UpdatedAt),
 		}
 	}
 	return res

+ 34 - 0
module/backend/config_data_other.go

@@ -399,3 +399,37 @@ func (s *StoreEntry) PregnantCheckNameEnumList(isAll string) []*pasturePb.Config
 	})
 	return configOptions
 }
+
+func (s *StoreEntry) UnMatingReasonsEnumList(isAll string) []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	if isAll == model.IsAllYes {
+		configOptions = append(configOptions,
+			&pasturePb.ConfigOptionsList{
+				Value:    int32(0),
+				Label:    "全部",
+				Disabled: true,
+			})
+	}
+	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.UnMatingReasons_Irregular_Estrus),
+		Label:    "不规则发情",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.UnMatingReasons_No_Mating),
+		Label:    "禁配",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.UnMatingReasons_Disease),
+		Label:    "疾病",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.UnMatingReasons_Out),
+		Label:    "淘汰",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.UnMatingReasons_Other),
+		Label:    "其他",
+		Disabled: true,
+	})
+	return configOptions
+}

+ 1 - 0
module/backend/enum_options.go

@@ -193,6 +193,7 @@ func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName, i
 		"outType":                    s.OutTypeEnumList,
 		"auditStatus":                s.AuditStatusEnumList,
 		"pregnantCheckName":          s.PregnantCheckNameEnumList,
+		"unMatingReasons":            s.UnMatingReasonsEnumList,
 	}
 
 	getConfigFunc, ok := getConfigFuncMap[optionsName]

+ 13 - 16
module/backend/event_breed.go

@@ -159,29 +159,26 @@ func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.SearchEventR
 }
 
 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)
+	estrusInfo, err := s.EventEstrusCheck(ctx, req)
 	if err != nil {
 		return xerr.Custom("获取当前登录用户失败")
 	}
+	if err = s.DB.Create(estrusInfo).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}
 
-	for _, cow := range cowList {
-		operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
+func (s *StoreEntry) EstrusBatch(ctx context.Context, req *pasturePb.EventEstrusBatch) error {
+	estrusList := make([]*model.EventEstrus, 0)
+	for _, v := range req.Item {
+		estrusInfo, err := s.EventEstrusCheck(ctx, v)
 		if err != nil {
-			return xerr.WithStack(err)
+			return xerr.Custom("获取当前登录用户失败")
 		}
-		req.OperationName = operationUser.Name
-		estrusList = append(estrusList, model.NewEventEstrus(cow, currentUser, req))
+		estrusList = append(estrusList, estrusInfo)
 	}
-
-	if err = s.DB.Create(estrusList).Error; err != nil {
+	if err := s.DB.Create(estrusList).Error; err != nil {
 		return xerr.WithStack(err)
 	}
 	return nil

+ 1 - 1
module/backend/event_breed_abortion.go

@@ -44,7 +44,7 @@ func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.Searc
 }
 
 func (s *StoreEntry) PregnantCheckCreateBatch(ctx context.Context, req *pasturePb.EventPregnantCheckBatch) error {
-	pregnantCheckBatchModelList, err := s.PregnantCheckCreateCheck(ctx, req)
+	pregnantCheckBatchModelList, err := s.PregnantCheckDataCheck(ctx, req)
 	if err != nil {
 		return xerr.WithStack(err)
 	}

+ 23 - 1
module/backend/event_check.go

@@ -84,7 +84,7 @@ func (s *StoreEntry) MatingCreateCheck(ctx context.Context, req *pasturePb.Event
 	}, nil
 }
 
-func (s *StoreEntry) PregnantCheckCreateCheck(ctx context.Context, req *pasturePb.EventPregnantCheckBatch) ([]*PregnantCheckBatchModel, error) {
+func (s *StoreEntry) PregnantCheckDataCheck(ctx context.Context, req *pasturePb.EventPregnantCheckBatch) ([]*PregnantCheckBatchModel, error) {
 	if len(req.Item) <= 0 {
 		return nil, xerr.Custom("请选择相关牛只")
 	}
@@ -117,3 +117,25 @@ func (s *StoreEntry) PregnantCheckCreateCheck(ctx context.Context, req *pastureP
 
 	return pregnantCheckBatchModelList, nil
 }
+
+func (s *StoreEntry) EventEstrusCheck(ctx context.Context, req *pasturePb.EventEstrus) (*model.EventEstrus, error) {
+	if req.CowId <= 0 {
+		return nil, xerr.Custom("请选择相关牛只")
+	}
+
+	cow, err := s.GetCowInfoByCowId(ctx, int64(req.CowId))
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	currentUser, err := s.GetCurrentSystemUser(ctx)
+	if err != nil {
+		return nil, xerr.Custom("获取当前登录用户失败")
+	}
+
+	operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
+	return model.NewEventEstrus(cow, currentUser, operationUser, req), nil
+}

+ 4 - 0
module/backend/event_health.go

@@ -138,6 +138,10 @@ func (s *StoreEntry) CowDiseaseList(ctx context.Context, req *pasturePb.SearchEv
 		pref.Where("a.health_status = ?", req.HealthStatus)
 	}
 
+	if req.DiseasedStartAt > 0 && req.DiseaseEndAt > 0 && req.DiseaseEndAt >= req.DiseasedStartAt {
+		pref.Where("a.disease_at BETWEEN ? AND ?", req.DiseasedStartAt, req.DiseaseEndAt)
+	}
+
 	if err := pref.Order("a.id desc").
 		Count(&count).Limit(int(pagination.PageSize)).
 		Offset(int(pagination.PageOffset)).

+ 1 - 0
module/backend/interface.go

@@ -169,6 +169,7 @@ type EventService interface {
 	// EstrusList 发情
 	EstrusList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EstrusEventResponse, error)
 	EstrusCreate(ctx context.Context, req *pasturePb.EventEstrus) error
+	EstrusBatch(ctx context.Context, req *pasturePb.EventEstrusBatch) error
 	// AbortionList 流产
 	AbortionList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventAbortionResponse, error)
 	AbortionCreate(ctx context.Context, req *pasturePb.EventAbortionRequest) error