ot_app_dashboard.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package apis
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "github.com/go-admin-team/go-admin-core/sdk/api"
  6. "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
  7. _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
  8. "go-admin/app/admin/models"
  9. "go-admin/app/admin/service"
  10. "go-admin/app/admin/service/dto"
  11. "go-admin/common/actions"
  12. )
  13. type OtAppDashboard struct {
  14. api.Api
  15. }
  16. // GetPage 获取OtAppDashboard列表
  17. // @Summary 获取OtAppDashboard列表
  18. // @Description 获取OtAppDashboard列表
  19. // @Tags OtAppDashboard
  20. // @Param pageSize query int false "页条数"
  21. // @Param pageIndex query int false "页码"
  22. // @Success 200 {object} response.Response{data=response.Page{list=[]models.OtAppDashboard}} "{"code": 200, "data": [...]}"
  23. // @Router /api/v1/ot-app-dashboard [get]
  24. // @Security Bearer
  25. func (e OtAppDashboard) GetPage(c *gin.Context) {
  26. req := dto.OtAppDashboardGetPageReq{}
  27. s := service.OtAppDashboard{}
  28. err := e.MakeContext(c).
  29. MakeOrm().
  30. Bind(&req).
  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. p := actions.GetPermissionFromContext(c)
  39. list := make([]models.OtAppDashboard, 0)
  40. var count int64
  41. err = s.GetPage(&req, p, &list, &count)
  42. if err != nil {
  43. e.Error(500, err, fmt.Sprintf("获取OtAppDashboard失败,\r\n失败信息 %s", err.Error()))
  44. return
  45. }
  46. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  47. }
  48. // Get 获取OtAppDashboard
  49. // @Summary 获取OtAppDashboard
  50. // @Description 获取OtAppDashboard
  51. // @Tags OtAppDashboard
  52. // @Param id path int false "id"
  53. // @Success 200 {object} response.Response{data=models.OtAppDashboard} "{"code": 200, "data": [...]}"
  54. // @Router /api/v1/ot-app-dashboard/{id} [get]
  55. // @Security Bearer
  56. func (e OtAppDashboard) Get(c *gin.Context) {
  57. req := dto.OtAppDashboardGetReq{}
  58. s := service.OtAppDashboard{}
  59. err := e.MakeContext(c).
  60. MakeOrm().
  61. Bind(&req).
  62. MakeService(&s.Service).
  63. Errors
  64. if err != nil {
  65. e.Logger.Error(err)
  66. e.Error(500, err, err.Error())
  67. return
  68. }
  69. var object models.OtAppDashboard
  70. p := actions.GetPermissionFromContext(c)
  71. err = s.Get(&req, p, &object)
  72. if err != nil {
  73. e.Error(500, err, fmt.Sprintf("获取OtAppDashboard失败,\r\n失败信息 %s", err.Error()))
  74. return
  75. }
  76. e.OK(object, "查询成功")
  77. }
  78. // Insert 创建OtAppDashboard
  79. // @Summary 创建OtAppDashboard
  80. // @Description 创建OtAppDashboard
  81. // @Tags OtAppDashboard
  82. // @Accept application/json
  83. // @Product application/json
  84. // @Param data body dto.OtAppDashboardInsertReq true "data"
  85. // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
  86. // @Router /api/v1/ot-app-dashboard [post]
  87. // @Security Bearer
  88. func (e OtAppDashboard) Insert(c *gin.Context) {
  89. req := dto.OtAppDashboardInsertReq{}
  90. s := service.OtAppDashboard{}
  91. err := e.MakeContext(c).
  92. MakeOrm().
  93. Bind(&req).
  94. MakeService(&s.Service).
  95. Errors
  96. if err != nil {
  97. e.Logger.Error(err)
  98. e.Error(500, err, err.Error())
  99. return
  100. }
  101. // 设置创建人
  102. req.SetCreateBy(user.GetUserId(c))
  103. err = s.Insert(&req)
  104. if err != nil {
  105. e.Error(500, err, fmt.Sprintf("创建OtAppDashboard失败,\r\n失败信息 %s", err.Error()))
  106. return
  107. }
  108. e.OK(req.GetId(), "创建成功")
  109. }
  110. // Update 修改OtAppDashboard
  111. // @Summary 修改OtAppDashboard
  112. // @Description 修改OtAppDashboard
  113. // @Tags OtAppDashboard
  114. // @Accept application/json
  115. // @Product application/json
  116. // @Param id path int true "id"
  117. // @Param data body dto.OtAppDashboardUpdateReq true "body"
  118. // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
  119. // @Router /api/v1/ot-app-dashboard/{id} [put]
  120. // @Security Bearer
  121. func (e OtAppDashboard) Update(c *gin.Context) {
  122. req := dto.OtAppDashboardUpdateReq{}
  123. s := service.OtAppDashboard{}
  124. err := e.MakeContext(c).
  125. MakeOrm().
  126. Bind(&req).
  127. MakeService(&s.Service).
  128. Errors
  129. if err != nil {
  130. e.Logger.Error(err)
  131. e.Error(500, err, err.Error())
  132. return
  133. }
  134. req.SetUpdateBy(user.GetUserId(c))
  135. p := actions.GetPermissionFromContext(c)
  136. err = s.Update(&req, p)
  137. if err != nil {
  138. e.Error(500, err, fmt.Sprintf("修改OtAppDashboard失败,\r\n失败信息 %s", err.Error()))
  139. return
  140. }
  141. e.OK(req.GetId(), "修改成功")
  142. }
  143. // Delete 删除OtAppDashboard
  144. // @Summary 删除OtAppDashboard
  145. // @Description 删除OtAppDashboard
  146. // @Tags OtAppDashboard
  147. // @Param data body dto.OtAppDashboardDeleteReq true "body"
  148. // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
  149. // @Router /api/v1/ot-app-dashboard [delete]
  150. // @Security Bearer
  151. func (e OtAppDashboard) Delete(c *gin.Context) {
  152. s := service.OtAppDashboard{}
  153. req := dto.OtAppDashboardDeleteReq{}
  154. err := e.MakeContext(c).
  155. MakeOrm().
  156. Bind(&req).
  157. MakeService(&s.Service).
  158. Errors
  159. if err != nil {
  160. e.Logger.Error(err)
  161. e.Error(500, err, err.Error())
  162. return
  163. }
  164. // req.SetUpdateBy(user.GetUserId(c))
  165. p := actions.GetPermissionFromContext(c)
  166. err = s.Remove(&req, p)
  167. if err != nil {
  168. e.Error(500, err, fmt.Sprintf("删除OtAppDashboard失败,\r\n失败信息 %s", err.Error()))
  169. return
  170. }
  171. e.OK(req.GetId(), "删除成功")
  172. }
  173. func (e OtAppDashboard) GetDashBoardByAppId(c *gin.Context) {
  174. req := dto.OtAppDashboardGetByAppReq{}
  175. s := service.OtAppDashboard{}
  176. err := e.MakeContext(c).
  177. MakeOrm().
  178. Bind(&req).
  179. MakeService(&s.Service).
  180. Errors
  181. if err != nil {
  182. e.Logger.Error(err)
  183. e.Error(500, err, err.Error())
  184. return
  185. }
  186. var object models.OtAppDashboard
  187. object.AppId = req.AppId
  188. err = s.GetByAppId(&object)
  189. if err != nil {
  190. e.Error(500, err, fmt.Sprintf("获取OtAppDashboard失败,\r\n失败信息 %s", err.Error()))
  191. return
  192. }
  193. e.OK(object, "查询成功")
  194. }