event.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package backend
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-pasture/model"
  6. "net/http"
  7. "gitee.com/xuyiping_admin/pkg/logger/zaplog"
  8. "go.uber.org/zap"
  9. "gitee.com/xuyiping_admin/pkg/xerr"
  10. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  11. )
  12. func (s *StoreEntry) EnterList(ctx context.Context, req *pasturePb.SearchEnterEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEnterEventResponse, error) {
  13. eventEnterList := make([]*pasturePb.SearchEnterData, 0)
  14. var count int64 = 0
  15. pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventEnter).TableName())).
  16. Select("a.*,b.name as breed_status_name,c.name as cow_source_name ,d.name as cow_type_name,e.name as cow_kind_name,f.name as pen_name").
  17. Joins(fmt.Sprintf("JOIN %s AS b ON a.breed_status_id = b.id", new(model.ConfigBreedStatus).TableName())).
  18. Joins(fmt.Sprintf("JOIN %s AS c on a.cow_source_id = c.id", new(model.ConfigCowSource).TableName())).
  19. Joins(fmt.Sprintf("JOIN %s AS d on a.cow_type_id = d.id", new(model.ConfigCowType).TableName())).
  20. Joins(fmt.Sprintf("JOIN %s AS e ON a.cow_kind_id = e.id", new(model.ConfigCowKind).TableName())).
  21. Joins(fmt.Sprintf("JOIN %s AS f on a.pen_id = f.id", new(model.Pen).TableName()))
  22. if req.CowId > 0 {
  23. pref.Where("a.cow_id ?", req.CowId)
  24. }
  25. if err := pref.Order("a.id desc").
  26. Count(&count).Limit(int(pagination.PageSize)).
  27. Offset(int(pagination.PageOffset)).
  28. Find(&eventEnterList).Error; err != nil {
  29. return nil, xerr.WithStack(err)
  30. }
  31. return &pasturePb.SearchEnterEventResponse{
  32. Code: http.StatusOK,
  33. Message: "ok",
  34. Data: &pasturePb.SearchEnterEventData{
  35. List: eventEnterList,
  36. Total: int32(count),
  37. PageSize: pagination.PageSize,
  38. Page: pagination.Page,
  39. },
  40. }, nil
  41. }
  42. func (s *StoreEntry) CreateEnterEvent(ctx context.Context, req *pasturePb.SearchEnterData) error {
  43. zaplog.Info("CreateEnterEvent", zap.Any("req", req))
  44. return nil
  45. }