event_health.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. package event
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. "strconv"
  6. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  7. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  8. "gitee.com/xuyiping_admin/pkg/apierr"
  9. "gitee.com/xuyiping_admin/pkg/ginutil"
  10. "gitee.com/xuyiping_admin/pkg/valid"
  11. "github.com/gin-gonic/gin"
  12. )
  13. func CowDiseaseCreate(c *gin.Context) {
  14. var req pasturePb.EventCowDiseaseRequest
  15. if err := ginutil.BindProto(c, &req); err != nil {
  16. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  17. return
  18. }
  19. if err := valid.ValidateStruct(&req,
  20. valid.Field(&req.EarNumber, valid.Required),
  21. valid.Field(&req.DiseaseAt, valid.Required),
  22. valid.Field(&req.DiseaseId, valid.Required),
  23. valid.Field(&req.OperationId, valid.Required),
  24. ); err != nil {
  25. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  26. return
  27. }
  28. source := c.GetHeader("Source")
  29. if err := middleware.BackendOperation(c).OpsService.CowDiseaseCreate(c, &req, source); err != nil {
  30. apierr.ClassifiedAbort(c, err)
  31. return
  32. }
  33. ginutil.JSONResp(c, &operationPb.CommonOK{
  34. Code: http.StatusOK,
  35. Msg: "ok",
  36. Data: &operationPb.Success{Success: true},
  37. })
  38. }
  39. func CowDiseaseList(c *gin.Context) {
  40. var req pasturePb.SearchEventCowTreatmentRequest
  41. if err := ginutil.BindProto(c, &req); err != nil {
  42. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  43. return
  44. }
  45. pagination := &pasturePb.PaginationModel{
  46. Page: int32(c.GetInt(middleware.Page)),
  47. PageSize: int32(c.GetInt(middleware.PageSize)),
  48. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  49. }
  50. res, err := middleware.Dependency(c).StoreEventHub.OpsService.CowDiseaseList(c, &req, pagination)
  51. if err != nil {
  52. apierr.ClassifiedAbort(c, err)
  53. return
  54. }
  55. ginutil.JSONResp(c, res)
  56. }
  57. func CowDiseaseDiagnose(c *gin.Context) {
  58. var req pasturePb.CowDiagnosedRequest
  59. if err := ginutil.BindProto(c, &req); err != nil {
  60. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  61. return
  62. }
  63. if err := valid.ValidateStruct(&req,
  64. valid.Field(&req.Id, valid.Required),
  65. valid.Field(&req.CowId, valid.Required),
  66. valid.Field(&req.DiagnosedResult, valid.Required),
  67. ); err != nil {
  68. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  69. return
  70. }
  71. if err := middleware.BackendOperation(c).OpsService.CowDiseaseDiagnose(c, &req); err != nil {
  72. apierr.ClassifiedAbort(c, err)
  73. return
  74. }
  75. ginutil.JSONResp(c, &operationPb.CommonOK{
  76. Code: http.StatusOK,
  77. Msg: "ok",
  78. Data: &operationPb.Success{Success: true},
  79. })
  80. }
  81. func DiseaseSuggestPrescription(c *gin.Context) {
  82. diseaseIdStr := c.Param("id")
  83. diseaseId, _ := strconv.Atoi(diseaseIdStr)
  84. if err := valid.Validate(diseaseId, valid.Required, valid.Min(1)); err != nil {
  85. apierr.ClassifiedAbort(c, err)
  86. return
  87. }
  88. res, err := middleware.BackendOperation(c).OpsService.DiseaseSuggestPrescription(c, int64(diseaseId))
  89. if err != nil {
  90. apierr.ClassifiedAbort(c, err)
  91. return
  92. }
  93. ginutil.JSONResp(c, res)
  94. }
  95. func CowDiseaseTreatment(c *gin.Context) {
  96. var req pasturePb.CowTreatmentRequest
  97. if err := ginutil.BindProto(c, &req); err != nil {
  98. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  99. return
  100. }
  101. if err := valid.ValidateStruct(&req,
  102. valid.Field(&req.Id, valid.Required),
  103. valid.Field(&req.CowId, valid.Required),
  104. valid.Field(&req.DiseaseId, valid.Required),
  105. valid.Field(&req.PrescriptionId, valid.Required),
  106. valid.Field(&req.TreatmentAt, valid.Required),
  107. valid.Field(&req.OperationId, valid.Required),
  108. ); err != nil {
  109. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  110. return
  111. }
  112. if err := middleware.BackendOperation(c).OpsService.CowDiseaseTreatment(c, &req); err != nil {
  113. apierr.ClassifiedAbort(c, err)
  114. return
  115. }
  116. ginutil.JSONResp(c, &operationPb.CommonOK{
  117. Code: http.StatusOK,
  118. Msg: "ok",
  119. Data: &operationPb.Success{Success: true},
  120. })
  121. }
  122. func CowDiseaseTreatmentDetail(c *gin.Context) {
  123. var req pasturePb.EventCowTreatmentDetailRequest
  124. if err := ginutil.BindProto(c, &req); err != nil {
  125. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  126. return
  127. }
  128. if err := valid.ValidateStruct(&req,
  129. valid.Field(&req.CowId, valid.Required),
  130. valid.Field(&req.Id, valid.Required),
  131. ); err != nil {
  132. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  133. return
  134. }
  135. pagination := &pasturePb.PaginationModel{
  136. Page: int32(c.GetInt(middleware.Page)),
  137. PageSize: int32(c.GetInt(middleware.PageSize)),
  138. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  139. }
  140. res, err := middleware.BackendOperation(c).OpsService.CowDiseaseTreatmentDetail(c, &req, pagination)
  141. if err != nil {
  142. apierr.ClassifiedAbort(c, err)
  143. return
  144. }
  145. ginutil.JSONResp(c, res)
  146. }
  147. func CowDiseaseCurable(c *gin.Context) {
  148. var req pasturePb.EventCowCurableRequest
  149. if err := ginutil.BindProto(c, &req); err != nil {
  150. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  151. return
  152. }
  153. if err := valid.ValidateStruct(&req,
  154. valid.Field(&req.Ids, valid.Required),
  155. valid.Field(&req.OperationId, valid.Required),
  156. valid.Field(&req.CurableAt, valid.Required),
  157. ); err != nil {
  158. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  159. return
  160. }
  161. if err := middleware.BackendOperation(c).OpsService.CowDiseaseCurable(c, &req); err != nil {
  162. apierr.ClassifiedAbort(c, err)
  163. return
  164. }
  165. ginutil.JSONResp(c, &operationPb.CommonOK{
  166. Code: http.StatusOK,
  167. Msg: "ok",
  168. Data: &operationPb.Success{Success: true},
  169. })
  170. }
  171. func ImmunizationList(c *gin.Context) {
  172. var req pasturePb.SearchEventImmunizationRequest
  173. if err := ginutil.BindProto(c, &req); err != nil {
  174. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  175. return
  176. }
  177. pagination := &pasturePb.PaginationModel{
  178. Page: int32(c.GetInt(middleware.Page)),
  179. PageSize: int32(c.GetInt(middleware.PageSize)),
  180. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  181. }
  182. res, err := middleware.Dependency(c).StoreEventHub.OpsService.ImmunizationList(c, &req, pagination)
  183. if err != nil {
  184. apierr.ClassifiedAbort(c, err)
  185. return
  186. }
  187. ginutil.JSONResp(c, res)
  188. }
  189. func ImmunizationBatch(c *gin.Context) {
  190. var req pasturePb.ImmunizationItem
  191. if err := ginutil.BindProto(c, &req); err != nil {
  192. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  193. return
  194. }
  195. if err := valid.ValidateStruct(&req,
  196. valid.Field(&req.PlanId, valid.Required),
  197. valid.Field(&req.OperationId, valid.Required),
  198. valid.Field(&req.CowIds, valid.Required),
  199. valid.Field(&req.ImmunizationAt, valid.Required),
  200. valid.Field(&req.Usage, valid.Required),
  201. ); err != nil {
  202. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  203. return
  204. }
  205. if err := middleware.Dependency(c).StoreEventHub.OpsService.ImmunizationBatch(c, &req); err != nil {
  206. apierr.ClassifiedAbort(c, err)
  207. return
  208. }
  209. ginutil.JSONResp(c, &operationPb.CommonOK{
  210. Code: http.StatusOK,
  211. Msg: "ok",
  212. Data: &operationPb.Success{Success: true},
  213. })
  214. }