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
c48c9883
authored
Jul 21, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
66d3adc7
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
85 additions
and
88 deletions
conf/database.ini
controller/get_data_controller.go
controller/quote_controller.go
dao/cms_user.go
dao/supplier_channel.go
middleware/cors.go
model/cms_user.go
model/supplier_channel.go
pkg/config/mysql.go
pkg/mysql/mysql.go
service/query/quote_query.go
service/quote_service.go
test/test.go
conf/database.ini
View file @
c48c9883
[gorm]
mode
=
debug
[mysql]
user_name
=
root
password
=
root
host
=
192.168.2.250
database
=
test1
table_prefix
=
type
=
mysql
[bom]
user_name
=
root
password
=
root
host
=
192.168.2.250
database
=
test
table_prefix
=
type
=
mysql
[spu]
user_name
=
spu
password
=
spu
...
...
@@ -29,7 +13,7 @@ type = mysql
#SupDbUser:Supssy2@@!!@$#yxy@172.18.137.21:3306/liexin_supp
[supp]
user_name
=
liexin_ass
password
=
liexin_ass#zsyM
password
=
`liexin_ass#zsyM`
host
=
192.168.2.232
database
=
liexin_ass
table_prefix
=
lie_
...
...
@@ -37,7 +21,7 @@ type = mysql
[cms]
user_name
=
ichuntcms
password
=
ichuntcms#zsyM
password
=
`ichuntcms#zsyM`
host
=
192.168.2.232
database
=
ichuntcms
table_prefix
=
...
...
controller/get_data_controller.go
View file @
c48c9883
...
...
@@ -41,7 +41,7 @@ func GetDataIndex(c *gin.Context) {
defer
redisCon
.
Close
()
//获取stockFlag
res
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"SADD"
,
"search_keyword_member"
,
r
.
Keyword
+
"_"
+
r
.
SupplierName
))
fmt
.
Println
(
r
.
Keyword
+
"_"
+
r
.
SupplierName
)
fmt
.
Println
(
r
.
Keyword
+
"_"
+
r
.
SupplierName
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
...
...
@@ -54,7 +54,7 @@ func GetDataIndex(c *gin.Context) {
r
.
FirstSearchPage
=
2
quoteService
:=
service
.
QuoteService
{}
result
,
_
:=
quoteService
.
GetGoodsBySupplier
(
r
.
GetGoodsBySupplierRequest
)
c
.
JSON
(
200
,
common
.
SuccessResponse
(
1
,
""
,
result
)
)
c
ommon
.
Output
(
1
,
""
,
result
)
return
}
}
...
...
controller/quote_controller.go
View file @
c48c9883
package
controller
import
(
"fmt"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger"
...
...
@@ -34,10 +35,12 @@ func QuoteIndex(c *gin.Context) {
var
res
map
[
string
]
interface
{}
if
r
.
FollowHit
!=
0
&&
r
.
FollowHit
!=
1
{
res
,
_
=
quoteService
.
GetGoodsBySupplier
(
r
.
GetGoodsBySupplierRequest
)
if
len
(
res
)
>
0
{
if
res
!=
nil
{
flag
=
0
common
.
Output
(
flag
,
""
,
res
)
}
else
{
common
.
Output
(
flag
,
""
,
nil
)
}
common
.
Output
(
flag
,
""
,
res
)
return
}
//获取供应商名称
...
...
@@ -62,7 +65,7 @@ func QuoteIndex(c *gin.Context) {
}
func
mouserOrg
(
keyword
,
suppliedId
string
)
(
result
map
[
string
]
interface
{},
err
error
)
{
mouserRes
:=
service
.
OutLink
(
&
keyword
,
"
-
1"
)
mouserRes
:=
service
.
OutLink
(
&
keyword
,
"1"
)
redisCon
:=
gredis
.
Conn
(
"search_r"
)
defer
redisCon
.
Close
()
skuMouser
:=
make
(
map
[
string
]
string
)
...
...
@@ -71,7 +74,7 @@ func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err e
if
k
==
"N/A"
{
continue
}
snSku
:=
php2go
.
Md5
(
strings
.
To
Upp
er
(
k
+
"_"
+
suppliedId
))
snSku
:=
php2go
.
Md5
(
strings
.
To
Low
er
(
k
+
"_"
+
suppliedId
))
skuId
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
config
.
Get
(
"SKU_UNIQUE_JUDGE"
)
.
String
(),
snSku
))
if
skuId
!=
""
{
skuMouser
[
skuId
]
=
mouseItem
.
RestrictionMessage
...
...
@@ -94,32 +97,47 @@ func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err e
//获取内部编码对应关系
func
GetDataPur
(
c
*
gin
.
Context
)
{
supplierData
,
_
:=
dao
.
GetAllSupplierCodeAndUid
()
intracode
,
_
:=
dao
.
GetAllIntraCode
()
userInfo
,
_
:=
dao
.
GetAllUserBaseInfo
()
temp
:=
make
(
map
[
int
]
string
)
supplierData
,
err
:=
dao
.
GetAllSupplierCodeAndUid
()
if
err
!=
nil
{
c
.
JSON
(
200
,
err
.
Error
())
return
}
intracode
,
err
:=
dao
.
GetAllIntraCode
()
if
err
!=
nil
{
c
.
JSON
(
200
,
err
.
Error
())
return
}
userInfo
,
err
:=
dao
.
GetAllUserBaseInfo
()
if
err
!=
nil
{
c
.
JSON
(
200
,
err
.
Error
())
return
}
userInfoData
:=
make
(
map
[
int
]
string
)
for
_
,
user
:=
range
userInfo
{
if
user
.
Name
==
""
&&
user
.
Email
!=
""
{
temp
[
user
.
UserId
]
=
user
.
Email
userInfoData
[
user
.
UserId
]
=
user
.
Email
}
else
{
temp
[
user
.
UserId
]
=
user
.
Name
fmt
.
Println
(
user
.
UserId
)
userInfoData
[
user
.
UserId
]
=
user
.
Name
}
}
temp2
:=
make
(
map
[
int
]
string
)
for
_
,
code
:=
range
intracode
{
if
_
,
exist
:=
temp
[
code
.
AdminId
];
exist
{
temp2
[
code
.
CodeId
]
=
temp
[
code
.
AdminId
]
//fmt.Println(userInfoData[code.AdminId])
if
_
,
exist
:=
userInfoData
[
code
.
AdminId
];
exist
{
temp2
[
code
.
CodeId
]
=
userInfoData
[
code
.
AdminId
]
}
else
{
temp2
[
code
.
CodeId
]
=
""
}
}
redisCon
:=
gredis
.
Conn
(
"search_
r
"
)
redisCon
:=
gredis
.
Conn
(
"search_
w
"
)
defer
redisCon
.
Close
()
for
_
,
supplier
:=
range
supplierData
{
if
value
,
exist
:=
temp2
[
supplier
.
ChannelUid
];
exist
{
res
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"HSET"
,
"search_supplier_canaltopurchase"
,
supplier
.
SupplierCode
,
value
))
fmt
.
Println
(
value
)
fmt
.
Println
(
temp2
[
supplier
.
ChannelUid
])
res
,
err
:=
redis
.
Bool
(
redisCon
.
Do
(
"HSET"
,
"search_supplier_canaltopurchase_test"
,
supplier
.
SupplierCode
,
value
))
if
err
!=
nil
||
!
res
{
c
.
String
(
200
,
"失败"
)
return
...
...
@@ -134,5 +152,6 @@ func GetDataPur(c *gin.Context) {
func
GetData
(
keyword
,
supplierName
string
)
(
res
interface
{})
{
quoteService
:=
service
.
QuoteService
{}
res
,
_
=
quoteService
.
GetData
(
keyword
,
supplierName
)
fmt
.
Println
(
res
)
return
}
dao/cms_user.go
View file @
c48c9883
...
...
@@ -7,13 +7,12 @@ import (
//获取所有内部编码
func
GetAllIntraCode
()
(
intracode
[]
model
.
Intracode
,
err
error
)
{
_
,
err
=
mysql
.
Conn
(
"cms"
)
.
Table
(
"lie_intracode"
)
.
Select
(
"supplier_code,channel_uid"
)
.
Where
(
"status = ?"
,
2
)
.
Get
(
&
intracode
)
err
=
mysql
.
Conn
(
"cms"
)
.
Table
(
"lie_intracode"
)
.
Select
(
"code_id,admin_id"
)
.
Find
(
&
intracode
)
return
}
//获取所有的用户基础信息
func
GetAllUserBaseInfo
()
(
userBaseInfo
[]
model
.
CmsUserInfo
,
err
error
)
{
_
,
err
=
mysql
.
Conn
(
"cms"
)
.
Table
(
"user_info"
)
.
Select
(
"name,email,userId"
)
.
Get
(
&
userBaseInfo
)
err
=
mysql
.
Conn
(
"cms"
)
.
Table
(
"user_info"
)
.
Select
(
"name,email,userId"
)
.
Find
(
&
userBaseInfo
)
return
}
dao/supplier_channel.go
View file @
c48c9883
...
...
@@ -7,8 +7,7 @@ import (
//获取供应商编码和渠道开发员id
func
GetAllSupplierCodeAndUid
()
(
supplierChannels
[]
model
.
SupplierChannel
,
err
error
)
{
_
,
err
=
mysql
.
Conn
(
"supp"
)
.
Table
(
"lie_supplier_extra
"
)
.
Select
(
"supplier_code,channel_uid"
)
.
Where
(
"status = ?"
,
2
)
.
Get
(
&
supplierChannels
)
err
=
mysql
.
Conn
(
"supp"
)
.
Table
(
"lie_supplier_channel
"
)
.
Select
(
"supplier_code,channel_uid"
)
.
Where
(
"status = ?"
,
2
)
.
Find
(
&
supplierChannels
)
return
}
middleware/cors.go
View file @
c48c9883
...
...
@@ -10,6 +10,7 @@ import (
func
Cors
()
gin
.
HandlerFunc
{
corsDomain
:=
config
.
Get
(
"web.cors_domain"
)
.
Strings
(
","
)
corsDomain
=
append
(
corsDomain
,
"https://bom.ichunt.com"
)
corsDomain
=
append
(
corsDomain
,
"https://bom.ichunt.com"
)
return
cors
.
New
(
cors
.
Config
{
AllowOrigins
:
corsDomain
,
AllowMethods
:
[]
string
{
"POST"
,
"GET"
,
"PUT"
,
"DELETE"
},
...
...
model/cms_user.go
View file @
c48c9883
...
...
@@ -2,18 +2,18 @@ package model
//内部编码表
type
Intracode
struct
{
CodeId
int
`
json
:"code_id"`
AdminId
int
`
json
:"admin_id"`
UserId
int
`
json
:"user_id"`
CreateTime
int
`
json
:"create_time"`
UpdateTime
int
`
json
:"update_time"`
CodeId
int
`
xorm
:"code_id"`
AdminId
int
`
xorm
:"admin_id"`
UserId
int
`
xorm
:"user_id"`
CreateTime
int
`
xorm
:"create_time"`
UpdateTime
int
`
xorm
:"update_time"`
}
type
CmsUserInfo
struct
{
UserId
int
`json:"userId"`
Name
string
`
json
:"name"`
EngName
string
`
json
:"engName"`
Email
string
`
json
:"email"`
Mobile
string
`
json
:"mobile"`
UserId
int
`json:"userId"
xorm:"userId"
`
Name
string
`
xorm
:"name"`
EngName
string
`
xorm
:"engName"`
Email
string
`
xorm
:"email"`
Mobile
string
`
xorm
:"mobile"`
}
\ No newline at end of file
model/supplier_channel.go
View file @
c48c9883
package
model
type
SupplierChannel
struct
{
SupplierCode
string
`
json
:"supplier_code"`
ChannelUid
int
`
json
:"channel_uid"`
SupplierCode
string
`
xorm
:"supplier_code"`
ChannelUid
int
`
xorm
:"channel_uid"`
}
pkg/config/mysql.go
View file @
c48c9883
...
...
@@ -13,20 +13,6 @@ type BaseDatabase struct {
//多数据库配置
func
BuildDatabaseList
()
(
DatabaseList
map
[
string
]
BaseDatabase
)
{
return
map
[
string
]
BaseDatabase
{
"mysql"
:
{
UserName
:
Get
(
"mysql.user_name"
)
.
String
(),
Password
:
Get
(
"mysql.password"
)
.
String
(),
Host
:
Get
(
"mysql.host"
)
.
String
(),
Database
:
Get
(
"mysql.database"
)
.
String
(),
Prefix
:
Get
(
"mysql.prefix"
)
.
String
(),
},
"bom"
:
{
UserName
:
Get
(
"bom.user_name"
)
.
String
(),
Password
:
Get
(
"bom.password"
)
.
String
(),
Host
:
Get
(
"bom.host"
)
.
String
(),
Database
:
Get
(
"bom.database"
)
.
String
(),
Prefix
:
Get
(
"mysql.prefix"
)
.
String
(),
},
"spu"
:
{
UserName
:
Get
(
"spu.user_name"
)
.
String
(),
Password
:
Get
(
"spu.password"
)
.
String
(),
...
...
@@ -35,11 +21,18 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
Prefix
:
Get
(
"spu.table_prefix"
)
.
String
(),
},
"supp"
:
{
UserName
:
Get
(
"spu.user_name"
)
.
String
(),
Password
:
Get
(
"spu.password"
)
.
String
(),
Host
:
Get
(
"spu.host"
)
.
String
(),
Database
:
Get
(
"spu.database"
)
.
String
(),
Prefix
:
Get
(
"spu.table_prefix"
)
.
String
(),
UserName
:
Get
(
"supp.user_name"
)
.
String
(),
Password
:
Get
(
"supp.password"
)
.
String
(),
Host
:
Get
(
"supp.host"
)
.
String
(),
Database
:
Get
(
"supp.database"
)
.
String
(),
Prefix
:
Get
(
"supp.table_prefix"
)
.
String
(),
},
"cms"
:
{
UserName
:
Get
(
"cms.user_name"
)
.
String
(),
Password
:
Get
(
"cms.password"
)
.
String
(),
Host
:
Get
(
"cms.host"
)
.
String
(),
Database
:
Get
(
"cms.database"
)
.
String
(),
Prefix
:
Get
(
"cms.table_prefix"
)
.
String
(),
},
}
}
pkg/mysql/mysql.go
View file @
c48c9883
...
...
@@ -29,7 +29,7 @@ func Setup() error {
}
//日志打印SQL
DatabaseConMap
[
conName
]
.
ShowSQL
(
fals
e
)
DatabaseConMap
[
conName
]
.
ShowSQL
(
tru
e
)
//设置连接池的空闲数大小
DatabaseConMap
[
conName
]
.
SetMaxIdleConns
(
db
.
MaxIdleCons
)
...
...
@@ -44,4 +44,3 @@ func Setup() error {
func
Conn
(
conName
string
)
*
xorm
.
Engine
{
return
DatabaseConMap
[
conName
]
}
service/query/quote_query.go
View file @
c48c9883
package
query
import
(
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/uniplaces/carbon"
...
...
@@ -77,7 +76,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string,
query
.
MustNot
(
elastic
.
NewTermQuery
(
"status"
,
10
))
if
r
.
BrandId
!=
""
{
brandIdSlice
:=
strings
.
Split
(
r
.
BrandId
,
","
)
//todo : 取整
query
.
MustNot
(
elastic
.
NewTermQuery
(
"brand_id"
,
brandIdSlice
))
}
...
...
@@ -332,6 +330,5 @@ func GetGoodsBySupplierIdQuery(r requests.GetGoodsBySupplierRequest) (string, er
}
source
.
Query
(
query
)
searchRequest
:=
elastic
.
NewSearchRequest
()
.
Source
(
source
)
.
Preference
(
"_primary_first"
)
fmt
.
Println
(
searchRequest
.
Body
())
return
searchRequest
.
Body
()
}
service/quote_service.go
View file @
c48c9883
...
...
@@ -26,7 +26,6 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
if
err
!=
nil
{
return
}
queryString
=
""
esResult
,
err
:=
es
.
CurlES
(
supplierIndex
,
queryString
)
if
err
!=
nil
{
return
...
...
@@ -34,8 +33,12 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
goodsIds
:=
GetGoodsIdsByEs
(
esResult
)
goodsList
,
err
:=
GetGoodsInfo
(
goodsIds
)
dullData
,
err
:=
transformer
.
DullDataInfo
(
r
.
Keyword
,
goodsList
)
//整合供应商数据
result
=
GetReturnSupplierData
(
dullData
)
result
[
"total"
]
=
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
if
gjson
.
Get
(
esResult
,
"hits.total"
)
.
Int
()
==
0
{
return
nil
,
err
}
result
[
"took"
]
=
gjson
.
Get
(
esResult
,
"took"
)
.
Int
()
return
}
...
...
@@ -67,6 +70,7 @@ func (qs *QuoteService) GetData(keyword, supplier string) (res interface{}, err
}
quoteTransformer
:=
transformer
.
QuoteTransformer
{}
res
=
quoteTransformer
.
TransformCollectData
(
keyword
,
supplier
,
collectData
)
return
}
...
...
test/test.go
View file @
c48c9883
...
...
@@ -5,9 +5,9 @@ import (
"fmt"
log
"github.com/sirupsen/logrus"
"github.com/syyongx/php2go"
"os"
"reflect"
"search_server/boot"
"search_server/controller"
)
func
StrRandom
(
lenNum
int
)
string
{
...
...
@@ -39,15 +39,16 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
log
.
SetFormatter
(
new
(
LogFormatter
))
//设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
str
,
_
:=
os
.
Getwd
()
file
,
_
:=
os
.
OpenFile
(
str
+
"/logs/search/1.log"
,
os
.
O_CREATE
|
os
.
O_WRONLY
,
0666
)
log
.
SetOutput
(
file
)
fmt
.
Println
(
str
)
log
.
Error
(
"sadsadsadsa"
)
log
.
Error
(
"sadsadsadsa"
)
log
.
Error
(
"sadsadsadsa"
)
//log.SetFormatter(new(LogFormatter))
////设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
//str, _ := os.Getwd()
//file, _ := os.OpenFile(str+"/logs/search/1.log", os.O_CREATE|os.O_WRONLY, 0666)
//log.SetOutput(file)
//fmt.Println(str)
//log.Error("sadsadsadsa")
//log.Error("sadsadsadsa")
//log.Error("sadsadsadsa")
controller
.
GetData
(
"LM358"
,
"arrow"
)
}
...
...
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