- check store_map

This commit is contained in:
gazebo
2018-10-24 14:54:20 +08:00
parent 7b6c9fd73a
commit 508a949006
4 changed files with 100 additions and 88 deletions

View File

@@ -328,7 +328,7 @@ func (v *VendorSync) LoopSingleStoreVendors(ctx *jxcontext.Context, db *dao.DaoD
if err = dao.GetRows(db, &storeMaps, ` if err = dao.GetRows(db, &storeMaps, `
SELECT * SELECT *
FROM store_map FROM store_map
WHERE vendor_id IN (`+dao.GenQuestionMarks(len(v.SingleStoreVendorIDs))+")", v.SingleStoreVendorIDs); err == nil { WHERE deleted_at = ? AND vendor_id IN (`+dao.GenQuestionMarks(len(v.SingleStoreVendorIDs))+")", utils.DefaultTimeValue, v.SingleStoreVendorIDs); err == nil {
task := tasksch.NewParallelTask(taskName, nil, userName, handler, storeMaps) task := tasksch.NewParallelTask(taskName, nil, userName, handler, storeMaps)
ctx.SetTaskOrAddChild(task, nil) ctx.SetTaskOrAddChild(task, nil)
tasksch.ManageTask(task).Run() tasksch.ManageTask(task).Run()

View File

@@ -49,13 +49,13 @@ func (p *PurchaseHandler) CreateStore(db *dao.DaoDB, storeID int, userName strin
IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator, t2.sync_status, IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator, t2.sync_status,
province.ebai_code province_id, city.ebai_code city_id, district.ebai_code district_id province.ebai_code province_id, city.ebai_code city_id, district.ebai_code district_id
FROM store t1 FROM store t1
LEFT JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? LEFT JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
JOIN place district ON t1.district_code = district.code JOIN place district ON t1.district_code = district.code
JOIN place city ON t1.city_code = city.code JOIN place city ON t1.city_code = city.code
JOIN place province ON city.parent_code = province.code JOIN place province ON city.parent_code = province.code
WHERE t1.id = ? AND t2.id IS NULL; WHERE t1.id = ? AND t2.id IS NULL;
` `
if err = dao.GetRow(db, &store, sql, model.VendorIDEBAI, storeID); err == nil { if err = dao.GetRow(db, &store, sql, model.VendorIDEBAI, utils.DefaultTimeValue, storeID); err == nil {
params := genStoreMapFromStore(&store) params := genStoreMapFromStore(&store)
params["shop_id"] = store.ID params["shop_id"] = store.ID
params["business_form_id"] = "179" params["business_form_id"] = "179"
@@ -135,44 +135,50 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
} }
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) { func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
var store tEbaiStoreInfo var stores []*tEbaiStoreInfo
sql := ` sql := `
SELECT t1.*, t2.status ebai_store_status, t2.vendor_store_id, SELECT t1.*, t2.status ebai_store_status, t2.vendor_store_id,
IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator, t2.sync_status IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator, t2.sync_status
FROM store t1 FROM store t1
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND (t2.deleted_at = ? OR t2.sync_status <> 0)
WHERE t1.id = ?; WHERE t1.id = ?
ORDER BY t2.updated_at
` `
if err = dao.GetRow(db, &store, sql, model.VendorIDEBAI, storeID); err == nil { if err = dao.GetRow(db, &stores, sql, model.VendorIDEBAI, utils.DefaultTimeValue, storeID); err == nil {
params := genStoreMapFromStore(&store) for _, store := range stores {
// globals.SugarLogger.Debug(utils.Format4Output(params, false)) params := genStoreMapFromStore(store)
if globals.EnableStoreWrite { // globals.SugarLogger.Debug(utils.Format4Output(params, false))
if err = api.EbaiAPI.ShopUpdate(params); err == nil { if globals.EnableStoreWrite {
shopID := 0 if err = api.EbaiAPI.ShopUpdate(params); err == nil {
if store.SyncStatus&model.SyncFlagDeletedMask == 0 { shopID := 0
shopID = store.ID if store.SyncStatus&model.SyncFlagDeletedMask == 0 {
} shopID = store.ID
store2, err2 := p.ReadStore(store.VendorStoreID)
if err = err2; err == nil {
if store2.ID == store.ID {
shopID = -1
} }
} store2, err2 := p.ReadStore(store.VendorStoreID)
if err == nil { if err = err2; err == nil {
if shopID > 0 { if store2.ID == store.ID {
err = api.EbaiAPI.ShopIDBatchUpdate([]string{store.VendorStoreID}, []string{utils.Int2Str(shopID)}) shopID = -1
} else if shopID == 0 { }
// todo remove out shop id
} }
} if err == nil {
if err == nil { if shopID > 0 {
mergeStatus := jxutils.MergeStoreStatus(store.Status, store.EbaiStoreStatus) err = api.EbaiAPI.ShopIDBatchUpdate([]string{store.VendorStoreID}, []string{utils.Int2Str(shopID)})
if mergeStatus == model.StoreStatusOpened { } else if shopID == 0 {
err = api.EbaiAPI.ShopOnline("", utils.Str2Int64(store.VendorStoreID)) // todo remove out shop id
} else if mergeStatus == model.StoreStatusClosed { }
err = api.EbaiAPI.ShopOffline("", utils.Str2Int64(store.VendorStoreID)) }
} else if mergeStatus == model.StoreStatusClosed { if err == nil {
err = api.EbaiAPI.ShopClose("", utils.Str2Int64(store.VendorStoreID)) mergeStatus := jxutils.MergeStoreStatus(store.Status, store.EbaiStoreStatus)
if mergeStatus == model.StoreStatusOpened {
err = api.EbaiAPI.ShopOnline("", utils.Str2Int64(store.VendorStoreID))
} else if mergeStatus == model.StoreStatusClosed {
err = api.EbaiAPI.ShopOffline("", utils.Str2Int64(store.VendorStoreID))
} else if mergeStatus == model.StoreStatusClosed {
err = api.EbaiAPI.ShopClose("", utils.Str2Int64(store.VendorStoreID))
}
if err != nil {
return err
}
} }
} }
} }

View File

@@ -86,53 +86,56 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
// stoerIDs为nil表示所有 // stoerIDs为nil表示所有
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) { func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
var store tJdStoreInfo var stores []*tJdStoreInfo
sql := ` sql := `
SELECT t1.*, city.jd_code jd_city_code, district.jd_code jd_district_code, t2.status jd_store_status, t2.vendor_store_id, SELECT t1.*, city.jd_code jd_city_code, district.jd_code jd_district_code, t2.status jd_store_status, t2.vendor_store_id,
IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator, t2.sync_status IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator, t2.sync_status
FROM store t1 FROM store t1
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND (t2.deleted_at = ? OR t2.sync_status <> 0)
LEFT JOIN place city ON t1.city_code = city.code LEFT JOIN place city ON t1.city_code = city.code
LEFT JOIN place district ON t1.district_code = district.code LEFT JOIN place district ON t1.district_code = district.code
WHERE t1.id = ? WHERE t1.id = ?
ORDER BY t2.updated_at DESC ORDER BY t2.updated_at
LIMIT 1;
` `
if err = dao.GetRow(db, &store, sql, model.VendorIDJD, storeID); err == nil { if err = dao.GetRows(db, &stores, sql, model.VendorIDJD, utils.DefaultTimeValue, storeID); err == nil {
outSystemID := "" for _, store := range stores {
if store.SyncStatus&model.SyncFlagDeletedMask == 0 { outSystemID := ""
outSystemID = utils.Int2Str(int(store.ID)) if store.SyncStatus&model.SyncFlagDeletedMask == 0 {
} outSystemID = utils.Int2Str(int(store.ID))
params := map[string]interface{}{ }
"outSystemId": outSystemID, // todo 直接修改这个字段可能会有问题 params := map[string]interface{}{
"stationName": jxutils.ComposeStoreName(store.Name, partner.StoreNameSeparator, VendorStorePrefix), "outSystemId": outSystemID, // todo 直接修改这个字段可能会有问题
"stationAddress": store.Address, "stationName": jxutils.ComposeStoreName(store.Name, partner.StoreNameSeparator, VendorStorePrefix),
"serviceTimeStart1": JxOperationTime2JdOperationTime(store.OpenTime1), "stationAddress": store.Address,
"serviceTimeEnd1": JxOperationTime2JdOperationTime(store.CloseTime1), "serviceTimeStart1": JxOperationTime2JdOperationTime(store.OpenTime1),
"deliveryRangeType": store.DeliveryRangeType, "serviceTimeEnd1": JxOperationTime2JdOperationTime(store.CloseTime1),
"coordinateType": 3, // 一直用高德 "deliveryRangeType": store.DeliveryRangeType,
"lng": jxutils.IntCoordinate2Standard(store.Lng), "coordinateType": 3, // 一直用高德
"lat": jxutils.IntCoordinate2Standard(store.Lat), "lng": jxutils.IntCoordinate2Standard(store.Lng),
"city": store.JdCityCode, "lat": jxutils.IntCoordinate2Standard(store.Lat),
"county": store.JdDistrictCode, "city": store.JdCityCode,
"phone": store.Tel1, "county": store.JdDistrictCode,
"mobile": store.Tel2, "phone": store.Tel1,
} "mobile": store.Tel2,
if store.DeliveryRangeType == model.DeliveryRangeTypePolygon { }
params["coordinatePoints"] = store.DeliveryRange if store.DeliveryRangeType == model.DeliveryRangeTypePolygon {
} else { params["coordinatePoints"] = store.DeliveryRange
params["deliveryRangeRadius"] = utils.Str2Int64(store.DeliveryRange) } else {
} params["deliveryRangeRadius"] = utils.Str2Int64(store.DeliveryRange)
}
openTime2 := JxOperationTime2JdOperationTime(store.OpenTime2) openTime2 := JxOperationTime2JdOperationTime(store.OpenTime2)
if openTime2 != 0 { if openTime2 != 0 {
params["serviceTimeStart2"] = openTime2 params["serviceTimeStart2"] = openTime2
params["serviceTimeEnd2"] = JxOperationTime2JdOperationTime(store.CloseTime2) params["serviceTimeEnd2"] = JxOperationTime2JdOperationTime(store.CloseTime2)
} }
_, params["closeStatus"] = JxStoreStatus2JdStatus(jxutils.MergeStoreStatus(store.Status, store.JdStoreStatus)) _, params["closeStatus"] = JxStoreStatus2JdStatus(jxutils.MergeStoreStatus(store.Status, store.JdStoreStatus))
// globals.SugarLogger.Debug(utils.Format4Output(params, false)) // globals.SugarLogger.Debug(utils.Format4Output(params, false))
if globals.EnableStoreWrite { if globals.EnableStoreWrite {
err = api.JdAPI.UpdateStoreInfo4Open(store.VendorStoreID, store.RealLastOperator, params) if err = api.JdAPI.UpdateStoreInfo4Open(store.VendorStoreID, store.RealLastOperator, params); err != nil {
return err
}
}
} }
} }
return err return err

View File

@@ -29,23 +29,30 @@ func (p *PurchaseHandler) SyncStoresSkus(db *dao.DaoDB, storeIDs []int, skuIDs [
} }
task := tasksch.RunManagedParallelTask("SyncStoresSkus", tasksch.NewParallelConfig().SetParallelCount(parallelCount), userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { task := tasksch.RunManagedParallelTask("SyncStoresSkus", tasksch.NewParallelConfig().SetParallelCount(parallelCount), userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
storeID := batchItemList[0].(int) storeID := batchItemList[0].(int)
sqlParams := []interface{}{ sqlWhere := `
WHERE (t1.deleted_at = ? OR t1.jd_sync_status <> 0) AND t1.store_id = ?
`
sqlWhereParams := []interface{}{
utils.DefaultTimeValue, utils.DefaultTimeValue,
storeID, storeID,
} }
if skuIDs != nil && len(skuIDs) > 0 {
sqlWhere += " AND t1.sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
sqlWhereParams = append(sqlWhereParams, skuIDs)
}
sql := ` sql := `
SELECT t1.*, t2.price_percentage SELECT t1.*, t2.price_percentage
FROM store_sku_bind t1 FROM store_sku_bind t1
JOIN store_map t2 ON t1.store_id = t2.store_id JOIN store_map t2 ON t1.store_id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
WHERE (t1.deleted_at = ? OR t1.jd_sync_status <> 0) AND t1.store_id = ? ` + sqlWhere
`
if skuIDs != nil && len(skuIDs) > 0 {
sql += " AND t1.sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
sqlParams = append(sqlParams, skuIDs)
}
var storeSkus []*tStoreSkuBindExt var storeSkus []*tStoreSkuBindExt
// globals.SugarLogger.Debug(sql, sqlParams) sqlParams := []interface{}{
if err = dao.GetRows(db, &storeSkus, sql, sqlParams); err == nil { model.VendorIDJD,
utils.DefaultTimeValue,
}
if err = dao.GetRows(db, &storeSkus, sql, append(sqlParams, sqlWhereParams...)...); err == nil {
outStationNo := utils.Int2Str(storeID) outStationNo := utils.Int2Str(storeID)
task := tasksch.RunParallelTask("SyncStoresSkus inner", tasksch.NewParallelConfig().SetBatchSize(MaxSkuBatchSize), userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { task := tasksch.RunParallelTask("SyncStoresSkus inner", tasksch.NewParallelConfig().SetBatchSize(MaxSkuBatchSize), userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
var skuPriceInfoList []*jdapi.SkuPriceInfo var skuPriceInfoList []*jdapi.SkuPriceInfo
@@ -101,12 +108,8 @@ func (p *PurchaseHandler) SyncStoresSkus(db *dao.DaoDB, storeIDs []int, skuIDs [
sql := ` sql := `
UPDATE store_sku_bind t1 UPDATE store_sku_bind t1
SET t1.jd_sync_status = 0 SET t1.jd_sync_status = 0
WHERE (t1.deleted_at = ? OR t1.jd_sync_status <> 0) AND t1.store_id = ? ` + sqlWhere
` _, err = dao.ExecuteSQL(db, sql, sqlWhereParams...)
if skuIDs != nil && len(skuIDs) > 0 {
sql += " AND sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
}
_, err = dao.ExecuteSQL(db, sql, sqlParams)
} }
} }
return nil, err return nil, err