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
ef80ebc2
authored
May 11, 2022
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
统计
parent
43a9e07d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
18 deletions
.gitignore
app/dao/supplier.go
app/model/supplier.go
app/service/supplier_sku_statistics.go
cmd/statistics/sku_num.go
config/dev/config.toml
.gitignore
View file @
ef80ebc2
/logs
/.idea
/config/*.toml
*.properties
*.exe
*.exe~
gowatch.yml
/logs
/.idea
/.history
/config/*.toml
*.properties
*.exe
*.exe~
gowatch.yml
app/dao/supplier.go
View file @
ef80ebc2
...
...
@@ -6,6 +6,8 @@ import (
"github.com/imroc/req"
"github.com/tidwall/gjson"
"go_supplier_sever/app/model"
"strconv"
"time"
)
func
StatisticsSuppliersSkuNum
()
(
err
error
)
{
...
...
@@ -44,7 +46,50 @@ func StatisticsSuppliersSkuNum() (err error) {
return
}
//添加erp同步记录
//统计供应商是否上传过sku
func
StatisticsSuppliersHasUploadedSku
()
(
err
error
)
{
supplier
:=
new
(
model
.
Supplier
)
//先去根据供应商内部编码找出对应的supplierId
rows
,
err
:=
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
()
var
num
int
for
rows
.
Next
()
{
time
.
Sleep
(
100
*
time
.
Millisecond
)
err
=
rows
.
Scan
(
supplier
)
//设置一个判断是否有上传sku的时间,目前是决定取2021年1月1日0点作为标准,这个时间往后的,有上传sku都是有合作过的
startTime
,
_
:=
time
.
Parse
(
"2006-01-02 15:04:05"
,
"2021-01-01 00:00:00"
)
startTimeUnix
:=
strconv
.
Itoa
(
int
(
startTime
.
Unix
()))
endTimeUnix
:=
strconv
.
Itoa
(
int
(
time
.
Now
()
.
Unix
()))
//去es查询sku数量
params
:=
req
.
Param
{
"canal/condition"
:
supplier
.
SupplierCode
,
"create_time/range"
:
startTimeUnix
+
","
+
endTimeUnix
,
}
url
:=
lib
.
Instance
(
"config"
)
.
GetString
(
"es.es_sku_url"
)
resp
,
err
:=
req
.
Post
(
url
,
params
)
if
err
!=
nil
{
return
err
}
result
:=
resp
.
String
()
skuNum
:=
gjson
.
Get
(
result
,
"data.total"
)
.
Int
()
//fmt.Println("供应商ID : ", supplier.SupplierId, "数量 : ", int(skuNum))
hasUploadedSku
:=
-
1
if
skuNum
>
0
{
num
++
hasUploadedSku
=
1
}
err
=
UpdateSupplierHasUploadedSku
(
supplier
.
SupplierId
,
hasUploadedSku
)
if
err
!=
nil
{
return
err
}
}
fmt
.
Println
(
"执行完成,历史有sku合作的供应商数量为 : "
,
num
)
return
}
func
UpdateSupplierSkuNum
(
supplierId
,
skuNum
int
)
(
err
error
)
{
supplier
:=
new
(
model
.
Supplier
)
//先去根据供应商内部编码找出对应的supplierId
...
...
@@ -64,6 +109,25 @@ func UpdateSupplierSkuNum(supplierId, skuNum int) (err error) {
return
}
func
UpdateSupplierHasUploadedSku
(
supplierId
int
,
hasUploadedSku
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
.
UploadedSku
=
hasUploadedSku
//还要去写映射表lie_supplier_merger_mapping
_
,
err
=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id = ?"
,
supplierId
)
.
Cols
(
"sku_num"
)
.
Update
(
supplier
)
if
err
!=
nil
{
return
err
}
return
}
//修改sku_mode
func
UpdateSupplierSkuMode
(
supplierId
,
skuMode
int
)
(
err
error
)
{
supplier
:=
new
(
model
.
Supplier
)
...
...
app/model/supplier.go
View file @
ef80ebc2
...
...
@@ -4,6 +4,7 @@ type Supplier struct {
SupplierId
int
SupplierCode
string
SupplierName
string
UploadedSku
int
SkuNum
int
SkuMode
int
}
app/service/supplier_sku_statistics.go
View file @
ef80ebc2
package
service
import
"go_supplier_sever/app/dao"
import
(
"fmt"
"go_supplier_sever/app/dao"
)
func
StatisticsSupplierSkuNum
()
(
err
error
)
{
func
StatisticsSupplierSkuStatus
()
(
err
error
)
{
fmt
.
Println
(
"开始统计"
)
//先找出所有需要判断的供应商
return
dao
.
StatisticsSuppliersSkuNum
()
err
=
dao
.
StatisticsSuppliersSkuNum
()
if
err
!=
nil
{
return
err
}
err
=
dao
.
StatisticsSuppliersHasUploadedSku
()
return
err
}
cmd/statistics/sku_num.go
View file @
ef80ebc2
...
...
@@ -18,7 +18,8 @@ func main() {
flag
.
Parse
()
boot
.
Init
(
configPath
,
logPath
)
err
:=
service
.
StatisticsSupplierSkuNum
()
//统计供应商sku相关情况
err
:=
service
.
StatisticsSupplierSkuStatus
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
...
...
config/dev/config.toml
View file @
ef80ebc2
[rabbit_mq_default]
url
=
"amqp://guest:guest@192.168.1.252:5672/"
[es]
es_sku_url
=
"http://soso12.liexin.com/search/Es/searchSku"
\ No newline at end of file
[rabbit_mq_default]
url
=
"amqp://guest:guest@192.168.1.252:5672/"
[es]
es_sku_url
=
"http://so.liexin.net/search/Es/searchSku"
\ 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