|  | @@ -7,6 +7,8 @@ import (
 | 
											
												
													
														|  |  	"kpt-pasture/util"
 |  |  	"kpt-pasture/util"
 | 
											
												
													
														|  |  	"time"
 |  |  	"time"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +	"github.com/nicksnyder/go-i18n/v2/i18n"
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  	"gorm.io/gorm"
 |  |  	"gorm.io/gorm"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	"go.uber.org/zap"
 |  |  	"go.uber.org/zap"
 | 
											
										
											
												
													
														|  | @@ -43,33 +45,73 @@ type AbortionCheckBatchModel struct {
 | 
											
												
													
														|  |  	IsLact        pasturePb.IsShow_Kind
 |  |  	IsLact        pasturePb.IsShow_Kind
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -func (s *StoreEntry) EnterCheck(ctx context.Context, req *pasturePb.EventEnterRequest) error {
 |  | 
 | 
											
												
													
														|  | 
 |  | +func (s *StoreEntry) EnterCheck(userModel *model.UserModel, req *pasturePb.EventEnterRequest) error {
 | 
											
												
													
														|  |  	var count int64
 |  |  	var count int64
 | 
											
												
													
														|  | -	if err := s.DB.Model(new(model.Cow)).Where("ear_number = ?", req.EarNumber).Count(&count).Error; err != nil {
 |  | 
 | 
											
												
													
														|  | 
 |  | +	if err := s.DB.Model(new(model.Cow)).
 | 
											
												
													
														|  | 
 |  | +		Where("ear_number = ?", req.EarNumber).
 | 
											
												
													
														|  | 
 |  | +		Where("pasture_id = ?", userModel.AppPasture.Id).
 | 
											
												
													
														|  | 
 |  | +		Count(&count).Error; err != nil {
 | 
											
												
													
														|  |  		return xerr.WithStack(err)
 |  |  		return xerr.WithStack(err)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	if count > 0 {
 |  |  	if count > 0 {
 | 
											
												
													
														|  | -		return xerr.Custom("该牛只已存在")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +			MessageID: "cow.Exists",
 | 
											
												
													
														|  | 
 |  | +		})
 | 
											
												
													
														|  | 
 |  | +		return xerr.Custom(messageId)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +	if req.BirthAt > req.EnterAt {
 | 
											
												
													
														|  | 
 |  | +		messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +			MessageID: "validate.birthTimeEnterTime",
 | 
											
												
													
														|  | 
 |  | +		})
 | 
											
												
													
														|  | 
 |  | +		return xerr.Custom(messageId)
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  	return nil
 |  |  	return nil
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -func (s *StoreEntry) MatingCreateCheck(ctx context.Context, pastureId int64, req *pasturePb.EventMatingBatch) ([]*model.EventMatingCheckBatchModel, error) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +func (s *StoreEntry) MatingCreateCheck(ctx context.Context, userModel *model.UserModel, req *pasturePb.EventMatingBatch) ([]*model.EventMatingCheckBatchModel, error) {
 | 
											
												
													
														|  |  	if len(req.Items) <= 0 {
 |  |  	if len(req.Items) <= 0 {
 | 
											
												
													
														|  | -		return nil, xerr.Custom("请选择相关牛只")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +			MessageID: "cow.selectCow",
 | 
											
												
													
														|  | 
 |  | +		})
 | 
											
												
													
														|  | 
 |  | +		return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	if len(req.Items) > 50 {
 |  |  	if len(req.Items) > 50 {
 | 
											
												
													
														|  | -		return nil, xerr.Custom("最多只能选择50只牛只")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +			MessageID: "validate.dataLimit",
 | 
											
												
													
														|  | 
 |  | +		})
 | 
											
												
													
														|  | 
 |  | +		return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	eventMatingCheckBatchModelList := make([]*model.EventMatingCheckBatchModel, 0)
 |  |  	eventMatingCheckBatchModelList := make([]*model.EventMatingCheckBatchModel, 0)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	for _, v := range req.Items {
 |  |  	for _, v := range req.Items {
 | 
											
												
													
														|  | -		cowInfo, err := s.GetCowInfoByEarNumber(ctx, pastureId, v.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +		cowInfo, err := s.GetCowInfoByEarNumber(ctx, userModel.AppPasture.Id, v.EarNumber)
 | 
											
												
													
														|  |  		if err != nil {
 |  |  		if err != nil {
 | 
											
												
													
														|  |  			return nil, xerr.WithStack(err)
 |  |  			return nil, xerr.WithStack(err)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +		if cowInfo.GetEventDayAge(int64(v.MatingAt)) < 0 {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.matingTimeBirthTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		if int64(v.MatingAt) < cowInfo.LastCalvingAt {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.matingTimeLastCalvingTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  		operationUser, err := s.GetSystemUserById(ctx, int64(v.OperationId))
 |  |  		operationUser, err := s.GetSystemUserById(ctx, int64(v.OperationId))
 | 
											
												
													
														|  |  		if err != nil {
 |  |  		if err != nil {
 | 
											
												
													
														|  |  			return nil, xerr.WithStack(err)
 |  |  			return nil, xerr.WithStack(err)
 | 
											
										
											
												
													
														|  | @@ -78,35 +120,83 @@ func (s *StoreEntry) MatingCreateCheck(ctx context.Context, pastureId int64, req
 | 
											
												
													
														|  |  		frozenSemen := &model.FrozenSemen{}
 |  |  		frozenSemen := &model.FrozenSemen{}
 | 
											
												
													
														|  |  		if err = s.DB.Where("bull_id = ?", v.FrozenSemenNumber).
 |  |  		if err = s.DB.Where("bull_id = ?", v.FrozenSemenNumber).
 | 
											
												
													
														|  |  			First(frozenSemen).Error; err != nil {
 |  |  			First(frozenSemen).Error; err != nil {
 | 
											
												
													
														|  | -			return nil, xerr.Custom("未找到冻精信息")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "goods.frozenSemenNotExist",
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if frozenSemen.Quantity < v.FrozenSemenCount {
 |  |  		if frozenSemen.Quantity < v.FrozenSemenCount {
 | 
											
												
													
														|  | -			return nil, xerr.Custom("冻精数量不足")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "goods.frozenSemenNotEnough",
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if cowInfo.Sex != pasturePb.Genders_Female {
 |  |  		if cowInfo.Sex != pasturePb.Genders_Female {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %d,不是母牛", cowInfo.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.cowSex",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if int64(v.MatingAt) < cowInfo.LastMatingAt {
 |  |  		if int64(v.MatingAt) < cowInfo.LastMatingAt {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,最近一次配种时间: %d,不能小于本次配种时间: %d", cowInfo.EarNumber, cowInfo.LastMatingAt, v.MatingAt)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.matingTimeLastMatingTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber":      cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +					"matingTime":     time.Unix(int64(v.MatingAt), 0).Format(model.LayoutDate2),
 | 
											
												
													
														|  | 
 |  | +					"lastMatingTime": time.Unix(cowInfo.LastMatingAt, 0).Format(model.LayoutDate2),
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if int64(v.MatingAt) < cowInfo.LastPregnantCheckAt {
 |  |  		if int64(v.MatingAt) < cowInfo.LastPregnantCheckAt {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,最近一次孕检时间: %d,不能小于本次配种时间: %d", cowInfo.EarNumber, cowInfo.LastPregnantCheckAt, v.MatingAt)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.validate.pregnantCheckMatingTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if int64(v.MatingAt) < cowInfo.LastAbortionAt {
 |  |  		if int64(v.MatingAt) < cowInfo.LastAbortionAt {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,最近一次流产时间: %d,不能小于本次配种时间: %d", cowInfo.EarNumber, cowInfo.LastAbortionAt, v.MatingAt)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.matingTimeLastAbortionTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber":        cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +					"lastAbortionDate": time.Unix(cowInfo.LastAbortionAt, 0).Format(model.LayoutDate2),
 | 
											
												
													
														|  | 
 |  | +					"matingDate":       time.Unix(int64(v.MatingAt), 0).Format(model.LayoutDate2),
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if int64(v.MatingAt) < cowInfo.BirthAt {
 |  |  		if int64(v.MatingAt) < cowInfo.BirthAt {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,出生时间: %d,不能小于本次配种时间: %d", cowInfo.EarNumber, cowInfo.BirthAt, v.MatingAt)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.matingTimeBirthTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if cowInfo.BreedStatus == pasturePb.BreedStatus_Pregnant || cowInfo.BreedStatus == pasturePb.BreedStatus_No_Mating {
 |  |  		if cowInfo.BreedStatus == pasturePb.BreedStatus_Pregnant || cowInfo.BreedStatus == pasturePb.BreedStatus_No_Mating {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,当前状态为: %s,不能进行配种", cowInfo.EarNumber, cowInfo.BreedStatus.String())
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.breedStatusError",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber":   cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +					"breedStatus": cowInfo.BreedStatus.String(),
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  		eventMatingCheckBatchModelList = append(eventMatingCheckBatchModelList, &model.EventMatingCheckBatchModel{
 |  |  		eventMatingCheckBatchModelList = append(eventMatingCheckBatchModelList, &model.EventMatingCheckBatchModel{
 | 
											
												
													
														|  |  			Cow:              cowInfo,
 |  |  			Cow:              cowInfo,
 | 
											
										
											
												
													
														|  | @@ -122,41 +212,91 @@ func (s *StoreEntry) MatingCreateCheck(ctx context.Context, pastureId int64, req
 | 
											
												
													
														|  |  	return eventMatingCheckBatchModelList, nil
 |  |  	return eventMatingCheckBatchModelList, nil
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -func (s *StoreEntry) PregnantCheckDataCheck(ctx context.Context, pastureId int64, req *pasturePb.EventPregnantCheckBatch) ([]*PregnantCheckBatchModel, error) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +func (s *StoreEntry) PregnantCheckDataCheck(ctx context.Context, userModel *model.UserModel, req *pasturePb.EventPregnantCheckBatch) ([]*PregnantCheckBatchModel, error) {
 | 
											
												
													
														|  |  	if len(req.Items) <= 0 {
 |  |  	if len(req.Items) <= 0 {
 | 
											
												
													
														|  | -		return nil, xerr.Custom("请选择相关牛只数据")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +			MessageID: "cow.selectCow",
 | 
											
												
													
														|  | 
 |  | +		})
 | 
											
												
													
														|  | 
 |  | +		return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	if len(req.Items) > 50 {
 |  |  	if len(req.Items) > 50 {
 | 
											
												
													
														|  | -		return nil, xerr.Custom("一次性最多限制提交50牛数据")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +			MessageID: "validate.dataLimit",
 | 
											
												
													
														|  | 
 |  | +		})
 | 
											
												
													
														|  | 
 |  | +		return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	pregnantCheckBatchModelList := make([]*PregnantCheckBatchModel, 0)
 |  |  	pregnantCheckBatchModelList := make([]*PregnantCheckBatchModel, 0)
 | 
											
												
													
														|  |  	cowInfo := &model.Cow{}
 |  |  	cowInfo := &model.Cow{}
 | 
											
												
													
														|  |  	var err error
 |  |  	var err error
 | 
											
												
													
														|  |  	for _, item := range req.Items {
 |  |  	for _, item := range req.Items {
 | 
											
												
													
														|  | -		cowInfo, err = s.GetCowInfoByEarNumber(ctx, pastureId, item.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +		cowInfo, err = s.GetCowInfoByEarNumber(ctx, userModel.AppPasture.Id, item.EarNumber)
 | 
											
												
													
														|  |  		if err != nil {
 |  |  		if err != nil {
 | 
											
												
													
														|  |  			return nil, xerr.WithStack(err)
 |  |  			return nil, xerr.WithStack(err)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if cowInfo.Sex != pasturePb.Genders_Female {
 |  |  		if cowInfo.Sex != pasturePb.Genders_Female {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %d,不是母牛", cowInfo.Id)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.cowSex",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		if int64(item.PregnantCheckAt) > cowInfo.LastMatingAt {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.pregnantCheckMatingTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		if cowInfo.GetEventDayAge(int64(item.PregnantCheckAt)) < 0 {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.pregnantCheckBirthTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
 |  |  		operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
 | 
											
												
													
														|  |  		if err != nil {
 |  |  		if err != nil {
 | 
											
												
													
														|  | -			zaplog.Error("PregnantCheckDataCheck", zap.Any("id", item.OperationId), zap.Any("error", err.Error()))
 |  | 
 | 
											
												
													
														|  | -			return nil, xerr.Customf("获取操作人员信息失败")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			zaplog.Error("PregnantCheckDataCheck",
 | 
											
												
													
														|  | 
 |  | +				zap.Any("id", item.OperationId),
 | 
											
												
													
														|  | 
 |  | +				zap.Any("error", err.Error()),
 | 
											
												
													
														|  | 
 |  | +			)
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "auth.getOperationError",
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -		// 过滤掉没有配种状态的牛只
 |  | 
 | 
											
												
													
														|  | -		if cowInfo.BreedStatus != pasturePb.BreedStatus_Breeding && cowInfo.BreedStatus != pasturePb.BreedStatus_Pregnant {
 |  | 
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s 未参加配种,不能进行孕检", cowInfo.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +		if cowInfo.LastMatingAt <= 0 {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.matingDataError",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -		if cowInfo.LastMatingAt <= 0 {
 |  | 
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,最近一次配种数据异常", cowInfo.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +		// 过滤掉没有配种状态的牛只
 | 
											
												
													
														|  | 
 |  | +		if cowInfo.BreedStatus != pasturePb.BreedStatus_Breeding && cowInfo.BreedStatus != pasturePb.BreedStatus_Pregnant {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.cannotPregnantCheck",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		itemEventPregnantCheck, err := s.FindEventPregnantCheckIsExIstByCowId(ctx, cowInfo)
 |  |  		itemEventPregnantCheck, err := s.FindEventPregnantCheckIsExIstByCowId(ctx, cowInfo)
 | 
											
										
											
												
													
														|  | @@ -165,16 +305,34 @@ func (s *StoreEntry) PregnantCheckDataCheck(ctx context.Context, pastureId int64
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if itemEventPregnantCheck.Id <= 0 {
 |  |  		if itemEventPregnantCheck.Id <= 0 {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("未发现该牛只: %s 孕检数据", cowInfo.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.notFoundPregnantCheckData",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -		lastEventMating, err := s.FindLastEventMatingByCowId(ctx, pastureId, cowInfo.Id)
 |  | 
 | 
											
												
													
														|  | 
 |  | +		lastEventMating, err := s.FindLastEventMatingByCowId(ctx, userModel.AppPasture.Id, cowInfo.Id)
 | 
											
												
													
														|  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 |  |  		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("未发现该牛只: %s 配种数据", cowInfo.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.notFoundMatingData",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if lastEventMating == nil || lastEventMating.Status == pasturePb.IsShow_No {
 |  |  		if lastEventMating == nil || lastEventMating.Status == pasturePb.IsShow_No {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("未发现该牛只: %s 配种数据", cowInfo.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.notFoundMatingData",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		pregnantCheckBatchModelList = append(pregnantCheckBatchModelList, &PregnantCheckBatchModel{
 |  |  		pregnantCheckBatchModelList = append(pregnantCheckBatchModelList, &PregnantCheckBatchModel{
 | 
											
										
											
												
													
														|  | @@ -210,23 +368,43 @@ func (s *StoreEntry) EstrusCheckDataCheck(ctx context.Context, userModel *model.
 | 
											
												
													
														|  |  	for _, item := range req.Items {
 |  |  	for _, item := range req.Items {
 | 
											
												
													
														|  |  		cowInfo, err := s.GetCowInfoByEarNumber(ctx, pastureId, item.EarNumber)
 |  |  		cowInfo, err := s.GetCowInfoByEarNumber(ctx, pastureId, item.EarNumber)
 | 
											
												
													
														|  |  		if err != nil {
 |  |  		if err != nil {
 | 
											
												
													
														|  | -			return nil, xerr.Custom("牛只信息不存在")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "cow.cowNotExist",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": item.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if cowInfo.Sex != pasturePb.Genders_Female {
 |  |  		if cowInfo.Sex != pasturePb.Genders_Female {
 | 
											
												
													
														|  | -			return nil, xerr.Custom("该牛只不是母牛")
 |  | 
 | 
											
												
													
														|  | -		}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -		if item.EstrusAt <= 0 {
 |  | 
 | 
											
												
													
														|  | -			return nil, xerr.Custom("发情时间不能为空")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "cow.cowSex",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if int64(item.EstrusAt) <= cowInfo.BirthAt {
 |  |  		if int64(item.EstrusAt) <= cowInfo.BirthAt {
 | 
											
												
													
														|  | -			return nil, xerr.Custom("发情时间不能小于出生时间")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.estrusDateBirthDate",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if int64(item.EstrusAt) <= cowInfo.LastCalvingAt {
 |  |  		if int64(item.EstrusAt) <= cowInfo.LastCalvingAt {
 | 
											
												
													
														|  | -			return nil, xerr.Custom("发情时间不能小于产犊时间")
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.estrusDateLastCalvingDate",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		estrusAt := time.Unix(int64(item.EstrusAt), 0).Local().Format(model.LayoutDate2)
 |  |  		estrusAt := time.Unix(int64(item.EstrusAt), 0).Local().Format(model.LayoutDate2)
 | 
											
										
											
												
													
														|  | @@ -235,7 +413,13 @@ func (s *StoreEntry) EstrusCheckDataCheck(ctx context.Context, userModel *model.
 | 
											
												
													
														|  |  		isExists := s.FindEventEstrusByCowId(pastureId, cowInfo.Id, estrusLocalStartTime, estrusLocalEndTime)
 |  |  		isExists := s.FindEventEstrusByCowId(pastureId, cowInfo.Id, estrusLocalStartTime, estrusLocalEndTime)
 | 
											
												
													
														|  |  		// 如果存在,并且当天已经提交过则跳过
 |  |  		// 如果存在,并且当天已经提交过则跳过
 | 
											
												
													
														|  |  		if isExists {
 |  |  		if isExists {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("该牛只:%s,今天已经提交过发情数据", item.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.estrusDataAlready",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": item.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		operationUser, _ := s.GetSystemUserById(ctx, int64(item.OperationId))
 |  |  		operationUser, _ := s.GetSystemUserById(ctx, int64(item.OperationId))
 | 
											
										
											
												
													
														|  | @@ -248,7 +432,13 @@ func (s *StoreEntry) EstrusCheckDataCheck(ctx context.Context, userModel *model.
 | 
											
												
													
														|  |  		if item.IsMating == pasturePb.IsShow_Ok {
 |  |  		if item.IsMating == pasturePb.IsShow_Ok {
 | 
											
												
													
														|  |  			isExists = s.FindEventMatingByCowId(pastureId, cowInfo.Id)
 |  |  			isExists = s.FindEventMatingByCowId(pastureId, cowInfo.Id)
 | 
											
												
													
														|  |  			if isExists {
 |  |  			if isExists {
 | 
											
												
													
														|  | -				return nil, xerr.Customf("配种清单已经有该牛只数据 :%s,今天已经提交过配种数据", item.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +				messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +					MessageID: "validate.matingDataItemAlready",
 | 
											
												
													
														|  | 
 |  | +					TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +						"earNumber": item.EarNumber,
 | 
											
												
													
														|  | 
 |  | +					},
 | 
											
												
													
														|  | 
 |  | +				})
 | 
											
												
													
														|  | 
 |  | +				return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  			}
 |  |  			}
 | 
											
												
													
														|  |  			newEventMating := model.NewEventMating(pastureId, cowInfo, time.Now().Local().Unix(), exposeEstrusType)
 |  |  			newEventMating := model.NewEventMating(pastureId, cowInfo, time.Now().Local().Unix(), exposeEstrusType)
 | 
											
												
													
														|  |  			res.EventMatingList = append(res.EventMatingList, newEventMating)
 |  |  			res.EventMatingList = append(res.EventMatingList, newEventMating)
 | 
											
										
											
												
													
														|  | @@ -266,10 +456,16 @@ func (s *StoreEntry) EstrusCheckDataCheck(ctx context.Context, userModel *model.
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  func (s *StoreEntry) AbortionEventDataCheck(ctx context.Context, userModel *model.UserModel, items []*pasturePb.EventAbortionItem) ([]*AbortionCheckBatchModel, error) {
 |  |  func (s *StoreEntry) AbortionEventDataCheck(ctx context.Context, userModel *model.UserModel, items []*pasturePb.EventAbortionItem) ([]*AbortionCheckBatchModel, error) {
 | 
											
												
													
														|  |  	if len(items) <= 0 {
 |  |  	if len(items) <= 0 {
 | 
											
												
													
														|  | -		return nil, xerr.Custom("请选择相关数据")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +			MessageID: "cow.selectCow",
 | 
											
												
													
														|  | 
 |  | +		})
 | 
											
												
													
														|  | 
 |  | +		return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	if len(items) > 50 {
 |  |  	if len(items) > 50 {
 | 
											
												
													
														|  | -		return nil, xerr.Custom("一次性最多限制提交50牛数据")
 |  | 
 | 
											
												
													
														|  | 
 |  | +		messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +			MessageID: "validate.dataLimit",
 | 
											
												
													
														|  | 
 |  | +		})
 | 
											
												
													
														|  | 
 |  | +		return nil, xerr.Custom(messageId)
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	abortionCheckBatchModelList := make([]*AbortionCheckBatchModel, 0)
 |  |  	abortionCheckBatchModelList := make([]*AbortionCheckBatchModel, 0)
 | 
											
												
													
														|  |  	for _, item := range items {
 |  |  	for _, item := range items {
 | 
											
										
											
												
													
														|  | @@ -279,15 +475,43 @@ func (s *StoreEntry) AbortionEventDataCheck(ctx context.Context, userModel *mode
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if cow.Sex != pasturePb.Genders_Female {
 |  |  		if cow.Sex != pasturePb.Genders_Female {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,不是母牛", cow.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "cow.cowSex",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cow.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if cow.IsPregnant != pasturePb.IsShow_Ok {
 |  |  		if cow.IsPregnant != pasturePb.IsShow_Ok {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,不是怀孕状态", cow.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.CowNotPregnant",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cow.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if cow.BreedStatus != pasturePb.BreedStatus_Pregnant {
 |  |  		if cow.BreedStatus != pasturePb.BreedStatus_Pregnant {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,不是怀孕状态", cow.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.CowNotPregnant",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cow.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		if cow.GetEventDayAge(int64(item.AbortionAt)) < 0 {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.AbortionDateBirthDate",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": item.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
 |  |  		operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
 | 
											
										
											
												
													
														|  | @@ -318,11 +542,23 @@ func (s *StoreEntry) ForbiddenMatingCheck(ctx context.Context, userModel *model.
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if cowInfo.Sex != pasturePb.Genders_Female {
 |  |  		if cowInfo.Sex != pasturePb.Genders_Female {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,不是母牛", cowInfo.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "cow.cowSex",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if v.ForbiddenMatingAt < int32(cowInfo.BirthAt) {
 |  |  		if v.ForbiddenMatingAt < int32(cowInfo.BirthAt) {
 | 
											
												
													
														|  | -			return nil, xerr.Customf("牛只: %s,禁止配种时间不能小于出生时间", cowInfo.EarNumber)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.unMatingDate",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cowInfo.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		operationUser, err := s.GetSystemUserById(ctx, int64(v.OperationId))
 |  |  		operationUser, err := s.GetSystemUserById(ctx, int64(v.OperationId))
 | 
											
										
											
												
													
														|  | @@ -342,3 +578,74 @@ func (s *StoreEntry) ForbiddenMatingCheck(ctx context.Context, userModel *model.
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	return res, nil
 |  |  	return res, nil
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +func (s *StoreEntry) DeathCheck(ctx context.Context, userModel *model.UserModel, req *pasturePb.EventDeathBatch) ([]*model.EventDeathModel, error) {
 | 
											
												
													
														|  | 
 |  | +	newEventDeathList := make([]*model.EventDeathModel, 0)
 | 
											
												
													
														|  | 
 |  | +	for _, item := range req.Items {
 | 
											
												
													
														|  | 
 |  | +		cow, err := s.GetCowInfoByEarNumber(ctx, userModel.AppPasture.Id, item.EarNumber)
 | 
											
												
													
														|  | 
 |  | +		if err != nil {
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.WithStack(err)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		if cow.BirthAt <= int64(item.DeathAt) {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.deathTime",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cow.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		lastEventLog, _ := s.GetEventCowLog(ctx, userModel.AppPasture.Id, cow.Id)
 | 
											
												
													
														|  | 
 |  | +		if lastEventLog != nil && int64(item.DeathAt) < lastEventLog.EventAt {
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "validate.deathTimeLastEvent",
 | 
											
												
													
														|  | 
 |  | +				TemplateData: map[string]interface{}{
 | 
											
												
													
														|  | 
 |  | +					"earNumber": cow.EarNumber,
 | 
											
												
													
														|  | 
 |  | +				},
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		if name, ok := s.DeadReasonMap()[item.DeathReasonKind]; ok {
 | 
											
												
													
														|  | 
 |  | +			item.DeathReasonName = name
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
 | 
											
												
													
														|  | 
 |  | +		if err != nil {
 | 
											
												
													
														|  | 
 |  | +			zaplog.Error("DeathBatch", zap.Any("item", item), zap.Any("err", err))
 | 
											
												
													
														|  | 
 |  | +			messageId, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
 | 
											
												
													
														|  | 
 |  | +				MessageID: "auth.getOperationError",
 | 
											
												
													
														|  | 
 |  | +			})
 | 
											
												
													
														|  | 
 |  | +			return nil, xerr.Customf(messageId)
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		if name, ok := s.CowDeathDestinationMap()[item.DeathDestinationKind]; ok {
 | 
											
												
													
														|  | 
 |  | +			item.DeathDestinationName = name
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		newEventDeath := model.NewEventDeath(userModel.AppPasture.Id, cow, item, userModel.SystemUser, operationUser)
 | 
											
												
													
														|  | 
 |  | +		eventDeathModel := &model.EventDeathModel{
 | 
											
												
													
														|  | 
 |  | +			Cow:         cow,
 | 
											
												
													
														|  | 
 |  | +			EventDeath:  newEventDeath,
 | 
											
												
													
														|  | 
 |  | +			NeckRing:    nil,
 | 
											
												
													
														|  | 
 |  | +			CalvingCalf: nil,
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		// 犊牛死亡更新
 | 
											
												
													
														|  | 
 |  | +		if cow.DayAge <= model.CalfDefaultDayAge {
 | 
											
												
													
														|  | 
 |  | +			calvingCalf, ok := s.IsExistCalvingCalf(userModel.AppPasture.Id, cow.Id)
 | 
											
												
													
														|  | 
 |  | +			if ok && calvingCalf != nil {
 | 
											
												
													
														|  | 
 |  | +				eventDeathModel.CalvingCalf = calvingCalf
 | 
											
												
													
														|  | 
 |  | +			}
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +		if neckRing, ok := s.NeckRingIsExist(userModel.AppPasture.Id, item.EarNumber); ok && neckRing != nil {
 | 
											
												
													
														|  | 
 |  | +			eventDeathModel.NeckRing = neckRing
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +		newEventDeathList = append(newEventDeathList, eventDeathModel)
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +	return newEventDeathList, nil
 | 
											
												
													
														|  | 
 |  | +}
 |