drugs.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. package goods
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. "strconv"
  6. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  7. "gitee.com/xuyiping_admin/pkg/valid"
  8. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  9. "gitee.com/xuyiping_admin/pkg/apierr"
  10. "gitee.com/xuyiping_admin/pkg/ginutil"
  11. "github.com/gin-gonic/gin"
  12. )
  13. func DrugsList(c *gin.Context) {
  14. var req pasturePb.SearchDrugsRequest
  15. if err := ginutil.BindProto(c, &req); err != nil {
  16. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  17. return
  18. }
  19. pagination := &pasturePb.PaginationModel{
  20. Page: int32(c.GetInt(middleware.Page)),
  21. PageSize: int32(c.GetInt(middleware.PageSize)),
  22. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  23. }
  24. res, err := middleware.Dependency(c).StoreEventHub.OpsService.DrugsList(c, &req, pagination)
  25. if err != nil {
  26. apierr.ClassifiedAbort(c, err)
  27. return
  28. }
  29. ginutil.JSONResp(c, res)
  30. }
  31. func DrugsCreateOrUpdate(c *gin.Context) {
  32. var req pasturePb.SearchDrugsList
  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.CategoryId, valid.Required),
  40. valid.Field(&req.Producer, valid.Required),
  41. valid.Field(&req.Usage, valid.Required),
  42. valid.Field(&req.Unit, valid.Required),
  43. valid.Field(&req.Specs, valid.Required),
  44. valid.Field(&req.Inventory, valid.Required),
  45. valid.Field(&req.ExpirationAt, valid.Required),
  46. valid.Field(&req.BatchNumber, valid.Required),
  47. ); err != nil {
  48. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  49. return
  50. }
  51. if err := middleware.BackendOperation(c).OpsService.DrugsCreateOrUpdate(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 MedicalEquipmentList(c *gin.Context) {
  62. var req pasturePb.SearchMedicalEquipmentRequest
  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.MedicalEquipmentList(c, &req, pagination)
  73. if err != nil {
  74. apierr.ClassifiedAbort(c, err)
  75. return
  76. }
  77. ginutil.JSONResp(c, res)
  78. }
  79. func MedicalEquipmentCreateOrUpdate(c *gin.Context) {
  80. var req pasturePb.SearchMedicalEquipmentList
  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.Name, valid.Required),
  87. valid.Field(&req.Producer, valid.Required),
  88. valid.Field(&req.Unit, valid.Required),
  89. valid.Field(&req.Specs, valid.Required),
  90. valid.Field(&req.Inventory, valid.Required),
  91. valid.Field(&req.BatchNumber, valid.Required),
  92. ); err != nil {
  93. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  94. return
  95. }
  96. if err := middleware.BackendOperation(c).OpsService.MedicalEquipmentCreateOrUpdate(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 NeckRingList(c *gin.Context) {
  107. var req pasturePb.SearchNeckRingRequest
  108. if err := ginutil.BindProto(c, &req); err != nil {
  109. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  110. return
  111. }
  112. pagination := &pasturePb.PaginationModel{
  113. Page: int32(c.GetInt(middleware.Page)),
  114. PageSize: int32(c.GetInt(middleware.PageSize)),
  115. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  116. }
  117. res, err := middleware.Dependency(c).StoreEventHub.OpsService.NeckRingLogList(c, &req, pagination)
  118. if err != nil {
  119. apierr.ClassifiedAbort(c, err)
  120. return
  121. }
  122. ginutil.JSONResp(c, res)
  123. }
  124. func NeckRingCreateOrUpdate(c *gin.Context) {
  125. var req pasturePb.NeckRingCreateRequest
  126. if err := ginutil.BindProto(c, &req); err != nil {
  127. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  128. return
  129. }
  130. if err := valid.ValidateStruct(&req,
  131. valid.Field(&req.Items, valid.Required),
  132. ); err != nil {
  133. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  134. return
  135. }
  136. if err := middleware.BackendOperation(c).OpsService.NeckRingLogCreateOrUpdate(c, &req); err != nil {
  137. apierr.ClassifiedAbort(c, err)
  138. return
  139. }
  140. ginutil.JSONResp(c, &operationPb.CommonOK{
  141. Code: http.StatusOK,
  142. Msg: "ok",
  143. Data: &operationPb.Success{Success: true},
  144. })
  145. }
  146. func OutboundApply(c *gin.Context) {
  147. var req pasturePb.OutboundApplyItem
  148. if err := ginutil.BindProto(c, &req); err != nil {
  149. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  150. return
  151. }
  152. if err := valid.ValidateStruct(&req,
  153. valid.Field(&req.OutType, valid.Required),
  154. valid.Field(&req.Goods, valid.Required),
  155. ); err != nil {
  156. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  157. return
  158. }
  159. if err := middleware.BackendOperation(c).OpsService.OutboundApply(c, &req); err != nil {
  160. apierr.ClassifiedAbort(c, err)
  161. return
  162. }
  163. ginutil.JSONResp(c, &operationPb.CommonOK{
  164. Code: http.StatusOK,
  165. Msg: "ok",
  166. Data: &operationPb.Success{Success: true},
  167. })
  168. }
  169. func OutboundList(c *gin.Context) {
  170. var req pasturePb.SearchOutboundApplyRequest
  171. if err := ginutil.BindProto(c, &req); err != nil {
  172. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  173. return
  174. }
  175. pagination := &pasturePb.PaginationModel{
  176. Page: int32(c.GetInt(middleware.Page)),
  177. PageSize: int32(c.GetInt(middleware.PageSize)),
  178. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  179. }
  180. res, err := middleware.Dependency(c).StoreEventHub.OpsService.OutboundList(c, &req, pagination)
  181. if err != nil {
  182. apierr.ClassifiedAbort(c, err)
  183. return
  184. }
  185. ginutil.JSONResp(c, res)
  186. }
  187. func OutboundAudit(c *gin.Context) {
  188. var req pasturePb.OutboundApplyAuditRequest
  189. if err := ginutil.BindProto(c, &req); err != nil {
  190. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  191. return
  192. }
  193. if err := valid.ValidateStruct(&req,
  194. valid.Field(&req.Id, valid.Required),
  195. valid.Field(&req.AuditStatus, valid.Required),
  196. ); err != nil {
  197. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  198. return
  199. }
  200. if err := middleware.BackendOperation(c).OpsService.OutboundAudit(c, &req); err != nil {
  201. apierr.ClassifiedAbort(c, err)
  202. return
  203. }
  204. ginutil.JSONResp(c, &operationPb.CommonOK{
  205. Code: http.StatusOK,
  206. Msg: "ok",
  207. Data: &operationPb.Success{Success: true},
  208. })
  209. }
  210. func OutboundDetail(c *gin.Context) {
  211. idStr := c.Query("id")
  212. id, _ := strconv.ParseInt(idStr, 10, 64)
  213. if err := valid.Validate(id, valid.Required); err != nil {
  214. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  215. return
  216. }
  217. res, err := middleware.BackendOperation(c).OpsService.OutboundDetail(c, id)
  218. if err != nil {
  219. apierr.ClassifiedAbort(c, err)
  220. return
  221. }
  222. ginutil.JSONResp(c, res)
  223. }