event_health.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. valid.Field(&req.OperationId, valid.Required),
  66. ); err != nil {
  67. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  68. return
  69. }
  70. if err := middleware.BackendOperation(c).OpsService.CowDiseaseDiagnose(c, &req); err != nil {
  71. apierr.ClassifiedAbort(c, err)
  72. return
  73. }
  74. ginutil.JSONResp(c, &operationPb.CommonOK{
  75. Code: http.StatusOK,
  76. Msg: "ok",
  77. Data: &operationPb.Success{Success: true},
  78. })
  79. }
  80. func CowDiseaseTreatment(c *gin.Context) {
  81. var req pasturePb.CowTreatmentRequest
  82. if err := ginutil.BindProto(c, &req); err != nil {
  83. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  84. return
  85. }
  86. if err := valid.ValidateStruct(&req,
  87. valid.Field(&req.Id, valid.Required),
  88. valid.Field(&req.CowId, valid.Required),
  89. valid.Field(&req.DiseaseId, valid.Required),
  90. valid.Field(&req.PrescriptionId, valid.Required),
  91. valid.Field(&req.TreatmentAt, valid.Required),
  92. valid.Field(&req.OperationId, valid.Required),
  93. ); err != nil {
  94. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  95. return
  96. }
  97. if err := middleware.BackendOperation(c).OpsService.CowDiseaseTreatment(c, &req); err != nil {
  98. apierr.ClassifiedAbort(c, err)
  99. return
  100. }
  101. ginutil.JSONResp(c, &operationPb.CommonOK{
  102. Code: http.StatusOK,
  103. Msg: "ok",
  104. Data: &operationPb.Success{Success: true},
  105. })
  106. }
  107. func CowDiseaseTreatmentDetail(c *gin.Context) {
  108. var req pasturePb.EventCowTreatmentDetailRequest
  109. if err := ginutil.BindProto(c, &req); err != nil {
  110. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  111. return
  112. }
  113. if err := valid.ValidateStruct(&req,
  114. valid.Field(&req.CowId, valid.Required),
  115. valid.Field(&req.DiseaseId, valid.Required),
  116. ); err != nil {
  117. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  118. return
  119. }
  120. pagination := &pasturePb.PaginationModel{
  121. Page: int32(c.GetInt(middleware.Page)),
  122. PageSize: int32(c.GetInt(middleware.PageSize)),
  123. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  124. }
  125. res, err := middleware.BackendOperation(c).OpsService.CowDiseaseTreatmentDetail(c, &req, pagination)
  126. if err != nil {
  127. apierr.ClassifiedAbort(c, err)
  128. return
  129. }
  130. ginutil.JSONResp(c, res)
  131. }