company_api.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package admin
  2. import (
  3. "ulink-admin/frame"
  4. "ulink-admin/modules/car/models/model"
  5. "ulink-admin/modules/car/models/req"
  6. "ulink-admin/modules/car/models/response"
  7. "ulink-admin/modules/car/service"
  8. "ulink-admin/pkg/excels"
  9. "ulink-admin/pkg/file"
  10. "ulink-admin/pkg/page"
  11. "ulink-admin/utils"
  12. )
  13. type CompanyApi struct {
  14. CompanyService *service.CompanyService `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.CompanyQuery false "查询参数"
  24. // @Security ApiKeyAuth
  25. // @Success 200 {object} resp.Response{data=page.Page{list=model.Company},msg=string} "分页获取公司管理列表,返回包括列表,总数,页码,每页数量"
  26. // @Router /company/page [get]
  27. func (this CompanyApi) Page(c *frame.Context) {
  28. query := &req.CompanyQuery{}
  29. c.ValidteError(c.ShouldBind(query), query)
  30. list := make([]response.CompanyResponse, 0)
  31. i := this.CompanyService.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.CompanyQuery false "查询参数"
  42. // @Security ApiKeyAuth
  43. // @Success 200 {object} resp.Response{data=model.Company,msg=string} "分页获取公司管理列表,返回包括列表,总数,页码,每页数量"
  44. // @Router /company/list [get]
  45. func (this CompanyApi) List(c *frame.Context) {
  46. query := &req.CompanyQuery{}
  47. list := make([]response.CompanyResponse, 0)
  48. c.ValidteError(c.ShouldBind(query), query)
  49. this.CompanyService.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.Company,msg=string} "返回公司管理详情查询"
  62. // @Router /company [get]
  63. func (this CompanyApi) 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.CompanyService.Get(req.Id))
  69. }
  70. // Add 新增公司管理
  71. // @Summary 新增公司管理接口
  72. // @Description 新增公司管理接口
  73. // @Tags 公司管理相关接口
  74. // @Accept application/json
  75. // @Produce application/json
  76. // @Param Authorization header string false "Bearer 令牌"
  77. // @Param data body model.Company true "公司管理实体对象"
  78. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  79. // @Router /company/add [post]
  80. func (this CompanyApi) Add(c *frame.Context) {
  81. params, company := &req.CompanyAdd{}, &model.Company{}
  82. c.ValidteError(c.ShouldBind(params), params)
  83. utils.CopyFields(company, params)
  84. this.CompanyService.Insert(company)
  85. }
  86. // Edit 修改公司管理数据接口
  87. // @Summary 修改公司管理接口
  88. // @Description 新增公司管理接口
  89. // @Tags 公司管理相关接口
  90. // @Accept application/json
  91. // @Produce application/json
  92. // @Param Authorization header string false "Bearer 令牌"
  93. // @Param data body model.Company true "公司管理实体对象"
  94. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  95. // @Router /company/edit [put]
  96. func (this CompanyApi) Edit(c *frame.Context) {
  97. params, company := &req.CompanyEdit{}, &model.Company{}
  98. c.ValidteError(c.ShouldBind(params), params)
  99. utils.CopyFields(company, params)
  100. this.CompanyService.Edit(company, c.Cols())
  101. }
  102. // Delete 删除公司管理数据
  103. // @Summary 删除公司管理接口
  104. // @Description 删除公司管理接口
  105. // @Tags 公司管理相关接口
  106. // @Accept application/json
  107. // @Produce application/json
  108. // @Param Authorization header string false "Bearer 令牌"
  109. // @Param id path int true "id" id
  110. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  111. // @Router /company [delete]
  112. func (a CompanyApi) Delete(c *frame.Context) {
  113. var req struct {
  114. Ids []int64 `form:"ids" binding:"required" msg:"ids不存在"` //ids
  115. }
  116. c.ValidteError(c.ShouldBind(&req), &req)
  117. a.CompanyService.Delete(req.Ids)
  118. }
  119. // Export 导出excel
  120. func (this CompanyApi) Export(c *frame.Context) {
  121. query := &req.CompanyQuery{}
  122. list := make([]model.Company, 0)
  123. c.ValidteError(c.ShouldBind(query), query)
  124. this.CompanyService.List(query, list)
  125. excelList := make([]interface{}, 0)
  126. for _, company := range list {
  127. excelList = append(excelList, company)
  128. }
  129. _, files := excels.ExportExcel(excelList, "公司管理数据表")
  130. file.DownloadExcel(c, files)
  131. }