|
@@ -12,17 +12,30 @@ import (
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
)
|
|
)
|
|
|
|
|
|
-// CalendarToDoList 获取日历待办列表
|
|
|
|
-func (s *StoreEntry) CalendarToDoList(ctx context.Context, req *pasturePb.CalendarToDoRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalendarToDoResponse, error) {
|
|
|
|
|
|
+func (s *StoreEntry) CalendarToDoCount(ctx context.Context) (*pasturePb.TodoCountResponse, error) {
|
|
userModel, err := s.GetUserModel(ctx)
|
|
userModel, err := s.GetUserModel(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ todoList, err := s.CalendarToDoHistoryList(ctx, userModel.AppPasture.Id, "")
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return &pasturePb.TodoCountResponse{
|
|
|
|
+ Code: http.StatusOK,
|
|
|
|
+ Msg: "ok",
|
|
|
|
+ Data: &pasturePb.TodoCountData{Count: int32(len(todoList))},
|
|
|
|
+ }, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *StoreEntry) CalendarToDoHistoryList(ctx context.Context, pastureId int64, earNumber string) ([]*pasturePb.CalendarToDoList, error) {
|
|
whereSql := ""
|
|
whereSql := ""
|
|
- if req.EarNumber != "" {
|
|
|
|
- whereSql += fmt.Sprintf(` AND ear_number = '%s' `, req.EarNumber)
|
|
|
|
|
|
+ if earNumber != "" {
|
|
|
|
+ whereSql += fmt.Sprintf(` AND ear_number = '%s' `, earNumber)
|
|
}
|
|
}
|
|
- whereSql += fmt.Sprintf(" AND pasture_id = %d AND end_day <= %d ", userModel.AppPasture.Id, util.TimeParseLocalEndUnix(time.Now().Format(model.LayoutDate2)))
|
|
|
|
|
|
+ whereSql += fmt.Sprintf(" AND pasture_id = %d AND end_day <= %d ", pastureId, util.TimeParseLocalEndUnix(time.Now().Format(model.LayoutDate2)))
|
|
|
|
|
|
calendarToDoList := make([]*pasturePb.CalendarToDoList, 0)
|
|
calendarToDoList := make([]*pasturePb.CalendarToDoList, 0)
|
|
sql := `SELECT a.cow_id,b.pen_name,a.calendar_type_name,a.calendar_type_kind as calendar_type,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day,a.remaining_days,b.lact,b.ear_number FROM (
|
|
sql := `SELECT a.cow_id,b.pen_name,a.calendar_type_name,a.calendar_type_kind as calendar_type,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day,a.remaining_days,b.lact,b.ear_number FROM (
|
|
@@ -40,35 +53,51 @@ func (s *StoreEntry) CalendarToDoList(ctx context.Context, req *pasturePb.Calend
|
|
UNION ALL
|
|
UNION ALL
|
|
SELECT cow_id,plan_day,'干奶' as calendar_type_name,9 as calendar_type_kind,TIMESTAMPDIFF(DAY, NOW(), FROM_UNIXTIME(end_day)) AS remaining_days FROM event_dry_milk WHERE status = 2` + whereSql + `
|
|
SELECT cow_id,plan_day,'干奶' as calendar_type_name,9 as calendar_type_kind,TIMESTAMPDIFF(DAY, NOW(), FROM_UNIXTIME(end_day)) AS remaining_days FROM event_dry_milk WHERE status = 2` + whereSql + `
|
|
UNION ALL
|
|
UNION ALL
|
|
- SELECT cow_id,disease_at as plan_day,'疾病' as calendar_type_name,7 as calendar_type_kind,0 AS remaining_days FROM event_cow_disease WHERE diagnosed_result IN (2,3) AND pasture_id = ` + fmt.Sprintf("%d", userModel.AppPasture.Id) + `
|
|
|
|
|
|
+ SELECT cow_id,disease_at as plan_day,'疾病' as calendar_type_name,7 as calendar_type_kind,0 AS remaining_days FROM event_cow_disease WHERE diagnosed_result IN (2,3) AND pasture_id = ` + fmt.Sprintf("%d", pastureId) + `
|
|
) as a JOIN cow b ON a.cow_id = b.id WHERE 1 = 1 `
|
|
) as a JOIN cow b ON a.cow_id = b.id WHERE 1 = 1 `
|
|
|
|
|
|
completeSql := fmt.Sprintf("%s ORDER BY a.plan_day DESC", sql)
|
|
completeSql := fmt.Sprintf("%s ORDER BY a.plan_day DESC", sql)
|
|
- if err = s.DB.Raw(completeSql).Find(&calendarToDoList).Error; err != nil {
|
|
|
|
|
|
+ if err := s.DB.Raw(completeSql).Find(&calendarToDoList).Error; err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
+ return calendarToDoList, nil
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// CalendarToDoList 获取日历待办列表
|
|
|
|
+func (s *StoreEntry) CalendarToDoList(ctx context.Context, req *pasturePb.CalendarToDoRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalendarToDoResponse, error) {
|
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pastureId := userModel.AppPasture.Id
|
|
|
|
+ calendarToDoList, err := s.CalendarToDoHistoryList(ctx, pastureId, req.EarNumber)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
|
|
nowTime := time.Now().Format(model.LayoutDate2)
|
|
nowTime := time.Now().Format(model.LayoutDate2)
|
|
todayCompletedSql := `SELECT a.count as count,a.calendar_type_name as calendar_type_name,a.calendar_type_kind as calendar_type_kind FROM (
|
|
todayCompletedSql := `SELECT a.count as count,a.calendar_type_name as calendar_type_name,a.calendar_type_kind as calendar_type_kind FROM (
|
|
- SELECT count('cow_id') as count,'免疫' as calendar_type_name,1 as calendar_type_kind FROM event_immunization_plan WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ?
|
|
|
|
|
|
+ SELECT count('cow_id') as count,'免疫' as calendar_type_name,1 as calendar_type_kind FROM event_immunization_plan WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ? AND pasture_id = ?
|
|
UNION ALL
|
|
UNION ALL
|
|
- SELECT count('cow_id') as count,'同期' as calendar_type_name,2 as calendar_type_kind FROM event_cow_same_time WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ?
|
|
|
|
|
|
+ SELECT count('cow_id') as count,'同期' as calendar_type_name,2 as calendar_type_kind FROM event_cow_same_time WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ? AND pasture_id = ?
|
|
UNION ALL
|
|
UNION ALL
|
|
- SELECT count('cow_id') as count,'孕检' as calendar_type_name,4 as calendar_type_kind FROM event_pregnant_check WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ?
|
|
|
|
|
|
+ SELECT count('cow_id') as count,'孕检' as calendar_type_name,4 as calendar_type_kind FROM event_pregnant_check WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ? AND pasture_id = ?
|
|
UNION ALL
|
|
UNION ALL
|
|
- SELECT count('cow_id') as count,'断奶' as calendar_type_name,6 as calendar_type_kind FROM event_weaning WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ?
|
|
|
|
|
|
+ SELECT count('cow_id') as count,'断奶' as calendar_type_name,6 as calendar_type_kind FROM event_weaning WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ? AND pasture_id = ?
|
|
UNION ALL
|
|
UNION ALL
|
|
- SELECT count('cow_id') as count,'配种' as calendar_type_name,8 as calendar_type_kind FROM event_mating WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ?
|
|
|
|
|
|
+ SELECT count('cow_id') as count,'配种' as calendar_type_name,8 as calendar_type_kind FROM event_mating WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ? AND pasture_id = ?
|
|
UNION ALL
|
|
UNION ALL
|
|
- SELECT count('cow_id') as count,'产犊' as calendar_type_name,9 as calendar_type_kind FROM event_calving WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ?
|
|
|
|
|
|
+ SELECT count('cow_id') as count,'产犊' as calendar_type_name,9 as calendar_type_kind FROM event_calving WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ? AND pasture_id = ?
|
|
UNION ALL
|
|
UNION ALL
|
|
- SELECT count('cow_id') as count,'干奶' as calendar_type_name,10 as calendar_type_kind FROM event_dry_milk WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ?
|
|
|
|
|
|
+ SELECT count('cow_id') as count,'干奶' as calendar_type_name,10 as calendar_type_kind FROM event_dry_milk WHERE status = 1 AND DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m-%d') = ? AND pasture_id = ?
|
|
UNION ALL
|
|
UNION ALL
|
|
- SELECT count('cow_id') as count,'疾病' as calendar_type_name,7 as calendar_type_kind FROM event_cow_disease WHERE diagnosed_result = 4 AND DATE_FORMAT(FROM_UNIXTIME(curable_at), '%Y-%m-%d') = ?
|
|
|
|
|
|
+ SELECT count('cow_id') as count,'疾病' as calendar_type_name,7 as calendar_type_kind FROM event_cow_disease WHERE diagnosed_result = 4 AND DATE_FORMAT(FROM_UNIXTIME(curable_at), '%Y-%m-%d') = ? AND pasture_id = ?
|
|
) as a `
|
|
) as a `
|
|
|
|
|
|
toDayCompletedList := make([]*model.TodayCompletedData, 0)
|
|
toDayCompletedList := make([]*model.TodayCompletedData, 0)
|
|
- if err = s.DB.Raw(todayCompletedSql, nowTime, nowTime, nowTime, nowTime, nowTime, nowTime, nowTime, nowTime).
|
|
|
|
|
|
+ if err = s.DB.Raw(todayCompletedSql, nowTime, pastureId, nowTime, pastureId, nowTime, pastureId, nowTime, pastureId, nowTime, pastureId, nowTime, pastureId, nowTime, pastureId, nowTime, pastureId).
|
|
Find(&toDayCompletedList).Error; err != nil {
|
|
Find(&toDayCompletedList).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|