Explorar o código

cowDisease: 疾病治疗详情

Yi hai 5 meses
pai
achega
62b9b7e8c5

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20241022063225-d34353c88fd2
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20241023073355-19a0c4c38a5a
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241010101255-0c6bd229b939
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eko/gocache v1.1.0

+ 12 - 0
go.sum

@@ -98,6 +98,18 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20241021095634-62b455bd33a1 h1:umkLXvBm
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241021095634-62b455bd33a1/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241022063225-d34353c88fd2 h1:oDKwxyg5gnNuHIcjSIJXFIGhPxEUcAXJTTevZShpL5g=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241022063225-d34353c88fd2/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241022072049-792c54387a3e h1:jzPQ7lMEWMKr1wqaxgs6TIyPdmmSexNA82WwSpcaRYE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241022072049-792c54387a3e/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023035107-bcad0081b029 h1:Q3Z4UOaHnR/KMpRlycfl6JifFK1VUHEe8VtzKOJMh0c=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023035107-bcad0081b029/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023053142-1182de347f3c h1:pRgoopd3kZUnIxKLcPagcVZ8cEeKxTlhyH2nzxpBtWc=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023053142-1182de347f3c/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023063806-2a544733ca7f h1:DpwlDgZ4in0gtX3SnAD/b8+i/xYj9HhDGuOS8RxHUwk=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023063806-2a544733ca7f/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023064328-b40bdd7fbde6 h1:0NflcKQrgC0lFBxDr/JtKMtA8n6Epi9sEEbBYt729dM=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023064328-b40bdd7fbde6/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023073355-19a0c4c38a5a h1:7GFvstT8R48anOv757i18W4H0EsbHwvh/+v1o5ZiycU=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241023073355-19a0c4c38a5a/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015 h1:dfb5dRd57L2HKjdwLT93UFmPYFPOmEl56gtZmqcNnaE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015/go.mod h1:Fk4GYI/v0IK3XFrm1Gn+VkgCz5Y7mfswD5hsTJYOG6A=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241008063555-121a776fd331 h1:qJcpJ3o+O7uxDqR0I9LijQmi607IKvhf4mGum/ZUPT0=

+ 2 - 2
http/handler/config/config.go

@@ -37,8 +37,8 @@ func BarnListOptions(c *gin.Context) {
 }
 
 func DiseaseTypeOptions(c *gin.Context) {
-	isAll := c.Query("is_children")
-	res, err := middleware.Dependency(c).StoreEventHub.OpsService.DiseaseTypeOptions(c, isAll)
+	isChildren := c.Query("is_children")
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.DiseaseTypeOptions(c, isChildren)
 	if err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return

+ 33 - 3
http/handler/event/event_health.go

@@ -13,7 +13,7 @@ import (
 )
 
 func CowDiseaseCreate(c *gin.Context) {
-	var req pasturePb.EventCowDisease
+	var req pasturePb.EventCowDiseaseRequest
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
@@ -74,7 +74,6 @@ func CowDiseaseDiagnose(c *gin.Context) {
 		valid.Field(&req.Id, valid.Required),
 		valid.Field(&req.CowId, valid.Required),
 		valid.Field(&req.DiagnosedResult, valid.Required),
-		valid.Field(&req.DiseaseId, valid.Required),
 		valid.Field(&req.OperationId, valid.Required),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
@@ -103,7 +102,8 @@ func CowDiseaseTreatment(c *gin.Context) {
 	if err := valid.ValidateStruct(&req,
 		valid.Field(&req.Id, valid.Required),
 		valid.Field(&req.CowId, valid.Required),
-		valid.Field(&req.PrescriptionDetail, valid.Required),
+		valid.Field(&req.DiseaseId, valid.Required),
+		valid.Field(&req.PrescriptionId, valid.Required),
 		valid.Field(&req.TreatmentAt, valid.Required),
 		valid.Field(&req.OperationId, valid.Required),
 	); err != nil {
@@ -122,3 +122,33 @@ func CowDiseaseTreatment(c *gin.Context) {
 		Data: &operationPb.Success{Success: true},
 	})
 }
+
+func CowDiseaseTreatmentDetail(c *gin.Context) {
+	var req pasturePb.EventCowTreatmentDetailRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.CowId, valid.Required),
+		valid.Field(&req.DiseaseId, valid.Required),
+	); 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.CowDiseaseTreatmentDetail(c, &req, pagination)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, res)
+}

+ 1 - 0
http/route/analysis_api.go

@@ -18,5 +18,6 @@ func AnalysisAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		pastureRoute.POST("/mating/timely", analysis.MatingTimeLy)
 		pastureRoute.POST("/pen/weight", analysis.PenWeight)
 		pastureRoute.POST("/abortion/rate", analysis.AbortionRate)
