diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index bb9cd29f8..2f12b8483 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -20,7 +20,7 @@ import ( const ( DefActSkuStock = 200 // 缺省活动库存 - maxDiscount4SkuSecKill = 100 + maxDiscount4SkuSecKill = 99 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) { - 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) - } else if actType == model.ActSkuSecKill && pricePercentage >= maxDiscount4SkuSecKill { + } else if actType == model.ActSkuSecKill && pricePercentage > maxDiscount4SkuSecKill { err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill) } return err diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index d0e0a79b6..bfbc71efb 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -499,7 +499,8 @@ func (v *VendorSync) PruneMissingStoreSkus(ctx *jxcontext.Context, vendorIDs []i func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) 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) { storeMap := batchItemList[0].(*model.StoreMap) _, 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) { loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) 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) { storeMap := batchItemList[0].(*model.StoreMap) _, err = AddCreateFlagForJxStoreSku(ctx, task, loopMapInfo.VendorID, storeMap.StoreID, storeMap.VendorStoreID, false, isContinueWhenError) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 72ba52d50..ee5bd62d3 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -539,6 +539,7 @@ func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, ven } } } + localSkuMap = nil case 1: if len(sku2Delete) > 0 { _, 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 } - var skuIDList []int + var storeSkuBindIDs []int seqTaskFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { case 0: @@ -583,19 +584,19 @@ func AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask } } for _, v := range localSkuList { - if remoteSkuMap[v.SkuID] == nil && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) { - skuIDList = append(skuIDList, v.SkuID) + if remoteSkuMap[v.SkuID] == nil && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 { + storeSkuBindIDs = append(storeSkuBindIDs, v.BindID) } } + storeSkuBindIDs = nil } case 1: - if len(skuIDList) > 0 { - storeSkuList, err := dao.GetStoresSkusInfo(db, []int{storeID}, skuIDList) - if err == nil { - for _, skuBind := range storeSkuList { - fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID]) - dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask) - } + if len(storeSkuBindIDs) > 0 { + for _, bindID := range storeSkuBindIDs { + fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID]) + skuBind := &model.StoreSkuBind{} + skuBind.ID = bindID + dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask) } } } diff --git a/business/jxutils/jxutils_sync_map.go b/business/jxutils/jxutils_sync_map.go index 92827aea6..99c2beeab 100644 --- a/business/jxutils/jxutils_sync_map.go +++ b/business/jxutils/jxutils_sync_map.go @@ -24,6 +24,6 @@ func (m *SyncMapWithTimeout) Delete(key interface{}) { if value, ok := m.timers.Load(key); ok { timer := value.(*time.Timer) timer.Stop() + m.timers.Delete(key) } - m.timers.Delete(key) } diff --git a/business/jxutils/tasksch/parallel_task.go b/business/jxutils/tasksch/parallel_task.go index de62f3cf8..d402e8a2c 100644 --- a/business/jxutils/tasksch/parallel_task.go +++ b/business/jxutils/tasksch/parallel_task.go @@ -179,6 +179,7 @@ func (task *ParallelTask) Run() { close(task.subFinishChan) task.jobList = nil // 如果不释放,任务被管理的话,会导致内存不能释放 + task.worker = nil }) } diff --git a/business/jxutils/tasksch/sequence_task.go b/business/jxutils/tasksch/sequence_task.go index c443c85e6..7bcd3faac 100644 --- a/business/jxutils/tasksch/sequence_task.go +++ b/business/jxutils/tasksch/sequence_task.go @@ -59,6 +59,8 @@ func (task *SeqTask) Run() { task.Result = taskResult task.mainErr = taskErr task.locker.Unlock() + + task.worker = nil }) } diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index 533c84e7c..f968eab6d 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -169,6 +169,7 @@ func (t *BaseTask) GetID() string { return t.ID } +// 此函数成功返回结果后,结果在任务中会被删除(以免被管理的任务不必要的HOLD住对象) func (t *BaseTask) GetResult(duration time.Duration) (retVal []interface{}, err error) { if t.GetStatus() >= TaskStatusEndBegin { return t.getResult(), t.GetErr() @@ -279,10 +280,12 @@ func (t *BaseTask) GetNoticeMsg() string { return t.NoticeMsg } -func (t *BaseTask) getResult() []interface{} { - t.locker.RLock() - defer t.locker.RUnlock() - return t.Result +func (t *BaseTask) getResult() (result []interface{}) { + t.locker.Lock() + defer t.locker.Unlock() + result = t.Result + t.Result = nil + return result } func (t *BaseTask) AddBatchErr(err error) { diff --git a/business/model/api_config.go b/business/model/api_config.go index 6b4561217..5ef647a6b 100644 --- a/business/model/api_config.go +++ b/business/model/api_config.go @@ -181,8 +181,8 @@ func GetVendorType(vendorID int) (vendorType int) { type AppKeyConfig struct { ModelIDCULD - VendorID int `json:"vendorID"` - OrgCode string `orm:"size(32)" json:"orgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空 + VendorID int `json:"vendorID"` + VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空 Name string `orm:"size(32)" json:"name"` Value1 string `orm:"size(1024)" json:"value1"` @@ -194,6 +194,6 @@ type AppKeyConfig struct { func (a *AppKeyConfig) TableUnique() [][]string { return [][]string{ - []string{"VendorID", "OrgCode", "DeletedAt"}, + []string{"VendorID", "VendorOrgCode", "DeletedAt"}, } } diff --git a/business/model/sku.go b/business/model/sku.go index 12f52a783..e5ead117d 100644 --- a/business/model/sku.go +++ b/business/model/sku.go @@ -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 { ModelIDCULD diff --git a/controllers/cms_task.go b/controllers/cms_task.go index 1023178f0..5c2a1561e 100644 --- a/controllers/cms_task.go +++ b/controllers/cms_task.go @@ -2,6 +2,8 @@ package controllers import ( "fmt" + "runtime" + "time" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -69,6 +71,8 @@ func (c *TaskController) UnmanageTasks() { var taskIDs []string if err = jxutils.Strings2Objs(params.TaskIDs, &taskIDs); err == nil { tasksch.UnmanageTasks(taskIDs) + runtime.GC() + time.Sleep(3 * time.Second) } return retVal, "", err })