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
644a3d90
authored
Jul 15, 2020
by
孙龙
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'dev' of
http://119.23.72.7/mushishixian/search_server
into dev
parents
ad35df08
d2747670
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
49 deletions
cmd/test1.go
pkg/es/es.go
service/common_ly_service.go
service/mouser_service.go
cmd/test1.go
View file @
644a3d90
...
...
@@ -3,10 +3,8 @@ package main
import
(
"flag"
"os"
"fmt"
"search_server/boot"
"search_server/pkg/gredis"
"search_server/service"
"search_server/pkg/es"
)
func
main
()
{
...
...
@@ -26,16 +24,21 @@ func main() {
//fmt.Println(flag)
//os.Exit(1)
redisConn
:=
gredis
.
Conn
(
"search_r"
)
defer
redisConn
.
Close
()
attrName
,
err
:=
gredis
.
String
(
redisConn
.
Do
(
"GET"
,
"hcy1"
))
fmt
.
Println
(
err
)
fmt
.
Println
(
attrName
)
//
redisConn := gredis.Conn("search_r")
//
defer redisConn.Close()
//
attrName, err := gredis.String(redisConn.Do("GET", "hcy1"))
//
//
fmt.Println(err)
//
fmt.Println(attrName)
//os.Exit(1)
dd
:=
service
.
OutLink
(
"LM358"
,
"-1"
)
print
(
"niin"
)
print
(
dd
)
//dd := service.OutLink("LM358","-1")
result
,
err
:=
es
.
BulkES
(
`{ "index":{"_index":"hcy1","_type":"goods","_id":"8888888"} }
{ "name":"john doe","age":25 }
{ "index":{"_index":"hcy1","_type":"goods","_id":"9999999"} }
{ "name":"mary smith","age":32 }`
)
println
(
result
,
err
)
os
.
Exit
(
1
)
}
...
...
pkg/es/es.go
View file @
644a3d90
...
...
@@ -31,3 +31,29 @@ func CurlES(index string, param string) (result string, err error) {
result
=
resp
.
String
()
return
}
/*
批量插入 或者 更新 es
POST /_bulk
{ "index":{"_index":"hcy1","_type":"goods","_id":"333333"} }
{ "name":"john doe","age":25 }
{ "index":{"_index":"hcy1","_type":"goods","_id":"6666"} }
{ "name":"mary smith","age":32 }
eg:
es.BulkES(`{"index":{"_index":"hcy1","_type":"goods","_id":"8888888"} }
{ "name":"john doe","age":25 }
{ "index":{"_index":"hcy1","_type":"goods","_id":"9999999"} }
{ "name":"mary smith","age":32 }`)
*/
func
BulkES
(
param
string
)
(
result
string
,
err
error
)
{
endpoints
:=
config
.
Get
(
"es.urls"
)
.
Strings
(
","
)
esUrl
:=
endpoints
[
rand
.
Intn
(
len
(
endpoints
))]
//随机获取一个节点进行请求
params
:=
req
.
BodyJSON
(
param
)
resp
,
err
:=
req
.
Post
(
esUrl
+
"/_bulk"
,
params
)
if
err
!=
nil
{
return
}
result
=
resp
.
String
()
return
}
\ No newline at end of file
service/common_ly_service.go
View file @
644a3d90
package
service
/*
等同于 php.search_server.middleBaseController
联营请求外链后 更新或者新增到平台 (es,redis,rabmq)
*/
import
(
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
...
...
@@ -19,14 +22,8 @@ type CommonLyService struct {
supplierId
int64
//调用当前方法的供应商ID
supplierName
string
//调用当前方法的供应商名称
skuEsUpdataList
[]
map
[
string
]
interface
{}
//组装批量更新es数据
SKU_UNIQUE_JUDGE
string
//
SPU_UNIQUE_JUDGE
string
//
BRAND_NAME_ALL
string
//
SUPPLIER_BRAND_ALL
string
//
BRAND
string
//
SKU
string
//
SPU
string
SKU_RAW_MAP
string
spuId
string
//spuId
skuId
string
//skuId
}
//初始化类
...
...
@@ -40,15 +37,7 @@ func (t *CommonLyService) LyServerRun(){
"tme"
:
3600
,
"buerklin"
:
3600
,
}
//用到的redis键值
CommonLyService
.
SKU_UNIQUE_JUDGE
=
config
.
Get
(
"redis_all.SKU_UNIQUE_JUDGE"
)
.
String
()
//
CommonLyService
.
SPU_UNIQUE_JUDGE
=
config
.
Get
(
"redis_all.SPU_UNIQUE_JUDGE"
)
.
String
()
//
CommonLyService
.
BRAND_NAME_ALL
=
config
.
Get
(
"redis_all.BRAND_NAME_ALL"
)
.
String
()
//
CommonLyService
.
SUPPLIER_BRAND_ALL
=
config
.
Get
(
"redis_all.SUPPLIER_BRAND_ALL"
)
.
String
()
//
CommonLyService
.
BRAND
=
config
.
Get
(
"redis_all.BRAND"
)
.
String
()
//
CommonLyService
.
SKU
=
config
.
Get
(
"redis_all.SKU"
)
.
String
()
//
CommonLyService
.
SPU
=
config
.
Get
(
"redis_all.SPU"
)
.
String
()
CommonLyService
.
SKU_RAW_MAP
=
config
.
Get
(
"redis_all.SKU_RAW_MAP"
)
.
String
()
}
/*
...
...
@@ -71,7 +60,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
for
goods_sn
,
info
:=
range
goodsList
{
snSku
:=
php2go
.
Md5
(
strings
.
ToLower
(
goods_sn
))
skuId
,
_
:=
gredis
.
String
(
redisRead
.
Do
(
"HGET"
,
t
.
SKU_UNIQUE_JUDGE
,
snSku
))
//查询唯一值,反查sku_id
skuId
,
_
:=
gredis
.
String
(
redisRead
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.SKU_UNIQUE_JUDGE"
)
.
String
()
,
snSku
))
//查询唯一值,反查sku_id
var
sku_flag
bool
=
false
;
//是否新增或者更新db+redis,为true则新增
if
skuId
==
""
{
//为空,先创建sku
...
...
@@ -102,7 +91,7 @@ func (t *CommonLyService) writeSkuInfo(skuInfo *model.LyClearGoodsList,skuId str
defer
redisWrite
.
Close
()
spuKey
:=
common
.
GetKey
(
skuInfo
.
GoodsName
+
"_"
+
skuInfo
.
BrandName
)
spuId
,
_
:=
gredis
.
String
(
redisWrite
.
Do
(
"HGET"
,
t
.
SKU_UNIQUE_JUDGE
,
spuKey
))
spuId
,
_
:=
gredis
.
String
(
redisWrite
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.SKU_UNIQUE_JUDGE"
)
.
String
()
,
spuKey
))
if
spuId
==
""
{
//不存在spu,创建新的spu
spuId
=
t
.
writeSpuInfo
(
skuInfo
)
}
...
...
@@ -115,9 +104,9 @@ func (t *CommonLyService) writeSkuInfo(skuInfo *model.LyClearGoodsList,skuId str
SpuId
:
spuId
,
Encoded
:
""
,
Moq
:
skuInfo
.
Moq
,
Mpq
:
skuInfo
.
Increment
,
OldGoodsId
:
0
,
GoodsType
:
1
,
Mpq
:
skuInfo
.
Increment
,
OldGoodsId
:
0
,
GoodsType
:
1
,
GoodsStatus
:
1
,
BatchSn
:
""
,
Stock
:
skuInfo
.
Stock
,
...
...
@@ -134,11 +123,11 @@ func (t *CommonLyService) writeSkuInfo(skuInfo *model.LyClearGoodsList,skuId str
redisWrite
.
Do
(
"HSET"
,
"sku"
,
spuId
,
jsonStr
)
skuKey
:=
common
.
GetKey
(
skuInfo
.
GoodsSn
+
"_"
+
strconv
.
FormatInt
(
t
.
supplierId
,
10
))
redisWrite
.
Do
(
"HSET"
,
t
.
SKU_UNIQUE_JUDGE
,
skuKey
,
skuId
)
redisWrite
.
Do
(
"HSET"
,
config
.
Get
(
"redis_all.SKU_UNIQUE_JUDGE"
)
.
String
()
,
skuKey
,
skuId
)
//todo 如果是digikey新增,需要插入原始映射表
if
t
.
supplierId
==
7
{
//redisWrite.Do("HSET",SKU_RAW_MAP
,skuKey,skuId)
redisWrite
.
Do
(
"HSET"
,
config
.
Get
(
"redis_all.SKU_RAW_MAP"
)
.
String
()
,
skuKey
,
skuId
)
}
}
...
...
@@ -151,9 +140,9 @@ func (t *CommonLyService) writeSpuInfo(skuInfo *model.LyClearGoodsList) string {
defer
redisWrite
.
Close
()
brand_key
:=
common
.
GetKey
(
strings
.
ToLower
(
skuInfo
.
BrandName
))
brandId
,
_
:=
redis
.
Int64
(
redisWrite
.
Do
(
"HGET"
,
t
.
BRAND_NAME_ALL
,
brand_key
))
brandId
,
_
:=
redis
.
Int64
(
redisWrite
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.BRAND_NAME_ALL"
)
.
String
()
,
brand_key
))
if
brandId
==
0
{
brandId
,
_
=
redis
.
Int64
(
redisWrite
.
Do
(
"HGET"
,
t
.
SUPPLIER_BRAND_ALL
,
brand_key
))
brandId
,
_
=
redis
.
Int64
(
redisWrite
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.SUPPLIER_BRAND_ALL"
)
.
String
()
,
brand_key
))
if
brandId
==
0
{
brandId
=
t
.
writeBrandInfo
(
skuInfo
)
}
...
...
@@ -178,7 +167,7 @@ func (t *CommonLyService) writeSpuInfo(skuInfo *model.LyClearGoodsList) string {
redisWrite
.
Do
(
"HSET"
,
"spu"
,
spuId
,
jsonStr
)
spuKey
:=
common
.
GetKey
(
skuInfo
.
GoodsName
+
"_"
+
skuInfo
.
BrandName
)
redisWrite
.
Do
(
"HSET"
,
t
.
SPU_UNIQUE_JUDGE
,
spuKey
,
spuId
)
redisWrite
.
Do
(
"HSET"
,
config
.
Get
(
"redis_all.SPU_UNIQUE_JUDGE"
)
.
String
()
,
spuKey
,
spuId
)
return
spuId
}
...
...
@@ -210,15 +199,15 @@ func (t *CommonLyService) writeBrandInfo(skuInfo *model.LyClearGoodsList) int64
brandId
,
_
=
results
.
LastInsertId
()
}
//更新redis 品牌数据
redisWrite
.
Do
(
"HSET"
,
t
.
BRAND_NAME_ALL
,
brandkey
,
brandId
)
redisWrite
.
Do
(
"HSET"
,
t
.
BRAND
,
brandkey
,
brandId
)
redisWrite
.
Do
(
"HSET"
,
config
.
Get
(
"redis_all.BRAND_NAME_ALL"
)
.
String
()
,
brandkey
,
brandId
)
redisWrite
.
Do
(
"HSET"
,
config
.
Get
(
"redis_all.BRAND"
)
.
String
()
,
brandkey
,
brandId
)
return
brandId
;
}
/*
组装推送到es数据
*/
func
esSkuInfo
(
skuInfo
*
model
.
LyClearGoodsList
)
{
func
esSkuInfo
(
skuInfo
*
model
.
LyClearGoodsList
,
brandId
*
string
)
{
}
...
...
service/mouser_service.go
View file @
644a3d90
...
...
@@ -9,12 +9,6 @@ import (
//mouser外链网址
const
Mouser_api_url
string
=
"https://api.mouser.com/api/v1/search/partnumber?apiKey=0a11fa6f-ddcb-4ddf-9947-e42b2f3b4723"
//单例
type
MouserServiceImpl
struct
{}
func
NewMouserServiceImpl
()
*
MouserServiceImpl
{
return
&
MouserServiceImpl
{}
}
//mouser请求外链
func
OutLink
(
goodsName
*
string
,
flag
string
)
map
[
string
]
*
model
.
LyClearGoodsList
{
var
result
string
;
...
...
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