Yi 3 дней назад
Родитель
Сommit
f701df51c9

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250616080546-3ebf4d3f0874
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250623073137-994f2b6ab389
 	gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eclipse/paho.mqtt.golang v1.4.3

+ 6 - 0
go.sum

@@ -38,6 +38,10 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
 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-20250616080546-3ebf4d3f0874 h1:jD/wa9PorrqH0TDiasHboBdLgmlXw1oFOc0Fly7Fw/s=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250616080546-3ebf4d3f0874/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250623070841-590ca50f5b8d h1:wCiJ6yav1+Q182ntip8yXxxzGhqW+KQStlJw1uRfZZY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250623070841-590ca50f5b8d/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250623073137-994f2b6ab389 h1:832/HoapM95MaKgjLpVRALQDnoDzw2XE8hy14Pe6kbo=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250623073137-994f2b6ab389/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0 h1:ZCOqEAnGm6+DTAhACigzWKbwMKtleb8/7OzP2xfHG7g=
 gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@@ -173,6 +177,7 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
 github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
 github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
+github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
 github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
 github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
@@ -611,6 +616,7 @@ go.uber.org/dig v1.15.0/go.mod h1:pKHs0wMynzL6brANhB2hLMro+zalv1osARTviTcqHLM=
 go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI=
 go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
 go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
+go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
 go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
 go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
 go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=

+ 0 - 1
http/handler/event/event_base.go

@@ -53,7 +53,6 @@ func EnterEventCreate(c *gin.Context) {
 		valid.Field(&req.PenId, valid.Required),
 		valid.Field(&req.OperationId, valid.Required),
 		valid.Field(&req.Weight, valid.Required),
-		valid.Field(&req.BatchNumber, valid.Required),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return

+ 1 - 0
model/cow.go

@@ -711,6 +711,7 @@ func NewEnterCow(pastureId int64, req *pasturePb.EventEnterRequest, penMap map[i
 		LastAbortionAt:      int64(req.AbortionAt),
 		AdmissionPrice:      req.Price,
 		BatchNumber:         req.BatchNumber,
+		NeckRingNumber:      req.NeckRingNumber,
 	}
 	cow.AdmissionAge = cow.GetAdmissionAge()
 	cow.DayAge = cow.GetDayAge()

+ 11 - 11
model/event_enter.go

@@ -45,20 +45,20 @@ type EventEnter struct {
 func (e *EventEnter) TableName() string {
 	return "event_enter"
 }
-func NewEventEnter(pastureId, cowId int64, req *pasturePb.EventEnterRequest) *EventEnter {
+func NewEventEnter(pastureId int64, cowInfo *Cow, req *pasturePb.EventEnterRequest) *EventEnter {
 	return &EventEnter{
 		PastureId:        pastureId,
-		EarNumber:        req.EarNumber,
-		CowId:            cowId,
-		Sex:              req.Sex,
-		BirthAt:          int64(req.BirthAt),
-		CowSource:        req.CowSource,
-		CowType:          req.CowType,
-		BreedStatus:      req.BreedStatus,
-		Lact:             req.Lact,
+		EarNumber:        cowInfo.EarNumber,
+		CowId:            cowInfo.Id,
+		Sex:              cowInfo.Sex,
+		BirthAt:          cowInfo.BirthAt,
+		CowSource:        cowInfo.SourceKind,
+		CowType:          cowInfo.CowType,
+		BreedStatus:      cowInfo.BreedStatus,
+		Lact:             cowInfo.Lact,
 		DayAge:           int32(math.Floor(float64(int32(time.Now().Local().Unix())-req.BirthAt) / 86400)),
-		PenId:            req.PenId,
-		CowKind:          req.CowKind,
+		PenId:            cowInfo.PenId,
+		CowKind:          cowInfo.CowKind,
 		FatherNumber:     req.FatherNumber,
 		MotherNumber:     req.MotherNumber,
 		MatingAt:         int64(req.MatingAt),

+ 2 - 0
model/event_weight.go

@@ -8,6 +8,8 @@ import (
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
+const EnterWeigh = "入场体重"
+
 type EventWeight struct {
 	ID            int64  `json:"id"`
 	PastureId     int64  `json:"pastureId"`

+ 4 - 0
model/neck_ring_bind_log.go

@@ -4,6 +4,10 @@ const (
 	OperationNameBind   = "绑定"
 	OperationNameUnbind = "解绑"
 	OperationNameUpdate = "编辑"
+	EventEnterBind      = "入场绑定"
+	EventDieBind        = "死亡解绑"
+	DefaultBind         = "正常绑定"
+	DefaultUnBind       = "正常解绑"
 )
 
 type NeckRingBindLog struct {

+ 4 - 4
module/backend/config_data.go

@@ -126,7 +126,7 @@ func (s *StoreEntry) CowTypeEnumList(optionName, isAll string) []*pasturePb.Conf
 			Disabled: true,
 		}, &pasturePb.ConfigOptionsList{
 			Value:    int32(pasturePb.CowType_Breeding_Calf),
-			Label:    "母牛",
+			Label:    "母牛",
 			Disabled: true,
 		})
 		return cowTypeList
@@ -154,7 +154,7 @@ func (s *StoreEntry) CowTypeEnumList(optionName, isAll string) []*pasturePb.Conf
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.CowType_Breeding_Calf),
-		Label:    "母牛",
+		Label:    "母牛",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.CowType_Breeding_Bull),
@@ -179,7 +179,7 @@ func (s *StoreEntry) SameTimeCowTypeEnumList(isAll string) []*pasturePb.ConfigOp
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.SameTimeCowType_Breeding_Calf),
-		Label:    "母牛",
+		Label:    "母牛",
 		Disabled: true,
 	})
 	return cowTypeList
@@ -238,7 +238,7 @@ func (s *StoreEntry) ImmunizationCowTypeEnumList(isAll string) []*pasturePb.Conf
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.CowType_Breeding_Calf),
-		Label:    "母牛",
+		Label:    "母牛",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.CowType_Breeding_Bull),

