소스 검색

disease: 牛只治疗

Yi 7 달 전
부모
커밋
08539c757f
9개의 변경된 파일240개의 추가작업 그리고 47개의 파일을 삭제
  1. 1 1
      go.mod
  2. 14 0
      go.sum
  3. 1 2
      model/cow.go
  4. 19 17
      model/event_cow_disease.go
  5. 31 13
      model/event_cow_treatment.go
  6. 9 5
      module/backend/config_data.go
  7. 8 0
      module/backend/enum_map.go
  8. 156 9
      module/backend/event_health.go
  9. 1 0
      module/backend/interface.go

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240923095155-018cf8ed2fc8
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240924055824-5af0e461aca7
 	gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eko/gocache v1.1.0

+ 14 - 0
go.sum

@@ -42,6 +42,20 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240923085405-91f84f9d76ae h1:xLJpN8gN
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240923085405-91f84f9d76ae/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240923095155-018cf8ed2fc8 h1:8a85MdnwHBChtQJ7DQzd2AE6+FHPsEEFRwYHB6WKEco=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240923095155-018cf8ed2fc8/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924015834-ae0ff3b55739 h1:YbLRCw8NgDH96X6V+3EapQz/qVifr0bo+jmfW7CIuRc=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924015834-ae0ff3b55739/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924025247-8eb858531568 h1:Zpau5uItX1QCSFASCfvxOD2/hfo6NhpgS1nzHevXxDU=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924025247-8eb858531568/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924031103-30868d7c5151 h1:iHkZlH4bCZ6vuA95/9Z3hhvxKAO+7wP63QZcdGYB13M=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924031103-30868d7c5151/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924033646-0597ca2774a0 h1:38M7tkqZB23XoIGIoFJeY21Wnsjd51FK/fbfBfkoaPU=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924033646-0597ca2774a0/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924052617-be2ff50e18eb h1:ealcStYG4O0D6ok39EeEEy/2+vEolLyncFedmuhX9Z8=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924052617-be2ff50e18eb/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924054441-100cb4142f8f h1:QQCL4CvPRLl1QY9y3P4VrZS4HwxWrXX+65f/AHGu4YM=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924054441-100cb4142f8f/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924055824-5af0e461aca7 h1:X3n4Y1ucCBdZ7I8+iS88LqZwNtwSyvY1mWP7ajdPClg=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240924055824-5af0e461aca7/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=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 1 - 2
model/cow.go

