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
ed640eee
authored
May 19, 2021
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完成大屏数据同步
parent
eff63c65
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
168 additions
and
5 deletions
app/dao/scm_data_dao/dao.go
cmd/scm/README.md
cmd/scm/sync_bigtv_statistics/main.go
config/dev/db.toml
app/dao/scm_data_dao/dao.go
View file @
ed640eee
...
...
@@ -18,3 +18,12 @@ func GetScmDataDb()*xorm.Engine {
}
return
db
}
func
GetDashboardDb
()
*
xorm
.
Engine
{
db
,
err
:=
xorm
.
NewEngine
(
"mysql"
,
lib
.
Instance
(
"db"
)
.
GetString
(
"dashboard.dns"
))
if
err
!=
nil
{
fmt
.
Println
(
err
)
log
.
Fatalln
(
err
)
}
return
db
}
cmd/scm/README.md
View file @
ed640eee
...
...
@@ -3,3 +3,9 @@
sync_customs 海关所需要的信息同步
go run ./cmd/scm/sync_customs/main.go -config=./config/dev/ -logdir = ./logs/
sync_bigtv_statistics 同步erp的每日统计至shuju库
go run ./cmd/scm/sync_bigtv_statistics/main.go -config=./config/dev/ -logdir = ./logs/
cmd/scm/sync_bigtv_statistics/main.go
0 → 100644
View file @
ed640eee
package
main
import
(
"flag"
"fmt"
"github.com/hprose/hprose-golang/rpc"
"github.com/ichunt2019/cfg/lib"
"github.com/tidwall/gjson"
"golang-asynctask/app/dao/scm_data_dao"
"runtime"
"sync"
"time"
)
var
(
wg
sync
.
WaitGroup
currentDate
string
)
func
init
(){
var
(
configPath
string
logPath
string
)
flag
.
StringVar
(
&
configPath
,
"config"
,
"./config/dev/"
,
"配置文件"
)
flag
.
StringVar
(
&
logPath
,
"logdir"
,
"./logs/"
,
"日志文件存储目录"
)
flag
.
Parse
()
err
:=
lib
.
Init
(
configPath
)
if
err
!=
nil
{
panic
(
err
)
}
return
}
func
main
()
{
runtime
.
GOMAXPROCS
(
2
)
currentDate
=
time
.
Now
()
.
Format
(
"2006-01-02"
)
currentDate
:=
"20210506"
//获取当前时间
fmt
.
Println
(
currentDate
)
wg
.
Add
(
2
)
//指统计指定日期前20条物料记录
go
getMaterialstatistic
()
//返回历史物数量以及当日物料统计数量
go
getTotalStatistic
()
wg
.
Wait
()
}
func
getTotalStatistic
()
{
defer
wg
.
Done
()
jsonStr
:=
requestTableInfo
(
"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
()
==
"[]"
{
fmt
.
Println
(
jsonStr
)
return
}
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
()
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"
])
if
err
!=
nil
{
fmt
.
Println
(
"getTotalStatistic_sql_"
+
err
.
Error
())
}
}
}
func
getMaterialstatistic
()
{
defer
wg
.
Done
()
jsonStr
:=
requestTableInfo
(
"topStatistic"
)
//{"data": [], "returnCode": "0000", "returnMsg": "\u6210\u529f"}
if
gjson
.
Get
(
jsonStr
,
"returnCode"
)
.
String
()
!=
"0000"
||
gjson
.
Get
(
jsonStr
,
"data"
)
.
String
()
==
"[]"
{
fmt
.
Println
(
jsonStr
)
return
}
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
()
return
true
})
//添加数据
_
,
err
:=
sqlDb
.
Exec
(
"insert into lie_btv_daily_top_order (datetime,sn,order_num)"
+
"value(?,?,?)"
,
currentDate
,
erpKey
[
"materialName"
],
erpKey
[
"materialQty"
])
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
}
//获取表信息,返回byte
//request example //http://119.23.228.186:50005/ getCustomsDockingData {"tableName":"SYS_OPERATE_LOG","bizDate":"2021-05-07"}
func
requestTableInfo
(
requestType
string
)
string
{
type
Sub
struct
{
Get_materialstatistic
func
(
string
)
(
string
,
error
)
}
var
sub
*
Sub
client
:=
rpc
.
NewHTTPClient
(
"http://119.23.228.186:50005/"
)
client
.
UseService
(
&
sub
)
result
,
err
:=
sub
.
Get_materialstatistic
(
`{"date":"`
+
currentDate
+
`","requestType":"`
+
requestType
+
`"}`
)
if
err
!=
nil
{
fmt
.
Println
(
requestType
+
"请求服务器出错"
+
err
.
Error
())
return
""
}
//json字符串
return
result
}
\ No newline at end of file
config/dev/db.toml
View file @
ed640eee
...
...
@@ -57,11 +57,12 @@ ShowSQL = true
[dashboard]
dns
=
"dashboard:dashboard#zsyM@tcp(192.168.1.235:3306)/dashboard?charset=utf8&parseTime=true&loc=Asia%2FShanghai"
max_open_conn
=
20
max_idle_conn
=
10
table_prefix
=
""
max_conn_life_time
=
100
[scm_data]
...
...
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