run_api.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/service"
  7. "ulink-admin/pkg/excels"
  8. "ulink-admin/pkg/file"
  9. "ulink-admin/pkg/page"
  10. )
  11. type RunApi struct {
  12. RunService *service.RunService `inject:""`
  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.RunQuery false "查询参数"
  22. // @Security ApiKeyAuth
  23. // @Success 200 {object} resp.Response{data=page.Page{list=model.Run},msg=string} "分页获取营运记录列表,返回包括列表,总数,页码,每页数量"
  24. // @Router /run/page [get]
  25. func (this RunApi) Page(c *frame.Context) {
  26. query := &req.RunQuery{}
  27. c.ValidteError(c.ShouldBind(query), query)
  28. find, i := this.RunService.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.RunQuery false "查询参数"
  39. // @Security ApiKeyAuth
  40. // @Success 200 {object} resp.Response{data=model.Run,msg=string} "分页获取营运记录列表,返回包括列表,总数,页码,每页数量"
  41. // @Router /run/list [get]
  42. func (this RunApi) List(c *frame.Context) {
  43. query := &req.RunQuery{}
  44. list := make([]model.Run, 0)
  45. c.ValidteError(c.ShouldBind(query), query)
  46. this.RunService.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.Run,msg=string} "返回营运记录详情查询"
  59. // @Router /run [get]
  60. func (this RunApi) 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.RunService.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.Run true "营运记录实体对象"
  75. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  76. // @Router /run/add [post]
  77. func (this RunApi) Add(c *frame.Context) {
  78. run := &model.Run{}
  79. c.ValidteError(c.ShouldBind(run), run)
  80. this.RunService.Insert(run)
  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.Run true "营运记录实体对象"
  90. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  91. // @Router /run/edit [put]
  92. func (this RunApi) Edit(c *frame.Context) {
  93. run := &model.Run{}
  94. c.ValidteError(c.ShouldBind(run), run)
  95. this.RunService.Edit(run, 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 /run [delete]
  107. func (a RunApi) 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.RunService.Delete(req.Ids)
  113. }
  114. // Export 导出excel
  115. func (this RunApi) Export(c *frame.Context) {
  116. query := &req.RunQuery{}
  117. list := make([]model.Run, 0)
  118. c.ValidteError(c.ShouldBind(query), query)
  119. this.RunService.List(query, list)
  120. excelList := make([]interface{}, 0)
  121. for _, run := range list {
  122. excelList = append(excelList, run)
  123. }
  124. _, files := excels.ExportExcel(excelList, "营运记录数据表")
  125. file.DownloadExcel(c, files)
  126. }