@@ -31,7 +31,6 @@ type Cow struct {
 	MotherNumber        string                      `json:"motherNumber"`
 	IsRemove            pasturePb.IsShow_Kind       `json:"isRemove"`
 	IsPregnant          pasturePb.IsShow_Kind       `json:"isPregnant"`
-	IsHealth            pasturePb.IsShow_Kind       `json:"isHealth"`
 	HealthStatus        pasturePb.HealthStatus_Kind `json:"healthStatus"`
 	WeaningAt           int64                       `json:"weaningAt"`
 	CalvingAt           int64                       `json:"calvingAt"`
@@ -114,7 +113,7 @@ func NewCow(req *pasturePb.EventEnterData) *Cow {
 		FatherNumber:        req.FatherNumber,
 		MotherNumber:        req.MotherNumber,
 		IsRemove:            pasturePb.IsShow_Ok,
-		IsHealth:            pasturePb.IsShow_Ok,
+		HealthStatus:        pasturePb.HealthStatus_Health,
 		IsPregnant:          isPregnant,
 		WeaningAt:           int64(req.WeaningAt),
 		BirthAt:             int64(req.BirthAt),

+ 19 - 17
model/event_cow_disease.go

@@ -13,6 +13,7 @@ type EventCowDisease struct {
 	DiagnoseName          string                      `json:"diagnoseName"`
 	PenId                 int32                       `json:"penId"`
 	HealthStatus          pasturePb.HealthStatus_Kind `json:"healthStatus"`
+	DiagnosedResult       pasturePb.IsShow_Kind       `json:"diagnosedResult"`
 	DiseaseAt             int64                       `json:"diseaseAt"`
 	Temperature           int32                       `json:"temperature"`
 	Remarks               string                      `json:"remarks"`
@@ -36,7 +37,7 @@ func NewEventCowDisease(cow *Cow, req *pasturePb.EventCowDisease) *EventCowDisea
 		DiseaseId:     req.DiseaseId,
 		DiseaseName:   req.DiseaseName,
 		PenId:         req.PenId,
-		HealthStatus:  pasturePb.HealthStatus_Disease,
+		HealthStatus:  pasturePb.HealthStatus_Health,
 		DiseaseAt:     int64(req.DiseaseAt),
 		Temperature:   int32(req.Temperature * 10),
 		OperationId:   req.OperationId,
@@ -47,25 +48,26 @@ func NewEventCowDisease(cow *Cow, req *pasturePb.EventCowDisease) *EventCowDisea
 
 type EventCowDiseaseSlice []*EventCowDisease
 
-func (e EventCowDiseaseSlice) ToPB() []*pasturePb.EventCowDisease {
+func (e EventCowDiseaseSlice) ToPB(healthStatusMap map[pasturePb.HealthStatus_Kind]string) []*pasturePb.EventCowDisease {
 	res := make([]*pasturePb.EventCowDisease, len(e))
 	for i, v := range e {
 		res[i] = &pasturePb.EventCowDisease{
-			Id:            int32(v.Id),
-			CowId:         int32(v.CowId),
-			Lact:          v.Lact,
-			DayAge:        v.DayAge,
-			DiseaseId:     v.DiseaseId,
-			DiseaseName:   v.DiseaseName,
-			DiagnoseId:    v.DiagnoseId,
-			DiagnoseName:  v.DiagnoseName,
-			PenId:         v.PenId,
-			HealthStatus:  v.HealthStatus,
-			Temperature:   float32(v.HealthStatus / 10),
-			DiseaseAt:     int32(v.DiseaseAt),
-			Remarks:       v.Remarks,
-			OperationId:   v.OperationId,
-			OperationName: v.OperationName,
+			Id:               int32(v.Id),
+			CowId:            int32(v.CowId),
+			Lact:             v.Lact,
+			DayAge:           v.DayAge,
+			DiseaseId:        v.DiseaseId,
+			DiseaseName:      v.DiseaseName,
+			DiagnoseId:       v.DiagnoseId,
+			DiagnoseName:     v.DiagnoseName,
+			PenId:            v.PenId,
+			HealthStatus:     v.HealthStatus,
+			HealthStatusName: healthStatusMap[v.HealthStatus],
+			Temperature:      float32(v.HealthStatus / 10),
+			DiseaseAt:        int32(v.DiseaseAt),
+			Remarks:          v.Remarks,
+			OperationId:      v.OperationId,
+			OperationName:    v.OperationName,
 		}
 	}
 	return res

+ 31 - 13
model/event_cow_treatment.go

@@ -1,22 +1,40 @@
 package model
 
-import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+import (
+	"encoding/json"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
 
 type EventCowTreatment struct {
-	Id                 int64                 `json:"id"`
-	CowId              int64                 `json:"cowId"`
-	CowDiseaseId       int64                 `json:"cowDiseaseId"`
-	PrescriptionId     int32                 `json:"prescriptionId"`
-	PrescriptionName   string                `json:"prescriptionName"`
-	PrescriptionDetail string                `json:"prescriptionDetail"`
-	TreatmentResult    pasturePb.IsShow_Kind `json:"treatmentResult"`
-	OperationId        int64                 `json:"operationId"`
-	OperationName      string                `json:"operationName"`
-	Remarks            string                `json:"remarks"`
-	CreatedAt          int64                 `json:"createdAt"`
-	UpdatedAt          int64                 `json:"updatedAt"`
+	Id                 int64                          `json:"id"`
+	CowId              int64                          `json:"cowId"`
+	CowDiseaseId       int64                          `json:"cowDiseaseId"`
+	PrescriptionId     int32                          `json:"prescriptionId"`
+	PrescriptionDetail string                         `json:"prescriptionDetail"`
+	TreatmentResult    pasturePb.TreatmentResult_Kind `json:"treatmentResult"`
+	OperationId        int64                          `json:"operationId"`
+	OperationName      string                         `json:"operationName"`
+	Remarks            string                         `json:"remarks"`
+	TreatmentAt        int64                          `json:"treatmentAt"`
+	CreatedAt          int64                          `json:"createdAt"`
+	UpdatedAt          int64                          `json:"updatedAt"`
 }
 
 func (e *EventCowTreatment) TableName() string {
 	return "event_cow_treatment"
 }
+
+func NewEventCowTreatment(req *pasturePb.CowTreatmentRequest, systemUser *SystemUser) *EventCowTreatment {
+	b, _ := json.Marshal(req.PrescriptionDetail)
+	return &EventCowTreatment{
+		CowId:              int64(req.CowId),
+		CowDiseaseId:       int64(req.Id),
+		PrescriptionId:     req.PrescriptionId,
+		PrescriptionDetail: string(b),
+		TreatmentResult:    req.TreatmentResult,
+		OperationId:        systemUser.Id,
+		OperationName:      systemUser.Name,
+		Remarks:            req.Remarks,
+	}
+}

+ 9 - 5
module/backend/config_data.go

@@ -45,7 +45,7 @@ func (s *StoreEntry) BarnTypeEnumList() []*pasturePb.ConfigOptionsList {
 		Label:    "病牛舍",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.PenType_Eliminate),
+		Value:    int32(pasturePb.PenType_Out),
 		Label:    "淘汰牛舍",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
@@ -807,10 +807,6 @@ func (s *StoreEntry) HealthStatusEnumList() []*pasturePb.ConfigOptionsList {
 		Value:    int32(pasturePb.HealthStatus_Disease),
 		Label:    "发病",
 		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.HealthStatus_Diagnosed),
-		Label:    "确诊",
-		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.HealthStatus_Treatment),
 		Label:    "治疗",
@@ -819,6 +815,14 @@ func (s *StoreEntry) HealthStatusEnumList() []*pasturePb.ConfigOptionsList {
 		Value:    int32(pasturePb.HealthStatus_Curable),
 		Label:    "治愈",
 		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.HealthStatus_Out),
+		Label:    "淘汰",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.HealthStatus_Dead),
+		Label:    "死亡",
+		Disabled: true,
 	})
 	return configOptions
 }

+ 8 - 0
module/backend/enum_map.go

@@ -153,3 +153,11 @@ func (s *StoreEntry) PregnantCheckResultMap() map[pasturePb.PregnantCheckResult_
 	}
 	return res
 }
