Yi 4 сар өмнө
parent
commit
c6d94741b2

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20241121031639-c1bda72e25b5
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20241122093434-2c4af4bddc59
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eclipse/paho.mqtt.golang v1.4.3

+ 6 - 0
go.sum

@@ -40,6 +40,12 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20241118130425-0268b6791546 h1:j6ocvgNQ
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241118130425-0268b6791546/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241121031639-c1bda72e25b5 h1:8UyjUjPax9gkjWtFnpaA1pzM3Dz9cu6Y4CzoAt9791U=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241121031639-c1bda72e25b5/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241122085413-8b760c95f985 h1:cLxh8njy76yUYbWq3LbBYIzrnBrkPp0OM/pBFgEIQ9A=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241122085413-8b760c95f985/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241122090558-77fd1cd65cb5 h1:XCxiDeGzfmmWObxBuqloJMGW+2NsOzJDVWw9NIAMAbE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241122090558-77fd1cd65cb5/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241122093434-2c4af4bddc59 h1:TxIsS8RgDS3hjM5YjdAvbwzYjD4Wr8nYDuUtj72aVYs=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241122093434-2c4af4bddc59/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b h1:w05MxH7yqveRlaRbxHhbif5YjPrJFodRPfOjYhXn7Zk=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 2 - 2
http/route/cow_api.go

@@ -12,7 +12,7 @@ func CowAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 			opt(s)
 		}
 		// CowAPI API 组  牛只信息
-		eventRoute := authRouteGroup(s, "/api/v1/cow/")
-		eventRoute.POST("/list", cow.List)
+		eventRoute := authRouteGroup(s, "/api/v1/search/")
+		eventRoute.POST("/cow/list", cow.List)
 	}
 }

+ 88 - 20
model/cow.go

@@ -64,31 +64,99 @@ func (c CowSlice) ToPB(
 	cowTypeMap map[pasturePb.CowType_Kind]string,
 	breedStatusMap map[pasturePb.BreedStatus_Kind]string,
 	cowKindMap map[pasturePb.CowKind_Kind]string,
-) []*pasturePb.SearchCowList {
-	res := make([]*pasturePb.SearchCowList, len(c))
+	cowSourceMap map[pasturePb.CowSource_Kind]string,
+	admissionStatusMap map[pasturePb.AdmissionStatus_Kind]string,
+	healthStatusMap map[pasturePb.HealthStatus_Kind]string,
+) []*pasturePb.CowDetails {
+	res := make([]*pasturePb.CowDetails, len(c))
 	for i, v := range c {
 		penName := ""
 		if pen, ok := penMap[v.PenId]; ok {
 			penName = pen.Name
 		}
-		res[i] = &pasturePb.SearchCowList{
-			CowId:           int32(v.Id),
-			Sex:             v.Sex,
-			NeckRingNumber:  v.NeckRingNumber,
-			EarNumber:       v.EarNumber,
-			PenId:           v.PenId,
-			PenName:         penName,
-			CowType:         int32(v.CowType),
-			Lact:            v.Lact,
-			CowTypeName:     cowTypeMap[v.CowType],
-			BreedStatus:     v.BreedStatus,
-			BreedStatusName: breedStatusMap[v.BreedStatus],
-			CowKind:         v.CowKind,
-			CowKindName:     cowKindMap[v.CowKind],
-			BirthAt:         int32(v.BirthAt),
-			BirthWeight:     int32(v.BirthWeight) / 1000,
-			CurrentWeight:   int32(v.CurrentWeight) / 1000,
-			LastWeightAt:    int32(v.LastWeightAt),
+
+		sex := "公"
+		if v.Sex == pasturePb.Genders_Female {
+			sex = "母"
+		}
+		lastWeightAtFormat := ""
+		if v.LastWeightAt > 0 {
+			lastWeightAtFormat = time.Unix(v.LastWeightAt, 0).Format(LayoutDate2)
+		}
+
+		isPregnantName := ""
+		if v.IsPregnant == pasturePb.IsShow_Ok {
+			isPregnantName = "已孕"
+		} else {
+			isPregnantName = "未孕"
+		}
+
+		admissionAtFormat := ""
+		if v.AdmissionAt > 0 {
+			admissionAtFormat = time.Unix(v.AdmissionAt, 0).Format(LayoutDate2)
+		}
+
+		birthAtFormat := ""
+		if v.BirthAt > 0 {
+			birthAtFormat = time.Unix(v.BirthAt, 0).Format(LayoutDate2)
+		}
+
+		weaningAtFormat := ""
+		if v.WeaningAt > 0 {
+			weaningAtFormat = time.Unix(v.WeaningAt, 0).Format(LayoutDate2)
+		}
+
+		firstMatingAtFormat := ""
+		if v.FirstMatingAt > 0 {
+			firstMatingAtFormat = time.Unix(v.FirstMatingAt, 0).Format(LayoutDate2)
+		}
+
+		lastMatingAtFormat := ""
+		if v.LastMatingAt > 0 {
+			lastMatingAtFormat = time.Unix(v.LastMatingAt, 0).Format(LayoutDate2)
+		}
+
+		lastPregnantCheckAtFormat := ""
+		if v.LastPregnantCheckAt > 0 {
+			lastPregnantCheckAtFormat = time.Unix(v.LastPregnantCheckAt, 0).Format(LayoutDate2)
+		}
+
+		lastCalvingAtFormat := ""
+		if v.LastCalvingAt > 0 {
+			lastCalvingAtFormat = time.Unix(v.LastCalvingAt, 0).Format(LayoutDate2)
+		}
+		res[i] = &pasturePb.CowDetails{
+			CowId:                     int32(v.Id),
+			Sex:                       sex,
+			NeckRingNumber:            v.NeckRingNumber,
+			PenName:                   penName,
+			Lact:                      v.Lact,
+			CowTypeName:               cowTypeMap[v.CowType],
+			BreedStatusName:           breedStatusMap[v.BreedStatus],
+			CowKindName:               cowKindMap[v.CowKind],
+			EarNumber:                 v.EarNumber,
+			BirthWeight:               float32(v.BirthWeight) / 1000,
+			CurrentWeight:             float32(v.CurrentWeight) / 1000,
+			DayAge:                    v.DayAge,
+			SourceName:                cowSourceMap[v.SourceId],
+			MontherNumber:             v.MotherNumber,
+			FatherNumber:              v.FatherNumber,
+			AdmissionStatusName:       admissionStatusMap[v.AdmissionStatus],
+			HealthStatusName:          healthStatusMap[v.HealthStatus],
+			IsPregnantName:            isPregnantName,
+			AdmissionAtFormat:         admissionAtFormat,
+			BirthAtFormat:             birthAtFormat,
+			WeaningAtFormat:           weaningAtFormat,
+			CalvingAge:                int32(v.GetCalvingAge()),
+			AbortionAge:               int32(v.AbortionAge),
+			MatingTimes:               v.MatingTimes,
+			FirstMatingAtFormat:       firstMatingAtFormat,
+			LastMatingAtFormat:        lastMatingAtFormat,
+			LastBullNumber:            v.LastBullNumber,
+			LastPregnantCheckAtFormat: lastPregnantCheckAtFormat,
+			LastWeightAtFormat:        lastWeightAtFormat,
+			LastCalvingAtFormat:       lastCalvingAtFormat,
+			//PregnancyAge:              v.PregnancyAge,
 		}
 	}
 	return res

+ 41 - 0
module/backend/config_data_extend.go

@@ -0,0 +1,41 @@
+package backend
+
+import (
+	"kpt-pasture/model"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+func (s *StoreEntry) AdmissionStatusEnumList(isAll string) []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	if isAll == model.IsAllYes {
+		configOptions = append(configOptions,
+			&pasturePb.ConfigOptionsList{
+				Value:    int32(pasturePb.AuditStatus_Invalid),
+				Label:    "全部",
+				Disabled: true,
+			})
+	}
+	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.AdmissionStatus_Admission),
+		Label:    "在群",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.AdmissionStatus_Die),
+		Label:    "死亡",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.AdmissionStatus_Out),
+		Label:    "淘汰",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.AdmissionStatus_Sale),
+		Label:    "售卖",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.AdmissionStatus_Transfer),
+		Label:    "转出",
+		Disabled: true,
+	})
+	return configOptions
+}

