Merge remote-tracking branch 'origin/mark' into don
This commit is contained in:
@@ -20,7 +20,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
DefActSkuStock = 200 // 缺省活动库存
|
DefActSkuStock = 200 // 缺省活动库存
|
||||||
|
|
||||||
maxDiscount4SkuSecKill = 100
|
maxDiscount4SkuSecKill = 99
|
||||||
minDiscount4SkuDirectDown = 0
|
minDiscount4SkuDirectDown = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -270,9 +270,9 @@ func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkDiscountValidation(actType int, pricePercentage int) (err error) {
|
func checkDiscountValidation(actType int, pricePercentage int) (err error) {
|
||||||
if actType == model.ActSkuDirectDown && (pricePercentage <= minDiscount4SkuDirectDown || pricePercentage >= 100) {
|
if actType == model.ActSkuDirectDown && (pricePercentage < minDiscount4SkuDirectDown || pricePercentage > 99) {
|
||||||
err = fmt.Errorf("%s活动折扣必须大于:%d, 且必须有折扣", model.ActTypeName[actType], minDiscount4SkuDirectDown)
|
err = fmt.Errorf("%s活动折扣必须大于:%d, 且必须有折扣", model.ActTypeName[actType], minDiscount4SkuDirectDown)
|
||||||
} else if actType == model.ActSkuSecKill && pricePercentage >= maxDiscount4SkuSecKill {
|
} else if actType == model.ActSkuSecKill && pricePercentage > maxDiscount4SkuSecKill {
|
||||||
err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill)
|
err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -499,7 +499,8 @@ func (v *VendorSync) PruneMissingStoreSkus(ctx *jxcontext.Context, vendorIDs []i
|
|||||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||||
if len(loopMapInfo.StoreMapList) > 1 {
|
if len(loopMapInfo.StoreMapList) > 1 {
|
||||||
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]),
|
||||||
|
tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(5), ctx,
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
storeMap := batchItemList[0].(*model.StoreMap)
|
storeMap := batchItemList[0].(*model.StoreMap)
|
||||||
_, err = PruneMissingStoreSkus(ctx, task, loopMapInfo.VendorID, storeMap.StoreID, storeMap.VendorStoreID, false, isContinueWhenError)
|
_, err = PruneMissingStoreSkus(ctx, task, loopMapInfo.VendorID, storeMap.StoreID, storeMap.VendorStoreID, false, isContinueWhenError)
|
||||||
@@ -523,7 +524,8 @@ func (v *VendorSync) AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, vendorID
|
|||||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||||
if len(loopMapInfo.StoreMapList) > 1 {
|
if len(loopMapInfo.StoreMapList) > 1 {
|
||||||
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]),
|
||||||
|
tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(5), ctx,
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
storeMap := batchItemList[0].(*model.StoreMap)
|
storeMap := batchItemList[0].(*model.StoreMap)
|
||||||
_, err = AddCreateFlagForJxStoreSku(ctx, task, loopMapInfo.VendorID, storeMap.StoreID, storeMap.VendorStoreID, false, isContinueWhenError)
|
_, err = AddCreateFlagForJxStoreSku(ctx, task, loopMapInfo.VendorID, storeMap.StoreID, storeMap.VendorStoreID, false, isContinueWhenError)
|
||||||
|
|||||||
@@ -539,6 +539,7 @@ func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, ven
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
localSkuMap = nil
|
||||||
case 1:
|
case 1:
|
||||||
if len(sku2Delete) > 0 {
|
if len(sku2Delete) > 0 {
|
||||||
_, err = putils.FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
|
_, err = putils.FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
|
||||||
@@ -570,7 +571,7 @@ func AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
var skuIDList []int
|
var storeSkuBindIDs []int
|
||||||
seqTaskFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
seqTaskFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -583,19 +584,19 @@ func AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, v := range localSkuList {
|
for _, v := range localSkuList {
|
||||||
if remoteSkuMap[v.SkuID] == nil && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) {
|
if remoteSkuMap[v.SkuID] == nil && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 {
|
||||||
skuIDList = append(skuIDList, v.SkuID)
|
storeSkuBindIDs = append(storeSkuBindIDs, v.BindID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
storeSkuBindIDs = nil
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
if len(skuIDList) > 0 {
|
if len(storeSkuBindIDs) > 0 {
|
||||||
storeSkuList, err := dao.GetStoresSkusInfo(db, []int{storeID}, skuIDList)
|
for _, bindID := range storeSkuBindIDs {
|
||||||
if err == nil {
|
fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID])
|
||||||
for _, skuBind := range storeSkuList {
|
skuBind := &model.StoreSkuBind{}
|
||||||
fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID])
|
skuBind.ID = bindID
|
||||||
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask)
|
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,6 @@ func (m *SyncMapWithTimeout) Delete(key interface{}) {
|
|||||||
if value, ok := m.timers.Load(key); ok {
|
if value, ok := m.timers.Load(key); ok {
|
||||||
timer := value.(*time.Timer)
|
timer := value.(*time.Timer)
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
|
m.timers.Delete(key)
|
||||||
}
|
}
|
||||||
m.timers.Delete(key)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ func (task *ParallelTask) Run() {
|
|||||||
|
|
||||||
close(task.subFinishChan)
|
close(task.subFinishChan)
|
||||||
task.jobList = nil // 如果不释放,任务被管理的话,会导致内存不能释放
|
task.jobList = nil // 如果不释放,任务被管理的话,会导致内存不能释放
|
||||||
|
task.worker = nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ func (task *SeqTask) Run() {
|
|||||||
task.Result = taskResult
|
task.Result = taskResult
|
||||||
task.mainErr = taskErr
|
task.mainErr = taskErr
|
||||||
task.locker.Unlock()
|
task.locker.Unlock()
|
||||||
|
|
||||||
|
task.worker = nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ func (t *BaseTask) GetID() string {
|
|||||||
return t.ID
|
return t.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 此函数成功返回结果后,结果在任务中会被删除(以免被管理的任务不必要的HOLD住对象)
|
||||||
func (t *BaseTask) GetResult(duration time.Duration) (retVal []interface{}, err error) {
|
func (t *BaseTask) GetResult(duration time.Duration) (retVal []interface{}, err error) {
|
||||||
if t.GetStatus() >= TaskStatusEndBegin {
|
if t.GetStatus() >= TaskStatusEndBegin {
|
||||||
return t.getResult(), t.GetErr()
|
return t.getResult(), t.GetErr()
|
||||||
@@ -279,10 +280,12 @@ func (t *BaseTask) GetNoticeMsg() string {
|
|||||||
return t.NoticeMsg
|
return t.NoticeMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BaseTask) getResult() []interface{} {
|
func (t *BaseTask) getResult() (result []interface{}) {
|
||||||
t.locker.RLock()
|
t.locker.Lock()
|
||||||
defer t.locker.RUnlock()
|
defer t.locker.Unlock()
|
||||||
return t.Result
|
result = t.Result
|
||||||
|
t.Result = nil
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BaseTask) AddBatchErr(err error) {
|
func (t *BaseTask) AddBatchErr(err error) {
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ func GetVendorType(vendorID int) (vendorType int) {
|
|||||||
|
|
||||||
type AppKeyConfig struct {
|
type AppKeyConfig struct {
|
||||||
ModelIDCULD
|
ModelIDCULD
|
||||||
VendorID int `json:"vendorID"`
|
VendorID int `json:"vendorID"`
|
||||||
OrgCode string `orm:"size(32)" json:"orgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||||
|
|
||||||
Name string `orm:"size(32)" json:"name"`
|
Name string `orm:"size(32)" json:"name"`
|
||||||
Value1 string `orm:"size(1024)" json:"value1"`
|
Value1 string `orm:"size(1024)" json:"value1"`
|
||||||
@@ -194,6 +194,6 @@ type AppKeyConfig struct {
|
|||||||
|
|
||||||
func (a *AppKeyConfig) TableUnique() [][]string {
|
func (a *AppKeyConfig) TableUnique() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
[]string{"VendorID", "OrgCode", "DeletedAt"},
|
[]string{"VendorID", "VendorOrgCode", "DeletedAt"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,23 @@ func (*SkuCategory) TableIndex() [][]string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SkuCategoryMap struct {
|
||||||
|
ModelIDCULD
|
||||||
|
|
||||||
|
CatID int `orm:"column(cat_id)" json:"catID"`
|
||||||
|
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||||
|
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||||
|
|
||||||
|
VendorCatID string `orm:"size(32);column(vendor_cat_id)" json:"vendorCatID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SkuCategoryMap) TableUnique() [][]string {
|
||||||
|
return [][]string{
|
||||||
|
[]string{"CatID", "VendorID", "VendorOrgCode", "DeletedAt"},
|
||||||
|
[]string{"VendorCatID", "VendorID", "VendorOrgCode", "DeletedAt"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type SkuName struct {
|
type SkuName struct {
|
||||||
ModelIDCULD
|
ModelIDCULD
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
|
||||||
@@ -69,6 +71,8 @@ func (c *TaskController) UnmanageTasks() {
|
|||||||
var taskIDs []string
|
var taskIDs []string
|
||||||
if err = jxutils.Strings2Objs(params.TaskIDs, &taskIDs); err == nil {
|
if err = jxutils.Strings2Objs(params.TaskIDs, &taskIDs); err == nil {
|
||||||
tasksch.UnmanageTasks(taskIDs)
|
tasksch.UnmanageTasks(taskIDs)
|
||||||
|
runtime.GC()
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
}
|
}
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user