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
99bc6df0
authored
Jul 17, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
b937bb0f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
22 deletions
cmd/test1.go
controller/mouser_controller.go
model/ly.go
pkg/es/es.go
service/common_ly_service.go
service/mouser_service.go
cmd/test1.go
View file @
99bc6df0
...
...
@@ -4,6 +4,8 @@ import (
"flag"
"os"
"search_server/boot"
"search_server/pkg/es"
"strings"
)
func
main
()
{
...
...
@@ -32,16 +34,32 @@ func main() {
//os.Exit(1)
//dd := service.OutLink("LM358","-1")
//lines := []string{
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`,
// `{"name":"john doe","age":25 }`,
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`,
// `{"name":"mary smith","age":32 }`,
lines
:=
[]
string
{
`{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`
,
`{"name":"john doe","age":25 }`
,
`{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`
,
`{"name":"mary smith","age":32 }`
,
}
param
:=
strings
.
Join
(
lines
,
"
\n
"
)
+
"
\n
"
result
,
err
:=
es
.
BulkES
(
param
)
println
(
result
,
err
)
//var skuEsUpdataList []string
//
//param := map[string]interface{}{
// "goods_status":1,
// "status":1,
// "encoded": "{'ddd'}",
//}
//param := strings.Join(lines, "\n")+"\n"
//
//result,err := es.BulkES(param)
//println(result,err)
//paramjson,_ := json.Marshal(param)
//
//skuEsUpdataList = append(skuEsUpdataList,string(paramjson))
//skuEsUpdataList = append(skuEsUpdataList,string(paramjson))
//
//
//println(strings.Join(skuEsUpdataList,"\n"))
os
.
Exit
(
1
)
}
...
...
controller/mouser_controller.go
View file @
99bc6df0
...
...
@@ -11,10 +11,8 @@ import (
func
GetMouserData
(
c
*
gin
.
Context
)
{
goodsName
,
_
:=
c
.
GetPostForm
(
"goods_name"
)
lycon
:=
new
(
service
.
CommonLyService
)
//调外链拿数据
apiData
:=
service
.
OutLink
(
&
goodsName
,
"1"
)
//供应商详情
supplierInfo
:=
model
.
SUPPLIER_REDIS_INFO_
{
SupplierId
:
14
,
...
...
@@ -30,5 +28,5 @@ func GetMouserData(c *gin.Context) {
ErrMsg
:
""
,
Data
:
goods
,
}
c
.
JSON
(
200
,
res
)
c
.
JSON
(
200
,
res
)
}
model/ly.go
View file @
99bc6df0
...
...
@@ -18,6 +18,7 @@ type LyClearGoodsList struct {
Stock
int64
`json:"increment"`
//库存
Moq
int64
`json:"moq"`
//最小起订量、起订量
Tiered
[]
*
TierItem
//价格梯度数量
PriceTemp
[]
interface
{}
//拼接梯度,目前只有联营推送队列用
}
type
TierItem
struct
{
Purchases
uint64
//购买数量
...
...
pkg/es/es.go
View file @
99bc6df0
...
...
@@ -63,7 +63,7 @@ func BulkES(param string) (result string, err error) {
//req.Debug = true
header
:=
make
(
http
.
Header
)
header
.
Set
(
"Content-Type"
,
"application/x-ndjson"
)
resp
,
err
:=
req
.
Post
(
esUrl
+
"/_bulk
"
,
header
,
param
)
resp
,
err
:=
req
.
Post
(
esUrl
+
"/_bulk
?refresh=true"
,
header
,
param
)
//refresh=true 立刻插入或修改 立刻生效,不需要等待es缓存写入文档
if
err
!=
nil
{
return
}
...
...
service/common_ly_service.go
View file @
99bc6df0
...
...
@@ -4,11 +4,14 @@ package service
联营请求外链后 更新或者新增到平台 (es,redis,rabmq)
*/
import
(
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"search_server/middleware"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/pkg/mysql"
"strconv"
...
...
@@ -22,12 +25,14 @@ type CommonLyService struct {
supplierId
int64
//调用当前方法的供应商ID
supplierName
string
//调用当前方法的供应商名称
skuEsUpdataList
[]
string
//组装批量更新es数据
flag
string
//调试开关
flagStr
string
//调试输出内容
ctx
*
gin
.
Context
}
//初始化类
func
(
t
*
CommonLyService
)
LyServerRun
(){
CommonLyService
:=
new
(
CommonLyService
)
CommonLyService
.
supplier_over_time
=
map
[
string
]
int64
{
t
.
supplier_over_time
=
map
[
string
]
int64
{
"arrow"
:
3600
,
"verical"
:
3600
,
"mouser"
:
3600
,
...
...
@@ -35,7 +40,13 @@ func (t *CommonLyService) LyServerRun(){
"tme"
:
3600
,
"buerklin"
:
3600
,
}
t
.
ctx
=
middleware
.
Context
t
.
ctx
.
MultipartForm
()
for
requestName
,
requstValue
:=
range
t
.
ctx
.
Request
.
Form
{
if
requestName
==
"flag"
{
t
.
flag
=
strings
.
TrimSpace
(
requstValue
[
0
])
}
}
}
/*
...
...
@@ -254,20 +265,48 @@ func (t * CommonLyService) EsSkuInfo(skuInfo *model.LyClearGoodsList,spuId * str
}
paramjson
,
_
:=
json
.
Marshal
(
param
)
_
=
append
(
t
.
skuEsUpdataList
,
`{"index":{"_index":"`
+
t
.
supplierName
+
`","_type":"goods","_id":"`
+
skuInfo
.
GoodsId
+
`"}}`
)
_
=
append
(
t
.
skuEsUpdataList
,
string
(
paramjson
))
t
.
skuEsUpdataList
=
append
(
t
.
skuEsUpdataList
,
`{"index":{"_index":"`
+
t
.
supplierName
+
`","_type":"goods","_id":"`
+
skuInfo
.
GoodsId
+
`"}}`
)
t
.
skuEsUpdataList
=
append
(
t
.
skuEsUpdataList
,
string
(
paramjson
))
}
/*
推入队列
推入队列
=》(斌 go队列去消费更新db+mongodb..等操作)
*/
func
toGoRabmq
()
{
func
(
t
*
CommonLyService
)
updateSkuDB
(
skuInfo
*
model
.
LyClearGoodsList
)
{
if
skuInfo
.
GoodsId
==
""
{
return
}
param
:=
map
[
string
]
interface
{}{
"pn"
:
t
.
supplierName
,
"stock"
:
skuInfo
.
Stock
,
"tiered"
:
skuInfo
.
PriceTemp
,
"increment"
:
skuInfo
.
Increment
,
"sku_id"
:
skuInfo
.
GoodsId
,
"brand_name"
:
skuInfo
.
BrandName
,
"goods_name"
:
skuInfo
.
GoodsName
,
"goods_sn"
:
skuInfo
.
GoodsSn
,
}
}
/*
更新es
批量插入或者
更新es
*/
func
toEs
()
{
func
(
t
*
CommonLyService
)
pushEs
()
{
if
len
(
t
.
skuEsUpdataList
)
==
0
{
if
t
.
flag
==
"101"
{
t
.
flagStr
+=
"<br/>没有可插入es的数据"
}
return
}
param
:=
strings
.
Join
(
t
.
skuEsUpdataList
,
"
\n
"
)
+
"
\n
"
result
,
_
:=
es
.
BulkES
(
param
)
//批量插入
if
t
.
flag
==
"101"
{
t
.
flagStr
+=
"<br/>"
t
.
flagStr
+=
"插入es:"
t
.
flagStr
+=
param
t
.
flagStr
+=
result
}
}
service/mouser_service.go
View file @
99bc6df0
...
...
@@ -34,6 +34,7 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
goodsSn
:=
goods
.
Get
(
"MouserPartNumber"
)
.
String
()
ladderPrice
:=
make
([]
*
model
.
TierItem
,
0
)
priceTemp
:=
make
([]
interface
{},
0
)
//拼接价格梯度
apiPriceTi
:=
goods
.
Get
(
"PriceBreaks"
)
.
Array
()
var
apiLowerPrice
float64
=
0
;
//计算最低价格
...
...
@@ -51,6 +52,10 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
PriceCn
:
0
,
}
ladderPrice
=
append
(
ladderPrice
,
&
ladder
)
//梯度缓存数据
priceTemp
=
append
(
priceTemp
,
gjson
.
Get
(
priceItemStr
,
"Quantity"
)
.
Uint
())
priceTemp
=
append
(
priceTemp
,
gjson
.
Get
(
priceItemStr
,
"Price"
)
.
Float
())
}
//拼接联营数据
...
...
@@ -67,6 +72,7 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
RestrictionMessage
:
goods
.
Get
(
"RestrictionMessage"
)
.
String
(),
SinglePrice
:
apiLowerPrice
,
Tiered
:
ladderPrice
,
PriceTemp
:
priceTemp
,
}
productList
[
goodsSn
]
=
&
LyClearGoodsList
...
...
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