|
@@ -134,6 +134,8 @@ func (s *StoreEntry) getCalendarCowList(
|
|
|
return s.TreatmentCowList(ctx, req, pagination)
|
|
|
case pasturePb.CalendarType_Mating: // 配种
|
|
|
return s.MatingCowList(ctx, req, pagination)
|
|
|
+ case pasturePb.CalendarType_Calving: // 产犊
|
|
|
+ return s.CalvingCowList(ctx, req, pagination)
|
|
|
default:
|
|
|
return nil, xerr.New("不支持的日历类型")
|
|
|
}
|
|
@@ -382,7 +384,8 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
|
|
|
pref.Where("a.status = ?", req.Status)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Order("a.id desc").Count(&count).
|
|
|
+ if err := pref.Order("a.id desc").
|
|
|
+ Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
|
Find(&matingItems).Error; err != nil {
|
|
@@ -413,10 +416,72 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
+func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingItemsResponse, error) {
|
|
|
+ calvingItems := make([]*pasturePb.CalvingItems, 0)
|
|
|
+ count := int64(0)
|
|
|
+ pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCalving).TableName())).
|
|
|
+ Select(`a.id,a.cow_id,a.status,b.breed_status,b.pen_id,DATE_FORMAT(FROM_UNIXTIME(last_mating_at), '%Y-%m-%d') AS mating_at_format,
|
|
|
+ b.day_age,b.last_bull_number as bull_id,DATEDIFF(NOW(),FROM_UNIXTIME(last_mating_at)) AS mating_age,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day`).
|
|
|
+ Joins("left join cow as b on a.cow_id = b.id").
|
|
|
+ Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission)
|
|
|
+
|
|
|
+ if req.EndDay != "" {
|
|
|
+ dateTime := util.TimeParseLocalEndUnix(req.EndDay)
|
|
|
+ pref.Where("a.plan_day <= ?", dateTime)
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.Status > 0 {
|
|
|
+ pref.Where("a.status = ?", req.Status)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := pref.Order("a.id desc").
|
|
|
+ Count(&count).
|
|
|
+ Limit(int(pagination.PageSize)).
|
|
|
+ Offset(int(pagination.PageOffset)).
|
|
|
+ Find(&calvingItems).Error; err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ breedStatusMap := s.CowBreedStatusMap()
|
|
|
+ for _, v := range calvingItems {
|
|
|
+ breedStatusName := ""
|
|
|
+ if breedStatus, ok := breedStatusMap[v.BreedStatus]; ok {
|
|
|
+ breedStatusName = breedStatus
|
|
|
+ }
|
|
|
+ v.BreedStatusName = breedStatusName
|
|
|
+ }
|
|
|
+
|
|
|
+ return &pasturePb.CalvingItemsResponse{
|
|
|
+ Code: http.StatusOK,
|
|
|
+ Message: "ok",
|
|
|
+ Data: &pasturePb.CalvingItemsData{
|
|
|
+ Total: int32(count),
|
|
|
+ Page: pagination.Page,
|
|
|
+ PageSize: pagination.PageSize,
|
|
|
+ Header: map[string]string{
|
|
|
+ "id": "编号",
|
|
|
+ "cowId": "牛号",
|
|
|
+ "breedStatusName": "繁殖状态",
|
|
|
+ "penName": "栏舍",
|
|
|
+ "lact": "胎次",
|
|
|
+ "matingAge": "配后天数",
|
|
|
+ "dayAge": "日龄",
|
|
|
+ "status": "是否完成",
|
|
|
+ "bullId": "配种公牛号",
|
|
|
+ "planDay": "预产时间",
|
|
|
+ },
|
|
|
+ List: calvingItems,
|
|
|
+ },
|
|
|
+ }, nil
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// WorkOrderCowList 暂时不处理工单业务
|
|
|
func (s *StoreEntry) WorkOrderCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (interface{}, error) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
+// TreatmentCowList 治疗清单
|
|
|
func (s *StoreEntry) TreatmentCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (interface{}, error) {
|
|
|
return nil, nil
|
|
|
}
|