Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
bom_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
f8931d40
authored
Jun 18, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
d1c06c2d
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
106 additions
and
105 deletions
cmd/queue/bom.go
internal/logic/bom_item.go
internal/logic/match.go
internal/mapping/search_keyword.go
internal/mapping/unit_attr.go
internal/mapping/value_attr.go
server/main.go
cmd/queue/bom.go
View file @
f8931d40
...
...
@@ -14,16 +14,16 @@ type RecvPro struct {
}
func
init
()
{
//
queueExchange := rabbitmq.QueueExchange{
//
"bom_match",
//
"bom_match",
//
"bom",
//
"direct",
//
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
//
}
//
//str := `{"bom_id":436
,"delivery_type":1,"sort":1}`
//
rabbitmq.Send(queueExchange, str)
queueExchange
:=
rabbitmq
.
QueueExchange
{
"bom_match"
,
"bom_match"
,
"bom"
,
"direct"
,
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
,
}
str
:=
`{"bom_id":491
,"delivery_type":1,"sort":1}`
rabbitmq
.
Send
(
queueExchange
,
str
)
}
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
(
err
error
)
{
...
...
@@ -34,6 +34,7 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
if
err
!=
nil
{
log
.
Error
(
err
)
}
err
=
logic
.
MatchGoods
(
message
)
if
err
!=
nil
{
log
.
Error
(
err
)
...
...
internal/logic/bom_item.go
View file @
f8931d40
...
...
@@ -85,6 +85,8 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
return
err
}
defer
client
.
Stop
()
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
bomItems
,
err
=
MatchGoodsNameByAttrs
(
bomItems
)
//直接模糊匹配
goodsMapList
,
err
:=
getUpdateGoodsData
(
bomId
,
bomItems
,
where
.
DeliveryType
,
where
.
Sort
,
client
,
true
)
//fmt.Println(goodsMapList)
...
...
internal/logic/match.go
View file @
f8931d40
...
...
@@ -110,7 +110,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
}
//先去处理没有匹配到的数据
err
=
UpdateNoMatchBomItem
(
notMatchBomItems
,
fals
e
)
err
=
UpdateNoMatchBomItem
(
notMatchBomItems
,
tru
e
)
if
err
!=
nil
{
return
}
...
...
@@ -286,7 +286,7 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
//构建请求参数
func
getSearchParams
(
index
,
goodsName
,
brandName
string
,
sort
,
number
int
,
flag
bool
)
(
searchRequest
*
es
.
SearchRequest
)
{
query
:=
getTermQuery
(
goodsName
,
brandName
,
number
,
flag
)
query
:=
getTermQuery
(
goodsName
,
brandName
,
sort
,
number
,
flag
)
source
:=
es
.
NewSearchSource
()
.
Query
(
query
)
if
sort
==
1
{
source
.
Sort
(
"sort"
,
false
)
...
...
@@ -299,6 +299,7 @@ func getSearchParams(index, goodsName, brandName string, sort, number int, flag
// source.Sort("single_price_sort", false)
//}
//source.Sort("single_price_sort", false)
//source.Sort("stock", false)
source
.
Sort
(
"single_price"
,
true
)
//sort=3是按照库存排序
}
else
if
sort
==
3
{
...
...
@@ -313,7 +314,7 @@ func getSearchParams(index, goodsName, brandName string, sort, number int, flag
}
//构建term条件
func
getTermQuery
(
goodsName
,
brandName
string
,
number
int
,
flag
bool
)
(
query
*
es
.
BoolQuery
)
{
func
getTermQuery
(
goodsName
,
brandName
string
,
sort
,
number
int
,
flag
bool
)
(
query
*
es
.
BoolQuery
)
{
query
=
es
.
NewBoolQuery
()
if
flag
{
field
:=
"auto_goods_name.raw"
...
...
@@ -333,6 +334,14 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es
field
:=
"auto_goods_name"
query
=
query
.
Must
(
es
.
NewTermQuery
(
field
,
goodsName
))
}
//按价格排序
if
sort
==
2
{
query
=
query
.
Filter
(
es
.
NewRangeQuery
(
"single_price"
)
.
Gt
(
0
))
}
//库存排序
if
sort
==
3
{
query
=
query
.
Filter
(
es
.
NewRangeQuery
(
"stock"
)
.
Gt
(
0
))
}
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//query = query.Filter(es.NewRangeQuery("stock").Gt(0))
if
configs
.
ApiSetting
.
Mode
!=
"debug"
{
...
...
internal/mapping/search_keyword.go
View file @
f8931d40
...
...
@@ -21,3 +21,82 @@ var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//`^[\d\.]+(Uf|uf|μf|uF|UF)$`: "μF",
//`^[\d\.]+(Uh|uh|μh|uH|UH)$`: "μH",
//`^[\d\.]+K$`: "KΩ",
//属性单位对应属性
var
UnitAttrMapping
=
map
[
string
]
string
{
"r"
:
"阻值(欧姆)|直流电阻(内阻)"
,
"Ω"
:
"阻值(欧姆)|直流电阻(内阻)"
,
"OHM"
:
"阻值(欧姆)|直流电阻(内阻)"
,
"mh"
:
"电感"
,
"F"
:
"容值"
,
"w"
:
"功率"
,
"W"
:
"功率"
,
"Ω/r "
:
"内阻"
,
"%"
:
"精度"
,
"V"
:
"额定电压"
,
"A"
:
"额定电流"
,
}
//属性对应的基础属性
var
UnitBaseMapping
=
map
[
string
]
string
{
"μΩ"
:
"Ω"
,
"mΩ"
:
"Ω"
,
"Ω"
:
"Ω"
,
"kΩ"
:
"Ω"
,
"KΩ"
:
"Ω"
,
"MΩ"
:
"Ω"
,
"pF"
:
"F"
,
"nF"
:
"F"
,
"μF"
:
"F"
,
"μf"
:
"F"
,
"mF"
:
"F"
,
"F"
:
"F"
,
"μH"
:
"H"
,
"mH"
:
"H"
,
"H"
:
"H"
,
"V"
:
"V"
,
"kV"
:
"V"
,
"mA"
:
"A"
,
"A"
:
"A"
,
"W"
:
"W"
,
"kW"
:
"W"
,
"KW"
:
"W"
,
"%"
:
"%"
,
}
//根据单位对值的转换,比如1kΩ=>1000Ω
var
UnitValueMapping
=
map
[
string
]
string
{
"μΩ"
:
"0.000001"
,
"mΩ"
:
"0.001"
,
"Ω"
:
"1"
,
"kΩ"
:
"1000"
,
"KΩ"
:
"1000"
,
"MΩ"
:
"1000000"
,
"pF"
:
"1"
,
"nF"
:
"1000"
,
"μF"
:
"1000000"
,
"mF"
:
"1000000000"
,
"F"
:
"1000000000000"
,
"μH"
:
"1"
,
"mH"
:
"1000"
,
"H"
:
"1000000"
,
"V"
:
"1"
,
"kV"
:
"1000"
,
"mA"
:
"1"
,
"A"
:
"1000"
,
"W"
:
"1"
,
"kW"
:
"1000"
,
"%"
:
"0.01"
,
}
internal/mapping/unit_attr.go
deleted
100644 → 0
View file @
d1c06c2d
package
mapping
//属性单位对应属性
var
UnitAttrMapping
=
map
[
string
]
string
{
"r"
:
"阻值(欧姆)|直流电阻(内阻)"
,
"Ω"
:
"阻值(欧姆)|直流电阻(内阻)"
,
"OHM"
:
"阻值(欧姆)|直流电阻(内阻)"
,
"mh"
:
"电感"
,
"F"
:
"容值"
,
"w"
:
"功率"
,
"W"
:
"功率"
,
"Ω/r "
:
"内阻"
,
"%"
:
"精度"
,
"V"
:
"额定电压"
,
"A"
:
"额定电流"
,
}
//属性对应的基础属性
var
UnitBaseMapping
=
map
[
string
]
string
{
"μΩ"
:
"Ω"
,
"mΩ"
:
"Ω"
,
"Ω"
:
"Ω"
,
"kΩ"
:
"Ω"
,
"KΩ"
:
"Ω"
,
"MΩ"
:
"Ω"
,
"pF"
:
"F"
,
"nF"
:
"F"
,
"μF"
:
"F"
,
"μf"
:
"F"
,
"mF"
:
"F"
,
"F"
:
"F"
,
"μH"
:
"H"
,
"mH"
:
"H"
,
"H"
:
"H"
,
"V"
:
"V"
,
"kV"
:
"V"
,
"mA"
:
"A"
,
"A"
:
"A"
,
"W"
:
"W"
,
"kW"
:
"W"
,
"KW"
:
"W"
,
"%"
:
"%"
,
}
//根据单位对值的转换,比如1kΩ=>1000Ω
var
UnitValueMapping
=
map
[
string
]
string
{
"μΩ"
:
"0.000001"
,
"mΩ"
:
"0.001"
,
"Ω"
:
"1"
,
"kΩ"
:
"1000"
,
"KΩ"
:
"1000"
,
"MΩ"
:
"1000000"
,
"pF"
:
"1"
,
"nF"
:
"1000"
,
"μF"
:
"1000000"
,
"mF"
:
"1000000000"
,
"F"
:
"1000000000000"
,
"μH"
:
"1"
,
"mH"
:
"1000"
,
"H"
:
"1000000"
,
"V"
:
"1"
,
"kV"
:
"1000"
,
"mA"
:
"1"
,
"A"
:
"1000"
,
"W"
:
"1"
,
"kW"
:
"1000"
,
"%"
:
"0.01"
,
}
internal/mapping/value_attr.go
deleted
100644 → 0
View file @
d1c06c2d
package
mapping
//封装列表
var
PackingList
=
[]
string
{
"0402"
,
"0603"
,
}
//介质列表
var
MediaList
=
[]
string
{
"X5U"
,
"X7R"
,
}
server/main.go
View file @
f8931d40
...
...
@@ -3,6 +3,7 @@ package main
import
(
"bom_server/configs"
"bom_server/internal/model"
"bom_server/internal/pkg/gredis"
"bom_server/server/http"
"flag"
)
...
...
@@ -13,6 +14,7 @@ func main() {
flag
.
Parse
()
configs
.
Setup
(
path
)
model
.
Setup
()
gredis
.
Setup
()
err
:=
http
.
InitApiServer
()
if
err
!=
nil
{
panic
(
err
)
...
...
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