| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 | 
							- 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) {
 
- 	currentUser, err := s.GetCurrentSystemUser(ctx)
 
- 	if err != nil {
 
- 		return nil, xerr.Custom("当前用户信息错误,请退出重新登录")
 
- 	}
 
- 	cowList := make([]*model.Cow, 0)
 
- 	var count int64 = 0
 
- 	pref := s.DB.Model(new(model.Cow)).
 
- 		Where("pasture_id = ?", currentUser.PastureId)
 
- 	if len(req.CowId) > 0 {
 
- 		cowIds := strings.Split(req.CowId, ",")
 
- 		pref.Where("id IN ?", cowIds)
 
- 	}
 
- 	if req.Id > 0 {
 
- 		pref.Where("id = ?", req.Id)
 
- 	}
 
- 	if req.PenId > 0 {
 
- 		pref.Where("pen_id = ?", req.PenId)
 
- 	}
 
- 	if req.CowType > 0 {
 
- 		pref.Where("cow_type = ?", req.CowType)
 
- 	}
 
- 	if req.BreedStatus > 0 {
 
- 		pref.Where("breed_status = ?", req.BreedStatus)
 
- 	}
 
- 	if req.CowKind > 0 {
 
- 		pref.Where("cow_kind = ?", req.CowKind)
 
- 	}
 
- 	if req.Sex > 0 {
 
- 		pref.Where("sex = ?", req.Sex)
 
- 	}
 
- 	if req.Lact > 0 {
 
- 		pref.Where("lact = ?", req.Lact)
 
- 	}
 
- 	if req.CowSource > 0 {
 
- 		pref.Where("source_id = ?", req.CowSource)
 
- 	}
 
- 	if req.EarNumber != "" {
 
- 		pref.Where("ear_number = ?", req.EarNumber)
 
- 	}
 
- 	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)
 
- 	}
 
- 	penMap := s.PenMap(ctx, currentUser.PastureId)
 
- 	cowTypeMap := s.CowTypeMap()
 
- 	breedStatusMap := s.CowBreedStatusMap()
 
- 	cowKindMap := s.CowKindMap()
 
- 	cowSourceMap := s.CowSourceMap()
 
- 	admissionStatusMap := s.AdmissionStatusMap()
 
- 	healthStatusMap := s.HealthStatusMap()
 
- 	return &pasturePb.SearchCowListResponse{
 
- 		Code:    http.StatusOK,
 
- 		Message: "ok",
 
- 		Data: &pasturePb.SearchCowData{
 
- 			List: model.CowSlice(cowList).ToPB(penMap, cowTypeMap, breedStatusMap,
 
- 				cowKindMap, cowSourceMap, admissionStatusMap, healthStatusMap),
 
- 			Total:    int32(count),
 
- 			PageSize: pagination.PageSize,
 
- 			Page:     pagination.Page,
 
- 		},
 
- 	}, nil
 
- }
 
 
  |