Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ae00a568
authored
Oct 10, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
tj
parent
60c30781
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
32 deletions
controller/sku_controller.go
service/service_ly.go
service/service_zy.go
controller/sku_controller.go
View file @
ae00a568
...
...
@@ -9,8 +9,7 @@ import (
"sync"
)
const
goods_slice_count
=
10
//每多少个型号id开启一个协程
const
goodsSliceCount
=
10
//每多少个型号id开启一个协程
/*
查询商品详情(自营或者联营)
...
...
@@ -30,67 +29,65 @@ const goods_slice_count = 10 //每多少个型号id开启一个协程
*/
func
Synchronization
(
c
*
gin
.
Context
)
{
common
.
PrintDebugHeader
()
//开启debug调试
common
.
PrintDebugHeader
()
//开启debug调试
zyService
:=
service
.
ZiyingService
{}
//实例化自营查询
lyService
:=
service
.
LyService
{}
//实例化自营查询
lyService
:=
service
.
LyService
{}
//实例化自营查询
//抽取自营 或者联营 goods_id
GoodsIdStr
:=
middleware
.
REQUEST
[
"goods_id"
]
GoodsIdStr
:=
middleware
.
REQUEST
[
"goods_id"
]
if
GoodsIdStr
==
""
{
common
.
Output
(
1001
,
"查询型号ID不得为空"
,
""
)
common
.
Output
(
1001
,
"查询型号ID不得为空"
,
""
)
}
GoodsRes
:=
make
(
map
[
string
]
interface
{},
0
)
//接收算好的数据
goodsIdArr
:=
php2go
.
Explode
(
","
,
GoodsIdStr
)
goodsIdArr
:=
php2go
.
Explode
(
","
,
GoodsIdStr
)
wg
:=
sync
.
WaitGroup
{}
zyGoodsId
:=
make
([]
string
,
0
)
lyGoodsId
:=
make
([]
string
,
0
)
for
_
,
goods_i
d
:=
range
goodsIdArr
{
if
len
(
goods
_i
d
)
<
19
{
//自营
zyGoodsId
=
append
(
zyGoodsId
,
goods_i
d
)
if
len
(
zyGoodsId
)
>=
goods
_slice_c
ount
{
zyGoodsId
:=
make
([]
string
,
0
)
lyGoodsId
:=
make
([]
string
,
0
)
for
_
,
goodsI
d
:=
range
goodsIdArr
{
if
len
(
goods
I
d
)
<
19
{
//自营
zyGoodsId
=
append
(
zyGoodsId
,
goodsI
d
)
if
len
(
zyGoodsId
)
>=
goods
SliceC
ount
{
common
.
PrintDebugHtml
(
"zy增加协程:"
)
common
.
PrintDebugHtml
(
zyGoodsId
)
wg
.
Add
(
1
)
//协程计数一
go
zyService
.
ZyGoodsDetail
(
zyGoodsId
,
&
GoodsRes
,
&
wg
)
wg
.
Add
(
1
)
//协程计数一
go
zyService
.
ZyGoodsDetail
(
zyGoodsId
,
&
GoodsRes
,
&
wg
)
zyGoodsId
=
zyGoodsId
[
:
0
:
0
]
}
}
else
{
//联营
lyGoodsId
=
append
(
lyGoodsId
,
goods_i
d
)
if
len
(
lyGoodsId
)
>=
goods
_slice_c
ount
{
}
}
else
{
//联营
lyGoodsId
=
append
(
lyGoodsId
,
goodsI
d
)
if
len
(
lyGoodsId
)
>=
goods
SliceC
ount
{
common
.
PrintDebugHtml
(
"ly增加协程:"
)
common
.
PrintDebugHtml
(
zyGoodsId
)
wg
.
Add
(
1
)
go
lyService
.
LyGoodsDetail
(
lyGoodsId
,
&
wg
)
go
lyService
.
LyGoodsDetail
(
lyGoodsId
,
&
GoodsRes
,
&
wg
)
lyGoodsId
=
lyGoodsId
[
:
0
:
0
]
}
}
}
if
len
(
zyGoodsId
)
>
0
{
if
len
(
zyGoodsId
)
>
0
{
common
.
PrintDebugHtml
(
"zy增加协程:"
)
common
.
PrintDebugHtml
(
zyGoodsId
)
wg
.
Add
(
1
)
//协程计数一
go
zyService
.
ZyGoodsDetail
(
zyGoodsId
,
&
GoodsRes
,
&
wg
)
wg
.
Add
(
1
)
//协程计数一
go
zyService
.
ZyGoodsDetail
(
zyGoodsId
,
&
GoodsRes
,
&
wg
)
}
if
len
(
lyGoodsId
)
>=
goods_slice_count
{
//if len(lyGoodsId) >= goodsSliceCount {
if
len
(
lyGoodsId
)
>=
0
{
common
.
PrintDebugHtml
(
"ly增加协程:"
)
common
.
PrintDebugHtml
(
zyGoodsId
)
wg
.
Add
(
1
)
go
lyService
.
LyGoodsDetail
(
lyGoodsId
,
&
wg
)
go
lyService
.
LyGoodsDetail
(
lyGoodsId
,
&
GoodsRes
,
&
wg
)
}
wg
.
Wait
()
common
.
Output
(
0
,
"查询成功"
,
GoodsRes
)
common
.
Output
(
0
,
"查询成功"
,
GoodsRes
)
}
service/service_ly.go
View file @
ae00a568
package
service
import
(
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"goods_machining/model"
"goods_machining/pkg/gredis"
"strings"
"sync"
)
type
LyService
struct
{
}
/*
自
营数据详情
联
营数据详情
*/
func
(
qs
*
LyService
)
LyGoodsDetail
(
goodsIds
[]
string
,
wg
*
sync
.
WaitGroup
)
(
results
model
.
LyResponse
)
{
func
(
qs
*
LyService
)
LyGoodsDetail
(
goodsIds
[]
string
,
goodsRes
*
map
[
string
]
interface
{},
wg
*
sync
.
WaitGroup
)
(
results
model
.
LyResponse
)
{
redisConn
:=
gredis
.
Conn
(
"search_r"
)
defer
func
()
{
wg
.
Done
()
redisConn
.
Close
()
}()
//批量获取商品详情
skuArr
:=
gredis
.
HgetPi
(
"search_r"
,
"sku"
,
goodsIds
)
//为了性能着想,这边也先去批量获取spu的信息
spuList
:=
qs
.
getSpuList
(
goodsIds
)
fmt
.
Println
(
spuList
)
for
goodsId
,
info
:=
range
skuArr
{
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
.
Set
(
"packing"
,
""
)
//读取包装字段的缓存
if
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
()
==
7
{
//sku_raw_map哪里写入(成意写的)
packing
,
err
:=
redis
.
String
(
redisConn
.
Do
(
"HGET"
,
"SKU_RAW_MAP"
,
goodsId
))
if
err
==
nil
{
A
.
Set
(
"packing"
,
gjson
.
Get
(
packing
,
"pack"
)
.
String
())
}
}
A
.
Set
(
"goods_id"
,
goodsId
)
//去获取spu的信息
spuInfo
:=
spuList
[
goodsId
]
spuLargeImage
:=
gjson
.
Get
(
spuInfo
,
"images_l"
)
.
String
()
A
.
Set
(
"images_l"
,
spuLargeImage
)
if
spuLargeImage
!=
""
&&
php2go
.
Strlen
(
spuLargeImage
)
<
5
{
A
.
Set
(
"images_l"
,
""
)
}
pdf
:=
gjson
.
Get
(
spuInfo
,
"pdf"
)
.
String
()
A
.
Set
(
"pdf"
,
pdf
)
if
pdf
==
""
||
(
php2go
.
Strlen
(
spuLargeImage
)
<
5
)
{
A
.
Set
(
"pdf"
,
""
)
}
//商品图片不存在用大图代替
goodsImage
:=
gjson
.
Get
(
info
,
"goods_images"
)
.
String
()
A
.
Set
(
"goods_images"
,
goodsImage
)
if
goodsImage
==
""
&&
spuLargeImage
!=
""
{
goodsImage
=
spuLargeImage
A
.
Set
(
"goods_images"
,
spuLargeImage
)
}
//加上是否是rocelec图片的判断,如果是的话,就将图片设置为空
if
strings
.
Contains
(
goodsImage
,
"rocelec"
)
{
A
.
Set
(
"goods_images"
,
""
)
}
goodsName
:=
gjson
.
Get
(
info
,
"goods_name"
)
.
String
()
A
.
Set
(
"goods_name"
,
goodsName
)
if
goodsName
==
""
{
A
.
Set
(
"goods_name"
,
gjson
.
Get
(
spuInfo
,
"spu_name"
))
}
//获取品牌名称
brandId
:=
gjson
.
Get
(
spuInfo
,
"brand_id"
)
.
String
()
brandName
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"HGET"
,
"brand"
,
brandId
))
A
.
Set
(
"brand_name"
,
brandName
)
//todo 条件判断
//获取税务信息
if
true
{
//仅提供价格和库存
}
//(*goodsRes)[goodsId] = A
}
return
}
func
(
qs
*
LyService
)
getSpuList
(
goodsIds
[]
string
)
(
spuList
map
[
string
]
string
)
{
redisConn
:=
gredis
.
Conn
(
"search_r"
)
defer
redisConn
.
Close
()
//批量获取spu详情
spuList
=
gredis
.
HgetPi
(
"search_r"
,
"sku"
,
goodsIds
)
return
}
service/service_zy.go
View file @
ae00a568
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment