刷新京东等级
This commit is contained in:
@@ -145,6 +145,11 @@ type VendorStoreExcel struct {
|
||||
OperatorName2 string `json:"运营负责人2"`
|
||||
}
|
||||
|
||||
type JdStoreLevelExt struct {
|
||||
Level string `json:"level`
|
||||
PageNo int `json:"pageNo"`
|
||||
}
|
||||
|
||||
var (
|
||||
ErrMissingInput = errors.New("没有有效的输入参数")
|
||||
ErrCanNotFindVendor = errors.New("vendorID参数不合法")
|
||||
@@ -1708,8 +1713,6 @@ func GetStoresVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, v
|
||||
DeliveryType: store.DeliveryType,
|
||||
StoreName: store.OriginalName,
|
||||
IsAutoOrder: store.IsAutoOrder,
|
||||
|
||||
JdStoreLevel: store.JdStoreLevel,
|
||||
}}
|
||||
}
|
||||
}
|
||||
@@ -1751,12 +1754,11 @@ func updateVendorStoreStatusBySnapshot(db *dao.DaoDB, curSnapshotList []*model.V
|
||||
}()
|
||||
for _, v := range storeMapList {
|
||||
if snapshot := snapshotMap[jxutils.Combine2Int(v.StoreID, v.VendorID)]; snapshot != nil &&
|
||||
(v.Status != snapshot.Status || v.DeliveryType != snapshot.DeliveryType || v.StoreName != snapshot.StoreName || v.JdStoreLevel != snapshot.JdStoreLevel) {
|
||||
(v.Status != snapshot.Status || v.DeliveryType != snapshot.DeliveryType || v.StoreName != snapshot.StoreName) {
|
||||
v.Status = snapshot.Status
|
||||
v.DeliveryType = snapshot.DeliveryType
|
||||
v.StoreName = snapshot.StoreName
|
||||
v.JdStoreLevel = snapshot.JdStoreLevel
|
||||
if _, err = dao.UpdateEntity(db, v, model.FieldStatus, "DeliveryType", "StoreName", "JdStoreLevel"); err != nil {
|
||||
if _, err = dao.UpdateEntity(db, v, model.FieldStatus, "DeliveryType", "StoreName"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -2578,3 +2580,54 @@ func CreateStorePriceScore(ctx *jxcontext.Context) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshJdLevel(ctx *jxcontext.Context) (err error) {
|
||||
db := dao.GetDB()
|
||||
storeMapList, err := dao.GetStoresMapList(db, []int{model.VendorIDJD}, nil, model.StoreStatusOpened, -1, "")
|
||||
if len(storeMapList) > 0 {
|
||||
for _, v := range storeMapList {
|
||||
var (
|
||||
pageNoList []int
|
||||
storeMap = make(map[int]string)
|
||||
pageNo int
|
||||
pageLimit = 50
|
||||
)
|
||||
for i := 1; i < pageLimit; i++ {
|
||||
pageNoList = append(pageNoList, i)
|
||||
}
|
||||
task1 := tasksch.NewParallelTask("获取京东门店等级", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
currentPage := batchItemList[0].(int)
|
||||
level, err := jd.GetAPI(v.VendorOrgCode).GetJdStoreLevel(v.VendorOrgCode, v.VendorStoreID, currentPage)
|
||||
tJdStoreInfo1 := &JdStoreLevelExt{
|
||||
Level: level,
|
||||
PageNo: currentPage,
|
||||
}
|
||||
retVal = []*JdStoreLevelExt{tJdStoreInfo1}
|
||||
return retVal, err
|
||||
}, pageNoList)
|
||||
tasksch.HandleTask(task1, nil, true).Run()
|
||||
tJdStoreInfoInterface, err := task1.GetResult(0)
|
||||
for _, v := range tJdStoreInfoInterface {
|
||||
store := v.(*JdStoreLevelExt)
|
||||
if store.PageNo < pageNo {
|
||||
pageNo = store.PageNo
|
||||
}
|
||||
storeMap[store.PageNo] = store.Level
|
||||
}
|
||||
v.JdStoreLevel = storeMap[pageNo]
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
_, err = dao.UpdateEntity(db, v, "JdStoreLevel")
|
||||
dao.Commit(db)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2139,7 +2139,7 @@ func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (storeSkuNameE
|
||||
return storeSkuNameExt, err
|
||||
}
|
||||
|
||||
func GetTopCategorysByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
|
||||
func GetTopCategoriesByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
|
||||
var (
|
||||
skuCategory2 []*model.SkuCategory
|
||||
skuCategoryMap = make(map[int]*model.SkuCategory)
|
||||
@@ -2149,7 +2149,7 @@ func GetTopCategorysByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCateg
|
||||
return skuCategory, err
|
||||
}
|
||||
db := dao.GetDB()
|
||||
skuCategory, err = dao.GetTopCategorysByStoreIDs(db, storeIDs, limit)
|
||||
skuCategory, err = dao.GetTopCategoriesByStoreIDs(db, storeIDs, limit)
|
||||
//若大于等于10个就不用做下面的操作
|
||||
if len(skuCategory) >= limit {
|
||||
return skuCategory, err
|
||||
|
||||
@@ -984,7 +984,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSk
|
||||
return storeSkuNameExt, err
|
||||
}
|
||||
|
||||
func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int, limit int) (skuCategory []*model.SkuCategory, err error) {
|
||||
func GetTopCategoriesByStoreIDs(db *DaoDB, storeIDs []int, limit int) (skuCategory []*model.SkuCategory, err error) {
|
||||
sql := `
|
||||
SELECT DISTINCT t5.* FROM(
|
||||
SELECT d.*
|
||||
|
||||
@@ -36,8 +36,6 @@ type tJdStoreInfo struct {
|
||||
VendorStoreID string `orm:"column(vendor_store_id)"`
|
||||
RealLastOperator string
|
||||
SyncStatus int
|
||||
Level string
|
||||
PageNo int
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -93,9 +91,6 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendo
|
||||
}
|
||||
}
|
||||
}
|
||||
if level, err := GetJdStoreLevel(ctx, vendorOrgCode, vendorStoreID); err == nil {
|
||||
retVal.JdStoreLevel = level
|
||||
}
|
||||
if retVal.DistrictCode == 0 {
|
||||
retVal.DistrictCode = api.AutonaviAPI.GetCoordinateDistrictCode(lng, lat)
|
||||
if retVal.CityCode == 0 {
|
||||
@@ -120,42 +115,6 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetJdStoreLevel(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (level string, err error) {
|
||||
var (
|
||||
pageNoList []int
|
||||
storeMap = make(map[int]string)
|
||||
pageNo int
|
||||
)
|
||||
a := getAPI(vendorOrgCode)
|
||||
for i := 1; i < 6; i++ {
|
||||
pageNoList = append(pageNoList, i)
|
||||
}
|
||||
task := tasksch.NewParallelTask("获取京东商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
currentPage := batchItemList[0].(int)
|
||||
level, err = a.GetJdStoreLevel(vendorOrgCode, vendorStoreID, currentPage)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
tJdStoreInfo1 := &tJdStoreInfo{
|
||||
Level: level,
|
||||
PageNo: currentPage,
|
||||
}
|
||||
retVal = []*tJdStoreInfo{tJdStoreInfo1}
|
||||
return retVal, err
|
||||
}, pageNoList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
tJdStoreInfoInterface, err := task.GetResult(0)
|
||||
for _, v := range tJdStoreInfoInterface {
|
||||
store := v.(*tJdStoreInfo)
|
||||
if store.PageNo > pageNo {
|
||||
pageNo = store.PageNo
|
||||
}
|
||||
storeMap[store.PageNo] = store.Level
|
||||
}
|
||||
return storeMap[pageNo], err
|
||||
}
|
||||
|
||||
// stoerIDs为nil表示所有
|
||||
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
|
||||
var stores []*tJdStoreInfo
|
||||
|
||||
@@ -611,7 +611,6 @@ func (c *StoreController) GetStorePriceScore() {
|
||||
// @Title 生成门店价格分数表
|
||||
// @Description 生成门店价格分数表
|
||||
// @Param token header string true "认证token"
|
||||
// @Param forRefresh formData bool true "是否是刷新中位价重新生成分数表"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /CreateStorePriceScore [post]
|
||||
@@ -622,16 +621,15 @@ func (c *StoreController) CreateStorePriceScore() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 测试jdlevel
|
||||
// @Description 测试jdlevel
|
||||
// @Title 刷新store_map的京东等级
|
||||
// @Description 刷新store_map的京东等级
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SaveAndSendAlarmVendorSnapshot [post]
|
||||
func (c *StoreController) SaveAndSendAlarmVendorSnapshot() {
|
||||
c.callSaveAndSendAlarmVendorSnapshot(func(params *tStoreSaveAndSendAlarmVendorSnapshotParams) (retVal interface{}, errCode string, err error) {
|
||||
err = cms.SaveAndSendAlarmVendorSnapshot(params.Ctx, nil, nil, true)
|
||||
// @router /RefreshJdLevel [post]
|
||||
func (c *StoreController) RefreshJdLevel() {
|
||||
c.callRefreshJdLevel(func(params *tStoreRefreshJdLevelParams) (retVal interface{}, errCode string, err error) {
|
||||
err = cms.RefreshJdLevel(params.Ctx)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -469,12 +469,12 @@ func (c *StoreSkuController) GetTopSkusByStoreIDs() {
|
||||
// @Param storeIDs query string true "门店列表"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetTopCategorysByStoreIDs [get]
|
||||
func (c *StoreSkuController) GetTopCategorysByStoreIDs() {
|
||||
// @router /GetTopCategoriesByStoreIDs [get]
|
||||
func (c *StoreSkuController) GetTopCategoriesByStoreIDs() {
|
||||
var storeIDList []int
|
||||
c.callGetTopCategorysByStoreIDs(func(params *tStoreSkuGetTopCategorysByStoreIDsParams) (retVal interface{}, errCode string, err error) {
|
||||
c.callGetTopCategoriesByStoreIDs(func(params *tStoreSkuGetTopCategoriesByStoreIDsParams) (retVal interface{}, errCode string, err error) {
|
||||
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
|
||||
retVal, err = cms.GetTopCategorysByStoreIDs(params.Ctx, storeIDList)
|
||||
retVal, err = cms.GetTopCategoriesByStoreIDs(params.Ctx, storeIDList)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user