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