event_base.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package event
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  6. "gitee.com/xuyiping_admin/pkg/valid"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. "gitee.com/xuyiping_admin/pkg/apierr"
  9. "gitee.com/xuyiping_admin/pkg/ginutil"
  10. "github.com/gin-gonic/gin"
  11. )
  12. func EnterEventList(c *gin.Context) {
  13. var req pasturePb.SearchEventRequest
  14. if err := ginutil.BindProto(c, &req); err != nil {
  15. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  16. return
  17. }
  18. pagination := &pasturePb.PaginationModel{
  19. Page: int32(c.GetInt(middleware.Page)),
  20. PageSize: int32(c.GetInt(middleware.PageSize)),
  21. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  22. }
  23. res, err := middleware.Dependency(c).StoreEventHub.OpsService.EnterList(c, &req, pagination)
  24. if err != nil {
  25. apierr.ClassifiedAbort(c, err)
  26. return
  27. }
  28. ginutil.JSONResp(c, res)
  29. }
  30. func EnterEventCreate(c *gin.Context) {
  31. var req pasturePb.EventEnterRequest
  32. if err := ginutil.BindProto(c, &req); err != nil {
  33. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  34. return
  35. }
  36. if err := valid.ValidateStruct(&req,
  37. valid.Field(&req.EarNumber, valid.Required),
  38. valid.Field(&req.BirthAt, valid.Required),
  39. valid.Field(&req.Sex, valid.Required),
  40. valid.Field(&req.CowType, valid.Required),
  41. valid.Field(&req.CowKind, valid.Required),
  42. valid.Field(&req.CowSource, valid.Required),
  43. valid.Field(&req.Lact, valid.Required),
  44. valid.Field(&req.EnterAt, valid.Required),
  45. valid.Field(&req.CowSource, valid.Required),
  46. valid.Field(&req.OperationId, valid.Required),
  47. ); err != nil {
  48. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  49. return
  50. }
  51. if err := middleware.BackendOperation(c).OpsService.CreateEnter(c, &req); err != nil {
  52. apierr.ClassifiedAbort(c, err)
  53. return
  54. }
  55. ginutil.JSONResp(c, &operationPb.CommonOK{
  56. Code: http.StatusOK,
  57. Msg: "ok",
  58. Data: &operationPb.Success{Success: true},
  59. })
  60. }
  61. func GroupTransferEventList(c *gin.Context) {
  62. var req pasturePb.SearchEventRequest
  63. if err := ginutil.BindProto(c, &req); err != nil {
  64. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  65. return
  66. }
  67. pagination := &pasturePb.PaginationModel{
  68. Page: int32(c.GetInt(middleware.Page)),
  69. PageSize: int32(c.GetInt(middleware.PageSize)),
  70. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  71. }
  72. res, err := middleware.Dependency(c).StoreEventHub.OpsService.GroupTransferList(c, &req, pagination)
  73. if err != nil {
  74. apierr.ClassifiedAbort(c, err)
  75. return
  76. }
  77. ginutil.JSONResp(c, res)
  78. }
  79. func GroupTransferEventCreate(c *gin.Context) {
  80. var req pasturePb.TransferGroupEventRequest
  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.Body, valid.Required, valid.Each(valid.By(func(value interface{}) error {
  87. s := value.(pasturePb.TransferGroupEventData)
  88. return valid.ValidateStruct(&s,
  89. valid.Field(&s.CowId, valid.Required),
  90. valid.Field(&s.TransferDate, valid.Required),
  91. valid.Field(&s.TransferInPenId, valid.Required),
  92. valid.Field(&s.TransferReasonId, valid.Required),
  93. valid.Field(&s.OperationId, valid.Required),
  94. )
  95. }))),
  96. ); err != nil {
  97. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  98. return
  99. }
  100. if err := middleware.BackendOperation(c).OpsService.CreateGroupTransfer(c, &req); err != nil {
  101. apierr.ClassifiedAbort(c, err)
  102. return
  103. }
  104. ginutil.JSONResp(c, &operationPb.CommonOK{
  105. Code: http.StatusOK,
  106. Msg: "ok",
  107. Data: &operationPb.Success{Success: true},
  108. })
  109. }
  110. func BodyScoreEventList(c *gin.Context) {
  111. var req pasturePb.SearchEventRequest
  112. if err := ginutil.BindProto(c, &req); err != nil {
  113. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  114. return
  115. }
  116. pagination := &pasturePb.PaginationModel{
  117. Page: int32(c.GetInt(middleware.Page)),
  118. PageSize: int32(c.GetInt(middleware.PageSize)),
  119. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  120. }
  121. res, err := middleware.Dependency(c).StoreEventHub.OpsService.BodyScoreList(c, &req, pagination)
  122. if err != nil {
  123. apierr.ClassifiedAbort(c, err)
  124. return
  125. }
  126. ginutil.JSONResp(c, res)
  127. }
  128. func BodyScoreEventCreate(c *gin.Context) {
  129. var req pasturePb.BodyScoreEventRequest
  130. if err := ginutil.BindProto(c, &req); err != nil {
  131. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  132. return
  133. }
  134. if err := valid.ValidateStruct(&req,
  135. valid.Field(&req.CowId, valid.Required),
  136. valid.Field(&req.ScoreAt, valid.Required),
  137. valid.Field(&req.Score, valid.Required),
  138. valid.Field(&req.OperationId, valid.Required),
  139. ); err != nil {
  140. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  141. return
  142. }
  143. if err := middleware.BackendOperation(c).OpsService.CreateBodyScore(c, &req); err != nil {
  144. apierr.ClassifiedAbort(c, err)
  145. return
  146. }
  147. ginutil.JSONResp(c, &operationPb.CommonOK{
  148. Code: http.StatusOK,
  149. Msg: "ok",
  150. Data: &operationPb.Success{Success: true},
  151. })
  152. }
  153. func WeightList(c *gin.Context) {
  154. var req pasturePb.SearchEventRequest
  155. if err := ginutil.BindProto(c, &req); err != nil {
  156. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  157. return
  158. }
  159. pagination := &pasturePb.PaginationModel{
  160. Page: int32(c.GetInt(middleware.Page)),
  161. PageSize: int32(c.GetInt(middleware.PageSize)),
  162. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  163. }
  164. res, err := middleware.Dependency(c).StoreEventHub.OpsService.WeightList(c, &req, pagination)
  165. if err != nil {
  166. apierr.ClassifiedAbort(c, err)
  167. return
  168. }
  169. ginutil.JSONResp(c, res)
  170. }
  171. func WeightBatch(c *gin.Context) {
  172. var req pasturePb.EventWeight
  173. if err := ginutil.BindProto(c, &req); err != nil {
  174. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  175. return
  176. }
  177. if err := valid.ValidateStruct(&req,
  178. valid.Field(&req.WeightAt, valid.Required),
  179. valid.Field(&req.OperationId, valid.Required),
  180. valid.Field(&req.WeightItems, valid.Required, valid.Each(valid.By(func(value interface{}) error {
  181. s := value.(pasturePb.WeightItem)
  182. return valid.ValidateStruct(&s,
  183. valid.Field(&s.Weight, valid.Required),
  184. valid.Field(&s.CowId, valid.Required),
  185. )
  186. }))),
  187. ); err != nil {
  188. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  189. return
  190. }
  191. if err := middleware.BackendOperation(c).OpsService.WeightBatch(c, &req); err != nil {
  192. apierr.ClassifiedAbort(c, err)
  193. return
  194. }
  195. ginutil.JSONResp(c, &operationPb.CommonOK{
  196. Code: http.StatusOK,
  197. Msg: "ok",
  198. Data: &operationPb.Success{Success: true},
  199. })
  200. }
  201. func Departure(c *gin.Context) {
  202. var req pasturePb.EventDepartureBatch
  203. if err := ginutil.BindProto(c, &req); err != nil {
  204. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  205. return
  206. }
  207. if err := valid.ValidateStruct(&req,
  208. valid.Field(&req.Item, valid.Required, valid.Each(valid.By(func(value interface{}) error {
  209. s := value.(pasturePb.EventDeparture)
  210. return valid.ValidateStruct(&s,
  211. valid.Field(&s.DepartureAt, valid.Required),
  212. valid.Field(&s.DepartureType, valid.Required),
  213. valid.Field(&s.DepartureReasonKind, valid.Required),
  214. valid.Field(&s.OperationId, valid.Required),
  215. valid.Field(&s.CowId, valid.Required),
  216. )
  217. }))),
  218. ); err != nil {
  219. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  220. return
  221. }
  222. if err := middleware.BackendOperation(c).OpsService.DepartureBatch(c, &req); err != nil {
  223. apierr.ClassifiedAbort(c, err)
  224. return
  225. }
  226. ginutil.JSONResp(c, &operationPb.CommonOK{
  227. Code: http.StatusOK,
  228. Msg: "ok",
  229. Data: &operationPb.Success{Success: true},
  230. })
  231. }
  232. func CowEarNumber(c *gin.Context) {
  233. var req pasturePb.EventReplaceEarNumber
  234. if err := ginutil.BindProto(c, &req); err != nil {
  235. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  236. return
  237. }
  238. if err := valid.ValidateStruct(&req,
  239. valid.Field(&req.CowId, valid.Required),
  240. valid.Field(&req.EarNumber, valid.Required),
  241. ); err != nil {
  242. apierr.ClassifiedAbort(c, err)
  243. return
  244. }
  245. if err := middleware.BackendOperation(c).OpsService.CowEarNumberUpdate(c, &req); err != nil {
  246. apierr.ClassifiedAbort(c, err)
  247. return
  248. }
  249. ginutil.JSONResp(c, &operationPb.CommonOK{
  250. Code: http.StatusOK,
  251. Msg: "ok",
  252. Data: &operationPb.Success{Success: true},
  253. })
  254. }