|
@@ -2,10 +2,12 @@ package merchant
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
+ stringUtils "eta/eta_mini_ht_api/common/utils/string"
|
|
|
"eta/eta_mini_ht_api/models"
|
|
|
"fmt"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"sort"
|
|
|
+ "strings"
|
|
|
"sync/atomic"
|
|
|
"time"
|
|
|
)
|
|
@@ -141,8 +143,8 @@ func CountProductList(isSignal bool) (total, latestId int64, ids []int) {
|
|
|
}
|
|
|
|
|
|
type MerchantProductIdMap struct {
|
|
|
- Type string
|
|
|
- ProductId string
|
|
|
+ Type string
|
|
|
+ SourceId string
|
|
|
}
|
|
|
|
|
|
func GetProductByProductType() (productIds map[string]string, err error) {
|
|
@@ -152,27 +154,29 @@ func GetProductByProductType() (productIds map[string]string, err error) {
|
|
|
err = db.Raw(sql).Find(&productIdMap).Error
|
|
|
productIds = make(map[string]string, len(productIdMap))
|
|
|
for _, v := range productIdMap {
|
|
|
- productIds[v.Type] = v.ProductId
|
|
|
+ productIds[v.Type] = v.SourceId
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func generateSignalPdSql(idMap map[string][]int) (condition string, pars []interface{}) {
|
|
|
+func generateSignalPdSql(idMap map[string][]int) (condition string) {
|
|
|
for k, v := range idMap {
|
|
|
if condition == "" {
|
|
|
- condition = "(" + fmt.Sprintf("(type =? and source_id in ?)")
|
|
|
+ condition = "(" + fmt.Sprintf("(type ='%s' and source_id in (%s))", k, strings.Join(stringUtils.IntToStringSlice(v), ","))
|
|
|
} else {
|
|
|
- condition = condition + fmt.Sprintf(" or (type =? and source_id in ?)")
|
|
|
+ condition = condition + fmt.Sprintf(" or (type ='%s' and source_id in (%s))", k, strings.Join(stringUtils.IntToStringSlice(v), ","))
|
|
|
}
|
|
|
- pars = append(pars, k, v)
|
|
|
}
|
|
|
condition = condition + ")"
|
|
|
+ if len(idMap) == 1 {
|
|
|
+ condition = condition[1 : len(condition)-1]
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func LatestId() (latestId int64) {
|
|
|
db := models.Main()
|
|
|
- _ = db.Select("max(id)").Where("deleted=?", false).Scan(&latestId).Error
|
|
|
+ _ = db.Model(&MerchantProduct{}).Select("max(id)").Where("deleted=?", false).Scan(&latestId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -183,7 +187,7 @@ type ProductDTO struct {
|
|
|
}
|
|
|
|
|
|
func ProductListBySort(list []ProductDTO, id int64, offset int, size int) (productList []MerchantProduct, err error) {
|
|
|
- var productMap map[string][]int
|
|
|
+ var productMap = make(map[string][]int, len(list))
|
|
|
sort.Slice(list, func(i, j int) bool {
|
|
|
return list[i].Score > list[j].Score
|
|
|
})
|
|
@@ -196,9 +200,10 @@ func ProductListBySort(list []ProductDTO, id int64, offset int, size int) (produ
|
|
|
ids = append(ids, v.SourceId)
|
|
|
productMap[v.SourceType] = ids
|
|
|
}
|
|
|
- sql, pars := generateSignalPdSql(productMap)
|
|
|
+ sql := generateSignalPdSql(productMap)
|
|
|
db := models.Main()
|
|
|
- err = db.Select(detailColumns).Where(fmt.Sprintf("id <= ? and deleted =? and %s order by Field(id,?) desc limit ?,? ", sql), id, false, pars, idSort, offset, size).Find(&productList).Error
|
|
|
+ query := fmt.Sprintf("id <= ? and deleted =? and %s order by Field(id,?) desc limit ?,?", sql)
|
|
|
+ err = db.Select(detailColumns).Where(query, id, false, strings.Join(stringUtils.IntToStringSlice(idSort), ","), offset, size).Find(&productList).Error
|
|
|
return
|
|
|
}
|
|
|
|