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
7de139c1
authored
Jan 17, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改取数据逻辑
parent
ff3b57b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
62 deletions
app/dao/supplier.go
app/service/supplier_sku_statistics.go
app/dao/supplier.go
View file @
7de139c1
...
@@ -14,79 +14,83 @@ import (
...
@@ -14,79 +14,83 @@ import (
)
)
func
StatisticsSuppliersSkuNum
()
(
err
error
)
{
func
StatisticsSuppliersSkuNum
()
(
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
}
//先重置所有供应商的平均数
supplierSkuNum
:=
new
(
model
.
Supplier
)
supplier
.
AverageSkuNum
=
0
_
,
err
=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id >= ?"
,
1
)
.
MustCols
(
"average_sku_num"
)
.
Update
(
supplierSkuNum
)
defer
rows
.
Close
()
var
num
int
var
num
int
for
rows
.
Next
()
{
total
,
_
:=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"is_type = ?"
,
0
)
.
Count
()
err
=
rows
.
Scan
(
supplier
)
for
i
:=
0
;
i
<
int
(
total
);
i
=
i
+
100
{
//去es查询sku数量
supplier
:=
new
(
model
.
Supplier
)
params
:=
req
.
Param
{
//先去根据供应商内部编码找出对应的supplierId
"goods_status/condition"
:
1
,
rows
,
err
:=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Limit
(
100
,
i
)
.
"canal/condition"
:
supplier
.
SupplierCode
,
Where
(
"is_type = ?"
,
0
)
.
OrderBy
(
"supplier_id desc"
)
.
Rows
(
supplier
)
"show_status"
:
1
,
"supplier_id"
:
17
,
"update_time/order"
:
"desc"
,
}
url
:=
lib
.
Instance
(
"config"
)
.
GetString
(
"es.es_sku_url"
)
resp
,
err
:=
req
.
Post
(
url
,
params
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
result
:=
resp
.
String
()
//先重置所有供应商的平均数
skuNum
:=
gjson
.
Get
(
result
,
"data.total"
)
.
Int
()
supplierSkuNum
:=
new
(
model
.
Supplier
)
if
skuNum
>
0
{
supplier
.
AverageSkuNum
=
0
num
++
_
,
err
=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id >= ?"
,
1
)
.
MustCols
(
"average_sku_num"
)
.
Update
(
supplierSkuNum
)
}
defer
rows
.
Close
()
for
rows
.
Next
()
{
/**
err
=
rows
.
Scan
(
supplier
)
sku数量和sku日志统计
//去es查询sku数量
**/
params
:=
req
.
Param
{
err
=
UpdateSupplierSkuNum
(
supplier
.
SupplierId
,
int
(
skuNum
))
"goods_status/condition"
:
1
,
if
err
!=
nil
{
"canal/condition"
:
supplier
.
SupplierCode
,
return
err
"show_status"
:
1
,
}
"supplier_id"
:
17
,
if
skuNum
>
0
{
"update_time/order"
:
"desc"
,
err
=
UpdateSupplierSkuLog
(
supplier
.
SupplierId
,
int
(
skuNum
))
}
url
:=
lib
.
Instance
(
"config"
)
.
GetString
(
"es.es_sku_url"
)
resp
,
err
:=
req
.
Post
(
url
,
params
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
}
result
:=
resp
.
String
()
skuNum
:=
gjson
.
Get
(
result
,
"data.total"
)
.
Int
()
if
skuNum
>
0
{
num
++
}
/**
/**
sku更新时间
sku数量和sku日志统计
**/
**/
if
skuNum
>
0
{
err
=
UpdateSupplierSkuNum
(
supplier
.
SupplierId
,
int
(
skuNum
))
updateSkuTime
:=
0
if
err
!=
nil
{
//找到第一个sku_id的更新时间
return
err
updateTimeMap
:=
gjson
.
Get
(
result
,
"data.update_time"
)
.
Map
()
if
updateTimeMap
!=
nil
{
for
_
,
createTime
:=
range
updateTimeMap
{
updateSkuTime
=
int
(
createTime
.
Int
())
break
}
}
}
if
updateSkuTime
>
0
{
if
skuNum
>
0
{
supplier
.
SkuUpdateTime
=
updateSkuTime
err
=
UpdateSupplierSkuLog
(
supplier
.
SupplierId
,
int
(
skuNum
))
affected
,
err
:=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id = ?"
,
supplier
.
SupplierId
)
.
Cols
(
"sku_update_time"
)
.
Update
(
supplier
)
if
affected
>
0
{
}
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
}
}
}
/**
sku更新时间
**/
if
skuNum
>
0
{
updateSkuTime
:=
0
//找到第一个sku_id的更新时间
updateTimeMap
:=
gjson
.
Get
(
result
,
"data.update_time"
)
.
Map
()
if
updateTimeMap
!=
nil
{
for
_
,
createTime
:=
range
updateTimeMap
{
updateSkuTime
=
int
(
createTime
.
Int
())
break
}
}
if
updateSkuTime
>
0
{
supplier
.
SkuUpdateTime
=
updateSkuTime
affected
,
err
:=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_id = ?"
,
supplier
.
SupplierId
)
.
Cols
(
"sku_update_time"
)
.
Update
(
supplier
)
if
affected
>
0
{
}
if
err
!=
nil
{
return
err
}
}
}
}
}
}
fmt
.
Println
(
"执行完成,有上传sku的供应商数量为 : "
,
num
)
fmt
.
Println
(
"执行完成,有上传sku的供应商数量为 : "
,
num
)
return
return
}
}
...
...
app/service/supplier_sku_statistics.go
View file @
7de139c1
...
@@ -7,10 +7,10 @@ import (
...
@@ -7,10 +7,10 @@ import (
func
StatisticsSupplierSkuStatus
()
(
err
error
)
{
func
StatisticsSupplierSkuStatus
()
(
err
error
)
{
fmt
.
Println
(
"开始统计"
)
fmt
.
Println
(
"开始统计"
)
err
=
dao
.
StatisticsSkuCreateTime
()
//
err = dao.StatisticsSkuCreateTime()
if
err
!=
nil
{
//
if err != nil {
return
err
//
return err
}
//
}
//先找出所有需要判断的供应商
//先找出所有需要判断的供应商
err
=
dao
.
StatisticsSuppliersSkuNum
()
err
=
dao
.
StatisticsSuppliersSkuNum
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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