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.

78 lines
2.6 KiB

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