|
@@ -386,9 +386,10 @@ func (s *StoreEntry) GetEventCowSameTimeByCowId(ctx context.Context, pastureId,
|
|
|
return eventCowSameTime, nil
|
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) SearchSystemDeptListByIds(ctx context.Context, ids []int64) ([]*model.SystemDept, error) {
|
|
|
+func (s *StoreEntry) SearchSystemDeptListByIds(ctx context.Context, pastureId int64, ids []int64) ([]*model.SystemDept, error) {
|
|
|
systemDeptList := make([]*model.SystemDept, 0)
|
|
|
if err := s.DB.Model(new(model.SystemDept)).
|
|
|
+ Where("pasture_id = ?", pastureId).
|
|
|
Where("is_show = ?", operationPb.IsShow_OK).
|
|
|
Find(&systemDeptList, ids).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
@@ -414,171 +415,3 @@ func (s *StoreEntry) GetSystemBasicByName(ctx context.Context, pastureId int64,
|
|
|
}
|
|
|
return systemBasic, nil
|
|
|
}
|
|
|
-
|
|
|
-// FindLastEventMatingByCowId 根据cowId获取最近一次配种表信息
|
|
|
-func (s *StoreEntry) FindLastEventMatingByCowId(ctx context.Context, pastureId, cowId int64) (*model.EventMating, error) {
|
|
|
- newEventMating := &model.EventMating{}
|
|
|
- if err := s.DB.Model(new(model.EventMating)).
|
|
|
- Where("cow_id = ?", cowId).
|
|
|
- Where("pasture_id = ?", pastureId).
|
|
|
- Order("id desc").
|
|
|
- First(newEventMating).Error; err != nil {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
- return newEventMating, nil
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) FindEventEstrusByCowId(pastureId, cowId int64, startTime, endTime int64) bool {
|
|
|
- var count int64
|
|
|
- if err := s.DB.Model(new(model.EventEstrus)).
|
|
|
- Where("cow_id = ?", cowId).
|
|
|
- Where("pasture_id = ?", pastureId).
|
|
|
- Where("reality_day BETWEEN ? AND ?", startTime, endTime).
|
|
|
- Where("is_show = ? ", pasturePb.IsShow_Ok).
|
|
|
- Count(&count).Error; err != nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- return count > 0
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) FindEventMatingByCowId(pastureId, cowId int64) bool {
|
|
|
- var count int64
|
|
|
- if err := s.DB.Model(new(model.EventMating)).
|
|
|
- Where("cow_id = ?", cowId).
|
|
|
- Where("pasture_id = ?", pastureId).
|
|
|
- Where("is_show = ? ", pasturePb.IsShow_Ok).
|
|
|
- Count(&count).Error; err != nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- return count > 0
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) GetOutboundById(ctx context.Context, pastureId, id int64) (*model.Outbound, error) {
|
|
|
- res := &model.Outbound{}
|
|
|
- if err := s.DB.Model(new(model.Outbound)).Where("pasture_id = ?", pastureId).
|
|
|
- Where("id = ?", id).First(res).Error; err != nil {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
- return res, nil
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) GetOutboundDetailByOutboundId(ctx context.Context, id int64) ([]*model.OutboundDetail, error) {
|
|
|
- list := make([]*model.OutboundDetail, 0)
|
|
|
- if err := s.DB.Model(new(model.OutboundDetail)).
|
|
|
- Where("outbound_id = ?", id).
|
|
|
- Where("is_delete = ?", pasturePb.IsShow_Ok).
|
|
|
- Find(&list).Error; err != nil {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
- return list, nil
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) FindEventPregnantCheckIsExIstByCowId(ctx context.Context, cow *model.Cow) (*model.EventPregnantCheck, error) {
|
|
|
- newEventPregnantCheck := &model.EventPregnantCheck{}
|
|
|
- if err := s.DB.Model(new(model.EventPregnantCheck)).
|
|
|
- Where("cow_id = ?", cow.Id).
|
|
|
- Where("lact = ?", cow.Lact).
|
|
|
- Where("status = ?", pasturePb.IsShow_No).
|
|
|
- Order("id desc").
|
|
|
- First(newEventPregnantCheck).Error; err != nil {
|
|
|
- if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
- return nil, xerr.Customf("该牛只: %d 孕检数据未找到", cow.Id)
|
|
|
- } else {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
- }
|
|
|
- return newEventPregnantCheck, nil
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) DiseaseMaps(ctx context.Context) (map[int64]*model.Disease, error) {
|
|
|
- res := make(map[int64]*model.Disease)
|
|
|
- list := make([]*model.Disease, 0)
|
|
|
- if err := s.DB.Model(new(model.Disease)).Where("is_show = ?", pasturePb.IsShow_Ok).Find(&list).Error; err != nil {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
- for _, v := range list {
|
|
|
- res[v.Id] = v
|
|
|
- }
|
|
|
- return res, nil
|
|
|
-}
|
|
|
-
|
|
|
-// NeckRingIsExist 根据neckRingNumber判断该耳环是否存在
|
|
|
-func (s *StoreEntry) NeckRingIsExist(pastureId int64, number string) (*model.NeckRing, bool) {
|
|
|
- neckRing := &model.NeckRing{}
|
|
|
- if err := s.DB.Model(new(model.NeckRing)).
|
|
|
- Where("neck_ring_number = ?", number).
|
|
|
- Where("pasture_id = ?", pastureId).
|
|
|
- First(neckRing).Error; err != nil {
|
|
|
- if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
- return nil, false
|
|
|
- } else {
|
|
|
- return nil, false
|
|
|
- }
|
|
|
- }
|
|
|
- return neckRing, true
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) GetEventLogList(
|
|
|
- cowId int64, lact int32,
|
|
|
- eventCategoryId pasturePb.EventCategory_Kind,
|
|
|
- paginationModel *pasturePb.PaginationModel,
|
|
|
-) ([]*model.EventCowLog, error) {
|
|
|
- eventLogList := make([]*model.EventCowLog, 0)
|
|
|
- newEventCowLog := &model.EventCowLog{CowId: cowId}
|
|
|
- pref := s.DB.Table(newEventCowLog.TableName()).
|
|
|
- Where("cow_id = ?", cowId)
|
|
|
- if lact >= 0 {
|
|
|
- pref.Where("lact = ?", lact)
|
|
|
- }
|
|
|
-
|
|
|
- if eventCategoryId > 0 {
|
|
|
- pref.Where("event_category_id = ?", eventCategoryId)
|
|
|
- }
|
|
|
-
|
|
|
- if err := pref.Order("id desc").
|
|
|
- Offset(int(paginationModel.PageOffset)).
|
|
|
- Limit(int(paginationModel.PageSize)).
|
|
|
- Find(&eventLogList).Error; err != nil {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
- return eventLogList, nil
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) FindIndicatorsDetailsList(ctx context.Context) ([]*model.IndicatorsDetails, error) {
|
|
|
- list := make([]*model.IndicatorsDetails, 0)
|
|
|
- if err := s.DB.Model(new(model.IndicatorsDetails)).Find(&list).Error; err != nil {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
- return list, nil
|
|
|
-}
|
|
|
-
|
|
|
-func (s *StoreEntry) GetCowLastEvent(pastureId, cowId int64, eventCategoryId pasturePb.EventCategory_Kind) *model.EventCowLog {
|
|
|
- newEventCowLog := &model.EventCowLog{CowId: cowId}
|
|
|
- pref := s.DB.Table(newEventCowLog.TableName()).
|
|
|
- Where("cow_id = ?", cowId).Where("pasture_id = ?", pastureId)
|
|
|
- if eventCategoryId > 0 {
|
|
|
- pref.Where("event_category_kind = ?", eventCategoryId)
|
|
|
- }
|
|
|
-
|
|
|
- if err := pref.Order("id desc").
|
|
|
- First(newEventCowLog); err != nil {
|
|
|
- return nil
|
|
|
- }
|
|
|
- return newEventCowLog
|
|
|
-}
|
|
|
-
|
|
|
-// IsExistCalvingCalf 根据cowId查询犊牛信息
|
|
|
-func (s *StoreEntry) IsExistCalvingCalf(pastureId, cowId int64) (*model.CalvingCalf, bool) {
|
|
|
- calvingCalf := &model.CalvingCalf{}
|
|
|
- if err := s.DB.Model(new(model.CalvingCalf)).
|
|
|
- Where("cow_id = ?", cowId).
|
|
|
- Where("pasture_id = ?", pastureId).
|
|
|
- First(calvingCalf).Error; err != nil {
|
|
|
- if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
- return nil, false
|
|
|
- } else {
|
|
|
- return nil, false
|
|
|
- }
|
|
|
- }
|
|
|
- return calvingCalf, true
|
|
|
-}
|