sys_info_api.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package admin
  2. import (
  3. "github.com/druidcaesa/gotool"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "ulink-admin/frame"
  8. "ulink-admin/modules/system/models/model"
  9. "ulink-admin/modules/system/models/req"
  10. "ulink-admin/modules/system/service"
  11. "ulink-admin/pkg/jwt/admin"
  12. "ulink-admin/pkg/page"
  13. )
  14. type SysInfoApi struct {
  15. SysInfoService *service.SysInfoService `inject:""`
  16. }
  17. // List 查询系统设置分页数据
  18. // @Summary 分页查询系统设置数据接口
  19. // @Description 分页查询系统设置数据接口
  20. // @Tags 系统设置相关接口
  21. // @Accept application/json
  22. // @Produce application/json
  23. // @Param Authorization header string false "Bearer 令牌"
  24. // @Param object query req.SysInfoQuery false "查询参数"
  25. // @Security ApiKeyAuth
  26. // @Success 200 {object} resp.Response{data=page.Page{list=model.SysInfo},msg=string} "分页获取系统设置列表,返回包括列表,总数,页码,每页数量"
  27. // @Router /sysinfo/list [get]
  28. func (a SysInfoApi) List(c *frame.Context) {
  29. query := &req.SysInfoQuery{}
  30. c.ValidteError(c.ShouldBind(query), query)
  31. list, i := a.SysInfoService.FindList(query)
  32. c.Ok(page.Page{
  33. List: list,
  34. Total: i,
  35. Size: query.PageSize,
  36. })
  37. }
  38. // List 查询系统设置所有数据
  39. // @Summary 查询全部数据系统设置数据接口
  40. // @Description 查询全部数据系统设置数据接口
  41. // @Tags 系统设置相关接口
  42. // @Accept application/json
  43. // @Produce application/json
  44. // @Param Authorization header string false "Bearer 令牌"
  45. // @Security ApiKeyAuth
  46. // @Success 200 {object} resp.Response{data=model.SysInfo,msg=string} "分页获取系统设置列表,返回包括列表,总数,页码,每页数量"
  47. // @Router /sysinfo/listAll [get]
  48. func (a SysInfoApi) ListAll(c *frame.Context) {
  49. list := a.SysInfoService.FindAll()
  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. // @Security ApiKeyAuth
  60. // @Success 200 {object} resp.Response{data=model.SysInfo,msg=string} "返回系统设置详情查询"
  61. // @Router /sysinfo [get]
  62. func (a SysInfoApi) Get(c *frame.Context) {
  63. list := a.SysInfoService.FindAll()
  64. if len(list) > 0 {
  65. c.Ok(list[0])
  66. } else {
  67. c.Error("没有查询到任何系统配置规则")
  68. }
  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.SysInfo true "系统设置实体对象"
  78. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  79. // @Router /sysinfo/add [post]
  80. func (a SysInfoApi) Add(c *frame.Context) {
  81. sysInfo := &model.SysInfo{}
  82. c.ValidteError(c.ShouldBind(sysInfo), sysInfo)
  83. sysInfo.CreateBy = admin.GetUserInfo(c).UserName
  84. sysInfo.CreateTime = time.Now()
  85. sysInfo.UpdateBy = admin.GetUserInfo(c).UserName
  86. sysInfo.UpdateTime = time.Now()
  87. a.SysInfoService.Insert(sysInfo)
  88. }
  89. // Edit 修改系统设置数据接口
  90. // @Summary 修改系统设置接口
  91. // @Description 新增系统设置接口
  92. // @Tags 系统设置相关接口
  93. // @Accept application/json
  94. // @Produce application/json
  95. // @Param Authorization header string false "Bearer 令牌"
  96. // @Param data body model.SysInfo true "系统设置实体对象"
  97. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  98. // @Router /sysinfo/edit [put]
  99. func (a SysInfoApi) Edit(c *frame.Context) {
  100. sysInfo := &model.SysInfo{}
  101. c.ValidteError(c.ShouldBind(sysInfo), sysInfo)
  102. sysInfo.UpdateBy = admin.GetUserInfo(c).UserName
  103. sysInfo.UpdateTime = time.Now()
  104. a.SysInfoService.Update(sysInfo)
  105. }
  106. // Delete 删除系统设置数据
  107. // @Summary 删除系统设置接口
  108. // @Description 删除系统设置接口
  109. // @Tags 系统设置相关接口
  110. // @Accept application/json
  111. // @Produce application/json
  112. // @Param Authorization header string false "Bearer 令牌"
  113. // @Param id path int true "id" id
  114. // @Success 200 {object} resp.Response{msg=string} "操作状态"
  115. // @Router /sysinfo [delete]
  116. func (a SysInfoApi) Delete(c *frame.Context) {
  117. //获取sysInfoId
  118. param := c.Param("id")
  119. list := make([]int64, 0)
  120. if gotool.StrUtils.HasNotEmpty(param) {
  121. strs := strings.Split(param, ",")
  122. for _, str := range strs {
  123. id, _ := strconv.ParseInt(str, 10, 64)
  124. list = append(list, id)
  125. }
  126. }
  127. //判断是否可以删除
  128. a.SysInfoService.Delete(list)
  129. }