Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
golang_asynctask
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
ba90d0ba
authored
May 24, 2021
by
孙龙
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'master' of
http://119.23.72.7/sunlong_v5/golang-asynctask
parents
bea328e7
9191b5ed
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
10 deletions
cmd/scm/sync_bigtv_statistics/main.go
cmd/scm/sync_bigtv_statistics/main.go
View file @
ba90d0ba
...
...
@@ -7,7 +7,10 @@ import (
"github.com/ichunt2019/cfg/lib"
"github.com/tidwall/gjson"
"golang-asynctask/app/dao/scm_data_dao"
"io/ioutil"
"net/http"
"runtime"
"strconv"
"sync"
"time"
)
...
...
@@ -15,6 +18,8 @@ import (
var
(
wg
sync
.
WaitGroup
currentDate
string
timeStart
time
.
Time
currentUnix
int64
)
func
init
(){
...
...
@@ -39,7 +44,12 @@ func main() {
runtime
.
GOMAXPROCS
(
2
)
currentDate
=
time
.
Now
()
.
Format
(
"2006-01-02"
)
currentDate
:=
"20210506"
//currentDate := "2021-05-06"
//请求数据
currentUnix
=
time
.
Now
()
.
Unix
()
timeLocal
,
_
:=
time
.
LoadLocation
(
"Local"
)
timeStart
,
_
=
time
.
ParseInLocation
(
"2006-01-02"
,
currentDate
,
timeLocal
)
//获取当前时间
fmt
.
Println
(
currentDate
)
...
...
@@ -47,19 +57,19 @@ func main() {
wg
.
Add
(
2
)
//指统计指定日期前20条物料记录
go
g
etMaterialstatistic
()
go
G
etMaterialstatistic
()
//返回历史物数量以及当日物料统计数量
go
g
etTotalStatistic
()
go
G
etTotalStatistic
()
wg
.
Wait
()
}
func
g
etTotalStatistic
()
{
func
G
etTotalStatistic
()
{
defer
wg
.
Done
()
jsonStr
:=
r
equestTableInfo
(
"totalStatistic"
)
jsonStr
:=
R
equestTableInfo
(
"totalStatistic"
)
//{"data": [{"materialQty": 0, "materialCount": 0, "materialTotalQty": 966724502}], "returnCode": "0000", "returnMsg": "\u6210\u529f"}
if
gjson
.
Get
(
jsonStr
,
"returnCode"
)
.
String
()
!=
"0000"
||
gjson
.
Get
(
jsonStr
,
"data"
)
.
String
()
==
"[]"
{
...
...
@@ -69,6 +79,8 @@ func getTotalStatistic() {
sqlDb
:=
scm_data_dao
.
GetDashboardDb
()
currentSearch
:=
TopSearch
()
for
_
,
res
:=
range
gjson
.
Get
(
jsonStr
,
"data"
)
.
Array
()
{
erpKey
:=
make
(
map
[
string
]
interface
{})
...
...
@@ -78,9 +90,12 @@ func getTotalStatistic() {
return
true
})
//获取当前日元器件型号搜索量
//添加数据
_
,
err
:=
sqlDb
.
Exec
(
"insert into lie_btv_daily_order_transaction (datetime,daily_ic_num,daily_ic_sn_num,history_ic_search_xinum)"
+
"value(?,?,?,?
)"
,
currentDate
,
erpKey
[
"materialQty"
],
erpKey
[
"materialCount"
],
erpKey
[
"materialTotalQty"
]
)
_
,
err
:=
sqlDb
.
Exec
(
"insert into lie_btv_daily_order_transaction (datetime,daily_ic_num,daily_ic_sn_num,history_ic_search_xinum
,current_sku_sum,daily_ic_search_num,daily_ic_search_xinum
)"
+
"value(?,?,?,?
,?,?,?)"
,
currentDate
,
erpKey
[
"materialQty"
],
erpKey
[
"materialCount"
],
erpKey
[
"materialTotalQty"
],
GetCurrentSku
(),
currentSearch
,
currentSearch
)
if
err
!=
nil
{
fmt
.
Println
(
"getTotalStatistic_sql_"
+
err
.
Error
())
...
...
@@ -89,11 +104,11 @@ func getTotalStatistic() {
}
func
g
etMaterialstatistic
()
{
func
G
etMaterialstatistic
()
{
defer
wg
.
Done
()
jsonStr
:=
r
equestTableInfo
(
"topStatistic"
)
jsonStr
:=
R
equestTableInfo
(
"topStatistic"
)
//{"data": [], "returnCode": "0000", "returnMsg": "\u6210\u529f"}
if
gjson
.
Get
(
jsonStr
,
"returnCode"
)
.
String
()
!=
"0000"
||
gjson
.
Get
(
jsonStr
,
"data"
)
.
String
()
==
"[]"
{
...
...
@@ -122,9 +137,59 @@ func getMaterialstatistic() {
}
//获取搜索数据 request example http://so12.ichunt.com/search/SearchLog/aggs?start_time=1621785600&end_time=1621871999&limit=2
// start_time 开始时间戳
// end_time 结束时间戳
// limit 显示前几条
func
TopSearch
()
int64
{
//获取前两百条数据
requestUrl
:=
"http://so12.ichunt.com/search/SearchLog/aggs?start_time="
+
strconv
.
FormatInt
(
timeStart
.
Unix
(),
10
)
+
"&end_time="
+
strconv
.
FormatInt
(
currentUnix
,
10
)
+
"&limit=200"
//requestUrl = "http://so12.ichunt.com/search/SearchLog/aggs?start_time=1621785600&end_time=1621871999&limit=200"
jsonStr
:=
RequestUrl
(
requestUrl
)
//{"error_code":0,"error_msg":"","data":[{"goods_name":"1N5408","count":20},{"goods_name":"OPA356AQDBVRQ1","count":19}]}
if
gjson
.
Get
(
jsonStr
,
"error_code"
)
.
String
()
!=
"0"
{
fmt
.
Println
(
"获取搜索数据失败"
,
jsonStr
)
return
0
}
insertDataNum
:=
20
var
allNum
int64
sqlDb
:=
scm_data_dao
.
GetDashboardDb
()
for
_
,
res
:=
range
gjson
.
Get
(
jsonStr
,
"data"
)
.
Array
()
{
erpKey
:=
make
(
map
[
string
]
interface
{})
res
.
ForEach
(
func
(
key
,
value
gjson
.
Result
)
bool
{
erpKey
[
key
.
String
()]
=
value
.
String
()
if
key
.
String
()
==
"count"
{
allNum
+=
value
.
Int
()
}
return
true
})
if
insertDataNum
>
0
{
//添加数据
_
,
err
:=
sqlDb
.
Exec
(
"insert into lie_btv_daily_top_search (datetime,sn,search_num)"
+
"value(?,?,?)"
,
currentDate
,
erpKey
[
"goods_name"
],
erpKey
[
"count"
])
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
insertDataNum
--
}
return
allNum
}
//获取表信息,返回byte
//request example //http://119.23.228.186:50005/ getCustomsDockingData {"tableName":"SYS_OPERATE_LOG","bizDate":"2021-05-07"}
func
r
equestTableInfo
(
requestType
string
)
string
{
func
R
equestTableInfo
(
requestType
string
)
string
{
type
Sub
struct
{
...
...
@@ -144,3 +209,30 @@ func requestTableInfo(requestType string)string {
//json字符串
return
result
}
func
GetCurrentSku
()
string
{
requestStr
:=
"http://soso12.ichunt.com/search/Es/searchSku?create_time/range="
+
strconv
.
FormatInt
(
timeStart
.
Unix
(),
10
)
+
","
+
strconv
.
FormatInt
(
currentUnix
,
10
)
+
"&goods_status/condition=1"
requestResult
:=
RequestUrl
(
requestStr
)
return
gjson
.
Get
(
requestResult
,
"data.total"
)
.
String
()
}
func
RequestUrl
(
url
string
)
string
{
//获取sku数量 http://soso12.ichunt.com/search/Es/searchSku?create_time/range=1620379867,1621489319&goods_status/condition=1
///{"error_code":0,"error_msg":"","data":{"total":"1765","scroll_id":null,"goods_id":[]}}
//获取当日搜索前二十
res
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
return
""
}
robots
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
res
.
Body
.
Close
()
if
err
!=
nil
{
return
""
}
return
string
(
robots
)
}
\ 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