aa
This commit is contained in:
@@ -369,7 +369,7 @@ func GetStoresSkusForStore(ctx *jxcontext.Context, storeID int, isFocus, isAct b
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer dao.Commit(db, txDB)
|
||||
if err = dao.GetRows(db, &SkuNames, sql, sqlParams...); err == nil {
|
||||
skuNamesInfo = &dao.StoreSkuNamesInfo{
|
||||
@@ -715,7 +715,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, upcs []str
|
||||
}
|
||||
sqlParamsPage := []interface{}{sqlPageSize, sqlOffset}
|
||||
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
@@ -784,12 +784,12 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, upcs []str
|
||||
}
|
||||
var tmpList []*tGetStoresSkusInfo
|
||||
beginTime := time.Now()
|
||||
if err = dao.GetRows(db, &tmpList, sql, sqlParams...); err != nil {
|
||||
if err = dao.GetRowsTx(txDB, &tmpList, sql, sqlParams...); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, err
|
||||
}
|
||||
if isBySku {
|
||||
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db)
|
||||
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount2(db, txDB)
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
globals.SugarLogger.Debugf("GetStoresSkusNew get result2:%v", time.Now().Sub(beginTime))
|
||||
@@ -1258,7 +1258,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
needSyncIDMap := make(map[int]int)
|
||||
isSyncSkus := false
|
||||
var appCodeList []string
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
@@ -1731,7 +1731,7 @@ func updateStoreSkusSaleWithoutSync(ctx *jxcontext.Context, storeID int, skuBind
|
||||
skuBindSkuInfosMap[v.SkuID] = v
|
||||
}
|
||||
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
@@ -1937,10 +1937,10 @@ func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID int, toStoreIDs []int, co
|
||||
}
|
||||
break
|
||||
}
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db,txDB)
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
@@ -2205,7 +2205,7 @@ func filterStorePriceChange(ctx *jxcontext.Context, storeIDs []int, skuBindInfos
|
||||
globals.SugarLogger.Debug("filterStorePriceChange")
|
||||
if globals.EnablePendingChange {
|
||||
db := dao.GetDB()
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer dao.Rollback(db, txDB)
|
||||
for _, storeID := range storeIDs {
|
||||
for _, skuBindInfo := range skuBindInfos {
|
||||
@@ -2448,7 +2448,7 @@ func GetStoreOpRequests(ctx *jxcontext.Context, fromTime, toTime time.Time, keyw
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
var requestList []*StoreOpRequestInfo
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer dao.Commit(db, txDB)
|
||||
if err = dao.GetRows(db, &requestList, sql, sqlParams...); err == nil {
|
||||
return &model.PagedInfo{
|
||||
@@ -2507,7 +2507,7 @@ func changeStoreOpStatus(ctx *jxcontext.Context, reqIDs []int, status int8, reje
|
||||
return err
|
||||
}
|
||||
db := dao.GetDB()
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer dao.Rollback(db, txDB)
|
||||
for _, reqID := range reqIDs {
|
||||
op := &model.StoreOpRequest{}
|
||||
@@ -2648,7 +2648,7 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
|
||||
}
|
||||
case 2:
|
||||
if len(storeSkuList) > 0 {
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
@@ -3262,7 +3262,7 @@ func WriteToExcelJx(task *tasksch.SeqTask, dataSuccess []DataSuccess, dataFailed
|
||||
|
||||
func CreateOrUpdateStoreSkuNamePriceByExcel(db *dao.DaoDB, ctx *jxcontext.Context, storeSkuNamePriceList []*model.StoreSkuNamePrice, storeSkuNamePriceListOrg []*model.StoreSkuNamePrice) (err error) {
|
||||
storeSkuNamePriceMap := StoreSkuNamePriceList2Map(ctx, storeSkuNamePriceListOrg)
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
@@ -4821,7 +4821,7 @@ func SyncMatterC4ToGy(ctx *jxcontext.Context, isContinueWhenError, isAsync bool)
|
||||
skuNameExt.DeletedAt = utils.DefaultTimeValue
|
||||
skuNameExt.CreatedAt = time.Now()
|
||||
skuNameExt.LastOperator = ctx.GetUserName()
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
@@ -4867,7 +4867,7 @@ func SyncMatterC4ToGy(ctx *jxcontext.Context, isContinueWhenError, isAsync bool)
|
||||
if len(skuNames) > 0 {
|
||||
skuName = skuNames[0]
|
||||
}
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
@@ -5433,7 +5433,7 @@ func DeleteActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, act
|
||||
return 0, fmt.Errorf("当前活动状态:%s,不能进行此操作,或已过期", model.ActStatusName[act.Status])
|
||||
}
|
||||
|
||||
txDB , _ := dao.Begin(db)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
|
||||
@@ -147,6 +147,15 @@ func GetRows(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (e
|
||||
return err
|
||||
}
|
||||
|
||||
func GetRowsTx(txDB orm.TxOrmer, inPtr interface{}, sql string, values ...interface{}) (err error) {
|
||||
if txDB == nil {
|
||||
return
|
||||
}
|
||||
_, err = txDB.Raw(sql, values).QueryRows(inPtr)
|
||||
// _, err = db.Db.Raw(sql, values).QueryRows(inPtr)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetEntity(db *DaoDB, item interface{}, cols ...string) (err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
@@ -225,8 +234,22 @@ func ExecuteSQL(db *DaoDB, sql string, params ...interface{}) (num int64, err er
|
||||
// 此函数要求db在事务中,否则可能导致取得到的是另一个连接的数据
|
||||
func GetLastTotalRowCount(db *DaoDB) int {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
// if err := txDB.Raw("SELECT FOUND_ROWS() ct", nil).QueryRow(countInfo); err == nil {
|
||||
// return countInfo.Ct
|
||||
// }
|
||||
if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||
return countInfo.Ct
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func GetLastTotalRowCount2(db *DaoDB, txDB orm.TxOrmer) int {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
if err := txDB.Raw("SELECT FOUND_ROWS() ct", nil).QueryRow(countInfo); err == nil {
|
||||
return countInfo.Ct
|
||||
}
|
||||
// if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||
// return countInfo.Ct
|
||||
// }
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user