Browse Source

test: RNP-213

Yi 2 days ago
parent
commit
3af8c961bb

+ 9 - 0
module/backend/event_base.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"kpt-pasture/model"
+	"kpt-pasture/util"
 	"net/http"
 	"strconv"
 	"strings"
@@ -247,6 +248,11 @@ func (s *StoreEntry) CreateGroupTransfer(ctx context.Context, req *pasturePb.Tra
 				return xerr.Custom("转入栏舍和牛只当前栏舍不能一致")
 			}
 
+			transferGroupAt := util.DateTimeParseLocalUnix(v.TransferDate)
+			if cow.GetEventDayAge(transferGroupAt) < 0 {
+				return xerr.Custom("转栏时间不能早于牛只出生时间")
+			}
+
 			operationUser, err := s.GetSystemUserById(ctx, int64(v.OperationId))
 			if err != nil {
 				return xerr.WithStack(err)
@@ -407,6 +413,9 @@ func (s *StoreEntry) WeightBatch(ctx context.Context, req *pasturePb.BatchEventW
 				return xerr.WithStack(err)
 			}
 
+			if cow.GetEventDayAge(int64(item.WeightAt)) < 0 {
+				return xerr.Custom("称重时间不能早于牛只出生时间")
+			}
 			// 更新牛只信息
 			cow.EventWeightUpdate(int64(item.Weight*1000), int64(item.Height), int64(item.WeightAt))
 			if err = tx.Model(new(model.Cow)).

+ 12 - 0
module/backend/event_base_more.go

@@ -193,6 +193,10 @@ func (s *StoreEntry) CowSaleCreate(ctx context.Context, req *pasturePb.EventCowS
 	eventCowLogList := make([]*model.EventCowLog, 0)
 	neckRingList := make([]*model.NeckRing, 0)
 	for _, cow := range cowList {
+		if cow.GetEventDayAge(int64(req.SaleAt)) < 0 {
+			return xerr.Customf("牛号: %s,销售时间不能早于牛只出生时间", cow.EarNumber)
+		}
+
 		var newEventCowLog *model.EventCowLog
 		if req.SalesType == pasturePb.SalesType_Sales {
 			newEventCowLog = s.SubmitEventLog(ctx, userModel.AppPasture.Id, cow, pasturePb.EventType_Sale, req)
@@ -408,6 +412,10 @@ func (s *StoreEntry) ImmunizationBatch(ctx context.Context, req *pasturePb.Immun
 		return xerr.Custom("请选择相关牛只数据")
 	}
 
+	if len(req.EarNumbers) > 50 {
+		return xerr.Custom("最多只能添加50条数据")
+	}
+
 	eventImmunizationList := make([]*model.EventImmunizationPlan, 0)
 	if err = s.DB.Model(new(model.EventImmunizationPlan)).
 		Where("pasture_id = ?", userModel.AppPasture.Id).
@@ -441,6 +449,10 @@ func (s *StoreEntry) ImmunizationBatch(ctx context.Context, req *pasturePb.Immun
 				return xerr.WithStack(err)
 			}
 
+			if cowInfo.GetEventDayAge(int64(req.ImmunizationAt)) < 0 {
+				return xerr.Customf("牛号: %s,免疫时间不能早于牛只出生时间", cowInfo.EarNumber)
+			}
+
 			// 更新数据
 			eventImmunization.EventUpdate(int64(req.ImmunizationAt), cowInfo, drugsInfo, req.Usage, operationUser, userModel.SystemUser, req.Remarks)
 			if err = tx.Model(new(model.EventImmunizationPlan)).

+ 4 - 0
module/backend/event_breed.go

@@ -82,6 +82,10 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
 		return xerr.Custom("请选择相关牛只")
 	}
 
+	if cow.GetEventDayAge(int64(req.CalvingAt)) < 0 {
+		return xerr.Custom("产犊时间不能早于牛只出生时间")
+	}
+
 	if len(req.CalfItemList) != int(req.ChildNumber) {
 		return xerr.Custom("犊牛信息与产子数不相符")
 	}

+ 4 - 0
module/backend/event_breed_more.go

@@ -523,6 +523,10 @@ func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeani
 				return xerr.WithStack(err)
 			}
 
+			if cowInfo.GetEventDayAge(int64(item.WeaningAt)) < 0 {
+				return xerr.Customf("牛号: %s,断奶时间不能早于牛只出生时间", cowInfo.EarNumber)
+			}
+
 			eventWeaning := &model.EventWeaning{}
 			if err = s.DB.Model(new(model.EventWeaning)).
 				Where("ear_number = ?", item.EarNumber).

+ 13 - 5
module/backend/event_breed_more_more.go

@@ -53,6 +53,11 @@ func (s *StoreEntry) DryMilkList(ctx context.Context, req *pasturePb.SearchEvent
 }
 
 func (s *StoreEntry) DryMilkBatch(ctx context.Context, req *pasturePb.EventMilkBatch) error {
+	userModel, err := s.GetUserModel(ctx)
+	if err != nil {
+		return xerr.WithStack(err)
+	}
+
 	if len(req.Items) <= 0 {
 		return nil
 	}
@@ -61,11 +66,6 @@ func (s *StoreEntry) DryMilkBatch(ctx context.Context, req *pasturePb.EventMilkB
 		return xerr.Custom("最多只能添加50条数据")
 	}
 
-	userModel, err := s.GetUserModel(ctx)
-	if err != nil {
-		return xerr.WithStack(err)
-	}
-
 	penMap := s.PenMap(ctx, userModel.AppPasture.Id)
 	if err = s.DB.Transaction(func(tx *gorm.DB) error {
 		for _, v := range req.Items {
@@ -74,6 +74,10 @@ func (s *StoreEntry) DryMilkBatch(ctx context.Context, req *pasturePb.EventMilkB
 				return xerr.WithStack(err)
 			}
 
+			if cowInfo.GetEventDayAge(int64(v.DryMilkAt)) < 0 {
+				return xerr.Customf("牛号: %s,干奶时间不能早于牛只出生时间", cowInfo.EarNumber)
+			}
+
 			cowInfo.EventDryMilkUpdate(int64(v.DryMilkAt), penMap[v.PenId])
 			if err = tx.Select("milk_kind", "last_dry_milk_at", "pen_id", "pen_name").
 				Where("id = ?", cowInfo.Id).
@@ -253,6 +257,10 @@ func (s *StoreEntry) UnForbiddenMating(ctx context.Context, req *pasturePb.Event
 				return xerr.WithStack(err)
 			}
 
+			if cowInfo.GetEventDayAge(int64(item.UnForbiddenMatingAt)) < 0 {
+				return xerr.Customf("牛号: %s,解禁时间不能早于牛只出生时间", cowInfo.EarNumber)
+			}
+
 			// 牛只解配更新
 			cowInfo.UnForbiddenMatingUpdate()
 			if err = tx.Model(new(model.Cow)).

+ 13 - 1
module/backend/event_check.go

@@ -78,6 +78,10 @@ func (s *StoreEntry) MatingCreateCheck(ctx context.Context, pastureId int64, req
 			return nil, xerr.WithStack(err)
 		}
 
+		if cowInfo.GetEventDayAge(int64(v.MatingAt)) < 0 {
+			return nil, xerr.Customf("牛号:%s,配种时间不能早于牛只出生时间", cowInfo.EarNumber)
+		}
+
 		operationUser, err := s.GetSystemUserById(ctx, int64(v.OperationId))
 		if err != nil {
 			return nil, xerr.WithStack(err)
@@ -152,6 +156,10 @@ func (s *StoreEntry) PregnantCheckDataCheck(ctx context.Context, pastureId int64
 			return nil, xerr.Customf("牛只: %d,不是母牛", cowInfo.Id)
 		}
 
+		if cowInfo.GetEventDayAge(int64(item.PregnantCheckAt)) < 0 {
+			return nil, xerr.Customf("牛号: %s,孕检时间不能早于牛只出生时间", cowInfo.EarNumber)
+		}
+
 		operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
 		if err != nil {
 			zaplog.Error("PregnantCheckDataCheck", zap.Any("id", item.OperationId), zap.Any("error", err.Error()))
@@ -230,7 +238,7 @@ func (s *StoreEntry) EstrusCheckDataCheck(ctx context.Context, userModel *model.
 		}
 
 		if int64(item.EstrusAt) <= cowInfo.BirthAt {
-			return nil, xerr.Custom("发情时间不能小于出生时间")
+			return nil, xerr.Customf("牛号: %s,发情时间不能小于出生时间", cowInfo.EarNumber)
 		}
 
 		if int64(item.EstrusAt) <= cowInfo.LastCalvingAt {
@@ -298,6 +306,10 @@ func (s *StoreEntry) AbortionEventDataCheck(ctx context.Context, userModel *mode
 			return nil, xerr.Customf("牛只: %s,不是怀孕状态", cow.EarNumber)
 		}
 
+		if cow.GetEventDayAge(int64(item.AbortionAt)) < 0 {
+			return nil, xerr.Customf("牛号: %s,流产时间不能早于牛只出生时间", cow.EarNumber)
+		}
+
 		operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
 		if err != nil {
 			return nil, xerr.WithStack(err)

+ 8 - 0
module/backend/event_health.go

@@ -90,6 +90,10 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
 		return xerr.Customf("牛只信息错误: %d", req.CowId)
 	}
 
+	if cow.GetEventDayAge(int64(req.DiseaseAt)) < 0 {
+		return xerr.Customf("牛号: %s,发病时间不能早于牛只出生时间", cow.EarNumber)
+	}
+
 	operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
 	if err != nil {
 		return xerr.Customf("请检查操作人信息")
@@ -393,6 +397,10 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
 		return xerr.Custom("异常牛只数据")
 	}
 
+	if eventCowDisease.DiagnosedAt < int64(req.TreatmentAt) {
+		return xerr.Custom("治疗时间不能大于确诊时间")
+	}
+
 	// 处方详情
 	unitMap := s.UnitMap()
 	prescriptionDetail := make([]*pasturePb.PrescriptionDrugsList, len(prescriptionDrugs))

+ 3 - 0
module/backend/event_health_more.go

@@ -141,6 +141,9 @@ func (s *StoreEntry) CowDiseaseCurable(ctx context.Context, req *pasturePb.Event
 
 	eventCowTreatmentList := make([]*model.EventCowTreatment, 0)
 	for _, v := range eventCowDiseaseList {
+		if v.LastTreatmentAt > int64(req.CurableAt) {
+			return xerr.Customf("牛只: %s,治愈时间不能小于上次治疗时间", v.EarNumber)
+		}
 		newEventCowTreatment := model.NewEventCowCurableTreatment(userModel.AppPasture.Id, userModel.SystemUser, operationUser, v, req.Remarks, int64(req.CurableAt))
 		eventCowTreatmentList = append(eventCowTreatmentList, newEventCowTreatment)
 	}