ot_fire_events.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 OtFireEvents struct {
  14. api.Api
  15. }
  16. // GetPage 获取OtFireEvents列表
  17. // @Summary 获取OtFireEvents列表
  18. // @Description 获取OtFireEvents列表
  19. // @Tags OtFireEvents
  20. // @Param appId query int64 false "业务ID"
  21. // @Param ruleId query int64 false ""
  22. // @Param exceptionName query string false "告警名称/信息"
  23. // @Param appName query string false ""
  24. // @Param appAlias query string false ""
  25. // @Param alertStatus query int64 false ""
  26. // @Param isKnow query int64 false "已知悉"
  27. // @Param isResolve query int64 false "已解决"
  28. // @Param isIgnore query int64 false "已忽略"
  29. // @Param pageSize query int false "页条数"
  30. // @Param pageIndex query int false "页码"
  31. // @Success 200 {object} response.Response{data=response.Page{list=[]models.OtFireEvents}} "{"code": 200, "data": [...]}"
  32. // @Router /api/v1/ot-fire-events [get]
  33. // @Security Bearer
  34. func (e OtFireEvents) GetPage(c *gin.Context) {
  35. req := dto.OtFireEventsGetPageReq{}
  36. s := service.OtFireEvents{}
  37. err := e.MakeContext(c).
  38. MakeOrm().
  39. Bind(&req).
  40. MakeService(&s.Service).
  41. Errors
  42. if err != nil {
  43. e.Logger.Error(err)
  44. e.Error(500, err, err.Error())
  45. return
  46. }
  47. p := actions.GetPermissionFromContext(c)
  48. list := make([]models.OtFireEvents, 0)
  49. var count int64
  50. err = s.GetPage(&req, p, &list, &count)
  51. if err != nil {
  52. e.Error(500, err, fmt.Sprintf("获取OtFireEvents失败,\r\n失败信息 %s", err.Error()))
  53. return
  54. }
  55. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  56. }
  57. // Get 获取OtFireEvents
  58. // @Summary 获取OtFireEvents
  59. // @Description 获取OtFireEvents
  60. // @Tags OtFireEvents
  61. // @Param id path int false "id"
  62. // @Success 200 {object} response.Response{data=models.OtFireEvents} "{"code": 200, "data": [...]}"
  63. // @Router /api/v1/ot-fire-events/{id} [get]
  64. // @Security Bearer
  65. func (e OtFireEvents) Get(c *gin.Context) {
  66. req := dto.OtFireEventsGetReq{}
  67. s := service.OtFireEvents{}
  68. err := e.MakeContext(c).
  69. MakeOrm().
  70. Bind(&req).
  71. MakeService(&s.Service).
  72. Errors
  73. if err != nil {
  74. e.Logger.Error(err)
  75. e.Error(500, err, err.Error())
  76. return
  77. }
  78. var object models.OtFireEvents
  79. p := actions.GetPermissionFromContext(c)
  80. err = s.Get(&req, p, &object)
  81. if err != nil {
  82. e.Error(500, err, fmt.Sprintf("获取OtFireEvents失败,\r\n失败信息 %s", err.Error()))
  83. return
  84. }
  85. e.OK(object, "查询成功")
  86. }
  87. // Insert 创建OtFireEvents
  88. // @Summary 创建OtFireEvents
  89. // @Description 创建OtFireEvents
  90. // @Tags OtFireEvents
  91. // @Accept application/json
  92. // @Product application/json
  93. // @Param data body dto.OtFireEventsInsertReq true "data"
  94. // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
  95. // @Router /api/v1/ot-fire-events [post]
  96. // @Security Bearer
  97. func (e OtFireEvents) Insert(c *gin.Context) {
  98. req := dto.OtFireEventsInsertReq{}
  99. s := service.OtFireEvents{}
  100. err := e.MakeContext(c).
  101. MakeOrm().
  102. Bind(&req).
  103. MakeService(&s.Service).
  104. Errors
  105. if err != nil {
  106. e.Logger.Error(err)
  107. e.Error(500, err, err.Error())
  108. return
  109. }
  110. // 设置创建人
  111. req.SetCreateBy(user.GetUserId(c))
  112. err = s.Insert(&req)
  113. if err != nil {
  114. e.Error(500, err, fmt.Sprintf("创建OtFireEvents失败,\r\n失败信息 %s", err.Error()))
  115. return
  116. }
  117. e.OK(req.GetId(), "创建成功")
  118. }
  119. // Update 修改OtFireEvents
  120. // @Summary 修改OtFireEvents
  121. // @Description 修改OtFireEvents
  122. // @Tags OtFireEvents
  123. // @Accept application/json
  124. // @Product application/json
  125. // @Param id path int true "id"
  126. // @Param data body dto.OtFireEventsUpdateReq true "body"
  127. // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
  128. // @Router /api/v1/ot-fire-events/{id} [put]
  129. // @Security Bearer
  130. func (e OtFireEvents) Update(c *gin.Context) {
  131. req := dto.OtFireEventsUpdateReq{}
  132. s := service.OtFireEvents{}
  133. err := e.MakeContext(c).
  134. MakeOrm().
  135. Bind(&req).
  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. req.SetUpdateBy(user.GetUserId(c))
  144. p := actions.GetPermissionFromContext(c)
  145. err = s.Update(&req, p)
  146. if err != nil {
  147. e.Error(500, err, fmt.Sprintf("修改OtFireEvents失败,\r\n失败信息 %s", err.Error()))
  148. return
  149. }
  150. e.OK(req.GetId(), "修改成功")
  151. }
  152. // Delete 删除OtFireEvents
  153. // @Summary 删除OtFireEvents
  154. // @Description 删除OtFireEvents
  155. // @Tags OtFireEvents
  156. // @Param data body dto.OtFireEventsDeleteReq true "body"
  157. // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
  158. // @Router /api/v1/ot-fire-events [delete]
  159. // @Security Bearer
  160. func (e OtFireEvents) Delete(c *gin.Context) {
  161. s := service.OtFireEvents{}
  162. req := dto.OtFireEventsDeleteReq{}
  163. err := e.MakeContext(c).
  164. MakeOrm().
  165. Bind(&req).
  166. MakeService(&s.Service).
  167. Errors
  168. if err != nil {
  169. e.Logger.Error(err)
  170. e.Error(500, err, err.Error())
  171. return
  172. }
  173. // req.SetUpdateBy(user.GetUserId(c))
  174. p := actions.GetPermissionFromContext(c)
  175. err = s.Remove(&req, p)
  176. if err != nil {
  177. e.Error(500, err, fmt.Sprintf("删除OtFireEvents失败,\r\n失败信息 %s", err.Error()))
  178. return
  179. }
  180. e.OK(req.GetId(), "删除成功")
  181. }
  182. func (e OtFireEvents) Notate(c *gin.Context) {
  183. req := dto.OtFireEventsUpdateReq{}
  184. s := service.OtFireEvents{}
  185. err := e.MakeContext(c).
  186. MakeOrm().
  187. Bind(&req).
  188. MakeService(&s.Service).
  189. Errors
  190. if err != nil {
  191. e.Logger.Error(err)
  192. e.Error(500, err, err.Error())
  193. return
  194. }
  195. req.SetUpdateBy(user.GetUserId(c))
  196. p := actions.GetPermissionFromContext(c)
  197. err = s.Notate(&req, p)
  198. if err != nil {
  199. e.Error(500, err, fmt.Sprintf("Notate OtFireEvents失败,\r\n失败信息 %s", err.Error()))
  200. return
  201. }
  202. e.OK(req.GetId(), "标记成功")
  203. }