|
@@ -37,7 +37,8 @@ func (s *StoreEntry) CalendarToDoList(ctx context.Context, req *pasturePb.Calend
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- sql := `SELECT a.cow_id,b.pen_name,a.calendar_type_name,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day,b.lact FROM (
|
|
|
+ sql := `SELECT a.cow_id,b.pen_name,a.calendar_type_name,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day,b.lact,
|
|
|
+ b.ear_number FROM (
|
|
|
SELECT cow_id,plan_day,'免疫' as calendar_type_name FROM event_immunization_plan WHERE status = 2 ` + pastureWhereSql + `
|
|
|
UNION ALL
|
|
|
SELECT cow_id,plan_day ,'同期' as calendar_type_name FROM event_cow_same_time WHERE status = 2 ` + pastureWhereSql + `
|
|
@@ -49,9 +50,9 @@ func (s *StoreEntry) CalendarToDoList(ctx context.Context, req *pasturePb.Calend
|
|
|
SELECT cow_id,plan_day ,'配种' as calendar_type_name FROM event_mating WHERE status = 2 ` + pastureWhereSql + `
|
|
|
UNION ALL
|
|
|
SELECT cow_id,plan_day ,'产犊' as calendar_type_name FROM event_calving WHERE status = 2 ` + pastureWhereSql + `
|
|
|
- ) as a JOIN cow b ON event_item.cow_id = c.id WHERE 1 = 1 `
|
|
|
+ ) as a JOIN cow b ON a.cow_id = b.id WHERE 1 = 1 `
|
|
|
|
|
|
- completeSql := fmt.Sprintf("%s %s ORDER BY a.plan_day DESC LIMIT %d OFFSET %d", sql, whereSql, pagination.PageSize, pagination.PageOffset)
|
|
|
+ completeSql := fmt.Sprintf("%s %s ORDER BY a.plan_day ASC LIMIT %d OFFSET %d", sql, whereSql, pagination.PageSize, pagination.PageOffset)
|
|
|
if err = s.DB.Raw(completeSql).Find(&calendarToDoList).Error; err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -126,7 +127,7 @@ func (s *StoreEntry) getCalendarCowList(
|
|
|
pagination *pasturePb.PaginationModel,
|
|
|
pastureId int64,
|
|
|
) (interface{}, error) {
|
|
|
- req := &pasturePb.ItemsRequest{EndDay: showDay, CalendarType: calendarType, Status: pasturePb.IsShow_No, PastureId: int32(pastureId)}
|
|
|
+ req := &pasturePb.ItemsRequest{EndDay: showDay, CalendarType: calendarType, PastureId: int32(pastureId)}
|
|
|
switch calendarType {
|
|
|
case pasturePb.CalendarType_Immunisation: // 免疫
|
|
|
return s.ImmunisationCowList(ctx, req, pagination)
|
|
@@ -155,33 +156,27 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
|
|
|
}
|
|
|
eventImmunizationPlanList := make([]*model.EventImmunizationPlan, 0)
|
|
|
count := int64(0)
|
|
|
- pref := s.DB.Model(new(model.EventImmunizationPlan)).
|
|
|
- Where("status = ?", pasturePb.IsShow_No).
|
|
|
- Where("pasture_id = ?", userModel.AppPasture.Id)
|
|
|
- if req.StartDay != "" {
|
|
|
- dateTime := util.TimeParseLocalUnix(req.StartDay)
|
|
|
- pref.Where("plan_day >= ?", dateTime)
|
|
|
- }
|
|
|
-
|
|
|
- if req.EndDay != "" {
|
|
|
- dateTime := util.TimeParseLocalEndUnix(req.EndDay)
|
|
|
- pref.Where("plan_day <= ?", dateTime)
|
|
|
+ pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventImmunizationPlan).TableName())).
|
|
|
+ Select("a.id,a.cow_id,a.plan_day,a.plan_name as immunization_plan_name,b.pen_name,b.day_age,b.ear_number").
|
|
|
+ Joins(fmt.Sprintf("JOIN %s AS b on a.cow_id = b.id", new(model.Cow).TableName())).
|
|
|
+ Where("a.status = ?", pasturePb.IsShow_No).
|
|
|
+ Where("a.pasture_id = ?", userModel.AppPasture.Id)
|
|
|
+ if req.StartDay != "" && req.EndDay != "" {
|
|
|
+ startTime := util.TimeParseLocalUnix(req.StartDay)
|
|
|
+ endTime := util.TimeParseLocalEndUnix(req.EndDay)
|
|
|
+ pref.Where("a.plan_day between ? and ?", startTime, endTime)
|
|
|
}
|
|
|
|
|
|
if req.CowId > 0 {
|
|
|
- pref.Where("cow_id = ?", req.CowId)
|
|
|
+ pref.Where("a.cow_id = ?", req.CowId)
|
|
|
}
|
|
|
|
|
|
if req.ImmunizationId > 0 {
|
|
|
- pref.Where("plan_id = ?", req.ImmunizationId)
|
|
|
+ pref.Where("a.plan_id = ?", req.ImmunizationId)
|
|
|
}
|
|
|
|
|
|
if req.PenId > 0 {
|
|
|
- pref.Where("pen_id = ?", req.PenId)
|
|
|
- }
|
|
|
-
|
|
|
- if req.Status > 0 {
|
|
|
- pref.Where("status = ?", req.Status)
|
|
|
+ pref.Where("b.pen_id = ?", req.PenId)
|
|
|
}
|
|
|
|
|
|
if err = pref.Order("id desc").
|
|
@@ -208,7 +203,6 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
|
|
|
"dayAge": "日龄",
|
|
|
"planDay": "免疫时间",
|
|
|
"immunizationPlanName": "免疫名称",
|
|
|
- "status": "状态",
|
|
|
},
|
|
|
List: model.EventImmunizationPlanSlice(eventImmunizationPlanList).ToPB(),
|
|
|
},
|
|
@@ -224,8 +218,8 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
|
|
|
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.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`).
|
|
|
+ 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,a.plan_day,
|
|
|
+ b.cow_type,b.day_age,b.calving_age,b.abortion_age,b.last_calving_at,b.last_abortion_at,b.lact,b.pen_name,b.mating_times`).
|
|
|
Joins("left join cow as b on a.cow_id = b.id").
|
|
|
Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
|
Where("a.pasture_id = ?", userModel.AppPasture.Id).
|
|
@@ -236,22 +230,13 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
|
|
|
pref.Where("a.plan_day <= ?", dateTime)
|
|
|
}
|
|
|
|
|
|
- if req.CalendarType > 0 {
|
|
|
- pref.Where("a.same_time_type = ?", req.CalendarType)
|
|
|
- }
|
|
|
-
|
|
|
if req.CowType > 0 {
|
|
|
pref.Where("b.cow_type = ?", req.CowType)
|
|
|
}
|
|
|
|
|
|
- if req.Status > 0 {
|
|
|
- pref.Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
- }
|
|
|
-
|
|
|
- if err = pref.Order("a.id desc").Count(&count).
|
|
|
+ if err = pref.Order("a.plan_day ASC").Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
|
- Order("id desc").
|
|
|
Find(&sameTimeBodyList).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
@@ -271,6 +256,7 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
|
|
|
"earNumber": "耳标号",
|
|
|
"breedStatusName": "繁殖状态",
|
|
|
"cowTypeName": "牛只类型",
|
|
|
+ "planDayAtFormat": "执行日期",
|
|
|
"penName": "栏舍",
|
|
|
"lact": "胎次",
|
|
|
"calvingAge": "产后天数",
|
|
@@ -304,11 +290,11 @@ func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.I
|
|
|
|
|
|
if req.EndDay != "" {
|
|
|
dateTime := util.TimeParseLocalEndUnix(req.EndDay)
|
|
|
- pref.Where("plan_day <= ?", dateTime)
|
|
|
+ pref.Where("a.plan_day <= ?", dateTime)
|
|
|
}
|
|
|
|
|
|
if req.CowType > 0 {
|
|
|
- pref.Where("cow_type = ?", req.CowType)
|
|
|
+ pref.Where("a.cow_type = ?", req.CowType)
|
|
|
}
|
|
|
|
|
|
if req.Status > 0 {
|
|
@@ -316,14 +302,13 @@ func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.I
|
|
|
}
|
|
|
|
|
|
if req.PregnantCheckType > 0 {
|
|
|
- pref.Where("pregnant_check_name = ?", model.PregnantCheckNameValueMap[req.PregnantCheckType])
|
|
|
+ pref.Where("a.pregnant_check_name = ?", model.PregnantCheckNameValueMap[req.PregnantCheckType])
|
|
|
}
|
|
|
|
|
|
- if err = pref.Order("id desc").
|
|
|
+ if err = pref.Order("a.plan_day ASC").
|
|
|
Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
|
- Order("id desc").
|
|
|
Find(&newPregnancyCheckItems).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
@@ -377,11 +362,7 @@ func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsReq
|
|
|
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).
|
|
|
+ if err = pref.Order("a.plan_day ASC").Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
|
Find(&weaningItems).Error; err != nil {
|
|
@@ -427,9 +408,8 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
|
|
|
WHEN 4 THEN '同期'
|
|
|
ELSE '其他'
|
|
|
END AS expose_estrus_type_name,
|
|
|
- b.breed_status,b.cow_type,b.pen_id,b.day_age,b.calving_age,b.abortion_age,c.name as pen_name`).
|
|
|
+ b.breed_status,b.cow_type,b.pen_id,b.day_age,b.calving_age,b.abortion_age,b.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("a.pasture_id = ?", userModel.AppPasture.Id).
|
|
|
Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
|
|
@@ -439,14 +419,10 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
|
|
|
}
|
|
|
|
|
|
if req.PenId > 0 {
|
|
|
- pref.Where("a.pen_id = ?", req.PenId)
|
|
|
- }
|
|
|
-
|
|
|
- if req.Status > 0 {
|
|
|
- pref.Where("a.status = ?", req.Status)
|
|
|
+ pref.Where("b.pen_id = ?", req.PenId)
|
|
|
}
|
|
|
|
|
|
- if err = pref.Order("a.id desc").
|
|
|
+ if err = pref.Order("a.plan_day ASC").
|
|
|
Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
@@ -504,7 +480,7 @@ func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsReq
|
|
|
pref.Where("a.status = ?", req.Status)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Order("a.id desc").
|
|
|
+ if err = pref.Order("a.plan_day ASC").
|
|
|
Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|