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, ¶ms) 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() }