浏览代码

disease: 牛只健康管理接口

Yi 8 月之前
父节点
当前提交
c56a9bd08e
共有 6 个文件被更改,包括 68 次插入9 次删除
  1. 60 0
      http/handler/event/event_health.go
  2. 2 1
      http/route/event_api.go
  3. 1 1
      http/route/work_order.go
  4. 2 5
      model/cow.go
  5. 2 2
      module/backend/cow.go
  6. 1 0
      module/backend/interface.go

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

@@ -62,3 +62,63 @@ func CowDiseaseList(c *gin.Context) {
 	ginutil.JSONResp(c, res)
 
 }
+
+func CowDiseaseDiagnose(c *gin.Context) {
+	var req pasturePb.CowDiagnosedRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := valid.ValidateStruct(&req,
+		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)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.CowDiseaseDiagnose(c, &req); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}
+
+func CowDiseaseTreatment(c *gin.Context) {
+	var req pasturePb.CowTreatmentRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	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.TreatmentAt, valid.Required),
+		valid.Field(&req.OperationId, valid.Required),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.CowDiseaseTreatment(c, &req); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}

+ 2 - 1
http/route/event_api.go

@@ -52,6 +52,7 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		// 发病
 		eventRoute.POST("/disease/create", event.CowDiseaseCreate)
 		eventRoute.POST("/disease/list", event.CowDiseaseList)
-
+		eventRoute.POST("/disease/diagnose", event.CowDiseaseDiagnose)
+		eventRoute.POST("/disease/treatment", event.CowDiseaseTreatment)
 	}
 }

+ 1 - 1
http/route/work_order.go

@@ -11,7 +11,7 @@ func WorkOrderAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		for _, opt := range opts {
 			opt(s)
 		}
-		// goods API 组  物品管理
+		// work API 组  工作清单
 		workRoute := authRouteGroup(s, "/api/v1/work/")
 		workRoute.POST("/order/list", work.OrderList)
 		workRoute.POST("/order/createOrUpdate", work.OrderCreateOrUpdate)

+ 2 - 5
model/cow.go

@@ -58,7 +58,7 @@ func (c *Cow) TableName() string {
 type CowSlice []*Cow
 
 func (c CowSlice) ToPB(
-	penList []*Pen,
+	penMap map[int32]*Pen,
 	cowTypeMap map[pasturePb.CowType_Kind]string,
 	breedStatusMap map[pasturePb.BreedStatus_Kind]string,
 	cowKindMap map[pasturePb.CowKind_Kind]string,
@@ -66,10 +66,7 @@ func (c CowSlice) ToPB(
 	res := make([]*pasturePb.SearchCowList, len(c))
 	for i, v := range c {
 		penName := ""
-		for _, pen := range penList {
-			if v.PenId != int32(pen.Id) {
-				continue
-			}
+		if pen, ok := penMap[v.PenId]; ok {
 			penName = pen.Name
 		}
 		res[i] = &pasturePb.SearchCowList{

+ 2 - 2
module/backend/cow.go

@@ -28,7 +28,7 @@ func (s *StoreEntry) CowList(ctx context.Context, req *pasturePb.SearchEventRequ
 		return nil, xerr.WithStack(err)
 	}
 
-	penList, _ := s.GetPenList(ctx)
+	penMap := s.PenMap(ctx)
 	cowTypeMap := s.CowTypeMap()
 	breedStatusMap := s.CowBreedStatusMap()
 	cowKindMap := s.CowKindMap()
@@ -36,7 +36,7 @@ func (s *StoreEntry) CowList(ctx context.Context, req *pasturePb.SearchEventRequ
 		Code:    http.StatusOK,
 		Message: "ok",
 		Data: &pasturePb.SearchCowData{
-			List:     model.CowSlice(cowList).ToPB(penList, cowTypeMap, breedStatusMap, cowKindMap),
+			List:     model.CowSlice(cowList).ToPB(penMap, cowTypeMap, breedStatusMap, cowKindMap),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,

+ 1 - 0
module/backend/interface.go

@@ -183,6 +183,7 @@ type EventService interface {
 	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
+	CowDiseaseTreatment(ctx context.Context, req *pasturePb.CowTreatmentRequest) error
 }
 
 //go:generate mockgen -destination mock/CowService.go -package kptservicemock kpt-pasture/module/backend CowService