Browse Source

event: 发情列表

Yi 1 month ago
parent
commit
77e5692408

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250213075704-04d28f7cc1b4
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250213100800-994fcef7c178
 	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

+ 8 - 0
go.sum

@@ -193,6 +193,14 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250212100748-0f1f0b733b1a h1:R8ys1+ph
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250212100748-0f1f0b733b1a/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250213075704-04d28f7cc1b4 h1:1og9G9acY6DAQIcDwzebzGln44iN/cQgsxCl2BtIg+U=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250213075704-04d28f7cc1b4/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250213095231-1b0f5b519ad7 h1:pVbZ/drwC1J38N/qD+ViiiCz2Q4mdX+bgVQxpGsPeNU=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250213095231-1b0f5b519ad7/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250213100110-e0ec5e535968 h1:2yr5yk82gT8j4qV8T4iFstiw5EhX5bJ+NGrfgvjmUB4=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250213100110-e0ec5e535968/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250213100400-33572489c398 h1:bLWaZq0NWBK0ggH/9xVh21+JcUTqkY0zbry/h7kd/FI=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250213100400-33572489c398/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250213100800-994fcef7c178 h1:lNDW0YZJxsgpdvf8AjIXXEi4MZuaozJ5cGVn46Wn8Fw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250213100800-994fcef7c178/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=

+ 0 - 22
http/handler/event/event_health.go

@@ -198,25 +198,3 @@ func CowDiseaseCurable(c *gin.Context) {
 		Data: &operationPb.Success{Success: true},
 	})
 }
-
-func EstrusList(c *gin.Context) {
-	var req pasturePb.EstrusItemsRequest
-	if err := ginutil.BindProto(c, &req); err != nil {
-		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
-		return
-	}
-
-	pagination := &pasturePb.PaginationModel{
-		Page:       int32(c.GetInt(middleware.Page)),
-		PageSize:   int32(c.GetInt(middleware.PageSize)),
-		PageOffset: int32(c.GetInt(middleware.PageOffset)),
-	}
-
-	res, err := middleware.BackendOperation(c).OpsService.EstrusList(c, &req, pagination)
-	if err != nil {
-		apierr.ClassifiedAbort(c, err)
-		return
-	}
-
-	ginutil.JSONResp(c, res)
-}

+ 35 - 0
http/handler/work/item.go

@@ -0,0 +1,35 @@
+package work
+
+import (
+	"kpt-pasture/http/middleware"
+	"net/http"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+	"gitee.com/xuyiping_admin/pkg/apierr"
+	"gitee.com/xuyiping_admin/pkg/ginutil"
+	"github.com/gin-gonic/gin"
+)
+
+func EstrusItem(c *gin.Context) {
+	c.JSON(http.StatusOK, gin.H{"result": "ok"})
+	return
+	var req pasturePb.EstrusItemsRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	pagination := &pasturePb.PaginationModel{
+		Page:       int32(c.GetInt(middleware.Page)),
+		PageSize:   int32(c.GetInt(middleware.PageSize)),
+		PageOffset: int32(c.GetInt(middleware.PageOffset)),
+	}
+
+	res, err := middleware.BackendOperation(c).OpsService.EstrusList(c, &req, pagination)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, res)
+}

+ 1 - 1
http/route/work_api.go

@@ -30,7 +30,7 @@ func WorkOrderAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		workRoute.POST("/weaning/items", work.WeaningCowList)
 		workRoute.POST("/mating/items", work.MatingCowList)
 		workRoute.POST("/calving/items", work.CalvingList)
+		workRoute.POST("/estrus/items", work.EstrusItem)
 		workRoute.POST("/disease/items", event.CowDiseaseList)
-		workRoute.POST("/estrus/items", event.EstrusList)
 	}
 }

+ 15 - 30
model/event_estrus.go

