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
e5c069bf
authored
Jul 22, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
62621c25
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
19 deletions
controller/mouser_controller.go
routes/router.go
service/ly/common.go
controller/mouser_controller.go
View file @
e5c069bf
package
controller
import
(
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"search_server/model"
"search_server/pkg/common"
"search_server/service/ly"
)
//搜索型号
func
GetMouserData
(
c
*
gin
.
Context
)
{
goodsName
,
_
:=
c
.
GetPostForm
(
"goods_name"
)
lycon
:=
new
(
ly
.
CommonLyService
)
//
lycon := new(ly.CommonLyService)
//调外链拿数据
apiData
:=
ly
.
OutLinkMouser
(
&
goodsName
,
"1"
)
//供应商详情
supplierInfo
:=
model
.
SUPPLIER_REDIS_INFO
{
SupplierId
:
14
,
SupplierNickname
:
"mouser"
,
}
err
:=
lycon
.
GetSkuByGoodsSn
(
apiData
,
&
supplierInfo
)
var
errCode
int
if
!
err
{
errCode
=
1
}
res
:=
common
.
BomResponse
{
ErrCode
:
errCode
,
ErrMsg
:
""
,
Data
:
""
,
apiData
:=
ly
.
OutLinkMouser
(
&
goodsName
,
"-1"
)
//var shu string
//for _, info := range apiData {
//
// //PrintHtml(t.ctx,&t.flag,"snSku:"+snSku+" 查询得出sku"+skuId+" info",info)
// //jsonDatas,_ := json.Marshal(map[string]interface{}{
// // "dddd":"333333",
// // "ninifa":"333333",
// // "3333":"333333",
// // "gagaga":"333333",
// //})
// //fmt.Println(len(info))
// josn, errs := json.Marshal(info)
// if errs != nil {
// fmt.Println("错误")
// }
// shu += string(josn)
//}
// jsonDatas,_ := json.Marshal(map[string]interface{}{
// "dddd":"333333",
// "ninifa":"333333",
// "3333":"333333",
// "gagaga":"333333",
// })
josn
,
errs
:=
json
.
Marshal
(
apiData
)
if
errs
!=
nil
{
fmt
.
Println
(
"错误"
)
}
c
.
JSON
(
200
,
res
)
c
.
JSON
(
200
,
string
(
josn
))
//供应商详情
//supplierInfo := model.SUPPLIER_REDIS_INFO{
// SupplierId:14,
// SupplierNickname: "mouser",
//}
//err := lycon.GetSkuByGoodsSn(apiData,&supplierInfo)
//var errCode int
//if !err {
// errCode = 1
//}
//res := common.BomResponse{
// ErrCode: errCode,
// ErrMsg: "",
// Data: "",
//}
//c.JSON(200, map[string]interface{}{
// "error_code":777777,
// "err_msg":"ddddd2",
//})
}
routes/router.go
View file @
e5c069bf
...
...
@@ -21,6 +21,7 @@ func InitRouter() *gin.Engine {
r
.
POST
(
"/search/bom/recommend"
,
controller
.
Recommend
)
r
.
POST
(
"search/ZiYing/zyh"
,
controller
.
Zyh
)
r
.
POST
(
"search/mouser/GetMouserData"
,
controller
.
GetMouserData
)
r
.
GET
(
"search/mouser/GetMouserData"
,
controller
.
GetMouserData
)
//快手平台相关
r
.
GET
(
"/search/quote"
,
controller
.
QuoteIndex
)
...
...
service/ly/common.go
View file @
e5c069bf
...
...
@@ -50,6 +50,27 @@ func (t *CommonLyService) LyServerRun(){
t
.
flag
=
strings
.
TrimSpace
(
requstValue
[
0
])
}
}
if
t
.
flag
==
"101"
{
t
.
ctx
.
Header
(
"Content-Type"
,
"text/html; charset=utf-8"
)
}
}
/*
格式化数据直接输出浏览器
*/
func
PrintHtml
(
ctx
*
gin
.
Context
,
flag
*
string
,
data
string
,
jsondata
interface
{})
{
if
*
flag
==
"101"
{
if
jsondata
!=
""
{
jsonData
,
err
:=
json
.
Marshal
(
jsondata
)
if
err
!=
nil
{
fmt
.
Println
(
"错误:-----"
,
err
)
}
else
{
ctx
.
JSON
(
200
,
data
+
"</br>"
+
string
(
jsonData
))
}
}
else
{
ctx
.
JSON
(
200
,
data
+
"</br>"
)
}
}
}
/*
...
...
@@ -61,6 +82,11 @@ func (t *CommonLyService) LyServerRun(){
func
(
t
*
CommonLyService
)
GetSkuByGoodsSn
(
goodsList
map
[
string
]
*
model
.
LyClearGoodsList
,
supplierInfo
*
model
.
SUPPLIER_REDIS_INFO
)
bool
{
t
.
LyServerRun
();
//初始化变量
if
len
(
goodsList
)
==
0
{
PrintHtml
(
t
.
ctx
,
&
t
.
flag
,
"没有数据"
,
""
)
return
true
}
redisWrite
:=
gredis
.
Conn
(
"search_w"
)
defer
redisWrite
.
Close
()
...
...
@@ -73,6 +99,21 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
snSku
:=
php2go
.
Md5
(
strings
.
ToLower
(
goodsSn
))
skuId
,
_
:=
gredis
.
String
(
redisWrite
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.SKU_UNIQUE_JUDGE"
)
.
String
(),
snSku
))
//查询唯一值,反查sku_id
//PrintHtml(t.ctx,&t.flag,"snSku:"+snSku+" 查询得出sku"+skuId+" info",info)
//jsonData,err := json.Marshal(map[string]interface{}{
// "dddd":"333333",
// "ninifa":"333333",
// "3333":"333333",
// "gagaga":"333333",
//})
jsonData
,
err
:=
json
.
Marshal
(
info
)
if
err
!=
nil
{
fmt
.
Println
(
"错误:-----"
,
err
)
}
else
{
t
.
ctx
.
JSON
(
200
,
string
(
jsonData
))
}
continue
;
/**********新增sku**************/
skuFlag
:=
false
;
//是否新增或者更新db+redis,为true则新增
if
skuId
==
""
{
//redis没有此sku,创建
...
...
@@ -150,6 +191,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
}
t
.
pushEs
();
//最后推送ES
return
true
}
...
...
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