|
@@ -100,15 +100,15 @@ func (s *StoreEntry) CalendarTableDetail(
|
|
|
req *pasturePb.CalendarTableRequest,
|
|
|
pagination *pasturePb.PaginationModel,
|
|
|
) (interface{}, error) {
|
|
|
- if req.Start != time.Now().Format(model.LayoutDate2) {
|
|
|
- return nil, xerr.Custom("只能获取当天的数据")
|
|
|
- }
|
|
|
-
|
|
|
userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
+ if req.Start != time.Now().Format(model.LayoutDate2) {
|
|
|
+ return nil, xerr.Custom("只能获取当天的数据")
|
|
|
+ }
|
|
|
+
|
|
|
newCalendar := &model.Calendar{}
|
|
|
if err = s.DB.Model(&model.Calendar{}).
|
|
|
Where("calendar_type = ?", req.CalendarType).
|
|
@@ -156,11 +156,15 @@ func (s *StoreEntry) getCalendarCowList(
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.ImmunizationItemsResponse, error) {
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
eventImmunizationPlanList := make([]*model.EventImmunizationPlan, 0)
|
|
|
count := int64(0)
|
|
|
pref := s.DB.Model(&model.EventImmunizationPlan{}).
|
|
|
Where("status = ?", pasturePb.IsShow_No).
|
|
|
- Where("pasture_id = ?", req.PastureId)
|
|
|
+ Where("pasture_id = ?", userModel.AppPasture.Id)
|
|
|
if req.StartDay != "" {
|
|
|
dateTime := util.TimeParseLocalUnix(req.StartDay)
|
|
|
pref.Where("plan_day >= ?", dateTime)
|
|
@@ -187,7 +191,7 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
|
|
|
pref.Where("status = ?", req.Status)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Order("id desc").
|
|
|
+ if err = pref.Order("id desc").
|
|
|
Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
@@ -206,6 +210,7 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
|
|
|
Header: map[string]string{
|
|
|
"id": "编号",
|
|
|
"cowId": "牛号",
|
|
|
+ "earNumber": "耳标号",
|
|
|
"penName": "栏舍",
|
|
|
"dayAge": "日龄",
|
|
|
"planDay": "免疫开始时间",
|
|
@@ -219,13 +224,18 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SameTimeItemResponse, error) {
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
sameTimeBodyList := make([]*model.SameTimeItemBody, 0)
|
|
|
count := int64(0)
|
|
|
pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCowSameTime).TableName())).
|
|
|
- Select("a.id,a.cow_id,a.pen_name,a.status,a.same_time_type,b.breed_status,a.same_time_name,b.cow_type,b.day_age,b.calving_age,b.abortion_age,b.last_calving_at,b.last_abortion_at").
|
|
|
+ Select(`a.id,a.cow_id,a.ear_number,a.pen_name,a.status,a.same_time_type,b.breed_status,a.same_time_name,
|
|
|
+ b.cow_type,b.day_age,b.calving_age,b.abortion_age,b.last_calving_at,b.last_abortion_at`).
|
|
|
Joins("left join cow as b on a.cow_id = b.id").
|
|
|
Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
|
- Where("a.pasture_id = ?", req.PastureId).
|
|
|
+ Where("a.pasture_id = ?", userModel.AppPasture.Id).
|
|
|
Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
|
|
|
if req.EndDay != "" {
|
|
@@ -245,7 +255,7 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
|
|
|
pref.Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
}
|
|
|
|
|
|
- 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)).
|
|
|
Order("id desc").
|
|
@@ -265,6 +275,7 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
|
|
|
Header: map[string]string{
|
|
|
"id": "编号",
|
|
|
"cowId": "牛号",
|
|
|
+ "earNumber": "耳标号",
|
|
|
"breedStatusName": "繁殖状态",
|
|
|
"cowTypeName": "牛只类型",
|
|
|
"penName": "栏舍",
|
|
@@ -285,13 +296,17 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyCheckItemsResponse, error) {
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
newPregnancyCheckItems := make([]*pasturePb.PregnancyCheckItems, 0)
|
|
|
var count int64
|
|
|
pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventPregnantCheck).TableName())).
|
|
|
- Select("a.id,a.cow_id,a.pen_id,a.status,b.breed_status,b.cow_type,b.day_age,b.calving_age,b.abortion_age,a.bull_id").
|
|
|
+ Select("a.id,a.cow_id,a.ear_number,a.pen_id,a.status,b.breed_status,b.cow_type,b.day_age,b.calving_age,b.abortion_age,a.bull_id").
|
|
|
Joins("left join cow as b on a.cow_id = b.id").
|
|
|
Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
|
- Where("a.pasture_id = ?", req.PastureId).
|
|
|
+ Where("a.pasture_id = ?", userModel.AppPasture.Id).
|
|
|
Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
|
|
|
if req.EndDay != "" {
|
|
@@ -330,6 +345,7 @@ func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.I
|
|
|
Header: map[string]string{
|
|
|
"id": "编号",
|
|
|
"cowId": "牛号",
|
|
|
+ "ear_number": "耳标号",
|
|
|
"cowTypeName": "牛只类型",
|
|
|
"penName": "栏舍",
|
|
|
"lact": "胎次",
|
|
@@ -349,16 +365,20 @@ func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.I
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.WeaningItemsResponse, error) {
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
weaningItems := make([]*pasturePb.WeaningItems, 0)
|
|
|
count := int64(0)
|
|
|
-
|
|
|
pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventWeaning).TableName())).
|
|
|
Select("a.*,b.day_age,c.name as pen_name").
|
|
|
Joins("left join cow as b on a.cow_id = b.id").
|
|
|
Joins("left join pen as c on a.before_pen_id = c.id").
|
|
|
Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
|
- Where("a.pasture_id = ?", req.PastureId).
|
|
|
- Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
+ Where("a.status = ?", pasturePb.IsShow_No).
|
|
|
+ Where("a.pasture_id = ?", userModel.AppPasture.Id)
|
|
|
|
|
|
if req.EndDay != "" {
|
|
|
dateTime := util.TimeParseLocalEndUnix(req.EndDay)
|
|
@@ -369,7 +389,7 @@ func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsReq
|
|
|
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(&weaningItems).Error; err != nil {
|
|
@@ -384,12 +404,13 @@ func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsReq
|
|
|
Page: pagination.Page,
|
|
|
PageSize: pagination.PageSize,
|
|
|
Header: map[string]string{
|
|
|
- "id": "编号",
|
|
|
- "cowId": "牛号",
|
|
|
- "penName": "栏舍",
|
|
|
- "planDay": "断奶日期",
|
|
|
- "dayAge": "日龄",
|
|
|
- "status": "状态",
|
|
|
+ "id": "编号",
|
|
|
+ "cowId": "牛号",
|
|
|
+ "ear_number": "耳标号",
|
|
|
+ "penName": "栏舍",
|
|
|
+ "planDay": "断奶日期",
|
|
|
+ "dayAge": "日龄",
|
|
|
+ "status": "状态",
|
|
|
},
|
|
|
List: weaningItems,
|
|
|
},
|
|
@@ -397,13 +418,18 @@ func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsReq
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingItemsResponse, error) {
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
matingItems := make([]*pasturePb.MatingItems, 0)
|
|
|
count := int64(0)
|
|
|
pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventMating).TableName())).
|
|
|
- Select("a.id,a.cow_id,a.status,b.breed_status,b.cow_type,b.pen_id,b.day_age,b.calving_age,b.abortion_age,c.name as pen_name").
|
|
|
+ Select(`a.id,a.cow_id,a.status,a.ear_number,b.breed_status,b.cow_type,b.pen_id,b.day_age,
|
|
|
+ b.calving_age,b.abortion_age,c.name as pen_name`).
|
|
|
Joins("left join cow as b on a.cow_id = b.id").
|
|
|
Joins("left join pen as c on a.pen_id = c.id").
|
|
|
- Where("").
|
|
|
+ Where("a.pasture_id = ?", userModel.AppPasture.Id).
|
|
|
Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
|
|
|
if req.EndDay != "" {
|
|
@@ -419,7 +445,7 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
|
|
|
pref.Where("a.status = ?", req.Status)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Order("a.id desc").
|
|
|
+ if err = pref.Order("a.id desc").
|
|
|
Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
@@ -437,6 +463,7 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
|
|
|
Header: map[string]string{
|
|
|
"id": "编号",
|
|
|
"cowId": "牛号",
|
|
|
+ "earNumber": "耳标号",
|
|
|
"breedStatusName": "繁殖状态",
|
|
|
"cowTypeName": "牛只类型",
|
|
|
"penName": "栏舍",
|
|
@@ -452,13 +479,18 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingItemsResponse, error) {
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
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,
|
|
|
+ Select(`a.id,a.cow_id,a.ear_number,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)
|
|
|
+ Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
|
+ Where("a.pasture_id = ?", userModel.AppPasture.Id)
|
|
|
|
|
|
if req.EndDay != "" {
|
|
|
dateTime := util.TimeParseLocalEndUnix(req.EndDay)
|
|
@@ -496,6 +528,7 @@ func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsReq
|
|
|
Header: map[string]string{
|
|
|
"id": "编号",
|
|
|
"cowId": "牛号",
|
|
|
+ "earNumber": "耳标号",
|
|
|
"breedStatusName": "繁殖状态",
|
|
|
"penName": "栏舍",
|
|
|
"lact": "胎次",
|