Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
go_supplier_sever
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
a5235e60
authored
Sep 24, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
sku模式统计
parent
7babdd53
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
128 additions
and
2 deletions
app/common/config/redis.go
app/dao/supplier.go
app/model/supplier.go
app/service/supplier_sku_mode.go
cmd/sku_mode/sku_mode.go
config/dev/config.toml
config/dev/redis.toml
app/common/config/redis.go
View file @
a5235e60
...
@@ -31,5 +31,15 @@ func BuildRedisGroupConfigs() ( map[string]RedisGroupDatabase) {
...
@@ -31,5 +31,15 @@ func BuildRedisGroupConfigs() ( map[string]RedisGroupDatabase) {
WriteTimeout
:
time
.
Duration
(
lib
.
Instance
(
"redis"
)
.
GetInt
(
"api.write_timeout"
))
*
time
.
Second
,
WriteTimeout
:
time
.
Duration
(
lib
.
Instance
(
"redis"
)
.
GetInt
(
"api.write_timeout"
))
*
time
.
Second
,
MinIdleConns
:
lib
.
Instance
(
"redis"
)
.
GetInt
(
"api.min_idle_conns"
),
MinIdleConns
:
lib
.
Instance
(
"redis"
)
.
GetInt
(
"api.min_idle_conns"
),
},
},
"sku"
:
{
MasterHost
:
lib
.
Instance
(
"redis"
)
.
GetString
(
"sku.master.host"
),
Password
:
lib
.
Instance
(
"redis"
)
.
GetString
(
"sku.master.password"
),
SlaveHost
:
lib
.
Instance
(
"redis"
)
.
GetStringSlice
(
"sku.slave.host"
),
ReadonlyPassword
:
lib
.
Instance
(
"redis"
)
.
GetString
(
"sku.slave.password"
),
DialTimeout
:
time
.
Duration
(
lib
.
Instance
(
"redis"
)
.
GetInt
(
"sku.dial_timeout"
))
*
time
.
Second
,
ReadTimeout
:
time
.
Duration
(
lib
.
Instance
(
"redis"
)
.
GetInt
(
"sku.read_timeout"
))
*
time
.
Second
,
WriteTimeout
:
time
.
Duration
(
lib
.
Instance
(
"redis"
)
.
GetInt
(
"sku.write_timeout"
))
*
time
.
Second
,
MinIdleConns
:
lib
.
Instance
(
"redis"
)
.
GetInt
(
"sku.min_idle_conns"
),
},
}
}
}
}
app/dao/supplier.go
View file @
a5235e60
...
@@ -61,3 +61,23 @@ func UpdateSupplierSkuNum(supplierId, skuNum int) (err error) {
...
@@ -61,3 +61,23 @@ func UpdateSupplierSkuNum(supplierId, skuNum int) (err error) {
}
}
return
return
}
}
//修改sku_mode
func
UpdateSupplierSkuMode
(
supplierId
,
skuMode
int
)
(
err
error
)
{
supplier
:=
new
(
model
.
Supplier
)
//先去根据供应商内部编码找出对应的supplierId
_
,
err
=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id = ?"
,
supplierId
)
.
Get
(
supplier
)
if
supplier
.
SupplierId
==
0
{
return
err
}
if
err
!=
nil
{
return
err
}
supplier
.
SkuMode
=
skuMode
//还要去写映射表lie_supplier_merger_mapping
_
,
err
=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id = ?"
,
supplierId
)
.
Update
(
supplier
)
if
err
!=
nil
{
return
err
}
return
}
app/model/supplier.go
View file @
a5235e60
...
@@ -5,4 +5,5 @@ type Supplier struct {
...
@@ -5,4 +5,5 @@ type Supplier struct {
SupplierCode
string
SupplierCode
string
SupplierName
string
SupplierName
string
SkuNum
int
SkuNum
int
SkuMode
int
}
}
app/service/supplier_sku_mode.go
0 → 100644
View file @
a5235e60
package
service
import
(
"fmt"
"github.com/ichunt2019/cfg/lib"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"go_supplier_sever/app/dao"
"go_supplier_sever/app/model"
"time"
)
//从ES统计出sku类型,然后写到供应商的sku_mode字段
func
SaveSkuModeFromES
()
(
err
error
)
{
supplier
:=
new
(
model
.
Supplier
)
//先去根据供应商内部编码找出对应的supplierId
rows
,
err
:=
dao
.
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"is_type = ?"
,
0
)
.
OrderBy
(
"supplier_id desc"
)
.
Rows
(
supplier
)
if
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
for
rows
.
Next
()
{
err
=
rows
.
Scan
(
supplier
)
//去es查询sku数量
params
:=
req
.
Param
{
"status/condition"
:
1
,
"canal/condition"
:
supplier
.
SupplierCode
,
}
url
:=
lib
.
Instance
(
"config"
)
.
GetString
(
"es.es_sku_url"
)
resp
,
err
:=
req
.
Post
(
url
,
params
)
if
err
!=
nil
{
return
err
}
result
:=
resp
.
String
()
goodsIdArr
:=
gjson
.
Get
(
result
,
"data.goods_id"
)
.
Array
()
if
len
(
goodsIdArr
)
>
0
{
//取一个goods_id就好
goodsId
:=
goodsIdArr
[
0
]
.
String
()
//去redis里面找出对应的goods_label
redisCon
:=
dao
.
Dao
.
GetRedisDbGroup
(
"sku"
)
result
:=
redisCon
.
HGet
(
"goods_tag"
,
goodsId
)
.
String
()
goodsLabel
:=
gjson
.
Get
(
result
,
"goods_label"
)
.
Int
()
if
int
(
goodsLabel
)
!=
0
{
//fmt.Println(supplier.SupplierId, goodsLabel)
err
=
dao
.
UpdateSupplierSkuMode
(
supplier
.
SupplierId
,
int
(
goodsLabel
))
if
err
!=
nil
{
return
err
}
}
}
time
.
Sleep
(
100
*
time
.
Millisecond
)
}
fmt
.
Println
(
"执行完成"
)
return
}
cmd/sku_mode/sku_mode.go
0 → 100644
View file @
a5235e60
package
main
import
(
"flag"
"fmt"
"go_supplier_sever/app/service"
"go_supplier_sever/boot"
)
var
(
configPath
string
logPath
string
)
func
main
()
{
flag
.
StringVar
(
&
configPath
,
"config"
,
"./config/dev/"
,
"配置文件"
)
flag
.
StringVar
(
&
logPath
,
"logdir"
,
"./logs/"
,
"日志文件存储目录"
)
flag
.
Parse
()
boot
.
Init
(
configPath
,
logPath
)
err
:=
service
.
SaveSkuModeFromES
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
config/dev/config.toml
View file @
a5235e60
...
@@ -2,4 +2,4 @@
...
@@ -2,4 +2,4 @@
url
=
"amqp://guest:guest@192.168.1.252:5672/"
url
=
"amqp://guest:guest@192.168.1.252:5672/"
[es]
[es]
es_sku_url
=
"http://soso12.ichunt.com/search/Es/searchSku"
es_sku_url
=
"http://soso12.liexin.com/search/Es/searchSku"
\ No newline at end of file
\ No newline at end of file
config/dev/redis.toml
View file @
a5235e60
...
@@ -12,3 +12,17 @@
...
@@ -12,3 +12,17 @@
"192.168.1.235:6379"
,
"192.168.1.235:6379"
,
"192.168.1.237:6379"
,
"192.168.1.237:6379"
,
]
]
[sku]
dial_timeout
=
20
min_idle_conns
=
10
read_timeout
=
10
write_timeout
=
10
[sku.master]
host
=
"192.168.1.235:6379"
password
=
"icDb29mLy2s"
[sku.slave]
password
=
"icDb29mLy2s"
host
=
[
"192.168.1.235:6379"
,
"192.168.1.237:6379"
,
]
\ No newline at end of file
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