添加API SyncStoresCourierInfo

This commit is contained in:
gazebo
2019-10-11 16:12:09 +08:00
parent 7946ab6207
commit 470f54f705
9 changed files with 124 additions and 7 deletions

View File

@@ -18,7 +18,7 @@ import (
func (c *BaseScheduler) CreateWaybillOnProviders(ctx *jxcontext.Context, order *model.GoodsOrder, courierVendorIDs, excludeCourierVendorIDs []int, maxDeliveryFee int64, createOnlyOne bool) (bills []*model.Waybill, err error) {
userName := ctx.GetUserName()
globals.SugarLogger.Infof("CreateWaybillOnProviders orderID:%s userName:%s, courierVendorIDs:%v, excludeCourierVendorIDs:%v", order.VendorOrderID, userName, courierVendorIDs, excludeCourierVendorIDs)
storeCourierList, err := dao.GetStoreCourierList(dao.GetDB(), []int{jxutils.GetSaleStoreIDFromOrder(order)}, model.StoreStatusOpened)
storeCourierList, err := dao.GetStoreCourierList(dao.GetDB(), []int{jxutils.GetSaleStoreIDFromOrder(order)}, model.StoreStatusOpened, model.StoreAuditStatusOnline)
if err != nil {
return nil, err
}

View File

@@ -210,7 +210,7 @@ func (s *DefScheduler) QueryOrderWaybillFeeInfoEx(ctx *jxcontext.Context, vendor
if order.DeliveryType == model.OrderDeliveryTypeSelfTake {
return nil, fmt.Errorf("订单:%s是自提单", vendorOrderID)
}
storeCourierList, err := dao.GetStoreCourierList(db, []int{jxutils.GetSaleStoreIDFromOrder(order)}, model.StoreStatusAll)
storeCourierList, err := dao.GetStoreCourierList(db, []int{jxutils.GetSaleStoreIDFromOrder(order)}, model.StoreStatusAll, model.StoreAuditStatusOnline)
if err != nil {
return nil, err
}

View File

@@ -273,7 +273,7 @@ func setStoreMapInfo(ctx *jxcontext.Context, db *dao.DaoDB, storesInfo *StoresIn
if err != nil {
return err
}
storeCourierList, err := dao.GetStoreCourierList(db, storeIDs, model.StoreStatusAll)
storeCourierList, err := dao.GetStoreCourierList(db, storeIDs, model.StoreStatusAll, model.StoreAuditStatusAll)
if err != nil {
return err
}
@@ -1873,6 +1873,85 @@ func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs
return err
}
func SyncStoresCourierInfo(ctx *jxcontext.Context, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
storeList2, err := dao.GetStoreList(db, storeIDs, nil, "")
var storeList []*model.Store
for _, v := range storeList2 {
if v.Status != model.StoreStatusDisabled {
storeList = append(storeList, v)
}
}
if err == nil && len(storeList) > 0 {
task := tasksch.NewParallelTask(fmt.Sprintf("同步门店快递信息1:%v", storeIDs),
tasksch.NewParallelConfig().SetParallelCount(2).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
store := batchItemList[0].(*model.Store)
subTask := tasksch.NewParallelTask(fmt.Sprintf("同步门店快递信息2:%d", store.ID),
tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
vendorID := batchItemList[0].(int)
storeDetail2, err := dao.GetStoreDetail2(db, store.ID, "", vendorID)
if err == nil && storeDetail2.VendorStoreID != "" && storeDetail2.CourierStatus != model.StoreStatusDisabled {
if handler := partner.GetDeliveryPlatformFromVendorID(vendorID); handler != nil {
if updateHandler, ok := handler.Handler.(partner.IDeliveryUpdateStoreHandler); ok {
updateHandler.UpdateStore(ctx, storeDetail2)
}
storeCourier, err2 := handler.Handler.GetStore(ctx, store.ID, storeDetail2.VendorStoreID)
if err = err2; err == nil {
if storeDetail2.AuditStatus == model.StoreAuditStatusCreated { // 如果已经通过审核,更新本地状态
partner.CurStoreManager.OnCourierStoreStatusChanged(ctx, storeCourier.VendorStoreID, vendorID, storeCourier.AuditStatus)
}
distance := jxutils.EarthDistance(jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat), jxutils.IntCoordinate2Standard(storeCourier.Lng), jxutils.IntCoordinate2Standard(storeCourier.Lat))
params := map[string]interface{}{
"Lng": storeCourier.Lng,
"Lat": storeCourier.Lat,
"Remark": fmt.Sprintf("%d", int(distance*1000)),
}
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.StoreCourierMap{}, params, ctx.GetUserName(), map[string]interface{}{
"StoreID": store.ID,
"VendorID": vendorID,
})
if distance > 0.2 {
globals.SugarLogger.Infof("SyncStoresCourierInfo [运营2]门店:%s-%d的%s配送门店坐标不一致,京西:%d,%d,平台:%d,%d,距离:%f公里", store.Name, store.ID, model.VendorChineseNames[vendorID], store.Lng, store.Lat, storeCourier.Lng, storeCourier.Lat, distance)
retVal = [][]interface{}{
[]interface{}{
store,
storeDetail2,
},
}
}
} else if handler.Handler.IsErrStoreNotExist(err) {
if storeDetail2.AuditStatus == model.StoreAuditStatusCreated {
err = nil
} else {
globals.SugarLogger.Infof("SyncStoresCourierInfo [运营2]门店:%s-%d的%s配送门店%s获取出错:%v", store.Name, store.ID, model.VendorChineseNames[vendorID], storeDetail2.VendorStoreID, err)
}
}
}
} else if dao.IsNoRowsError(err) {
err = nil
}
return retVal, err
}, partner.UseableDeliveryVendorIDs)
tasksch.HandleTask(subTask, task, true).Run()
retVal, err = subTask.GetResult(0)
return retVal, err
}, storeList)
tasksch.HandleTask(task, nil, true).Run()
if isAsync {
hint = task.GetID()
} else {
resultList, err2 := task.GetResult(0)
if err = err2; err == nil {
hint = utils.Int2Str(len(resultList))
}
}
}
return hint, err
}
func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
if len(storeIDs) > 0 {
db := dao.GetDB()

View File

@@ -208,7 +208,7 @@ func GetStoreDetail2(db *DaoDB, storeID int, vendorStoreID string, vendorID int)
return storeDetail, err
}
func GetStoreCourierList(db *DaoDB, storeIDs []int, status int) (courierStoreList []*model.StoreCourierMap, err error) {
func GetStoreCourierList(db *DaoDB, storeIDs []int, status, auditStatus int) (courierStoreList []*model.StoreCourierMap, err error) {
sql := `
SELECT t1.*
FROM store_courier_map t1
@@ -225,6 +225,10 @@ func GetStoreCourierList(db *DaoDB, storeIDs []int, status int) (courierStoreLis
sql += " AND t1.status = ?"
sqlParams = append(sqlParams, status)
}
if auditStatus != model.StoreAuditStatusAll {
sql += " AND t1.audit_status = ?"
sqlParams = append(sqlParams, auditStatus)
}
if err = GetRows(db, &courierStoreList, sql, sqlParams...); err == nil {
return courierStoreList, nil
}

View File

@@ -17,7 +17,7 @@ func TestGetStoreDetail(t *testing.T) {
}
func TestGetStoreCourierList(t *testing.T) {
storeCourierList, err := GetStoreCourierList(GetDB(), []int{100119}, model.StoreStatusOpened)
storeCourierList, err := GetStoreCourierList(GetDB(), []int{100119}, model.StoreStatusOpened, model.StoreAuditStatusOnline)
if err != nil {
t.Fatal(err)
}

View File

@@ -22,6 +22,7 @@ const (
StoreAuditStatusCreated = 1
StoreAuditStatusOnline = 0
StoreAuditStatusRejected = -1
StoreAuditStatusAll = -9
)
const (
@@ -391,6 +392,11 @@ type StoreCourierMap struct {
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
Status int `json:"status"`
AuditStatus int `json:"auditStatus"`
// 以下数据仅用于同步使用
Lng int `json:"-"` // 乘了10的6次方
Lat int `json:"-"` // 乘了10的6次方
Remark string `orm:"size(255)" json:"-"`
}
func (*StoreCourierMap) TableUnique() [][]string {

View File

@@ -294,8 +294,8 @@ elmSecret = "1fc221f8265506531da36fb613d5f5ad673f2e9a"
ebaiSource = "34665"
ebaiSecret = "c3db75b754ea2d89"
mtpsAppKey = "25e816550bc9484480642f19a95f13fd"
mtpsSecret = "r4$HqrKx9~=7?2Jfo,$Z~a7%~k!Au&pEdI2)oPJvSbH2ao@2N0[8wSIvtuumh_J^"
mtpsAppKey = "3c0a05d464c247c19d7ec13accc78605"
mtpsSecret = "b1M}9?:sTbsB[OF2gNORnN(|(iy9rB8(`7]|[wGLnbmt`evfM>E:A90DjHAW:UPE"
dadaIsProd = true
dadaCallbackURL = "http://callback.beta.jxc4.com/dadadelivery/msg"

View File

@@ -510,3 +510,22 @@ func (c *StoreController) GetStoreAlertList() {
return retVal, "", err
})
}
// @Title 同步快递平台门店信息并报警
// @Description 同步快递平台门店信息并报警
// @Param token header string true "认证token"
// @Param storeIDs formData string false "京西门店ID列表必须非空值"
// @Param isAsync formData bool false "是否异步操作"
// @Param isContinueWhenError formData bool false "单个同步失败是否继续缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SyncStoresCourierInfo [post]
func (c *StoreController) SyncStoresCourierInfo() {
c.callSyncStoresCourierInfo(func(params *tStoreSyncStoresCourierInfoParams) (retVal interface{}, errCode string, err error) {
var storeIDs []int
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil {
retVal, err = cms.SyncStoresCourierInfo(params.Ctx, storeIDs, params.IsAsync, params.IsContinueWhenError)
}
return retVal, "", err
})
}

View File

@@ -1323,6 +1323,15 @@ func init() {
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.ControllerComments{
Method: "SyncStoresCourierInfo",
Router: `/SyncStoresCourierInfo`,
AllowHTTPMethods: []string{"post"},
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.ControllerComments{
Method: "SyncStoresQualify",