SyncStores
This commit is contained in:
@@ -69,7 +69,7 @@ var (
|
||||
MinValue: 0,
|
||||
MaxValue: 500,
|
||||
AfterChanged: func() (err error) {
|
||||
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), model.VendorIDEBAI, nil, model.SyncFlagModifiedMask)
|
||||
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), []int{model.VendorIDEBAI}, nil, model.SyncFlagModifiedMask)
|
||||
return err
|
||||
},
|
||||
},
|
||||
@@ -78,7 +78,7 @@ var (
|
||||
MinValue: 0,
|
||||
MaxValue: 500,
|
||||
AfterChanged: func() (err error) {
|
||||
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), model.VendorIDMTWM, nil, model.SyncFlagModifiedMask)
|
||||
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), []int{model.VendorIDMTWM}, nil, model.SyncFlagModifiedMask)
|
||||
return err
|
||||
},
|
||||
},
|
||||
|
||||
@@ -185,15 +185,10 @@ func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB
|
||||
// return "", err
|
||||
// }
|
||||
|
||||
func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SyncStore, storeID:%d", storeID)
|
||||
var vendorIDs []int
|
||||
if vendorID != -1 {
|
||||
vendorIDs = []int{
|
||||
vendorID,
|
||||
}
|
||||
}
|
||||
hint, err = v.LoopStoresMap(ctx, db, fmt.Sprintf("同步门店信息:%d", storeID), isAsync, false, vendorIDs, []int{storeID}, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) {
|
||||
func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs, storeIDs []int, mustDirty, isAsync bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SyncStore2, storeIDs:%d", storeIDs)
|
||||
userName := ctx.GetUserName()
|
||||
_, hint, err = v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店信息:%v", storeIDs), isAsync, false, vendorIDs, storeIDs, mustDirty, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) {
|
||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||
handler := v.GetStoreHandler(loopMapInfo.VendorID)
|
||||
if handler != nil {
|
||||
@@ -232,6 +227,16 @@ func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID,
|
||||
return hint, makeSyncError(err)
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) {
|
||||
var vendorIDs []int
|
||||
if vendorID != -1 {
|
||||
vendorIDs = []int{
|
||||
vendorID,
|
||||
}
|
||||
}
|
||||
return v.SyncStore2(ctx, db, vendorIDs, []int{storeID}, false, isAsync)
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuID int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) {
|
||||
var (
|
||||
nameIDs []int
|
||||
@@ -384,7 +389,7 @@ func (v *VendorSync) SyncStoresCategory(ctx *jxcontext.Context, db *dao.DaoDB, v
|
||||
func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debug("SyncStoresSkus2")
|
||||
isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8
|
||||
task, hint, err := v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店商品信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs,
|
||||
task, hint, err := v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店商品信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs, false,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
|
||||
@@ -561,9 +566,9 @@ func (v *VendorSync) AmendAndPruneStoreStuff(ctx *jxcontext.Context, vendorIDs [
|
||||
return hint, makeSyncError(err)
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
|
||||
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, mustDirty bool, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
|
||||
var storeMapList []*model.StoreMap
|
||||
if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, ""); err != nil {
|
||||
if storeMapList, err = dao.GetStoresMapList2(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, "", mustDirty); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if len(storeMapList) == 0 {
|
||||
@@ -585,7 +590,6 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
||||
if len(loopInfoList) == 1 {
|
||||
taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID])
|
||||
}
|
||||
// globals.SugarLogger.Debugf("LoopStoresMap2 loopInfoList:%s", utils.Format4Output(loopInfoList, false))
|
||||
task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList)
|
||||
tasksch.HandleTask(task, nil, isManageIt).Run()
|
||||
if !isAsync {
|
||||
@@ -604,7 +608,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) {
|
||||
_, hint, err = v.LoopStoresMap2(ctx, db, taskName, isAsync, isManageIt, vendorIDs, storeIDs, handler, isContinueWhenError)
|
||||
_, hint, err = v.LoopStoresMap2(ctx, db, taskName, isAsync, isManageIt, vendorIDs, storeIDs, false, handler, isContinueWhenError)
|
||||
return hint, err
|
||||
}
|
||||
|
||||
|
||||
@@ -208,6 +208,8 @@ func doDailyWork() {
|
||||
cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true)
|
||||
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
|
||||
|
||||
cms.CurVendorSync.SyncStore2(jxcontext.AdminCtx, dao.GetDB(), nil, nil, true, true)
|
||||
|
||||
syncStoreSku()
|
||||
|
||||
InitEx()
|
||||
|
||||
@@ -211,7 +211,7 @@ func GetStoreCourierList(db *DaoDB, storeIDs []int, status, auditStatus int) (co
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int, pricePack string) (storeMapList []*model.StoreMap, err error) {
|
||||
func GetStoresMapList2(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int, pricePack string, mustDirty bool) (storeMapList []*model.StoreMap, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM store_map t1
|
||||
@@ -242,6 +242,10 @@ func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int,
|
||||
sql += " AND t1.price_percentage_pack = ?"
|
||||
sqlParams = append(sqlParams, pricePack)
|
||||
}
|
||||
if mustDirty {
|
||||
sql += " AND t1.sync_status <> 0"
|
||||
sqlParams = append(sqlParams, pricePack)
|
||||
}
|
||||
sql += " ORDER BY t1.store_id DESC, t1.vendor_id"
|
||||
if err = GetRows(db, &storeMapList, sql, sqlParams...); err == nil {
|
||||
return storeMapList, nil
|
||||
@@ -249,6 +253,10 @@ func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int, pricePack string) (storeMapList []*model.StoreMap, err error) {
|
||||
return GetStoresMapList2(db, vendorIDs, storeIDs, status, isSync, pricePack, false)
|
||||
}
|
||||
|
||||
// 此函数在检测到一个门店的所有平台状态一样,且不为StoreStatusOpened时,
|
||||
// 将平台门店状态全部改为StoreStatusOpened,则把京西门店状态改为之前那个统一的平台门店状态
|
||||
func FormalizeStoreStatus(db *DaoDB, storeID, storeStatus int) (err error) {
|
||||
@@ -581,8 +589,8 @@ func GetStorePriceScoreSnapshot(db *DaoDB, snapDate time.Time) (storePriceScoreS
|
||||
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)
|
||||
func SetStoreMapSyncStatus(db *DaoDB, vendorIDs, storeIDs []int, syncStatus int) (num int64, err error) {
|
||||
globals.SugarLogger.Debugf("SetStoreMapSyncStatus, vendorIDs:%v, storeIDs:%v", vendorIDs, storeIDs)
|
||||
|
||||
sql := `
|
||||
UPDATE store_map t1
|
||||
@@ -591,8 +599,12 @@ func SetStoreMapSyncStatus(db *DaoDB, vendorID int, storeIDs []int, syncStatus i
|
||||
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)
|
||||
sql += " WHERE t1.is_sync <> 0 AND t1.deleted_at = ? AND t1.sync_status & ? = 0"
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.SyncFlagDeletedMask)
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
|
||||
@@ -144,6 +144,33 @@ func (c *SyncController) DeleteRemoteStoreSkus() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 同步门店
|
||||
// @Description 同步门店
|
||||
// @Param token header string true "认证token"
|
||||
// @Param vendorIDs formData string false "平台ID(京东0 美团1 饿百3)列表"
|
||||
// @Param vendorOrgCodes formData string false "平台账号列表"
|
||||
// @Param storeIDs formData string false "门店ID列表"
|
||||
// @Param isForce formData bool false "是否强制(设置修改标志)"
|
||||
// @Param isAsync formData bool false "是否异步"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SyncStores [post]
|
||||
func (c *SyncController) SyncStores() {
|
||||
c.callSyncStores(func(params *tSyncSyncStoresParams) (retVal interface{}, errCode string, err error) {
|
||||
var vendorIDs, storeIDs []int
|
||||
var vendorOrgCodes []string
|
||||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.StoreIDs, &storeIDs, params.VendorOrgCodes, &vendorOrgCodes); err == nil {
|
||||
db := dao.GetDB()
|
||||
if params.IsForce {
|
||||
dao.SetStoreMapSyncStatus(db, vendorIDs, storeIDs, model.SyncFlagModifiedMask)
|
||||
}
|
||||
retVal, err = cms.CurVendorSync.SyncStore2(params.Ctx, db, vendorIDs, storeIDs, true, params.IsAsync)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 同步商家分类(多门店平台)
|
||||
// @Description 同步商家分类(多门店平台)
|
||||
// @Param token header string true "认证token"
|
||||
|
||||
@@ -1908,6 +1908,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SyncStores",
|
||||
Router: `/SyncStores`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SyncStoresCategory",
|
||||
|
||||
Reference in New Issue
Block a user