Yi 1 tydzień temu
rodzic
commit
3ad3ae3ffb

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250407033055-a88907fe2237
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250407091052-1c45232ed0aa
 	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

@@ -124,6 +124,12 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250407031505-811f84cb2ef7 h1:pzfT/1Fw
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250407031505-811f84cb2ef7/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250407033055-a88907fe2237 h1:MrPG3W7f/Mbb7x3JpNnngDgHr/YQD6OOuGAyX3tqXyg=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250407033055-a88907fe2237/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250407062358-b0e1d2556279 h1:x8G2ihVpIzP8hclf9Fihwz7hQoscYvm+Tp3tpMUj830=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250407062358-b0e1d2556279/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250407062707-261478382cce h1:ho0ZTyNjnd5uGgB9YCGifW2SDGYWGOjipsWOhk2LM3o=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250407062707-261478382cce/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250407091052-1c45232ed0aa h1:JK8PEgl8XDRKeM59OCGR/KcEqn/8vqREYUyIQcqseyE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250407091052-1c45232ed0aa/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=

+ 9 - 9
http/handler/event/event_base.go

@@ -230,22 +230,22 @@ func WeightBatch(c *gin.Context) {
 	})
 }
 
-func Departure(c *gin.Context) {
-	var req pasturePb.EventDepartureBatch
+func Death(c *gin.Context) {
+	var req pasturePb.EventDeathBatch
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
 	if err := valid.ValidateStruct(&req,
-		valid.Field(&req.Item, valid.Required, valid.Each(valid.By(func(value interface{}) error {
-			s := value.(pasturePb.EventDeparture)
+		valid.Field(&req.Items, valid.Required, valid.Each(valid.By(func(value interface{}) error {
+			s := value.(pasturePb.EventDeath)
 			return valid.ValidateStruct(&s,
-				valid.Field(&s.DepartureAt, valid.Required),
-				valid.Field(&s.DepartureType, valid.Required),
-				valid.Field(&s.DepartureReasonKind, valid.Required),
+				valid.Field(&s.DeathAt, valid.Required),
+				valid.Field(&s.EarNumber, valid.Required),
+				valid.Field(&s.DeathDestinationKind, valid.Required),
 				valid.Field(&s.OperationId, valid.Required),
-				valid.Field(&s.CowId, valid.Required),
+				valid.Field(&s.DeathReasonKind, valid.Required),
 			)
 		}))),
 	); err != nil {
@@ -253,7 +253,7 @@ func Departure(c *gin.Context) {
 		return
 	}
 
-	if err := middleware.BackendOperation(c).OpsService.DepartureBatch(c, &req); err != nil {
+	if err := middleware.BackendOperation(c).OpsService.DeathBatch(c, &req); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return
 	}

+ 2 - 2
http/route/event_api.go

@@ -57,8 +57,8 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		eventRoute.POST("/disease/treatment/details", event.CowDiseaseTreatmentDetail)
 		// 批量治愈
 		eventRoute.POST("/disease/curable/batch", event.CowDiseaseCurable)
-		// 离场(死亡淘汰)
-		eventRoute.POST("/departure/batch", event.Departure)
+		// 死亡
+		eventRoute.POST("/death/batch", event.Death)
 		// 更换耳标号
 		eventRoute.PUT("/cow/ear/number", event.CowEarNumber)
 		// 牛只销售

+ 5 - 12
model/cow.go

@@ -147,18 +147,11 @@ func (c *Cow) EventEarNumberUpdate(newEarNumber string) {
 	c.EarNumber = newEarNumber
 }
 
-// EventDepartureUpdate 更新牛只离场信息
-func (c *Cow) EventDepartureUpdate(departureAt int64, departureType pasturePb.DepartureType_Kind) {
-	if departureType == pasturePb.DepartureType_Death {
-		c.AdmissionStatus = pasturePb.AdmissionStatus_Die
-		c.HealthStatus = pasturePb.HealthStatus_Dead
-	}
-
-	if departureType == pasturePb.DepartureType_Out {
-		c.AdmissionStatus = pasturePb.AdmissionStatus_Out
-		c.HealthStatus = pasturePb.HealthStatus_Out
-	}
-	c.DepartureAt = departureAt
+// EventDeathUpdate 更新牛只死亡信息
+func (c *Cow) EventDeathUpdate(eventAt int64) {
+	c.AdmissionStatus = pasturePb.AdmissionStatus_Die
+	c.HealthStatus = pasturePb.HealthStatus_Dead
+	c.DepartureAt = eventAt
 }
 
 // EventMatingUpdate 配种更新

+ 58 - 0
model/event_death.go

@@ -0,0 +1,58 @@
+package model
+
+import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+
+type EventDeath struct {
+	Id                   int64                           `json:"id"`
+	PastureId            int64                           `json:"pastureId"`
+	EarNumber            string                          `json:"earNumber"`
+	CowId                int64                           `json:"cowId"`
+	Lact                 int32                           `json:"lact"`
+	DayAge               int32                           `json:"dayAge"`
+	PregnancyAge         int32                           `json:"pregnancyAge"`
+	CalvingAge           int32                           `json:"calvingAge"`
+	AdmissionAge         int32                           `json:"admissionAge"`
+	DeathReasonKind      pasturePb.DeathReason_Kind      `json:"deathReasonKind"`
+	DeathReasonName      string                          `json:"deathReasonName"`
+	DeathDestinationKind pasturePb.DeathDestination_Kind `json:"deathDestinationKind"`
+	DeathDestinationName string                          `json:"deathDestinationName"`
+	DeathAt              int64                           `json:"deathAt"`
+	Remarks              string                          `json:"remarks"`
+	Weight               int32                           `json:"weight"`
+	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 *EventDeath) TableName() string {
+	return "event_death"
+}
+
+func NewEventDeath(pastureId int64, cow *Cow, req *pasturePb.EventDeath, currentUser, operationUser *SystemUser) *EventDeath {
+	return &EventDeath{
+		PastureId:            pastureId,
+		CowId:                cow.Id,
+		EarNumber:            cow.EarNumber,
+		Lact:                 cow.Lact,
+		DayAge:               cow.GetDayAge(),
+		DeathAt:              int64(req.DeathAt),
+		DeathReasonKind:      req.DeathReasonKind,
+		DeathReasonName:      req.DeathReasonName,
+		Remarks:              req.Remarks,
+		Weight:               int32(req.Weight * 1000),
+		DeathDestinationKind: req.DeathDestinationKind,
+		DeathDestinationName: req.DeathDestinationName,
+		OperationId:          operationUser.Id,
+		OperationName:        operationUser.Name,
+		MessageId:            currentUser.Id,
+		MessageName:          currentUser.Name,
+	}
+}
+
+type EventDeathModel struct {
+	Cow        *Cow
+	EventDeath *EventDeath
+}

+ 0 - 51
model/event_departure.go

@@ -1,51 +0,0 @@
-package model
-
-import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
-
-type EventDeparture struct {
-	Id            int64                        `json:"id"`
-	PastureId     int64                        `json:"pastureId"`
-	CowId         int64                        `json:"cowId"`
-	Lact          int32                        `json:"lact"`
-	DayAge        int32                        `json:"dayAge"`
-	DepartureAt   int64                        `json:"departureAt"`
-	DepartureType pasturePb.DepartureType_Kind `json:"departureType"`
-	ReasonId      int32                        `json:"reasonId"`
-	ReasonName    string                       `json:"reasonName"`
-	Remarks       string                       `json:"remarks"`
-	Weight        int32                        `json:"weight"`
-	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 *EventDeparture) TableName() string {
-	return "event_departure"
-}
-
-func NewEventDeparture(pastureId int64, cow *Cow, req *pasturePb.EventDeparture, reasonName string, currentUser, operationUser *SystemUser) *EventDeparture {
-	return &EventDeparture{
-		PastureId:     pastureId,
-		CowId:         cow.Id,
-		Lact:          cow.Lact,
-		DayAge:        cow.GetDayAge(),
-		DepartureAt:   int64(req.DepartureAt),
-		DepartureType: req.DepartureType,
-		ReasonId:      req.DepartureReasonKind,
-		ReasonName:    reasonName,
-		Remarks:       req.Remarks,
-		OperationId:   operationUser.Id,
-		OperationName: operationUser.Name,
-		MessageId:     currentUser.Id,
-		MessageName:   currentUser.Name,
-	}
-}
-
-type EventDepartureModel struct {
-	EventDeparture *EventDeparture
-	Cow            *Cow
-	DepartureAt    int64
-}

+ 88 - 46
module/backend/config_data_base.go

@@ -7,7 +7,7 @@ import (
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
-func (s *StoreEntry) DepartureTypeEnumList(isAll string) []*pasturePb.ConfigOptionsList {
+func (s *StoreEntry) OutReasonEnumList(isAll string) []*pasturePb.ConfigOptionsList {
 	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
 	if isAll == model.IsAllYes {
 		configOptions = append(configOptions,
@@ -18,96 +18,106 @@ func (s *StoreEntry) DepartureTypeEnumList(isAll string) []*pasturePb.ConfigOpti
 			})
 	}
 	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DepartureType_Death),
-		Label:    "死亡",
+		Value:    int32(pasturePb.OutReasons_Respiratory_System_Disease),
+		Label:    "呼吸系统疾病",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DepartureType_Out),
-		Label:    "淘汰",
+		Value:    int32(pasturePb.OutReasons_Nutritional_Metabolic_Disease),
+		Label:    "营养代谢疾病",
 		Disabled: true,
-	})
-	return configOptions
-}
-
-func (s *StoreEntry) OutReasonEnumList(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.OutReason_Long_Term_infertility),
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.OutReasons_Breeding_Disease),
+		Label:    "繁殖疾病",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.OutReasons_Breast_Disease),
+		Label:    "乳房疾病",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.OutReasons_Long_Term_infertility),
 		Label:    "久配不孕",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Multiple_Miscarriages),
+		Value:    int32(pasturePb.OutReasons_Multiple_Miscarriages),
 		Label:    "多次流产",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Long_Treatment_Without_Recovery),