+		pastureRoute.POST("/twentyone/rate", analysis.AbortionRate)
 	}
 }

+ 1 - 0
http/route/event_api.go

@@ -54,5 +54,6 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		eventRoute.POST("/disease/list", event.CowDiseaseList)
 		eventRoute.POST("/disease/diagnose", event.CowDiseaseDiagnose)
 		eventRoute.POST("/disease/treatment", event.CowDiseaseTreatment)
+		eventRoute.POST("/disease/treatment/details", event.CowDiseaseTreatmentDetail)
 	}
 }

+ 5 - 5
model/event_cow_disease.go

@@ -29,19 +29,19 @@ func (e *EventCowDisease) TableName() string {
 	return "event_cow_disease"
 }
 
-func NewEventCowDisease(cow *Cow, req *pasturePb.EventCowDisease) *EventCowDisease {
+func NewEventCowDisease(cow *Cow, disease *Disease, req *pasturePb.EventCowDiseaseRequest, operation *SystemUser) *EventCowDisease {
 	return &EventCowDisease{
 		CowId:         cow.Id,
 		Lact:          cow.Lact,
 		DayAge:        cow.DayAge,
-		DiseaseId:     req.DiseaseId,
-		DiseaseName:   req.DiseaseName,
+		DiseaseId:     int32(disease.Id),
+		DiseaseName:   disease.Name,
 		PenId:         req.PenId,
 		HealthStatus:  pasturePb.HealthStatus_Health,
 		DiseaseAt:     int64(req.DiseaseAt),
 		Temperature:   int32(req.Temperature * 10),
-		OperationId:   req.OperationId,
-		OperationName: req.OperationName,
+		OperationId:   int32(operation.Id),
+		OperationName: operation.Name,
 		Remarks:       req.Remarks,
 	}
 }

+ 9 - 3
model/event_cow_treatment.go

@@ -10,7 +10,10 @@ type EventCowTreatment struct {
 	Id                 int64                          `json:"id"`
 	CowId              int64                          `json:"cowId"`
 	CowDiseaseId       int64                          `json:"cowDiseaseId"`
+	DiseaseId          int64                          `json:"diseaseId"`
+	DiseaseName        string                         `json:"diseaseName"`
 	PrescriptionId     int32                          `json:"prescriptionId"`
+	PrescriptionName   string                         `json:"prescriptionName"`
 	PrescriptionDetail string                         `json:"prescriptionDetail"`
 	TreatmentResult    pasturePb.TreatmentResult_Kind `json:"treatmentResult"`
 	OperationId        int64                          `json:"operationId"`
@@ -25,16 +28,19 @@ func (e *EventCowTreatment) TableName() string {
 	return "event_cow_treatment"
 }
 
-func NewEventCowTreatment(req *pasturePb.CowTreatmentRequest, systemUser *SystemUser) *EventCowTreatment {
+func NewEventCowTreatment(prescription *Prescription, req *pasturePb.CowTreatmentRequest, operation *SystemUser) *EventCowTreatment {
 	b, _ := json.Marshal(req.PrescriptionDetail)
 	return &EventCowTreatment{
 		CowId:              int64(req.CowId),
 		CowDiseaseId:       int64(req.Id),
+		DiseaseId:          int64(req.DiseaseId),
+		DiseaseName:        req.DiseaseName,
 		PrescriptionId:     req.PrescriptionId,
+		PrescriptionName:   prescription.Name,
 		PrescriptionDetail: string(b),
 		TreatmentResult:    req.TreatmentResult,
-		OperationId:        systemUser.Id,
-		OperationName:      systemUser.Name,
+		OperationId:        operation.Id,
+		OperationName:      operation.Name,
 		Remarks:            req.Remarks,
 	}
 }

+ 2 - 2
module/backend/enum_options.go

@@ -37,7 +37,7 @@ func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int, isAll str
 	}, nil
 }
 
-func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context, isAll string) (*pasturePb.ConfigOptionsListResponse, error) {
+func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context, isChildren string) (*pasturePb.ConfigOptionsListResponse, error) {
 	diseaseTypeList := make([]*model.ConfigDiseaseType, 0)
 	pref := s.DB.Table(new(model.ConfigDiseaseType).TableName()).
 		Where("is_show =? ", pasturePb.IsShow_Ok)
@@ -45,7 +45,7 @@ func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context, isAll string) (*pas
 		return nil, xerr.WithStack(err)
 	}
 	diseaseList := make([]*model.Disease, 0)
