- ExportShopsHealthInfo
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package orderman
|
package orderman
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -18,9 +16,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/qiniu/api.v7/storage"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -466,13 +462,6 @@ func (c *OrderManager) ExportOrders(ctx *jxcontext.Context, fromDateStr, toDateS
|
|||||||
}
|
}
|
||||||
excelBin = excel.Obj2Excel([]*excel.Obj2ExcelSheetConfig{excelConf})
|
excelBin = excel.Obj2Excel([]*excel.Obj2ExcelSheetConfig{excelConf})
|
||||||
case 3:
|
case 3:
|
||||||
putPolicy := storage.PutPolicy{
|
|
||||||
Scope: globals.QiniuBucket,
|
|
||||||
Expires: 10 * 60,
|
|
||||||
DeleteAfterDays: 1,
|
|
||||||
}
|
|
||||||
upToken := putPolicy.UploadToken(api.QiniuAPI)
|
|
||||||
cfg := &storage.Config{}
|
|
||||||
keyPart := []string{
|
keyPart := []string{
|
||||||
ctx.GetUserName(),
|
ctx.GetUserName(),
|
||||||
}
|
}
|
||||||
@@ -484,15 +473,10 @@ func (c *OrderManager) ExportOrders(ctx *jxcontext.Context, fromDateStr, toDateS
|
|||||||
}
|
}
|
||||||
keyPart = append(keyPart, time.Now().Format("20060102T150405")+".xlsx")
|
keyPart = append(keyPart, time.Now().Format("20060102T150405")+".xlsx")
|
||||||
key := "export/" + strings.Join(keyPart, "_")
|
key := "export/" + strings.Join(keyPart, "_")
|
||||||
formUploader := storage.NewFormUploader(cfg)
|
excelURL, err2 := jxutils.UploadExportContent(excelBin, key)
|
||||||
ret := storage.PutRet{}
|
if err = err2; err == nil {
|
||||||
for i := 0; i < 3; i++ {
|
task.SetNoticeMsg(excelURL)
|
||||||
if err = formUploader.Put(context.Background(), &ret, upToken, key, bytes.NewReader(excelBin), int64(len(excelBin)), &storage.PutExtra{}); err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
excelURL := jxutils.ComposeQiniuResURL(key)
|
|
||||||
task.SetNoticeMsg(excelURL)
|
|
||||||
globals.SugarLogger.Debugf("导出订单SKU信息excelURL:%s, err:%v", excelURL, err)
|
globals.SugarLogger.Debugf("导出订单SKU信息excelURL:%s, err:%v", excelURL, err)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/feieapi"
|
"git.rosy.net.cn/baseapi/platformapi/feieapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/netprinter"
|
"git.rosy.net.cn/jx-callback/business/jxutils/netprinter"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
@@ -1039,3 +1042,85 @@ func updateOrCreateDadaStore(storeDetail *dao.StoreDetail2) (err error) {
|
|||||||
func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) {
|
func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) {
|
||||||
return storeDetail.Name + "-" + storeDetail.DadaStoreID
|
return storeDetail.Name + "-" + storeDetail.DadaStoreID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExportShopsHealthInfo(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
db := dao.GetDB()
|
||||||
|
vendorID := model.VendorIDEBAI
|
||||||
|
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, model.StoreStatusAll)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
storeMap2 := make(map[string]*model.StoreMap)
|
||||||
|
for _, v := range storeMapList {
|
||||||
|
storeMap2[v.VendorStoreID] = v
|
||||||
|
}
|
||||||
|
if len(storeMapList) > 0 {
|
||||||
|
var healthInfoList []interface{}
|
||||||
|
var excelBin []byte
|
||||||
|
var excelURL string
|
||||||
|
task := tasksch.NewSeqTask(fmt.Sprintf("ExportShopHealthInfo[%s]", model.VendorChineseNames[vendorID]), ctx,
|
||||||
|
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
|
switch step {
|
||||||
|
case 0:
|
||||||
|
subTask := tasksch.NewParallelTask(fmt.Sprintf("ExportShopHealthInfo2[%s]", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
storeMap := batchItemList[0].(*model.StoreMap)
|
||||||
|
healthInfo, err := ebai.CurPurchaseHandler.GetShopHealthInfo(storeMap.VendorStoreID)
|
||||||
|
if err == nil {
|
||||||
|
retVal = []map[string]interface{}{healthInfo}
|
||||||
|
}
|
||||||
|
return retVal, err
|
||||||
|
}, storeMapList)
|
||||||
|
tasksch.AddChild(task, subTask).Run()
|
||||||
|
healthInfoList, err = subTask.GetResult(0)
|
||||||
|
if isContinueWhenError && err != nil && len(healthInfoList) > 0 {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
var healthInfoList2 []map[string]interface{}
|
||||||
|
for _, v := range healthInfoList {
|
||||||
|
mapInfo := v.(map[string]interface{})
|
||||||
|
mapInfo["real_shop_id"] = storeMap2[utils.Interface2String(mapInfo["merchant_id"])].StoreID
|
||||||
|
healthInfoList2 = append(healthInfoList2, mapInfo)
|
||||||
|
}
|
||||||
|
excelConf := &excel.Obj2ExcelSheetConfig{
|
||||||
|
Title: "饿百门店情况导出",
|
||||||
|
Data: healthInfoList2,
|
||||||
|
CaptionList: []string{
|
||||||
|
"real_shop_id",
|
||||||
|
"merchant_id",
|
||||||
|
"merchant_name",
|
||||||
|
"hours",
|
||||||
|
"sku_num",
|
||||||
|
"target_jiedan",
|
||||||
|
"is_healthy",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
excelBin = excel.Obj2Excel([]*excel.Obj2ExcelSheetConfig{excelConf})
|
||||||
|
case 2:
|
||||||
|
keyPart := []string{
|
||||||
|
ctx.GetUserName(),
|
||||||
|
"饿百门店情况",
|
||||||
|
}
|
||||||
|
keyPart = append(keyPart, time.Now().Format("20060102T150405")+".xlsx")
|
||||||
|
key := "export/" + strings.Join(keyPart, "_")
|
||||||
|
excelURL, err = jxutils.UploadExportContent(excelBin, key)
|
||||||
|
if err == nil {
|
||||||
|
task.SetNoticeMsg(excelURL)
|
||||||
|
}
|
||||||
|
globals.SugarLogger.Debugf("导出饿百门店情况excelURL:%s, err:%v", excelURL, err)
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}, 3)
|
||||||
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
|
if !isAsync {
|
||||||
|
_, err = task.GetResult(0)
|
||||||
|
if err == nil {
|
||||||
|
hint = excelURL
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hint = task.GetID()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package jxutils
|
package jxutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -14,7 +16,9 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/utils/routinepool"
|
"git.rosy.net.cn/baseapi/utils/routinepool"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
"github.com/qiniu/api.v7/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -511,3 +515,24 @@ func RemoveSkuFromOrder(order *model.GoodsOrder, removedSkuList []*model.OrderSk
|
|||||||
order.Skus = skuList
|
order.Skus = skuList
|
||||||
return RefreshOrderSkuRelated(order)
|
return RefreshOrderSkuRelated(order)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UploadExportContent(content []byte, key string) (downloadURL string, err error) {
|
||||||
|
putPolicy := storage.PutPolicy{
|
||||||
|
Scope: globals.QiniuBucket,
|
||||||
|
Expires: 10 * 60,
|
||||||
|
DeleteAfterDays: 1,
|
||||||
|
}
|
||||||
|
upToken := putPolicy.UploadToken(api.QiniuAPI)
|
||||||
|
cfg := &storage.Config{}
|
||||||
|
formUploader := storage.NewFormUploader(cfg)
|
||||||
|
ret := storage.PutRet{}
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
if err = formUploader.Put(context.Background(), &ret, upToken, key, bytes.NewReader(content), int64(len(content)), &storage.PutExtra{}); err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
downloadURL = ComposeQiniuResURL(key)
|
||||||
|
}
|
||||||
|
return downloadURL, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -423,3 +423,11 @@ func (c *PurchaseHandler) onShopMsgPush(msg *ebaiapi.CallbackMsg) (response *eba
|
|||||||
}
|
}
|
||||||
return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, err, nil)
|
return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *PurchaseHandler) GetShopHealthInfo(vendorShopID string) (shopHealthInfo map[string]interface{}, err error) {
|
||||||
|
result, err := api.EbaiAPI.GetShopHealthByDetail(utils.Str2Int64(vendorShopID))
|
||||||
|
if err == nil {
|
||||||
|
shopHealthInfo = utils.Struct2FlatMap(result)
|
||||||
|
}
|
||||||
|
return shopHealthInfo, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -351,3 +351,23 @@ func (c *StoreController) RefreshMissingDadaStores() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 导出门店健康度信息
|
||||||
|
// @Description 导出门店健康度信息
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param vendorIDs query string false "平台ID列表"
|
||||||
|
// @Param storeIDs query string false "门店ID列表"
|
||||||
|
// @Param isAsync query bool false "是否异步操作"
|
||||||
|
// @Param isContinueWhenError query bool false "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /ExportShopsHealthInfo [get]
|
||||||
|
func (c *StoreController) ExportShopsHealthInfo() {
|
||||||
|
c.callExportShopsHealthInfo(func(params *tStoreExportShopsHealthInfoParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
var vendorIDList, storeIDList []int
|
||||||
|
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil {
|
||||||
|
retVal, err = cms.ExportShopsHealthInfo(params.Ctx, vendorIDList, storeIDList, params.IsAsync, params.IsContinueWhenError)
|
||||||
|
}
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1087,6 +1087,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "ExportShopsHealthInfo",
|
||||||
|
Router: `/ExportShopsHealthInfo`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetStoreCourierMaps",
|
Method: "GetStoreCourierMaps",
|
||||||
|
|||||||
Reference in New Issue
Block a user