+		Value:    int32(pasturePb.OutReasons_Long_Treatment_Without_Recovery),
 		Label:    "久治不愈",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Postpartum_Paralysis),
+		Value:    int32(pasturePb.OutReasons_Postpartum_Paralysis),
 		Label:    "产后瘫痪",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Mastitis),
+		Value:    int32(pasturePb.OutReasons_Mastitis),
 		Label:    "乳房炎",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Hoof_Disease),
+		Value:    int32(pasturePb.OutReasons_Hoof_Disease),
 		Label:    "蹄病",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Congenital_Malformation),
+		Value:    int32(pasturePb.OutReasons_Congenital_Malformation),
 		Label:    "先天畸形",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Dysplasia),
+		Value:    int32(pasturePb.OutReasons_Congenital_Malformation),
+		Label:    "先天畸形",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.OutReasons_Dysplasia),
 		Label:    "发育不良",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Hernia),
+		Value:    int32(pasturePb.OutReasons_Hernia),
 		Label:    "疝气",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Excessive_Age),
+		Value:    int32(pasturePb.OutReasons_Excessive_Age),
+		Label:    "月龄过大",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.OutReasons_Excessive_Age),
 		Label:    "月龄过大",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Excessive_Weight),
+		Value:    int32(pasturePb.OutReasons_Excessive_Weight),
 		Label:    "体重过肥",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Other_Disease),