-	if isAll == model.IsAllYes {
+	if isChildren == model.IsAllYes {
 		if err := s.DB.Table(new(model.Disease).TableName()).
 			Where("is_show =? ", pasturePb.IsShow_Ok).Find(&diseaseList).Error; err != nil {
 			return nil, xerr.WithStack(err)

+ 1 - 0
module/backend/event_breed.go

@@ -645,6 +645,7 @@ func (s *StoreEntry) AbortionCreate(ctx context.Context, req *pasturePb.EventAbo
 				"is_pregnant":      pasturePb.IsShow_No,
 				"last_abortion_at": req.AbortionAt,
 				"breed_status":     pasturePb.BreedStatus_Abort,
+				"lact":             cow.Lact + 1,
 			}).Error; err != nil {
 			return xerr.WithStack(err)
 		}

+ 79 - 31
module/backend/event_health.go

@@ -15,7 +15,7 @@ import (
 )
 
 // CowDiseaseCreate 牛只发病提交
-func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventCowDisease) error {
+func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventCowDiseaseRequest) error {
 	cow, err := s.GetCowInfoByCowId(ctx, int64(req.CowId))
 	if err != nil {
 		return xerr.WithStack(err)
@@ -26,8 +26,6 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
 		return xerr.WithStack(err)
 	}
 
-	req.OperationName = systemUser.Name
-
 	disease, err := s.GetDiseaseById(ctx, req.DiseaseId)
 	if err != nil {
 		return xerr.WithStack(err)
@@ -40,8 +38,7 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
 		}
 	}
 
-	req.DiseaseName = disease.Name
-	newEventCowDisease := model.NewEventCowDisease(cow, req)
+	newEventCowDisease := model.NewEventCowDisease(cow, disease, req, systemUser)
 	if prescription.Id > 0 {
 		newEventCowDisease.HealthStatus = pasturePb.HealthStatus_Treatment
 	}
@@ -78,9 +75,11 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
 				}
 			}
 
