Commit cff10b5b by Joneq

完成海关库的开发

parent 1a5cb428
......@@ -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)
......
......@@ -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-07"
currentDate = "2021-05-08"
//循环获取表名,然后获取表内当天信息,并且存入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 currenKeyValue = make(map[string]interface{})
var currentKey,valueString,currentNum string
var currentString []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)
}
}
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment