|
@@ -354,6 +354,7 @@ func (s *StoreEntry) PregnantCheckCreate(ctx context.Context, req *pasturePb.Pre
|
|
cowList := strings.Split(req.CowId, ",")
|
|
cowList := strings.Split(req.CowId, ",")
|
|
eventPregnantCheckList := make([]*model.EventPregnantCheck, 0)
|
|
eventPregnantCheckList := make([]*model.EventPregnantCheck, 0)
|
|
currentUser, _ := s.GetCurrentSystemUser(ctx)
|
|
currentUser, _ := s.GetCurrentSystemUser(ctx)
|
|
|
|
+
|
|
for _, v := range cowList {
|
|
for _, v := range cowList {
|
|
cowId, _ := strconv.ParseInt(v, 10, 64)
|
|
cowId, _ := strconv.ParseInt(v, 10, 64)
|
|
cow, err := s.GetCowInfo(ctx, cowId)
|
|
cow, err := s.GetCowInfo(ctx, cowId)
|
|
@@ -368,3 +369,56 @@ func (s *StoreEntry) PregnantCheckCreate(ctx context.Context, req *pasturePb.Pre
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingEventResponse, error) {
|
|
|
|
+ matingList := make([]*model.EventMating, 0)
|
|
|
|
+ var count int64 = 0
|
|
|
|
+ pref := s.DB.Table(new(model.EventMating).TableName())
|
|
|
|
+ if len(req.CowId) > 0 {
|
|
|
|
+ cowIds := strings.Split(req.CowId, ",")
|
|
|
|
+ pref.Where("cow_id IN ?", cowIds)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err := pref.Order("id desc").
|
|
|
|
+ Count(&count).Limit(int(pagination.PageSize)).
|
|
|
|
+ Offset(int(pagination.PageOffset)).
|
|
|
|
+ Find(&matingList).Error; err != nil {
|
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ systemUserList, _ := s.SystemUserList(ctx)
|
|
|
|
+ exposeEstrusTypeMap := s.ExposeEstrusTypeMap()
|
|
|
|
+ return &pasturePb.MatingEventResponse{
|
|
|
|
+ Code: http.StatusOK,
|
|
|
|
+ Message: "ok",
|
|
|
|
+ Data: &pasturePb.SearchMatingData{
|
|
|
|
+ List: model.EventMatingSlice(matingList).ToPB(systemUserList, exposeEstrusTypeMap),
|
|
|
|
+ Total: int32(count),
|
|
|
|
+ PageSize: pagination.PageSize,
|
|
|
|
+ Page: pagination.Page,
|
|
|
|
+ },
|
|
|
|
+ }, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.MatingEventRequest) error {
|
|
|
|
+ if len(req.CowId) <= 0 {
|
|
|
|
+ return xerr.Custom("请选择相关牛只")
|
|
|
|
+ }
|
|
|
|
+ cowList := strings.Split(req.CowId, ",")
|
|
|
|
+ matingList := make([]*model.EventMating, 0)
|
|
|
|
+ currentUser, _ := s.GetCurrentSystemUser(ctx)
|
|
|
|
+
|
|
|
|
+ for _, v := range cowList {
|
|
|
|
+ cowId, _ := strconv.ParseInt(v, 10, 64)
|
|
|
|
+ cow, err := s.GetCowInfo(ctx, cowId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+ matingList = append(matingList, model.NewEventMating(cow, currentUser, req))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err := s.DB.Create(matingList).Error; err != nil {
|
|
|
|
+ return xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|