-			newEventCowTreatment := model.NewEventCowTreatment(&pasturePb.CowTreatmentRequest{
+			newEventCowTreatment := model.NewEventCowTreatment(prescription, &pasturePb.CowTreatmentRequest{
 				CowId:              req.CowId,
 				PrescriptionId:     prescription.Id,
+				DiseaseId:          req.DiseaseId,
+				DiseaseName:        disease.Name,
 				PrescriptionDetail: prescriptionDetail,
 				TreatmentResult:    pasturePb.TreatmentResult_GoOn,
 				Remarks:            "",
@@ -180,7 +179,7 @@ func (s *StoreEntry) CowDiseaseDiagnose(ctx context.Context, req *pasturePb.CowD
 	}
 	// 未发病
 	if req.DiagnosedResult == pasturePb.IsShow_No {
-		if err := s.DB.Model(eventCowDisease).
+		if err = s.DB.Model(eventCowDisease).
 			Where("id = ?", req.Id).
 			Where("cow_id = ?", req.CowId).
 			Updates(map[string]interface{}{
@@ -247,29 +246,31 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
 	}
 
 	systemUser, _ := s.GetSystemUserById(ctx, int64(req.OperationId))
+	prescription, err := s.GetPrescriptionById(ctx, req.PrescriptionId)
+	if err != nil {
+		return xerr.WithStack(err)
+	}
 
-	if req.PrescriptionId > 0 {
-		prescription, err := s.GetPrescriptionById(ctx, req.PrescriptionId)
-		if err != nil {
-			return xerr.WithStack(err)
-		}
-		prescriptionDrugs, err := s.PrescriptionDrugsByPrescriptionId(ctx, prescription.Id)
-		if err != nil {
-			return xerr.WithStack(err)
-		}
+	disease, err := s.GetDiseaseById(ctx, eventCowDisease.DiagnoseId)
+	if err != nil {
+		return xerr.WithStack(err)
+	}
+	req.DiseaseName = disease.Name
+	prescriptionDrugs, err := s.PrescriptionDrugsByPrescriptionId(ctx, prescription.Id)
+	if err != nil {
+		return xerr.WithStack(err)
+	}
 
-		prescriptionDetail := make([]*pasturePb.TreatmentDrugs, len(prescriptionDrugs))
-		for i, v := range prescriptionDrugs {
-			prescriptionDetail[i] = &pasturePb.TreatmentDrugs{
-				DrugsId:   int32(v.DrugsId),
-				DrugsName: v.DrugsName,
-				Unit:      v.Unit,
-				UseNum:    float32(v.Dosages),
-			}
+	prescriptionDetail := make([]*pasturePb.TreatmentDrugs, len(prescriptionDrugs))
+	for i, v := range prescriptionDrugs {
+		prescriptionDetail[i] = &pasturePb.TreatmentDrugs{
+			DrugsId:   int32(v.DrugsId),
+			DrugsName: v.DrugsName,
+			Unit:      v.Unit,
+			UseNum:    float32(v.Dosages),
 		}
-		req.PrescriptionDetail = prescriptionDetail
-		return nil
 	}
+	req.PrescriptionDetail = prescriptionDetail
 
 	healthStatus := pasturePb.HealthStatus_Treatment
 	if req.TreatmentResult == pasturePb.TreatmentResult_Curable {
@@ -284,13 +285,13 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
 		healthStatus = pasturePb.HealthStatus_Dead
 	}
 
-	newEventCowTreatment := model.NewEventCowTreatment(req, systemUser)
-	if err := s.DB.Transaction(func(tx *gorm.DB) error {
-		if err := tx.Create(newEventCowTreatment).Error; err != nil {
+	newEventCowTreatment := model.NewEventCowTreatment(prescription, req, systemUser)
+	if err = s.DB.Transaction(func(tx *gorm.DB) error {
+		if err = tx.Create(newEventCowTreatment).Error; err != nil {
 			return xerr.WithStack(err)
 		}
 
-		if err := tx.Model(eventCowDisease).
+		if err = tx.Model(eventCowDisease).
 			Where("id = ?", req.Id).
 			Where("cow_id = ?", req.CowId).
 			Updates(map[string]interface{}{
@@ -299,7 +300,7 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
 			return xerr.WithStack(err)
 		}
 
-		if err := tx.Model(new(model.Cow)).
+		if err = tx.Model(new(model.Cow)).
 			Where("id = ?", req.CowId).
 			Updates(map[string]interface{}{
 				"health_status": healthStatus,
@@ -313,3 +314,50 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
 
 	return nil
 }
+
+func (s *StoreEntry) CowDiseaseTreatmentDetail(ctx context.Context, req *pasturePb.EventCowTreatmentDetailRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowTreatmentDetailResponse, error) {
+	eventCowDiseaseList := make([]*model.EventCowDisease, 0)
+	var count int64 = 0
+	pref := s.DB.Where("cow_id = ?", req.CowId)
+
+	if req.DiseaseId > 0 {
+		pref.Where("disease_id = ?", req.DiseaseId)
+	}
+
+	if req.DiseaseStartAt > 0 && req.DiseaseEndAt > 0 && req.DiseaseStartAt <= req.DiseaseEndAt {
+		pref.Where("disease_at BETWEEN ? AND ?", req.DiseaseStartAt, req.DiseaseEndAt)
+	}
+
+	if err := pref.Count(&count).
+		Limit(int(pagination.PageSize)).
+		Offset(int(pagination.PageOffset)).
+		Order("id desc").
+		Find(&eventCowDiseaseList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	eventCowTreatmentList := make([]*pasturePb.EventCowTreatment, 0)
+	cowDiseaseIds := make([]int64, len(eventCowDiseaseList))
+	for i, v := range eventCowDiseaseList {
+		cowDiseaseIds[i] = v.Id
+	}
+
+	if err := s.DB.Where("cow_disease_id IN ?", cowDiseaseIds).
+		Where("cow_id = ?", req.CowId).
+		Group("cow_disease_id").
+		Order("id desc").
+		Find(&eventCowTreatmentList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	return &pasturePb.EventCowTreatmentDetailResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.EventCowTreatmentDetail{
+			List:     eventCowTreatmentList,
+			Total:    int32(count),
+			PageSize: pagination.Page,
+			Page:     pagination.PageSize,
+		},
+	}, nil
+}

+ 3 - 2
module/backend/interface.go

@@ -141,7 +141,7 @@ type ConfigDataService interface {
 	SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error)
 	BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error)
 	SystemBaseConfigOptions(ctx context.Context, optionName, isAll string) (*pasturePb.ConfigOptionsListResponse, error)
-	DiseaseTypeOptions(ctx context.Context, isAll string) (*pasturePb.ConfigOptionsListResponse, error)
+	DiseaseTypeOptions(ctx context.Context, isChildren string) (*pasturePb.ConfigOptionsListResponse, error)
 	DiseaseOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	PrescriptionOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 }
@@ -184,10 +184,11 @@ type EventService interface {
 	WeightCreate(ctx context.Context, req *pasturePb.EventWeight) error
 
 	// CowDiseaseCreate 牛只发病
-	CowDiseaseCreate(ctx context.Context, req *pasturePb.EventCowDisease) error
+	CowDiseaseCreate(ctx context.Context, req *pasturePb.EventCowDiseaseRequest) error
 	CowDiseaseList(ctx context.Context, req *pasturePb.SearchEventCowTreatmentRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowDiseaseResponse, error)
 	CowDiseaseDiagnose(ctx context.Context, req *pasturePb.CowDiagnosedRequest) error
 	CowDiseaseTreatment(ctx context.Context, req *pasturePb.CowTreatmentRequest) error
+	CowDiseaseTreatmentDetail(ctx context.Context, req *pasturePb.EventCowTreatmentDetailRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowTreatmentDetailResponse, error)
 }
 
 //go:generate mockgen -destination mock/CowService.go -package kptservicemock kpt-pasture/module/backend CowService