- refactor using jxutils.Strings2Objs

This commit is contained in:
gazebo
2018-12-20 21:54:20 +08:00
parent ae9bc84921
commit 8fc41df791
2 changed files with 24 additions and 66 deletions

View File

@@ -3,6 +3,7 @@ package controllers
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model/dao"
"github.com/astaxie/beego"
)
@@ -25,20 +26,10 @@ type SyncController struct {
func (c *SyncController) SyncStoresSkus() {
c.callSyncStoresSkus(func(params *tSyncSyncStoresSkusParams) (retVal interface{}, errCode string, err error) {
db := dao.GetDB()
var storeIDs []int
var skuIDs []int
var vendorIDs []int
if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &storeIDs); err != nil {
var storeIDs, skuIDs, vendorIDs []int
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs, params.VendorIDs, &vendorIDs); err != nil {
return retVal, "", err
}
if err = utils.UnmarshalUseNumber([]byte(params.VendorIDs), &vendorIDs); err != nil {
return retVal, "", err
}
if params.SkuIDs != "" {
if err = utils.UnmarshalUseNumber([]byte(params.SkuIDs), &skuIDs); err != nil {
return retVal, "", err
}
}
retVal, err = cms.CurVendorSync.SyncStoresSkus(params.Ctx, db, vendorIDs, storeIDs, skuIDs, params.IsAsync, params.IsContinueWhenError)
return retVal, "", err
})
@@ -57,12 +48,8 @@ func (c *SyncController) SyncStoresSkus() {
func (c *SyncController) SyncStoresCategory() {
c.callSyncStoresCategory(func(params *tSyncSyncStoresCategoryParams) (retVal interface{}, errCode string, err error) {
db := dao.GetDB()
var storeIDs []int
var vendorIDs []int
if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &storeIDs); err != nil {
return retVal, "", err
}
if err = utils.UnmarshalUseNumber([]byte(params.VendorIDs), &vendorIDs); err != nil {
var storeIDs, vendorIDs []int
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.VendorIDs, &vendorIDs); err != nil {
return retVal, "", err
}
retVal, err = cms.CurVendorSync.SyncStoresCategory(params.Ctx, db, vendorIDs, storeIDs, params.IsAsync)
@@ -101,14 +88,9 @@ func (c *SyncController) RefreshAllStoresID() {
func (c *SyncController) RefreshAllSkusID() {
c.callRefreshAllSkusID(func(params *tSyncRefreshAllSkusIDParams) (retVal interface{}, errCode string, err error) {
var vendorIDs, storeIDs []int
if err = utils.UnmarshalUseNumber([]byte(params.VendorIDs), &vendorIDs); err != nil {
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.VendorIDs, &vendorIDs); err != nil {
return retVal, "", err
}
if params.StoreIDs != "" {
if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &storeIDs); err != nil {
return retVal, "", err
}
}
retVal, err = cms.CurVendorSync.RefreshAllSkusID(params.Ctx, params.IsAsync, vendorIDs, storeIDs)
return retVal, "", err
})
@@ -127,12 +109,8 @@ func (c *SyncController) RefreshAllSkusID() {
func (c *SyncController) FullSyncStoresSkus() {
c.callFullSyncStoresSkus(func(params *tSyncFullSyncStoresSkusParams) (retVal interface{}, errCode string, err error) {
db := dao.GetDB()
var storeIDs []int
var vendorIDs []int
if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &storeIDs); err != nil {
return retVal, "", err
}
if err = utils.UnmarshalUseNumber([]byte(params.VendorIDs), &vendorIDs); err != nil {
var vendorIDs, storeIDs []int
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.VendorIDs, &vendorIDs); err != nil {
return retVal, "", err
}
retVal, err = cms.CurVendorSync.FullSyncStoresSkus(params.Ctx, db, vendorIDs, storeIDs, params.IsAsync, params.IsContinueWhenError)