Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_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
d91ee4fe
authored
Feb 02, 2023
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
optimum
parent
d4d72263
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
111 deletions
conf/dev/database.ini
conf/dev/redis.ini
service/optimum_service.go
conf/dev/database.ini
View file @
d91ee4fe
...
...
@@ -4,7 +4,7 @@ mode = debug
[spu]
user_name
=
spu
password
=
spu
host
=
192.168.1.23
8
host
=
192.168.1.23
4
database
=
liexin_spu
table_prefix
=
lie_
type
=
mysql
...
...
conf/dev/redis.ini
View file @
d91ee4fe
;redis连接信息
[default_redis_read]
host
=
192.168.1.23
4
:6379
host
=
192.168.1.23
5
:6379
password
=
icDb29mLy2s
max_idle
=
500
max_active
=
500
idle_timeout
=
20
[default_redis_write]
host
=
192.168.1.23
4
:6379
host
=
192.168.1.23
5
:6379
password
=
icDb29mLy2s
max_idle
=
500
max_active
=
500
idle_timeout
=
20
[api_redis]
host
=
192.168.1.23
4
:6379
host
=
192.168.1.23
5
:6379
password
=
icDb29mLy2s
max_idle
=
50
max_active
=
100
...
...
service/optimum_service.go
View file @
d91ee4fe
...
...
@@ -21,12 +21,12 @@ import (
type
OptimumService
struct
{
}
var
REQUEST
map
[
string
]
string
//接收所有参数
var
REQUEST
map
[
string
]
string
//接收所有参数
var
REQUEST_ATTR
map
[
string
][]
string
//接收属性搜索
/*
整理接收数组参数
*/
func
(
qs
*
OptimumService
)
getQueryAttr
(
ctx
*
gin
.
Context
)
{
*/
func
(
qs
*
OptimumService
)
getQueryAttr
(
ctx
*
gin
.
Context
)
{
//接收参数,接收参数搜索
REQUEST
=
make
(
map
[
string
]
string
)
REQUEST_ATTR
=
make
(
map
[
string
][]
string
)
...
...
@@ -37,16 +37,16 @@ func (qs *OptimumService) getQueryAttr(ctx *gin.Context) {
ev
:=
REQUEST
[
"attr"
]
if
ev
!=
""
{
//存在属性搜索
slice1
:=
php2go
.
Explode
(
"^"
,
ev
)
;
slice1
:=
php2go
.
Explode
(
"^"
,
ev
)
for
_
,
proa
:=
range
slice1
{
prob
:=
php2go
.
Explode
(
"_"
,
proa
)
;
attr_name_id
:=
prob
[
0
]
;
//属性名称
prob
:=
php2go
.
Explode
(
"_"
,
proa
)
attr_name_id
:=
prob
[
0
]
//属性名称
attr_value_ids
:=
php2go
.
Explode
(
"||"
,
prob
[
1
])
REQUEST_ATTR
[
attr_name_id
]
=
attr_value_ids
}
}
common
.
PrintDebugHtml
(
ctx
,
REQUEST
)
common
.
PrintDebugHtml
(
ctx
,
REQUEST_ATTR
)
common
.
PrintDebugHtml
(
ctx
,
REQUEST
)
common
.
PrintDebugHtml
(
ctx
,
REQUEST_ATTR
)
}
/*
...
...
@@ -80,86 +80,92 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
qs
.
getQueryAttr
(
ctx
)
//获取查询条件
queryString
,
err
:=
query
.
GetOptimumAttrQuery
(
ctx
,
&
REQUEST_ATTR
,
1
)
queryString
,
err
:=
query
.
GetOptimumAttrQuery
(
ctx
,
&
REQUEST_ATTR
,
1
)
if
err
!=
nil
{
results
.
ErrorCode
=
1001
;
results
.
ErrorCode
=
1001
results
.
ErrorMsg
=
err
.
Error
()
return
}
//查询es
esResult
,
err
:=
es
.
CurlES
(
"goods_optimum"
,
queryString
)
if
err
!=
nil
{
results
.
ErrorCode
=
1002
;
results
.
ErrorCode
=
1002
results
.
ErrorMsg
=
err
.
Error
()
return
}
common
.
PrintDebugHtml
(
ctx
,
esResult
)
common
.
PrintDebugHtml
(
ctx
,
esResult
)
//判断返回总条数
total
:=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
if
total
==
0
{
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询没有数据"
return
}
//拼接返回数据
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
results
.
ErrorCode
=
0
;
results
.
ErrorMsg
=
"查询成功"
;
A
.
Set
(
"total"
,
total
)
//查询总条数
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询成功"
A
.
Set
(
"total"
,
total
)
//查询总条数
aggs
:=
orderedmap
.
New
()
//拼接aggs
aggs
:=
orderedmap
.
New
()
//拼接aggs
aggregations
:=
gjson
.
Get
(
esResult
,
"aggregations"
)
.
Map
()
aggregations
:=
gjson
.
Get
(
esResult
,
"aggregations"
)
.
Map
()
redisConn
:=
gredis
.
Conn
(
"search_r"
)
//brand_id,存在品牌统计数据
brandIdGroup
:=
gjson
.
Get
(
aggregations
[
"brand_id"
]
.
String
(),
"buckets"
)
.
Array
()
if
len
(
aggregations
)
>
0
{
brandArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
brandIdGroup
{
brandIdGroup
:=
gjson
.
Get
(
aggregations
[
"brand_id"
]
.
String
(),
"buckets"
)
.
Array
()
if
len
(
aggregations
)
>
0
{
brandArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
brandIdGroup
{
valueMap
:=
v
.
Map
()
brandId
:=
valueMap
[
"key"
]
.
String
()
brandName
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"brand"
,
brandId
))
brandId
:=
valueMap
[
"key"
]
.
String
()
//todo 标准品牌
brand_name_json
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"standard_brand"
,
brandId
))
brandName
:=
gjson
.
Get
(
brand_name_json
,
"brand_name"
)
.
String
()
if
brandName
==
""
{
brandName
,
_
=
redis
.
String
(
redisConn
.
Do
(
"Hget"
,
"brand"
,
brandId
))
}
ischeck
:=
"0"
//是否选中
if
php2go
.
InArray
(
brandId
,
REQUEST_ATTR
[
"brand"
])
{
ischeck
:=
"0"
//是否选中
if
php2go
.
InArray
(
brandId
,
REQUEST_ATTR
[
"brand"
])
{
ischeck
=
"1"
}
brandArr
=
append
(
brandArr
,
brandId
+
"€"
+
brandName
+
"€"
+
ischeck
)
brandArr
=
append
(
brandArr
,
brandId
+
"€"
+
brandName
+
"€"
+
ischeck
)
}
aggs
.
Set
(
"brand€品牌"
,
brandArr
)
aggs
.
Set
(
"brand€品牌"
,
brandArr
)
}
//拼接属性统计
attrsAttrNameBuckets
:=
gjson
.
Get
(
aggregations
[
"attrs"
]
.
String
(),
"attr_name.buckets"
)
.
Array
()
if
len
(
attrsAttrNameBuckets
)
>
0
{
attrsAttrNameBuckets
:=
gjson
.
Get
(
aggregations
[
"attrs"
]
.
String
(),
"attr_name.buckets"
)
.
Array
()
if
len
(
attrsAttrNameBuckets
)
>
0
{
for
_
,
vbuckets
:=
range
attrsAttrNameBuckets
{
for
_
,
vbuckets
:=
range
attrsAttrNameBuckets
{
vbucketsMap
:=
vbuckets
.
Map
()
attr_name
:=
vbucketsMap
[
"key"
]
.
String
()
//属性名称: 电容
attr_name_id
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_by_val"
)
.
String
(),
attr_name
))
//属性id
attr_name
:=
vbucketsMap
[
"key"
]
.
String
()
//属性名称: 电容
attr_name_id
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_by_val"
)
.
String
(),
attr_name
))
//属性id
attrValueBuckets
:=
gjson
.
Get
(
vbuckets
.
String
(),
"attr_value.buckets"
)
.
Array
()
//属性值数组: 1V
attrValueBuckets
:=
gjson
.
Get
(
vbuckets
.
String
(),
"attr_value.buckets"
)
.
Array
()
//属性值数组: 1V
attrValueArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
attrValueBuckets
{
attrValueArr
:=
make
([]
string
,
0
)
for
_
,
v
:=
range
attrValueBuckets
{
valueMap
:=
v
.
Map
()
attr_value_name
:=
valueMap
[
"key"
]
.
String
()
//属性值:1V
attr_value_id
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_value_by_val"
)
.
String
(),
attr_value_name
))
//属性值id
attr_value_name
:=
valueMap
[
"key"
]
.
String
()
//属性值:1V
attr_value_id
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_value_by_val"
)
.
String
(),
attr_value_name
))
//属性值id
ischeck
:=
"0"
//是否选中redigo
if
php2go
.
InArray
(
attr_value_id
,
REQUEST_ATTR
[
attr_name_id
])
{
ischeck
:=
"0"
//是否选中redigo
if
php2go
.
InArray
(
attr_value_id
,
REQUEST_ATTR
[
attr_name_id
])
{
ischeck
=
"1"
}
attrValueArr
=
append
(
attrValueArr
,
attr_value_id
+
"€"
+
attr_value_name
+
"€"
+
ischeck
)
attrValueArr
=
append
(
attrValueArr
,
attr_value_id
+
"€"
+
attr_value_name
+
"€"
+
ischeck
)
}
aggs
.
Set
(
attr_name_id
+
"€"
+
attr_name
,
attrValueArr
)
aggs
.
Set
(
attr_name_id
+
"€"
+
attr_name
,
attrValueArr
)
}
}
A
.
Set
(
"aggs"
,
aggs
)
A
.
Set
(
"aggs"
,
aggs
)
results
.
Data
=
A
return
...
...
@@ -167,44 +173,43 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
/*
返回供应商详情
*/
*/
func
(
qs
*
OptimumService
)
GetOptimumAttrInfo
(
ctx
*
gin
.
Context
)
(
results
model
.
LyResponse
)
{
//修复分页数据
if
gconv
.
Int64
(
ctx
.
Request
.
FormValue
(
"page"
))
*
gconv
.
Int64
(
ctx
.
Request
.
FormValue
(
"page_size"
))
>
10000
{
results
.
ErrorCode
=
0
;
if
gconv
.
Int64
(
ctx
.
Request
.
FormValue
(
"page"
))
*
gconv
.
Int64
(
ctx
.
Request
.
FormValue
(
"page_size"
))
>
10000
{
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询es没有数据,分页查询不得超出10000条"
return
}
//索引字典
qs
.
getQueryAttr
(
ctx
)
//获取查询条件
queryString
,
err
:=
query
.
GetOptimumAttrQuery
(
ctx
,
&
REQUEST_ATTR
,
2
)
queryString
,
err
:=
query
.
GetOptimumAttrQuery
(
ctx
,
&
REQUEST_ATTR
,
2
)
if
err
!=
nil
{
results
.
ErrorCode
=
1001
;
results
.
ErrorCode
=
1001
results
.
ErrorMsg
=
err
.
Error
()
return
}
esResult
,
err
:=
es
.
CurlES
(
"goods_optimum"
,
queryString
)
if
err
!=
nil
{
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询es没有数据"
return
}
common
.
PrintDebugHtml
(
ctx
,
esResult
)
common
.
PrintDebugHtml
(
ctx
,
esResult
)
goodsIds
:=
make
([]
string
,
0
)
//goods_id
goodsIds
:=
make
([]
string
,
0
)
//goods_id
attrs
:=
make
(
map
[
string
][]
map
[
string
]
string
)
//属性
gjArray
:=
gjson
.
Get
(
esResult
,
"hits.hits.#._source"
)
.
Array
()
for
_
,
item
:=
range
gjArray
{
goods_id
:=
item
.
Get
(
"goods_id"
)
.
String
()
goodsIds
=
append
(
goodsIds
,
goods_id
)
temp
:=
make
([]
map
[
string
]
string
,
0
)
for
_
,
attr
:=
range
item
.
Get
(
"attrs"
)
.
Array
()
{
temp
=
append
(
temp
,
map
[
string
]
string
{
"attr_name"
:
attr
.
Get
(
"attr_name"
)
.
String
(),
"attr_value"
:
attr
.
Get
(
"attr_value"
)
.
String
(),
temp
:=
make
([]
map
[
string
]
string
,
0
)
for
_
,
attr
:=
range
item
.
Get
(
"attrs"
)
.
Array
()
{
temp
=
append
(
temp
,
map
[
string
]
string
{
"attr_name"
:
attr
.
Get
(
"attr_name"
)
.
String
(),
"attr_value"
:
attr
.
Get
(
"attr_value"
)
.
String
(),
})
}
attrs
[
goods_id
]
=
temp
...
...
@@ -213,39 +218,38 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
//判断返回总条数
total
:=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
if
total
==
0
{
results
.
ErrorCode
=
0
;
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询没有数据"
return
}
//拼接返回数据
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
results
.
ErrorCode
=
0
;
results
.
ErrorMsg
=
"查询成功"
;
page
:=
PageClear
(
ctx
,
total
);
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询成功"
page
:=
PageClear
(
ctx
,
total
)
page
[
"took"
]
=
gjson
.
Get
(
esResult
,
"took"
)
.
Int
()
A
.
Set
(
"page"
,
page
)
//分页信息
A
.
Set
(
"page"
,
page
)
//分页信息
//aggs := orderedmap.New() //拼接aggs
common
.
PrintDebugHtml
(
ctx
,
goodsIds
)
common
.
PrintDebugHtml
(
ctx
,
goodsIds
)
//组装商品详情
endArr
:=
make
([]
model
.
DullGoodsData
,
0
)
goodsList
,
_
:=
GetGoodsInfo
(
ctx
,
goodsIds
)
for
_
,
v
:=
range
goodsList
{
endArr
:=
make
([]
model
.
DullGoodsData
,
0
)
goodsList
,
_
:=
GetGoodsInfo
(
ctx
,
goodsIds
)
for
_
,
v
:=
range
goodsList
{
GoodsUrl
:=
""
GoodsUrl
:=
""
BrandUrl
:=
""
referer
:=
ctx
.
GetHeader
(
"Referer"
)
if
referer
!=
""
{
dome
:=
strings
.
Split
(
referer
,
".com"
)
if
len
(
dome
)
>
0
{
if
referer
!=
""
{
dome
:=
strings
.
Split
(
referer
,
".com"
)
if
len
(
dome
)
>
0
{
if
v
.
SupplierName
==
"猎芯自营"
{
GoodsUrl
=
dome
[
0
]
+
".com/item/"
+
v
.
GoodsId
+
".html"
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
v
.
BrandId
)
+
".html"
}
else
{
GoodsUrl
=
dome
[
0
]
+
".com/goods_"
+
v
.
GoodsId
+
".html"
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
v
.
BrandId
)
+
".html"
GoodsUrl
=
dome
[
0
]
+
".com/item/"
+
v
.
GoodsId
+
".html"
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
v
.
BrandId
)
+
".html"
}
else
{
GoodsUrl
=
dome
[
0
]
+
".com/goods_"
+
v
.
GoodsId
+
".html"
BrandUrl
=
dome
[
0
]
+
".com/v3/brand/list/"
+
strconv
.
Itoa
(
v
.
BrandId
)
+
".html"
}
}
}
...
...
@@ -264,57 +268,57 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
v
.
MplStr
=
common
.
NumberToHtml
(
v
.
Mpl
)
MultipleStr
:=
common
.
NumberToHtml
(
Multiple
)
endArr
=
append
(
endArr
,
model
.
DullGoodsData
{
ApiGoods
:
v
,
GoodsUrl
:
GoodsUrl
,
BrandUrl
:
BrandUrl
,
Attrs
:
attrs
[
v
.
GoodsId
],
MultipleStr
:
MultipleStr
,
endArr
=
append
(
endArr
,
model
.
DullGoodsData
{
ApiGoods
:
v
,
GoodsUrl
:
GoodsUrl
,
BrandUrl
:
BrandUrl
,
Attrs
:
attrs
[
v
.
GoodsId
],
MultipleStr
:
MultipleStr
,
})
}
A
.
Set
(
"goods_lists"
,
endArr
)
results
.
Data
=
A
;
A
.
Set
(
"goods_lists"
,
endArr
)
results
.
Data
=
A
return
}
//處理分頁信息
func
PageClear
(
ctx
*
gin
.
Context
,
total
int64
)
map
[
string
]
interface
{}
{
func
PageClear
(
ctx
*
gin
.
Context
,
total
int64
)
map
[
string
]
interface
{}
{
page_size
:=
ctx
.
Request
.
FormValue
(
"page_size"
)
if
page_size
==
""
{
page_size
=
"10"
;
page_size
=
"10"
}
totalPage
:=
math
.
Ceil
(
float64
(
total
)
/
common
.
MyFloat64
(
page_size
))
totalPage
:=
math
.
Ceil
(
float64
(
total
)
/
common
.
MyFloat64
(
page_size
))
if
total
>
10000
{
total
=
10000
}
page
:=
make
(
map
[
string
]
interface
{},
0
)
if
totalPage
>
1
{
page
:=
make
(
map
[
string
]
interface
{},
0
)
if
totalPage
>
1
{
p
:=
ctx
.
Request
.
FormValue
(
"page"
)
if
p
==
""
{
if
p
==
""
{
p
=
"1"
}
//如果是自营同步输出
//自定義分頁
page
[
"orgin_search"
]
=
REQUEST
page
[
"total"
]
=
strconv
.
FormatInt
(
total
,
10
)
page
[
"total"
]
=
strconv
.
FormatInt
(
total
,
10
)
page
[
"current_page"
]
=
p
page
[
"offset"
]
=
page_size
if
total
==
10000
{
page
[
"total_page"
]
=
math
.
Ceil
(
float64
(
total
)
/
common
.
MyFloat64
(
page_size
))
}
else
{
page
[
"total_page"
]
=
strconv
.
FormatInt
(
int64
(
totalPage
),
10
)
page
[
"total_page"
]
=
math
.
Ceil
(
float64
(
total
)
/
common
.
MyFloat64
(
page_size
))
}
else
{
page
[
"total_page"
]
=
strconv
.
FormatInt
(
int64
(
totalPage
),
10
)
}
pageData
:=
make
(
map
[
int
]
int
,
0
)
pageData
:=
make
(
map
[
int
]
int
,
0
)
pInt
:=
int
(
1
)
var
err
error
pInt
,
err
=
strconv
.
Atoi
(
p
)
if
err
!=
nil
{
pInt
=
int
(
1
)
if
err
!=
nil
{
pInt
=
int
(
1
)
}
if
pInt
>
1000
{
...
...
@@ -322,19 +326,19 @@ func PageClear(ctx *gin.Context,total int64) map[string]interface{}{
}
checkPage
:=
gconv
.
Int
(
page
[
"total_page"
])
if
pInt
>=
checkPage
{
for
i
:=
pInt
-
10
;
i
<=
pInt
;
i
++
{
for
i
:=
pInt
-
10
;
i
<=
pInt
;
i
++
{
//原始查询参数拼接
pageData
[
i
]
=
i
}
}
else
{
}
else
{
pageNum
:=
0
for
i
:=
1
;
i
<=
checkPage
;
i
++
{
for
i
:=
1
;
i
<=
checkPage
;
i
++
{
if
pageNum
==
10
{
break
}
if
pInt
>
6
&&
pInt
<=
checkPage
{
if
pInt
>
6
&&
pInt
<=
checkPage
{
//大于10页只获取中间10页
if
i
<
pInt
-
5
||
i
>
pInt
+
5
{
if
i
<
pInt
-
5
||
i
>
pInt
+
5
{
continue
}
}
...
...
@@ -343,10 +347,10 @@ func PageClear(ctx *gin.Context,total int64) map[string]interface{}{
}
}
page
[
"page_data"
]
=
common
.
MapSort
(
pageData
)
}
else
{
}
else
{
page
[
"total"
]
=
total
page
[
"total_page"
]
=
totalPage
page
[
"page_data"
]
=
""
}
return
page
}
\ No newline at end of file
}
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