+
+func (s *StoreEntry) HealthStatusMap() map[pasturePb.HealthStatus_Kind]string {
+	res := make(map[pasturePb.HealthStatus_Kind]string)
+	for _, v := range s.HealthStatusEnumList() {
+		res[pasturePb.HealthStatus_Kind(v.Value)] = v.Label
+	}
+	return res
+}

+ 156 - 9
module/backend/event_health.go

@@ -56,10 +56,12 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
 	return nil
 }
 
+// CowDiseaseList 发病牛只清单
 func (s *StoreEntry) CowDiseaseList(ctx context.Context, req *pasturePb.SearchEventCowTreatmentRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowDiseaseResponse, error) {
 	cowDiseaseList := make([]*model.EventCowDisease, 0)
 	var count int64 = 0
-	pref := s.DB.Model(new(model.EventCowDisease))
+	pref := s.DB.Model(new(model.EventCowDisease)).
+		Where("diagnosed_result < ?", pasturePb.IsShow_No)
 
 	if len(req.CowIds) > 0 {
 		pref.Where("cow_id IN ?", req.CowIds)
@@ -83,12 +85,6 @@ func (s *StoreEntry) CowDiseaseList(ctx context.Context, req *pasturePb.SearchEv
 
 	if req.HealthStatus > 0 {
 		pref.Where("health_status = ?", req.HealthStatus)
-	} else {
-		pref.Where("health_status IN ?", []pasturePb.HealthStatus_Kind{
-			pasturePb.HealthStatus_Disease,
-			pasturePb.HealthStatus_Treatment,
-			pasturePb.HealthStatus_Diagnosed,
-		})
 	}
 
 	if err := pref.Order("id desc").
@@ -98,11 +94,12 @@ func (s *StoreEntry) CowDiseaseList(ctx context.Context, req *pasturePb.SearchEv
 		return nil, xerr.WithStack(err)
 	}
 
+	healthStatusMap := s.HealthStatusMap()
 	return &pasturePb.EventCowDiseaseResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
 		Data: &pasturePb.EventCowDiseaseData{
-			List:     model.EventCowDiseaseSlice(cowDiseaseList).ToPB(),
+			List:     model.EventCowDiseaseSlice(cowDiseaseList).ToPB(healthStatusMap),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,
@@ -110,6 +107,156 @@ func (s *StoreEntry) CowDiseaseList(ctx context.Context, req *pasturePb.SearchEv
 	}, nil
 }
 
-func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context) {
+// CowDiseaseDiagnose 发病牛只诊断
+func (s *StoreEntry) CowDiseaseDiagnose(ctx context.Context, req *pasturePb.CowDiagnosedRequest) error {
+	eventCowDisease := &model.EventCowDisease{}
+	if err := s.DB.Where("cow_id = ?", req.CowId).
+		Where("id = ?", req.Id).
+		First(eventCowDisease).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+
+	if eventCowDisease.HealthStatus != pasturePb.HealthStatus_Health {
+		return xerr.Custom("异常牛只数据")
+	}
+
+	systemUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
+	if err != nil {
+		return xerr.WithStack(err)
+	}
+	// 未发病
+	if req.DiagnosedResult == pasturePb.IsShow_No {
+		if err := s.DB.Model(eventCowDisease).
+			Where("id = ?", req.Id).
+			Where("cow_id = ?", req.CowId).
+			Updates(map[string]interface{}{
+				"diagnosed_result":        pasturePb.IsShow_No,
+				"diagnose_operation_id":   req.OperationId,
+				"diagnose_operation_name": systemUser.Name,
+				"remarks":                 req.Remarks,
+			}).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+		return nil
+	}
+
+	// 已发病
+	disease, err := s.GetDiseaseById(ctx, req.DiseaseId)
+	if err != nil {
+		return xerr.WithStack(err)
+	}
+
+	if err = s.DB.Transaction(func(tx *gorm.DB) error {
+		if err = tx.Model(eventCowDisease).
+			Where("id = ?", req.Id).
+			Where("cow_id = ?", req.CowId).
+			Updates(map[string]interface{}{
+				"health_status":           pasturePb.HealthStatus_Disease,
+				"diagnosed_result":        pasturePb.IsShow_Ok,
+				"diagnose_id":             req.DiseaseId,
+				"diagnose_name":           disease.Name,
+				"temperature":             int32(req.Temperature * 10),
+				"diagnose_operation_id":   req.OperationId,
+				"diagnose_operation_name": systemUser.Name,
+				"remarks":                 req.Remarks,
+			}).Error; err != nil {
+			return xerr.WithStack(err)
+		}
 
+		if err = tx.Model(new(model.Cow)).
+			Where("id = ?", req.CowId).
+			Updates(map[string]interface{}{
+				"health_status": pasturePb.HealthStatus_Disease,
+			}).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+		return nil
+	}); err != nil {
+		return xerr.WithStack(err)
+	}
+
+	return nil
+}
+
+// CowDiseaseTreatment 发病牛只治疗
+func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.CowTreatmentRequest) error {
+	eventCowDisease := &model.EventCowDisease{}
+	if err := s.DB.Where("cow_id = ?", req.CowId).
+		Where("id = ?", req.Id).
+		First(eventCowDisease).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+
+	if eventCowDisease.HealthStatus != pasturePb.HealthStatus_Disease &&
+		eventCowDisease.HealthStatus != pasturePb.HealthStatus_Treatment {
+		return xerr.Custom("异常牛只数据")
+	}
+
+	systemUser, _ := s.GetSystemUserById(ctx, int64(req.OperationId))
+
+	if req.PrescriptionId > 0 {
+		prescription := &model.Prescription{}
+		if err := s.DB.Where("id = ?", req.PrescriptionId).
+			Where("is_show = ?", pasturePb.IsShow_Ok).
+			First(prescription).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+		prescriptionDrugs := make([]*model.PrescriptionDrugs, 0)
+		if err := s.DB.Where("prescription_id = ?", req.PrescriptionId).Find(&prescriptionDrugs).Error; 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),
+			}
+		}
+		req.PrescriptionDetail = prescriptionDetail
+		return nil
+	}
+	healthStatus := pasturePb.HealthStatus_Treatment
+	if req.TreatmentResult == pasturePb.TreatmentResult_Curable {
+		healthStatus = pasturePb.HealthStatus_Curable
+	}
+
+	if req.TreatmentResult == pasturePb.TreatmentResult_Out {
+		healthStatus = pasturePb.HealthStatus_Out
+	}
+
+	if req.TreatmentResult == pasturePb.TreatmentResult_Dead {
+		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 {
+			return xerr.WithStack(err)
+		}
+
+		if err := tx.Model(eventCowDisease).
+			Where("id = ?", req.Id).
+			Where("cow_id = ?", req.CowId).
+			Updates(map[string]interface{}{
+				"health_status": healthStatus,
+			}).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+
+		if err := tx.Model(new(model.Cow)).
+			Where("id = ?", req.CowId).
+			Updates(map[string]interface{}{
+				"health_status": healthStatus,
+			}).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+		return nil
+	}); err != nil {
+		return xerr.WithStack(err)
+	}
+
+	return nil
 }

+ 1 - 0
module/backend/interface.go

@@ -182,6 +182,7 @@ type EventService interface {
 	// CowDiseaseCreate 牛只发病
 	CowDiseaseCreate(ctx context.Context, req *pasturePb.EventCowDisease) error
 	CowDiseaseList(ctx context.Context, req *pasturePb.SearchEventCowTreatmentRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowDiseaseResponse, error)
+	CowDiseaseDiagnose(ctx context.Context, req *pasturePb.CowDiagnosedRequest) error
 }
 
 //go:generate mockgen -destination mock/CowService.go -package kptservicemock kpt-pasture/module/backend CowService