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
8807400c
authored
Jan 11, 2024
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
分类
parent
e81fc24f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
32 deletions
conf/dev/elastic.ini
doc/test/test3.go
pkg/es/es.go
service/goods_service.go
service/optimum_service.go
conf/dev/elastic.ini
View file @
8807400c
;存放es配置
;存放es配置
[es]
[es]
url_es8
=
http://192.168.1.234:9201
url
=
http://192.168.1.237:9200
url
=
http://192.168.1.237:9200
urls
=
http://192.168.1.237:9200,http://192.168.1.237:9200
urls
=
http://192.168.1.237:9200,http://192.168.1.237:9200
index_name
=
future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
index_name
=
future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
...
...
doc/test/test3.go
View file @
8807400c
...
@@ -2,37 +2,19 @@ package main
...
@@ -2,37 +2,19 @@ package main
import
(
import
(
"fmt"
"fmt"
"
encoding/json
"
"
strings
"
"
search_server/model
"
"
github.com/tidwall/gjson
"
)
)
func
main
()
{
func
main
()
{
jsonContent
:=
`{"spu_id":2170358070290851004,"old_goods_id":17003294699,"update_time":1703580702,"cp_time":0,"goods_status":1,"goods_type":1,"supplier_id":5,"goods_name":"NFM21HC105R1C3D","encoded":"","batch_sn":"2310","moq":232,"mpq":1,"stock":3562,"hk_delivery_time":"","cn_delivery_time":"","ladder_price":[{"purchases":232,"price_cn":0,"price_us":0.1377,"cost_price":0},{"purchases":500,"price_cn":0,"price_us":0.1211,"cost_price":0},{"purchases":1000,"price_cn":0,"price_us":0.0961,"cost_price":0},{"purchases":2000,"price_cn":0,"price_us":0.0924,"cost_price":0}],"goods_images":"","canal":"","eccn":"EAR99","multiple":0,"source":2}`
spu_id
:=
gjson
.
Get
(
jsonContent
,
"spu_id"
)
.
String
()
var
LyClearGoodsList
model
.
LyClearGoodsList
fmt
.
Println
(
spu_id
)
LyClearGoodsList
.
GoodsName
=
"LM358"
fmt
.
Println
(
"ddddddddd"
)
ladderPrice
:=
make
([]
*
model
.
TierItem
,
0
)
jsonContent
=
strings
.
Replace
(
jsonContent
,
spu_id
,
"
\"
"
+
spu_id
+
"
\"
"
,
1
)
ladder
:=
model
.
TierItem
{
Purchases
:
1
,
PriceUs
:
0.44
,
PriceCn
:
1.55
,
}
ladderPrice
=
append
(
ladderPrice
,
&
ladder
)
LyClearGoodsList
.
Tiered
=
ladderPrice
var
productList
map
[
string
]
*
model
.
LyClearGoodsList
fmt
.
Println
(
jsonContent
)
productList
=
make
(
map
[
string
]
*
model
.
LyClearGoodsList
,
0
)
productList
[
"595-LM358BIDR"
]
=
&
LyClearGoodsList
//map的遍历
for
k
,
v
:=
range
productList
{
fmt
.
Println
(
k
,
v
)
}
jsonStr
,
err
:=
json
.
Marshal
(
productList
)
if
err
!=
nil
{
return
}
fmt
.
Printf
(
"%s
\n
"
,
jsonStr
)
}
}
\ No newline at end of file
pkg/es/es.go
View file @
8807400c
...
@@ -20,6 +20,20 @@ type HitsResult struct {
...
@@ -20,6 +20,20 @@ type HitsResult struct {
Hits
string
`json:"hits"`
Hits
string
`json:"hits"`
}
}
//新版es8 请求
func
CurlESNew
(
index
string
,
param
string
)
(
result
string
,
err
error
)
{
endpoints
:=
config
.
Get
(
"es.url_es8"
)
.
Strings
(
","
)
//随机获取一个节点进行请求
esUrl
:=
endpoints
[
rand
.
Intn
(
len
(
endpoints
))]
params
:=
req
.
BodyJSON
(
param
)
resp
,
err
:=
req
.
Get
(
esUrl
+
"/"
+
index
+
"/_search"
,
params
)
if
err
!=
nil
{
return
}
result
=
resp
.
String
()
return
}
func
CurlES
(
index
string
,
param
string
)
(
result
string
,
err
error
)
{
func
CurlES
(
index
string
,
param
string
)
(
result
string
,
err
error
)
{
endpoints
:=
config
.
Get
(
"es.urls"
)
.
Strings
(
","
)
endpoints
:=
config
.
Get
(
"es.urls"
)
.
Strings
(
","
)
//随机获取一个节点进行请求
//随机获取一个节点进行请求
...
...
service/goods_service.go
View file @
8807400c
...
@@ -156,8 +156,8 @@ func CurlGoodsInfo(ctx *gin.Context, goodsIdsStr string, params req.Param) (good
...
@@ -156,8 +156,8 @@ func CurlGoodsInfo(ctx *gin.Context, goodsIdsStr string, params req.Param) (good
goods
.
ScmBrandName
=
data
.
Get
(
"scm_brand_name"
)
.
String
()
goods
.
ScmBrandName
=
data
.
Get
(
"scm_brand_name"
)
.
String
()
goods
.
AllowCoupon
=
int
(
data
.
Get
(
"allow_coupon"
)
.
Int
())
goods
.
AllowCoupon
=
int
(
data
.
Get
(
"allow_coupon"
)
.
Int
())
goods
.
UpdateTime
=
int
(
data
.
Get
(
"update_time"
)
.
Int
())
goods
.
UpdateTime
=
int
(
data
.
Get
(
"update_time"
)
.
Int
())
goods
.
ClassId1Name
=
data
.
Get
(
"class_
id1_name
"
)
.
String
()
goods
.
ClassId1Name
=
data
.
Get
(
"class_
name1
"
)
.
String
()
goods
.
CLassId2Name
=
data
.
Get
(
"c
_lass_id2_name
"
)
.
String
()
goods
.
CLassId2Name
=
data
.
Get
(
"c
lass_name2
"
)
.
String
()
goods
.
SpuId
=
data
.
Get
(
"spu_id"
)
.
String
()
goods
.
SpuId
=
data
.
Get
(
"spu_id"
)
.
String
()
goods
.
BatchSn
=
data
.
Get
(
"batch_sn"
)
.
String
()
goods
.
BatchSn
=
data
.
Get
(
"batch_sn"
)
.
String
()
goods
.
Canal
=
data
.
Get
(
"canal"
)
.
String
()
goods
.
Canal
=
data
.
Get
(
"canal"
)
.
String
()
...
...
service/optimum_service.go
View file @
8807400c
...
@@ -87,7 +87,7 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
...
@@ -87,7 +87,7 @@ func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResp
return
return
}
}
//查询es
//查询es
esResult
,
err
:=
es
.
CurlES
(
"goods_optimum"
,
queryString
)
esResult
,
err
:=
es
.
CurlES
New
(
"goods_optimum"
,
queryString
)
if
err
!=
nil
{
if
err
!=
nil
{
results
.
ErrorCode
=
1002
results
.
ErrorCode
=
1002
results
.
ErrorMsg
=
err
.
Error
()
results
.
ErrorMsg
=
err
.
Error
()
...
@@ -194,7 +194,7 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
...
@@ -194,7 +194,7 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
results
.
ErrorMsg
=
err
.
Error
()
results
.
ErrorMsg
=
err
.
Error
()
return
return
}
}
esResult
,
err
:=
es
.
CurlES
(
"goods_optimum"
,
queryString
)
esResult
,
err
:=
es
.
CurlES
New
(
"goods_optimum"
,
queryString
)
if
err
!=
nil
{
if
err
!=
nil
{
results
.
ErrorCode
=
0
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询es没有数据"
results
.
ErrorMsg
=
"查询es没有数据"
...
@@ -219,7 +219,7 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
...
@@ -219,7 +219,7 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
}
}
//判断返回总条数
//判断返回总条数
total
:=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
total
:=
gjson
.
Get
(
esResult
,
"hits.total
.value
"
)
.
Int
()
if
total
==
0
{
if
total
==
0
{
results
.
ErrorCode
=
0
results
.
ErrorCode
=
0
results
.
ErrorMsg
=
"查询没有数据"
results
.
ErrorMsg
=
"查询没有数据"
...
...
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