+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
}

View File

@@ -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...)
}

View File

@@ -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 {