根据excel刷新京西价
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"mime/multipart"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -2147,9 +2148,62 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
||||
GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice)
|
||||
storeSkuNamePriceList = append(storeSkuNamePriceList, storeSkuNamePrice)
|
||||
}
|
||||
db := dao.GetDB()
|
||||
storeSkuNamePriceListOrg, err := dao.GetStoreSkuNamePrice(db)
|
||||
CreateOrUpdateStoreSkuNamePriceByExcel(db, ctx, storeSkuNamePriceList, storeSkuNamePriceListOrg)
|
||||
hint, err = RefershJxPrice(db)
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func RefershJxPrice(db *dao.DaoDB) (hint string, err error) {
|
||||
// storeSkuNamePriceList, err := dao.GetStoreSkuNamePrice(db)
|
||||
// task := tasksch.NewParallelTask("根据Excel刷新京西价", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
|
||||
// return retVal, err
|
||||
// }, orderList)
|
||||
// tasksch.HandleTask(task, nil, true).Run()
|
||||
// if !isAsync {
|
||||
// _, err = task.GetResult(0)
|
||||
// hint = "1"
|
||||
// } else {
|
||||
// hint = task.GetID()
|
||||
// }
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func CreateOrUpdateStoreSkuNamePriceByExcel(db *dao.DaoDB, ctx *jxcontext.Context, storeSkuNamePriceList []*model.StoreSkuNamePrice, storeSkuNamePriceListOrg []*model.StoreSkuNamePrice) (err error) {
|
||||
storeSkuNamePriceMap := StoreSkuNamePriceList2Map(ctx, storeSkuNamePriceListOrg)
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
for _, v := range storeSkuNamePriceList {
|
||||
if storeSkuNamePriceMap[v.OutSkuID] != nil {
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
dao.UpdateEntity(db, storeSkuNamePriceMap[v.OutSkuID], "Price", "NameIDGroup", "Unit", "CreatedAt", "UpdatedAt", "LastOperator", "DeletedAt")
|
||||
} else {
|
||||
dao.CreateEntity(db, v)
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
return err
|
||||
}
|
||||
|
||||
func StoreSkuNamePriceList2Map(ctx *jxcontext.Context, storeSkuNamePriceList []*model.StoreSkuNamePrice) (result map[string]*model.StoreSkuNamePrice) {
|
||||
result = make(map[string]*model.StoreSkuNamePrice, len(storeSkuNamePriceList))
|
||||
for _, v := range storeSkuNamePriceList {
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
result[v.OutSkuID] = v
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSkuNamePrice *model.StoreSkuNamePrice) {
|
||||
for k, cell := range row {
|
||||
if k == sheetParam.OutSkuIDCol {
|
||||
@@ -2159,7 +2213,11 @@ func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSk
|
||||
storeSkuNamePrice.Name = cell
|
||||
}
|
||||
if k == sheetParam.SkuNameIDCol {
|
||||
storeSkuNamePrice.NameIDGroup = cell
|
||||
cellReplace := strings.ReplaceAll(cell, ",", ",")
|
||||
if cellReplace[len(cellReplace)-1:len(cellReplace)] == "," {
|
||||
cellReplace = cellReplace[0 : len(cellReplace)-1]
|
||||
}
|
||||
storeSkuNamePrice.NameIDGroup = cellReplace
|
||||
}
|
||||
if k == sheetParam.SkuPriceCol {
|
||||
storeSkuNamePrice.Price = int(utils.Float64TwoInt64(utils.Str2Float64(cell) * 100))
|
||||
|
||||
Reference in New Issue
Block a user