+ 30 - 14
module/backend/event_base.go

@@ -93,19 +93,22 @@ func (s *StoreEntry) CreateEnter(ctx context.Context, req *pasturePb.EventEnterR
 		return xerr.WithStack(err)
 	}
 
+	pastureId := userModel.AppPasture.Id
 	req.MessengerId = int32(userModel.SystemUser.Id)
 	req.MessengerName = userModel.SystemUser.Name
-	if req.OperationId > 0 {
-		systemUser, _ := s.GetSystemUserById(ctx, int64(req.OperationId))
-		req.OperationName = systemUser.Name
+
+	operationSystemUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
+	if err != nil {
+		return xerr.WithStack(err)
 	}
+	req.OperationName = operationSystemUser.Name
 
-	penMap := s.PenMap(ctx, userModel.AppPasture.Id)
+	penMap := s.PenMap(ctx, pastureId)
 	if len(penMap) <= 0 {
 		return xerr.Customf("请先设置牛舍信息")
 	}
 
-	newCow := model.NewEnterCow(userModel.AppPasture.Id, req, penMap)
+	newCow := model.NewEnterCow(pastureId, req, penMap)
 	if err = s.DB.Transaction(func(tx *gorm.DB) error {
 		// 新增牛只信息
 		if err = tx.Model(new(model.Cow)).Create(newCow).Error; err != nil {
@@ -113,34 +116,47 @@ func (s *StoreEntry) CreateEnter(ctx context.Context, req *pasturePb.EventEnterR
 		}
 
 		// 新增入场事件
-		newEventEnter := model.NewEventEnter(userModel.AppPasture.Id, newCow.Id, req)
+		newEventEnter := model.NewEventEnter(pastureId, newCow, req)
 		if err = tx.Model(new(model.EventEnter)).Create(newEventEnter).Error; err != nil {
 			return xerr.WithStack(err)
 		}
 
 		// 新增胎次数据
-		newCowLact := model.NewCowLact(userModel.AppPasture.Id, newCow)
+		newCowLact := model.NewCowLact(pastureId, newCow)
 		if err = tx.Model(new(model.CowLact)).Create(newCowLact).Error; err != nil {
 			return xerr.WithStack(err)
 		}
 
-		eventWeight := model.NewEventWeight(
-			userModel.AppPasture.Id,
-			newCow,
-			userModel.SystemUser,
+		eventWeight := model.NewEventWeight(pastureId, newCow, userModel.SystemUser,
 			&pasturePb.EventWeight{
 				WeightAt:      req.EnterAt,
-				Remarks:       "入场体重",
+				Remarks:       model.EnterWeigh,
 				OperationId:   req.OperationId,
 				OperationName: req.OperationName,
 				Weight:        req.Weight,
 			})
-		if err = tx.Model(new(model.EventWeight)).Create(eventWeight).Error; err != nil {
+		if err = tx.Model(new(model.EventWeight)).
+			Create(eventWeight).Error; err != nil {
 			return xerr.WithStack(err)
 		}
 
+		// 脖环绑定
+		if newCow.NeckRingNumber != "" {
+			newCowNeckRing := model.NewNeckRing(pastureId, newCow.NeckRingNumber, newCow, operationSystemUser)
+			if err = tx.Model(new(model.NeckRing)).
+				Create(newCowNeckRing).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+
+			newNeckRingBindLog := model.NewNeckRingBindLog(pastureId, newCow.NeckRingNumber, newCow, userModel.SystemUser, model.EventEnterBind)
+			if err = tx.Model(new(model.NeckRingBindLog)).
+				Create(newNeckRingBindLog).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
+
 		// 记录事件日志
-		cowLogs := s.SubmitEventLog(ctx, userModel.AppPasture.Id, newCow, pasturePb.EventType_Enter, req)
+		cowLogs := s.SubmitEventLog(ctx, pastureId, newCow, pasturePb.EventType_Enter, req)
 		if err = tx.Table(cowLogs.TableName()).Create(cowLogs).Error; err != nil {
 			return xerr.WithStack(err)
 		}

+ 1 - 1
module/backend/event_base_more.go

@@ -297,7 +297,7 @@ func (s *StoreEntry) CowSaleCreate(ctx context.Context, req *pasturePb.EventCowS
 					Updates(neckRing).Error; err != nil {
 					return xerr.WithStack(err)
 				}
-				newNeckRingBindLog := model.NewNeckRingBindLog(userModel.AppPasture.Id, neckRing.NeckRingNumber, cowInfo, userModel.SystemUser, "死亡解绑")
+				newNeckRingBindLog := model.NewNeckRingBindLog(userModel.AppPasture.Id, neckRing.NeckRingNumber, cowInfo, userModel.SystemUser, model.EventDieBind)
 				if err = tx.Model(new(model.NeckRingBindLog)).Create(newNeckRingBindLog).Error; err != nil {
 					return xerr.WithStack(err)
 				}

+ 2 - 0
module/backend/goods.go

@@ -165,6 +165,7 @@ func (s *StoreEntry) NeckRingCreateOrUpdate(ctx context.Context, req *pasturePb.
 				}
 				number = item.Number
 				newNeckRingLog.OperationName = model.OperationNameBind
+				newNeckRingLog.Remarks = model.DefaultBind
 				// 解绑
 			case pasturePb.NeckRingOperationStatus_UnBind:
 				if ok && neckRing.IsBind != pasturePb.NeckRingIsBind_Bind {
@@ -181,6 +182,7 @@ func (s *StoreEntry) NeckRingCreateOrUpdate(ctx context.Context, req *pasturePb.
 					return xerr.WithStack(err)
 				}
 				newNeckRingLog.OperationName = model.OperationNameUnbind
+				newNeckRingLog.Remarks = model.DefaultUnBind
 				// 编辑
 			case pasturePb.NeckRingOperationStatus_Edit:
 				if cowInfo.NeckRingNumber != "" && item.Number != cowInfo.NeckRingNumber {