+		Value:    int32(pasturePb.OutReasons_Other_Disease),
 		Label:    "其他疾病",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Weak_Child),
+		Value:    int32(pasturePb.OutReasons_Weak_Child),
 		Label:    "弱仔",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Obsessive_Bull),
+		Value:    int32(pasturePb.OutReasons_Obsessive_Bull),
 		Label:    "恶癖牛",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Splitting),
-		Label:    "滑倒卧地不起",
+		Value:    int32(pasturePb.OutReasons_Low_Milk),
+		Label:    "低产",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.OutReason_Other),
+		Value:    int32(pasturePb.OutReasons_Slow_Growing),
+		Label:    "生长缓慢",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.OutReasons_Other),
 		Label:    "其他",
 		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.OutReasons_Unknown),
+		Label:    "未知原因",
+		Disabled: true,
 	})
 	return configOptions
 }
 
-func (s *StoreEntry) DeadReasonEnumList(isAll string) []*pasturePb.ConfigOptionsList {
+func (s *StoreEntry) DeathReasonEnumList(isAll string) []*pasturePb.ConfigOptionsList {
 	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
 	if isAll == model.IsAllYes {
 		configOptions = append(configOptions,
@@ -118,35 +128,67 @@ func (s *StoreEntry) DeadReasonEnumList(isAll string) []*pasturePb.ConfigOptions
 			})
 	}
 	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DeadReason_Digestive_System_Diseases),
