You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.6 KiB

3 years ago
3 years ago
  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  6. systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
  7. "github.com/flipped-aurora/gin-vue-admin/server/utils"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. )
  11. type SystemApi struct {
  12. }
  13. // @Tags System
  14. // @Summary 获取配置文件内容
  15. // @Security ApiKeyAuth
  16. // @Produce application/json
  17. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  18. // @Router /system/getSystemConfig [post]
  19. func (s *SystemApi) GetSystemConfig(c *gin.Context) {
  20. if err, config := systemConfigService.GetSystemConfig(); err != nil {
  21. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  22. response.FailWithMessage("获取失败", c)
  23. } else {
  24. response.OkWithDetailed(systemRes.SysConfigResponse{Config: config}, "获取成功", c)
  25. }
  26. }
  27. // @Tags System
  28. // @Summary 设置配置文件内容
  29. // @Security ApiKeyAuth
  30. // @Produce application/json
  31. // @Param data body system.System true "设置配置文件内容"
  32. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  33. // @Router /system/setSystemConfig [post]
  34. func (s *SystemApi) SetSystemConfig(c *gin.Context) {
  35. var sys system.System
  36. _ = c.ShouldBindJSON(&sys)
  37. if err := systemConfigService.SetSystemConfig(sys); err != nil {
  38. global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
  39. response.FailWithMessage("设置失败", c)
  40. } else {
  41. response.OkWithData("设置成功", c)
  42. }
  43. }
  44. // @Tags System
  45. // @Summary 重启系统
  46. // @Security ApiKeyAuth
  47. // @Produce application/json
  48. // @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
  49. // @Router /system/reloadSystem [post]
  50. func (s *SystemApi) ReloadSystem(c *gin.Context) {
  51. err := utils.Reload()
  52. if err != nil {
  53. global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
  54. response.FailWithMessage("重启系统失败", c)
  55. } else {
  56. response.OkWithMessage("重启系统成功", c)
  57. }
  58. }
  59. // @Tags System
  60. // @Summary 获取服务器信息
  61. // @Security ApiKeyAuth
  62. // @Produce application/json
  63. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  64. // @Router /system/getServerInfo [post]
  65. func (s *SystemApi) GetServerInfo(c *gin.Context) {
  66. if server, err := systemConfigService.GetServerInfo(); err != nil {
  67. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  68. response.FailWithMessage("获取失败", c)
  69. } else {
  70. response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
  71. }
  72. }