+ 41 - 9
module/backend/cow.go

@@ -14,20 +14,52 @@ import (
 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("admission_status = ?", pasturePb.AdmissionStatus_Admission)
+	pref := s.DB.Model(new(model.Cow))
 
 	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 LIKE ?", "%"+req.EarNumber+"%")
+		pref.Where("ear_number = ?", req.EarNumber)
 	}
 
 	if err := pref.Order("id desc").
-		Count(&count).Limit(int(pagination.PageSize)).
+		Count(&count).
+		Limit(int(pagination.PageSize)).
 		Offset(int(pagination.PageOffset)).
 		Find(&cowList).Error; err != nil {
 		return nil, xerr.WithStack(err)
@@ -37,11 +69,15 @@ func (s *StoreEntry) CowList(ctx context.Context, req *pasturePb.SearchEventRequ
 	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),
+			List: model.CowSlice(cowList).ToPB(penMap, cowTypeMap, breedStatusMap,
+				cowKindMap, cowSourceMap, admissionStatusMap, healthStatusMap),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,
@@ -49,7 +85,3 @@ func (s *StoreEntry) CowList(ctx context.Context, req *pasturePb.SearchEventRequ
 	}, nil
 
 }
-
-func (s *StoreEntry) CowDetail(ctx context.Context, req *pasturePb.SearchEventRequest) {
-
-}

+ 8 - 0
module/backend/enum_map.go

@@ -214,3 +214,11 @@ func (s *StoreEntry) AuditStatusMap() map[pasturePb.AuditStatus_Kind]string {
 	}
 	return res
 }
+
+func (s *StoreEntry) AdmissionStatusMap() map[pasturePb.AdmissionStatus_Kind]string {
+	res := make(map[pasturePb.AdmissionStatus_Kind]string)
+	for _, v := range s.AdmissionStatusEnumList("") {
+		res[pasturePb.AdmissionStatus_Kind(v.Value)] = v.Label
+	}
+	return res
+}