barn.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. package pasture
  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 SearchBarnList(c *gin.Context) {
  13. var req pasturePb.SearchNameRequest
  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.SearchBarnList(c, &req, pagination)
  24. if err != nil {
  25. apierr.ClassifiedAbort(c, err)
  26. return
  27. }
  28. ginutil.JSONResp(c, res)
  29. }
  30. // CreatedOrUpdateBarn 添加或者更新栏舍
  31. func CreatedOrUpdateBarn(c *gin.Context) {
  32. var req pasturePb.SearchBarnList
  33. if err := ginutil.BindProto(c, &req); err != nil {
  34. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  35. return
  36. }
  37. if err := valid.ValidateStruct(&req,
  38. valid.Field(&req.Name, valid.Required),
  39. valid.Field(&req.Lengths, valid.Required, valid.Min(1)),
  40. valid.Field(&req.Widths, valid.Required, valid.Min(1)),
  41. valid.Field(&req.DoctrinalCapacity, valid.Required, valid.Min(1)),
  42. ); err != nil {
  43. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  44. return
  45. }
  46. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateBarn(c, &req); err != nil {
  47. apierr.ClassifiedAbort(c, err)
  48. return
  49. }
  50. ginutil.JSONResp(c, &operationPb.CommonOK{
  51. Code: http.StatusOK,
  52. Msg: "ok",
  53. Data: &operationPb.Success{Success: true},
  54. })
  55. }
  56. func SearchBarnTypeList(c *gin.Context) {
  57. var req pasturePb.SearchNameRequest
  58. if err := ginutil.BindProto(c, &req); err != nil {
  59. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  60. return
  61. }
  62. pagination := &pasturePb.PaginationModel{
  63. Page: int32(c.GetInt(middleware.Page)),
  64. PageSize: int32(c.GetInt(middleware.PageSize)),
  65. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  66. }
  67. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchBarnTypeList(c, &req, pagination)
  68. if err != nil {
  69. apierr.ClassifiedAbort(c, err)
  70. return
  71. }
  72. ginutil.JSONResp(c, res)
  73. }
  74. // CreatedOrUpdateBarnType 添加或者更新栏舍类型
  75. func CreatedOrUpdateBarnType(c *gin.Context) {
  76. var req pasturePb.SearchBaseConfigList
  77. if err := ginutil.BindProto(c, &req); err != nil {
  78. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  79. return
  80. }
  81. if err := valid.ValidateStruct(&req,
  82. valid.Field(&req.Name, valid.Required),
  83. ); err != nil {
  84. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  85. return
  86. }
  87. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateBarnType(c, &req); err != nil {
  88. apierr.ClassifiedAbort(c, err)
  89. return
  90. }
  91. ginutil.JSONResp(c, &operationPb.CommonOK{
  92. Code: http.StatusOK,
  93. Msg: "ok",
  94. Data: &operationPb.Success{Success: true},
  95. })
  96. }
  97. func SearchBreedStatusList(c *gin.Context) {
  98. var req pasturePb.SearchNameRequest
  99. if err := ginutil.BindProto(c, &req); err != nil {
  100. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  101. return
  102. }
  103. pagination := &pasturePb.PaginationModel{
  104. Page: int32(c.GetInt(middleware.Page)),
  105. PageSize: int32(c.GetInt(middleware.PageSize)),
  106. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  107. }
  108. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchBreedStatusList(c, &req, pagination)
  109. if err != nil {
  110. apierr.ClassifiedAbort(c, err)
  111. return
  112. }
  113. ginutil.JSONResp(c, res)
  114. }
  115. // CreatedOrUpdateBreedStatus 添加或者更新繁殖状态
  116. func CreatedOrUpdateBreedStatus(c *gin.Context) {
  117. var req pasturePb.SearchBaseConfigList
  118. if err := ginutil.BindProto(c, &req); err != nil {
  119. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  120. return
  121. }
  122. if err := valid.ValidateStruct(&req,
  123. valid.Field(&req.Name, valid.Required),
  124. ); err != nil {
  125. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  126. return
  127. }
  128. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateBreedStatus(c, &req); err != nil {
  129. apierr.ClassifiedAbort(c, err)
  130. return
  131. }
  132. ginutil.JSONResp(c, &operationPb.CommonOK{
  133. Code: http.StatusOK,
  134. Msg: "ok",
  135. Data: &operationPb.Success{Success: true},
  136. })
  137. }
  138. func SearchCowKindList(c *gin.Context) {
  139. var req pasturePb.SearchNameRequest
  140. if err := ginutil.BindProto(c, &req); err != nil {
  141. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  142. return
  143. }
  144. pagination := &pasturePb.PaginationModel{
  145. Page: int32(c.GetInt(middleware.Page)),
  146. PageSize: int32(c.GetInt(middleware.PageSize)),
  147. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  148. }
  149. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchCowKindList(c, &req, pagination)
  150. if err != nil {
  151. apierr.ClassifiedAbort(c, err)
  152. return
  153. }
  154. ginutil.JSONResp(c, res)
  155. }
  156. // CreatedOrUpdateCowKind 添加或者更新牛只种类
  157. func CreatedOrUpdateCowKind(c *gin.Context) {
  158. var req pasturePb.SearchBaseConfigList
  159. if err := ginutil.BindProto(c, &req); err != nil {
  160. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  161. return
  162. }
  163. if err := valid.ValidateStruct(&req,
  164. valid.Field(&req.Name, valid.Required),
  165. ); err != nil {
  166. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  167. return
  168. }
  169. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateCowKind(c, &req); err != nil {
  170. apierr.ClassifiedAbort(c, err)
  171. return
  172. }
  173. ginutil.JSONResp(c, &operationPb.CommonOK{
  174. Code: http.StatusOK,
  175. Msg: "ok",
  176. Data: &operationPb.Success{Success: true},
  177. })
  178. }
  179. func SearchCowStatusList(c *gin.Context) {
  180. var req pasturePb.SearchNameRequest
  181. if err := ginutil.BindProto(c, &req); err != nil {
  182. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  183. return
  184. }
  185. pagination := &pasturePb.PaginationModel{
  186. Page: int32(c.GetInt(middleware.Page)),
  187. PageSize: int32(c.GetInt(middleware.PageSize)),
  188. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  189. }
  190. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchCowStatusList(c, &req, pagination)
  191. if err != nil {
  192. apierr.ClassifiedAbort(c, err)
  193. return
  194. }
  195. ginutil.JSONResp(c, res)
  196. }
  197. // CreatedOrUpdateCowStatus 添加或者更新牛只状态
  198. func CreatedOrUpdateCowStatus(c *gin.Context) {
  199. var req pasturePb.SearchBaseConfigList
  200. if err := ginutil.BindProto(c, &req); err != nil {
  201. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  202. return
  203. }
  204. if err := valid.ValidateStruct(&req,
  205. valid.Field(&req.Name, valid.Required),
  206. ); err != nil {
  207. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  208. return
  209. }
  210. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateCowStatus(c, &req); err != nil {
  211. apierr.ClassifiedAbort(c, err)
  212. return
  213. }
  214. ginutil.JSONResp(c, &operationPb.CommonOK{
  215. Code: http.StatusOK,
  216. Msg: "ok",
  217. Data: &operationPb.Success{Success: true},
  218. })
  219. }