根据excel刷新京西价

This commit is contained in:
苏尹岚
2019-12-10 17:20:49 +08:00
parent 04ab485bd7
commit ed67833601
3 changed files with 77 additions and 3 deletions

View File

@@ -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))

View File

@@ -1050,6 +1050,22 @@ func RefershStoreSkusMidPrice(db *DaoDB, storeIDs []int) (count int64, err error
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) {
switch vendorID {
case model.VendorIDJD:

View File

@@ -495,13 +495,13 @@ type StoreSkuNamePrice struct {
func (*StoreSkuNamePrice) TableUnique() [][]string {
return [][]string{
[]string{"Name", "NameIDGroup"},
[]string{"OutSkuID", "Price", "NameIDGroup"},
}
}
func (*StoreSkuNamePrice) TableIndex() [][]string {
return [][]string{
[]string{"Name"},
[]string{"OutSkuID"},
}
}