Merge remote-tracking branch 'origin/mark' into don

This commit is contained in:
Rosy-zhudan
2019-08-29 14:49:09 +08:00
10 changed files with 53 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -179,6 +179,7 @@ func (task *ParallelTask) Run() {
close(task.subFinishChan)
task.jobList = nil // 如果不释放,任务被管理的话,会导致内存不能释放
task.worker = nil
})
}

View File

@@ -59,6 +59,8 @@ func (task *SeqTask) Run() {
task.Result = taskResult
task.mainErr = taskErr
task.locker.Unlock()
task.worker = nil
})
}

View File

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

View File

@@ -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"},
}
}

View File

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

View File

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