+		Value:    int32(pasturePb.DeathReason_Digestive_System_Diseases),
 		Label:    "消化性疾病",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DeadReason_Respiratory_System_Diseases),
+		Value:    int32(pasturePb.DeathReason_Respiratory_System_Diseases),
 		Label:    "呼吸性疾病",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DeadReason_Reproductive_System_Diseases),
+		Value:    int32(pasturePb.DeathReason_Reproductive_System_Diseases),
 		Label:    "繁殖性疾病",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DeadReason_Metabolic_System_Diseases),
+		Value:    int32(pasturePb.DeathReason_Metabolic_System_Diseases),
 		Label:    "代谢性疾病",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DeadReason_Infectious_Diseases),
+		Value:    int32(pasturePb.DeathReason_Infectious_Diseases),
 		Label:    "传染性疾病",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DeadReason_Difficult_Birth),
+		Value:    int32(pasturePb.DeathReason_Difficult_Birth),
 		Label:    "难产",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DeadReason_Accident_Dead),
+		Value:    int32(pasturePb.DeathReason_Accident_Dead),
 		Label:    "意外死亡",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.DeadReason_Other),
+		Value:    int32(pasturePb.DeathReason_Stress),
+		Label:    "应激",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DeathReason_Trauma),
+		Label:    "外伤",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DeathReason_Pneumonia),
+		Label:    "肺炎",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DeathReason_Diarrhea),
+		Label:    "腹泻",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DeathReason_Ketosis),
+		Label:    "酮症",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DeathReason_Acidosis),
+		Label:    "酸中毒",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DeathReason_Rumina_Impaction),
+		Label:    "瘤胃积食",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DeathReason_Intestinal_Torsion),
+		Label:    "肠扭转",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DeathReason_Other),
 		Label:    "其他",
 		Disabled: true,
 	})

+ 7 - 7
module/backend/enum_map.go

@@ -255,18 +255,18 @@ func (s *StoreEntry) DystociaReasonMap() map[pasturePb.DystociaReason_Kind]strin
 	return res
 }
 