@@ -1,9 +1,6 @@
 package model
 
 import (
-	"fmt"
-	"kpt-pasture/store/kptstore"
-
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
@@ -69,34 +66,22 @@ func NewEventEstrus(
 
 type EventEstrusSlice []*EventEstrus
 
-func (e EventEstrusSlice) ToPB(
-	dB *kptstore.DB,
-	getCowInfo func(dB *kptstore.DB, cowId int64) *Cow,
-	getCowLastEvent func(DB *kptstore.DB, cowId int64, eventCategoryId pasturePb.EventCategory_Kind) *EventCowLog,
-) []*pasturePb.EstrusItems {
-	res := make([]*pasturePb.EstrusItems, len(e))
+func (e EventEstrusSlice) ToPB() []*pasturePb.SearchEventEstrusList {
+	res := make([]*pasturePb.SearchEventEstrusList, len(e))
 	for i, v := range e {
-		cowInfo := getCowInfo(dB, v.CowId)
-		lastEventLog := getCowLastEvent(dB, v.CowId, pasturePb.EventCategory_Breed)
-		planDay, optimumMatingTime := "", ""
-		lastBreedEventDetails := ""
-		if lastEventLog != nil {
-			lastBreedEventDetails = fmt.Sprintf("%s %s", lastEventLog.EventTypeName, lastEventLog.EventDescription)
-		}
-		res[i] = &pasturePb.EstrusItems{
-			Id:                     int32(v.Id),
-			CowId:                  int32(v.CowId),
-			EarNumber:              v.EarNumber,
-			DayAge:                 cowInfo.DayAge,
-			Lact:                   v.Lact,
-			PenName:                cowInfo.PenName,
-			Status:                 v.IsShow,
-			CalvingAge:             cowInfo.CalvingAge,
-			PlanDay:                planDay,
-			MatingTimes:            cowInfo.MatingTimes,
-			OptimumMatingStartTime: optimumMatingTime,
-			OptimumMatingEndTime:   optimumMatingTime,
-			LastBreedEventDetails:  lastBreedEventDetails,
+		res[i] = &pasturePb.SearchEventEstrusList{
+			Id:              int32(v.Id),
+			CowId:           int32(v.CowId),
+			EarNumber:       v.EarNumber,
+			DayAge:          v.DayAge,
+			Lact:            v.Lact,
+			EstrusAt:        int32(v.RealityDay),
+			IsMating:        v.IsMating,
+			UnMatingReasons: v.UnMatingReasonsName,
+			OperationName:   v.OperationName,
+			Remarks:         v.Remarks,
+			CreatedAt:       int32(v.CreatedAt),
+			UpdatedAt:       int32(v.UpdatedAt),
 		}
 	}
 	return res

+ 1 - 0
model/prescription_drugs.go

@@ -26,6 +26,7 @@ func NewPrescriptionDrugs(pastureId int64, prescriptionId int32, list []*pasture
 	res := make([]*PrescriptionDrugs, len(list))
 	for i, v := range list {
 		res[i] = &PrescriptionDrugs{
+			PastureId:      pastureId,
 			PrescriptionId: prescriptionId,
 			DrugsId:        int64(v.DrugsId),
 			DrugsName:      v.DrugsName,

+ 4 - 6
module/backend/event_breed.go

@@ -312,7 +312,7 @@ func (s *StoreEntry) SameTimeList(
 	}, nil
 }
 
-func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventEstrusResponse, error) {
+func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEventEstrusResponse, error) {
 	userModel, err := s.GetUserModel(ctx)
 	if err != nil {
 		return nil, xerr.WithStack(err)
@@ -345,13 +345,11 @@ func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsR
 		return nil, xerr.WithStack(err)
 	}
 
-	getCowInfoByCowId := GetCowInfoByCowId
-	getCowLastEvent := GetCowLastEvent
-	return &pasturePb.EventEstrusResponse{
+	return &pasturePb.SearchEventEstrusResponse{
 		Code: http.StatusOK,
 		Msg:  "ok",
-		Data: &pasturePb.EstrusItemsData{
-			List:     model.EventEstrusSlice(estrusList).ToPB(s.DB, getCowInfoByCowId, getCowLastEvent),
+		Data: &pasturePb.SearchEventEstrusData{
+			List:     model.EventEstrusSlice(estrusList).ToPB(),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,

+ 1 - 1
module/backend/interface.go

@@ -287,7 +287,7 @@ type WorkService interface {
 	MatingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingItemsResponse, error)
 	CalvingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingItemsResponse, error)
 	CowDiseaseList(ctx context.Context, req *pasturePb.SearchEventCowTreatmentRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowDiseaseResponse, error)
-	EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventEstrusResponse, error)
+	EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEventEstrusResponse, error)
 }
 
 type TestService interface {

+ 4 - 4
module/crontab/cow_cron.go

@@ -369,19 +369,19 @@ func (e *Entry) SystemBasicCrontab() error {
 			pref.Where("breed_status = ?", pasturePb.BreedStatus_Breeding).
 				Where("last_mating_at > ?", 0).
 				Where("DATE(FROM_UNIXTIME(last_mating_at)) BETWEEN DATE_SUB(CURDATE(), INTERVAL ? DAY) AND DATE_SUB(CURDATE(), INTERVAL ? DAY)", systemBasic.MaxValue, systemBasic.MinValue).
-				Where("NOT EXISTS (?)", fmt.Sprintf("SELECT 1 FROM event_pregnant_check WHERE event_pregnant_check.cow_id = cow.id AND event_pregnant_check.status = %d", pasturePb.IsShow_No))
+				Where("NOT EXISTS (SELECT 1 FROM event_pregnant_check WHERE event_pregnant_check.cow_id = cow.id AND event_pregnant_check.status = ?)", pasturePb.IsShow_No)
 		case model.PregnantCheckForSecond: // 复检清单 过滤初检空怀的牛只
 			pref.Where("breed_status IN (?)", []pasturePb.BreedStatus_Kind{pasturePb.BreedStatus_Pregnant}).
 				Where("last_mating_at > ?", 0).
 				Where("DATE(FROM_UNIXTIME(last_mating_at)) = ?", fmt.Sprintf("DATE_SUB(CURDATE(), INTERVAL %d DAY))", systemBasic.MinValue)).
-				Where("NOT EXISTS (?)", fmt.Sprintf("SELECT 1 FROM event_pregnant_check WHERE event_pregnant_check.cow_id = cow.id AND event_pregnant_check.status = %d", pasturePb.IsShow_No))
+				Where("NOT EXISTS (SELECT 1 FROM event_pregnant_check WHERE event_pregnant_check.cow_id = cow.id AND event_pregnant_check.status = ?)", pasturePb.IsShow_No)
 		case model.WeaningAge: // 断奶清单
 			pref.Where("day_age = ?", systemBasic.MinValue).
-				Where("NOT EXISTS (?)", fmt.Sprintf("SELECT 1 FROM event_weaning WHERE event_weaning.cow_id = cow.id AND event_weaning.status = %d", pasturePb.IsShow_No))
+				Where("NOT EXISTS (SELECT 1 FROM event_weaning WHERE event_weaning.cow_id = cow.id AND event_weaning.status = ?)", pasturePb.IsShow_No)
 		case model.PregnancyAge: // 产犊清单
 			pref.Where("pregnancy_age = ?", systemBasic.MinValue).
 				Where("breed_status = ?", pasturePb.BreedStatus_Pregnant).
-				Where("NOT EXISTS (?)", fmt.Sprintf("SELECT 1 FROM event_calving WHERE event_calving.cow_id = cow.id AND event_calving.status = %d", pasturePb.IsShow_No))
+				Where("NOT EXISTS (SELECT 1 FROM event_calving WHERE event_calving.cow_id = cow.id AND event_calving.status = ?)", pasturePb.IsShow_No)
 		default:
 			continue
 		}