gas_cylinder.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package controller
  2. import (
  3. "gas-cylinder-api/app/admin/model"
  4. "gas-cylinder-api/app/admin/service"
  5. "gas-cylinder-api/app/admin/service/dto"
  6. "gas-cylinder-api/common/actions"
  7. "github.com/gin-gonic/gin"
  8. "github.com/gin-gonic/gin/binding"
  9. "gogs.baozhida.cn/zoie/OAuth-core/api"
  10. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  11. )
  12. type GasCylinderController struct {
  13. api.Api
  14. }
  15. // GetPage 获取钢瓶档案列表
  16. // @Summary 获取钢瓶档案列表
  17. // @Description 获取钢瓶档案列表
  18. // @Tags 钢瓶档案
  19. // @Param innerCode query string false "单位内编码"
  20. // @Param pageSize query int false "页条数"
  21. // @Param page query int false "页码"
  22. // @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinder}} "{"code": 200, "data": [...]}"
  23. // @Router /api/dispatch-cost [get]
  24. // @Security Bearer
  25. func (e GasCylinderController) GetPage(c *gin.Context) {
  26. s := service.GasCylinder{}
  27. req := dto.GasCylinderGetPageReq{}
  28. err := e.MakeContext(c).
  29. MakeOrm().
  30. Bind(&req, binding.Query).
  31. MakeService(&s.Service).
  32. Errors
  33. if err != nil {
  34. e.Logger.Error(err)
  35. e.Error(500, err, err.Error())
  36. return
  37. }
  38. //数据权限检查
  39. p := actions.GetPermissionFromContext(c)
  40. list := make([]model.GasCylinder, 0)
  41. var count int64
  42. err = s.GetPage(&req, &list, &count, p)
  43. if err != nil {
  44. e.Error(500, err, err.Error())
  45. return
  46. }
  47. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  48. }
  49. // Get 通过id获取钢瓶档案
  50. // @Summary 通过id获取钢瓶档案
  51. // @Description 通过id获取钢瓶档案
  52. // @Tags 钢瓶档案
  53. // @Param id path string true "钢瓶档案id"
  54. // @Success 200 {object} response.Response{data=model.GasCylinder} "{"code": 200, "data": [...]}"
  55. // @Router /api/goods/{id} [get]
  56. // @Security Bearer
  57. func (e GasCylinderController) Get(c *gin.Context) {
  58. s := service.GasCylinder{}
  59. req := dto.GasCylinderGetReq{}
  60. err := e.MakeContext(c).
  61. MakeOrm().
  62. Bind(&req, nil).
  63. MakeService(&s.Service).
  64. Errors
  65. if err != nil {
  66. e.Logger.Error(err)
  67. e.Error(500, err, err.Error())
  68. return
  69. }
  70. var object model.ProvGasCylinder
  71. p := actions.GetPermissionFromContext(c)
  72. //数据权限检查
  73. err = s.Get(&req, &object, p)
  74. if err != nil {
  75. e.Error(500, err, err.Error())
  76. return
  77. }
  78. e.OK(object, "查询成功")
  79. }
  80. // GetByUid 通过高频编码获取钢瓶信息
  81. // @Summary 通过高频编码获取钢瓶信息
  82. // @Description 通过高频编码获取钢瓶信息
  83. // @Tags 钢瓶档案
  84. // @Param chipUid path string true "高频编码"
  85. // @Success 200 {object} response.Response{data=model.GasCylinder} "{"code": 200, "data": [...]}"
  86. // @Router /api/goods/{id} [get]
  87. // @Security Bearer
  88. func (e GasCylinderController) GetByUid(c *gin.Context) {
  89. s := service.GasCylinder{}
  90. operationLogSvc := service.OperationLog{}
  91. req := dto.GasCylinderGetByUidReq{}
  92. err := e.MakeContext(c).
  93. MakeOrm().
  94. Bind(&req, nil).
  95. MakeService(&s.Service).
  96. MakeService(&operationLogSvc.Service).
  97. Errors
  98. if err != nil {
  99. e.Logger.Error(err)
  100. e.Error(500, err, err.Error())
  101. return
  102. }
  103. var gasCylinder model.ProvGasCylinder
  104. p := actions.GetPermissionFromContext(c)
  105. //数据权限检查
  106. err = s.GetByUid(&req, &gasCylinder, p)
  107. if err != nil {
  108. e.Error(500, err, err.Error())
  109. return
  110. }
  111. operationLogList := make([]model.OperationLog, 0)
  112. err = operationLogSvc.ListByUid(gasCylinder.InnerCode, &operationLogList)
  113. if err != nil {
  114. e.Error(500, err, err.Error())
  115. return
  116. }
  117. e.OK(map[string]interface{}{
  118. "gasCylinder": gasCylinder,
  119. "operationLog": operationLogList,
  120. }, "查询成功")
  121. }
  122. // Mock 模拟气瓶数据
  123. // @Summary 模拟气瓶数据
  124. // @Description 模拟气瓶数据
  125. // @Tags 钢瓶档案
  126. // @Param data body dto.GasCylinderMockReq true "data"
  127. // @Success 200 {object} response.Response{data=model.GasCylinder} "{"code": 200, "data": [...]}"
  128. // @Router /api/goods/{id} [get]
  129. // @Security Bearer
  130. func (e GasCylinderController) Mock(c *gin.Context) {
  131. s := service.GasCylinder{}
  132. req := dto.GasCylinderMockReq{}
  133. err := e.MakeContext(c).
  134. MakeOrm().
  135. Bind(&req, binding.JSON).
  136. MakeService(&s.Service).
  137. Errors
  138. if err != nil {
  139. e.Logger.Error(err)
  140. e.Error(500, err, err.Error())
  141. return
  142. }
  143. //数据权限检查
  144. err = s.Mock(&req)
  145. if err != nil {
  146. e.Error(500, err, err.Error())
  147. return
  148. }
  149. e.OK(nil, "生成成功")
  150. }