Commit 7f202186 by huangchengyi

1.0

parent abbed5e0
......@@ -2,24 +2,28 @@ package main
import (
"fmt"
"github.com/syyongx/php2go"
"sync"
)
var wg sync.WaitGroup
func main() {
userCount := 10000
userCount := 1
ch := make(chan bool, 2)
for i := 0; i < userCount; i++ {
php2go.Time()
wg.Add(1)
//fmt.Println(i)
ch <- true
//fmt.Println("ddd")
go send(ch, i)
}
wg.Wait()
//time.Sleep(time.Second)
}
func send(ch chan bool, i int) {
defer wg.Done()
//time.Sleep(time.Second*i)
fmt.Println(php2go.Time())
fmt.Printf("go func: %d\n", i)
fmt.Println("dddd",i)
//fmt.Printf("go func: %d\n", i)
<- ch
}
......@@ -10,6 +10,7 @@ import (
"search_server/model"
"search_server/pkg/common"
"strings"
"sync"
"time"
)
......@@ -62,7 +63,7 @@ const SourceSkuPriceUrl = "https://catalog.sourcengine.com/api/parts/%s/offers/s
请求外链
但是价格和库存有很多条记录,我们过滤掉交期大于14天的期货之后,找一条库存大于0,价格最便宜的一条记录作为这个SKU的价格和库存
*/
*/
func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
if *goodsName == "" {
return nil
......@@ -84,14 +85,17 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
//协程并发请求
//接收通道所有的值
A := orderedmap.New()
ch := make(chan bool,1)
wg := sync.WaitGroup{} //协程等待
ch := make(chan bool,1) //管道
p := 0;
for _,a := range skuRsults {
goods_sn := a.Get("sku").String() //goods_sn
goods_name := a.Get("mpn").String() //型号
brand_name := a.Get("manufacturer").String() //品牌
goods_sn := a.Get("sku").String() //goods_sn
goods_name := a.Get("mpn").String() //型号
brand_name := a.Get("manufacturer").String() //品牌
desc := a.Get("description").String() //描述
wg.Add(1)
ch <- true
go func() {
B := orderedmap.New()
......@@ -99,7 +103,7 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
B.Set("goods_name",goods_name)
B.Set("brand_name",brand_name)
B.Set("desc",desc)
flag := GetSourceInfo(ctx,B)
flag := GetSourceInfo(ctx,B,&wg)
//res,_ := json.Marshal(A)
if flag {
A.Set(goods_sn,B)
......@@ -109,27 +113,14 @@ func OutLinkSource(ctx *gin.Context,goodsName *string) *orderedmap.OrderedMap {
p ++;
}
wg.Wait()
//接收通道所有的值
//A := orderedmap.New();
//for i := 0; i < p; i++ {
// select {
// case x := <-ch:
// if x == nil {
// continue
// }
// goods_sn,_ := x.Get("goods_sn")
// A.Set(gconv.String(goods_sn),x)
// case <- time.After(time.Second *2):
// fmt.Println("超时退出等待")
// }
//}
//allRes,_ := json.Marshal(A)
return A;
}
//请求价格和库存
func GetSourceInfo(ctx *gin.Context,B *orderedmap.OrderedMap) bool {
func GetSourceInfo(ctx *gin.Context,B *orderedmap.OrderedMap,wg *sync.WaitGroup) bool {
defer wg.Done()
goods_sn,_ := B.Get("goods_sn")
skuInfo := GetSourceGineData(ctx,fmt.Sprintf(SourceSkuPriceUrl,goods_sn))
......@@ -148,7 +139,7 @@ func GetSourceInfo(ctx *gin.Context,B *orderedmap.OrderedMap) bool {
B.Set("goods_img","")
B.Set("cat","")
//todo 确定: 分类 , 来源网站sku的url ,图片路径 这三个字段留空,然后价格取: 梯度最后一个价格判断最低 && 库存大于0 && 交期<14 天
//todo 确定: 分类 , 来源网站sku的url ,图片路径 这三个字段留空,然后价格取: 梯度最后一个价格判断最低 && 库存大于0 && 交期<14 天
var LowerPrice float64 = 0 //最低价格
flag := false;
for _, goods := range priceGoodsList {
......@@ -199,7 +190,7 @@ func GetSourceInfo(ctx *gin.Context,B *orderedmap.OrderedMap) bool {
LowerPrice = apiLowerPrice;
}else if LowerPrice < apiLowerPrice { //不是最低价格,跳过
common.PrintDebugHtml(ctx,"不是最低价格跳过")
continue;
continue;
}
//写入数据
mpq := goods.Get("mpq").Int()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment