zhangqian
2024-07-31 155f70979af20ca520a55b89c6ec8cd46c43f8a5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package controllers
 
import (
    "github.com/gin-gonic/gin"
    "wms/extend/code"
    "wms/extend/util"
    "wms/models"
    "wms/pkg/logx"
    "wms/pkg/structx"
    "wms/request"
    "wms/service"
    "wms/task"
)
 
type SystemConfigController struct{}
 
// SaveConfig
// @Tags      系统设置
// @Summary   保存系统设置
// @Produce   application/json
// @Param     object  body  request.SystemConfig true  "系统设置信息"'
// @Param     Authorization    header string true "token"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/systemConfig/save [post]
func (slf SystemConfigController) SaveConfig(c *gin.Context) {
    var reqParams request.SystemConfig
    var params models.SystemConfig
    if err := c.BindJSON(&reqParams); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if err := structx.AssignTo(reqParams, &params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "数据转换错误")
        return
    }
 
    srv := service.NewSystemConfigService()
 
    if err := srv.ParamsCheck(params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, err.Error())
        return
    }
 
    if params.Id == 0 {
        if err := models.NewSystemConfigSearch().Create(&params); err != nil {
            logx.Errorf("SystemConfig create err: %v", err)
            util.ResponseFormat(c, code.SaveFail, "插入失败")
            return
        }
    } else {
        if err := models.NewSystemConfigSearch().SetID(params.ID).Update(&params); err != nil {
            logx.Errorf("SystemConfig update err: %v", err)
            util.ResponseFormat(c, code.SaveFail, "插入失败")
            return
        }
    }
 
    if err := task.RestartDynamicTask(); err != nil {
        util.ResponseFormat(c, code.SaveFail, "重启定时任务失败")
        return
    }
 
    util.ResponseFormat(c, code.Success, "保存成功")
}
 
// GetSystemConfig
// @Tags      系统设置
// @Summary   根据设置类型查询系统设置
// @Produce   application/json
// @Param     object  query    request.GetSystemConfig true  "查询参数"
// @Param     Authorization    header string true "token"
// @Success   200   {object}  util.Response{data=models.SystemConfig}  "成功"
// @Router    /api-wms/v1/systemConfig/get [get]
func (slf SystemConfigController) GetSystemConfig(c *gin.Context) {
    var params request.GetSystemConfig
    if err := c.ShouldBindQuery(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, err.Error())
        return
    }
 
    if params.ConfigType == 0 {
        util.ResponseFormat(c, code.RequestParamError, "配置类型缺失")
        return
    }
 
    config, _ := models.NewSystemConfigSearch().SetConfigType(params.ConfigType).First()
 
    util.ResponseFormat(c, code.Success, config)
}