sms_api.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package client
  2. import (
  3. "ulink-admin/frame"
  4. "ulink-admin/modules/system/models/model"
  5. "ulink-admin/modules/system/models/req"
  6. "ulink-admin/modules/system/models/response"
  7. "ulink-admin/modules/system/service"
  8. "ulink-admin/pkg/excels"
  9. "ulink-admin/pkg/file"
  10. "ulink-admin/pkg/page"
  11. "ulink-admin/utils"
  12. )
  13. type SmsApi struct {
  14. SmsService *service.SmsService `inject:""`
  15. }
  16. // List 查询短信管理分页数据
  17. // @Summary 分页查询短信管理数据接口
  18. // @Description 分页查询短信管理数据接口
  19. // @Tags 短信管理相关接口
  20. // @Accept application/json
  21. // @Produce application/json
  22. // @Param Authorization header string false "Bearer 令牌"
  23. // @Param object query req.SmsQuery false "查询参数"
  24. // @Security ApiKeyAuth
  25. // @Success 200 {object} resp.Response{data=page.Page{list=model.Sms},msg=string} "分页获取短信管理列表,返回包括列表,总数,页码,每页数量"
  26. // @Router /sms/page [get]
  27. func (this SmsApi) Page(c *frame.Context) {
  28. query := &req.SmsQuery{}
  29. c.ValidteError(c.ShouldBind(query), query)
  30. list := make([]response.SmsResponse, 0)
  31. i := this.SmsService.Page(query, &list)
  32. c.Ok(page.Page{List: list, Total: i, Size: query.PageSize})
  33. }
  34. // List 查询短信管理所有数据
  35. // @Summary 查询全部数据短信管理数据接口
  36. // @Description 查询全部数据短信管理数据接口
  37. // @Tags 短信管理相关接口
  38. // @Accept application/json
  39. // @Produce application/json
  40. // @Param Authorization header string false "Bearer 令牌"
  41. // @Param object query req.SmsQuery false "查询参数"
  42. // @Security ApiKeyAuth
  43. // @Success 200 {object} resp.Response{data=model.Sms,msg=string} "分页获取短信管理列表,返回包括列表,总数,页码,每页数量"
  44. // @Router /sms/list [get]
  45. func (this SmsApi) List(c *frame.Context) {
  46. query := &req.SmsQuery{}
  47. list := make([]response.SmsResponse, 0)
  48. c.ValidteError(c.ShouldBind(query), query)
  49. this.SmsService.List(query, &list)
  50. c.Ok(list)
  51. }
  52. // Get 根据短信管理Id获取详细信息
  53. // @Summary 短信管理详情查询接口
  54. // @Description 短信管理详情查询接口
  55. // @Tags 短信管理相关接口
  56. // @Accept application/json
  57. // @Produce application/json
  58. // @Param Authorization header string false "Bearer 令牌"
  59. // @Param id query int true "id" id
  60. // @Security ApiKeyAuth
  61. // @Success 200 {object} resp.Response{data=model.Sms,msg=string} "返回短信管理详情查询"
  62. // @Router /sms [get]
  63. func (this SmsApi) Get(c *frame.Context) {
  64. var req struct {
  65. Id int64 `form:"id" binding:"required" msg:"id不存在" ` //id
  66. }
  67. c.ValidteError(c.ShouldBind(&req), &req)
  68. c.Ok(this.SmsService.Get(req.Id))
  69. }
  70. // Get 根据短信管理Id获取详细信息
  71. // @Summary 短信管理详情查询接口
  72. // @Description 短信管理详情查询接口
  73. // @Tags 短信管理相关接口
  74. // @Accept application/json
  75. // @Produce application/json
  76. // @Param Authorization header string false "Bearer 令牌"
  77. // @Param id query int true "id" id
  78. // @Security ApiKeyAuth
  79. // @Success 200 {object} resp.Response{data=model.Sms,msg=string} "返回短信管理详情查询"
  80. // @Router /sms/code [get]
  81. func (this SmsApi) GetSmsCode(c *frame.Context) {
  82. var req struct {
  83. Phone string `form:"phone" binding:"required" msg:"手机号不存在" ` //id
  84. }
  85. c.ValidteError(c.ShouldBind(&req), &req)
  86. c.Ok(this.SmsService.GetSmsCode(req.Phone))
  87. }
  88. // Add 新增短信管理
  89. // @Summary 新增短信管理接口
  90. // @Description 新增短信管理接口
  91. // @Tags 短信管理相关接口
  92. // @Accept application/json
  93. // @Produce application/json
  94. // @Param Authorization header string false "Bearer 令牌"
  95. // @Param data body model.Sms true "短信管理实体对象"
  96. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  97. // @Router /sms/add [post]
  98. func (this SmsApi) Add(c *frame.Context) {
  99. params, sms := &req.SmsAdd{}, &model.Sms{}
  100. c.ValidteError(c.ShouldBind(params), params)
  101. utils.CopyFields(sms, params)
  102. this.SmsService.Insert(sms)
  103. }
  104. // Edit 修改短信管理数据接口
  105. // @Summary 修改短信管理接口
  106. // @Description 新增短信管理接口
  107. // @Tags 短信管理相关接口
  108. // @Accept application/json
  109. // @Produce application/json
  110. // @Param Authorization header string false "Bearer 令牌"
  111. // @Param data body model.Sms true "短信管理实体对象"
  112. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  113. // @Router /sms/edit [put]
  114. func (this SmsApi) Edit(c *frame.Context) {
  115. params, sms := &req.SmsEdit{}, &model.Sms{}
  116. c.ValidteError(c.ShouldBind(params), params)
  117. utils.CopyFields(sms, params)
  118. this.SmsService.Edit(sms, c.Cols())
  119. }
  120. // Delete 删除短信管理数据
  121. // @Summary 删除短信管理接口
  122. // @Description 删除短信管理接口
  123. // @Tags 短信管理相关接口
  124. // @Accept application/json
  125. // @Produce application/json
  126. // @Param Authorization header string false "Bearer 令牌"
  127. // @Param id path int true "id" id
  128. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  129. // @Router /sms [delete]
  130. func (a SmsApi) Delete(c *frame.Context) {
  131. var req struct {
  132. Ids []int64 `form:"ids" binding:"required" msg:"ids不存在"` //ids
  133. }
  134. c.ValidteError(c.ShouldBind(&req), &req)
  135. a.SmsService.Delete(req.Ids)
  136. }
  137. // Export 导出excel
  138. func (this SmsApi) Export(c *frame.Context) {
  139. query := &req.SmsQuery{}
  140. list := make([]model.Sms, 0)
  141. c.ValidteError(c.ShouldBind(query), query)
  142. this.SmsService.List(query, list)
  143. excelList := make([]interface{}, 0)
  144. for _, sms := range list {
  145. excelList = append(excelList, sms)
  146. }
  147. _, files := excels.ExportExcel(excelList, "短信管理数据表")
  148. file.DownloadExcel(c, files)
  149. }