|
@@ -541,3 +541,57 @@ func (s *StoreEntry) FrozenSemenCreate(ctx context.Context, req *pasturePb.Searc
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func (s *StoreEntry) WeightList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchWeightEventResponse, error) {
|
|
|
+ weightList := make([]*pasturePb.SearchWeightList, 0)
|
|
|
+ var count int64 = 0
|
|
|
+ pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventWeight).TableName())).
|
|
|
+ Select(`a.id,a.cow_id,a.ear_number,a.weight / 100 as weight,a.lact,a.day_age,a.weight_at,a.remarks,a.created_at,
|
|
|
+ a.updated_at,a.staff_member_id,a.operation_id,b.name as staff_member_name,c.name as operation_name`).
|
|
|
+ Joins(fmt.Sprintf("JOIN %s AS b on a.staff_member_id = b.id", new(model.SystemUser).TableName())).
|
|
|
+ Joins(fmt.Sprintf("JOIN %s AS c on a.operation_id = c.id", new(model.SystemUser).TableName()))
|
|
|
+ if len(req.CowId) > 0 {
|
|
|
+ cowIds := strings.Split(req.CowId, ",")
|
|
|
+ pref.Where("a.cow_id IN ?", cowIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := pref.Order("a.id desc").
|
|
|
+ Count(&count).Limit(int(pagination.PageSize)).
|
|
|
+ Offset(int(pagination.PageOffset)).
|
|
|
+ Find(&weightList).Error; err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ return &pasturePb.SearchWeightEventResponse{
|
|
|
+ Code: http.StatusOK,
|
|
|
+ Message: "ok",
|
|
|
+ Data: &pasturePb.SearchWeightData{
|
|
|
+ List: weightList,
|
|
|
+ Total: int32(count),
|
|
|
+ PageSize: pagination.PageSize,
|
|
|
+ Page: pagination.Page,
|
|
|
+ },
|
|
|
+ }, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (s *StoreEntry) CreateWeight(ctx context.Context, req *pasturePb.WeightEventRequest) error {
|
|
|
+ if len(req.CowId) <= 0 {
|
|
|
+ return xerr.Custom("请选择相关牛只")
|
|
|
+ }
|
|
|
+ currentSystemUser, _ := s.GetCurrentSystemUser(ctx)
|
|
|
+ cowList := strings.Split(req.CowId, ",")
|
|
|
+ weightEvent := make([]*model.EventWeight, 0)
|
|
|
+ for _, cowIdStr := range cowList {
|
|
|
+ cowId, _ := strconv.ParseInt(cowIdStr, 10, 64)
|
|
|
+ cow, err := s.GetCowInfo(ctx, cowId)
|
|
|
+ if err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ weightEvent = append(weightEvent, model.NewEventWeight(cow, currentSystemUser.Id, req))
|
|
|
+ }
|
|
|
+ if len(weightEvent) <= 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ return s.DB.Create(weightEvent).Error
|
|
|
+}
|