calendar.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package backend
  2. import (
  3. "context"
  4. "kpt-pasture/model"
  5. "net/http"
  6. "time"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. "gitee.com/xuyiping_admin/pkg/xerr"
  9. )
  10. func (s *StoreEntry) CalendarList(ctx context.Context, req *pasturePb.CalendarRequest) (*pasturePb.CalendarResponse, error) {
  11. calendarList := make([]*model.Calendar, 0)
  12. if err := s.DB.Model(&model.Calendar{}).
  13. Where("show_day >= ?", req.ShowStartDay).
  14. Where("show_day <= ?", req.ShowEndDay).
  15. Where("is_show = ?", pasturePb.IsShow_Ok).
  16. Find(&calendarList).Error; err != nil {
  17. return nil, xerr.WithStack(err)
  18. }
  19. return &pasturePb.CalendarResponse{
  20. Code: http.StatusOK,
  21. Message: "ok",
  22. Data: model.CalendarSlice(calendarList).ToPB(),
  23. }, nil
  24. }
  25. func (s *StoreEntry) CalendarTableDetail(
  26. ctx context.Context,
  27. req *pasturePb.CalendarTableRequest,
  28. pagination *pasturePb.PaginationModel,
  29. ) (interface{}, error) {
  30. if req.Start != time.Now().Format(model.LayoutDate2) {
  31. return nil, xerr.New("参数错误")
  32. }
  33. newCalendar := &model.Calendar{}
  34. if err := s.DB.Model(&model.Calendar{}).
  35. Where("calendar_type = ?", req.CalendarType).
  36. Where("show_day = ?", req.Start).
  37. Where("is_show = ?", pasturePb.IsShow_Ok).
  38. First(newCalendar).Error; err != nil {
  39. return nil, xerr.WithStack(err)
  40. }
  41. if newCalendar.Id == 0 {
  42. return nil, xerr.New("不存在该日历数据")
  43. }
  44. return s.getCalendarCowList(ctx, req.CalendarType, req.Start, pagination), nil
  45. }
  46. func (s *StoreEntry) getCalendarCowList(
  47. ctx context.Context,
  48. calendarType pasturePb.CalendarType_Kind,
  49. startDate string,
  50. pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  51. switch calendarType {
  52. case pasturePb.CalendarType_Immunisation: // 免疫
  53. return s.ImmunisationCowList(ctx, startDate, pagination)
  54. case pasturePb.CalendarType_PG: // 同期PG
  55. return s.PGCowList(ctx, startDate, pagination)
  56. case pasturePb.CalendarType_RnGH: // 同期RnGH
  57. return s.RnGHCowList(ctx, startDate, pagination)
  58. case pasturePb.CalendarType_Pregnancy_Check: // 孕检
  59. return s.PregnancyCheckCowList(ctx, startDate, pagination)
  60. case pasturePb.CalendarType_WorkOrder: // 工作单
  61. return s.WorkOrderCowList(ctx, startDate, pagination)
  62. case pasturePb.CalendarType_Weaning: // 断奶
  63. return s.WeaningCowList(ctx, startDate, pagination)
  64. case pasturePb.CalendarType_Treatment: // 治疗
  65. return s.TreatmentCowList(ctx, startDate, pagination)
  66. case pasturePb.CalendarType_Mating: // 配种
  67. return s.MatingCowList(ctx, startDate, pagination)
  68. default:
  69. return nil, xerr.New("不支持的日历类型")
  70. }
  71. }
  72. func (s *StoreEntry) ImmunisationCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  73. immunizationPlanCowList := make([]*model.ImmunizationPlanCow, 0)
  74. count := int64(0)
  75. if err := s.DB.Model(&model.ImmunizationPlanCow{}).
  76. Where("plan_start_time <= ?", dateTime).
  77. Where("status = ?", pasturePb.IsShow_No).
  78. Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
  79. Find(&immunizationPlanCowList).Error; err != nil {
  80. return nil, xerr.WithStack(err)
  81. }
  82. return &model.CalendarResponse{
  83. Code: http.StatusOK,
  84. Message: "ok",
  85. Data: &model.CalendarData{
  86. Total: int32(count),
  87. Page: pagination.Page,
  88. PageSize: pagination.PageSize,
  89. Header: model.ImmunizationCalendarHeader{
  90. Id: "id",
  91. CowId: "cowId",
  92. PlanStartTime: "planStartTime",
  93. ImmunizationPlanId: "immunizationPlanId",
  94. ImmunizationPlanName: "immunizationPlanName",
  95. Status: "status",
  96. },
  97. List: model.ImmunizationPlanCowSlice(immunizationPlanCowList).ToPB(),
  98. },
  99. }, nil
  100. }
  101. func (s *StoreEntry) PGCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  102. return nil, nil
  103. }
  104. func (s *StoreEntry) RnGHCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  105. return nil, nil
  106. }
  107. func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  108. return nil, nil
  109. }
  110. func (s *StoreEntry) WorkOrderCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  111. return nil, nil
  112. }
  113. func (s *StoreEntry) WeaningCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  114. return nil, nil
  115. }
  116. func (s *StoreEntry) TreatmentCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  117. return nil, nil
  118. }
  119. func (s *StoreEntry) MatingCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
  120. return nil, nil
  121. }