package backend import ( "context" "fmt" "kpt-pasture/model" "net/http" "gitee.com/xuyiping_admin/pkg/logger/zaplog" "go.uber.org/zap" "gitee.com/xuyiping_admin/pkg/xerr" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) func (s *StoreEntry) EnterList(ctx context.Context, req *pasturePb.SearchEnterEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEnterEventResponse, error) { eventEnterList := make([]*pasturePb.SearchEnterData, 0) var count int64 = 0 pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventEnter).TableName())). 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"). Joins(fmt.Sprintf("JOIN %s AS b ON a.breed_status_id = b.id", new(model.ConfigBreedStatus).TableName())). Joins(fmt.Sprintf("JOIN %s AS c on a.cow_source_id = c.id", new(model.ConfigCowSource).TableName())). Joins(fmt.Sprintf("JOIN %s AS d on a.cow_type_id = d.id", new(model.ConfigCowType).TableName())). Joins(fmt.Sprintf("JOIN %s AS e ON a.cow_kind_id = e.id", new(model.ConfigCowKind).TableName())). Joins(fmt.Sprintf("JOIN %s AS f on a.pen_id = f.id", new(model.Pen).TableName())) if req.CowId > 0 { pref.Where("a.cow_id ?", req.CowId) } if err := pref.Order("a.id desc"). Count(&count).Limit(int(pagination.PageSize)). Offset(int(pagination.PageOffset)). Find(&eventEnterList).Error; err != nil { return nil, xerr.WithStack(err) } return &pasturePb.SearchEnterEventResponse{ Code: http.StatusOK, Message: "ok", Data: &pasturePb.SearchEnterEventData{ List: eventEnterList, Total: int32(count), PageSize: pagination.PageSize, Page: pagination.Page, }, }, nil } func (s *StoreEntry) CreateEnterEvent(ctx context.Context, req *pasturePb.SearchEnterData) error { zaplog.Info("CreateEnterEvent", zap.Any("req", req)) return nil }