重构代码

This commit is contained in:
Rosy-zhudan
2019-08-08 12:03:25 +08:00
parent df40806734
commit 94f9a07519

View File

@@ -19,44 +19,42 @@ const (
specialSkuNameKeyWord = "温馨提示" specialSkuNameKeyWord = "温馨提示"
startOpStoreStockNumber = 0 startOpStoreStockNumber = 0
endOpStoreStockNumber = model.MaxStoreSkuStockQty endOpStoreStockNumber = model.MaxStoreSkuStockQty
startOpStoreTimeDefaultMTWM = int16(2200)
endOpStoreTimeDefaultMTWM = int16(2355)
startOpStoreTimeDefaultEBAI = int16(5)
endOpStoreTimeDefaultEBAI = int16(2355)
) )
var ( var (
//only for MTWM
startOpStoreTimeListJXGY_MTWM = []string{
"22:00:00",
}
endOpStoreTimeListJXGY_MTWM = []string{
"00:00:00",
}
startOpStoreTimeListJXCS_MTWM = []string {
"22:10:00",
}
endOpStoreTimeListJXCS_MTWM = []string{
"00:10:00",
}
//for other vendor
startOpStoreTimeListJXGY = []string{
"22:20:00",
}
endOpStoreTimeListJXGY = []string{
"06:00:00",
}
startOpStoreTimeListJXCS = []string{
"22:30:00",
}
endOpStoreTimeListJXCS = []string{
"06:10:00",
}
vendorList = map[int]bool { vendorList = map[int]bool {
model.VendorIDMTWM: true, model.VendorIDMTWM: true,
model.VendorIDEBAI: true, model.VendorIDEBAI: true,
} }
vendorStoreRefreshTimeList = map[int][]string {
model.VendorIDMTWM: []string {
//start and end time for JXGY
"22:00:00",
"00:00:00",
//start and end time for JXCS
"22:10:00",
"00:10:00",
},
model.VendorIDEBAI: []string {
"22:20:00",
"06:00:00",
"22:30:00",
"06:10:00",
},
}
vendorStartEndStoreTime = map[int][]int16 {
model.VendorIDMTWM: []int16 {
int16(2200),//start time
int16(2355),//end time
},
model.VendorIDEBAI: []int16 {
int16(5),
int16(2355),
},
}
) )
func AddOrDelExtraStoreOptime(vendorID, storeID int, vendorStoreID string, storeInfo *model.Store, startOpStoreTime, endOpStoreTime int16, needAddTime bool) bool { func AddOrDelExtraStoreOptime(vendorID, storeID int, vendorStoreID string, storeInfo *model.Store, startOpStoreTime, endOpStoreTime int16, needAddTime bool) bool {
@@ -78,13 +76,9 @@ func GetStockValue(isStart bool) int {
} }
func GetOpStoreTime(vendorID int) (startTime, endTime int16) { func GetOpStoreTime(vendorID int) (startTime, endTime int16) {
if vendorID == model.VendorIDMTWM { startTime = vendorStartEndStoreTime[vendorID][0]
return startOpStoreTimeDefaultMTWM, endOpStoreTimeDefaultMTWM endTime = vendorStartEndStoreTime[vendorID][1]
} else if vendorID == model.VendorIDEBAI { return startTime, endTime
return startOpStoreTimeDefaultEBAI, endOpStoreTimeDefaultEBAI
}
return 0, 0
} }
func IsSpecialSku(name string) bool { func IsSpecialSku(name string) bool {
@@ -212,25 +206,21 @@ func StartOrEndOpStore(isStart bool, vendorIDList []int, storeIDList []int, star
return retVal, err return retVal, err
} }
func StartDaemon(vendorID int) { func GetVendorStoreRefreshTime(vendorID int) (startTimeList, stopTimeList []string) {
startTimeList := []string{} isJXCS := globals.IsMainProductEnv()
stopTimeList := []string{} refreshTimeList := vendorStoreRefreshTimeList[vendorID]
if vendorID == model.VendorIDMTWM { if isJXCS {
startTimeList = startOpStoreTimeListJXCS_MTWM startTimeList = []string{refreshTimeList[2]}
stopTimeList = endOpStoreTimeListJXCS_MTWM stopTimeList = []string{refreshTimeList[3]}
if !globals.IsMainProductEnv() {
startTimeList = startOpStoreTimeListJXGY_MTWM
stopTimeList = endOpStoreTimeListJXGY_MTWM
}
} else { } else {
startTimeList = startOpStoreTimeListJXCS startTimeList = []string{refreshTimeList[0]}
stopTimeList = endOpStoreTimeListJXCS stopTimeList = []string{refreshTimeList[1]}
if !globals.IsMainProductEnv() {
startTimeList = startOpStoreTimeListJXGY
stopTimeList = endOpStoreTimeListJXGY
}
} }
return startTimeList, stopTimeList
}
func RefreshStore(vendorID int) {
startTimeList, stopTimeList := GetVendorStoreRefreshTime(vendorID)
vendorIDList := []int{vendorID} vendorIDList := []int{vendorID}
storeIDList := []int{} storeIDList := []int{}
ScheduleTimerFunc("StartOpStore", func() { ScheduleTimerFunc("StartOpStore", func() {
@@ -248,7 +238,7 @@ func StartDaemon(vendorID int) {
func InitEx() { func InitEx() {
for index, value := range vendorList { for index, value := range vendorList {
if value { if value {
StartDaemon(index) RefreshStore(index)
} }
} }
} }