liujiandao
2023-12-22 28d04b70a786c5084ddceb12f6cc34b5702e0d36
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
package v1
 
import (
    "aps_crm/constvar"
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/contextx"
    "aps_crm/pkg/ecode"
    "aps_crm/service"
    "github.com/gin-gonic/gin"
    "gorm.io/gorm"
)
 
type SystemSetApi struct{}
 
// GetSystemSet
//
//    @Tags        系统设置
//    @Summary    获取系统设置
//    @Produce    application/json
//    @Success    200        {object}    contextx.Response{data=map[string]interface{}}    "成功"
//    @Router        /api/system/getSystemSet [get]
func (slf SystemSetApi) GetSystemSet(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    systemSet, err := service.GetSystemSet()
    if err != nil {
        ctx.FailWithMsg(ecode.UnknownErr, "查询失败")
        return
    }
    constvar.SystemSet["CRM"] = systemSet
    ctx.OkWithDetailed(constvar.SystemSet)
}
 
// SaveSystemSet
//
//    @Tags        系统设置
//    @Summary    保存系统设置
//    @Produce    application/json
//    @Param        object    body        request.SaveSystemSet    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}    "成功"
//    @Router        /api/system/saveSystemSet [post]
func (slf SystemSetApi) SaveSystemSet(c *gin.Context) {
    var params request.SaveSystemSet
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    err := model.WithTransaction(func(db *gorm.DB) error {
        err := model.NewSystemSetSearch().SetOrm(db).SetTypes(params.SystemTypes).DeleteAll()
        if err != nil {
            return err
        }
        err = model.NewSystemSetSearch().SetOrm(db).CreateBatch(params.Sets)
        return err
    })
    if err != nil {
        ctx.FailWithMsg(ecode.UnknownErr, "保存失败")
        return
    }
    ctx.Ok()
}