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, ¶ms); 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(¶ms); err != nil { logx.Errorf("SystemConfig create err: %v", err) util.ResponseFormat(c, code.SaveFail, "插入失败") return } } else { if err := models.NewSystemConfigSearch().SetID(params.ID).Update(¶ms); 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(¶ms); 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) }