+onSysConfigChanged

This commit is contained in:
gazebo
2019-12-31 10:28:52 +08:00
parent 174727bafc
commit 229601c11e
3 changed files with 76 additions and 28 deletions

View File

@@ -32,6 +32,13 @@ const (
SendMsgTypeSuggestRequest = "suggestRequest"
)
type SysConfigLimit struct {
ValueType reflect.Kind
MinValue int64
MaxValue int64
AfterChanged func() error
}
var (
serviceInfo map[string]interface{}
allowUpdatePlaceFieldsMap = map[string]bool{
@@ -55,6 +62,36 @@ var (
needConfirmRequestMap = map[string]int{
SendMsgTypeOpenStoreRequest: 1,
}
SysConfigLimitMap = map[string]*SysConfigLimit{
model.ConfigSysEbaiBoxFee: &SysConfigLimit{
ValueType: reflect.Int,
MinValue: 0,
MaxValue: 500,
AfterChanged: func() (err error) {
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), model.VendorIDEBAI, nil, model.SyncFlagModifiedMask)
return err
},
},
model.ConfigSysMtwmBoxFee: &SysConfigLimit{
ValueType: reflect.Int,
MinValue: 0,
MaxValue: 500,
AfterChanged: func() (err error) {
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), model.VendorIDMTWM, nil, model.SyncFlagModifiedMask)
return err
},
},
model.ConfigSysMtwmSkuBoxFee: &SysConfigLimit{
ValueType: reflect.Int,
MinValue: 0,
MaxValue: 50,
AfterChanged: func() (err error) {
_, err = dao.SetStoreSkuSyncStatus(dao.GetDB(), model.VendorIDMTWM, nil, nil, model.SyncFlagModifiedMask)
return err
},
},
}
)
func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
@@ -195,7 +232,7 @@ func SendMsg2Somebody(ctx *jxcontext.Context, mobileNum, verifyCode, msgType, ms
}
func checkSysConfig(key, value string) (err error) {
if limit := model.SysConfigLimitMap[key]; limit != nil {
if limit := SysConfigLimitMap[key]; limit != nil {
if limit.ValueType == reflect.Int {
int64Value, err2 := strconv.ParseInt(value, 10, 64)
if err = err2; err == nil {
@@ -208,6 +245,13 @@ func checkSysConfig(key, value string) (err error) {
return err
}
func onSysConfigChanged(key, value string) (err error) {
if limit := SysConfigLimitMap[key]; limit != nil && limit.AfterChanged != nil {
err = limit.AfterChanged()
}
return err
}
func checkConfig(opFlag int, configType, key, value string) (err error) {
switch configType {
case model.ConfigTypePricePack:
@@ -266,7 +310,11 @@ func AddConfig(ctx *jxcontext.Context, key, configType, value string) (err error
Value: value,
}
dao.WrapAddIDCULDEntity(conf, ctx.GetUserName())
return dao.CreateEntity(db, conf)
err = dao.CreateEntity(db, conf)
if configType == model.ConfigTypeSys && err == nil {
err = onSysConfigChanged(key, value)
}
return err
}
func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
@@ -331,6 +379,9 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
"Type": configType,
})
}
if configType == model.ConfigTypeSys && err == nil {
err = onSysConfigChanged(key, "")
}
return err
}
@@ -410,6 +461,9 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
default:
dao.Commit(db)
}
if configType == model.ConfigTypeSys && err == nil {
err = onSysConfigChanged(key, value)
}
return hint, err
}