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
cff10b5b
authored
May 11, 2021
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完成海关库的开发
parent
1a5cb428
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
19 deletions
app/dao/scm_data_dao/dao.go
cmd/scm/sync_customs/main.go
go.mod
app/dao/scm_data_dao/dao.go
View file @
cff10b5b
...
...
@@ -4,14 +4,14 @@ import (
"fmt"
"github.com/ichunt2019/cfg/lib"
_
"github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"log"
"xorm.io/xorm"
)
//初始化数据库
func
GetScmDataDb
()
*
sqlx
.
DB
{
db
,
err
:=
sqlx
.
Open
(
"mysql"
,
lib
.
Instance
(
"db"
)
.
GetString
(
"scm_data.dns"
))
func
GetScmDataDb
()
*
xorm
.
Engine
{
db
,
err
:=
xorm
.
NewEngine
(
"mysql"
,
lib
.
Instance
(
"db"
)
.
GetString
(
"scm_data.dns"
))
if
err
!=
nil
{
fmt
.
Println
(
err
)
log
.
Fatalln
(
err
)
...
...
cmd/scm/sync_customs/main.go
View file @
cff10b5b
...
...
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/ichunt2019/cfg/lib"
"golang-asynctask/app/dao/scm_data_dao"
"sync"
"time"
"github.com/hprose/hprose-golang/rpc"
...
...
@@ -24,9 +23,6 @@ var (
"SYS_OPERATE_LOG"
,
}
wg
sync
.
WaitGroup
)
...
...
@@ -52,7 +48,7 @@ func main() {
//获取当天时间
var
currentDate
=
time
.
Now
()
.
Format
(
"2006-01-02"
)
currentDate
=
"2021-05-0
7
"
currentDate
=
"2021-05-0
8
"
//循环获取表名,然后获取表内当天信息,并且存入mysql,协程处理
for
_
,
v
:=
range
syncTable
{
...
...
@@ -80,29 +76,42 @@ func handleCurrentTable(tableName,currentDate string) {
//var sqlInsert string = "insert into "+ tableName
sqlDb
:=
scm_data_dao
.
GetScmDataDb
()
var
sqlKeyValue
[]
map
[
string
]
interface
{}
var
curren
KeyValue
=
make
(
map
[
string
]
interface
{})
var
currentKey
,
valueString
,
currentNum
string
var
curren
tString
[]
interface
{}
for
_
,
res
:=
range
gjson
.
Parse
(
currentJson
)
.
Array
()
{
currentString
=
currentString
[
0
:
0
]
currentKey
=
""
valueString
=
""
currentNum
=
""
currentString
=
append
(
currentString
,
""
)
//sqlkey
res
.
ForEach
(
func
(
key
,
value
gjson
.
Result
)
bool
{
//获取key和val并拼接字符串
currenKeyValue
[
key
.
String
()]
=
value
.
String
()
currentKey
+=
key
.
String
()
+
","
valueString
+=
"?,"
currentString
=
append
(
currentString
,
value
.
String
())
if
key
.
String
()
==
"number"
&&
value
.
String
()
!=
""
{
currentNum
=
value
.
String
()
}
return
true
})
sqlKeyValue
=
append
(
sqlKeyValue
,
currenKeyValue
)
}
var
keystring
,
valstring
string
for
k
,
_
:=
range
sqlKeyValue
[
0
]
{
keystring
+=
k
+
","
valstring
+=
":"
+
k
+
","
//如果当前num 不为空,就删除掉之前的,然后新增
if
currentNum
!=
""
&&
tableName
!=
"SYS_OPERATE_LOG"
{
sqlDb
.
Exec
(
"delete from "
+
tableName
+
" where number = ?"
,
currentNum
)
}
_
,
err
:=
sqlDb
.
NamedExec
(
`INSERT INTO `
+
tableName
+
` (`
+
keystring
[
:
len
(
keystring
)
-
1
]
+
`)VALUES (`
+
valstring
[
:
len
(
valstring
)
-
1
]
+
`)`
,
sqlKeyValue
)
currentString
[
0
]
=
`INSERT INTO `
+
tableName
+
` (`
+
currentKey
[
:
len
(
currentKey
)
-
1
]
+
`)VALUES (`
+
valueString
[
:
len
(
valueString
)
-
1
]
+
`)`
_
,
err
:=
sqlDb
.
Exec
(
currentString
...
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
}
...
...
go.mod
View file @
cff10b5b
...
...
@@ -13,7 +13,6 @@ require (
github.com/ichunt2019/golang-rbmq-sl v0.0.0-20200515075131-59a37ab77d7d
github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042
github.com/jmoiron/sqlx v1.3.3
github.com/lib/pq v1.7.0
github.com/spf13/viper v1.7.1
github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.8
...
...
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