|
@@ -201,10 +201,28 @@ func (s *StoreEntry) AlreadySale(ctx context.Context, req *pasturePb.AlreadySale
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- cowKindMap := s.CowKindMap()
|
|
|
+ cowIds := make([]int64, 0)
|
|
|
+ for _, v := range eventSaleCowList {
|
|
|
+ cowIds = append(cowIds, v.CowId)
|
|
|
+ }
|
|
|
+
|
|
|
+ cowList := make([]*model.Cow, 0)
|
|
|
+ if err = s.DB.Model(new(model.Cow)).
|
|
|
+ Where("id IN ?", cowIds).
|
|
|
+ Where("pasture_id = ?", pastureId).
|
|
|
+ Find(&cowList).Error; err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ cowMap := make(map[int64]*model.Cow)
|
|
|
+ for _, v := range cowList {
|
|
|
+ cowMap[v.Id] = v
|
|
|
+ }
|
|
|
|
|
|
+ sourceMap := s.CowSourceMap()
|
|
|
+ cowKindMap := s.CowKindMap()
|
|
|
result.Data.Total = int32(len(eventSaleCowList))
|
|
|
- result.Data.List = model.EventSaleCowSlice(eventSaleCowList).ToPB(eventSaleMap, cowKindMap)
|
|
|
+ result.Data.List = model.EventSaleCowSlice(eventSaleCowList).ToPB(eventSaleMap, cowKindMap, cowMap, sourceMap)
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
@@ -219,7 +237,19 @@ func (s *StoreEntry) CanSale(ctx context.Context, req *pasturePb.CanSalesReportR
|
|
|
var count int64
|
|
|
pref := s.DB.Model(new(model.Cow)).
|
|
|
Where("pasture_id = ?", pastureId).
|
|
|
- Where("current_weight BETWEEN ? AND ?", req.WeightStart, req.WeightEnd)
|
|
|
+ Where("current_weight BETWEEN ? AND ?", req.WeightStart*1000, req.WeightEnd*1000)
|
|
|
+
|
|
|
+ if req.BatchNumber != "" {
|
|
|
+ pref.Where("batch_number = ?", req.BatchNumber)
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.CowKind > pasturePb.CowKind_Invalid {
|
|
|
+ pref.Where("cow_kind = ?", req.CowKind)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(req.PenId) > 0 {
|
|
|
+ pref.Where("pen_id IN ?", req.PenId)
|
|
|
+ }
|
|
|
|
|
|
if err = pref.Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|