根据excel刷新京西价
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -2147,9 +2148,62 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
|||||||
GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice)
|
GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice)
|
||||||
storeSkuNamePriceList = append(storeSkuNamePriceList, 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
|
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) {
|
func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSkuNamePrice *model.StoreSkuNamePrice) {
|
||||||
for k, cell := range row {
|
for k, cell := range row {
|
||||||
if k == sheetParam.OutSkuIDCol {
|
if k == sheetParam.OutSkuIDCol {
|
||||||
@@ -2159,7 +2213,11 @@ func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSk
|
|||||||
storeSkuNamePrice.Name = cell
|
storeSkuNamePrice.Name = cell
|
||||||
}
|
}
|
||||||
if k == sheetParam.SkuNameIDCol {
|
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 {
|
if k == sheetParam.SkuPriceCol {
|
||||||
storeSkuNamePrice.Price = int(utils.Float64TwoInt64(utils.Str2Float64(cell) * 100))
|
storeSkuNamePrice.Price = int(utils.Float64TwoInt64(utils.Str2Float64(cell) * 100))
|
||||||
|
|||||||
@@ -1050,6 +1050,22 @@ func RefershStoreSkusMidPrice(db *DaoDB, storeIDs []int) (count int64, err error
|
|||||||
return ExecuteSQL(db, sql, sqlParams)
|
return ExecuteSQL(db, sql, sqlParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetStoreSkuNamePrice(db *DaoDB) (storeSkuNamePriceList []*model.StoreSkuNamePrice, err error) {
|
||||||
|
sql := `
|
||||||
|
SELECT *
|
||||||
|
FROM store_sku_name_price
|
||||||
|
WHERE deleted_at = ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
}
|
||||||
|
err = GetRows(db, &storeSkuNamePriceList, sql, sqlParams...)
|
||||||
|
if err != nil {
|
||||||
|
return nil,err
|
||||||
|
}
|
||||||
|
return storeSkuNamePriceList, err
|
||||||
|
}
|
||||||
|
|
||||||
func SetStoreSkuBindVendorPrice(storeSkuBind *model.StoreSkuBind, vendorID int, vendorPrice int) {
|
func SetStoreSkuBindVendorPrice(storeSkuBind *model.StoreSkuBind, vendorID int, vendorPrice int) {
|
||||||
switch vendorID {
|
switch vendorID {
|
||||||
case model.VendorIDJD:
|
case model.VendorIDJD:
|
||||||
|
|||||||
@@ -495,13 +495,13 @@ type StoreSkuNamePrice struct {
|
|||||||
|
|
||||||
func (*StoreSkuNamePrice) TableUnique() [][]string {
|
func (*StoreSkuNamePrice) TableUnique() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
[]string{"Name", "NameIDGroup"},
|
[]string{"OutSkuID", "Price", "NameIDGroup"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*StoreSkuNamePrice) TableIndex() [][]string {
|
func (*StoreSkuNamePrice) TableIndex() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
[]string{"Name"},
|
[]string{"OutSkuID"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user