-func (s *StoreEntry) DeadReasonMap() map[pasturePb.DeadReason_Kind]string {
-	res := make(map[pasturePb.DeadReason_Kind]string)
-	for _, v := range s.DeadReasonEnumList("") {
-		res[pasturePb.DeadReason_Kind(v.Value)] = v.Label
+func (s *StoreEntry) DeadReasonMap() map[pasturePb.DeathReason_Kind]string {
+	res := make(map[pasturePb.DeathReason_Kind]string)
+	for _, v := range s.DeathReasonEnumList("") {
+		res[pasturePb.DeathReason_Kind(v.Value)] = v.Label
 	}
 	return res
 }
 
-func (s *StoreEntry) OutReasonMap() map[pasturePb.OutReason_Kind]string {
-	res := make(map[pasturePb.OutReason_Kind]string)
+func (s *StoreEntry) OutReasonMap() map[pasturePb.OutReasons_Kind]string {
+	res := make(map[pasturePb.OutReasons_Kind]string)
 	for _, v := range s.OutReasonEnumList("") {
-		res[pasturePb.OutReason_Kind(v.Value)] = v.Label
+		res[pasturePb.OutReasons_Kind(v.Value)] = v.Label
 	}
 	return res
 }

+ 1 - 2
module/backend/enum_options.go

@@ -212,9 +212,8 @@ func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName, i
 		"pregnantCheckName":          s.PregnantCheckNameEnumList,
 		"unMatingReasons":            s.UnMatingReasonsEnumList,
 		"evenType":                   s.EventTypeEnumList,
-		"departureType":              s.DepartureTypeEnumList,
 		"outReason":                  s.OutReasonEnumList,
-		"deadReason":                 s.DeadReasonEnumList,
+		"deathReason":                s.DeathReasonEnumList,
 		"categoryKind":               s.EventCategoryEnumList,
 		"indicatorsDetails":          s.IndicatorsDetailsList,
 		"purposeKind":                s.CowPurposeList,

+ 31 - 43
module/backend/event_base_more.go

@@ -13,73 +13,55 @@ import (
 	"gorm.io/gorm"
 )
 
-func (s *StoreEntry) DepartureBatch(ctx context.Context, req *pasturePb.EventDepartureBatch) (err error) {
-	if len(req.Item) <= 0 {
-		return xerr.Custom("请选择相关牛只")
-	}
-
+func (s *StoreEntry) DeathBatch(ctx context.Context, req *pasturePb.EventDeathBatch) (err error) {
 	userModel, err := s.GetUserModel(ctx)
 	if err != nil {
 		return xerr.WithStack(err)
 	}
 
-	newEventDepartureModelList := make([]*model.EventDepartureModel, 0)
-	cow := &model.Cow{}
-	for _, item := range req.Item {
-		cow, err = s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, int64(item.CowId))
+	if len(req.Items) <= 0 {
+		return xerr.Custom("请选择相关牛只")
+	}
+
+	newEventDeathList := make([]*model.EventDeathModel, 0)
+	for _, item := range req.Items {
+		cow, err := s.GetCowInfoByEarNumber(ctx, userModel.AppPasture.Id, item.EarNumber)
 		if err != nil {
-			zaplog.Error("DepartureBatch", zap.Any("item", item), zap.Any("err", err))
-			return xerr.Customf("获取牛只信息失败: %d", item.CowId)
+			zaplog.Error("DeathBatch", zap.Any("item", item), zap.Any("err", err))
+			return xerr.Customf("获取牛只信息失败: %s", item.EarNumber)
 		}
 
 		operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
 		if err != nil {
-			zaplog.Error("DepartureBatch", zap.Any("item", item), zap.Any("err", err))
+			zaplog.Error("DeathBatch", zap.Any("item", item), zap.Any("err", err))
 			return xerr.Customf("获取操作人员信息失败: %d", item.OperationId)
 		}
-		reasonName := ""
-		switch item.DepartureType {
-		case pasturePb.DepartureType_Death:
-			reasonName = s.DeadReasonMap()[pasturePb.DeadReason_Kind(item.DepartureReasonKind)]
-		case pasturePb.DepartureType_Out:
-			reasonName = s.OutReasonMap()[pasturePb.OutReason_Kind(item.DepartureReasonKind)]
-		default:
-			return xerr.Custom("未知的离场类型")
-		}
-		newEventDeparture := model.NewEventDeparture(userModel.AppPasture.Id, cow, item, reasonName, userModel.SystemUser, operationUser)
-		newEventDepartureModelList = append(newEventDepartureModelList, &model.EventDepartureModel{
-			EventDeparture: newEventDeparture,
-			Cow:            cow,
-			DepartureAt:    int64(item.DepartureAt),
-		})
-	}
 
-	if len(newEventDepartureModelList) <= 0 {
-		return nil
+		newEventDeath := model.NewEventDeath(userModel.AppPasture.Id, cow, item, userModel.SystemUser, operationUser)
+		newEventDeathList = append(newEventDeathList, &model.EventDeathModel{
+			Cow:        cow,
+			EventDeath: newEventDeath,
+		})
 	}
 
 	if err = s.DB.Transaction(func(tx *gorm.DB) error {
 		// 记录事件日志
-		for _, item := range newEventDepartureModelList {
-			eventType := pasturePb.EventType_Death
-			if item.EventDeparture.DepartureType == pasturePb.DepartureType_Out {
-				eventType = pasturePb.EventType_Out
-			}
-
-			if err = tx.Create(item.EventDeparture).Error; err != nil {
+		for _, item := range newEventDeathList {
+			if err = tx.Create(item.EventDeath).Error; err != nil {
 				return xerr.WithStack(err)
 			}
 
-			cow.EventDepartureUpdate(item.DepartureAt, item.EventDeparture.DepartureType)
-			if err = tx.Model(cow).
+			// 更新牛只死亡状态
+			item.Cow.EventDeathUpdate(item.Cow.DepartureAt)
+			if err = tx.Model(new(model.Cow)).
 				Select("admission_status", "health_status", "departure_at").
-				Where("id = ?", cow.Id).
-				Updates(cow).Error; err != nil {
+				Where("id = ?", item.Cow.Id).
+				Updates(item.Cow).Error; err != nil {
 				return xerr.WithStack(err)
 			}
 
 			// 记录事件日志
-			cowLogs := s.SubmitEventLog(ctx, userModel.AppPasture.Id, item.Cow, eventType, item)
+			cowLogs := s.SubmitEventLog(ctx, userModel.AppPasture.Id, item.Cow, pasturePb.EventType_Death, item.EventDeath)
 			if err = tx.Table(cowLogs.TableName()).Create(cowLogs).Error; err != nil {
 				return xerr.WithStack(err)
 			}
@@ -158,7 +140,13 @@ func (s *StoreEntry) CowSaleCreate(ctx context.Context, req *pasturePb.EventCowS
 	newEventSale := model.NewEventSale(userModel.AppPasture.Id, dealerInfo, req, operationUser, userModel.SystemUser)
 	eventCowLogList := make([]*model.EventCowLog, 0)
 	for _, cow := range cowList {
-		newEventCowLog := s.SubmitEventLog(ctx, userModel.AppPasture.Id, cow, pasturePb.EventType_Sale, req)
+		var newEventCowLog *model.EventCowLog
+		if req.SalesType == pasturePb.SalesType_Sales {
+			newEventCowLog = s.SubmitEventLog(ctx, userModel.AppPasture.Id, cow, pasturePb.EventType_Sale, req)
+		}
+		if req.SalesType == pasturePb.SalesType_Out {
+			newEventCowLog = s.SubmitEventLog(ctx, userModel.AppPasture.Id, cow, pasturePb.EventType_Out, req)
+		}
 		eventCowLogList = append(eventCowLogList, newEventCowLog)
 	}
 

+ 7 - 7
module/backend/event_cow_log.go

@@ -128,9 +128,9 @@ func (s *StoreEntry) SubmitEventLog(ctx context.Context, pastureId int64, cow *m
 		eventAt = cow.BirthAt
 		desc = fmt.Sprintf("出生体重: %s KG;母号:%s;父号: %s", strconv.FormatFloat(float64(cow.BirthWeight)/1000, 'f', 2, 64), cow.MotherNumber, cow.FatherNumber)
 	case pasturePb.EventType_Death:
-		data := req.(*model.EventDeparture)
-		eventAt = data.DepartureAt
-		desc = fmt.Sprintf("死亡原因: %s", data.ReasonName)
+		data := req.(*model.EventDeath)
+		eventAt = data.DeathAt
+		desc = fmt.Sprintf("死亡原因: %s", data.DeathReasonName)
 		operationUser.Id = data.OperationId
 		operationUser.Name = data.OperationName
 	case pasturePb.EventType_Dry_Milk:
@@ -139,10 +139,10 @@ func (s *StoreEntry) SubmitEventLog(ctx context.Context, pastureId int64, cow *m
 		operationUser.Id = data.OperationId
 		operationUser.Name = data.OperationName
 	case pasturePb.EventType_Out:
-		data := req.(*model.EventDeparture)
-		eventAt = data.DepartureAt
-		desc = fmt.Sprintf("淘汰原因: %s", data.ReasonName)
-		operationUser.Id = data.OperationId
+		data := req.(*pasturePb.EventCowSale)
+		eventAt = int64(data.SaleAt)
+		desc = fmt.Sprintf("淘汰原因: %s", data.OutReasonsName)
+		operationUser.Id = int64(data.OperationId)
 		operationUser.Name = data.OperationName
 	case pasturePb.EventType_Immunication:
 		data := req.(*model.EventImmunizationPlan)

+ 2 - 2
module/backend/interface.go

@@ -222,8 +222,8 @@ type EventService interface {
 	CowDiseaseTreatmentDetail(ctx context.Context, req *pasturePb.EventCowTreatmentDetailRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowTreatmentDetailResponse, error)
 	// CowDiseaseCurable 治愈
 	CowDiseaseCurable(ctx context.Context, req *pasturePb.EventCowCurableRequest) error
-	// DepartureBatch 离场
-	DepartureBatch(ctx context.Context, req *pasturePb.EventDepartureBatch) error
+	// DeathBatch 死亡
+	DeathBatch(ctx context.Context, req *pasturePb.EventDeathBatch) error
 	// CowEarNumberUpdate 修改耳号
 	CowEarNumberUpdate(ctx context.Context, req *pasturePb.EventReplaceEarNumber) error
 	// SubmitEventLog 记录提交事件结果日志