event_health.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package event
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  7. "gitee.com/xuyiping_admin/pkg/apierr"
  8. "gitee.com/xuyiping_admin/pkg/ginutil"
  9. "gitee.com/xuyiping_admin/pkg/valid"
  10. "github.com/gin-gonic/gin"
  11. )
  12. func CowDiseaseCreate(c *gin.Context) {
  13. var req pasturePb.EventCowDiseaseRequest
  14. if err := ginutil.BindProto(c, &req); err != nil {
  15. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  16. return
  17. }
  18. if err := valid.ValidateStruct(&req,
  19. valid.Field(&req.CowId, valid.Required),
  20. valid.Field(&req.DiseaseAt, valid.Required),
  21. valid.Field(&req.DiseaseId, valid.Required),
  22. valid.Field(&req.OperationId, valid.Required),
  23. ); err != nil {
  24. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  25. return
  26. }
  27. if err := middleware.BackendOperation(c).OpsService.CowDiseaseCreate(c, &req); err != nil {
  28. apierr.ClassifiedAbort(c, err)
  29. return
  30. }
  31. ginutil.JSONResp(c, &operationPb.CommonOK{
  32. Code: http.StatusOK,
  33. Msg: "ok",
  34. Data: &operationPb.Success{Success: true},
  35. })
  36. }
  37. func CowDiseaseList(c *gin.Context) {
  38. var req pasturePb.SearchEventCowTreatmentRequest
  39. if err := ginutil.BindProto(c, &req); err != nil {
  40. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  41. return
  42. }
  43. pagination := &pasturePb.PaginationModel{
  44. Page: int32(c.GetInt(middleware.Page)),
  45. PageSize: int32(c.GetInt(middleware.PageSize)),
  46. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  47. }
  48. res, err := middleware.Dependency(c).StoreEventHub.OpsService.CowDiseaseList(c, &req, pagination)
  49. if err != nil {
  50. apierr.ClassifiedAbort(c, err)
  51. return
  52. }
  53. ginutil.JSONResp(c, res)
  54. }
  55. func CowDiseaseDiagnose(c *gin.Context) {
  56. var req pasturePb.CowDiagnosedRequest
  57. if err := ginutil.BindProto(c, &req); err != nil {
  58. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  59. return
  60. }
  61. if err := valid.ValidateStruct(&req,
  62. valid.Field(&req.Id, valid.Required),
  63. valid.Field(&req.CowId, valid.Required),
  64. valid.Field(&req.DiagnosedResult, valid.Required),
  65. ); err != nil {
  66. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  67. return
  68. }
  69. if err := middleware.BackendOperation(c).OpsService.CowDiseaseDiagnose(c, &req); err != nil {
  70. apierr.ClassifiedAbort(c, err)
  71. return
  72. }
  73. ginutil.JSONResp(c, &operationPb.CommonOK{
  74. Code: http.StatusOK,
  75. Msg: "ok",
  76. Data: &operationPb.Success{Success: true},
  77. })
  78. }
  79. func CowDiseaseTreatment(c *gin.Context) {
  80. var req pasturePb.CowTreatmentRequest
  81. if err := ginutil.BindProto(c, &req); err != nil {
  82. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  83. return
  84. }
  85. if err := valid.ValidateStruct(&req,
  86. valid.Field(&req.Id, valid.Required),
  87. valid.Field(&req.CowId, valid.Required),
  88. valid.Field(&req.DiseaseId, valid.Required),
  89. valid.Field(&req.PrescriptionId, valid.Required),
  90. valid.Field(&req.TreatmentAt, valid.Required),
  91. valid.Field(&req.OperationId, valid.Required),
  92. ); err != nil {
  93. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  94. return
  95. }
  96. if err := middleware.BackendOperation(c).OpsService.CowDiseaseTreatment(c, &req); err != nil {
  97. apierr.ClassifiedAbort(c, err)
  98. return
  99. }
  100. ginutil.JSONResp(c, &operationPb.CommonOK{
  101. Code: http.StatusOK,
  102. Msg: "ok",
  103. Data: &operationPb.Success{Success: true},
  104. })
  105. }
  106. func CowDiseaseTreatmentDetail(c *gin.Context) {
  107. var req pasturePb.EventCowTreatmentDetailRequest
  108. if err := ginutil.BindProto(c, &req); err != nil {
  109. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  110. return
  111. }
  112. if err := valid.ValidateStruct(&req,
  113. valid.Field(&req.CowId, valid.Required),
  114. valid.Field(&req.DiseaseId, valid.Required),
  115. ); err != nil {
  116. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  117. return
  118. }
  119. pagination := &pasturePb.PaginationModel{
  120. Page: int32(c.GetInt(middleware.Page)),
  121. PageSize: int32(c.GetInt(middleware.PageSize)),
  122. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  123. }
  124. res, err := middleware.BackendOperation(c).OpsService.CowDiseaseTreatmentDetail(c, &req, pagination)
  125. if err != nil {
  126. apierr.ClassifiedAbort(c, err)
  127. return
  128. }
  129. ginutil.JSONResp(c, res)
  130. }