This commit is contained in:
苏尹岚
2021-03-17 13:58:14 +08:00
parent 30e4b26ebf
commit 1441e31bae

View File

@@ -399,39 +399,115 @@ func RefreshStoreManageState(ctx *jxcontext.Context) {
var ( var (
db = dao.GetDB() db = dao.GetDB()
vendorIDs = []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI} vendorIDs = []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}
dayTimeBegin, dayTimeEnd = utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "00:00:00"), utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "23:59:59") messageFlag = time.Now().Hour() == 10 && time.Now().Minute() > 0 && time.Now().Minute() < 12
coverAreaFlag = time.Now().Hour() == 10 && time.Now().Minute() > 0 && time.Now().Minute() < 12
) )
task := tasksch.NewParallelTask("RefreshStoreManageState", tasksch.NewParallelConfig().SetParallelCount(3).SetIsContinueWhenError(true), ctx, task := tasksch.NewParallelTask("RefreshStoreManageState", tasksch.NewParallelConfig().SetParallelCount(3).SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
vendorID := batchItemList[0].(int) vendorID := batchItemList[0].(int)
storeMaps, err := dao.GetStoresMapList(db, []int{vendorID}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "") storeMaps, err := dao.GetStoresMapList(db, []int{vendorID}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "")
paged, err := dao.GetStoreManageState(db, nil, nil, vendorID, 0, 0, model.UnlimitedPageSize)
var (
storeManageStates = paged.Data.([]*dao.GetStoreManageStateResult)
storeMapsMap = make(map[int]*model.StoreMap)
storeManagesMap = make(map[int]*dao.GetStoreManageStateResult)
deleteList []int
createList, updateList []*model.StoreMap
)
for _, v := range storeMaps {
storeMapsMap[v.StoreID] = v
}
for _, v := range storeManageStates {
storeManagesMap[v.StoreID] = v
if storeMapsMap[v.StoreID] != nil {
updateList = append(updateList, storeMapsMap[v.StoreID])
} else {
deleteList = append(deleteList, v.StoreID)
}
}
for _, v := range storeMapsMap {
if storeManagesMap[v.StoreID] == nil {
createList = append(createList, v)
}
}
task2 := tasksch.NewParallelTask("GetStoreManageState2", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx, task2 := tasksch.NewParallelTask("GetStoreManageState2", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
step := batchItemList[0].(int)
switch step {
case 0:
task3 := tasksch.NewParallelTask("deleteList", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeID := batchItemList[0].(int)
storeManage := &model.StoreManageState{
StoreID: storeID,
VendorID: vendorID,
}
dao.DeleteEntity(db, storeManage, "StoreID", "VendorID")
return retVal, err
}, deleteList)
tasksch.HandleTask(task3, task, true).Run()
task3.GetResult(0)
case 1:
task3 := tasksch.NewParallelTask("createList", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap) storeMap := batchItemList[0].(*model.StoreMap)
if storeMap.VendorOrgCode == "" || storeMap.VendorStoreID == "" { if storeMap.VendorOrgCode == "" || storeMap.VendorStoreID == "" {
return retVal, err return retVal, err
} }
storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, vendorID, storeMap.VendorOrgCode) storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, vendorID, storeMap.VendorOrgCode)
storeManage := buildStoreManageState(ctx, db, storeMap, storeDetail, messageFlag)
dao.UpdateEntity(db, storeManage)
return retVal, err
}, createList)
tasksch.HandleTask(task3, task, true).Run()
task3.GetResult(0)
case 2:
task3 := tasksch.NewParallelTask("updateList", tasksch.NewParallelConfig().SetParallelCount(50).SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap)
if storeMap.VendorOrgCode == "" || storeMap.VendorStoreID == "" {
return retVal, err
}
storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, vendorID, storeMap.VendorOrgCode)
storeManage := buildStoreManageState(ctx, db, storeMap, storeDetail, messageFlag)
dao.CreateEntity(db, storeManage)
return retVal, err
}, updateList)
tasksch.HandleTask(task3, task, true).Run()
task3.GetResult(0)
}
return retVal, err
}, []int{0, 1, 2})
tasksch.HandleTask(task, task2, true).Run()
task2.GetResult(0)
return retVal, err
}, vendorIDs)
tasksch.HandleTask(task, nil, true).Run()
task.GetID()
}
func buildStoreManageState(ctx *jxcontext.Context, db *dao.DaoDB, storeMap *model.StoreMap, storeDetail *dao.StoreDetail, messageFlag bool) *model.StoreManageState {
var (
dayTimeBegin, dayTimeEnd = utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "00:00:00"), utils.Str2Time(utils.Time2Str(utils.Time2Date(time.Now())) + "23:59:59")
)
storeManage := &model.StoreManageState{ storeManage := &model.StoreManageState{
StoreID: storeMap.StoreID, StoreID: storeMap.StoreID,
VendorID: storeMap.VendorID, VendorID: storeMap.VendorID,
} }
dao.WrapAddIDCULEntity(storeManage, ctx.GetUserName()) dao.WrapAddIDCULEntity(storeManage, ctx.GetUserName())
handler := partner.GetPurchasePlatformFromVendorID(vendorID) handler := partner.GetPurchasePlatformFromVendorID(storeMap.VendorID)
store, err := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID) store, _ := handler.ReadStore(ctx, storeDetail.VendorOrgCode, storeDetail.VendorStoreID)
// if coverAreaFlag { // if coverAreaFlag {
if vendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon { if storeMap.VendorID == model.VendorIDJD && store.DeliveryRangeType != model.DeliveryRangeTypePolygon {
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", math.Pi*utils.Str2Float64WithDefault(store.DeliveryRange, 0)/float64(1000)*utils.Str2Float64WithDefault(store.DeliveryRange, 0)/float64(1000))) storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", math.Pi*utils.Str2Float64WithDefault(store.DeliveryRange, 0)/float64(1000)*utils.Str2Float64WithDefault(store.DeliveryRange, 0)/float64(1000)))
} else { } else {
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), vendorID))) storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", CalculateCoverArea(strings.Split(store.DeliveryRange, ";"), storeMap.VendorID)))
} }
// } // }
storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", storeManage.CoverArea)) storeManage.CoverArea = utils.Str2Float64(fmt.Sprintf("%.2f", storeManage.CoverArea))
//营业状态 //营业状态
storeManage.VendorStatus = store.Status storeManage.VendorStatus = store.Status
//不一致发消息 //不一致发消息
if coverAreaFlag { if messageFlag {
vendorStatus, status := -1, -1 vendorStatus, status := -1, -1
if store.Status == model.StoreStatusOpened { if store.Status == model.StoreStatusOpened {
vendorStatus = 1 vendorStatus = 1
@@ -444,7 +520,7 @@ func RefreshStoreManageState(ctx *jxcontext.Context) {
-1: "休息", -1: "休息",
} }
if vendorStatus != status { if vendorStatus != status {
content := "您的门店 [" + storeDetail.Name + "]ID:[" + utils.Int2Str(storeDetail.ID) + "],在[" + model.VendorChineseNames[vendorID] + "] 平台上营业状态和京西不一致!平台状态:【" + statusMap[vendorStatus] + "】,京西状态:【" + statusMap[status] + "】" content := "您的门店 [" + storeDetail.Name + "]ID:[" + utils.Int2Str(storeDetail.ID) + "],在[" + model.VendorChineseNames[storeMap.VendorID] + "] 平台上营业状态和京西不一致!平台状态:【" + statusMap[vendorStatus] + "】,京西状态:【" + statusMap[status] + "】"
if user, err := dao.GetUserByID(db, "mobile", storeDetail.MarketManPhone); err == nil { if user, err := dao.GetUserByID(db, "mobile", storeDetail.MarketManPhone); err == nil {
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "平台门店状态变化", content) ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "平台门店状态变化", content)
} }
@@ -470,7 +546,7 @@ func RefreshStoreManageState(ctx *jxcontext.Context) {
storeManage.ActAmple = ample storeManage.ActAmple = ample
//订单 //订单
refuseOrderCount := 0 refuseOrderCount := 0
orderList, _ := dao.QueryOrdersForManageState(db, storeMap.StoreID, vendorID, model.OrderStatusCanceled, dayTimeBegin, dayTimeEnd) orderList, _ := dao.QueryOrdersForManageState(db, storeMap.StoreID, storeMap.VendorID, model.OrderStatusCanceled, dayTimeBegin, dayTimeEnd)
for _, v := range orderList { for _, v := range orderList {
if v.BindID == 0 { if v.BindID == 0 {
refuseOrderCount++ refuseOrderCount++
@@ -478,21 +554,13 @@ func RefreshStoreManageState(ctx *jxcontext.Context) {
} }
storeManage.NullOrderCount, storeManage.RefuseOrderCount = len(orderList), refuseOrderCount storeManage.NullOrderCount, storeManage.RefuseOrderCount = len(orderList), refuseOrderCount
//评分(美团) //评分(美团)
if vendorID == model.VendorIDMTWM { if storeMap.VendorID == model.VendorIDMTWM {
mtapi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, storeDetail.VendorOrgCode).(*mtwmapi.API) mtapi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, storeDetail.VendorOrgCode).(*mtwmapi.API)
if scoreResult, err := mtapi.CommentScore(storeDetail.VendorStoreID); err == nil { if scoreResult, err := mtapi.CommentScore(storeDetail.VendorStoreID); err == nil {
storeManage.StoreScore = scoreResult.AvgPoiScore storeManage.StoreScore = scoreResult.AvgPoiScore
} }
} }
dao.CreateOrUpdate(db, storeManage) return storeManage
return retVal, err
}, storeMaps)
tasksch.HandleTask(task2, task, true).Run()
task2.GetResult(0)
return retVal, err
}, vendorIDs)
tasksch.HandleTask(task, nil, true).Run()
task.GetID()
} }
func GetStoreManageState(ctx *jxcontext.Context, storeIDs, brandIDs []int, vendorID, sortType, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { func GetStoreManageState(ctx *jxcontext.Context, storeIDs, brandIDs []int, vendorID, sortType, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {