doc_file_api.go 4.7 KB

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