123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package backend
- import (
- "context"
- "kpt-pasture/model"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- "gitee.com/xuyiping_admin/pkg/xerr"
- )
- type EventCheckModel struct {
- CowList []*model.Cow
- CurrentUser *model.SystemUser
- OperationUser *model.SystemUser
- }
- func (s *StoreEntry) MatingCreateCheck(ctx context.Context, req *pasturePb.EventMating) (*EventCheckModel, error) {
- if len(req.CowIds) <= 0 {
- return nil, xerr.Custom("请选择相关牛只")
- }
- cowList, err := s.ParseCowIds(ctx, req.CowIds)
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- currentUser, err := s.GetCurrentSystemUser(ctx)
- if err != nil {
- return nil, xerr.Customf("获取当前用户失败: %s", err.Error())
- }
- for _, cow := range cowList {
- if cow.Sex != pasturePb.Genders_Female {
- return nil, xerr.Customf("牛只: %d,不是母牛", cow.Id)
- }
- if int64(req.MatingAt) < cow.LastMatingAt {
- return nil, xerr.Customf("牛只: %d,最近一次配种时间: %d,不能小于本次配种时间: %d", cow.Id, cow.LastMatingAt, req.MatingAt)
- }
- if int64(req.MatingAt) < cow.LastPregnantCheckAt {
- return nil, xerr.Customf("牛只: %d,最近一次孕检时间: %d,不能小于本次配种时间: %d", cow.Id, cow.LastPregnantCheckAt, req.MatingAt)
- }
- if int64(req.MatingAt) < cow.LastAbortionAt {
- return nil, xerr.Customf("牛只: %d,最近一次流产时间: %d,不能小于本次配种时间: %d", cow.Id, cow.LastAbortionAt, req.MatingAt)
- }
- if int64(req.MatingAt) < cow.BirthAt {
- return nil, xerr.Customf("牛只: %d,出生时间: %d,不能小于本次配种时间: %d", cow.Id, cow.BirthAt, req.MatingAt)
- }
- if cow.BreedStatus == pasturePb.BreedStatus_Pregnant || cow.BreedStatus == pasturePb.BreedStatus_No_Mating {
- return nil, xerr.Customf("牛只: %d,当前状态为: %s,不能进行配种", cow.Id, cow.BreedStatus.String())
- }
- }
- return &EventCheckModel{
- CowList: cowList,
- CurrentUser: currentUser,
- OperationUser: operationUser,
- }, nil
- }
- func (s *StoreEntry) PregnantCheckCreateCheck(ctx context.Context, req *pasturePb.EventPregnantCheck) (*EventCheckModel, error) {
- if len(req.CowId) <= 0 {
- return nil, xerr.Custom("请选择相关牛只")
- }
- operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- currentUser, err := s.GetCurrentSystemUser(ctx)
- if err != nil {
- return nil, xerr.Customf("获取当前用户失败: %s", err.Error())
- }
- cowList, err := s.ParseCowIds(ctx, req.CowId)
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- for _, cow := range cowList {
- // 过滤掉没有配种状态的牛只
- if cow.BreedStatus != pasturePb.BreedStatus_Breeding {
- return nil, xerr.Customf("牛只: %d,当前状态为: %s,不能进行孕检", cow.Id, cow.BreedStatus.String())
- }
- if int64(req.PregnantCheckAt) < cow.LastMatingAt {
- return nil, xerr.Customf("牛只: %d,最近一次配种时间: %d,不能小于本次孕检时间: %d", cow.Id, req.PregnantCheckAt)
- }
- if int64(req.PregnantCheckAt) < cow.LastCalvingAt {
- return nil, xerr.Customf("牛只: %d,最近一次产犊时间: %d,不能小于本次孕检时间: %d", cow.Id, cow.LastCalvingAt, req.PregnantCheckAt)
- }
- }
- return &EventCheckModel{
- CowList: cowList,
- CurrentUser: currentUser,
- OperationUser: operationUser,
- }, nil
- }
|