|
@@ -2,6 +2,7 @@ package backend
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
|
|
+ "fmt"
|
|
"kpt-pasture/model"
|
|
"kpt-pasture/model"
|
|
"net/http"
|
|
"net/http"
|
|
"time"
|
|
"time"
|
|
@@ -10,6 +11,8 @@ import (
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+// CalendarList
|
|
|
|
+// /*func (s StoreEntry) CalendarToDoList(ctx context.Context) (*pasturePb.CalendarToDoListResponse, error) {
|
|
func (s *StoreEntry) CalendarList(ctx context.Context, req *pasturePb.CalendarRequest) (*pasturePb.CalendarResponse, error) {
|
|
func (s *StoreEntry) CalendarList(ctx context.Context, req *pasturePb.CalendarRequest) (*pasturePb.CalendarResponse, error) {
|
|
calendarList := make([]*model.Calendar, 0)
|
|
calendarList := make([]*model.Calendar, 0)
|
|
if err := s.DB.Model(&model.Calendar{}).
|
|
if err := s.DB.Model(&model.Calendar{}).
|
|
@@ -59,10 +62,8 @@ func (s *StoreEntry) getCalendarCowList(
|
|
switch calendarType {
|
|
switch calendarType {
|
|
case pasturePb.CalendarType_Immunisation: // 免疫
|
|
case pasturePb.CalendarType_Immunisation: // 免疫
|
|
return s.ImmunisationCowList(ctx, startDate, pagination)
|
|
return s.ImmunisationCowList(ctx, startDate, pagination)
|
|
- case pasturePb.CalendarType_PG: // 同期PG
|
|
|
|
- return s.PGCowList(ctx, startDate, pagination)
|
|
|
|
- case pasturePb.CalendarType_RnGH: // 同期RnGH
|
|
|
|
- return s.RnGHCowList(ctx, startDate, pagination)
|
|
|
|
|
|
+ case pasturePb.CalendarType_PG, pasturePb.CalendarType_RnGH: // 同期
|
|
|
|
+ return s.SameTimeCowList(ctx, startDate, pagination, calendarType)
|
|
case pasturePb.CalendarType_Pregnancy_Check: // 孕检
|
|
case pasturePb.CalendarType_Pregnancy_Check: // 孕检
|
|
return s.PregnancyCheckCowList(ctx, startDate, pagination)
|
|
return s.PregnancyCheckCowList(ctx, startDate, pagination)
|
|
case pasturePb.CalendarType_WorkOrder: // 工作单
|
|
case pasturePb.CalendarType_WorkOrder: // 工作单
|
|
@@ -97,12 +98,11 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, dateTime string, p
|
|
Page: pagination.Page,
|
|
Page: pagination.Page,
|
|
PageSize: pagination.PageSize,
|
|
PageSize: pagination.PageSize,
|
|
Header: model.ImmunizationCalendarHeader{
|
|
Header: model.ImmunizationCalendarHeader{
|
|
- Id: "id",
|
|
|
|
- CowId: "cowId",
|
|
|
|
- PlanStartTime: "planStartTime",
|
|
|
|
- ImmunizationPlanId: "immunizationPlanId",
|
|
|
|
- ImmunizationPlanName: "immunizationPlanName",
|
|
|
|
- Status: "status",
|
|
|
|
|
|
+ Id: "编号",
|
|
|
|
+ CowId: "牛号",
|
|
|
|
+ PlanStartTime: "免疫开始时间",
|
|
|
|
+ ImmunizationPlanName: "免疫名称",
|
|
|
|
+ Status: "状态",
|
|
},
|
|
},
|
|
List: model.ImmunizationPlanCowSlice(immunizationPlanCowList).ToPB(),
|
|
List: model.ImmunizationPlanCowSlice(immunizationPlanCowList).ToPB(),
|
|
},
|
|
},
|
|
@@ -110,17 +110,33 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, dateTime string, p
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) PGCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
|
|
|
|
- sameTimeCowDetailList := make([]*model.SameTimeCowDetail, 0)
|
|
|
|
|
|
+func (s *StoreEntry) SameTimeCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel, calendarType pasturePb.CalendarType_Kind) (*model.CalendarResponse, error) {
|
|
|
|
+ sameTimeBodyList := make([]*model.SameTimeBody, 0)
|
|
count := int64(0)
|
|
count := int64(0)
|
|
- if err := s.DB.Model(&model.SameTimeCowDetail{}).
|
|
|
|
- Where("plan_start_time <= ?", dateTime).
|
|
|
|
- Where("status = ?", pasturePb.IsShow_No).
|
|
|
|
- Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
|
|
|
|
- Find(&sameTimeCowDetailList).Error; err != nil {
|
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
|
|
|
+ pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.SameTimeCowDetail).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").
|
|
|
|
+ Joins("left join cow as b on a.cow_id = b.id").
|
|
|
|
+ Where("b.is_remove = ?", pasturePb.IsShow_No).
|
|
|
|
+ Where("a.plan_day <= ?", dateTime).
|
|
|
|
+ Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
|
+
|
|
|
|
+ if calendarType == pasturePb.CalendarType_PG {
|
|
|
|
+ pref.Where("a.same_time_type = ?", calendarType)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if calendarType == pasturePb.CalendarType_RnGH {
|
|
|
|
+ pref.Where("a.same_time_type = ?", calendarType)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err := pref.Order("a.id desc").Count(&count).
|
|
|
|
+ Limit(int(pagination.PageSize)).
|
|
|
|
+ Offset(int(pagination.PageOffset)).
|
|
|
|
+ Find(&sameTimeBodyList).Error; err != nil {
|
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+ cowTypeMap := s.CowTypeMap()
|
|
|
|
+ breedStatusMap := s.CowBreedStatusMap()
|
|
|
|
+ penMap := s.PenMap(ctx)
|
|
return &model.CalendarResponse{
|
|
return &model.CalendarResponse{
|
|
Code: http.StatusOK,
|
|
Code: http.StatusOK,
|
|
Message: "ok",
|
|
Message: "ok",
|
|
@@ -129,26 +145,22 @@ func (s *StoreEntry) PGCowList(ctx context.Context, dateTime string, pagination
|
|
Page: pagination.Page,
|
|
Page: pagination.Page,
|
|
PageSize: pagination.PageSize,
|
|
PageSize: pagination.PageSize,
|
|
Header: model.SameTimeHeader{
|
|
Header: model.SameTimeHeader{
|
|
- Id: "id",
|
|
|
|
- CowId: "cowId",
|
|
|
|
- BreedStatus: "breedStatus",
|
|
|
|
- PenName: "penName",
|
|
|
|
- Lact: "lact",
|
|
|
|
- CalvingAge: "calvingAge",
|
|
|
|
- AbortionAge: "abortionAge",
|
|
|
|
- DayAge: "dayAge",
|
|
|
|
- Status: "status",
|
|
|
|
- ExecType: "execType",
|
|
|
|
|
|
+ Id: "编号",
|
|
|
|
+ CowId: "牛号",
|
|
|
|
+ BreedStatusName: "繁殖状态",
|
|
|
|
+ CowTypeName: "牛只类型",
|
|
|
|
+ PenName: "栏舍",
|
|
|
|
+ Lact: "胎次",
|
|
|
|
+ CalvingAge: "产后天数",
|
|
|
|
+ AbortionAge: "流产天数",
|
|
|
|
+ DayAge: "日龄",
|
|
|
|
+ Status: "状态",
|
|
},
|
|
},
|
|
- List: model.SameTimeCowDetailSlice(sameTimeCowDetailList).ToPB(),
|
|
|
|
|
|
+ List: model.SameTimeBodySlice(sameTimeBodyList).ToPB(cowTypeMap, breedStatusMap, penMap),
|
|
},
|
|
},
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) RnGHCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
|
|
|
|
- return nil, nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
|
|
func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
|
|
return nil, nil
|
|
return nil, nil
|
|
}
|
|
}
|
|
@@ -158,7 +170,42 @@ func (s *StoreEntry) WorkOrderCowList(ctx context.Context, dateTime string, pagi
|
|
}
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) WeaningCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
|
|
func (s *StoreEntry) WeaningCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
|
|
- return nil, nil
|
|
|
|
|
|
+ weaningBodyList := make([]*model.WeaningBody, 0)
|
|
|
|
+ count := int64(0)
|
|
|
|
+ dateTime = dateTime + " 23:59:59" // todo 转换成时间戳
|
|
|
|
+
|
|
|
|
+ pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.SameTimeCowDetail).TableName())).
|
|
|
|
+ Select("a.*,b.day_age").
|
|
|
|
+ Joins("left join cow as b on a.cow_id = b.id").
|
|
|
|
+ Where("b.is_remove = ?", pasturePb.IsShow_No).
|
|
|
|
+ Where("a.plan_day <= ?", dateTime).
|
|
|
|
+ Where("a.status = ?", pasturePb.IsShow_No)
|
|
|
|
+
|
|
|
|
+ if err := pref.Order("a.id desc").Count(&count).
|
|
|
|
+ Limit(int(pagination.PageSize)).
|
|
|
|
+ Offset(int(pagination.PageOffset)).
|
|
|
|
+ Find(&weaningBodyList).Error; err != nil {
|
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return &model.CalendarResponse{
|
|
|
|
+ Code: http.StatusOK,
|
|
|
|
+ Message: "ok",
|
|
|
|
+ Data: &model.CalendarData{
|
|
|
|
+ Total: int32(count),
|
|
|
|
+ Page: pagination.Page,
|
|
|
|
+ PageSize: pagination.PageSize,
|
|
|
|
+ Header: model.WeaningHeader{
|
|
|
|
+ Id: "编号",
|
|
|
|
+ CowId: "牛号",
|
|
|
|
+ PenName: "栏舍",
|
|
|
|
+ PlanDay: "断奶日期",
|
|
|
|
+ DayAge: "日龄",
|
|
|
|
+ Status: "状态",
|
|
|
|
+ },
|
|
|
|
+ List: weaningBodyList,
|
|
|
|
+ },
|
|
|
|
+ }, nil
|
|
}
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) TreatmentCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
|
|
func (s *StoreEntry) TreatmentCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
|