From 229601c11ea9c642f89e29d74ed319d5c4296acc Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 31 Dec 2019 10:28:52 +0800 Subject: [PATCH] +onSysConfigChanged --- business/jxstore/cms/cms.go | 58 ++++++++++++++++++++++++++++++++++-- business/model/dao/store.go | 20 +++++++++++++ business/model/new_config.go | 26 ---------------- 3 files changed, 76 insertions(+), 28 deletions(-) diff --git a/business/jxstore/cms/cms.go b/business/jxstore/cms/cms.go index 3908dba05..f473adb8f 100644 --- a/business/jxstore/cms/cms.go +++ b/business/jxstore/cms/cms.go @@ -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 } diff --git a/business/model/dao/store.go b/business/model/dao/store.go index c1b82afea..b39e85480 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -6,6 +6,7 @@ import ( "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/globals" ) // 带购物平台信息的 @@ -579,3 +580,22 @@ func GetStorePriceScoreSnapshot(db *DaoDB, snapDate time.Time) (storePriceScoreS err = GetRows(db, &storePriceScoreSnapshot, sql, sqlParams...) return storePriceScoreSnapshot, err } + +func SetStoreMapSyncStatus(db *DaoDB, vendorID int, storeIDs []int, syncStatus int) (num int64, err error) { + globals.SugarLogger.Debugf("SetStoreMapSyncStatus, storeIDs:%v, vendorID:%d", storeIDs, vendorID) + + sql := ` + UPDATE store_map t1 + SET t1.sync_status = t1.sync_status | ? + ` + sqlParams := []interface{}{ + syncStatus, + } + sql += " WHERE t1.deleted_at = ? AND t1.sync_status & ? = 0 AND t1.vendor_id = ?" + sqlParams = append(sqlParams, utils.DefaultTimeValue, model.SyncFlagDeletedMask, vendorID) + if len(storeIDs) > 0 { + sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")" + sqlParams = append(sqlParams, storeIDs) + } + return ExecuteSQL(db, sql, sqlParams...) +} diff --git a/business/model/new_config.go b/business/model/new_config.go index 70fbf353e..a3805bac0 100644 --- a/business/model/new_config.go +++ b/business/model/new_config.go @@ -1,7 +1,5 @@ package model -import "reflect" - const ( ConfigTypeSys = "Sys" ConfigTypePricePack = "PricePack" @@ -17,12 +15,6 @@ const ( ConfigSysMtwmSkuBoxFee = "MtwmSkuBoxFee" // 美团外卖单商品打包费 ) -type SysConfigLimit struct { - ValueType reflect.Kind - MinValue int64 - MaxValue int64 -} - var ( ConfigTypeName = map[string]string{ ConfigTypeSys: "系统", @@ -31,24 +23,6 @@ var ( ConfigTypeBank: "银行", ConfigTypeRole: "角色", } - - SysConfigLimitMap = map[string]*SysConfigLimit{ - ConfigSysEbaiBoxFee: &SysConfigLimit{ - ValueType: reflect.Int, - MinValue: 0, - MaxValue: 500, - }, - ConfigSysMtwmBoxFee: &SysConfigLimit{ - ValueType: reflect.Int, - MinValue: 0, - MaxValue: 500, - }, - ConfigSysMtwmSkuBoxFee: &SysConfigLimit{ - ValueType: reflect.Int, - MinValue: 0, - MaxValue: 50, - }, - } ) type NewConfig struct {