game_task.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package task
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "go.uber.org/zap"
  5. "log-server/global"
  6. "log-server/model/common/response"
  7. "log-server/model/task/request"
  8. "log-server/utils"
  9. )
  10. type GameTaskApi struct {
  11. }
  12. // @Tags gameTask
  13. // @Summary 创建游戏任务
  14. // @Security ApiKeyAuth
  15. // @accept application/json
  16. // @Produce application/json
  17. // @Param data body request.GameTaskRequest true
  18. // @Success 200 {object} response.Response{msg=string} "创建游戏任务"
  19. // @Router /gameTask/create [post]
  20. func (s *GameTaskApi) CreateGameTask(c *gin.Context) {
  21. var api request.GameTaskRequest
  22. _ = c.ShouldBindJSON(&api)
  23. if err := utils.Verify(api, utils.GameTaskVerify); err != nil {
  24. response.FailWithMessage(err.Error(), c)
  25. return
  26. }
  27. if err := taskService.CreateGameTask(api); err != nil {
  28. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  29. response.FailWithMessage("创建失败", c)
  30. } else {
  31. response.OkWithMessage("创建成功", c)
  32. }
  33. }
  34. // @Tags gameTask
  35. // @Summary 游戏任务列表
  36. // @Security ApiKeyAuth
  37. // @accept application/json
  38. // @Produce application/json
  39. // @Param data body request.GetCardListRequest true "游戏任务列表"
  40. // @Success 200 {object} response.Response{data=response.GetGameTaskListReply,msg=string} "分页游戏任务列表,返回包括列表,总数,页码,每页数量"
  41. // @Router /gameTask/getGameTaskList [post]
  42. func (s *GameTaskApi) GetGameTaskList(c *gin.Context) {
  43. var paramsInfo request.GetGameTaskListRequest
  44. _ = c.ShouldBindJSON(&paramsInfo)
  45. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  46. response.FailWithMessage(err.Error(), c)
  47. return
  48. }
  49. if list, total, err := taskService.GetGameTaskInfoList(paramsInfo.GameTask, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc); err != nil {
  50. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  51. response.FailWithMessage("获取失败", c)
  52. } else {
  53. response.OkWithDetailed(response.PageResult{
  54. List: list,
  55. Total: total,
  56. Page: paramsInfo.Page,
  57. PageSize: paramsInfo.PageSize,
  58. }, "获取成功", c)
  59. }
  60. }
  61. // @Tags gameTask
  62. // @Summary 根据id获取游戏任务信息
  63. // @Security ApiKeyAuth
  64. // @accept application/json
  65. // @Produce application/json
  66. // @Param data body request.GetById true "根据id获取游戏任务信息"
  67. // @Success 200 {object} response.Response{data=systemRes.GameTaskRequest} "根据id获取游戏任务信息,返回包括游戏任务信息详情"
  68. // @Router /gameTask/getGameTaskById [post]
  69. func (s *GameTaskApi) GetGameTaskById(c *gin.Context) {
  70. var idInfo request.GetById
  71. _ = c.ShouldBindJSON(&idInfo)
  72. if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
  73. response.FailWithMessage(err.Error(), c)
  74. return
  75. }
  76. api, err := taskService.GetGameTaskById(idInfo.ID)
  77. if err != nil {
  78. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  79. response.FailWithMessage("获取失败", c)
  80. } else {
  81. response.OkWithDetailed(api, "获取成功", c)
  82. }
  83. }
  84. // @Tags GameTask
  85. // @Summary 游戏任务信息状态
  86. // @Security ApiKeyAuth
  87. // @accept application/json
  88. // @Produce application/json
  89. // @Param data body request.UpdateGameTaskStatusRequest true "id, 状态"
  90. // @Success 200 {object} response.Response{msg=string} "修改游戏任务信息状态"
  91. // @Router /gameTask/statusOperation [post]
  92. func (s *GameTaskApi) StatusOperation(c *gin.Context) {
  93. var paramsInfo request.UpdateGameTaskStatusRequest
  94. _ = c.ShouldBindJSON(&paramsInfo)
  95. if paramsInfo.TaskId == 0 {
  96. response.FailWithMessage("Id不能为空", c)
  97. return
  98. }
  99. if paramsInfo.Status == 0 {
  100. response.FailWithMessage("状态值不能为空", c)
  101. return
  102. }
  103. if err := taskService.UpdateGameTaskStatus(paramsInfo); err != nil {
  104. global.GVA_LOG.Error("修改失败!", zap.Error(err))
  105. response.FailWithMessage(err.Error(), c)
  106. } else {
  107. response.OkWithMessage("修改成功", c)
  108. }
  109. }
  110. // @Tags gameTask
  111. // @Summary 更新游戏任务
  112. // @Security ApiKeyAuth
  113. // @accept application/json
  114. // @Produce application/json
  115. // @Param data body request.GameTaskRequest true
  116. // @Success 200 {object} response.Response{msg=string} "更新游戏任务"
  117. // @Router /gameTask/update [post]
  118. func (s *GameTaskApi) UpdateGameTask(c *gin.Context) {
  119. var api request.GameTaskRequest
  120. _ = c.ShouldBindJSON(&api)
  121. if err := utils.Verify(api, utils.GameTaskVerify); err != nil {
  122. response.FailWithMessage(err.Error(), c)
  123. return
  124. }
  125. if err := taskService.UpdateGameTask(api); err != nil {
  126. global.GVA_LOG.Error("更新失败!", zap.Error(err))
  127. response.FailWithMessage("更新失败", c)
  128. } else {
  129. response.OkWithMessage("更新成功", c)
  130. }
  131. }
  132. // @Tags gameTask
  133. // @Summary 删除gameTask
  134. // @Security ApiKeyAuth
  135. // @accept application/json
  136. // @Produce application/json
  137. // @Param data body task.GameTask true "ID"
  138. // @Success 200 {object} response.Response{msg=string} "删除gameTask"
  139. // @Router /gameTask/delete [post]
  140. func (s *GameTaskApi) DeleteGameTask(c *gin.Context) {
  141. var api request.GameTaskRequest
  142. _ = c.ShouldBindJSON(&api)
  143. if err := utils.Verify(api, utils.TaskIdVerify); err != nil {
  144. response.FailWithMessage(err.Error(), c)
  145. return
  146. }
  147. if err := taskService.DeleteGameTask(api); err != nil {
  148. global.GVA_LOG.Error("删除失败!", zap.Error(err))
  149. response.FailWithMessage("删除失败", c)
  150. } else {
  151. response.OkWithMessage("删除成功", c)
  152. }
  153. }