12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package backend
- import (
- "context"
- "kpt-pasture/model"
- "net/http"
- "strings"
- "gitee.com/xuyiping_admin/pkg/xerr"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- func (s *StoreEntry) CowList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchCowListResponse, error) {
- cowList := make([]*model.Cow, 0)
- var count int64 = 0
- pref := s.DB.Model(&model.Cow{}).Where("is_remove = ?", pasturePb.IsShow_Ok)
- if len(req.CowId) > 0 {
- cowIds := strings.Split(req.CowId, ",")
- pref.Where("id IN ?", cowIds)
- }
- if err := pref.Order("id desc").
- Count(&count).Limit(int(pagination.PageSize)).
- Offset(int(pagination.PageOffset)).
- Find(&cowList).Error; err != nil {
- return nil, xerr.WithStack(err)
- }
- penList, _ := s.GetPenList(ctx)
- cowTypeMap := s.CowTypeMap()
- breedStatusMap := s.CowBreedStatusMap()
- cowKindMap := s.CowKindMap()
- return &pasturePb.SearchCowListResponse{
- Code: http.StatusOK,
- Message: "ok",
- Data: &pasturePb.SearchCowData{
- List: model.CowSlice(cowList).ToPB(penList, cowTypeMap, breedStatusMap, cowKindMap),
- Total: int32(count),
- PageSize: pagination.PageSize,
- Page: pagination.Page,
- },
- }, nil
- }
|