sys_system.go 2.4 KB
Newer Older
1
package system
Mr.奇淼('s avatar
Mr.奇淼( 已提交
2 3

import (
4
	"gin-vue-admin/global"
5
	"gin-vue-admin/model/common/response"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
6
	"gin-vue-admin/model/system"
7
	systemRes "gin-vue-admin/model/system/response"
8
	"gin-vue-admin/utils"
9

Mr.奇淼('s avatar
Mr.奇淼( 已提交
10
	"github.com/gin-gonic/gin"
11
	"go.uber.org/zap"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
12 13
)

14 15 16
type SystemApi struct {
}

17
// @Tags System
Mr.奇淼('s avatar
Mr.奇淼( 已提交
18 19 20
// @Summary 获取配置文件内容
// @Security ApiKeyAuth
// @Produce  application/json
21
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
22
// @Router /system/getSystemConfig [post]
23 24
func (s *SystemApi) GetSystemConfig(c *gin.Context) {
	if err, config := systemConfigService.GetSystemConfig(); err != nil {
25 26
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
27
	} else {
28
		response.OkWithDetailed(systemRes.SysConfigResponse{Config: config}, "获取成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
29 30 31
	}
}

32
// @Tags System
Mr.奇淼('s avatar
Mr.奇淼( 已提交
33 34 35
// @Summary 设置配置文件内容
// @Security ApiKeyAuth
// @Produce  application/json
36
// @Param data body model.System true "设置配置文件内容"
37
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
38
// @Router /system/setSystemConfig [post]
39
func (s *SystemApi) SetSystemConfig(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
40
	var sys system.System
41
	_ = c.ShouldBindJSON(&sys)
42
	if err := systemConfigService.SetSystemConfig(sys); err != nil {
43 44
		global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
		response.FailWithMessage("设置失败", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
45
	} else {
46
		response.OkWithData("设置成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
47 48
	}
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
49

50 51
// @Tags System
// @Summary 重启系统
Mr.奇淼('s avatar
Mr.奇淼( 已提交
52 53
// @Security ApiKeyAuth
// @Produce  application/json
S
songzhibin97 已提交
54 55
// @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
// @Router /system/reloadSystem [post]
56
func (s *SystemApi) ReloadSystem(c *gin.Context) {
57
	err := utils.Reload()
58
	if err != nil {
59 60
		global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
		response.FailWithMessage("重启系统失败", c)
何秀钢 已提交
61 62
	} else {
		response.OkWithMessage("重启系统成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
63 64
	}
}
65

66
// @Tags System
67 68 69 70 71
// @Summary 获取服务器信息
// @Security ApiKeyAuth
// @Produce  application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getServerInfo [post]
72 73
func (s *SystemApi) GetServerInfo(c *gin.Context) {
	if server, err := systemConfigService.GetServerInfo(); err != nil {
74 75
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
76
	} else {
77
		response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
78
	}
79
}